raspberry-pi.patch 3.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592100593100594100595100596100597100598100599100600100601100602100603100604100605100606100607100608100609100610100611100612100613100614100615100616100617100618100619100620100621100622100623100624100625100626100627100628100629100630100631100632100633100634100635100636100637100638100639100640100641100642100643100644100645100646100647100648100649100650100651100652100653100654100655100656100657100658100659100660100661100662100663100664100665100666100667100668100669100670100671100672100673100674100675100676100677100678100679100680100681100682100683100684100685100686100687100688100689100690100691100692100693100694100695100696100697100698100699100700100701100702100703100704100705100706100707100708100709100710100711100712100713100714100715100716100717100718100719100720100721100722100723100724100725100726100727100728100729100730100731100732100733100734100735100736100737100738100739100740100741100742100743100744100745100746100747100748100749100750100751100752100753100754100755100756100757100758100759100760100761100762100763100764100765100766100767100768100769100770100771100772100773100774100775100776100777100778100779100780100781100782100783100784100785100786100787100788100789100790100791100792100793100794100795100796100797100798100799100800100801100802100803100804100805100806100807100808100809100810100811100812100813100814100815100816100817100818100819100820100821100822100823100824100825100826100827100828100829100830100831100832100833100834100835100836100837100838100839100840100841100842100843100844100845100846100847100848100849100850100851100852100853100854100855100856100857100858100859100860100861100862100863100864100865100866100867100868100869100870100871100872100873100874100875100876100877100878100879100880100881100882100883100884100885100886100887100888100889100890100891100892100893100894100895100896100897100898100899100900100901100902100903100904100905100906100907100908100909100910100911100912100913100914100915100916100917100918100919100920100921100922100923100924100925100926100927100928100929100930100931100932100933100934100935100936100937100938100939100940100941100942100943100944100945100946100947100948100949100950100951100952100953100954100955100956100957100958100959100960100961100962100963100964100965100966100967100968100969100970100971100972100973100974100975100976100977100978100979100980100981100982100983100984100985100986100987100988100989100990100991100992100993100994100995100996100997100998100999101000101001101002101003101004101005101006101007101008101009101010101011101012101013101014101015101016101017101018101019101020101021101022101023101024101025101026101027101028101029101030101031101032101033101034101035101036101037101038101039101040101041101042101043101044101045101046101047101048101049101050101051101052101053101054101055101056101057101058101059101060101061101062101063101064101065101066101067101068101069101070101071101072101073101074101075101076101077101078101079101080101081101082101083101084101085101086101087101088101089101090101091101092101093101094101095101096101097101098101099101100101101101102101103101104101105101106101107101108101109101110101111101112101113101114101115101116101117101118101119101120101121101122101123101124101125101126101127101128101129101130101131101132101133101134101135101136101137101138101139101140101141101142101143101144101145101146101147101148101149101150101151101152101153101154101155101156101157101158101159101160101161101162101163101164101165101166101167101168101169101170101171101172101173101174101175101176101177101178101179101180101181101182101183101184101185101186101187101188101189101190101191101192101193101194101195101196101197101198101199101200101201101202101203101204101205101206101207101208101209101210101211101212101213101214101215101216101217101218101219101220101221101222101223101224101225101226101227101228101229101230101231101232101233101234101235101236101237101238101239101240101241101242101243101244101245101246101247101248101249101250101251101252101253101254101255101256101257101258101259101260101261101262101263101264101265101266101267101268101269101270101271101272101273101274101275101276101277101278101279101280101281101282101283101284101285101286101287101288101289101290101291101292101293101294101295101296101297101298101299101300101301101302101303101304101305101306101307101308101309101310101311101312101313101314101315101316101317101318101319101320101321101322101323101324101325101326101327101328101329101330101331101332101333101334101335101336101337101338101339101340101341101342101343101344101345101346101347101348101349101350101351101352101353101354101355101356101357101358101359101360101361101362101363101364101365101366101367101368101369101370101371101372101373101374101375101376101377101378101379101380101381101382101383101384101385101386101387101388101389101390101391101392101393101394101395101396101397101398101399101400101401101402101403101404101405101406101407101408101409101410101411101412101413101414101415101416101417101418101419101420101421101422101423101424101425101426101427101428101429101430101431101432101433101434101435101436101437101438101439101440101441101442101443101444101445101446101447101448101449101450101451101452101453101454101455101456101457101458101459101460101461101462101463101464101465101466101467101468101469101470101471101472101473101474101475101476101477101478101479101480101481101482101483101484101485101486101487101488101489101490101491101492101493101494101495101496101497101498101499101500101501101502101503101504101505101506101507101508101509101510101511101512101513101514101515101516101517101518101519101520101521101522101523101524101525101526101527101528101529101530101531101532101533101534101535101536101537101538101539101540101541101542101543101544101545101546101547101548101549101550101551101552101553101554101555101556101557101558101559101560101561101562101563101564101565101566101567101568101569101570101571101572101573101574101575101576101577101578101579101580101581101582101583101584101585101586101587101588101589101590101591101592101593101594101595101596101597101598101599101600101601101602101603101604101605101606101607101608101609101610101611101612101613101614101615101616101617101618101619101620101621101622101623101624101625101626101627101628101629101630101631101632101633101634101635101636101637101638101639101640101641101642101643101644101645101646101647101648101649101650101651101652101653101654101655101656101657101658101659101660101661101662101663101664101665101666101667101668101669101670101671101672101673101674101675101676101677101678101679101680101681101682101683101684101685101686101687101688101689101690101691101692101693101694101695101696101697101698101699101700101701101702101703101704101705101706101707101708101709101710101711101712101713101714101715101716101717101718101719101720101721101722101723101724101725101726101727101728101729101730101731101732101733101734101735101736101737101738101739101740101741101742101743101744101745101746101747101748101749101750101751101752101753101754101755101756101757101758101759101760101761101762101763101764101765101766101767101768101769101770101771101772101773101774101775101776101777101778101779101780101781101782101783101784101785101786101787101788101789101790101791101792101793101794101795101796101797101798101799101800101801101802101803101804101805101806101807101808101809101810101811101812101813101814101815101816101817101818101819101820101821101822101823101824101825101826101827101828101829101830101831101832101833101834101835101836101837101838101839101840101841101842101843101844101845101846101847101848101849101850101851101852101853101854101855101856101857101858101859101860101861101862101863101864101865101866101867101868101869101870101871101872101873101874101875101876101877101878101879101880101881101882101883101884101885101886101887101888101889101890101891101892101893101894101895101896101897101898101899101900101901101902101903101904101905101906101907101908101909101910101911101912101913101914101915101916101917101918101919101920101921101922101923101924101925101926101927101928101929101930101931101932101933101934101935101936101937101938101939101940101941101942101943101944101945101946101947101948101949101950101951101952101953101954101955101956101957101958101959101960101961101962101963101964101965101966101967101968101969101970101971101972101973101974101975101976101977101978101979101980101981101982101983101984101985101986101987101988101989101990101991101992101993101994101995101996101997101998101999102000102001102002102003102004102005102006102007102008102009102010102011102012102013102014102015102016102017102018102019102020102021102022102023102024102025102026102027102028102029102030102031102032102033102034102035102036102037102038102039102040102041102042102043102044102045102046102047102048102049102050102051102052102053102054102055102056102057102058102059102060102061102062102063102064102065102066102067102068102069102070102071102072102073102074102075102076102077102078102079102080102081102082102083102084102085102086102087102088102089102090102091102092102093102094102095102096102097102098102099102100102101102102102103102104102105102106102107102108102109102110102111102112102113102114102115102116102117102118102119102120102121102122102123102124102125102126102127102128102129102130102131102132102133102134102135102136102137102138102139102140102141102142102143102144102145102146102147102148102149102150102151102152102153102154102155102156102157102158102159102160102161102162102163102164102165102166102167102168102169102170102171102172102173102174102175102176102177102178102179102180102181102182102183102184102185102186102187102188102189102190102191102192102193102194102195102196102197102198102199102200102201102202102203102204102205102206102207102208102209102210102211102212102213102214102215102216102217102218102219102220102221102222102223102224102225102226102227102228102229102230102231102232102233102234102235102236102237102238102239102240102241102242102243102244102245102246102247102248102249102250102251102252102253102254102255102256102257102258102259102260102261102262102263102264102265102266102267102268102269102270102271102272102273102274102275102276102277102278102279102280102281102282102283102284102285102286102287102288102289102290102291102292102293102294102295102296102297102298102299102300102301102302102303102304102305102306102307102308102309102310102311102312102313102314102315102316102317102318102319102320102321102322102323102324102325102326102327102328102329102330102331102332102333102334102335102336102337102338102339102340102341102342102343102344102345102346102347102348102349102350102351102352102353102354102355102356102357102358102359102360102361102362102363102364102365102366102367102368102369102370102371102372102373102374102375102376102377102378102379102380102381102382102383102384102385102386102387102388102389102390102391102392102393102394102395102396102397102398102399102400102401102402102403102404102405102406102407102408102409102410102411102412102413102414102415102416102417102418102419102420102421102422102423102424102425102426102427102428102429102430102431102432102433102434102435102436102437102438102439102440102441102442102443102444102445102446102447102448102449102450102451102452102453102454102455102456102457102458102459102460102461102462102463102464102465102466102467102468102469102470102471102472102473102474102475102476102477102478102479102480102481102482102483102484102485102486102487102488102489102490102491102492102493102494102495102496102497102498102499102500102501102502102503102504102505102506102507102508102509102510102511102512102513102514102515102516102517102518102519102520102521102522102523102524102525102526102527102528102529102530102531102532102533102534102535102536102537102538102539102540102541102542102543102544102545102546102547102548102549102550102551102552102553102554102555102556102557102558102559102560102561102562102563102564102565102566102567102568102569102570102571102572102573102574102575102576102577102578102579102580102581102582102583102584102585102586102587102588102589102590102591102592102593102594102595102596102597102598102599102600102601102602102603102604102605102606102607102608102609102610102611102612102613102614102615102616102617102618102619102620102621102622102623102624102625102626102627102628102629102630102631102632102633102634102635102636102637102638102639102640102641102642102643102644102645102646102647102648102649102650102651102652102653102654102655102656102657102658102659102660102661102662102663102664102665102666102667102668102669102670102671102672102673102674102675102676102677102678102679102680102681102682102683102684102685102686102687102688102689102690102691102692102693102694102695102696102697102698102699102700102701102702102703102704102705102706102707102708102709102710102711102712102713102714102715102716102717102718102719102720102721102722102723102724102725102726102727102728102729102730102731102732102733102734102735102736102737102738102739102740102741102742102743102744102745102746102747102748102749102750102751102752102753102754102755102756102757102758102759102760102761102762102763102764102765102766102767102768102769102770102771102772102773102774102775102776102777102778102779102780102781102782102783102784102785102786102787102788102789102790102791102792102793102794102795102796102797102798102799102800102801102802102803102804102805102806102807102808102809102810102811102812102813102814102815102816102817102818102819102820102821102822102823102824102825102826102827102828102829102830102831102832102833102834102835102836102837102838102839102840102841102842102843102844102845102846102847102848102849102850102851102852102853102854102855102856102857102858102859102860102861102862102863102864102865102866102867102868102869102870102871102872102873102874102875102876102877102878102879102880102881102882102883102884102885102886102887102888102889102890102891102892102893102894102895102896102897102898102899102900102901102902102903102904102905102906102907102908102909102910102911102912102913102914102915102916102917102918102919102920102921102922102923102924102925102926102927102928102929102930102931102932102933102934102935102936102937102938102939102940102941102942102943102944102945102946102947102948102949102950102951102952102953102954102955102956102957102958102959102960102961102962102963102964102965102966102967102968102969102970102971102972102973102974102975102976102977102978102979102980102981102982102983102984102985102986102987102988102989102990102991102992102993102994102995102996102997102998102999103000103001103002103003103004103005103006103007103008103009103010103011103012103013103014103015103016103017103018103019103020103021103022103023103024103025103026103027103028103029103030103031103032103033103034103035103036103037103038103039103040103041103042103043103044103045103046103047103048103049103050103051103052103053103054103055103056103057103058103059103060103061103062103063103064103065103066103067103068103069103070103071103072103073103074103075103076103077103078103079103080103081103082103083103084103085103086103087103088103089103090103091103092103093103094103095103096103097103098103099103100103101103102103103103104103105103106103107103108103109103110103111103112103113103114103115103116103117103118103119103120103121103122103123103124103125103126103127103128103129103130103131103132103133103134103135103136103137103138103139103140103141103142103143103144103145103146103147103148103149103150103151103152103153103154103155103156103157103158103159103160103161103162103163103164103165103166103167103168103169103170103171103172103173103174103175103176103177103178103179103180103181103182103183103184103185103186103187103188103189103190103191103192103193103194103195103196103197103198103199103200103201103202103203103204103205103206103207103208103209103210103211103212103213103214103215103216103217103218103219103220103221103222103223103224103225103226103227103228103229103230103231103232103233103234103235103236103237103238103239103240103241103242103243103244103245103246103247103248103249103250103251103252103253103254103255103256103257103258103259103260103261103262103263103264103265103266103267103268103269103270103271103272103273103274103275103276103277103278103279103280103281103282103283103284103285103286103287103288103289103290103291103292103293103294103295103296103297103298103299103300103301103302103303103304103305103306103307103308103309103310103311103312103313103314103315103316103317103318103319103320103321103322103323103324103325103326103327103328103329103330103331103332103333103334103335103336103337103338103339103340103341103342103343103344103345103346103347103348103349103350103351103352103353103354103355103356103357103358103359103360103361103362103363103364103365103366103367103368103369103370103371103372103373103374103375103376103377103378103379103380103381103382103383103384103385103386103387103388103389103390103391103392103393103394103395103396103397103398103399103400103401103402103403103404103405103406103407103408103409103410103411103412103413103414103415103416103417103418103419103420103421103422103423103424103425103426103427103428103429103430103431103432103433103434103435103436103437103438103439103440103441103442103443103444103445103446103447103448103449103450103451103452103453103454103455103456103457103458103459103460103461103462103463103464103465103466103467103468103469103470103471103472103473103474103475103476103477103478103479103480103481103482103483103484103485103486103487103488103489103490103491103492103493103494103495103496103497103498103499103500103501103502103503103504103505103506103507103508103509103510103511103512103513103514103515103516103517103518103519103520103521103522103523103524103525103526103527103528103529103530103531103532103533103534103535103536103537103538103539103540103541103542103543103544103545103546103547103548103549103550103551103552103553103554103555103556103557103558103559103560103561103562103563103564103565103566103567103568103569103570103571103572103573103574103575103576103577103578103579103580103581103582103583103584103585103586103587103588103589103590103591103592103593103594103595103596103597103598103599103600103601103602103603103604103605103606103607103608103609103610103611103612103613103614103615103616103617103618103619103620103621103622103623103624103625103626103627103628103629103630103631103632103633103634103635103636103637103638103639103640103641103642103643103644103645103646103647103648103649103650103651103652103653103654103655103656103657103658103659103660103661103662103663103664103665103666103667103668103669103670103671103672103673103674103675103676103677103678103679103680103681103682103683103684103685103686103687103688103689103690103691103692103693103694103695103696103697103698103699103700103701103702103703103704103705103706103707103708103709103710103711103712103713103714103715103716103717103718103719103720103721103722103723103724103725103726103727103728103729103730103731103732103733103734103735103736103737103738103739103740103741103742103743103744103745103746103747103748103749103750103751103752103753103754103755103756103757103758103759103760103761103762103763103764103765103766103767103768103769103770103771103772103773103774103775103776103777103778103779103780103781103782103783103784103785103786103787103788103789103790103791103792103793103794103795103796103797103798103799103800103801103802103803103804103805103806103807103808103809103810103811103812103813103814103815103816103817103818103819103820103821103822103823103824103825103826103827103828103829103830103831103832103833103834103835103836103837103838103839103840103841103842103843103844103845103846103847103848103849103850103851103852103853103854103855103856103857103858103859103860103861103862103863103864103865103866103867103868103869103870103871103872103873103874103875103876103877103878103879103880103881103882103883103884103885103886103887103888103889103890103891103892103893103894103895103896103897103898103899103900103901103902103903103904103905103906103907103908103909103910103911103912103913103914103915103916103917103918103919103920103921103922103923103924103925103926103927103928103929103930103931103932103933103934103935103936103937103938103939103940103941103942103943103944103945103946103947103948103949103950103951103952103953103954103955103956103957103958103959103960103961103962103963103964103965103966103967103968103969103970103971103972103973103974103975103976103977103978103979103980103981103982103983103984103985103986103987103988103989103990103991103992103993103994103995103996103997103998103999104000104001104002104003104004104005104006104007104008104009104010104011104012104013104014104015104016104017104018104019104020104021104022104023104024104025104026104027104028104029104030104031104032104033104034104035104036104037104038104039104040104041104042104043104044104045104046104047104048104049104050104051104052104053104054104055104056104057104058104059104060104061104062104063104064104065104066104067104068104069104070104071104072104073104074104075104076104077104078104079104080104081104082104083104084104085104086104087104088104089104090104091104092104093104094104095104096104097104098104099104100104101104102104103104104104105104106104107104108104109104110104111104112104113104114104115104116104117104118104119104120104121104122104123104124104125104126104127104128104129104130104131104132104133104134104135104136104137104138104139104140104141104142104143104144104145104146104147104148104149104150104151104152104153104154104155104156104157104158104159104160104161104162104163104164104165104166104167104168104169104170104171104172104173104174104175104176104177104178104179104180104181104182104183104184104185104186104187104188104189104190104191104192104193104194104195104196104197104198104199104200104201104202104203104204104205104206104207104208104209104210104211104212104213104214104215104216104217104218104219104220104221104222104223104224104225104226104227104228104229104230104231104232104233104234104235104236104237104238104239104240104241104242104243104244104245104246104247104248104249104250104251104252104253104254104255104256104257104258104259104260104261104262104263104264104265104266104267104268104269104270104271104272104273104274104275104276104277104278104279104280104281104282104283104284104285104286104287104288104289104290104291104292104293104294104295104296104297104298104299104300104301104302104303104304104305104306104307104308104309104310104311104312104313104314104315104316104317104318104319104320104321104322104323104324104325104326104327104328104329104330104331104332104333104334104335104336104337104338104339104340104341104342104343104344104345104346104347104348104349104350104351104352104353104354104355104356104357104358104359104360104361104362104363104364104365104366104367104368104369104370104371104372104373104374104375104376104377104378104379104380104381104382104383104384104385104386104387104388104389104390104391104392104393104394104395104396104397104398104399104400104401104402104403104404104405104406104407104408104409104410104411104412104413104414104415104416104417104418104419104420104421104422104423104424104425104426104427104428104429104430104431104432104433104434104435104436104437104438104439104440104441104442104443104444104445104446104447104448104449104450104451104452104453104454104455104456104457104458104459104460104461104462104463104464104465104466104467104468104469104470104471104472104473104474104475104476104477104478104479104480104481104482104483104484104485104486104487104488104489104490104491104492104493104494104495104496104497104498104499104500104501104502104503104504104505104506104507104508104509104510104511104512104513104514104515104516104517104518104519104520104521104522104523104524104525104526104527104528104529104530104531104532104533104534104535104536104537104538104539104540104541104542104543104544104545104546104547104548104549104550104551104552104553104554104555104556104557104558104559104560104561104562104563104564104565104566104567104568104569104570104571104572104573104574104575104576104577104578104579104580104581104582104583104584104585104586104587104588104589104590104591104592104593104594104595104596104597104598104599104600104601104602104603104604104605104606104607104608104609104610104611104612104613104614104615104616104617104618104619104620104621104622104623104624104625104626104627104628104629104630104631104632104633104634104635104636104637104638104639104640104641104642104643104644104645104646104647104648104649104650104651104652104653104654104655104656104657104658104659104660104661104662104663104664104665104666104667104668104669104670104671104672104673104674104675104676104677104678104679104680104681104682104683104684104685104686104687104688104689104690104691104692104693104694104695104696104697104698104699104700104701104702104703104704104705104706104707104708104709104710104711104712104713104714104715104716104717104718104719104720104721104722104723104724104725104726104727104728104729104730104731104732104733104734104735104736104737104738104739104740104741104742104743104744104745104746104747104748104749104750104751104752104753104754104755104756104757104758104759104760104761104762104763104764104765104766104767104768104769104770104771104772104773104774104775104776104777104778104779104780104781104782104783104784104785104786104787104788104789104790104791104792104793104794104795104796104797104798104799104800104801104802104803104804104805104806104807104808104809104810104811104812104813104814104815104816104817104818104819104820104821104822104823104824104825104826104827104828104829104830104831104832104833104834104835104836104837104838104839104840104841104842104843104844104845104846104847104848104849104850104851104852104853104854104855104856104857104858104859104860104861104862104863104864104865104866104867104868104869104870104871104872104873104874104875104876104877104878104879104880104881104882104883104884104885104886104887104888104889104890104891104892104893104894104895104896104897104898104899104900104901104902104903104904104905104906104907104908104909104910104911104912104913104914104915104916104917104918104919104920104921104922104923104924104925104926104927104928104929104930104931104932104933104934104935104936104937104938104939104940104941104942104943104944104945104946104947104948104949104950104951104952104953104954104955104956104957104958104959104960104961104962104963104964104965104966104967104968104969104970104971104972104973104974104975104976104977104978104979104980104981104982104983104984104985104986104987104988104989104990104991104992104993104994104995104996104997104998104999105000105001105002105003105004105005105006105007105008105009105010105011105012105013105014105015105016105017105018105019105020105021105022105023105024105025105026105027105028105029105030105031105032105033105034105035105036105037105038105039105040105041105042105043105044105045105046105047105048105049105050105051105052105053105054105055105056105057105058105059105060105061105062105063105064105065105066105067105068105069105070105071105072105073105074105075105076105077105078105079105080105081105082105083105084105085105086105087105088105089105090105091105092105093105094105095105096105097105098105099105100105101105102105103105104105105105106105107105108105109105110105111105112105113105114105115105116105117105118105119105120105121105122105123105124105125105126105127105128105129105130105131105132105133105134105135105136105137105138105139105140105141105142105143105144105145105146105147105148105149105150105151105152105153105154105155105156105157105158105159105160105161105162105163105164105165105166105167105168105169105170105171105172105173105174105175105176105177105178105179105180105181105182105183105184105185105186105187105188105189105190105191105192105193105194105195105196105197105198105199105200105201105202105203105204105205105206105207105208105209105210105211105212105213105214105215105216105217105218105219105220105221105222105223105224105225105226105227105228105229105230105231105232105233105234105235105236105237105238105239105240105241105242105243105244105245105246105247105248105249105250105251105252105253105254105255105256105257105258105259105260105261105262105263105264105265105266105267105268105269105270105271105272105273105274105275105276105277105278105279105280105281105282105283105284105285105286105287105288105289105290105291105292105293105294105295105296105297105298105299105300105301105302105303105304105305105306105307105308105309105310105311105312105313105314105315105316105317105318105319105320105321105322105323105324105325105326105327105328105329105330105331105332105333105334105335105336105337105338105339105340105341105342105343105344105345105346105347105348105349105350105351105352105353105354105355105356105357105358105359105360105361105362105363105364105365105366105367105368105369105370105371105372105373105374105375105376105377105378105379105380105381105382105383105384105385105386105387105388105389105390105391105392105393105394105395105396105397105398105399105400105401105402105403105404105405105406105407105408105409105410105411105412105413105414105415105416105417105418105419105420105421105422105423105424105425105426105427105428105429105430105431105432105433105434105435105436105437105438105439105440105441105442105443105444105445105446105447105448105449105450105451105452105453105454105455105456105457105458105459105460105461105462105463105464105465105466105467105468105469105470105471105472105473105474105475105476105477105478105479105480105481105482105483105484105485105486105487105488105489105490105491105492105493105494105495105496105497105498105499105500105501105502105503105504105505105506105507105508105509105510105511105512105513105514105515105516105517105518105519105520105521105522105523105524105525105526105527105528105529105530105531105532105533105534105535105536105537105538105539105540105541105542105543105544105545105546105547105548105549105550105551105552105553105554105555105556105557105558105559105560105561105562105563105564105565105566105567105568105569105570105571105572105573105574105575105576105577105578105579105580105581105582105583105584105585105586105587105588105589105590105591105592105593105594105595105596105597105598105599105600105601105602105603105604105605105606105607105608105609105610105611105612105613105614105615105616105617105618105619105620105621105622105623105624105625105626105627105628105629105630105631105632105633105634105635105636105637105638105639105640105641105642105643105644105645105646105647105648105649105650105651105652105653105654105655105656105657105658105659105660105661105662105663105664105665105666105667105668105669105670105671105672105673105674105675105676105677105678105679105680105681105682105683105684105685105686105687105688105689105690105691105692105693105694105695105696105697105698105699105700105701105702105703105704105705105706105707105708105709105710105711105712105713105714105715105716105717105718105719105720105721105722105723105724105725105726105727105728105729105730105731105732105733105734105735105736105737105738105739105740105741105742105743105744105745105746105747105748105749105750105751105752105753105754105755105756105757105758105759105760105761105762105763105764105765105766105767105768105769105770105771105772105773105774105775105776105777105778105779105780105781105782105783105784105785105786105787105788105789105790105791105792105793105794105795105796105797105798105799105800105801105802105803105804105805105806105807105808105809105810105811105812105813105814105815105816105817105818105819105820105821105822105823105824105825105826105827105828105829105830105831105832105833105834105835105836105837105838105839105840105841105842105843105844105845105846105847105848105849105850105851105852105853105854105855105856105857105858105859105860105861105862105863105864105865105866105867105868105869105870105871105872105873105874105875105876105877105878105879105880105881105882105883105884105885105886105887105888105889105890105891105892105893105894105895105896105897105898105899105900105901105902105903105904105905105906105907105908105909105910105911105912105913105914105915105916105917105918105919105920105921105922105923105924105925105926105927105928105929105930105931105932105933105934105935105936105937105938105939105940105941105942105943105944105945105946105947105948105949105950105951105952105953105954105955105956105957105958105959105960105961105962105963105964105965105966105967105968105969105970105971105972105973105974105975105976105977105978105979105980105981105982105983105984105985105986105987105988105989105990105991105992105993105994105995105996105997105998105999106000106001106002106003106004106005106006106007106008106009106010106011106012106013106014106015106016106017106018106019106020106021106022106023106024106025106026106027106028106029106030106031106032106033106034106035106036106037106038106039106040106041106042106043106044106045106046106047106048106049106050106051106052106053106054106055106056106057106058106059106060106061106062106063106064106065106066106067106068106069106070106071106072106073106074106075106076106077106078106079106080106081106082106083106084106085106086106087106088106089106090106091106092106093106094106095106096106097106098106099106100106101106102106103106104106105106106106107106108106109106110106111106112106113106114106115106116106117106118106119106120106121106122106123106124106125106126106127106128106129106130106131106132106133106134106135106136106137106138106139106140106141106142106143106144106145106146106147106148106149106150106151106152106153106154106155106156106157106158106159106160106161106162106163106164106165106166106167106168106169106170106171106172106173106174106175106176106177106178106179106180106181106182106183106184106185106186106187106188106189106190106191106192106193106194106195106196106197106198106199106200106201106202106203106204106205106206106207106208106209106210106211106212106213106214106215106216106217106218106219106220106221106222106223106224106225106226106227106228106229106230106231106232106233106234106235106236106237106238106239106240106241106242106243106244106245106246106247106248106249106250106251106252106253106254106255106256106257106258106259106260106261106262106263106264106265106266106267106268106269106270106271106272106273106274106275106276106277106278106279106280106281106282106283106284106285106286106287106288106289106290106291106292106293106294106295106296106297106298106299106300106301106302106303106304106305106306106307106308106309106310106311106312106313106314106315106316106317106318106319106320106321106322106323106324106325106326106327106328106329106330106331106332106333106334106335106336106337106338106339106340106341106342106343106344106345106346106347106348106349106350106351106352106353106354106355106356106357106358106359106360106361106362106363106364106365106366106367106368106369106370106371106372106373106374106375106376106377106378106379106380106381106382106383106384106385106386106387106388106389106390106391106392106393106394106395106396106397106398106399106400106401106402106403106404106405106406106407106408106409106410106411106412106413106414106415106416106417106418106419106420106421106422106423106424106425106426106427106428106429106430106431106432106433106434106435106436106437106438106439106440106441106442106443106444106445106446106447106448106449106450106451106452106453106454106455106456106457106458106459106460106461106462106463106464106465106466106467106468106469106470106471106472106473106474106475106476106477106478106479106480106481106482106483106484106485106486106487106488106489106490106491106492106493106494106495106496106497106498106499106500106501106502106503106504106505106506106507106508106509106510106511106512106513106514106515106516106517106518106519106520106521106522106523106524106525106526106527106528106529106530106531106532106533106534106535106536106537106538106539106540106541106542106543106544106545106546106547106548106549106550106551106552106553106554106555106556106557106558106559106560106561106562106563106564106565106566106567106568106569106570106571106572106573106574106575106576106577106578106579106580106581106582106583106584106585106586106587106588106589106590106591106592106593106594106595106596106597106598106599106600106601106602106603106604106605106606106607106608106609106610106611106612106613106614106615106616106617106618106619106620106621106622106623106624106625106626106627106628106629106630106631106632106633106634106635106636106637106638106639106640106641106642106643106644106645106646106647106648106649106650106651106652106653106654106655106656106657106658106659106660106661106662106663106664106665106666106667106668106669106670106671106672106673106674106675106676106677106678106679106680106681106682106683106684106685106686106687106688
  1. diff -Nur linux-3.12.18/arch/arc/boot/dts/nsimosci.dts linux-rpi/arch/arc/boot/dts/nsimosci.dts
  2. --- linux-3.12.18/arch/arc/boot/dts/nsimosci.dts 2014-04-18 11:14:28.000000000 +0200
  3. +++ linux-rpi/arch/arc/boot/dts/nsimosci.dts 2014-04-24 16:04:29.363023127 +0200
  4. @@ -11,16 +11,13 @@
  5. / {
  6. compatible = "snps,nsimosci";
  7. - clock-frequency = <20000000>; /* 20 MHZ */
  8. + clock-frequency = <80000000>; /* 80 MHZ */
  9. #address-cells = <1>;
  10. #size-cells = <1>;
  11. interrupt-parent = <&intc>;
  12. chosen {
  13. - /* this is for console on PGU */
  14. - /* bootargs = "console=tty0 consoleblank=0"; */
  15. - /* this is for console on serial */
  16. - bootargs = "earlycon=uart8250,mmio32,0xc0000000,115200n8 console=ttyS0,115200n8 consoleblank=0 debug";
  17. + bootargs = "console=tty0 consoleblank=0";
  18. };
  19. aliases {
  20. @@ -47,14 +44,15 @@
  21. };
  22. uart0: serial@c0000000 {
  23. - compatible = "ns8250";
  24. + compatible = "snps,dw-apb-uart";
  25. reg = <0xc0000000 0x2000>;
  26. interrupts = <11>;
  27. + #clock-frequency = <80000000>;
  28. clock-frequency = <3686400>;
  29. baud = <115200>;
  30. reg-shift = <2>;
  31. reg-io-width = <4>;
  32. - no-loopback-test = <1>;
  33. + status = "okay";
  34. };
  35. pgu0: pgu@c9000000 {
  36. diff -Nur linux-3.12.18/arch/arc/configs/nsimosci_defconfig linux-rpi/arch/arc/configs/nsimosci_defconfig
  37. --- linux-3.12.18/arch/arc/configs/nsimosci_defconfig 2014-04-18 11:14:28.000000000 +0200
  38. +++ linux-rpi/arch/arc/configs/nsimosci_defconfig 2014-04-24 16:04:29.363023127 +0200
  39. @@ -54,7 +54,6 @@
  40. CONFIG_SERIAL_8250=y
  41. CONFIG_SERIAL_8250_CONSOLE=y
  42. CONFIG_SERIAL_8250_DW=y
  43. -CONFIG_SERIAL_OF_PLATFORM=y
  44. CONFIG_SERIAL_ARC=y
  45. CONFIG_SERIAL_ARC_CONSOLE=y
  46. # CONFIG_HW_RANDOM is not set
  47. diff -Nur linux-3.12.18/arch/arm/configs/bcmrpi_cutdown_defconfig linux-rpi/arch/arm/configs/bcmrpi_cutdown_defconfig
  48. --- linux-3.12.18/arch/arm/configs/bcmrpi_cutdown_defconfig 1970-01-01 01:00:00.000000000 +0100
  49. +++ linux-rpi/arch/arm/configs/bcmrpi_cutdown_defconfig 2014-04-24 16:04:30.011029397 +0200
  50. @@ -0,0 +1,503 @@
  51. +CONFIG_EXPERIMENTAL=y
  52. +# CONFIG_LOCALVERSION_AUTO is not set
  53. +CONFIG_SYSVIPC=y
  54. +CONFIG_POSIX_MQUEUE=y
  55. +CONFIG_IKCONFIG=y
  56. +CONFIG_IKCONFIG_PROC=y
  57. +# CONFIG_UID16 is not set
  58. +# CONFIG_KALLSYMS is not set
  59. +CONFIG_EMBEDDED=y
  60. +# CONFIG_VM_EVENT_COUNTERS is not set
  61. +# CONFIG_COMPAT_BRK is not set
  62. +CONFIG_SLAB=y
  63. +CONFIG_MODULES=y
  64. +CONFIG_MODULE_UNLOAD=y
  65. +CONFIG_MODVERSIONS=y
  66. +CONFIG_MODULE_SRCVERSION_ALL=y
  67. +# CONFIG_BLK_DEV_BSG is not set
  68. +CONFIG_ARCH_BCM2708=y
  69. +CONFIG_NO_HZ=y
  70. +CONFIG_HIGH_RES_TIMERS=y
  71. +CONFIG_AEABI=y
  72. +CONFIG_ZBOOT_ROM_TEXT=0x0
  73. +CONFIG_ZBOOT_ROM_BSS=0x0
  74. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  75. +CONFIG_CPU_IDLE=y
  76. +CONFIG_VFP=y
  77. +CONFIG_BINFMT_MISC=m
  78. +CONFIG_NET=y
  79. +CONFIG_PACKET=y
  80. +CONFIG_UNIX=y
  81. +CONFIG_XFRM_USER=y
  82. +CONFIG_NET_KEY=m
  83. +CONFIG_INET=y
  84. +CONFIG_IP_MULTICAST=y
  85. +CONFIG_IP_PNP=y
  86. +CONFIG_IP_PNP_DHCP=y
  87. +CONFIG_IP_PNP_RARP=y
  88. +CONFIG_SYN_COOKIES=y
  89. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  90. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  91. +# CONFIG_INET_XFRM_MODE_BEET is not set
  92. +# CONFIG_INET_LRO is not set
  93. +# CONFIG_INET_DIAG is not set
  94. +# CONFIG_IPV6 is not set
  95. +CONFIG_NET_PKTGEN=m
  96. +CONFIG_IRDA=m
  97. +CONFIG_IRLAN=m
  98. +CONFIG_IRCOMM=m
  99. +CONFIG_IRDA_ULTRA=y
  100. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  101. +CONFIG_IRDA_FAST_RR=y
  102. +CONFIG_IRTTY_SIR=m
  103. +CONFIG_KINGSUN_DONGLE=m
  104. +CONFIG_KSDAZZLE_DONGLE=m
  105. +CONFIG_KS959_DONGLE=m
  106. +CONFIG_USB_IRDA=m
  107. +CONFIG_SIGMATEL_FIR=m
  108. +CONFIG_MCS_FIR=m
  109. +CONFIG_BT=m
  110. +CONFIG_BT_L2CAP=y
  111. +CONFIG_BT_SCO=y
  112. +CONFIG_BT_RFCOMM=m
  113. +CONFIG_BT_RFCOMM_TTY=y
  114. +CONFIG_BT_BNEP=m
  115. +CONFIG_BT_BNEP_MC_FILTER=y
  116. +CONFIG_BT_BNEP_PROTO_FILTER=y
  117. +CONFIG_BT_HIDP=m
  118. +CONFIG_BT_HCIBTUSB=m
  119. +CONFIG_BT_HCIBCM203X=m
  120. +CONFIG_BT_HCIBPA10X=m
  121. +CONFIG_BT_HCIBFUSB=m
  122. +CONFIG_BT_HCIVHCI=m
  123. +CONFIG_BT_MRVL=m
  124. +CONFIG_BT_MRVL_SDIO=m
  125. +CONFIG_BT_ATH3K=m
  126. +CONFIG_CFG80211=m
  127. +CONFIG_MAC80211=m
  128. +CONFIG_MAC80211_RC_PID=y
  129. +CONFIG_MAC80211_MESH=y
  130. +CONFIG_WIMAX=m
  131. +CONFIG_NET_9P=m
  132. +CONFIG_NFC=m
  133. +CONFIG_NFC_PN533=m
  134. +CONFIG_DEVTMPFS=y
  135. +CONFIG_BLK_DEV_LOOP=y
  136. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  137. +CONFIG_BLK_DEV_NBD=m
  138. +CONFIG_BLK_DEV_RAM=y
  139. +CONFIG_CDROM_PKTCDVD=m
  140. +CONFIG_MISC_DEVICES=y
  141. +CONFIG_SCSI=y
  142. +# CONFIG_SCSI_PROC_FS is not set
  143. +CONFIG_BLK_DEV_SD=m
  144. +CONFIG_BLK_DEV_SR=m
  145. +CONFIG_SCSI_MULTI_LUN=y
  146. +# CONFIG_SCSI_LOWLEVEL is not set
  147. +CONFIG_NETDEVICES=y
  148. +CONFIG_TUN=m
  149. +CONFIG_PHYLIB=m
  150. +CONFIG_MDIO_BITBANG=m
  151. +CONFIG_NET_ETHERNET=y
  152. +# CONFIG_NETDEV_1000 is not set
  153. +# CONFIG_NETDEV_10000 is not set
  154. +CONFIG_LIBERTAS_THINFIRM=m
  155. +CONFIG_LIBERTAS_THINFIRM_USB=m
  156. +CONFIG_AT76C50X_USB=m
  157. +CONFIG_USB_ZD1201=m
  158. +CONFIG_USB_NET_RNDIS_WLAN=m
  159. +CONFIG_RTL8187=m
  160. +CONFIG_MAC80211_HWSIM=m
  161. +CONFIG_ATH_COMMON=m
  162. +CONFIG_ATH9K=m
  163. +CONFIG_ATH9K_HTC=m
  164. +CONFIG_CARL9170=m
  165. +CONFIG_B43=m
  166. +CONFIG_B43LEGACY=m
  167. +CONFIG_HOSTAP=m
  168. +CONFIG_IWM=m
  169. +CONFIG_LIBERTAS=m
  170. +CONFIG_LIBERTAS_USB=m
  171. +CONFIG_LIBERTAS_SDIO=m
  172. +CONFIG_P54_COMMON=m
  173. +CONFIG_P54_USB=m
  174. +CONFIG_RT2X00=m
  175. +CONFIG_RT2500USB=m
  176. +CONFIG_RT73USB=m
  177. +CONFIG_RT2800USB=m
  178. +CONFIG_RT2800USB_RT53XX=y
  179. +CONFIG_RTL8192CU=m
  180. +CONFIG_WL1251=m
  181. +CONFIG_WL12XX_MENU=m
  182. +CONFIG_ZD1211RW=m
  183. +CONFIG_MWIFIEX=m
  184. +CONFIG_MWIFIEX_SDIO=m
  185. +CONFIG_WIMAX_I2400M_USB=m
  186. +CONFIG_USB_CATC=m
  187. +CONFIG_USB_KAWETH=m
  188. +CONFIG_USB_PEGASUS=m
  189. +CONFIG_USB_RTL8150=m
  190. +CONFIG_USB_USBNET=y
  191. +CONFIG_USB_NET_AX8817X=m
  192. +CONFIG_USB_NET_CDCETHER=m
  193. +CONFIG_USB_NET_CDC_EEM=m
  194. +CONFIG_USB_NET_DM9601=m
  195. +CONFIG_USB_NET_SMSC75XX=m
  196. +CONFIG_USB_NET_SMSC95XX=y
  197. +CONFIG_USB_NET_GL620A=m
  198. +CONFIG_USB_NET_NET1080=m
  199. +CONFIG_USB_NET_PLUSB=m
  200. +CONFIG_USB_NET_MCS7830=m
  201. +CONFIG_USB_NET_CDC_SUBSET=m
  202. +CONFIG_USB_ALI_M5632=y
  203. +CONFIG_USB_AN2720=y
  204. +CONFIG_USB_KC2190=y
  205. +# CONFIG_USB_NET_ZAURUS is not set
  206. +CONFIG_USB_NET_CX82310_ETH=m
  207. +CONFIG_USB_NET_KALMIA=m
  208. +CONFIG_USB_NET_INT51X1=m
  209. +CONFIG_USB_IPHETH=m
  210. +CONFIG_USB_SIERRA_NET=m
  211. +CONFIG_USB_VL600=m
  212. +CONFIG_PPP=m
  213. +CONFIG_PPP_ASYNC=m
  214. +CONFIG_PPP_SYNC_TTY=m
  215. +CONFIG_PPP_DEFLATE=m
  216. +CONFIG_PPP_BSDCOMP=m
  217. +CONFIG_SLIP=m
  218. +CONFIG_SLIP_COMPRESSED=y
  219. +CONFIG_NETCONSOLE=m
  220. +CONFIG_INPUT_POLLDEV=m
  221. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  222. +CONFIG_INPUT_JOYDEV=m
  223. +CONFIG_INPUT_EVDEV=m
  224. +# CONFIG_INPUT_KEYBOARD is not set
  225. +# CONFIG_INPUT_MOUSE is not set
  226. +CONFIG_INPUT_MISC=y
  227. +CONFIG_INPUT_AD714X=m
  228. +CONFIG_INPUT_ATI_REMOTE=m
  229. +CONFIG_INPUT_ATI_REMOTE2=m
  230. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  231. +CONFIG_INPUT_POWERMATE=m
  232. +CONFIG_INPUT_YEALINK=m
  233. +CONFIG_INPUT_CM109=m
  234. +CONFIG_INPUT_UINPUT=m
  235. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  236. +CONFIG_INPUT_ADXL34X=m
  237. +CONFIG_INPUT_CMA3000=m
  238. +CONFIG_SERIO=m
  239. +CONFIG_SERIO_RAW=m
  240. +CONFIG_GAMEPORT=m
  241. +CONFIG_GAMEPORT_NS558=m
  242. +CONFIG_GAMEPORT_L4=m
  243. +CONFIG_VT_HW_CONSOLE_BINDING=y
  244. +# CONFIG_LEGACY_PTYS is not set
  245. +# CONFIG_DEVKMEM is not set
  246. +CONFIG_SERIAL_AMBA_PL011=y
  247. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  248. +# CONFIG_HW_RANDOM is not set
  249. +CONFIG_RAW_DRIVER=y
  250. +CONFIG_GPIO_SYSFS=y
  251. +# CONFIG_HWMON is not set
  252. +CONFIG_WATCHDOG=y
  253. +CONFIG_BCM2708_WDT=m
  254. +# CONFIG_MFD_SUPPORT is not set
  255. +CONFIG_FB=y
  256. +CONFIG_FB_BCM2708=y
  257. +CONFIG_FRAMEBUFFER_CONSOLE=y
  258. +CONFIG_LOGO=y
  259. +# CONFIG_LOGO_LINUX_MONO is not set
  260. +# CONFIG_LOGO_LINUX_VGA16 is not set
  261. +CONFIG_SOUND=y
  262. +CONFIG_SND=m
  263. +CONFIG_SND_SEQUENCER=m
  264. +CONFIG_SND_SEQ_DUMMY=m
  265. +CONFIG_SND_MIXER_OSS=m
  266. +CONFIG_SND_PCM_OSS=m
  267. +CONFIG_SND_SEQUENCER_OSS=y
  268. +CONFIG_SND_HRTIMER=m
  269. +CONFIG_SND_DUMMY=m
  270. +CONFIG_SND_ALOOP=m
  271. +CONFIG_SND_VIRMIDI=m
  272. +CONFIG_SND_MTPAV=m
  273. +CONFIG_SND_SERIAL_U16550=m
  274. +CONFIG_SND_MPU401=m
  275. +CONFIG_SND_BCM2835=m
  276. +CONFIG_SND_USB_AUDIO=m
  277. +CONFIG_SND_USB_UA101=m
  278. +CONFIG_SND_USB_CAIAQ=m
  279. +CONFIG_SND_USB_6FIRE=m
  280. +CONFIG_SOUND_PRIME=m
  281. +CONFIG_HID_PID=y
  282. +CONFIG_USB_HIDDEV=y
  283. +CONFIG_HID_A4TECH=m
  284. +CONFIG_HID_ACRUX=m
  285. +CONFIG_HID_APPLE=m
  286. +CONFIG_HID_BELKIN=m
  287. +CONFIG_HID_CHERRY=m
  288. +CONFIG_HID_CHICONY=m
  289. +CONFIG_HID_CYPRESS=m
  290. +CONFIG_HID_DRAGONRISE=m
  291. +CONFIG_HID_EMS_FF=m
  292. +CONFIG_HID_ELECOM=m
  293. +CONFIG_HID_EZKEY=m
  294. +CONFIG_HID_HOLTEK=m
  295. +CONFIG_HID_KEYTOUCH=m
  296. +CONFIG_HID_KYE=m
  297. +CONFIG_HID_UCLOGIC=m
  298. +CONFIG_HID_WALTOP=m
  299. +CONFIG_HID_GYRATION=m
  300. +CONFIG_HID_TWINHAN=m
  301. +CONFIG_HID_KENSINGTON=m
  302. +CONFIG_HID_LCPOWER=m
  303. +CONFIG_HID_LOGITECH=m
  304. +CONFIG_HID_MAGICMOUSE=m
  305. +CONFIG_HID_MICROSOFT=m
  306. +CONFIG_HID_MONTEREY=m
  307. +CONFIG_HID_MULTITOUCH=m
  308. +CONFIG_HID_NTRIG=m
  309. +CONFIG_HID_ORTEK=m
  310. +CONFIG_HID_PANTHERLORD=m
  311. +CONFIG_HID_PETALYNX=m
  312. +CONFIG_HID_PICOLCD=m
  313. +CONFIG_HID_QUANTA=m
  314. +CONFIG_HID_ROCCAT=m
  315. +CONFIG_HID_SAMSUNG=m
  316. +CONFIG_HID_SONY=m
  317. +CONFIG_HID_SPEEDLINK=m
  318. +CONFIG_HID_SUNPLUS=m
  319. +CONFIG_HID_GREENASIA=m
  320. +CONFIG_HID_SMARTJOYPLUS=m
  321. +CONFIG_HID_TOPSEED=m
  322. +CONFIG_HID_THRUSTMASTER=m
  323. +CONFIG_HID_WACOM=m
  324. +CONFIG_HID_WIIMOTE=m
  325. +CONFIG_HID_ZEROPLUS=m
  326. +CONFIG_HID_ZYDACRON=m
  327. +CONFIG_USB=y
  328. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  329. +CONFIG_USB_MON=m
  330. +CONFIG_USB_DWCOTG=y
  331. +CONFIG_USB_STORAGE=y
  332. +CONFIG_USB_STORAGE_REALTEK=m
  333. +CONFIG_USB_STORAGE_DATAFAB=m
  334. +CONFIG_USB_STORAGE_FREECOM=m
  335. +CONFIG_USB_STORAGE_ISD200=m
  336. +CONFIG_USB_STORAGE_USBAT=m
  337. +CONFIG_USB_STORAGE_SDDR09=m
  338. +CONFIG_USB_STORAGE_SDDR55=m
  339. +CONFIG_USB_STORAGE_JUMPSHOT=m
  340. +CONFIG_USB_STORAGE_ALAUDA=m
  341. +CONFIG_USB_STORAGE_ONETOUCH=m
  342. +CONFIG_USB_STORAGE_KARMA=m
  343. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  344. +CONFIG_USB_STORAGE_ENE_UB6250=m
  345. +CONFIG_USB_UAS=m
  346. +CONFIG_USB_LIBUSUAL=y
  347. +CONFIG_USB_MDC800=m
  348. +CONFIG_USB_MICROTEK=m
  349. +CONFIG_USB_SERIAL=m
  350. +CONFIG_USB_SERIAL_GENERIC=y
  351. +CONFIG_USB_SERIAL_AIRCABLE=m
  352. +CONFIG_USB_SERIAL_ARK3116=m
  353. +CONFIG_USB_SERIAL_BELKIN=m
  354. +CONFIG_USB_SERIAL_CH341=m
  355. +CONFIG_USB_SERIAL_WHITEHEAT=m
  356. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  357. +CONFIG_USB_SERIAL_CP210X=m
  358. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  359. +CONFIG_USB_SERIAL_EMPEG=m
  360. +CONFIG_USB_SERIAL_FTDI_SIO=m
  361. +CONFIG_USB_SERIAL_FUNSOFT=m
  362. +CONFIG_USB_SERIAL_VISOR=m
  363. +CONFIG_USB_SERIAL_IPAQ=m
  364. +CONFIG_USB_SERIAL_IR=m
  365. +CONFIG_USB_SERIAL_EDGEPORT=m
  366. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  367. +CONFIG_USB_SERIAL_GARMIN=m
  368. +CONFIG_USB_SERIAL_IPW=m
  369. +CONFIG_USB_SERIAL_IUU=m
  370. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  371. +CONFIG_USB_SERIAL_KEYSPAN=m
  372. +CONFIG_USB_SERIAL_KLSI=m
  373. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  374. +CONFIG_USB_SERIAL_MCT_U232=m
  375. +CONFIG_USB_SERIAL_MOS7720=m
  376. +CONFIG_USB_SERIAL_MOS7840=m
  377. +CONFIG_USB_SERIAL_MOTOROLA=m
  378. +CONFIG_USB_SERIAL_NAVMAN=m
  379. +CONFIG_USB_SERIAL_PL2303=m
  380. +CONFIG_USB_SERIAL_OTI6858=m
  381. +CONFIG_USB_SERIAL_QCAUX=m
  382. +CONFIG_USB_SERIAL_QUALCOMM=m
  383. +CONFIG_USB_SERIAL_SPCP8X5=m
  384. +CONFIG_USB_SERIAL_HP4X=m
  385. +CONFIG_USB_SERIAL_SAFE=m
  386. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  387. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  388. +CONFIG_USB_SERIAL_SYMBOL=m
  389. +CONFIG_USB_SERIAL_TI=m
  390. +CONFIG_USB_SERIAL_CYBERJACK=m
  391. +CONFIG_USB_SERIAL_XIRCOM=m
  392. +CONFIG_USB_SERIAL_OPTION=m
  393. +CONFIG_USB_SERIAL_OMNINET=m
  394. +CONFIG_USB_SERIAL_OPTICON=m
  395. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  396. +CONFIG_USB_SERIAL_ZIO=m
  397. +CONFIG_USB_SERIAL_SSU100=m
  398. +CONFIG_USB_SERIAL_DEBUG=m
  399. +CONFIG_USB_EMI62=m
  400. +CONFIG_USB_EMI26=m
  401. +CONFIG_USB_ADUTUX=m
  402. +CONFIG_USB_SEVSEG=m
  403. +CONFIG_USB_RIO500=m
  404. +CONFIG_USB_LEGOTOWER=m
  405. +CONFIG_USB_LCD=m
  406. +CONFIG_USB_LED=m
  407. +CONFIG_USB_CYPRESS_CY7C63=m
  408. +CONFIG_USB_CYTHERM=m
  409. +CONFIG_USB_IDMOUSE=m
  410. +CONFIG_USB_FTDI_ELAN=m
  411. +CONFIG_USB_APPLEDISPLAY=m
  412. +CONFIG_USB_LD=m
  413. +CONFIG_USB_TRANCEVIBRATOR=m
  414. +CONFIG_USB_IOWARRIOR=m
  415. +CONFIG_USB_TEST=m
  416. +CONFIG_USB_ISIGHTFW=m
  417. +CONFIG_USB_YUREX=m
  418. +CONFIG_MMC=y
  419. +CONFIG_MMC_SDHCI=y
  420. +CONFIG_MMC_SDHCI_PLTFM=y
  421. +CONFIG_MMC_SDHCI_BCM2708=y
  422. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  423. +CONFIG_LEDS_GPIO=y
  424. +CONFIG_LEDS_TRIGGER_TIMER=m
  425. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  426. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  427. +CONFIG_UIO=m
  428. +CONFIG_UIO_PDRV=m
  429. +CONFIG_UIO_PDRV_GENIRQ=m
  430. +# CONFIG_IOMMU_SUPPORT is not set
  431. +CONFIG_EXT4_FS=y
  432. +CONFIG_EXT4_FS_POSIX_ACL=y
  433. +CONFIG_EXT4_FS_SECURITY=y
  434. +CONFIG_REISERFS_FS=m
  435. +CONFIG_REISERFS_FS_XATTR=y
  436. +CONFIG_REISERFS_FS_POSIX_ACL=y
  437. +CONFIG_REISERFS_FS_SECURITY=y
  438. +CONFIG_JFS_FS=m
  439. +CONFIG_JFS_POSIX_ACL=y
  440. +CONFIG_JFS_SECURITY=y
  441. +CONFIG_XFS_FS=m
  442. +CONFIG_XFS_QUOTA=y
  443. +CONFIG_XFS_POSIX_ACL=y
  444. +CONFIG_XFS_RT=y
  445. +CONFIG_GFS2_FS=m
  446. +CONFIG_OCFS2_FS=m
  447. +CONFIG_BTRFS_FS=m
  448. +CONFIG_BTRFS_FS_POSIX_ACL=y
  449. +CONFIG_NILFS2_FS=m
  450. +CONFIG_AUTOFS4_FS=y
  451. +CONFIG_FUSE_FS=m
  452. +CONFIG_CUSE=m
  453. +CONFIG_FSCACHE=y
  454. +CONFIG_CACHEFILES=y
  455. +CONFIG_ISO9660_FS=m
  456. +CONFIG_JOLIET=y
  457. +CONFIG_ZISOFS=y
  458. +CONFIG_UDF_FS=m
  459. +CONFIG_MSDOS_FS=y
  460. +CONFIG_VFAT_FS=y
  461. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  462. +CONFIG_NTFS_FS=m
  463. +CONFIG_TMPFS=y
  464. +CONFIG_TMPFS_POSIX_ACL=y
  465. +CONFIG_CONFIGFS_FS=y
  466. +CONFIG_SQUASHFS=m
  467. +CONFIG_SQUASHFS_XATTR=y
  468. +CONFIG_SQUASHFS_LZO=y
  469. +CONFIG_SQUASHFS_XZ=y
  470. +CONFIG_NFS_FS=y
  471. +CONFIG_NFS_V3=y
  472. +CONFIG_NFS_V3_ACL=y
  473. +CONFIG_NFS_V4=y
  474. +CONFIG_ROOT_NFS=y
  475. +CONFIG_NFS_FSCACHE=y
  476. +CONFIG_CIFS=m
  477. +CONFIG_CIFS_WEAK_PW_HASH=y
  478. +CONFIG_CIFS_XATTR=y
  479. +CONFIG_CIFS_POSIX=y
  480. +CONFIG_9P_FS=m
  481. +CONFIG_PARTITION_ADVANCED=y
  482. +CONFIG_MAC_PARTITION=y
  483. +CONFIG_EFI_PARTITION=y
  484. +CONFIG_NLS_DEFAULT="utf8"
  485. +CONFIG_NLS_CODEPAGE_437=y
  486. +CONFIG_NLS_CODEPAGE_737=m
  487. +CONFIG_NLS_CODEPAGE_775=m
  488. +CONFIG_NLS_CODEPAGE_850=m
  489. +CONFIG_NLS_CODEPAGE_852=m
  490. +CONFIG_NLS_CODEPAGE_855=m
  491. +CONFIG_NLS_CODEPAGE_857=m
  492. +CONFIG_NLS_CODEPAGE_860=m
  493. +CONFIG_NLS_CODEPAGE_861=m
  494. +CONFIG_NLS_CODEPAGE_862=m
  495. +CONFIG_NLS_CODEPAGE_863=m
  496. +CONFIG_NLS_CODEPAGE_864=m
  497. +CONFIG_NLS_CODEPAGE_865=m
  498. +CONFIG_NLS_CODEPAGE_866=m
  499. +CONFIG_NLS_CODEPAGE_869=m
  500. +CONFIG_NLS_CODEPAGE_936=m
  501. +CONFIG_NLS_CODEPAGE_950=m
  502. +CONFIG_NLS_CODEPAGE_932=m
  503. +CONFIG_NLS_CODEPAGE_949=m
  504. +CONFIG_NLS_CODEPAGE_874=m
  505. +CONFIG_NLS_ISO8859_8=m
  506. +CONFIG_NLS_CODEPAGE_1250=m
  507. +CONFIG_NLS_CODEPAGE_1251=m
  508. +CONFIG_NLS_ASCII=y
  509. +CONFIG_NLS_ISO8859_1=m
  510. +CONFIG_NLS_ISO8859_2=m
  511. +CONFIG_NLS_ISO8859_3=m
  512. +CONFIG_NLS_ISO8859_4=m
  513. +CONFIG_NLS_ISO8859_5=m
  514. +CONFIG_NLS_ISO8859_6=m
  515. +CONFIG_NLS_ISO8859_7=m
  516. +CONFIG_NLS_ISO8859_9=m
  517. +CONFIG_NLS_ISO8859_13=m
  518. +CONFIG_NLS_ISO8859_14=m
  519. +CONFIG_NLS_ISO8859_15=m
  520. +CONFIG_NLS_KOI8_R=m
  521. +CONFIG_NLS_KOI8_U=m
  522. +CONFIG_NLS_UTF8=m
  523. +# CONFIG_SCHED_DEBUG is not set
  524. +# CONFIG_DEBUG_BUGVERBOSE is not set
  525. +# CONFIG_FTRACE is not set
  526. +# CONFIG_ARM_UNWIND is not set
  527. +CONFIG_CRYPTO_AUTHENC=m
  528. +CONFIG_CRYPTO_SEQIV=m
  529. +CONFIG_CRYPTO_CBC=y
  530. +CONFIG_CRYPTO_HMAC=y
  531. +CONFIG_CRYPTO_XCBC=m
  532. +CONFIG_CRYPTO_MD5=y
  533. +CONFIG_CRYPTO_SHA1=y
  534. +CONFIG_CRYPTO_SHA256=m
  535. +CONFIG_CRYPTO_SHA512=m
  536. +CONFIG_CRYPTO_TGR192=m
  537. +CONFIG_CRYPTO_WP512=m
  538. +CONFIG_CRYPTO_CAST5=m
  539. +CONFIG_CRYPTO_DES=y
  540. +CONFIG_CRYPTO_DEFLATE=m
  541. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  542. +# CONFIG_CRYPTO_HW is not set
  543. +CONFIG_CRC_ITU_T=y
  544. +CONFIG_LIBCRC32C=y
  545. +CONFIG_I2C=y
  546. +CONFIG_I2C_BOARDINFO=y
  547. +CONFIG_I2C_COMPAT=y
  548. +CONFIG_I2C_CHARDEV=m
  549. +CONFIG_I2C_HELPER_AUTO=y
  550. +CONFIG_I2C_BCM2708=m
  551. +CONFIG_SPI=y
  552. +CONFIG_SPI_MASTER=y
  553. +CONFIG_SPI_BCM2708=m
  554. diff -Nur linux-3.12.18/arch/arm/configs/bcmrpi_defconfig linux-rpi/arch/arm/configs/bcmrpi_defconfig
  555. --- linux-3.12.18/arch/arm/configs/bcmrpi_defconfig 1970-01-01 01:00:00.000000000 +0100
  556. +++ linux-rpi/arch/arm/configs/bcmrpi_defconfig 2014-04-24 16:04:30.011029397 +0200
  557. @@ -0,0 +1,1097 @@
  558. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  559. +# CONFIG_LOCALVERSION_AUTO is not set
  560. +CONFIG_SYSVIPC=y
  561. +CONFIG_POSIX_MQUEUE=y
  562. +CONFIG_FHANDLE=y
  563. +CONFIG_AUDIT=y
  564. +CONFIG_NO_HZ=y
  565. +CONFIG_HIGH_RES_TIMERS=y
  566. +CONFIG_BSD_PROCESS_ACCT=y
  567. +CONFIG_BSD_PROCESS_ACCT_V3=y
  568. +CONFIG_TASKSTATS=y
  569. +CONFIG_TASK_DELAY_ACCT=y
  570. +CONFIG_TASK_XACCT=y
  571. +CONFIG_TASK_IO_ACCOUNTING=y
  572. +CONFIG_IKCONFIG=y
  573. +CONFIG_IKCONFIG_PROC=y
  574. +CONFIG_CGROUP_FREEZER=y
  575. +CONFIG_CGROUP_DEVICE=y
  576. +CONFIG_CGROUP_CPUACCT=y
  577. +CONFIG_RESOURCE_COUNTERS=y
  578. +CONFIG_MEMCG=y
  579. +CONFIG_BLK_CGROUP=y
  580. +CONFIG_NAMESPACES=y
  581. +CONFIG_SCHED_AUTOGROUP=y
  582. +CONFIG_RELAY=y
  583. +CONFIG_BLK_DEV_INITRD=y
  584. +CONFIG_EMBEDDED=y
  585. +# CONFIG_COMPAT_BRK is not set
  586. +CONFIG_PROFILING=y
  587. +CONFIG_OPROFILE=m
  588. +CONFIG_KPROBES=y
  589. +CONFIG_JUMP_LABEL=y
  590. +CONFIG_MODULES=y
  591. +CONFIG_MODULE_UNLOAD=y
  592. +CONFIG_MODVERSIONS=y
  593. +CONFIG_MODULE_SRCVERSION_ALL=y
  594. +CONFIG_BLK_DEV_THROTTLING=y
  595. +CONFIG_PARTITION_ADVANCED=y
  596. +CONFIG_MAC_PARTITION=y
  597. +CONFIG_CFQ_GROUP_IOSCHED=y
  598. +CONFIG_ARCH_BCM2708=y
  599. +CONFIG_PREEMPT=y
  600. +CONFIG_AEABI=y
  601. +CONFIG_CLEANCACHE=y
  602. +CONFIG_FRONTSWAP=y
  603. +CONFIG_CMA=y
  604. +CONFIG_UACCESS_WITH_MEMCPY=y
  605. +CONFIG_SECCOMP=y
  606. +CONFIG_CC_STACKPROTECTOR=y
  607. +CONFIG_ZBOOT_ROM_TEXT=0x0
  608. +CONFIG_ZBOOT_ROM_BSS=0x0
  609. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  610. +CONFIG_KEXEC=y
  611. +CONFIG_CPU_FREQ=y
  612. +CONFIG_CPU_FREQ_STAT=m
  613. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  614. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  615. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  616. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  617. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  618. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  619. +CONFIG_CPU_IDLE=y
  620. +CONFIG_VFP=y
  621. +CONFIG_BINFMT_MISC=m
  622. +CONFIG_NET=y
  623. +CONFIG_PACKET=y
  624. +CONFIG_UNIX=y
  625. +CONFIG_XFRM_USER=y
  626. +CONFIG_NET_KEY=m
  627. +CONFIG_INET=y
  628. +CONFIG_IP_MULTICAST=y
  629. +CONFIG_IP_ADVANCED_ROUTER=y
  630. +CONFIG_IP_MULTIPLE_TABLES=y
  631. +CONFIG_IP_ROUTE_MULTIPATH=y
  632. +CONFIG_IP_ROUTE_VERBOSE=y
  633. +CONFIG_IP_PNP=y
  634. +CONFIG_IP_PNP_DHCP=y
  635. +CONFIG_IP_PNP_RARP=y
  636. +CONFIG_NET_IPIP=m
  637. +CONFIG_NET_IPGRE_DEMUX=m
  638. +CONFIG_NET_IPGRE=m
  639. +CONFIG_IP_MROUTE=y
  640. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  641. +CONFIG_IP_PIMSM_V1=y
  642. +CONFIG_IP_PIMSM_V2=y
  643. +CONFIG_SYN_COOKIES=y
  644. +CONFIG_INET_AH=m
  645. +CONFIG_INET_ESP=m
  646. +CONFIG_INET_IPCOMP=m
  647. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  648. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  649. +CONFIG_INET_XFRM_MODE_BEET=m
  650. +CONFIG_INET_LRO=m
  651. +CONFIG_INET_DIAG=m
  652. +CONFIG_INET6_AH=m
  653. +CONFIG_INET6_ESP=m
  654. +CONFIG_INET6_IPCOMP=m
  655. +CONFIG_IPV6_TUNNEL=m
  656. +CONFIG_IPV6_MULTIPLE_TABLES=y
  657. +CONFIG_IPV6_MROUTE=y
  658. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  659. +CONFIG_IPV6_PIMSM_V2=y
  660. +CONFIG_NETFILTER=y
  661. +CONFIG_NF_CONNTRACK=m
  662. +CONFIG_NF_CONNTRACK_ZONES=y
  663. +CONFIG_NF_CONNTRACK_EVENTS=y
  664. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  665. +CONFIG_NF_CT_PROTO_DCCP=m
  666. +CONFIG_NF_CT_PROTO_UDPLITE=m
  667. +CONFIG_NF_CONNTRACK_AMANDA=m
  668. +CONFIG_NF_CONNTRACK_FTP=m
  669. +CONFIG_NF_CONNTRACK_H323=m
  670. +CONFIG_NF_CONNTRACK_IRC=m
  671. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  672. +CONFIG_NF_CONNTRACK_SNMP=m
  673. +CONFIG_NF_CONNTRACK_PPTP=m
  674. +CONFIG_NF_CONNTRACK_SANE=m
  675. +CONFIG_NF_CONNTRACK_SIP=m
  676. +CONFIG_NF_CONNTRACK_TFTP=m
  677. +CONFIG_NF_CT_NETLINK=m
  678. +CONFIG_NETFILTER_XT_SET=m
  679. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  680. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  681. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  682. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  683. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  684. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  685. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  686. +CONFIG_NETFILTER_XT_TARGET_LED=m
  687. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  688. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  689. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  690. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  691. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  692. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  693. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  694. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  695. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  696. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  697. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  698. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  699. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  700. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  701. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  702. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  703. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  704. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  705. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  706. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  707. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  708. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  709. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  710. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  711. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  712. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  713. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  714. +CONFIG_NETFILTER_XT_MATCH_IPVS=m
  715. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  716. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  717. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  718. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  719. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  720. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  721. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  722. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  723. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  724. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  725. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  726. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  727. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  728. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  729. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  730. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  731. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  732. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  733. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  734. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  735. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  736. +CONFIG_NETFILTER_XT_MATCH_U32=m
  737. +CONFIG_IP_SET=m
  738. +CONFIG_IP_SET_BITMAP_IP=m
  739. +CONFIG_IP_SET_BITMAP_IPMAC=m
  740. +CONFIG_IP_SET_BITMAP_PORT=m
  741. +CONFIG_IP_SET_HASH_IP=m
  742. +CONFIG_IP_SET_HASH_IPPORT=m
  743. +CONFIG_IP_SET_HASH_IPPORTIP=m
  744. +CONFIG_IP_SET_HASH_IPPORTNET=m
  745. +CONFIG_IP_SET_HASH_NET=m
  746. +CONFIG_IP_SET_HASH_NETPORT=m
  747. +CONFIG_IP_SET_HASH_NETIFACE=m
  748. +CONFIG_IP_SET_LIST_SET=m
  749. +CONFIG_IP_VS=m
  750. +CONFIG_IP_VS_PROTO_TCP=y
  751. +CONFIG_IP_VS_PROTO_UDP=y
  752. +CONFIG_IP_VS_PROTO_ESP=y
  753. +CONFIG_IP_VS_PROTO_AH=y
  754. +CONFIG_IP_VS_PROTO_SCTP=y
  755. +CONFIG_IP_VS_RR=m
  756. +CONFIG_IP_VS_WRR=m
  757. +CONFIG_IP_VS_LC=m
  758. +CONFIG_IP_VS_WLC=m
  759. +CONFIG_IP_VS_LBLC=m
  760. +CONFIG_IP_VS_LBLCR=m
  761. +CONFIG_IP_VS_DH=m
  762. +CONFIG_IP_VS_SH=m
  763. +CONFIG_IP_VS_SED=m
  764. +CONFIG_IP_VS_NQ=m
  765. +CONFIG_IP_VS_FTP=m
  766. +CONFIG_IP_VS_PE_SIP=m
  767. +CONFIG_NF_CONNTRACK_IPV4=m
  768. +CONFIG_IP_NF_IPTABLES=m
  769. +CONFIG_IP_NF_MATCH_AH=m
  770. +CONFIG_IP_NF_MATCH_ECN=m
  771. +CONFIG_IP_NF_MATCH_TTL=m
  772. +CONFIG_IP_NF_FILTER=m
  773. +CONFIG_IP_NF_TARGET_REJECT=m
  774. +CONFIG_IP_NF_TARGET_ULOG=m
  775. +CONFIG_NF_NAT_IPV4=m
  776. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  777. +CONFIG_IP_NF_TARGET_NETMAP=m
  778. +CONFIG_IP_NF_TARGET_REDIRECT=m
  779. +CONFIG_IP_NF_MANGLE=m
  780. +CONFIG_IP_NF_TARGET_ECN=m
  781. +CONFIG_IP_NF_TARGET_TTL=m
  782. +CONFIG_IP_NF_RAW=m
  783. +CONFIG_IP_NF_ARPTABLES=m
  784. +CONFIG_IP_NF_ARPFILTER=m
  785. +CONFIG_IP_NF_ARP_MANGLE=m
  786. +CONFIG_NF_CONNTRACK_IPV6=m
  787. +CONFIG_IP6_NF_IPTABLES=m
  788. +CONFIG_IP6_NF_MATCH_AH=m
  789. +CONFIG_IP6_NF_MATCH_EUI64=m
  790. +CONFIG_IP6_NF_MATCH_FRAG=m
  791. +CONFIG_IP6_NF_MATCH_OPTS=m
  792. +CONFIG_IP6_NF_MATCH_HL=m
  793. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  794. +CONFIG_IP6_NF_MATCH_MH=m
  795. +CONFIG_IP6_NF_MATCH_RT=m
  796. +CONFIG_IP6_NF_TARGET_HL=m
  797. +CONFIG_IP6_NF_FILTER=m
  798. +CONFIG_IP6_NF_TARGET_REJECT=m
  799. +CONFIG_IP6_NF_MANGLE=m
  800. +CONFIG_IP6_NF_RAW=m
  801. +CONFIG_NF_NAT_IPV6=m
  802. +CONFIG_IP6_NF_TARGET_MASQUERADE=m
  803. +CONFIG_IP6_NF_TARGET_NPT=m
  804. +CONFIG_BRIDGE_NF_EBTABLES=m
  805. +CONFIG_BRIDGE_EBT_BROUTE=m
  806. +CONFIG_BRIDGE_EBT_T_FILTER=m
  807. +CONFIG_BRIDGE_EBT_T_NAT=m
  808. +CONFIG_BRIDGE_EBT_802_3=m
  809. +CONFIG_BRIDGE_EBT_AMONG=m
  810. +CONFIG_BRIDGE_EBT_ARP=m
  811. +CONFIG_BRIDGE_EBT_IP=m
  812. +CONFIG_BRIDGE_EBT_IP6=m
  813. +CONFIG_BRIDGE_EBT_LIMIT=m
  814. +CONFIG_BRIDGE_EBT_MARK=m
  815. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  816. +CONFIG_BRIDGE_EBT_STP=m
  817. +CONFIG_BRIDGE_EBT_VLAN=m
  818. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  819. +CONFIG_BRIDGE_EBT_DNAT=m
  820. +CONFIG_BRIDGE_EBT_MARK_T=m
  821. +CONFIG_BRIDGE_EBT_REDIRECT=m
  822. +CONFIG_BRIDGE_EBT_SNAT=m
  823. +CONFIG_BRIDGE_EBT_LOG=m
  824. +CONFIG_BRIDGE_EBT_ULOG=m
  825. +CONFIG_BRIDGE_EBT_NFLOG=m
  826. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  827. +CONFIG_L2TP=m
  828. +CONFIG_L2TP_V3=y
  829. +CONFIG_L2TP_IP=m
  830. +CONFIG_L2TP_ETH=m
  831. +CONFIG_BRIDGE=m
  832. +CONFIG_VLAN_8021Q=m
  833. +CONFIG_VLAN_8021Q_GVRP=y
  834. +CONFIG_ATALK=m
  835. +CONFIG_NET_SCHED=y
  836. +CONFIG_NET_SCH_CBQ=m
  837. +CONFIG_NET_SCH_HTB=m
  838. +CONFIG_NET_SCH_HFSC=m
  839. +CONFIG_NET_SCH_PRIO=m
  840. +CONFIG_NET_SCH_MULTIQ=m
  841. +CONFIG_NET_SCH_RED=m
  842. +CONFIG_NET_SCH_SFB=m
  843. +CONFIG_NET_SCH_SFQ=m
  844. +CONFIG_NET_SCH_TEQL=m
  845. +CONFIG_NET_SCH_TBF=m
  846. +CONFIG_NET_SCH_GRED=m
  847. +CONFIG_NET_SCH_DSMARK=m
  848. +CONFIG_NET_SCH_NETEM=m
  849. +CONFIG_NET_SCH_DRR=m
  850. +CONFIG_NET_SCH_MQPRIO=m
  851. +CONFIG_NET_SCH_CHOKE=m
  852. +CONFIG_NET_SCH_QFQ=m
  853. +CONFIG_NET_SCH_CODEL=m
  854. +CONFIG_NET_SCH_FQ_CODEL=m
  855. +CONFIG_NET_SCH_INGRESS=m
  856. +CONFIG_NET_SCH_PLUG=m
  857. +CONFIG_NET_CLS_BASIC=m
  858. +CONFIG_NET_CLS_TCINDEX=m
  859. +CONFIG_NET_CLS_ROUTE4=m
  860. +CONFIG_NET_CLS_FW=m
  861. +CONFIG_NET_CLS_U32=m
  862. +CONFIG_CLS_U32_MARK=y
  863. +CONFIG_NET_CLS_RSVP=m
  864. +CONFIG_NET_CLS_RSVP6=m
  865. +CONFIG_NET_CLS_FLOW=m
  866. +CONFIG_NET_CLS_CGROUP=m
  867. +CONFIG_NET_EMATCH=y
  868. +CONFIG_NET_EMATCH_CMP=m
  869. +CONFIG_NET_EMATCH_NBYTE=m
  870. +CONFIG_NET_EMATCH_U32=m
  871. +CONFIG_NET_EMATCH_META=m
  872. +CONFIG_NET_EMATCH_TEXT=m
  873. +CONFIG_NET_EMATCH_IPSET=m
  874. +CONFIG_NET_CLS_ACT=y
  875. +CONFIG_NET_ACT_POLICE=m
  876. +CONFIG_NET_ACT_GACT=m
  877. +CONFIG_GACT_PROB=y
  878. +CONFIG_NET_ACT_MIRRED=m
  879. +CONFIG_NET_ACT_IPT=m
  880. +CONFIG_NET_ACT_NAT=m
  881. +CONFIG_NET_ACT_PEDIT=m
  882. +CONFIG_NET_ACT_SIMP=m
  883. +CONFIG_NET_ACT_SKBEDIT=m
  884. +CONFIG_NET_ACT_CSUM=m
  885. +CONFIG_BATMAN_ADV=m
  886. +CONFIG_OPENVSWITCH=m
  887. +CONFIG_NET_PKTGEN=m
  888. +CONFIG_HAMRADIO=y
  889. +CONFIG_AX25=m
  890. +CONFIG_NETROM=m
  891. +CONFIG_ROSE=m
  892. +CONFIG_MKISS=m
  893. +CONFIG_6PACK=m
  894. +CONFIG_BPQETHER=m
  895. +CONFIG_BAYCOM_SER_FDX=m
  896. +CONFIG_BAYCOM_SER_HDX=m
  897. +CONFIG_YAM=m
  898. +CONFIG_IRDA=m
  899. +CONFIG_IRLAN=m
  900. +CONFIG_IRNET=m
  901. +CONFIG_IRCOMM=m
  902. +CONFIG_IRDA_ULTRA=y
  903. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  904. +CONFIG_IRDA_FAST_RR=y
  905. +CONFIG_IRTTY_SIR=m
  906. +CONFIG_KINGSUN_DONGLE=m
  907. +CONFIG_KSDAZZLE_DONGLE=m
  908. +CONFIG_KS959_DONGLE=m
  909. +CONFIG_USB_IRDA=m
  910. +CONFIG_SIGMATEL_FIR=m
  911. +CONFIG_MCS_FIR=m
  912. +CONFIG_BT=m
  913. +CONFIG_BT_RFCOMM=m
  914. +CONFIG_BT_RFCOMM_TTY=y
  915. +CONFIG_BT_BNEP=m
  916. +CONFIG_BT_BNEP_MC_FILTER=y
  917. +CONFIG_BT_BNEP_PROTO_FILTER=y
  918. +CONFIG_BT_HIDP=m
  919. +CONFIG_BT_HCIBTUSB=m
  920. +CONFIG_BT_HCIBCM203X=m
  921. +CONFIG_BT_HCIBPA10X=m
  922. +CONFIG_BT_HCIBFUSB=m
  923. +CONFIG_BT_HCIVHCI=m
  924. +CONFIG_BT_MRVL=m
  925. +CONFIG_BT_MRVL_SDIO=m
  926. +CONFIG_BT_ATH3K=m
  927. +CONFIG_BT_WILINK=m
  928. +CONFIG_CFG80211=m
  929. +CONFIG_CFG80211_WEXT=y
  930. +CONFIG_MAC80211=m
  931. +CONFIG_MAC80211_RC_PID=y
  932. +CONFIG_MAC80211_MESH=y
  933. +CONFIG_WIMAX=m
  934. +CONFIG_RFKILL=m
  935. +CONFIG_RFKILL_INPUT=y
  936. +CONFIG_NET_9P=m
  937. +CONFIG_NFC=m
  938. +CONFIG_NFC_PN533=m
  939. +CONFIG_DEVTMPFS=y
  940. +CONFIG_DEVTMPFS_MOUNT=y
  941. +CONFIG_BLK_DEV_LOOP=y
  942. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  943. +CONFIG_BLK_DEV_DRBD=m
  944. +CONFIG_BLK_DEV_NBD=m
  945. +CONFIG_BLK_DEV_RAM=y
  946. +CONFIG_CDROM_PKTCDVD=m
  947. +CONFIG_SCSI=y
  948. +# CONFIG_SCSI_PROC_FS is not set
  949. +CONFIG_BLK_DEV_SD=y
  950. +CONFIG_CHR_DEV_ST=m
  951. +CONFIG_CHR_DEV_OSST=m
  952. +CONFIG_BLK_DEV_SR=m
  953. +CONFIG_CHR_DEV_SG=m
  954. +CONFIG_SCSI_MULTI_LUN=y
  955. +CONFIG_SCSI_ISCSI_ATTRS=y
  956. +CONFIG_ISCSI_TCP=m
  957. +CONFIG_ISCSI_BOOT_SYSFS=m
  958. +CONFIG_MD=y
  959. +CONFIG_MD_LINEAR=m
  960. +CONFIG_MD_RAID0=m
  961. +CONFIG_BLK_DEV_DM=m
  962. +CONFIG_DM_CRYPT=m
  963. +CONFIG_DM_SNAPSHOT=m
  964. +CONFIG_DM_MIRROR=m
  965. +CONFIG_DM_LOG_USERSPACE=m
  966. +CONFIG_DM_RAID=m
  967. +CONFIG_DM_ZERO=m
  968. +CONFIG_DM_DELAY=m
  969. +CONFIG_NETDEVICES=y
  970. +CONFIG_BONDING=m
  971. +CONFIG_DUMMY=m
  972. +CONFIG_IFB=m
  973. +CONFIG_MACVLAN=m
  974. +CONFIG_NETCONSOLE=m
  975. +CONFIG_TUN=m
  976. +CONFIG_VETH=m
  977. +CONFIG_MDIO_BITBANG=m
  978. +CONFIG_PPP=m
  979. +CONFIG_PPP_BSDCOMP=m
  980. +CONFIG_PPP_DEFLATE=m
  981. +CONFIG_PPP_FILTER=y
  982. +CONFIG_PPP_MPPE=m
  983. +CONFIG_PPP_MULTILINK=y
  984. +CONFIG_PPPOE=m
  985. +CONFIG_PPPOL2TP=m
  986. +CONFIG_PPP_ASYNC=m
  987. +CONFIG_PPP_SYNC_TTY=m
  988. +CONFIG_SLIP=m
  989. +CONFIG_SLIP_COMPRESSED=y
  990. +CONFIG_SLIP_SMART=y
  991. +CONFIG_USB_CATC=m
  992. +CONFIG_USB_KAWETH=m
  993. +CONFIG_USB_PEGASUS=m
  994. +CONFIG_USB_RTL8150=m
  995. +CONFIG_USB_RTL8152=m
  996. +CONFIG_USB_USBNET=y
  997. +CONFIG_USB_NET_AX8817X=m
  998. +CONFIG_USB_NET_AX88179_178A=m
  999. +CONFIG_USB_NET_CDCETHER=m
  1000. +CONFIG_USB_NET_CDC_EEM=m
  1001. +CONFIG_USB_NET_CDC_NCM=m
  1002. +CONFIG_USB_NET_CDC_MBIM=m
  1003. +CONFIG_USB_NET_DM9601=m
  1004. +CONFIG_USB_NET_SMSC75XX=m
  1005. +CONFIG_USB_NET_SMSC95XX=y
  1006. +CONFIG_USB_NET_GL620A=m
  1007. +CONFIG_USB_NET_NET1080=m
  1008. +CONFIG_USB_NET_PLUSB=m
  1009. +CONFIG_USB_NET_MCS7830=m
  1010. +CONFIG_USB_NET_CDC_SUBSET=m
  1011. +CONFIG_USB_ALI_M5632=y
  1012. +CONFIG_USB_AN2720=y
  1013. +CONFIG_USB_EPSON2888=y
  1014. +CONFIG_USB_KC2190=y
  1015. +CONFIG_USB_NET_ZAURUS=m
  1016. +CONFIG_USB_NET_CX82310_ETH=m
  1017. +CONFIG_USB_NET_KALMIA=m
  1018. +CONFIG_USB_NET_QMI_WWAN=m
  1019. +CONFIG_USB_NET_INT51X1=m
  1020. +CONFIG_USB_IPHETH=m
  1021. +CONFIG_USB_SIERRA_NET=m
  1022. +CONFIG_USB_VL600=m
  1023. +CONFIG_LIBERTAS_THINFIRM=m
  1024. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1025. +CONFIG_AT76C50X_USB=m
  1026. +CONFIG_USB_ZD1201=m
  1027. +CONFIG_USB_NET_RNDIS_WLAN=m
  1028. +CONFIG_RTL8187=m
  1029. +CONFIG_MAC80211_HWSIM=m
  1030. +CONFIG_ATH_CARDS=m
  1031. +CONFIG_ATH9K=m
  1032. +CONFIG_ATH9K_HTC=m
  1033. +CONFIG_CARL9170=m
  1034. +CONFIG_ATH6KL=m
  1035. +CONFIG_ATH6KL_USB=m
  1036. +CONFIG_AR5523=m
  1037. +CONFIG_B43=m
  1038. +# CONFIG_B43_PHY_N is not set
  1039. +CONFIG_B43LEGACY=m
  1040. +CONFIG_BRCMFMAC=m
  1041. +# CONFIG_BRCMFMAC_SDIO is not set
  1042. +CONFIG_BRCMFMAC_USB=y
  1043. +CONFIG_HOSTAP=m
  1044. +CONFIG_LIBERTAS=m
  1045. +CONFIG_LIBERTAS_USB=m
  1046. +CONFIG_LIBERTAS_SDIO=m
  1047. +CONFIG_P54_COMMON=m
  1048. +CONFIG_P54_USB=m
  1049. +CONFIG_RT2X00=m
  1050. +CONFIG_RT2500USB=m
  1051. +CONFIG_RT73USB=m
  1052. +CONFIG_RT2800USB=m
  1053. +CONFIG_RT2800USB_RT3573=y
  1054. +CONFIG_RT2800USB_RT53XX=y
  1055. +CONFIG_RT2800USB_RT55XX=y
  1056. +CONFIG_RT2800USB_UNKNOWN=y
  1057. +CONFIG_RTL8192CU=m
  1058. +CONFIG_ZD1211RW=m
  1059. +CONFIG_MWIFIEX=m
  1060. +CONFIG_MWIFIEX_SDIO=m
  1061. +CONFIG_WIMAX_I2400M_USB=m
  1062. +CONFIG_INPUT_POLLDEV=m
  1063. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1064. +CONFIG_INPUT_JOYDEV=m
  1065. +CONFIG_INPUT_EVDEV=m
  1066. +# CONFIG_INPUT_KEYBOARD is not set
  1067. +# CONFIG_INPUT_MOUSE is not set
  1068. +CONFIG_INPUT_JOYSTICK=y
  1069. +CONFIG_JOYSTICK_IFORCE=m
  1070. +CONFIG_JOYSTICK_IFORCE_USB=y
  1071. +CONFIG_JOYSTICK_XPAD=m
  1072. +CONFIG_JOYSTICK_XPAD_FF=y
  1073. +CONFIG_INPUT_MISC=y
  1074. +CONFIG_INPUT_AD714X=m
  1075. +CONFIG_INPUT_ATI_REMOTE2=m
  1076. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1077. +CONFIG_INPUT_POWERMATE=m
  1078. +CONFIG_INPUT_YEALINK=m
  1079. +CONFIG_INPUT_CM109=m
  1080. +CONFIG_INPUT_UINPUT=m
  1081. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1082. +CONFIG_INPUT_ADXL34X=m
  1083. +CONFIG_INPUT_CMA3000=m
  1084. +CONFIG_SERIO=m
  1085. +CONFIG_SERIO_RAW=m
  1086. +CONFIG_GAMEPORT=m
  1087. +CONFIG_GAMEPORT_NS558=m
  1088. +CONFIG_GAMEPORT_L4=m
  1089. +# CONFIG_LEGACY_PTYS is not set
  1090. +# CONFIG_DEVKMEM is not set
  1091. +CONFIG_SERIAL_AMBA_PL011=y
  1092. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1093. +CONFIG_TTY_PRINTK=y
  1094. +CONFIG_HW_RANDOM=y
  1095. +CONFIG_HW_RANDOM_BCM2708=m
  1096. +CONFIG_RAW_DRIVER=y
  1097. +CONFIG_BRCM_CHAR_DRIVERS=y
  1098. +CONFIG_BCM_VC_CMA=y
  1099. +CONFIG_I2C=y
  1100. +CONFIG_I2C_CHARDEV=m
  1101. +CONFIG_I2C_BCM2708=m
  1102. +CONFIG_SPI=y
  1103. +CONFIG_SPI_BCM2708=m
  1104. +CONFIG_SPI_SPIDEV=y
  1105. +CONFIG_GPIO_SYSFS=y
  1106. +CONFIG_W1=m
  1107. +CONFIG_W1_MASTER_DS2490=m
  1108. +CONFIG_W1_MASTER_DS2482=m
  1109. +CONFIG_W1_MASTER_DS1WM=m
  1110. +CONFIG_W1_MASTER_GPIO=m
  1111. +CONFIG_W1_SLAVE_THERM=m
  1112. +CONFIG_W1_SLAVE_SMEM=m
  1113. +CONFIG_W1_SLAVE_DS2408=m
  1114. +CONFIG_W1_SLAVE_DS2413=m
  1115. +CONFIG_W1_SLAVE_DS2423=m
  1116. +CONFIG_W1_SLAVE_DS2431=m
  1117. +CONFIG_W1_SLAVE_DS2433=m
  1118. +CONFIG_W1_SLAVE_DS2760=m
  1119. +CONFIG_W1_SLAVE_DS2780=m
  1120. +CONFIG_W1_SLAVE_DS2781=m
  1121. +CONFIG_W1_SLAVE_DS28E04=m
  1122. +CONFIG_W1_SLAVE_BQ27000=m
  1123. +CONFIG_BATTERY_DS2760=m
  1124. +# CONFIG_HWMON is not set
  1125. +CONFIG_THERMAL=y
  1126. +CONFIG_THERMAL_BCM2835=y
  1127. +CONFIG_WATCHDOG=y
  1128. +CONFIG_BCM2708_WDT=m
  1129. +CONFIG_MEDIA_SUPPORT=m
  1130. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  1131. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  1132. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  1133. +CONFIG_MEDIA_RADIO_SUPPORT=y
  1134. +CONFIG_MEDIA_RC_SUPPORT=y
  1135. +CONFIG_MEDIA_CONTROLLER=y
  1136. +CONFIG_LIRC=m
  1137. +CONFIG_RC_DEVICES=y
  1138. +CONFIG_RC_ATI_REMOTE=m
  1139. +CONFIG_IR_IMON=m
  1140. +CONFIG_IR_MCEUSB=m
  1141. +CONFIG_IR_REDRAT3=m
  1142. +CONFIG_IR_STREAMZAP=m
  1143. +CONFIG_IR_IGUANA=m
  1144. +CONFIG_IR_TTUSBIR=m
  1145. +CONFIG_RC_LOOPBACK=m
  1146. +CONFIG_IR_GPIO_CIR=m
  1147. +CONFIG_MEDIA_USB_SUPPORT=y
  1148. +CONFIG_USB_VIDEO_CLASS=m
  1149. +CONFIG_USB_M5602=m
  1150. +CONFIG_USB_STV06XX=m
  1151. +CONFIG_USB_GL860=m
  1152. +CONFIG_USB_GSPCA_BENQ=m
  1153. +CONFIG_USB_GSPCA_CONEX=m
  1154. +CONFIG_USB_GSPCA_CPIA1=m
  1155. +CONFIG_USB_GSPCA_ETOMS=m
  1156. +CONFIG_USB_GSPCA_FINEPIX=m
  1157. +CONFIG_USB_GSPCA_JEILINJ=m
  1158. +CONFIG_USB_GSPCA_JL2005BCD=m
  1159. +CONFIG_USB_GSPCA_KINECT=m
  1160. +CONFIG_USB_GSPCA_KONICA=m
  1161. +CONFIG_USB_GSPCA_MARS=m
  1162. +CONFIG_USB_GSPCA_MR97310A=m
  1163. +CONFIG_USB_GSPCA_NW80X=m
  1164. +CONFIG_USB_GSPCA_OV519=m
  1165. +CONFIG_USB_GSPCA_OV534=m
  1166. +CONFIG_USB_GSPCA_OV534_9=m
  1167. +CONFIG_USB_GSPCA_PAC207=m
  1168. +CONFIG_USB_GSPCA_PAC7302=m
  1169. +CONFIG_USB_GSPCA_PAC7311=m
  1170. +CONFIG_USB_GSPCA_SE401=m
  1171. +CONFIG_USB_GSPCA_SN9C2028=m
  1172. +CONFIG_USB_GSPCA_SN9C20X=m
  1173. +CONFIG_USB_GSPCA_SONIXB=m
  1174. +CONFIG_USB_GSPCA_SONIXJ=m
  1175. +CONFIG_USB_GSPCA_SPCA500=m
  1176. +CONFIG_USB_GSPCA_SPCA501=m
  1177. +CONFIG_USB_GSPCA_SPCA505=m
  1178. +CONFIG_USB_GSPCA_SPCA506=m
  1179. +CONFIG_USB_GSPCA_SPCA508=m
  1180. +CONFIG_USB_GSPCA_SPCA561=m
  1181. +CONFIG_USB_GSPCA_SPCA1528=m
  1182. +CONFIG_USB_GSPCA_SQ905=m
  1183. +CONFIG_USB_GSPCA_SQ905C=m
  1184. +CONFIG_USB_GSPCA_SQ930X=m
  1185. +CONFIG_USB_GSPCA_STK014=m
  1186. +CONFIG_USB_GSPCA_STV0680=m
  1187. +CONFIG_USB_GSPCA_SUNPLUS=m
  1188. +CONFIG_USB_GSPCA_T613=m
  1189. +CONFIG_USB_GSPCA_TOPRO=m
  1190. +CONFIG_USB_GSPCA_TV8532=m
  1191. +CONFIG_USB_GSPCA_VC032X=m
  1192. +CONFIG_USB_GSPCA_VICAM=m
  1193. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  1194. +CONFIG_USB_GSPCA_ZC3XX=m
  1195. +CONFIG_USB_PWC=m
  1196. +CONFIG_VIDEO_CPIA2=m
  1197. +CONFIG_USB_ZR364XX=m
  1198. +CONFIG_USB_STKWEBCAM=m
  1199. +CONFIG_USB_S2255=m
  1200. +CONFIG_USB_SN9C102=m
  1201. +CONFIG_VIDEO_PVRUSB2=m
  1202. +CONFIG_VIDEO_HDPVR=m
  1203. +CONFIG_VIDEO_TLG2300=m
  1204. +CONFIG_VIDEO_USBVISION=m
  1205. +CONFIG_VIDEO_AU0828=m
  1206. +CONFIG_VIDEO_CX231XX=m
  1207. +CONFIG_VIDEO_CX231XX_ALSA=m
  1208. +CONFIG_VIDEO_CX231XX_DVB=m
  1209. +CONFIG_VIDEO_TM6000=m
  1210. +CONFIG_VIDEO_TM6000_ALSA=m
  1211. +CONFIG_VIDEO_TM6000_DVB=m
  1212. +CONFIG_DVB_USB=m
  1213. +CONFIG_DVB_USB_A800=m
  1214. +CONFIG_DVB_USB_DIBUSB_MB=m
  1215. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  1216. +CONFIG_DVB_USB_DIBUSB_MC=m
  1217. +CONFIG_DVB_USB_DIB0700=m
  1218. +CONFIG_DVB_USB_UMT_010=m
  1219. +CONFIG_DVB_USB_CXUSB=m
  1220. +CONFIG_DVB_USB_M920X=m
  1221. +CONFIG_DVB_USB_DIGITV=m
  1222. +CONFIG_DVB_USB_VP7045=m
  1223. +CONFIG_DVB_USB_VP702X=m
  1224. +CONFIG_DVB_USB_GP8PSK=m
  1225. +CONFIG_DVB_USB_NOVA_T_USB2=m
  1226. +CONFIG_DVB_USB_TTUSB2=m
  1227. +CONFIG_DVB_USB_DTT200U=m
  1228. +CONFIG_DVB_USB_OPERA1=m
  1229. +CONFIG_DVB_USB_AF9005=m
  1230. +CONFIG_DVB_USB_AF9005_REMOTE=m
  1231. +CONFIG_DVB_USB_PCTV452E=m
  1232. +CONFIG_DVB_USB_DW2102=m
  1233. +CONFIG_DVB_USB_CINERGY_T2=m
  1234. +CONFIG_DVB_USB_DTV5100=m
  1235. +CONFIG_DVB_USB_FRIIO=m
  1236. +CONFIG_DVB_USB_AZ6027=m
  1237. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  1238. +CONFIG_DVB_USB_V2=m
  1239. +CONFIG_DVB_USB_AF9015=m
  1240. +CONFIG_DVB_USB_AF9035=m
  1241. +CONFIG_DVB_USB_ANYSEE=m
  1242. +CONFIG_DVB_USB_AU6610=m
  1243. +CONFIG_DVB_USB_AZ6007=m
  1244. +CONFIG_DVB_USB_CE6230=m
  1245. +CONFIG_DVB_USB_EC168=m
  1246. +CONFIG_DVB_USB_GL861=m
  1247. +CONFIG_DVB_USB_IT913X=m
  1248. +CONFIG_DVB_USB_LME2510=m
  1249. +CONFIG_DVB_USB_MXL111SF=m
  1250. +CONFIG_DVB_USB_RTL28XXU=m
  1251. +CONFIG_SMS_USB_DRV=m
  1252. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  1253. +CONFIG_VIDEO_EM28XX=m
  1254. +CONFIG_VIDEO_EM28XX_ALSA=m
  1255. +CONFIG_VIDEO_EM28XX_DVB=m
  1256. +CONFIG_V4L_PLATFORM_DRIVERS=y
  1257. +CONFIG_VIDEO_BCM2835=y
  1258. +CONFIG_VIDEO_BCM2835_MMAL=m
  1259. +CONFIG_RADIO_SI470X=y
  1260. +CONFIG_USB_SI470X=m
  1261. +CONFIG_I2C_SI470X=m
  1262. +CONFIG_USB_MR800=m
  1263. +CONFIG_USB_DSBR=m
  1264. +CONFIG_RADIO_SHARK=m
  1265. +CONFIG_RADIO_SHARK2=m
  1266. +CONFIG_RADIO_SI4713=m
  1267. +CONFIG_USB_KEENE=m
  1268. +CONFIG_USB_MA901=m
  1269. +CONFIG_RADIO_TEA5764=m
  1270. +CONFIG_RADIO_SAA7706H=m
  1271. +CONFIG_RADIO_TEF6862=m
  1272. +CONFIG_RADIO_WL1273=m
  1273. +CONFIG_RADIO_WL128X=m
  1274. +CONFIG_FB=y
  1275. +CONFIG_FB_BCM2708=y
  1276. +# CONFIG_BACKLIGHT_GENERIC is not set
  1277. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1278. +CONFIG_LOGO=y
  1279. +# CONFIG_LOGO_LINUX_MONO is not set
  1280. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1281. +CONFIG_SOUND=y
  1282. +CONFIG_SND=m
  1283. +CONFIG_SND_SEQUENCER=m
  1284. +CONFIG_SND_SEQ_DUMMY=m
  1285. +CONFIG_SND_MIXER_OSS=m
  1286. +CONFIG_SND_PCM_OSS=m
  1287. +CONFIG_SND_SEQUENCER_OSS=y
  1288. +CONFIG_SND_HRTIMER=m
  1289. +CONFIG_SND_DUMMY=m
  1290. +CONFIG_SND_ALOOP=m
  1291. +CONFIG_SND_VIRMIDI=m
  1292. +CONFIG_SND_MTPAV=m
  1293. +CONFIG_SND_SERIAL_U16550=m
  1294. +CONFIG_SND_MPU401=m
  1295. +CONFIG_SND_BCM2835=m
  1296. +CONFIG_SND_USB_AUDIO=m
  1297. +CONFIG_SND_USB_UA101=m
  1298. +CONFIG_SND_USB_CAIAQ=m
  1299. +CONFIG_SND_USB_CAIAQ_INPUT=y
  1300. +CONFIG_SND_USB_6FIRE=m
  1301. +CONFIG_SND_SOC=m
  1302. +CONFIG_SND_SOC_DMAENGINE_PCM=y
  1303. +CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y
  1304. +CONFIG_SND_SOC_WM8804=m
  1305. +CONFIG_SND_BCM2708_SOC_I2S=m
  1306. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  1307. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  1308. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  1309. +CONFIG_SND_SOC_I2C_AND_SPI=m
  1310. +CONFIG_SND_SOC_PCM5102A=m
  1311. +CONFIG_SND_SOC_PCM1794A=m
  1312. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  1313. +CONFIG_SOUND_PRIME=m
  1314. +CONFIG_HIDRAW=y
  1315. +CONFIG_HID_A4TECH=m
  1316. +CONFIG_HID_ACRUX=m
  1317. +CONFIG_HID_APPLE=m
  1318. +CONFIG_HID_BELKIN=m
  1319. +CONFIG_HID_CHERRY=m
  1320. +CONFIG_HID_CHICONY=m
  1321. +CONFIG_HID_CYPRESS=m
  1322. +CONFIG_HID_DRAGONRISE=m
  1323. +CONFIG_HID_EMS_FF=m
  1324. +CONFIG_HID_ELECOM=m
  1325. +CONFIG_HID_EZKEY=m
  1326. +CONFIG_HID_HOLTEK=m
  1327. +CONFIG_HID_KEYTOUCH=m
  1328. +CONFIG_HID_KYE=m
  1329. +CONFIG_HID_UCLOGIC=m
  1330. +CONFIG_HID_WALTOP=m
  1331. +CONFIG_HID_GYRATION=m
  1332. +CONFIG_HID_TWINHAN=m
  1333. +CONFIG_HID_KENSINGTON=m
  1334. +CONFIG_HID_LCPOWER=m
  1335. +CONFIG_HID_LOGITECH=m
  1336. +CONFIG_HID_MAGICMOUSE=m
  1337. +CONFIG_HID_MICROSOFT=m
  1338. +CONFIG_HID_MONTEREY=m
  1339. +CONFIG_HID_MULTITOUCH=m
  1340. +CONFIG_HID_NTRIG=m
  1341. +CONFIG_HID_ORTEK=m
  1342. +CONFIG_HID_PANTHERLORD=m
  1343. +CONFIG_HID_PETALYNX=m
  1344. +CONFIG_HID_PICOLCD=m
  1345. +CONFIG_HID_ROCCAT=m
  1346. +CONFIG_HID_SAMSUNG=m
  1347. +CONFIG_HID_SONY=m
  1348. +CONFIG_HID_SPEEDLINK=m
  1349. +CONFIG_HID_SUNPLUS=m
  1350. +CONFIG_HID_GREENASIA=m
  1351. +CONFIG_HID_SMARTJOYPLUS=m
  1352. +CONFIG_HID_TOPSEED=m
  1353. +CONFIG_HID_THINGM=m
  1354. +CONFIG_HID_THRUSTMASTER=m
  1355. +CONFIG_HID_WACOM=m
  1356. +CONFIG_HID_WIIMOTE=m
  1357. +CONFIG_HID_ZEROPLUS=m
  1358. +CONFIG_HID_ZYDACRON=m
  1359. +CONFIG_HID_PID=y
  1360. +CONFIG_USB_HIDDEV=y
  1361. +CONFIG_USB=y
  1362. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1363. +CONFIG_USB_MON=m
  1364. +CONFIG_USB_DWCOTG=y
  1365. +CONFIG_USB_PRINTER=m
  1366. +CONFIG_USB_STORAGE=y
  1367. +CONFIG_USB_STORAGE_REALTEK=m
  1368. +CONFIG_USB_STORAGE_DATAFAB=m
  1369. +CONFIG_USB_STORAGE_FREECOM=m
  1370. +CONFIG_USB_STORAGE_ISD200=m
  1371. +CONFIG_USB_STORAGE_USBAT=m
  1372. +CONFIG_USB_STORAGE_SDDR09=m
  1373. +CONFIG_USB_STORAGE_SDDR55=m
  1374. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1375. +CONFIG_USB_STORAGE_ALAUDA=m
  1376. +CONFIG_USB_STORAGE_ONETOUCH=m
  1377. +CONFIG_USB_STORAGE_KARMA=m
  1378. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1379. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1380. +CONFIG_USB_MDC800=m
  1381. +CONFIG_USB_MICROTEK=m
  1382. +CONFIG_USB_SERIAL=m
  1383. +CONFIG_USB_SERIAL_GENERIC=y
  1384. +CONFIG_USB_SERIAL_AIRCABLE=m
  1385. +CONFIG_USB_SERIAL_ARK3116=m
  1386. +CONFIG_USB_SERIAL_BELKIN=m
  1387. +CONFIG_USB_SERIAL_CH341=m
  1388. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1389. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1390. +CONFIG_USB_SERIAL_CP210X=m
  1391. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1392. +CONFIG_USB_SERIAL_EMPEG=m
  1393. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1394. +CONFIG_USB_SERIAL_VISOR=m
  1395. +CONFIG_USB_SERIAL_IPAQ=m
  1396. +CONFIG_USB_SERIAL_IR=m
  1397. +CONFIG_USB_SERIAL_EDGEPORT=m
  1398. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1399. +CONFIG_USB_SERIAL_F81232=m
  1400. +CONFIG_USB_SERIAL_GARMIN=m
  1401. +CONFIG_USB_SERIAL_IPW=m
  1402. +CONFIG_USB_SERIAL_IUU=m
  1403. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1404. +CONFIG_USB_SERIAL_KEYSPAN=m
  1405. +CONFIG_USB_SERIAL_KLSI=m
  1406. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1407. +CONFIG_USB_SERIAL_MCT_U232=m
  1408. +CONFIG_USB_SERIAL_METRO=m
  1409. +CONFIG_USB_SERIAL_MOS7720=m
  1410. +CONFIG_USB_SERIAL_MOS7840=m
  1411. +CONFIG_USB_SERIAL_NAVMAN=m
  1412. +CONFIG_USB_SERIAL_PL2303=m
  1413. +CONFIG_USB_SERIAL_OTI6858=m
  1414. +CONFIG_USB_SERIAL_QCAUX=m
  1415. +CONFIG_USB_SERIAL_QUALCOMM=m
  1416. +CONFIG_USB_SERIAL_SPCP8X5=m
  1417. +CONFIG_USB_SERIAL_SAFE=m
  1418. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1419. +CONFIG_USB_SERIAL_SYMBOL=m
  1420. +CONFIG_USB_SERIAL_TI=m
  1421. +CONFIG_USB_SERIAL_CYBERJACK=m
  1422. +CONFIG_USB_SERIAL_XIRCOM=m
  1423. +CONFIG_USB_SERIAL_OPTION=m
  1424. +CONFIG_USB_SERIAL_OMNINET=m
  1425. +CONFIG_USB_SERIAL_OPTICON=m
  1426. +CONFIG_USB_SERIAL_XSENS_MT=m
  1427. +CONFIG_USB_SERIAL_WISHBONE=m
  1428. +CONFIG_USB_SERIAL_ZTE=m
  1429. +CONFIG_USB_SERIAL_SSU100=m
  1430. +CONFIG_USB_SERIAL_QT2=m
  1431. +CONFIG_USB_SERIAL_DEBUG=m
  1432. +CONFIG_USB_EMI62=m
  1433. +CONFIG_USB_EMI26=m
  1434. +CONFIG_USB_ADUTUX=m
  1435. +CONFIG_USB_SEVSEG=m
  1436. +CONFIG_USB_RIO500=m
  1437. +CONFIG_USB_LEGOTOWER=m
  1438. +CONFIG_USB_LCD=m
  1439. +CONFIG_USB_LED=m
  1440. +CONFIG_USB_CYPRESS_CY7C63=m
  1441. +CONFIG_USB_CYTHERM=m
  1442. +CONFIG_USB_IDMOUSE=m
  1443. +CONFIG_USB_FTDI_ELAN=m
  1444. +CONFIG_USB_APPLEDISPLAY=m
  1445. +CONFIG_USB_LD=m
  1446. +CONFIG_USB_TRANCEVIBRATOR=m
  1447. +CONFIG_USB_IOWARRIOR=m
  1448. +CONFIG_USB_TEST=m
  1449. +CONFIG_USB_ISIGHTFW=m
  1450. +CONFIG_USB_YUREX=m
  1451. +CONFIG_MMC=y
  1452. +CONFIG_MMC_BLOCK_MINORS=32
  1453. +CONFIG_MMC_SDHCI=y
  1454. +CONFIG_MMC_SDHCI_PLTFM=y
  1455. +CONFIG_MMC_SDHCI_BCM2708=y
  1456. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  1457. +CONFIG_MMC_SPI=m
  1458. +CONFIG_LEDS_GPIO=m
  1459. +CONFIG_LEDS_TRIGGER_TIMER=y
  1460. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  1461. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  1462. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  1463. +CONFIG_LEDS_TRIGGER_CPU=y
  1464. +CONFIG_LEDS_TRIGGER_GPIO=y
  1465. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  1466. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  1467. +CONFIG_LEDS_TRIGGER_CAMERA=m
  1468. +CONFIG_RTC_CLASS=y
  1469. +# CONFIG_RTC_HCTOSYS is not set
  1470. +CONFIG_RTC_DRV_DS1307=m
  1471. +CONFIG_RTC_DRV_DS1374=m
  1472. +CONFIG_RTC_DRV_DS1672=m
  1473. +CONFIG_RTC_DRV_DS3232=m
  1474. +CONFIG_RTC_DRV_MAX6900=m
  1475. +CONFIG_RTC_DRV_RS5C372=m
  1476. +CONFIG_RTC_DRV_ISL1208=m
  1477. +CONFIG_RTC_DRV_ISL12022=m
  1478. +CONFIG_RTC_DRV_X1205=m
  1479. +CONFIG_RTC_DRV_PCF8523=m
  1480. +CONFIG_RTC_DRV_PCF8563=m
  1481. +CONFIG_RTC_DRV_PCF8583=m
  1482. +CONFIG_RTC_DRV_M41T80=m
  1483. +CONFIG_RTC_DRV_BQ32K=m
  1484. +CONFIG_RTC_DRV_S35390A=m
  1485. +CONFIG_RTC_DRV_FM3130=m
  1486. +CONFIG_RTC_DRV_RX8581=m
  1487. +CONFIG_RTC_DRV_RX8025=m
  1488. +CONFIG_RTC_DRV_EM3027=m
  1489. +CONFIG_RTC_DRV_RV3029C2=m
  1490. +CONFIG_RTC_DRV_M41T93=m
  1491. +CONFIG_RTC_DRV_M41T94=m
  1492. +CONFIG_RTC_DRV_DS1305=m
  1493. +CONFIG_RTC_DRV_DS1390=m
  1494. +CONFIG_RTC_DRV_MAX6902=m
  1495. +CONFIG_RTC_DRV_R9701=m
  1496. +CONFIG_RTC_DRV_RS5C348=m
  1497. +CONFIG_RTC_DRV_DS3234=m
  1498. +CONFIG_RTC_DRV_PCF2123=m
  1499. +CONFIG_RTC_DRV_RX4581=m
  1500. +CONFIG_DMADEVICES=y
  1501. +CONFIG_DMA_BCM2708=m
  1502. +CONFIG_DMA_ENGINE=y
  1503. +CONFIG_DMA_VIRTUAL_CHANNELS=m
  1504. +CONFIG_UIO=m
  1505. +CONFIG_UIO_PDRV_GENIRQ=m
  1506. +CONFIG_STAGING=y
  1507. +CONFIG_W35UND=m
  1508. +CONFIG_PRISM2_USB=m
  1509. +CONFIG_R8712U=m
  1510. +CONFIG_VT6656=m
  1511. +CONFIG_SPEAKUP=m
  1512. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  1513. +CONFIG_STAGING_MEDIA=y
  1514. +CONFIG_DVB_AS102=m
  1515. +CONFIG_LIRC_STAGING=y
  1516. +CONFIG_LIRC_IGORPLUGUSB=m
  1517. +CONFIG_LIRC_IMON=m
  1518. +CONFIG_LIRC_RPI=m
  1519. +CONFIG_LIRC_SASEM=m
  1520. +CONFIG_LIRC_SERIAL=m
  1521. +# CONFIG_IOMMU_SUPPORT is not set
  1522. +CONFIG_EXT4_FS=y
  1523. +CONFIG_EXT4_FS_POSIX_ACL=y
  1524. +CONFIG_EXT4_FS_SECURITY=y
  1525. +CONFIG_REISERFS_FS=m
  1526. +CONFIG_REISERFS_FS_XATTR=y
  1527. +CONFIG_REISERFS_FS_POSIX_ACL=y
  1528. +CONFIG_REISERFS_FS_SECURITY=y
  1529. +CONFIG_JFS_FS=m
  1530. +CONFIG_JFS_POSIX_ACL=y
  1531. +CONFIG_JFS_SECURITY=y
  1532. +CONFIG_JFS_STATISTICS=y
  1533. +CONFIG_XFS_FS=m
  1534. +CONFIG_XFS_QUOTA=y
  1535. +CONFIG_XFS_POSIX_ACL=y
  1536. +CONFIG_XFS_RT=y
  1537. +CONFIG_GFS2_FS=m
  1538. +CONFIG_OCFS2_FS=m
  1539. +CONFIG_BTRFS_FS=m
  1540. +CONFIG_BTRFS_FS_POSIX_ACL=y
  1541. +CONFIG_NILFS2_FS=m
  1542. +CONFIG_FANOTIFY=y
  1543. +CONFIG_QFMT_V1=m
  1544. +CONFIG_QFMT_V2=m
  1545. +CONFIG_AUTOFS4_FS=y
  1546. +CONFIG_FUSE_FS=m
  1547. +CONFIG_CUSE=m
  1548. +CONFIG_FSCACHE=y
  1549. +CONFIG_FSCACHE_STATS=y
  1550. +CONFIG_FSCACHE_HISTOGRAM=y
  1551. +CONFIG_CACHEFILES=y
  1552. +CONFIG_ISO9660_FS=m
  1553. +CONFIG_JOLIET=y
  1554. +CONFIG_ZISOFS=y
  1555. +CONFIG_UDF_FS=m
  1556. +CONFIG_MSDOS_FS=y
  1557. +CONFIG_VFAT_FS=y
  1558. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  1559. +CONFIG_NTFS_FS=m
  1560. +CONFIG_NTFS_RW=y
  1561. +CONFIG_TMPFS=y
  1562. +CONFIG_TMPFS_POSIX_ACL=y
  1563. +CONFIG_CONFIGFS_FS=y
  1564. +CONFIG_ECRYPT_FS=m
  1565. +CONFIG_HFS_FS=m
  1566. +CONFIG_HFSPLUS_FS=m
  1567. +CONFIG_SQUASHFS=m
  1568. +CONFIG_SQUASHFS_XATTR=y
  1569. +CONFIG_SQUASHFS_LZO=y
  1570. +CONFIG_SQUASHFS_XZ=y
  1571. +CONFIG_F2FS_FS=y
  1572. +CONFIG_NFS_FS=y
  1573. +CONFIG_NFS_V3_ACL=y
  1574. +CONFIG_NFS_V4=y
  1575. +CONFIG_ROOT_NFS=y
  1576. +CONFIG_NFS_FSCACHE=y
  1577. +CONFIG_NFSD=m
  1578. +CONFIG_NFSD_V3_ACL=y
  1579. +CONFIG_NFSD_V4=y
  1580. +CONFIG_CIFS=m
  1581. +CONFIG_CIFS_WEAK_PW_HASH=y
  1582. +CONFIG_CIFS_XATTR=y
  1583. +CONFIG_CIFS_POSIX=y
  1584. +CONFIG_9P_FS=m
  1585. +CONFIG_9P_FS_POSIX_ACL=y
  1586. +CONFIG_NLS_DEFAULT="utf8"
  1587. +CONFIG_NLS_CODEPAGE_437=y
  1588. +CONFIG_NLS_CODEPAGE_737=m
  1589. +CONFIG_NLS_CODEPAGE_775=m
  1590. +CONFIG_NLS_CODEPAGE_850=m
  1591. +CONFIG_NLS_CODEPAGE_852=m
  1592. +CONFIG_NLS_CODEPAGE_855=m
  1593. +CONFIG_NLS_CODEPAGE_857=m
  1594. +CONFIG_NLS_CODEPAGE_860=m
  1595. +CONFIG_NLS_CODEPAGE_861=m
  1596. +CONFIG_NLS_CODEPAGE_862=m
  1597. +CONFIG_NLS_CODEPAGE_863=m
  1598. +CONFIG_NLS_CODEPAGE_864=m
  1599. +CONFIG_NLS_CODEPAGE_865=m
  1600. +CONFIG_NLS_CODEPAGE_866=m
  1601. +CONFIG_NLS_CODEPAGE_869=m
  1602. +CONFIG_NLS_CODEPAGE_936=m
  1603. +CONFIG_NLS_CODEPAGE_950=m
  1604. +CONFIG_NLS_CODEPAGE_932=m
  1605. +CONFIG_NLS_CODEPAGE_949=m
  1606. +CONFIG_NLS_CODEPAGE_874=m
  1607. +CONFIG_NLS_ISO8859_8=m
  1608. +CONFIG_NLS_CODEPAGE_1250=m
  1609. +CONFIG_NLS_CODEPAGE_1251=m
  1610. +CONFIG_NLS_ASCII=y
  1611. +CONFIG_NLS_ISO8859_1=m
  1612. +CONFIG_NLS_ISO8859_2=m
  1613. +CONFIG_NLS_ISO8859_3=m
  1614. +CONFIG_NLS_ISO8859_4=m
  1615. +CONFIG_NLS_ISO8859_5=m
  1616. +CONFIG_NLS_ISO8859_6=m
  1617. +CONFIG_NLS_ISO8859_7=m
  1618. +CONFIG_NLS_ISO8859_9=m
  1619. +CONFIG_NLS_ISO8859_13=m
  1620. +CONFIG_NLS_ISO8859_14=m
  1621. +CONFIG_NLS_ISO8859_15=m
  1622. +CONFIG_NLS_KOI8_R=m
  1623. +CONFIG_NLS_KOI8_U=m
  1624. +CONFIG_DLM=m
  1625. +CONFIG_PRINTK_TIME=y
  1626. +CONFIG_BOOT_PRINTK_DELAY=y
  1627. +CONFIG_DEBUG_FS=y
  1628. +CONFIG_DEBUG_MEMORY_INIT=y
  1629. +CONFIG_DETECT_HUNG_TASK=y
  1630. +CONFIG_TIMER_STATS=y
  1631. +# CONFIG_DEBUG_PREEMPT is not set
  1632. +CONFIG_LATENCYTOP=y
  1633. +# CONFIG_KPROBE_EVENT is not set
  1634. +CONFIG_KGDB=y
  1635. +CONFIG_KGDB_KDB=y
  1636. +CONFIG_KDB_KEYBOARD=y
  1637. +CONFIG_STRICT_DEVMEM=y
  1638. +CONFIG_CRYPTO_USER=m
  1639. +CONFIG_CRYPTO_NULL=m
  1640. +CONFIG_CRYPTO_CRYPTD=m
  1641. +CONFIG_CRYPTO_CBC=y
  1642. +CONFIG_CRYPTO_XTS=m
  1643. +CONFIG_CRYPTO_XCBC=m
  1644. +CONFIG_CRYPTO_SHA1_ARM=m
  1645. +CONFIG_CRYPTO_SHA512=m
  1646. +CONFIG_CRYPTO_TGR192=m
  1647. +CONFIG_CRYPTO_WP512=m
  1648. +CONFIG_CRYPTO_AES_ARM=m
  1649. +CONFIG_CRYPTO_CAST5=m
  1650. +CONFIG_CRYPTO_DES=y
  1651. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  1652. +# CONFIG_CRYPTO_HW is not set
  1653. +CONFIG_CRC_ITU_T=y
  1654. +CONFIG_LIBCRC32C=y
  1655. diff -Nur linux-3.12.18/arch/arm/configs/bcmrpi_emergency_defconfig linux-rpi/arch/arm/configs/bcmrpi_emergency_defconfig
  1656. --- linux-3.12.18/arch/arm/configs/bcmrpi_emergency_defconfig 1970-01-01 01:00:00.000000000 +0100
  1657. +++ linux-rpi/arch/arm/configs/bcmrpi_emergency_defconfig 2014-04-24 16:04:30.011029397 +0200
  1658. @@ -0,0 +1,532 @@
  1659. +CONFIG_EXPERIMENTAL=y
  1660. +# CONFIG_LOCALVERSION_AUTO is not set
  1661. +CONFIG_SYSVIPC=y
  1662. +CONFIG_POSIX_MQUEUE=y
  1663. +CONFIG_BSD_PROCESS_ACCT=y
  1664. +CONFIG_BSD_PROCESS_ACCT_V3=y
  1665. +CONFIG_FHANDLE=y
  1666. +CONFIG_AUDIT=y
  1667. +CONFIG_IKCONFIG=y
  1668. +CONFIG_IKCONFIG_PROC=y
  1669. +CONFIG_BLK_DEV_INITRD=y
  1670. +CONFIG_INITRAMFS_SOURCE="../target_fs"
  1671. +CONFIG_CGROUP_FREEZER=y
  1672. +CONFIG_CGROUP_DEVICE=y
  1673. +CONFIG_CGROUP_CPUACCT=y
  1674. +CONFIG_RESOURCE_COUNTERS=y
  1675. +CONFIG_BLK_CGROUP=y
  1676. +CONFIG_NAMESPACES=y
  1677. +CONFIG_SCHED_AUTOGROUP=y
  1678. +CONFIG_EMBEDDED=y
  1679. +# CONFIG_COMPAT_BRK is not set
  1680. +CONFIG_SLAB=y
  1681. +CONFIG_PROFILING=y
  1682. +CONFIG_OPROFILE=m
  1683. +CONFIG_KPROBES=y
  1684. +CONFIG_MODULES=y
  1685. +CONFIG_MODULE_UNLOAD=y
  1686. +CONFIG_MODVERSIONS=y
  1687. +CONFIG_MODULE_SRCVERSION_ALL=y
  1688. +# CONFIG_BLK_DEV_BSG is not set
  1689. +CONFIG_BLK_DEV_THROTTLING=y
  1690. +CONFIG_CFQ_GROUP_IOSCHED=y
  1691. +CONFIG_ARCH_BCM2708=y
  1692. +CONFIG_NO_HZ=y
  1693. +CONFIG_HIGH_RES_TIMERS=y
  1694. +CONFIG_AEABI=y
  1695. +CONFIG_SECCOMP=y
  1696. +CONFIG_CC_STACKPROTECTOR=y
  1697. +CONFIG_ZBOOT_ROM_TEXT=0x0
  1698. +CONFIG_ZBOOT_ROM_BSS=0x0
  1699. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  1700. +CONFIG_KEXEC=y
  1701. +CONFIG_CPU_IDLE=y
  1702. +CONFIG_VFP=y
  1703. +CONFIG_BINFMT_MISC=m
  1704. +CONFIG_NET=y
  1705. +CONFIG_PACKET=y
  1706. +CONFIG_UNIX=y
  1707. +CONFIG_XFRM_USER=y
  1708. +CONFIG_NET_KEY=m
  1709. +CONFIG_INET=y
  1710. +CONFIG_IP_MULTICAST=y
  1711. +CONFIG_IP_PNP=y
  1712. +CONFIG_IP_PNP_DHCP=y
  1713. +CONFIG_IP_PNP_RARP=y
  1714. +CONFIG_SYN_COOKIES=y
  1715. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  1716. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  1717. +# CONFIG_INET_XFRM_MODE_BEET is not set
  1718. +# CONFIG_INET_LRO is not set
  1719. +# CONFIG_INET_DIAG is not set
  1720. +# CONFIG_IPV6 is not set
  1721. +CONFIG_NET_PKTGEN=m
  1722. +CONFIG_IRDA=m
  1723. +CONFIG_IRLAN=m
  1724. +CONFIG_IRCOMM=m
  1725. +CONFIG_IRDA_ULTRA=y
  1726. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  1727. +CONFIG_IRDA_FAST_RR=y
  1728. +CONFIG_IRTTY_SIR=m
  1729. +CONFIG_KINGSUN_DONGLE=m
  1730. +CONFIG_KSDAZZLE_DONGLE=m
  1731. +CONFIG_KS959_DONGLE=m
  1732. +CONFIG_USB_IRDA=m
  1733. +CONFIG_SIGMATEL_FIR=m
  1734. +CONFIG_MCS_FIR=m
  1735. +CONFIG_BT=m
  1736. +CONFIG_BT_L2CAP=y
  1737. +CONFIG_BT_SCO=y
  1738. +CONFIG_BT_RFCOMM=m
  1739. +CONFIG_BT_RFCOMM_TTY=y
  1740. +CONFIG_BT_BNEP=m
  1741. +CONFIG_BT_BNEP_MC_FILTER=y
  1742. +CONFIG_BT_BNEP_PROTO_FILTER=y
  1743. +CONFIG_BT_HIDP=m
  1744. +CONFIG_BT_HCIBTUSB=m
  1745. +CONFIG_BT_HCIBCM203X=m
  1746. +CONFIG_BT_HCIBPA10X=m
  1747. +CONFIG_BT_HCIBFUSB=m
  1748. +CONFIG_BT_HCIVHCI=m
  1749. +CONFIG_BT_MRVL=m
  1750. +CONFIG_BT_MRVL_SDIO=m
  1751. +CONFIG_BT_ATH3K=m
  1752. +CONFIG_CFG80211=m
  1753. +CONFIG_MAC80211=m
  1754. +CONFIG_MAC80211_RC_PID=y
  1755. +CONFIG_MAC80211_MESH=y
  1756. +CONFIG_WIMAX=m
  1757. +CONFIG_NET_9P=m
  1758. +CONFIG_NFC=m
  1759. +CONFIG_NFC_PN533=m
  1760. +CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
  1761. +CONFIG_BLK_DEV_LOOP=y
  1762. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  1763. +CONFIG_BLK_DEV_NBD=m
  1764. +CONFIG_BLK_DEV_RAM=y
  1765. +CONFIG_CDROM_PKTCDVD=m
  1766. +CONFIG_MISC_DEVICES=y
  1767. +CONFIG_SCSI=y
  1768. +# CONFIG_SCSI_PROC_FS is not set
  1769. +CONFIG_BLK_DEV_SD=y
  1770. +CONFIG_BLK_DEV_SR=m
  1771. +CONFIG_SCSI_MULTI_LUN=y
  1772. +# CONFIG_SCSI_LOWLEVEL is not set
  1773. +CONFIG_MD=y
  1774. +CONFIG_NETDEVICES=y
  1775. +CONFIG_TUN=m
  1776. +CONFIG_PHYLIB=m
  1777. +CONFIG_MDIO_BITBANG=m
  1778. +CONFIG_NET_ETHERNET=y
  1779. +# CONFIG_NETDEV_1000 is not set
  1780. +# CONFIG_NETDEV_10000 is not set
  1781. +CONFIG_LIBERTAS_THINFIRM=m
  1782. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1783. +CONFIG_AT76C50X_USB=m
  1784. +CONFIG_USB_ZD1201=m
  1785. +CONFIG_USB_NET_RNDIS_WLAN=m
  1786. +CONFIG_RTL8187=m
  1787. +CONFIG_MAC80211_HWSIM=m
  1788. +CONFIG_ATH_COMMON=m
  1789. +CONFIG_ATH9K=m
  1790. +CONFIG_ATH9K_HTC=m
  1791. +CONFIG_CARL9170=m
  1792. +CONFIG_B43=m
  1793. +CONFIG_B43LEGACY=m
  1794. +CONFIG_HOSTAP=m
  1795. +CONFIG_IWM=m
  1796. +CONFIG_LIBERTAS=m
  1797. +CONFIG_LIBERTAS_USB=m
  1798. +CONFIG_LIBERTAS_SDIO=m
  1799. +CONFIG_P54_COMMON=m
  1800. +CONFIG_P54_USB=m
  1801. +CONFIG_RT2X00=m
  1802. +CONFIG_RT2500USB=m
  1803. +CONFIG_RT73USB=m
  1804. +CONFIG_RT2800USB=m
  1805. +CONFIG_RT2800USB_RT53XX=y
  1806. +CONFIG_RTL8192CU=m
  1807. +CONFIG_WL1251=m
  1808. +CONFIG_WL12XX_MENU=m
  1809. +CONFIG_ZD1211RW=m
  1810. +CONFIG_MWIFIEX=m
  1811. +CONFIG_MWIFIEX_SDIO=m
  1812. +CONFIG_WIMAX_I2400M_USB=m
  1813. +CONFIG_USB_CATC=m
  1814. +CONFIG_USB_KAWETH=m
  1815. +CONFIG_USB_PEGASUS=m
  1816. +CONFIG_USB_RTL8150=m
  1817. +CONFIG_USB_USBNET=y
  1818. +CONFIG_USB_NET_AX8817X=m
  1819. +CONFIG_USB_NET_CDCETHER=m
  1820. +CONFIG_USB_NET_CDC_EEM=m
  1821. +CONFIG_USB_NET_DM9601=m
  1822. +CONFIG_USB_NET_SMSC75XX=m
  1823. +CONFIG_USB_NET_SMSC95XX=y
  1824. +CONFIG_USB_NET_GL620A=m
  1825. +CONFIG_USB_NET_NET1080=m
  1826. +CONFIG_USB_NET_PLUSB=m
  1827. +CONFIG_USB_NET_MCS7830=m
  1828. +CONFIG_USB_NET_CDC_SUBSET=m
  1829. +CONFIG_USB_ALI_M5632=y
  1830. +CONFIG_USB_AN2720=y
  1831. +CONFIG_USB_KC2190=y
  1832. +# CONFIG_USB_NET_ZAURUS is not set
  1833. +CONFIG_USB_NET_CX82310_ETH=m
  1834. +CONFIG_USB_NET_KALMIA=m
  1835. +CONFIG_USB_NET_INT51X1=m
  1836. +CONFIG_USB_IPHETH=m
  1837. +CONFIG_USB_SIERRA_NET=m
  1838. +CONFIG_USB_VL600=m
  1839. +CONFIG_PPP=m
  1840. +CONFIG_PPP_ASYNC=m
  1841. +CONFIG_PPP_SYNC_TTY=m
  1842. +CONFIG_PPP_DEFLATE=m
  1843. +CONFIG_PPP_BSDCOMP=m
  1844. +CONFIG_SLIP=m
  1845. +CONFIG_SLIP_COMPRESSED=y
  1846. +CONFIG_NETCONSOLE=m
  1847. +CONFIG_INPUT_POLLDEV=m
  1848. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1849. +CONFIG_INPUT_JOYDEV=m
  1850. +CONFIG_INPUT_EVDEV=m
  1851. +# CONFIG_INPUT_KEYBOARD is not set
  1852. +# CONFIG_INPUT_MOUSE is not set
  1853. +CONFIG_INPUT_MISC=y
  1854. +CONFIG_INPUT_AD714X=m
  1855. +CONFIG_INPUT_ATI_REMOTE=m
  1856. +CONFIG_INPUT_ATI_REMOTE2=m
  1857. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1858. +CONFIG_INPUT_POWERMATE=m
  1859. +CONFIG_INPUT_YEALINK=m
  1860. +CONFIG_INPUT_CM109=m
  1861. +CONFIG_INPUT_UINPUT=m
  1862. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1863. +CONFIG_INPUT_ADXL34X=m
  1864. +CONFIG_INPUT_CMA3000=m
  1865. +CONFIG_SERIO=m
  1866. +CONFIG_SERIO_RAW=m
  1867. +CONFIG_GAMEPORT=m
  1868. +CONFIG_GAMEPORT_NS558=m
  1869. +CONFIG_GAMEPORT_L4=m
  1870. +CONFIG_VT_HW_CONSOLE_BINDING=y
  1871. +# CONFIG_LEGACY_PTYS is not set
  1872. +# CONFIG_DEVKMEM is not set
  1873. +CONFIG_SERIAL_AMBA_PL011=y
  1874. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1875. +# CONFIG_HW_RANDOM is not set
  1876. +CONFIG_RAW_DRIVER=y
  1877. +CONFIG_GPIO_SYSFS=y
  1878. +# CONFIG_HWMON is not set
  1879. +CONFIG_WATCHDOG=y
  1880. +CONFIG_BCM2708_WDT=m
  1881. +# CONFIG_MFD_SUPPORT is not set
  1882. +CONFIG_FB=y
  1883. +CONFIG_FB_BCM2708=y
  1884. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1885. +CONFIG_LOGO=y
  1886. +# CONFIG_LOGO_LINUX_MONO is not set
  1887. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1888. +CONFIG_SOUND=y
  1889. +CONFIG_SND=m
  1890. +CONFIG_SND_SEQUENCER=m
  1891. +CONFIG_SND_SEQ_DUMMY=m
  1892. +CONFIG_SND_MIXER_OSS=m
  1893. +CONFIG_SND_PCM_OSS=m
  1894. +CONFIG_SND_SEQUENCER_OSS=y
  1895. +CONFIG_SND_HRTIMER=m
  1896. +CONFIG_SND_DUMMY=m
  1897. +CONFIG_SND_ALOOP=m
  1898. +CONFIG_SND_VIRMIDI=m
  1899. +CONFIG_SND_MTPAV=m
  1900. +CONFIG_SND_SERIAL_U16550=m
  1901. +CONFIG_SND_MPU401=m
  1902. +CONFIG_SND_BCM2835=m
  1903. +CONFIG_SND_USB_AUDIO=m
  1904. +CONFIG_SND_USB_UA101=m
  1905. +CONFIG_SND_USB_CAIAQ=m
  1906. +CONFIG_SND_USB_6FIRE=m
  1907. +CONFIG_SOUND_PRIME=m
  1908. +CONFIG_HID_PID=y
  1909. +CONFIG_USB_HIDDEV=y
  1910. +CONFIG_HID_A4TECH=m
  1911. +CONFIG_HID_ACRUX=m
  1912. +CONFIG_HID_APPLE=m
  1913. +CONFIG_HID_BELKIN=m
  1914. +CONFIG_HID_CHERRY=m
  1915. +CONFIG_HID_CHICONY=m
  1916. +CONFIG_HID_CYPRESS=m
  1917. +CONFIG_HID_DRAGONRISE=m
  1918. +CONFIG_HID_EMS_FF=m
  1919. +CONFIG_HID_ELECOM=m
  1920. +CONFIG_HID_EZKEY=m
  1921. +CONFIG_HID_HOLTEK=m
  1922. +CONFIG_HID_KEYTOUCH=m
  1923. +CONFIG_HID_KYE=m
  1924. +CONFIG_HID_UCLOGIC=m
  1925. +CONFIG_HID_WALTOP=m
  1926. +CONFIG_HID_GYRATION=m
  1927. +CONFIG_HID_TWINHAN=m
  1928. +CONFIG_HID_KENSINGTON=m
  1929. +CONFIG_HID_LCPOWER=m
  1930. +CONFIG_HID_LOGITECH=m
  1931. +CONFIG_HID_MAGICMOUSE=m
  1932. +CONFIG_HID_MICROSOFT=m
  1933. +CONFIG_HID_MONTEREY=m
  1934. +CONFIG_HID_MULTITOUCH=m
  1935. +CONFIG_HID_NTRIG=m
  1936. +CONFIG_HID_ORTEK=m
  1937. +CONFIG_HID_PANTHERLORD=m
  1938. +CONFIG_HID_PETALYNX=m
  1939. +CONFIG_HID_PICOLCD=m
  1940. +CONFIG_HID_QUANTA=m
  1941. +CONFIG_HID_ROCCAT=m
  1942. +CONFIG_HID_SAMSUNG=m
  1943. +CONFIG_HID_SONY=m
  1944. +CONFIG_HID_SPEEDLINK=m
  1945. +CONFIG_HID_SUNPLUS=m
  1946. +CONFIG_HID_GREENASIA=m
  1947. +CONFIG_HID_SMARTJOYPLUS=m
  1948. +CONFIG_HID_TOPSEED=m
  1949. +CONFIG_HID_THRUSTMASTER=m
  1950. +CONFIG_HID_WACOM=m
  1951. +CONFIG_HID_WIIMOTE=m
  1952. +CONFIG_HID_ZEROPLUS=m
  1953. +CONFIG_HID_ZYDACRON=m
  1954. +CONFIG_USB=y
  1955. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1956. +CONFIG_USB_MON=m
  1957. +CONFIG_USB_DWCOTG=y
  1958. +CONFIG_USB_STORAGE=y
  1959. +CONFIG_USB_STORAGE_REALTEK=m
  1960. +CONFIG_USB_STORAGE_DATAFAB=m
  1961. +CONFIG_USB_STORAGE_FREECOM=m
  1962. +CONFIG_USB_STORAGE_ISD200=m
  1963. +CONFIG_USB_STORAGE_USBAT=m
  1964. +CONFIG_USB_STORAGE_SDDR09=m
  1965. +CONFIG_USB_STORAGE_SDDR55=m
  1966. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1967. +CONFIG_USB_STORAGE_ALAUDA=m
  1968. +CONFIG_USB_STORAGE_ONETOUCH=m
  1969. +CONFIG_USB_STORAGE_KARMA=m
  1970. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1971. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1972. +CONFIG_USB_UAS=y
  1973. +CONFIG_USB_LIBUSUAL=y
  1974. +CONFIG_USB_MDC800=m
  1975. +CONFIG_USB_MICROTEK=m
  1976. +CONFIG_USB_SERIAL=m
  1977. +CONFIG_USB_SERIAL_GENERIC=y
  1978. +CONFIG_USB_SERIAL_AIRCABLE=m
  1979. +CONFIG_USB_SERIAL_ARK3116=m
  1980. +CONFIG_USB_SERIAL_BELKIN=m
  1981. +CONFIG_USB_SERIAL_CH341=m
  1982. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1983. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1984. +CONFIG_USB_SERIAL_CP210X=m
  1985. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1986. +CONFIG_USB_SERIAL_EMPEG=m
  1987. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1988. +CONFIG_USB_SERIAL_FUNSOFT=m
  1989. +CONFIG_USB_SERIAL_VISOR=m
  1990. +CONFIG_USB_SERIAL_IPAQ=m
  1991. +CONFIG_USB_SERIAL_IR=m
  1992. +CONFIG_USB_SERIAL_EDGEPORT=m
  1993. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1994. +CONFIG_USB_SERIAL_GARMIN=m
  1995. +CONFIG_USB_SERIAL_IPW=m
  1996. +CONFIG_USB_SERIAL_IUU=m
  1997. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1998. +CONFIG_USB_SERIAL_KEYSPAN=m
  1999. +CONFIG_USB_SERIAL_KLSI=m
  2000. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  2001. +CONFIG_USB_SERIAL_MCT_U232=m
  2002. +CONFIG_USB_SERIAL_MOS7720=m
  2003. +CONFIG_USB_SERIAL_MOS7840=m
  2004. +CONFIG_USB_SERIAL_MOTOROLA=m
  2005. +CONFIG_USB_SERIAL_NAVMAN=m
  2006. +CONFIG_USB_SERIAL_PL2303=m
  2007. +CONFIG_USB_SERIAL_OTI6858=m
  2008. +CONFIG_USB_SERIAL_QCAUX=m
  2009. +CONFIG_USB_SERIAL_QUALCOMM=m
  2010. +CONFIG_USB_SERIAL_SPCP8X5=m
  2011. +CONFIG_USB_SERIAL_HP4X=m
  2012. +CONFIG_USB_SERIAL_SAFE=m
  2013. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  2014. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  2015. +CONFIG_USB_SERIAL_SYMBOL=m
  2016. +CONFIG_USB_SERIAL_TI=m
  2017. +CONFIG_USB_SERIAL_CYBERJACK=m
  2018. +CONFIG_USB_SERIAL_XIRCOM=m
  2019. +CONFIG_USB_SERIAL_OPTION=m
  2020. +CONFIG_USB_SERIAL_OMNINET=m
  2021. +CONFIG_USB_SERIAL_OPTICON=m
  2022. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  2023. +CONFIG_USB_SERIAL_ZIO=m
  2024. +CONFIG_USB_SERIAL_SSU100=m
  2025. +CONFIG_USB_SERIAL_DEBUG=m
  2026. +CONFIG_USB_EMI62=m
  2027. +CONFIG_USB_EMI26=m
  2028. +CONFIG_USB_ADUTUX=m
  2029. +CONFIG_USB_SEVSEG=m
  2030. +CONFIG_USB_RIO500=m
  2031. +CONFIG_USB_LEGOTOWER=m
  2032. +CONFIG_USB_LCD=m
  2033. +CONFIG_USB_LED=m
  2034. +CONFIG_USB_CYPRESS_CY7C63=m
  2035. +CONFIG_USB_CYTHERM=m
  2036. +CONFIG_USB_IDMOUSE=m
  2037. +CONFIG_USB_FTDI_ELAN=m
  2038. +CONFIG_USB_APPLEDISPLAY=m
  2039. +CONFIG_USB_LD=m
  2040. +CONFIG_USB_TRANCEVIBRATOR=m
  2041. +CONFIG_USB_IOWARRIOR=m
  2042. +CONFIG_USB_TEST=m
  2043. +CONFIG_USB_ISIGHTFW=m
  2044. +CONFIG_USB_YUREX=m
  2045. +CONFIG_MMC=y
  2046. +CONFIG_MMC_SDHCI=y
  2047. +CONFIG_MMC_SDHCI_PLTFM=y
  2048. +CONFIG_MMC_SDHCI_BCM2708=y
  2049. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2050. +CONFIG_LEDS_GPIO=y
  2051. +CONFIG_LEDS_TRIGGER_TIMER=m
  2052. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  2053. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  2054. +CONFIG_UIO=m
  2055. +CONFIG_UIO_PDRV=m
  2056. +CONFIG_UIO_PDRV_GENIRQ=m
  2057. +# CONFIG_IOMMU_SUPPORT is not set
  2058. +CONFIG_EXT4_FS=y
  2059. +CONFIG_EXT4_FS_POSIX_ACL=y
  2060. +CONFIG_EXT4_FS_SECURITY=y
  2061. +CONFIG_REISERFS_FS=m
  2062. +CONFIG_REISERFS_FS_XATTR=y
  2063. +CONFIG_REISERFS_FS_POSIX_ACL=y
  2064. +CONFIG_REISERFS_FS_SECURITY=y
  2065. +CONFIG_JFS_FS=m
  2066. +CONFIG_JFS_POSIX_ACL=y
  2067. +CONFIG_JFS_SECURITY=y
  2068. +CONFIG_JFS_STATISTICS=y
  2069. +CONFIG_XFS_FS=m
  2070. +CONFIG_XFS_QUOTA=y
  2071. +CONFIG_XFS_POSIX_ACL=y
  2072. +CONFIG_XFS_RT=y
  2073. +CONFIG_GFS2_FS=m
  2074. +CONFIG_OCFS2_FS=m
  2075. +CONFIG_BTRFS_FS=m
  2076. +CONFIG_BTRFS_FS_POSIX_ACL=y
  2077. +CONFIG_NILFS2_FS=m
  2078. +CONFIG_FANOTIFY=y
  2079. +CONFIG_AUTOFS4_FS=y
  2080. +CONFIG_FUSE_FS=m
  2081. +CONFIG_CUSE=m
  2082. +CONFIG_FSCACHE=y
  2083. +CONFIG_FSCACHE_STATS=y
  2084. +CONFIG_FSCACHE_HISTOGRAM=y
  2085. +CONFIG_CACHEFILES=y
  2086. +CONFIG_ISO9660_FS=m
  2087. +CONFIG_JOLIET=y
  2088. +CONFIG_ZISOFS=y
  2089. +CONFIG_UDF_FS=m
  2090. +CONFIG_MSDOS_FS=y
  2091. +CONFIG_VFAT_FS=y
  2092. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2093. +CONFIG_NTFS_FS=m
  2094. +CONFIG_TMPFS=y
  2095. +CONFIG_TMPFS_POSIX_ACL=y
  2096. +CONFIG_CONFIGFS_FS=y
  2097. +CONFIG_SQUASHFS=m
  2098. +CONFIG_SQUASHFS_XATTR=y
  2099. +CONFIG_SQUASHFS_LZO=y
  2100. +CONFIG_SQUASHFS_XZ=y
  2101. +CONFIG_NFS_FS=y
  2102. +CONFIG_NFS_V3=y
  2103. +CONFIG_NFS_V3_ACL=y
  2104. +CONFIG_NFS_V4=y
  2105. +CONFIG_ROOT_NFS=y
  2106. +CONFIG_NFS_FSCACHE=y
  2107. +CONFIG_CIFS=m
  2108. +CONFIG_CIFS_WEAK_PW_HASH=y
  2109. +CONFIG_CIFS_XATTR=y
  2110. +CONFIG_CIFS_POSIX=y
  2111. +CONFIG_9P_FS=m
  2112. +CONFIG_9P_FS_POSIX_ACL=y
  2113. +CONFIG_PARTITION_ADVANCED=y
  2114. +CONFIG_MAC_PARTITION=y
  2115. +CONFIG_EFI_PARTITION=y
  2116. +CONFIG_NLS_DEFAULT="utf8"
  2117. +CONFIG_NLS_CODEPAGE_437=y
  2118. +CONFIG_NLS_CODEPAGE_737=m
  2119. +CONFIG_NLS_CODEPAGE_775=m
  2120. +CONFIG_NLS_CODEPAGE_850=m
  2121. +CONFIG_NLS_CODEPAGE_852=m
  2122. +CONFIG_NLS_CODEPAGE_855=m
  2123. +CONFIG_NLS_CODEPAGE_857=m
  2124. +CONFIG_NLS_CODEPAGE_860=m
  2125. +CONFIG_NLS_CODEPAGE_861=m
  2126. +CONFIG_NLS_CODEPAGE_862=m
  2127. +CONFIG_NLS_CODEPAGE_863=m
  2128. +CONFIG_NLS_CODEPAGE_864=m
  2129. +CONFIG_NLS_CODEPAGE_865=m
  2130. +CONFIG_NLS_CODEPAGE_866=m
  2131. +CONFIG_NLS_CODEPAGE_869=m
  2132. +CONFIG_NLS_CODEPAGE_936=m
  2133. +CONFIG_NLS_CODEPAGE_950=m
  2134. +CONFIG_NLS_CODEPAGE_932=m
  2135. +CONFIG_NLS_CODEPAGE_949=m
  2136. +CONFIG_NLS_CODEPAGE_874=m
  2137. +CONFIG_NLS_ISO8859_8=m
  2138. +CONFIG_NLS_CODEPAGE_1250=m
  2139. +CONFIG_NLS_CODEPAGE_1251=m
  2140. +CONFIG_NLS_ASCII=y
  2141. +CONFIG_NLS_ISO8859_1=m
  2142. +CONFIG_NLS_ISO8859_2=m
  2143. +CONFIG_NLS_ISO8859_3=m
  2144. +CONFIG_NLS_ISO8859_4=m
  2145. +CONFIG_NLS_ISO8859_5=m
  2146. +CONFIG_NLS_ISO8859_6=m
  2147. +CONFIG_NLS_ISO8859_7=m
  2148. +CONFIG_NLS_ISO8859_9=m
  2149. +CONFIG_NLS_ISO8859_13=m
  2150. +CONFIG_NLS_ISO8859_14=m
  2151. +CONFIG_NLS_ISO8859_15=m
  2152. +CONFIG_NLS_KOI8_R=m
  2153. +CONFIG_NLS_KOI8_U=m
  2154. +CONFIG_NLS_UTF8=m
  2155. +CONFIG_PRINTK_TIME=y
  2156. +CONFIG_DETECT_HUNG_TASK=y
  2157. +CONFIG_TIMER_STATS=y
  2158. +CONFIG_DEBUG_STACK_USAGE=y
  2159. +CONFIG_DEBUG_INFO=y
  2160. +CONFIG_DEBUG_MEMORY_INIT=y
  2161. +CONFIG_BOOT_PRINTK_DELAY=y
  2162. +CONFIG_LATENCYTOP=y
  2163. +CONFIG_SYSCTL_SYSCALL_CHECK=y
  2164. +CONFIG_IRQSOFF_TRACER=y
  2165. +CONFIG_SCHED_TRACER=y
  2166. +CONFIG_STACK_TRACER=y
  2167. +CONFIG_BLK_DEV_IO_TRACE=y
  2168. +CONFIG_FUNCTION_PROFILER=y
  2169. +CONFIG_KGDB=y
  2170. +CONFIG_KGDB_KDB=y
  2171. +CONFIG_KDB_KEYBOARD=y
  2172. +CONFIG_STRICT_DEVMEM=y
  2173. +CONFIG_CRYPTO_AUTHENC=m
  2174. +CONFIG_CRYPTO_SEQIV=m
  2175. +CONFIG_CRYPTO_CBC=y
  2176. +CONFIG_CRYPTO_HMAC=y
  2177. +CONFIG_CRYPTO_XCBC=m
  2178. +CONFIG_CRYPTO_MD5=y
  2179. +CONFIG_CRYPTO_SHA1=y
  2180. +CONFIG_CRYPTO_SHA256=m
  2181. +CONFIG_CRYPTO_SHA512=m
  2182. +CONFIG_CRYPTO_TGR192=m
  2183. +CONFIG_CRYPTO_WP512=m
  2184. +CONFIG_CRYPTO_CAST5=m
  2185. +CONFIG_CRYPTO_DES=y
  2186. +CONFIG_CRYPTO_DEFLATE=m
  2187. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2188. +# CONFIG_CRYPTO_HW is not set
  2189. +CONFIG_CRC_ITU_T=y
  2190. +CONFIG_LIBCRC32C=y
  2191. diff -Nur linux-3.12.18/arch/arm/configs/bcmrpi_quick_defconfig linux-rpi/arch/arm/configs/bcmrpi_quick_defconfig
  2192. --- linux-3.12.18/arch/arm/configs/bcmrpi_quick_defconfig 1970-01-01 01:00:00.000000000 +0100
  2193. +++ linux-rpi/arch/arm/configs/bcmrpi_quick_defconfig 2014-04-24 15:35:00.717527267 +0200
  2194. @@ -0,0 +1,197 @@
  2195. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2196. +CONFIG_LOCALVERSION="-quick"
  2197. +# CONFIG_LOCALVERSION_AUTO is not set
  2198. +# CONFIG_SWAP is not set
  2199. +CONFIG_SYSVIPC=y
  2200. +CONFIG_POSIX_MQUEUE=y
  2201. +CONFIG_NO_HZ=y
  2202. +CONFIG_HIGH_RES_TIMERS=y
  2203. +CONFIG_IKCONFIG=y
  2204. +CONFIG_IKCONFIG_PROC=y
  2205. +CONFIG_KALLSYMS_ALL=y
  2206. +CONFIG_EMBEDDED=y
  2207. +CONFIG_PERF_EVENTS=y
  2208. +# CONFIG_COMPAT_BRK is not set
  2209. +CONFIG_SLAB=y
  2210. +CONFIG_MODULES=y
  2211. +CONFIG_MODULE_UNLOAD=y
  2212. +CONFIG_MODVERSIONS=y
  2213. +CONFIG_MODULE_SRCVERSION_ALL=y
  2214. +# CONFIG_BLK_DEV_BSG is not set
  2215. +CONFIG_ARCH_BCM2708=y
  2216. +CONFIG_PREEMPT=y
  2217. +CONFIG_AEABI=y
  2218. +CONFIG_UACCESS_WITH_MEMCPY=y
  2219. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2220. +CONFIG_ZBOOT_ROM_BSS=0x0
  2221. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2222. +CONFIG_CPU_FREQ=y
  2223. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  2224. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  2225. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  2226. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  2227. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  2228. +CONFIG_CPU_IDLE=y
  2229. +CONFIG_VFP=y
  2230. +CONFIG_BINFMT_MISC=y
  2231. +CONFIG_NET=y
  2232. +CONFIG_PACKET=y
  2233. +CONFIG_UNIX=y
  2234. +CONFIG_INET=y
  2235. +CONFIG_IP_MULTICAST=y
  2236. +CONFIG_IP_PNP=y
  2237. +CONFIG_IP_PNP_DHCP=y
  2238. +CONFIG_IP_PNP_RARP=y
  2239. +CONFIG_SYN_COOKIES=y
  2240. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  2241. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  2242. +# CONFIG_INET_XFRM_MODE_BEET is not set
  2243. +# CONFIG_INET_LRO is not set
  2244. +# CONFIG_INET_DIAG is not set
  2245. +# CONFIG_IPV6 is not set
  2246. +# CONFIG_WIRELESS is not set
  2247. +CONFIG_DEVTMPFS=y
  2248. +CONFIG_DEVTMPFS_MOUNT=y
  2249. +CONFIG_BLK_DEV_LOOP=y
  2250. +CONFIG_BLK_DEV_RAM=y
  2251. +CONFIG_SCSI=y
  2252. +# CONFIG_SCSI_PROC_FS is not set
  2253. +# CONFIG_SCSI_LOWLEVEL is not set
  2254. +CONFIG_NETDEVICES=y
  2255. +# CONFIG_NET_VENDOR_BROADCOM is not set
  2256. +# CONFIG_NET_VENDOR_CIRRUS is not set
  2257. +# CONFIG_NET_VENDOR_FARADAY is not set
  2258. +# CONFIG_NET_VENDOR_INTEL is not set
  2259. +# CONFIG_NET_VENDOR_MARVELL is not set
  2260. +# CONFIG_NET_VENDOR_MICREL is not set
  2261. +# CONFIG_NET_VENDOR_NATSEMI is not set
  2262. +# CONFIG_NET_VENDOR_SEEQ is not set
  2263. +# CONFIG_NET_VENDOR_STMICRO is not set
  2264. +# CONFIG_NET_VENDOR_WIZNET is not set
  2265. +CONFIG_USB_USBNET=y
  2266. +# CONFIG_USB_NET_AX8817X is not set
  2267. +# CONFIG_USB_NET_CDCETHER is not set
  2268. +# CONFIG_USB_NET_CDC_NCM is not set
  2269. +CONFIG_USB_NET_SMSC95XX=y
  2270. +# CONFIG_USB_NET_NET1080 is not set
  2271. +# CONFIG_USB_NET_CDC_SUBSET is not set
  2272. +# CONFIG_USB_NET_ZAURUS is not set
  2273. +# CONFIG_WLAN is not set
  2274. +# CONFIG_INPUT_MOUSEDEV is not set
  2275. +CONFIG_INPUT_EVDEV=y
  2276. +# CONFIG_INPUT_KEYBOARD is not set
  2277. +# CONFIG_INPUT_MOUSE is not set
  2278. +# CONFIG_SERIO is not set
  2279. +CONFIG_VT_HW_CONSOLE_BINDING=y
  2280. +# CONFIG_LEGACY_PTYS is not set
  2281. +# CONFIG_DEVKMEM is not set
  2282. +CONFIG_SERIAL_AMBA_PL011=y
  2283. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2284. +CONFIG_TTY_PRINTK=y
  2285. +CONFIG_HW_RANDOM=y
  2286. +CONFIG_HW_RANDOM_BCM2708=y
  2287. +CONFIG_RAW_DRIVER=y
  2288. +CONFIG_THERMAL=y
  2289. +CONFIG_THERMAL_BCM2835=y
  2290. +CONFIG_WATCHDOG=y
  2291. +CONFIG_BCM2708_WDT=y
  2292. +CONFIG_REGULATOR=y
  2293. +CONFIG_REGULATOR_DEBUG=y
  2294. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  2295. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  2296. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  2297. +CONFIG_FB=y
  2298. +CONFIG_FB_BCM2708=y
  2299. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2300. +CONFIG_LOGO=y
  2301. +# CONFIG_LOGO_LINUX_MONO is not set
  2302. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2303. +CONFIG_SOUND=y
  2304. +CONFIG_SND=y
  2305. +CONFIG_SND_BCM2835=y
  2306. +# CONFIG_SND_USB is not set
  2307. +CONFIG_USB=y
  2308. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2309. +CONFIG_USB_DWCOTG=y
  2310. +CONFIG_MMC=y
  2311. +CONFIG_MMC_SDHCI=y
  2312. +CONFIG_MMC_SDHCI_PLTFM=y
  2313. +CONFIG_MMC_SDHCI_BCM2708=y
  2314. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2315. +CONFIG_NEW_LEDS=y
  2316. +CONFIG_LEDS_CLASS=y
  2317. +CONFIG_LEDS_TRIGGERS=y
  2318. +# CONFIG_IOMMU_SUPPORT is not set
  2319. +CONFIG_EXT4_FS=y
  2320. +CONFIG_EXT4_FS_POSIX_ACL=y
  2321. +CONFIG_EXT4_FS_SECURITY=y
  2322. +CONFIG_AUTOFS4_FS=y
  2323. +CONFIG_FSCACHE=y
  2324. +CONFIG_CACHEFILES=y
  2325. +CONFIG_MSDOS_FS=y
  2326. +CONFIG_VFAT_FS=y
  2327. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2328. +CONFIG_TMPFS=y
  2329. +CONFIG_TMPFS_POSIX_ACL=y
  2330. +CONFIG_CONFIGFS_FS=y
  2331. +# CONFIG_MISC_FILESYSTEMS is not set
  2332. +CONFIG_NFS_FS=y
  2333. +CONFIG_NFS_V3_ACL=y
  2334. +CONFIG_NFS_V4=y
  2335. +CONFIG_ROOT_NFS=y
  2336. +CONFIG_NFS_FSCACHE=y
  2337. +CONFIG_NLS_DEFAULT="utf8"
  2338. +CONFIG_NLS_CODEPAGE_437=y
  2339. +CONFIG_NLS_CODEPAGE_737=y
  2340. +CONFIG_NLS_CODEPAGE_775=y
  2341. +CONFIG_NLS_CODEPAGE_850=y
  2342. +CONFIG_NLS_CODEPAGE_852=y
  2343. +CONFIG_NLS_CODEPAGE_855=y
  2344. +CONFIG_NLS_CODEPAGE_857=y
  2345. +CONFIG_NLS_CODEPAGE_860=y
  2346. +CONFIG_NLS_CODEPAGE_861=y
  2347. +CONFIG_NLS_CODEPAGE_862=y
  2348. +CONFIG_NLS_CODEPAGE_863=y
  2349. +CONFIG_NLS_CODEPAGE_864=y
  2350. +CONFIG_NLS_CODEPAGE_865=y
  2351. +CONFIG_NLS_CODEPAGE_866=y
  2352. +CONFIG_NLS_CODEPAGE_869=y
  2353. +CONFIG_NLS_CODEPAGE_936=y
  2354. +CONFIG_NLS_CODEPAGE_950=y
  2355. +CONFIG_NLS_CODEPAGE_932=y
  2356. +CONFIG_NLS_CODEPAGE_949=y
  2357. +CONFIG_NLS_CODEPAGE_874=y
  2358. +CONFIG_NLS_ISO8859_8=y
  2359. +CONFIG_NLS_CODEPAGE_1250=y
  2360. +CONFIG_NLS_CODEPAGE_1251=y
  2361. +CONFIG_NLS_ASCII=y
  2362. +CONFIG_NLS_ISO8859_1=y
  2363. +CONFIG_NLS_ISO8859_2=y
  2364. +CONFIG_NLS_ISO8859_3=y
  2365. +CONFIG_NLS_ISO8859_4=y
  2366. +CONFIG_NLS_ISO8859_5=y
  2367. +CONFIG_NLS_ISO8859_6=y
  2368. +CONFIG_NLS_ISO8859_7=y
  2369. +CONFIG_NLS_ISO8859_9=y
  2370. +CONFIG_NLS_ISO8859_13=y
  2371. +CONFIG_NLS_ISO8859_14=y
  2372. +CONFIG_NLS_ISO8859_15=y
  2373. +CONFIG_NLS_UTF8=y
  2374. +CONFIG_PRINTK_TIME=y
  2375. +CONFIG_DEBUG_FS=y
  2376. +CONFIG_DETECT_HUNG_TASK=y
  2377. +# CONFIG_DEBUG_PREEMPT is not set
  2378. +# CONFIG_DEBUG_BUGVERBOSE is not set
  2379. +# CONFIG_FTRACE is not set
  2380. +CONFIG_KGDB=y
  2381. +CONFIG_KGDB_KDB=y
  2382. +# CONFIG_ARM_UNWIND is not set
  2383. +CONFIG_CRYPTO_CBC=y
  2384. +CONFIG_CRYPTO_HMAC=y
  2385. +CONFIG_CRYPTO_MD5=y
  2386. +CONFIG_CRYPTO_SHA1=y
  2387. +CONFIG_CRYPTO_DES=y
  2388. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2389. +# CONFIG_CRYPTO_HW is not set
  2390. +CONFIG_CRC_ITU_T=y
  2391. +CONFIG_LIBCRC32C=y
  2392. diff -Nur linux-3.12.18/arch/arm/include/asm/irqflags.h linux-rpi/arch/arm/include/asm/irqflags.h
  2393. --- linux-3.12.18/arch/arm/include/asm/irqflags.h 2014-04-18 11:14:28.000000000 +0200
  2394. +++ linux-rpi/arch/arm/include/asm/irqflags.h 2014-04-24 16:04:30.027029552 +0200
  2395. @@ -145,12 +145,22 @@
  2396. }
  2397. /*
  2398. - * restore saved IRQ & FIQ state
  2399. + * restore saved IRQ state
  2400. */
  2401. static inline void arch_local_irq_restore(unsigned long flags)
  2402. {
  2403. - asm volatile(
  2404. - " msr " IRQMASK_REG_NAME_W ", %0 @ local_irq_restore"
  2405. + unsigned long temp = 0;
  2406. + flags &= ~(1 << 6);
  2407. + asm volatile (
  2408. + " mrs %0, cpsr"
  2409. + : "=r" (temp)
  2410. + :
  2411. + : "memory", "cc");
  2412. + /* Preserve FIQ bit */
  2413. + temp &= (1 << 6);
  2414. + flags = flags | temp;
  2415. + asm volatile (
  2416. + " msr cpsr_c, %0 @ local_irq_restore"
  2417. :
  2418. : "r" (flags)
  2419. : "memory", "cc");
  2420. diff -Nur linux-3.12.18/arch/arm/Kconfig linux-rpi/arch/arm/Kconfig
  2421. --- linux-3.12.18/arch/arm/Kconfig 2014-04-18 11:14:28.000000000 +0200
  2422. +++ linux-rpi/arch/arm/Kconfig 2014-04-24 16:04:29.515024597 +0200
  2423. @@ -368,6 +368,24 @@
  2424. This enables support for systems based on Atmel
  2425. AT91RM9200 and AT91SAM9* processors.
  2426. +config ARCH_BCM2708
  2427. + bool "Broadcom BCM2708 family"
  2428. + select CPU_V6
  2429. + select ARM_AMBA
  2430. + select HAVE_CLK
  2431. + select HAVE_SCHED_CLOCK
  2432. + select NEED_MACH_GPIO_H
  2433. + select NEED_MACH_MEMORY_H
  2434. + select CLKDEV_LOOKUP
  2435. + select ARCH_HAS_CPUFREQ
  2436. + select GENERIC_CLOCKEVENTS
  2437. + select ARM_ERRATA_411920
  2438. + select MACH_BCM2708
  2439. + select VC4
  2440. + select FIQ
  2441. + help
  2442. + This enables support for Broadcom BCM2708 boards.
  2443. +
  2444. config ARCH_CLPS711X
  2445. bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
  2446. select ARCH_REQUIRE_GPIOLIB
  2447. @@ -1043,6 +1061,7 @@
  2448. source "arch/arm/mach-vt8500/Kconfig"
  2449. source "arch/arm/mach-w90x900/Kconfig"
  2450. +source "arch/arm/mach-bcm2708/Kconfig"
  2451. source "arch/arm/mach-zynq/Kconfig"
  2452. diff -Nur linux-3.12.18/arch/arm/Kconfig.debug linux-rpi/arch/arm/Kconfig.debug
  2453. --- linux-3.12.18/arch/arm/Kconfig.debug 2014-04-18 11:14:28.000000000 +0200
  2454. +++ linux-rpi/arch/arm/Kconfig.debug 2014-04-24 16:04:29.515024597 +0200
  2455. @@ -847,6 +847,14 @@
  2456. options; the platform specific options are deprecated
  2457. and will be soon removed.
  2458. + config DEBUG_BCM2708_UART0
  2459. + bool "Broadcom BCM2708 UART0 (PL011)"
  2460. + depends on MACH_BCM2708
  2461. + help
  2462. + Say Y here if you want the debug print routines to direct
  2463. + their output to UART 0. The port must have been initialised
  2464. + by the boot-loader before use.
  2465. +
  2466. endchoice
  2467. config DEBUG_EXYNOS_UART
  2468. diff -Nur linux-3.12.18/arch/arm/kernel/fiqasm.S linux-rpi/arch/arm/kernel/fiqasm.S
  2469. --- linux-3.12.18/arch/arm/kernel/fiqasm.S 2014-04-18 11:14:28.000000000 +0200
  2470. +++ linux-rpi/arch/arm/kernel/fiqasm.S 2014-04-24 16:04:30.039029668 +0200
  2471. @@ -47,3 +47,7 @@
  2472. mov r0, r0 @ avoid hazard prior to ARMv4
  2473. mov pc, lr
  2474. ENDPROC(__get_fiq_regs)
  2475. +
  2476. +ENTRY(__FIQ_Branch)
  2477. + mov pc, r8
  2478. +ENDPROC(__FIQ_Branch)
  2479. diff -Nur linux-3.12.18/arch/arm/kernel/process.c linux-rpi/arch/arm/kernel/process.c
  2480. --- linux-3.12.18/arch/arm/kernel/process.c 2014-04-18 11:14:28.000000000 +0200
  2481. +++ linux-rpi/arch/arm/kernel/process.c 2014-04-24 16:04:30.039029668 +0200
  2482. @@ -176,6 +176,16 @@
  2483. default_idle();
  2484. }
  2485. +char bcm2708_reboot_mode = 'h';
  2486. +
  2487. +int __init reboot_setup(char *str)
  2488. +{
  2489. + bcm2708_reboot_mode = str[0];
  2490. + return 1;
  2491. +}
  2492. +
  2493. +__setup("reboot=", reboot_setup);
  2494. +
  2495. /*
  2496. * Called by kexec, immediately prior to machine_kexec().
  2497. *
  2498. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/armctrl.c linux-rpi/arch/arm/mach-bcm2708/armctrl.c
  2499. --- linux-3.12.18/arch/arm/mach-bcm2708/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  2500. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.c 2014-04-24 15:35:00.773527891 +0200
  2501. @@ -0,0 +1,219 @@
  2502. +/*
  2503. + * linux/arch/arm/mach-bcm2708/armctrl.c
  2504. + *
  2505. + * Copyright (C) 2010 Broadcom
  2506. + *
  2507. + * This program is free software; you can redistribute it and/or modify
  2508. + * it under the terms of the GNU General Public License as published by
  2509. + * the Free Software Foundation; either version 2 of the License, or
  2510. + * (at your option) any later version.
  2511. + *
  2512. + * This program is distributed in the hope that it will be useful,
  2513. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2514. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2515. + * GNU General Public License for more details.
  2516. + *
  2517. + * You should have received a copy of the GNU General Public License
  2518. + * along with this program; if not, write to the Free Software
  2519. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2520. + */
  2521. +#include <linux/init.h>
  2522. +#include <linux/list.h>
  2523. +#include <linux/io.h>
  2524. +#include <linux/version.h>
  2525. +#include <linux/syscore_ops.h>
  2526. +#include <linux/interrupt.h>
  2527. +
  2528. +#include <asm/mach/irq.h>
  2529. +#include <mach/hardware.h>
  2530. +#include "armctrl.h"
  2531. +
  2532. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  2533. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  2534. + INTERRUPT_VC_JPEG,
  2535. + INTERRUPT_VC_USB,
  2536. + INTERRUPT_VC_3D,
  2537. + INTERRUPT_VC_DMA2,
  2538. + INTERRUPT_VC_DMA3,
  2539. + INTERRUPT_VC_I2C,
  2540. + INTERRUPT_VC_SPI,
  2541. + INTERRUPT_VC_I2SPCM,
  2542. + INTERRUPT_VC_SDIO,
  2543. + INTERRUPT_VC_UART,
  2544. + INTERRUPT_VC_ARASANSDIO
  2545. +};
  2546. +
  2547. +static void armctrl_mask_irq(struct irq_data *d)
  2548. +{
  2549. + static const unsigned int disables[4] = {
  2550. + ARM_IRQ_DIBL1,
  2551. + ARM_IRQ_DIBL2,
  2552. + ARM_IRQ_DIBL3,
  2553. + 0
  2554. + };
  2555. +
  2556. + if (d->irq >= FIQ_START) {
  2557. + writel(0, __io_address(ARM_IRQ_FAST));
  2558. + } else {
  2559. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2560. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  2561. + }
  2562. +}
  2563. +
  2564. +static void armctrl_unmask_irq(struct irq_data *d)
  2565. +{
  2566. + static const unsigned int enables[4] = {
  2567. + ARM_IRQ_ENBL1,
  2568. + ARM_IRQ_ENBL2,
  2569. + ARM_IRQ_ENBL3,
  2570. + 0
  2571. + };
  2572. +
  2573. + if (d->irq >= FIQ_START) {
  2574. + unsigned int data =
  2575. + (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  2576. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  2577. + } else {
  2578. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2579. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  2580. + }
  2581. +}
  2582. +
  2583. +#if defined(CONFIG_PM)
  2584. +
  2585. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  2586. +
  2587. +/* Static defines
  2588. + * struct armctrl_device - VIC PM device (< 3.xx)
  2589. + * @sysdev: The system device which is registered. (< 3.xx)
  2590. + * @irq: The IRQ number for the base of the VIC.
  2591. + * @base: The register base for the VIC.
  2592. + * @resume_sources: A bitmask of interrupts for resume.
  2593. + * @resume_irqs: The IRQs enabled for resume.
  2594. + * @int_select: Save for VIC_INT_SELECT.
  2595. + * @int_enable: Save for VIC_INT_ENABLE.
  2596. + * @soft_int: Save for VIC_INT_SOFT.
  2597. + * @protect: Save for VIC_PROTECT.
  2598. + */
  2599. +struct armctrl_info {
  2600. + void __iomem *base;
  2601. + int irq;
  2602. + u32 resume_sources;
  2603. + u32 resume_irqs;
  2604. + u32 int_select;
  2605. + u32 int_enable;
  2606. + u32 soft_int;
  2607. + u32 protect;
  2608. +} armctrl;
  2609. +
  2610. +static int armctrl_suspend(void)
  2611. +{
  2612. + return 0;
  2613. +}
  2614. +
  2615. +static void armctrl_resume(void)
  2616. +{
  2617. + return;
  2618. +}
  2619. +
  2620. +/**
  2621. + * armctrl_pm_register - Register a VIC for later power management control
  2622. + * @base: The base address of the VIC.
  2623. + * @irq: The base IRQ for the VIC.
  2624. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  2625. + *
  2626. + * For older kernels (< 3.xx) do -
  2627. + * Register the VIC with the system device tree so that it can be notified
  2628. + * of suspend and resume requests and ensure that the correct actions are
  2629. + * taken to re-instate the settings on resume.
  2630. + */
  2631. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  2632. + u32 resume_sources)
  2633. +{
  2634. + armctrl.base = base;
  2635. + armctrl.resume_sources = resume_sources;
  2636. + armctrl.irq = irq;
  2637. +}
  2638. +
  2639. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  2640. +{
  2641. + unsigned int off = d->irq & 31;
  2642. + u32 bit = 1 << off;
  2643. +
  2644. + if (!(bit & armctrl.resume_sources))
  2645. + return -EINVAL;
  2646. +
  2647. + if (on)
  2648. + armctrl.resume_irqs |= bit;
  2649. + else
  2650. + armctrl.resume_irqs &= ~bit;
  2651. +
  2652. + return 0;
  2653. +}
  2654. +
  2655. +#else
  2656. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  2657. + u32 arg1)
  2658. +{
  2659. +}
  2660. +
  2661. +#define armctrl_suspend NULL
  2662. +#define armctrl_resume NULL
  2663. +#define armctrl_set_wake NULL
  2664. +#endif /* CONFIG_PM */
  2665. +
  2666. +static struct syscore_ops armctrl_syscore_ops = {
  2667. + .suspend = armctrl_suspend,
  2668. + .resume = armctrl_resume,
  2669. +};
  2670. +
  2671. +/**
  2672. + * armctrl_syscore_init - initicall to register VIC pm functions
  2673. + *
  2674. + * This is called via late_initcall() to register
  2675. + * the resources for the VICs due to the early
  2676. + * nature of the VIC's registration.
  2677. +*/
  2678. +static int __init armctrl_syscore_init(void)
  2679. +{
  2680. + register_syscore_ops(&armctrl_syscore_ops);
  2681. + return 0;
  2682. +}
  2683. +
  2684. +late_initcall(armctrl_syscore_init);
  2685. +
  2686. +static struct irq_chip armctrl_chip = {
  2687. + .name = "ARMCTRL",
  2688. + .irq_ack = armctrl_mask_irq,
  2689. + .irq_mask = armctrl_mask_irq,
  2690. + .irq_unmask = armctrl_unmask_irq,
  2691. + .irq_set_wake = armctrl_set_wake,
  2692. +};
  2693. +
  2694. +/**
  2695. + * armctrl_init - initialise a vectored interrupt controller
  2696. + * @base: iomem base address
  2697. + * @irq_start: starting interrupt number, must be muliple of 32
  2698. + * @armctrl_sources: bitmask of interrupt sources to allow
  2699. + * @resume_sources: bitmask of interrupt sources to allow for resume
  2700. + */
  2701. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2702. + u32 armctrl_sources, u32 resume_sources)
  2703. +{
  2704. + unsigned int irq;
  2705. +
  2706. + for (irq = 0; irq < NR_IRQS; irq++) {
  2707. + unsigned int data = irq;
  2708. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  2709. + data = remap_irqs[irq - INTERRUPT_JPEG];
  2710. +
  2711. + irq_set_chip(irq, &armctrl_chip);
  2712. + irq_set_chip_data(irq, (void *)data);
  2713. + irq_set_handler(irq, handle_level_irq);
  2714. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  2715. + }
  2716. +
  2717. + armctrl_pm_register(base, irq_start, resume_sources);
  2718. + init_FIQ(FIQ_START);
  2719. + return 0;
  2720. +}
  2721. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/armctrl.h linux-rpi/arch/arm/mach-bcm2708/armctrl.h
  2722. --- linux-3.12.18/arch/arm/mach-bcm2708/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  2723. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.h 2014-04-24 15:35:00.773527891 +0200
  2724. @@ -0,0 +1,27 @@
  2725. +/*
  2726. + * linux/arch/arm/mach-bcm2708/armctrl.h
  2727. + *
  2728. + * Copyright (C) 2010 Broadcom
  2729. + *
  2730. + * This program is free software; you can redistribute it and/or modify
  2731. + * it under the terms of the GNU General Public License as published by
  2732. + * the Free Software Foundation; either version 2 of the License, or
  2733. + * (at your option) any later version.
  2734. + *
  2735. + * This program is distributed in the hope that it will be useful,
  2736. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2737. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2738. + * GNU General Public License for more details.
  2739. + *
  2740. + * You should have received a copy of the GNU General Public License
  2741. + * along with this program; if not, write to the Free Software
  2742. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2743. + */
  2744. +
  2745. +#ifndef __BCM2708_ARMCTRL_H
  2746. +#define __BCM2708_ARMCTRL_H
  2747. +
  2748. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2749. + u32 armctrl_sources, u32 resume_sources);
  2750. +
  2751. +#endif
  2752. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/bcm2708.c linux-rpi/arch/arm/mach-bcm2708/bcm2708.c
  2753. --- linux-3.12.18/arch/arm/mach-bcm2708/bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  2754. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.c 2014-04-24 16:04:30.051029784 +0200
  2755. @@ -0,0 +1,1017 @@
  2756. +/*
  2757. + * linux/arch/arm/mach-bcm2708/bcm2708.c
  2758. + *
  2759. + * Copyright (C) 2010 Broadcom
  2760. + *
  2761. + * This program is free software; you can redistribute it and/or modify
  2762. + * it under the terms of the GNU General Public License as published by
  2763. + * the Free Software Foundation; either version 2 of the License, or
  2764. + * (at your option) any later version.
  2765. + *
  2766. + * This program is distributed in the hope that it will be useful,
  2767. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2768. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2769. + * GNU General Public License for more details.
  2770. + *
  2771. + * You should have received a copy of the GNU General Public License
  2772. + * along with this program; if not, write to the Free Software
  2773. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2774. + */
  2775. +
  2776. +#include <linux/init.h>
  2777. +#include <linux/device.h>
  2778. +#include <linux/dma-mapping.h>
  2779. +#include <linux/serial_8250.h>
  2780. +#include <linux/platform_device.h>
  2781. +#include <linux/syscore_ops.h>
  2782. +#include <linux/interrupt.h>
  2783. +#include <linux/amba/bus.h>
  2784. +#include <linux/amba/clcd.h>
  2785. +#include <linux/clockchips.h>
  2786. +#include <linux/cnt32_to_63.h>
  2787. +#include <linux/io.h>
  2788. +#include <linux/module.h>
  2789. +#include <linux/spi/spi.h>
  2790. +#include <linux/w1-gpio.h>
  2791. +
  2792. +#include <linux/version.h>
  2793. +#include <linux/clkdev.h>
  2794. +#include <asm/system.h>
  2795. +#include <mach/hardware.h>
  2796. +#include <asm/irq.h>
  2797. +#include <linux/leds.h>
  2798. +#include <asm/mach-types.h>
  2799. +#include <linux/sched_clock.h>
  2800. +
  2801. +#include <asm/mach/arch.h>
  2802. +#include <asm/mach/flash.h>
  2803. +#include <asm/mach/irq.h>
  2804. +#include <asm/mach/time.h>
  2805. +#include <asm/mach/map.h>
  2806. +
  2807. +#include <mach/timex.h>
  2808. +#include <mach/dma.h>
  2809. +#include <mach/vcio.h>
  2810. +#include <mach/system.h>
  2811. +
  2812. +#include <linux/delay.h>
  2813. +
  2814. +#include "bcm2708.h"
  2815. +#include "armctrl.h"
  2816. +#include "clock.h"
  2817. +
  2818. +#ifdef CONFIG_BCM_VC_CMA
  2819. +#include <linux/broadcom/vc_cma.h>
  2820. +#endif
  2821. +
  2822. +
  2823. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  2824. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  2825. + * represent this window by setting our dmamasks to 26 bits but, in fact
  2826. + * we're not going to use addresses outside this range (they're not in real
  2827. + * memory) so we don't bother.
  2828. + *
  2829. + * In the future we might include code to use this IOMMU to remap other
  2830. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  2831. + * more legitimate.
  2832. + */
  2833. +#define DMA_MASK_BITS_COMMON 32
  2834. +
  2835. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  2836. +#define W1_GPIO 4
  2837. +
  2838. +/* command line parameters */
  2839. +static unsigned boardrev, serial;
  2840. +static unsigned uart_clock;
  2841. +static unsigned disk_led_gpio = 16;
  2842. +static unsigned disk_led_active_low = 1;
  2843. +static unsigned reboot_part = 0;
  2844. +static unsigned w1_gpio_pin = W1_GPIO;
  2845. +
  2846. +static void __init bcm2708_init_led(void);
  2847. +
  2848. +void __init bcm2708_init_irq(void)
  2849. +{
  2850. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  2851. +}
  2852. +
  2853. +static struct map_desc bcm2708_io_desc[] __initdata = {
  2854. + {
  2855. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  2856. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  2857. + .length = SZ_4K,
  2858. + .type = MT_DEVICE},
  2859. + {
  2860. + .virtual = IO_ADDRESS(UART0_BASE),
  2861. + .pfn = __phys_to_pfn(UART0_BASE),
  2862. + .length = SZ_4K,
  2863. + .type = MT_DEVICE},
  2864. + {
  2865. + .virtual = IO_ADDRESS(UART1_BASE),
  2866. + .pfn = __phys_to_pfn(UART1_BASE),
  2867. + .length = SZ_4K,
  2868. + .type = MT_DEVICE},
  2869. + {
  2870. + .virtual = IO_ADDRESS(DMA_BASE),
  2871. + .pfn = __phys_to_pfn(DMA_BASE),
  2872. + .length = SZ_4K,
  2873. + .type = MT_DEVICE},
  2874. + {
  2875. + .virtual = IO_ADDRESS(MCORE_BASE),
  2876. + .pfn = __phys_to_pfn(MCORE_BASE),
  2877. + .length = SZ_4K,
  2878. + .type = MT_DEVICE},
  2879. + {
  2880. + .virtual = IO_ADDRESS(ST_BASE),
  2881. + .pfn = __phys_to_pfn(ST_BASE),
  2882. + .length = SZ_4K,
  2883. + .type = MT_DEVICE},
  2884. + {
  2885. + .virtual = IO_ADDRESS(USB_BASE),
  2886. + .pfn = __phys_to_pfn(USB_BASE),
  2887. + .length = SZ_128K,
  2888. + .type = MT_DEVICE},
  2889. + {
  2890. + .virtual = IO_ADDRESS(PM_BASE),
  2891. + .pfn = __phys_to_pfn(PM_BASE),
  2892. + .length = SZ_4K,
  2893. + .type = MT_DEVICE},
  2894. + {
  2895. + .virtual = IO_ADDRESS(GPIO_BASE),
  2896. + .pfn = __phys_to_pfn(GPIO_BASE),
  2897. + .length = SZ_4K,
  2898. + .type = MT_DEVICE}
  2899. +};
  2900. +
  2901. +void __init bcm2708_map_io(void)
  2902. +{
  2903. + iotable_init(bcm2708_io_desc, ARRAY_SIZE(bcm2708_io_desc));
  2904. +}
  2905. +
  2906. +/* The STC is a free running counter that increments at the rate of 1MHz */
  2907. +#define STC_FREQ_HZ 1000000
  2908. +
  2909. +static inline uint32_t timer_read(void)
  2910. +{
  2911. + /* STC: a free running counter that increments at the rate of 1MHz */
  2912. + return readl(__io_address(ST_BASE + 0x04));
  2913. +}
  2914. +
  2915. +static unsigned long bcm2708_read_current_timer(void)
  2916. +{
  2917. + return timer_read();
  2918. +}
  2919. +
  2920. +static u32 notrace bcm2708_read_sched_clock(void)
  2921. +{
  2922. + return timer_read();
  2923. +}
  2924. +
  2925. +static cycle_t clksrc_read(struct clocksource *cs)
  2926. +{
  2927. + return timer_read();
  2928. +}
  2929. +
  2930. +static struct clocksource clocksource_stc = {
  2931. + .name = "stc",
  2932. + .rating = 300,
  2933. + .read = clksrc_read,
  2934. + .mask = CLOCKSOURCE_MASK(32),
  2935. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  2936. +};
  2937. +
  2938. +unsigned long frc_clock_ticks32(void)
  2939. +{
  2940. + return timer_read();
  2941. +}
  2942. +
  2943. +static void __init bcm2708_clocksource_init(void)
  2944. +{
  2945. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  2946. + printk(KERN_ERR "timer: failed to initialize clock "
  2947. + "source %s\n", clocksource_stc.name);
  2948. + }
  2949. +}
  2950. +
  2951. +
  2952. +/*
  2953. + * These are fixed clocks.
  2954. + */
  2955. +static struct clk ref24_clk = {
  2956. + .rate = UART0_CLOCK, /* The UART is clocked at 3MHz via APB_CLK */
  2957. +};
  2958. +
  2959. +static struct clk osc_clk = {
  2960. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2961. + .rate = 27000000,
  2962. +#else
  2963. + .rate = 500000000, /* ARM clock is set from the VideoCore booter */
  2964. +#endif
  2965. +};
  2966. +
  2967. +/* warning - the USB needs a clock > 34MHz */
  2968. +
  2969. +static struct clk sdhost_clk = {
  2970. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2971. + .rate = 4000000, /* 4MHz */
  2972. +#else
  2973. + .rate = 250000000, /* 250MHz */
  2974. +#endif
  2975. +};
  2976. +
  2977. +static struct clk_lookup lookups[] = {
  2978. + { /* UART0 */
  2979. + .dev_id = "dev:f1",
  2980. + .clk = &ref24_clk,
  2981. + },
  2982. + { /* USB */
  2983. + .dev_id = "bcm2708_usb",
  2984. + .clk = &osc_clk,
  2985. + }, { /* SPI */
  2986. + .dev_id = "bcm2708_spi.0",
  2987. + .clk = &sdhost_clk,
  2988. + }, { /* BSC0 */
  2989. + .dev_id = "bcm2708_i2c.0",
  2990. + .clk = &sdhost_clk,
  2991. + }, { /* BSC1 */
  2992. + .dev_id = "bcm2708_i2c.1",
  2993. + .clk = &sdhost_clk,
  2994. + }
  2995. +};
  2996. +
  2997. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  2998. +#define UART0_DMA { 15, 14 }
  2999. +
  3000. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  3001. +
  3002. +static struct amba_device *amba_devs[] __initdata = {
  3003. + &uart0_device,
  3004. +};
  3005. +
  3006. +static struct resource bcm2708_dmaman_resources[] = {
  3007. + {
  3008. + .start = DMA_BASE,
  3009. + .end = DMA_BASE + SZ_4K - 1,
  3010. + .flags = IORESOURCE_MEM,
  3011. + }
  3012. +};
  3013. +
  3014. +static struct platform_device bcm2708_dmaman_device = {
  3015. + .name = BCM_DMAMAN_DRIVER_NAME,
  3016. + .id = 0, /* first bcm2708_dma */
  3017. + .resource = bcm2708_dmaman_resources,
  3018. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  3019. +};
  3020. +
  3021. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  3022. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  3023. + .pin = W1_GPIO,
  3024. + .is_open_drain = 0,
  3025. +};
  3026. +
  3027. +static struct platform_device w1_device = {
  3028. + .name = "w1-gpio",
  3029. + .id = -1,
  3030. + .dev.platform_data = &w1_gpio_pdata,
  3031. +};
  3032. +#endif
  3033. +
  3034. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3035. +
  3036. +static struct platform_device bcm2708_fb_device = {
  3037. + .name = "bcm2708_fb",
  3038. + .id = -1, /* only one bcm2708_fb */
  3039. + .resource = NULL,
  3040. + .num_resources = 0,
  3041. + .dev = {
  3042. + .dma_mask = &fb_dmamask,
  3043. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3044. + },
  3045. +};
  3046. +
  3047. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  3048. + {
  3049. + .mapbase = UART1_BASE + 0x40,
  3050. + .irq = IRQ_AUX,
  3051. + .uartclk = 125000000,
  3052. + .regshift = 2,
  3053. + .iotype = UPIO_MEM,
  3054. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  3055. + .type = PORT_8250,
  3056. + },
  3057. + {},
  3058. +};
  3059. +
  3060. +static struct platform_device bcm2708_uart1_device = {
  3061. + .name = "serial8250",
  3062. + .id = PLAT8250_DEV_PLATFORM,
  3063. + .dev = {
  3064. + .platform_data = bcm2708_uart1_platform_data,
  3065. + },
  3066. +};
  3067. +
  3068. +static struct resource bcm2708_usb_resources[] = {
  3069. + [0] = {
  3070. + .start = USB_BASE,
  3071. + .end = USB_BASE + SZ_128K - 1,
  3072. + .flags = IORESOURCE_MEM,
  3073. + },
  3074. + [1] = {
  3075. + .start = MPHI_BASE,
  3076. + .end = MPHI_BASE + SZ_4K - 1,
  3077. + .flags = IORESOURCE_MEM,
  3078. + },
  3079. + [2] = {
  3080. + .start = IRQ_HOSTPORT,
  3081. + .end = IRQ_HOSTPORT,
  3082. + .flags = IORESOURCE_IRQ,
  3083. + },
  3084. +};
  3085. +
  3086. +
  3087. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3088. +
  3089. +static struct platform_device bcm2708_usb_device = {
  3090. + .name = "bcm2708_usb",
  3091. + .id = -1, /* only one bcm2708_usb */
  3092. + .resource = bcm2708_usb_resources,
  3093. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  3094. + .dev = {
  3095. + .dma_mask = &usb_dmamask,
  3096. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3097. + },
  3098. +};
  3099. +
  3100. +static struct resource bcm2708_vcio_resources[] = {
  3101. + [0] = { /* mailbox/semaphore/doorbell access */
  3102. + .start = MCORE_BASE,
  3103. + .end = MCORE_BASE + SZ_4K - 1,
  3104. + .flags = IORESOURCE_MEM,
  3105. + },
  3106. +};
  3107. +
  3108. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3109. +
  3110. +static struct platform_device bcm2708_vcio_device = {
  3111. + .name = BCM_VCIO_DRIVER_NAME,
  3112. + .id = -1, /* only one VideoCore I/O area */
  3113. + .resource = bcm2708_vcio_resources,
  3114. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  3115. + .dev = {
  3116. + .dma_mask = &vcio_dmamask,
  3117. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3118. + },
  3119. +};
  3120. +
  3121. +#ifdef CONFIG_BCM2708_GPIO
  3122. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3123. +
  3124. +static struct resource bcm2708_gpio_resources[] = {
  3125. + [0] = { /* general purpose I/O */
  3126. + .start = GPIO_BASE,
  3127. + .end = GPIO_BASE + SZ_4K - 1,
  3128. + .flags = IORESOURCE_MEM,
  3129. + },
  3130. +};
  3131. +
  3132. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3133. +
  3134. +static struct platform_device bcm2708_gpio_device = {
  3135. + .name = BCM_GPIO_DRIVER_NAME,
  3136. + .id = -1, /* only one VideoCore I/O area */
  3137. + .resource = bcm2708_gpio_resources,
  3138. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  3139. + .dev = {
  3140. + .dma_mask = &gpio_dmamask,
  3141. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3142. + },
  3143. +};
  3144. +#endif
  3145. +
  3146. +static struct resource bcm2708_systemtimer_resources[] = {
  3147. + [0] = { /* system timer access */
  3148. + .start = ST_BASE,
  3149. + .end = ST_BASE + SZ_4K - 1,
  3150. + .flags = IORESOURCE_MEM,
  3151. + },
  3152. + {
  3153. + .start = IRQ_TIMER3,
  3154. + .end = IRQ_TIMER3,
  3155. + .flags = IORESOURCE_IRQ,
  3156. + }
  3157. +
  3158. +};
  3159. +
  3160. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3161. +
  3162. +static struct platform_device bcm2708_systemtimer_device = {
  3163. + .name = "bcm2708_systemtimer",
  3164. + .id = -1, /* only one VideoCore I/O area */
  3165. + .resource = bcm2708_systemtimer_resources,
  3166. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  3167. + .dev = {
  3168. + .dma_mask = &systemtimer_dmamask,
  3169. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3170. + },
  3171. +};
  3172. +
  3173. +#ifdef CONFIG_MMC_SDHCI_BCM2708 /* Arasan emmc SD */
  3174. +static struct resource bcm2708_emmc_resources[] = {
  3175. + [0] = {
  3176. + .start = EMMC_BASE,
  3177. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  3178. + /* the memory map actually makes SZ_4K available */
  3179. + .flags = IORESOURCE_MEM,
  3180. + },
  3181. + [1] = {
  3182. + .start = IRQ_ARASANSDIO,
  3183. + .end = IRQ_ARASANSDIO,
  3184. + .flags = IORESOURCE_IRQ,
  3185. + },
  3186. +};
  3187. +
  3188. +static u64 bcm2708_emmc_dmamask = 0xffffffffUL;
  3189. +
  3190. +struct platform_device bcm2708_emmc_device = {
  3191. + .name = "bcm2708_sdhci",
  3192. + .id = 0,
  3193. + .num_resources = ARRAY_SIZE(bcm2708_emmc_resources),
  3194. + .resource = bcm2708_emmc_resources,
  3195. + .dev = {
  3196. + .dma_mask = &bcm2708_emmc_dmamask,
  3197. + .coherent_dma_mask = 0xffffffffUL},
  3198. +};
  3199. +#endif /* CONFIG_MMC_SDHCI_BCM2708 */
  3200. +
  3201. +static struct resource bcm2708_powerman_resources[] = {
  3202. + [0] = {
  3203. + .start = PM_BASE,
  3204. + .end = PM_BASE + SZ_256 - 1,
  3205. + .flags = IORESOURCE_MEM,
  3206. + },
  3207. +};
  3208. +
  3209. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3210. +
  3211. +struct platform_device bcm2708_powerman_device = {
  3212. + .name = "bcm2708_powerman",
  3213. + .id = 0,
  3214. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  3215. + .resource = bcm2708_powerman_resources,
  3216. + .dev = {
  3217. + .dma_mask = &powerman_dmamask,
  3218. + .coherent_dma_mask = 0xffffffffUL},
  3219. +};
  3220. +
  3221. +
  3222. +static struct platform_device bcm2708_alsa_devices[] = {
  3223. + [0] = {
  3224. + .name = "bcm2835_AUD0",
  3225. + .id = 0, /* first audio device */
  3226. + .resource = 0,
  3227. + .num_resources = 0,
  3228. + },
  3229. + [1] = {
  3230. + .name = "bcm2835_AUD1",
  3231. + .id = 1, /* second audio device */
  3232. + .resource = 0,
  3233. + .num_resources = 0,
  3234. + },
  3235. + [2] = {
  3236. + .name = "bcm2835_AUD2",
  3237. + .id = 2, /* third audio device */
  3238. + .resource = 0,
  3239. + .num_resources = 0,
  3240. + },
  3241. + [3] = {
  3242. + .name = "bcm2835_AUD3",
  3243. + .id = 3, /* forth audio device */
  3244. + .resource = 0,
  3245. + .num_resources = 0,
  3246. + },
  3247. + [4] = {
  3248. + .name = "bcm2835_AUD4",
  3249. + .id = 4, /* fifth audio device */
  3250. + .resource = 0,
  3251. + .num_resources = 0,
  3252. + },
  3253. + [5] = {
  3254. + .name = "bcm2835_AUD5",
  3255. + .id = 5, /* sixth audio device */
  3256. + .resource = 0,
  3257. + .num_resources = 0,
  3258. + },
  3259. + [6] = {
  3260. + .name = "bcm2835_AUD6",
  3261. + .id = 6, /* seventh audio device */
  3262. + .resource = 0,
  3263. + .num_resources = 0,
  3264. + },
  3265. + [7] = {
  3266. + .name = "bcm2835_AUD7",
  3267. + .id = 7, /* eighth audio device */
  3268. + .resource = 0,
  3269. + .num_resources = 0,
  3270. + },
  3271. +};
  3272. +
  3273. +static struct resource bcm2708_spi_resources[] = {
  3274. + {
  3275. + .start = SPI0_BASE,
  3276. + .end = SPI0_BASE + SZ_256 - 1,
  3277. + .flags = IORESOURCE_MEM,
  3278. + }, {
  3279. + .start = IRQ_SPI,
  3280. + .end = IRQ_SPI,
  3281. + .flags = IORESOURCE_IRQ,
  3282. + }
  3283. +};
  3284. +
  3285. +
  3286. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3287. +static struct platform_device bcm2708_spi_device = {
  3288. + .name = "bcm2708_spi",
  3289. + .id = 0,
  3290. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  3291. + .resource = bcm2708_spi_resources,
  3292. + .dev = {
  3293. + .dma_mask = &bcm2708_spi_dmamask,
  3294. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  3295. +};
  3296. +
  3297. +#ifdef CONFIG_BCM2708_SPIDEV
  3298. +static struct spi_board_info bcm2708_spi_devices[] = {
  3299. +#ifdef CONFIG_SPI_SPIDEV
  3300. + {
  3301. + .modalias = "spidev",
  3302. + .max_speed_hz = 500000,
  3303. + .bus_num = 0,
  3304. + .chip_select = 0,
  3305. + .mode = SPI_MODE_0,
  3306. + }, {
  3307. + .modalias = "spidev",
  3308. + .max_speed_hz = 500000,
  3309. + .bus_num = 0,
  3310. + .chip_select = 1,
  3311. + .mode = SPI_MODE_0,
  3312. + }
  3313. +#endif
  3314. +};
  3315. +#endif
  3316. +
  3317. +static struct resource bcm2708_bsc0_resources[] = {
  3318. + {
  3319. + .start = BSC0_BASE,
  3320. + .end = BSC0_BASE + SZ_256 - 1,
  3321. + .flags = IORESOURCE_MEM,
  3322. + }, {
  3323. + .start = INTERRUPT_I2C,
  3324. + .end = INTERRUPT_I2C,
  3325. + .flags = IORESOURCE_IRQ,
  3326. + }
  3327. +};
  3328. +
  3329. +static struct platform_device bcm2708_bsc0_device = {
  3330. + .name = "bcm2708_i2c",
  3331. + .id = 0,
  3332. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  3333. + .resource = bcm2708_bsc0_resources,
  3334. +};
  3335. +
  3336. +
  3337. +static struct resource bcm2708_bsc1_resources[] = {
  3338. + {
  3339. + .start = BSC1_BASE,
  3340. + .end = BSC1_BASE + SZ_256 - 1,
  3341. + .flags = IORESOURCE_MEM,
  3342. + }, {
  3343. + .start = INTERRUPT_I2C,
  3344. + .end = INTERRUPT_I2C,
  3345. + .flags = IORESOURCE_IRQ,
  3346. + }
  3347. +};
  3348. +
  3349. +static struct platform_device bcm2708_bsc1_device = {
  3350. + .name = "bcm2708_i2c",
  3351. + .id = 1,
  3352. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  3353. + .resource = bcm2708_bsc1_resources,
  3354. +};
  3355. +
  3356. +static struct platform_device bcm2835_hwmon_device = {
  3357. + .name = "bcm2835_hwmon",
  3358. +};
  3359. +
  3360. +static struct platform_device bcm2835_thermal_device = {
  3361. + .name = "bcm2835_thermal",
  3362. +};
  3363. +
  3364. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3365. +static struct resource bcm2708_i2s_resources[] = {
  3366. + {
  3367. + .start = I2S_BASE,
  3368. + .end = I2S_BASE + 0x20,
  3369. + .flags = IORESOURCE_MEM,
  3370. + },
  3371. + {
  3372. + .start = PCM_CLOCK_BASE,
  3373. + .end = PCM_CLOCK_BASE + 0x02,
  3374. + .flags = IORESOURCE_MEM,
  3375. + }
  3376. +};
  3377. +
  3378. +static struct platform_device bcm2708_i2s_device = {
  3379. + .name = "bcm2708-i2s",
  3380. + .id = 0,
  3381. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  3382. + .resource = bcm2708_i2s_resources,
  3383. +};
  3384. +#endif
  3385. +
  3386. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3387. +static struct platform_device snd_hifiberry_dac_device = {
  3388. + .name = "snd-hifiberry-dac",
  3389. + .id = 0,
  3390. + .num_resources = 0,
  3391. +};
  3392. +
  3393. +static struct platform_device snd_pcm5102a_codec_device = {
  3394. + .name = "pcm5102a-codec",
  3395. + .id = -1,
  3396. + .num_resources = 0,
  3397. +};
  3398. +#endif
  3399. +
  3400. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3401. +static struct platform_device snd_hifiberry_digi_device = {
  3402. + .name = "snd-hifiberry-digi",
  3403. + .id = 0,
  3404. + .num_resources = 0,
  3405. +};
  3406. +
  3407. +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
  3408. + {
  3409. + I2C_BOARD_INFO("wm8804", 0x3b)
  3410. + },
  3411. +};
  3412. +
  3413. +#endif
  3414. +
  3415. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3416. +static struct platform_device snd_rpi_dac_device = {
  3417. + .name = "snd-rpi-dac",
  3418. + .id = 0,
  3419. + .num_resources = 0,
  3420. +};
  3421. +
  3422. +static struct platform_device snd_pcm1794a_codec_device = {
  3423. + .name = "pcm1794a-codec",
  3424. + .id = -1,
  3425. + .num_resources = 0,
  3426. +};
  3427. +#endif
  3428. +
  3429. +
  3430. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  3431. +static struct platform_device snd_rpi_iqaudio_dac_device = {
  3432. + .name = "snd-rpi-iqaudio-dac",
  3433. + .id = 0,
  3434. + .num_resources = 0,
  3435. +};
  3436. +
  3437. +// Use the actual device name rather than generic driver name
  3438. +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
  3439. + {
  3440. + I2C_BOARD_INFO("pcm5122", 0x4c)
  3441. + },
  3442. +};
  3443. +#endif
  3444. +
  3445. +int __init bcm_register_device(struct platform_device *pdev)
  3446. +{
  3447. + int ret;
  3448. +
  3449. + ret = platform_device_register(pdev);
  3450. + if (ret)
  3451. + pr_debug("Unable to register platform device '%s': %d\n",
  3452. + pdev->name, ret);
  3453. +
  3454. + return ret;
  3455. +}
  3456. +
  3457. +int calc_rsts(int partition)
  3458. +{
  3459. + return PM_PASSWORD |
  3460. + ((partition & (1 << 0)) << 0) |
  3461. + ((partition & (1 << 1)) << 1) |
  3462. + ((partition & (1 << 2)) << 2) |
  3463. + ((partition & (1 << 3)) << 3) |
  3464. + ((partition & (1 << 4)) << 4) |
  3465. + ((partition & (1 << 5)) << 5);
  3466. +}
  3467. +
  3468. +static void bcm2708_restart(enum reboot_mode mode, const char *cmd)
  3469. +{
  3470. + extern char bcm2708_reboot_mode;
  3471. + uint32_t pm_rstc, pm_wdog;
  3472. + uint32_t timeout = 10;
  3473. + uint32_t pm_rsts = 0;
  3474. +
  3475. + if(bcm2708_reboot_mode == 'q')
  3476. + {
  3477. + // NOOBS < 1.3 booting with reboot=q
  3478. + pm_rsts = readl(__io_address(PM_RSTS));
  3479. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  3480. + }
  3481. + else if(bcm2708_reboot_mode == 'p')
  3482. + {
  3483. + // NOOBS < 1.3 halting
  3484. + pm_rsts = readl(__io_address(PM_RSTS));
  3485. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  3486. + }
  3487. + else
  3488. + {
  3489. + pm_rsts = calc_rsts(reboot_part);
  3490. + }
  3491. +
  3492. + writel(pm_rsts, __io_address(PM_RSTS));
  3493. +
  3494. + /* Setup watchdog for reset */
  3495. + pm_rstc = readl(__io_address(PM_RSTC));
  3496. +
  3497. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  3498. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  3499. +
  3500. + writel(pm_wdog, __io_address(PM_WDOG));
  3501. + writel(pm_rstc, __io_address(PM_RSTC));
  3502. +}
  3503. +
  3504. +/* We can't really power off, but if we do the normal reset scheme, and indicate to bootcode.bin not to reboot, then most of the chip will be powered off */
  3505. +static void bcm2708_power_off(void)
  3506. +{
  3507. + extern char bcm2708_reboot_mode;
  3508. + if(bcm2708_reboot_mode == 'q')
  3509. + {
  3510. + // NOOBS < v1.3
  3511. + bcm2708_restart('p', "");
  3512. + }
  3513. + else
  3514. + {
  3515. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  3516. + reboot_part = 63;
  3517. + /* continue with normal reset mechanism */
  3518. + bcm2708_restart(0, "");
  3519. + }
  3520. +}
  3521. +
  3522. +void __init bcm2708_init(void)
  3523. +{
  3524. + int i;
  3525. +
  3526. +#if defined(CONFIG_BCM_VC_CMA)
  3527. + vc_cma_early_init();
  3528. +#endif
  3529. + printk("bcm2708.uart_clock = %d\n", uart_clock);
  3530. + pm_power_off = bcm2708_power_off;
  3531. +
  3532. + if (uart_clock)
  3533. + lookups[0].clk->rate = uart_clock;
  3534. +
  3535. + for (i = 0; i < ARRAY_SIZE(lookups); i++)
  3536. + clkdev_add(&lookups[i]);
  3537. +
  3538. + bcm_register_device(&bcm2708_dmaman_device);
  3539. + bcm_register_device(&bcm2708_vcio_device);
  3540. +#ifdef CONFIG_BCM2708_GPIO
  3541. + bcm_register_device(&bcm2708_gpio_device);
  3542. +#endif
  3543. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  3544. + w1_gpio_pdata.pin = w1_gpio_pin;
  3545. + platform_device_register(&w1_device);
  3546. +#endif
  3547. + bcm_register_device(&bcm2708_systemtimer_device);
  3548. + bcm_register_device(&bcm2708_fb_device);
  3549. + bcm_register_device(&bcm2708_usb_device);
  3550. + bcm_register_device(&bcm2708_uart1_device);
  3551. + bcm_register_device(&bcm2708_powerman_device);
  3552. +
  3553. +#ifdef CONFIG_MMC_SDHCI_BCM2708
  3554. + bcm_register_device(&bcm2708_emmc_device);
  3555. +#endif
  3556. + bcm2708_init_led();
  3557. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  3558. + bcm_register_device(&bcm2708_alsa_devices[i]);
  3559. +
  3560. + bcm_register_device(&bcm2708_spi_device);
  3561. + bcm_register_device(&bcm2708_bsc0_device);
  3562. + bcm_register_device(&bcm2708_bsc1_device);
  3563. +
  3564. + bcm_register_device(&bcm2835_hwmon_device);
  3565. + bcm_register_device(&bcm2835_thermal_device);
  3566. +
  3567. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3568. + bcm_register_device(&bcm2708_i2s_device);
  3569. +#endif
  3570. +
  3571. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3572. + bcm_register_device(&snd_hifiberry_dac_device);
  3573. + bcm_register_device(&snd_pcm5102a_codec_device);
  3574. +#endif
  3575. +
  3576. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3577. + bcm_register_device(&snd_hifiberry_digi_device);
  3578. + i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  3579. +#endif
  3580. +
  3581. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3582. + bcm_register_device(&snd_rpi_dac_device);
  3583. + bcm_register_device(&snd_pcm1794a_codec_device);
  3584. +#endif
  3585. +
  3586. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  3587. + bcm_register_device(&snd_rpi_iqaudio_dac_device);
  3588. + i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  3589. +#endif
  3590. +
  3591. +
  3592. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  3593. + struct amba_device *d = amba_devs[i];
  3594. + amba_device_register(d, &iomem_resource);
  3595. + }
  3596. + system_rev = boardrev;
  3597. + system_serial_low = serial;
  3598. +
  3599. +#ifdef CONFIG_BCM2708_SPIDEV
  3600. + spi_register_board_info(bcm2708_spi_devices,
  3601. + ARRAY_SIZE(bcm2708_spi_devices));
  3602. +#endif
  3603. +}
  3604. +
  3605. +static void timer_set_mode(enum clock_event_mode mode,
  3606. + struct clock_event_device *clk)
  3607. +{
  3608. + switch (mode) {
  3609. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  3610. + case CLOCK_EVT_MODE_SHUTDOWN:
  3611. + break;
  3612. + case CLOCK_EVT_MODE_PERIODIC:
  3613. +
  3614. + case CLOCK_EVT_MODE_UNUSED:
  3615. + case CLOCK_EVT_MODE_RESUME:
  3616. +
  3617. + default:
  3618. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  3619. + (int)mode);
  3620. + break;
  3621. + }
  3622. +
  3623. +}
  3624. +
  3625. +static int timer_set_next_event(unsigned long cycles,
  3626. + struct clock_event_device *unused)
  3627. +{
  3628. + unsigned long stc;
  3629. +
  3630. + stc = readl(__io_address(ST_BASE + 0x04));
  3631. + writel(stc + cycles, __io_address(ST_BASE + 0x18)); /* stc3 */
  3632. + return 0;
  3633. +}
  3634. +
  3635. +static struct clock_event_device timer0_clockevent = {
  3636. + .name = "timer0",
  3637. + .shift = 32,
  3638. + .features = CLOCK_EVT_FEAT_ONESHOT,
  3639. + .set_mode = timer_set_mode,
  3640. + .set_next_event = timer_set_next_event,
  3641. +};
  3642. +
  3643. +/*
  3644. + * IRQ handler for the timer
  3645. + */
  3646. +static irqreturn_t bcm2708_timer_interrupt(int irq, void *dev_id)
  3647. +{
  3648. + struct clock_event_device *evt = &timer0_clockevent;
  3649. +
  3650. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  3651. +
  3652. + evt->event_handler(evt);
  3653. +
  3654. + return IRQ_HANDLED;
  3655. +}
  3656. +
  3657. +static struct irqaction bcm2708_timer_irq = {
  3658. + .name = "BCM2708 Timer Tick",
  3659. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  3660. + .handler = bcm2708_timer_interrupt,
  3661. +};
  3662. +
  3663. +/*
  3664. + * Set up timer interrupt, and return the current time in seconds.
  3665. + */
  3666. +
  3667. +static struct delay_timer bcm2708_delay_timer = {
  3668. + .read_current_timer = bcm2708_read_current_timer,
  3669. + .freq = STC_FREQ_HZ,
  3670. +};
  3671. +
  3672. +static void __init bcm2708_timer_init(void)
  3673. +{
  3674. + /* init high res timer */
  3675. + bcm2708_clocksource_init();
  3676. +
  3677. + /*
  3678. + * Initialise to a known state (all timers off)
  3679. + */
  3680. + writel(0, __io_address(ARM_T_CONTROL));
  3681. + /*
  3682. + * Make irqs happen for the system timer
  3683. + */
  3684. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  3685. +
  3686. + setup_sched_clock(bcm2708_read_sched_clock, 32, STC_FREQ_HZ);
  3687. +
  3688. + timer0_clockevent.mult =
  3689. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  3690. + timer0_clockevent.max_delta_ns =
  3691. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  3692. + timer0_clockevent.min_delta_ns =
  3693. + clockevent_delta2ns(0xf, &timer0_clockevent);
  3694. +
  3695. + timer0_clockevent.cpumask = cpumask_of(0);
  3696. + clockevents_register_device(&timer0_clockevent);
  3697. +
  3698. + register_current_timer_delay(&bcm2708_delay_timer);
  3699. +}
  3700. +
  3701. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  3702. +#include <linux/leds.h>
  3703. +
  3704. +static struct gpio_led bcm2708_leds[] = {
  3705. + [0] = {
  3706. + .gpio = 16,
  3707. + .name = "led0",
  3708. + .default_trigger = "mmc0",
  3709. + .active_low = 1,
  3710. + },
  3711. +};
  3712. +
  3713. +static struct gpio_led_platform_data bcm2708_led_pdata = {
  3714. + .num_leds = ARRAY_SIZE(bcm2708_leds),
  3715. + .leds = bcm2708_leds,
  3716. +};
  3717. +
  3718. +static struct platform_device bcm2708_led_device = {
  3719. + .name = "leds-gpio",
  3720. + .id = -1,
  3721. + .dev = {
  3722. + .platform_data = &bcm2708_led_pdata,
  3723. + },
  3724. +};
  3725. +
  3726. +static void __init bcm2708_init_led(void)
  3727. +{
  3728. + bcm2708_leds[0].gpio = disk_led_gpio;
  3729. + bcm2708_leds[0].active_low = disk_led_active_low;
  3730. + platform_device_register(&bcm2708_led_device);
  3731. +}
  3732. +#else
  3733. +static inline void bcm2708_init_led(void)
  3734. +{
  3735. +}
  3736. +#endif
  3737. +
  3738. +void __init bcm2708_init_early(void)
  3739. +{
  3740. + /*
  3741. + * Some devices allocate their coherent buffers from atomic
  3742. + * context. Increase size of atomic coherent pool to make sure such
  3743. + * the allocations won't fail.
  3744. + */
  3745. + init_dma_coherent_pool_size(SZ_4M);
  3746. +}
  3747. +
  3748. +static void __init board_reserve(void)
  3749. +{
  3750. +#if defined(CONFIG_BCM_VC_CMA)
  3751. + vc_cma_reserve();
  3752. +#endif
  3753. +}
  3754. +
  3755. +MACHINE_START(BCM2708, "BCM2708")
  3756. + /* Maintainer: Broadcom Europe Ltd. */
  3757. + .map_io = bcm2708_map_io,
  3758. + .init_irq = bcm2708_init_irq,
  3759. + .init_time = bcm2708_timer_init,
  3760. + .init_machine = bcm2708_init,
  3761. + .init_early = bcm2708_init_early,
  3762. + .reserve = board_reserve,
  3763. + .restart = bcm2708_restart,
  3764. +MACHINE_END
  3765. +
  3766. +module_param(boardrev, uint, 0644);
  3767. +module_param(serial, uint, 0644);
  3768. +module_param(uart_clock, uint, 0644);
  3769. +module_param(disk_led_gpio, uint, 0644);
  3770. +module_param(disk_led_active_low, uint, 0644);
  3771. +module_param(reboot_part, uint, 0644);
  3772. +module_param(w1_gpio_pin, uint, 0644);
  3773. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/bcm2708_gpio.c linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3774. --- linux-3.12.18/arch/arm/mach-bcm2708/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  3775. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c 2014-04-24 16:04:30.051029784 +0200
  3776. @@ -0,0 +1,361 @@
  3777. +/*
  3778. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3779. + *
  3780. + * Copyright (C) 2010 Broadcom
  3781. + *
  3782. + * This program is free software; you can redistribute it and/or modify
  3783. + * it under the terms of the GNU General Public License version 2 as
  3784. + * published by the Free Software Foundation.
  3785. + *
  3786. + */
  3787. +
  3788. +#include <linux/spinlock.h>
  3789. +#include <linux/module.h>
  3790. +#include <linux/list.h>
  3791. +#include <linux/io.h>
  3792. +#include <linux/irq.h>
  3793. +#include <linux/interrupt.h>
  3794. +#include <linux/slab.h>
  3795. +#include <mach/gpio.h>
  3796. +#include <linux/gpio.h>
  3797. +#include <linux/platform_device.h>
  3798. +#include <mach/platform.h>
  3799. +
  3800. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3801. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  3802. +#define BCM_GPIO_USE_IRQ 1
  3803. +
  3804. +#define GPIOFSEL(x) (0x00+(x)*4)
  3805. +#define GPIOSET(x) (0x1c+(x)*4)
  3806. +#define GPIOCLR(x) (0x28+(x)*4)
  3807. +#define GPIOLEV(x) (0x34+(x)*4)
  3808. +#define GPIOEDS(x) (0x40+(x)*4)
  3809. +#define GPIOREN(x) (0x4c+(x)*4)
  3810. +#define GPIOFEN(x) (0x58+(x)*4)
  3811. +#define GPIOHEN(x) (0x64+(x)*4)
  3812. +#define GPIOLEN(x) (0x70+(x)*4)
  3813. +#define GPIOAREN(x) (0x7c+(x)*4)
  3814. +#define GPIOAFEN(x) (0x88+(x)*4)
  3815. +#define GPIOUD(x) (0x94+(x)*4)
  3816. +#define GPIOUDCLK(x) (0x98+(x)*4)
  3817. +
  3818. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  3819. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  3820. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  3821. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  3822. +};
  3823. +
  3824. + /* Each of the two spinlocks protects a different set of hardware
  3825. + * regiters and data structurs. This decouples the code of the IRQ from
  3826. + * the GPIO code. This also makes the case of a GPIO routine call from
  3827. + * the IRQ code simpler.
  3828. + */
  3829. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  3830. +
  3831. +struct bcm2708_gpio {
  3832. + struct list_head list;
  3833. + void __iomem *base;
  3834. + struct gpio_chip gc;
  3835. + unsigned long rising;
  3836. + unsigned long falling;
  3837. + unsigned long high;
  3838. + unsigned long low;
  3839. +};
  3840. +
  3841. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  3842. + int function)
  3843. +{
  3844. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3845. + unsigned long flags;
  3846. + unsigned gpiodir;
  3847. + unsigned gpio_bank = offset / 10;
  3848. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  3849. +
  3850. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  3851. + if (offset >= BCM2708_NR_GPIOS)
  3852. + return -EINVAL;
  3853. +
  3854. + spin_lock_irqsave(&lock, flags);
  3855. +
  3856. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3857. + gpiodir &= ~(7 << gpio_field_offset);
  3858. + gpiodir |= function << gpio_field_offset;
  3859. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  3860. + spin_unlock_irqrestore(&lock, flags);
  3861. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3862. +
  3863. + return 0;
  3864. +}
  3865. +
  3866. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  3867. +{
  3868. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  3869. +}
  3870. +
  3871. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  3872. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  3873. + int value)
  3874. +{
  3875. + int ret;
  3876. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  3877. + if (ret >= 0)
  3878. + bcm2708_gpio_set(gc, offset, value);
  3879. + return ret;
  3880. +}
  3881. +
  3882. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  3883. +{
  3884. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3885. + unsigned gpio_bank = offset / 32;
  3886. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3887. + unsigned lev;
  3888. +
  3889. + if (offset >= BCM2708_NR_GPIOS)
  3890. + return 0;
  3891. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  3892. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  3893. + return 0x1 & (lev >> gpio_field_offset);
  3894. +}
  3895. +
  3896. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  3897. +{
  3898. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3899. + unsigned gpio_bank = offset / 32;
  3900. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3901. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  3902. + if (offset >= BCM2708_NR_GPIOS)
  3903. + return;
  3904. + if (value)
  3905. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  3906. + else
  3907. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  3908. +}
  3909. +
  3910. +/*************************************************************************************************************************
  3911. + * bcm2708 GPIO IRQ
  3912. + */
  3913. +
  3914. +#if BCM_GPIO_USE_IRQ
  3915. +
  3916. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  3917. +{
  3918. + return gpio_to_irq(gpio);
  3919. +}
  3920. +
  3921. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  3922. +{
  3923. + unsigned irq = d->irq;
  3924. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3925. +
  3926. + gpio->rising &= ~(1 << irq_to_gpio(irq));
  3927. + gpio->falling &= ~(1 << irq_to_gpio(irq));
  3928. + gpio->high &= ~(1 << irq_to_gpio(irq));
  3929. + gpio->low &= ~(1 << irq_to_gpio(irq));
  3930. +
  3931. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  3932. + return -EINVAL;
  3933. +
  3934. + if (type & IRQ_TYPE_EDGE_RISING)
  3935. + gpio->rising |= (1 << irq_to_gpio(irq));
  3936. + if (type & IRQ_TYPE_EDGE_FALLING)
  3937. + gpio->falling |= (1 << irq_to_gpio(irq));
  3938. + if (type & IRQ_TYPE_LEVEL_HIGH)
  3939. + gpio->high |= (1 << irq_to_gpio(irq));
  3940. + if (type & IRQ_TYPE_LEVEL_LOW)
  3941. + gpio->low |= (1 << irq_to_gpio(irq));
  3942. + return 0;
  3943. +}
  3944. +
  3945. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  3946. +{
  3947. + unsigned irq = d->irq;
  3948. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3949. + unsigned gn = irq_to_gpio(irq);
  3950. + unsigned gb = gn / 32;
  3951. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3952. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3953. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  3954. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  3955. +
  3956. + gn = gn % 32;
  3957. +
  3958. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3959. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3960. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  3961. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  3962. +}
  3963. +
  3964. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  3965. +{
  3966. + unsigned irq = d->irq;
  3967. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3968. + unsigned gn = irq_to_gpio(irq);
  3969. + unsigned gb = gn / 32;
  3970. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3971. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3972. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  3973. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  3974. +
  3975. + gn = gn % 32;
  3976. +
  3977. + writel(1 << gn, gpio->base + GPIOEDS(gb));
  3978. +
  3979. + if (gpio->rising & (1 << gn)) {
  3980. + writel(rising | (1 << gn), gpio->base + GPIOREN(gb));
  3981. + } else {
  3982. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3983. + }
  3984. +
  3985. + if (gpio->falling & (1 << gn)) {
  3986. + writel(falling | (1 << gn), gpio->base + GPIOFEN(gb));
  3987. + } else {
  3988. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3989. + }
  3990. +
  3991. + if (gpio->high & (1 << gn)) {
  3992. + writel(high | (1 << gn), gpio->base + GPIOHEN(gb));
  3993. + } else {
  3994. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  3995. + }
  3996. +
  3997. + if (gpio->low & (1 << gn)) {
  3998. + writel(low | (1 << gn), gpio->base + GPIOLEN(gb));
  3999. + } else {
  4000. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  4001. + }
  4002. +}
  4003. +
  4004. +static struct irq_chip bcm2708_irqchip = {
  4005. + .name = "GPIO",
  4006. + .irq_enable = bcm2708_gpio_irq_unmask,
  4007. + .irq_disable = bcm2708_gpio_irq_mask,
  4008. + .irq_unmask = bcm2708_gpio_irq_unmask,
  4009. + .irq_mask = bcm2708_gpio_irq_mask,
  4010. + .irq_set_type = bcm2708_gpio_irq_set_type,
  4011. +};
  4012. +
  4013. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  4014. +{
  4015. + unsigned long edsr;
  4016. + unsigned bank;
  4017. + int i;
  4018. + unsigned gpio;
  4019. + for (bank = 0; bank <= 1; bank++) {
  4020. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  4021. + for_each_set_bit(i, &edsr, 32) {
  4022. + gpio = i + bank * 32;
  4023. + generic_handle_irq(gpio_to_irq(gpio));
  4024. + }
  4025. + writel(0xffffffff, __io_address(GPIO_BASE) + GPIOEDS(bank));
  4026. + }
  4027. + return IRQ_HANDLED;
  4028. +}
  4029. +
  4030. +static struct irqaction bcm2708_gpio_irq = {
  4031. + .name = "BCM2708 GPIO catchall handler",
  4032. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  4033. + .handler = bcm2708_gpio_interrupt,
  4034. +};
  4035. +
  4036. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4037. +{
  4038. + unsigned irq;
  4039. +
  4040. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  4041. +
  4042. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  4043. + irq_set_chip_data(irq, ucb);
  4044. + irq_set_chip(irq, &bcm2708_irqchip);
  4045. + set_irq_flags(irq, IRQF_VALID);
  4046. + }
  4047. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  4048. +}
  4049. +
  4050. +#else
  4051. +
  4052. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4053. +{
  4054. +}
  4055. +
  4056. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  4057. +
  4058. +static int bcm2708_gpio_probe(struct platform_device *dev)
  4059. +{
  4060. + struct bcm2708_gpio *ucb;
  4061. + struct resource *res;
  4062. + int err = 0;
  4063. +
  4064. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  4065. +
  4066. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  4067. + if (NULL == ucb) {
  4068. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4069. + "mailbox memory\n");
  4070. + err = -ENOMEM;
  4071. + goto err;
  4072. + }
  4073. +
  4074. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  4075. +
  4076. + platform_set_drvdata(dev, ucb);
  4077. + ucb->base = __io_address(GPIO_BASE);
  4078. +
  4079. + ucb->gc.label = "bcm2708_gpio";
  4080. + ucb->gc.base = 0;
  4081. + ucb->gc.ngpio = BCM2708_NR_GPIOS;
  4082. + ucb->gc.owner = THIS_MODULE;
  4083. +
  4084. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  4085. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  4086. + ucb->gc.get = bcm2708_gpio_get;
  4087. + ucb->gc.set = bcm2708_gpio_set;
  4088. + ucb->gc.can_sleep = 0;
  4089. +
  4090. + bcm2708_gpio_irq_init(ucb);
  4091. +
  4092. + err = gpiochip_add(&ucb->gc);
  4093. + if (err)
  4094. + goto err;
  4095. +
  4096. +err:
  4097. + return err;
  4098. +
  4099. +}
  4100. +
  4101. +static int bcm2708_gpio_remove(struct platform_device *dev)
  4102. +{
  4103. + int err = 0;
  4104. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  4105. +
  4106. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  4107. +
  4108. + err = gpiochip_remove(&ucb->gc);
  4109. +
  4110. + platform_set_drvdata(dev, NULL);
  4111. + kfree(ucb);
  4112. +
  4113. + return err;
  4114. +}
  4115. +
  4116. +static struct platform_driver bcm2708_gpio_driver = {
  4117. + .probe = bcm2708_gpio_probe,
  4118. + .remove = bcm2708_gpio_remove,
  4119. + .driver = {
  4120. + .name = "bcm2708_gpio"},
  4121. +};
  4122. +
  4123. +static int __init bcm2708_gpio_init(void)
  4124. +{
  4125. + return platform_driver_register(&bcm2708_gpio_driver);
  4126. +}
  4127. +
  4128. +static void __exit bcm2708_gpio_exit(void)
  4129. +{
  4130. + platform_driver_unregister(&bcm2708_gpio_driver);
  4131. +}
  4132. +
  4133. +module_init(bcm2708_gpio_init);
  4134. +module_exit(bcm2708_gpio_exit);
  4135. +
  4136. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  4137. +MODULE_LICENSE("GPL");
  4138. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/bcm2708.h linux-rpi/arch/arm/mach-bcm2708/bcm2708.h
  4139. --- linux-3.12.18/arch/arm/mach-bcm2708/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  4140. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.h 2014-04-24 16:04:30.051029784 +0200
  4141. @@ -0,0 +1,49 @@
  4142. +/*
  4143. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  4144. + *
  4145. + * BCM2708 machine support header
  4146. + *
  4147. + * Copyright (C) 2010 Broadcom
  4148. + *
  4149. + * This program is free software; you can redistribute it and/or modify
  4150. + * it under the terms of the GNU General Public License as published by
  4151. + * the Free Software Foundation; either version 2 of the License, or
  4152. + * (at your option) any later version.
  4153. + *
  4154. + * This program is distributed in the hope that it will be useful,
  4155. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4156. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4157. + * GNU General Public License for more details.
  4158. + *
  4159. + * You should have received a copy of the GNU General Public License
  4160. + * along with this program; if not, write to the Free Software
  4161. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4162. + */
  4163. +
  4164. +#ifndef __BCM2708_BCM2708_H
  4165. +#define __BCM2708_BCM2708_H
  4166. +
  4167. +#include <linux/amba/bus.h>
  4168. +
  4169. +extern void __init bcm2708_init(void);
  4170. +extern void __init bcm2708_init_irq(void);
  4171. +extern void __init bcm2708_map_io(void);
  4172. +extern struct sys_timer bcm2708_timer;
  4173. +extern unsigned int mmc_status(struct device *dev);
  4174. +
  4175. +#define AMBA_DEVICE(name, busid, base, plat) \
  4176. +static struct amba_device name##_device = { \
  4177. + .dev = { \
  4178. + .coherent_dma_mask = ~0, \
  4179. + .init_name = busid, \
  4180. + .platform_data = plat, \
  4181. + }, \
  4182. + .res = { \
  4183. + .start = base##_BASE, \
  4184. + .end = (base##_BASE) + SZ_4K - 1,\
  4185. + .flags = IORESOURCE_MEM, \
  4186. + }, \
  4187. + .irq = base##_IRQ, \
  4188. +}
  4189. +
  4190. +#endif
  4191. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/clock.c linux-rpi/arch/arm/mach-bcm2708/clock.c
  4192. --- linux-3.12.18/arch/arm/mach-bcm2708/clock.c 1970-01-01 01:00:00.000000000 +0100
  4193. +++ linux-rpi/arch/arm/mach-bcm2708/clock.c 2014-04-24 15:35:00.773527891 +0200
  4194. @@ -0,0 +1,61 @@
  4195. +/*
  4196. + * linux/arch/arm/mach-bcm2708/clock.c
  4197. + *
  4198. + * Copyright (C) 2010 Broadcom
  4199. + *
  4200. + * This program is free software; you can redistribute it and/or modify
  4201. + * it under the terms of the GNU General Public License as published by
  4202. + * the Free Software Foundation; either version 2 of the License, or
  4203. + * (at your option) any later version.
  4204. + *
  4205. + * This program is distributed in the hope that it will be useful,
  4206. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4207. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4208. + * GNU General Public License for more details.
  4209. + *
  4210. + * You should have received a copy of the GNU General Public License
  4211. + * along with this program; if not, write to the Free Software
  4212. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4213. + */
  4214. +#include <linux/module.h>
  4215. +#include <linux/kernel.h>
  4216. +#include <linux/device.h>
  4217. +#include <linux/list.h>
  4218. +#include <linux/errno.h>
  4219. +#include <linux/err.h>
  4220. +#include <linux/string.h>
  4221. +#include <linux/clk.h>
  4222. +#include <linux/mutex.h>
  4223. +
  4224. +#include <asm/clkdev.h>
  4225. +
  4226. +#include "clock.h"
  4227. +
  4228. +int clk_enable(struct clk *clk)
  4229. +{
  4230. + return 0;
  4231. +}
  4232. +EXPORT_SYMBOL(clk_enable);
  4233. +
  4234. +void clk_disable(struct clk *clk)
  4235. +{
  4236. +}
  4237. +EXPORT_SYMBOL(clk_disable);
  4238. +
  4239. +unsigned long clk_get_rate(struct clk *clk)
  4240. +{
  4241. + return clk->rate;
  4242. +}
  4243. +EXPORT_SYMBOL(clk_get_rate);
  4244. +
  4245. +long clk_round_rate(struct clk *clk, unsigned long rate)
  4246. +{
  4247. + return clk->rate;
  4248. +}
  4249. +EXPORT_SYMBOL(clk_round_rate);
  4250. +
  4251. +int clk_set_rate(struct clk *clk, unsigned long rate)
  4252. +{
  4253. + return -EIO;
  4254. +}
  4255. +EXPORT_SYMBOL(clk_set_rate);
  4256. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/clock.h linux-rpi/arch/arm/mach-bcm2708/clock.h
  4257. --- linux-3.12.18/arch/arm/mach-bcm2708/clock.h 1970-01-01 01:00:00.000000000 +0100
  4258. +++ linux-rpi/arch/arm/mach-bcm2708/clock.h 2014-04-24 15:35:00.773527891 +0200
  4259. @@ -0,0 +1,24 @@
  4260. +/*
  4261. + * linux/arch/arm/mach-bcm2708/clock.h
  4262. + *
  4263. + * Copyright (C) 2010 Broadcom
  4264. + *
  4265. + * This program is free software; you can redistribute it and/or modify
  4266. + * it under the terms of the GNU General Public License as published by
  4267. + * the Free Software Foundation; either version 2 of the License, or
  4268. + * (at your option) any later version.
  4269. + *
  4270. + * This program is distributed in the hope that it will be useful,
  4271. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4272. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4273. + * GNU General Public License for more details.
  4274. + *
  4275. + * You should have received a copy of the GNU General Public License
  4276. + * along with this program; if not, write to the Free Software
  4277. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4278. + */
  4279. +struct module;
  4280. +
  4281. +struct clk {
  4282. + unsigned long rate;
  4283. +};
  4284. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/dma.c linux-rpi/arch/arm/mach-bcm2708/dma.c
  4285. --- linux-3.12.18/arch/arm/mach-bcm2708/dma.c 1970-01-01 01:00:00.000000000 +0100
  4286. +++ linux-rpi/arch/arm/mach-bcm2708/dma.c 2014-04-24 15:35:00.773527891 +0200
  4287. @@ -0,0 +1,407 @@
  4288. +/*
  4289. + * linux/arch/arm/mach-bcm2708/dma.c
  4290. + *
  4291. + * Copyright (C) 2010 Broadcom
  4292. + *
  4293. + * This program is free software; you can redistribute it and/or modify
  4294. + * it under the terms of the GNU General Public License version 2 as
  4295. + * published by the Free Software Foundation.
  4296. + */
  4297. +
  4298. +#include <linux/slab.h>
  4299. +#include <linux/device.h>
  4300. +#include <linux/platform_device.h>
  4301. +#include <linux/module.h>
  4302. +#include <linux/scatterlist.h>
  4303. +
  4304. +#include <mach/dma.h>
  4305. +#include <mach/irqs.h>
  4306. +
  4307. +/*****************************************************************************\
  4308. + * *
  4309. + * Configuration *
  4310. + * *
  4311. +\*****************************************************************************/
  4312. +
  4313. +#define CACHE_LINE_MASK 31
  4314. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  4315. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  4316. +
  4317. +/* valid only for channels 0 - 14, 15 has its own base address */
  4318. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  4319. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  4320. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  4321. +
  4322. +
  4323. +/*****************************************************************************\
  4324. + * *
  4325. + * DMA Auxilliary Functions *
  4326. + * *
  4327. +\*****************************************************************************/
  4328. +
  4329. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  4330. + section inside the DMA buffer and another section outside it.
  4331. + Even if we flush DMA buffers from the cache there is always the chance that
  4332. + during a DMA someone will access the part of a cache line that is outside
  4333. + the DMA buffer - which will then bring in unwelcome data.
  4334. + Without being able to dictate our own buffer pools we must insist that
  4335. + DMA buffers consist of a whole number of cache lines.
  4336. +*/
  4337. +
  4338. +extern int
  4339. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  4340. +{
  4341. + int i;
  4342. +
  4343. + for (i = 0; i < sg_len; i++) {
  4344. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  4345. + sg_ptr[i].length & CACHE_LINE_MASK)
  4346. + return 0;
  4347. + }
  4348. +
  4349. + return 1;
  4350. +}
  4351. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  4352. +
  4353. +extern void
  4354. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  4355. +{
  4356. + dsb(); /* ARM data synchronization (push) operation */
  4357. +
  4358. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  4359. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  4360. +}
  4361. +
  4362. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  4363. +{
  4364. + dsb();
  4365. +
  4366. + /* ugly busy wait only option for now */
  4367. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  4368. + cpu_relax();
  4369. +}
  4370. +
  4371. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  4372. +
  4373. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  4374. +{
  4375. + dsb();
  4376. +
  4377. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  4378. +}
  4379. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  4380. +
  4381. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  4382. + Does nothing if there is no DMA in progress.
  4383. + This routine waits for the current AXI transfer to complete before
  4384. + terminating the current DMA. If the current transfer is hung on a DREQ used
  4385. + by an uncooperative peripheral the AXI transfer may never complete. In this
  4386. + case the routine times out and return a non-zero error code.
  4387. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  4388. + does not produce an interrupt.
  4389. +*/
  4390. +extern int
  4391. +bcm_dma_abort(void __iomem *dma_chan_base)
  4392. +{
  4393. + unsigned long int cs;
  4394. + int rc = 0;
  4395. +
  4396. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4397. +
  4398. + if (BCM2708_DMA_ACTIVE & cs) {
  4399. + long int timeout = 10000;
  4400. +
  4401. + /* write 0 to the active bit - pause the DMA */
  4402. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  4403. +
  4404. + /* wait for any current AXI transfer to complete */
  4405. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  4406. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4407. +
  4408. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  4409. + /* we'll un-pause when we set of our next DMA */
  4410. + rc = -ETIMEDOUT;
  4411. +
  4412. + } else if (BCM2708_DMA_ACTIVE & cs) {
  4413. + /* terminate the control block chain */
  4414. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  4415. +
  4416. + /* abort the whole DMA */
  4417. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  4418. + dma_chan_base + BCM2708_DMA_CS);
  4419. + }
  4420. + }
  4421. +
  4422. + return rc;
  4423. +}
  4424. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  4425. +
  4426. +
  4427. +/***************************************************************************** \
  4428. + * *
  4429. + * DMA Manager Device Methods *
  4430. + * *
  4431. +\*****************************************************************************/
  4432. +
  4433. +struct vc_dmaman {
  4434. + void __iomem *dma_base;
  4435. + u32 chan_available; /* bitmap of available channels */
  4436. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  4437. +};
  4438. +
  4439. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  4440. + u32 chans_available)
  4441. +{
  4442. + dmaman->dma_base = dma_base;
  4443. + dmaman->chan_available = chans_available;
  4444. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  4445. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  4446. +}
  4447. +
  4448. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  4449. + unsigned preferred_feature_set)
  4450. +{
  4451. + u32 chans;
  4452. + int feature;
  4453. +
  4454. + chans = dmaman->chan_available;
  4455. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  4456. + /* select the subset of available channels with the desired
  4457. + feature so long as some of the candidate channels have that
  4458. + feature */
  4459. + if ((preferred_feature_set & (1 << feature)) &&
  4460. + (chans & dmaman->has_feature[feature]))
  4461. + chans &= dmaman->has_feature[feature];
  4462. +
  4463. + if (chans) {
  4464. + int chan = 0;
  4465. + /* return the ordinal of the first channel in the bitmap */
  4466. + while (chans != 0 && (chans & 1) == 0) {
  4467. + chans >>= 1;
  4468. + chan++;
  4469. + }
  4470. + /* claim the channel */
  4471. + dmaman->chan_available &= ~(1 << chan);
  4472. + return chan;
  4473. + } else
  4474. + return -ENOMEM;
  4475. +}
  4476. +
  4477. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  4478. +{
  4479. + if (chan < 0)
  4480. + return -EINVAL;
  4481. + else if ((1 << chan) & dmaman->chan_available)
  4482. + return -EIDRM;
  4483. + else {
  4484. + dmaman->chan_available |= (1 << chan);
  4485. + return 0;
  4486. + }
  4487. +}
  4488. +
  4489. +/*****************************************************************************\
  4490. + * *
  4491. + * DMA IRQs *
  4492. + * *
  4493. +\*****************************************************************************/
  4494. +
  4495. +static unsigned char bcm_dma_irqs[] = {
  4496. + IRQ_DMA0,
  4497. + IRQ_DMA1,
  4498. + IRQ_DMA2,
  4499. + IRQ_DMA3,
  4500. + IRQ_DMA4,
  4501. + IRQ_DMA5,
  4502. + IRQ_DMA6,
  4503. + IRQ_DMA7,
  4504. + IRQ_DMA8,
  4505. + IRQ_DMA9,
  4506. + IRQ_DMA10,
  4507. + IRQ_DMA11,
  4508. + IRQ_DMA12
  4509. +};
  4510. +
  4511. +
  4512. +/***************************************************************************** \
  4513. + * *
  4514. + * DMA Manager Monitor *
  4515. + * *
  4516. +\*****************************************************************************/
  4517. +
  4518. +static struct device *dmaman_dev; /* we assume there's only one! */
  4519. +
  4520. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  4521. + void __iomem **out_dma_base, int *out_dma_irq)
  4522. +{
  4523. + if (!dmaman_dev)
  4524. + return -ENODEV;
  4525. + else {
  4526. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4527. + int rc;
  4528. +
  4529. + device_lock(dmaman_dev);
  4530. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  4531. + if (rc >= 0) {
  4532. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  4533. + rc);
  4534. + *out_dma_irq = bcm_dma_irqs[rc];
  4535. + }
  4536. + device_unlock(dmaman_dev);
  4537. +
  4538. + return rc;
  4539. + }
  4540. +}
  4541. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  4542. +
  4543. +extern int bcm_dma_chan_free(int channel)
  4544. +{
  4545. + if (dmaman_dev) {
  4546. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4547. + int rc;
  4548. +
  4549. + device_lock(dmaman_dev);
  4550. + rc = vc_dmaman_chan_free(dmaman, channel);
  4551. + device_unlock(dmaman_dev);
  4552. +
  4553. + return rc;
  4554. + } else
  4555. + return -ENODEV;
  4556. +}
  4557. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  4558. +
  4559. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  4560. +{
  4561. + int rc = dmaman_dev ? -EINVAL : 0;
  4562. + dmaman_dev = dev;
  4563. + return rc;
  4564. +}
  4565. +
  4566. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  4567. +{
  4568. + dmaman_dev = NULL;
  4569. +}
  4570. +
  4571. +/*****************************************************************************\
  4572. + * *
  4573. + * DMA Device *
  4574. + * *
  4575. +\*****************************************************************************/
  4576. +
  4577. +static int dmachans = -1; /* module parameter */
  4578. +
  4579. +static int bcm_dmaman_probe(struct platform_device *pdev)
  4580. +{
  4581. + int ret = 0;
  4582. + struct vc_dmaman *dmaman;
  4583. + struct resource *dma_res = NULL;
  4584. + void __iomem *dma_base = NULL;
  4585. + int have_dma_region = 0;
  4586. +
  4587. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  4588. + if (NULL == dmaman) {
  4589. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4590. + "DMA management memory\n");
  4591. + ret = -ENOMEM;
  4592. + } else {
  4593. +
  4594. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  4595. + if (dma_res == NULL) {
  4596. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  4597. + "resource\n");
  4598. + ret = -ENODEV;
  4599. + } else if (!request_mem_region(dma_res->start,
  4600. + resource_size(dma_res),
  4601. + DRIVER_NAME)) {
  4602. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  4603. + ret = -EBUSY;
  4604. + } else {
  4605. + have_dma_region = 1;
  4606. + dma_base = ioremap(dma_res->start,
  4607. + resource_size(dma_res));
  4608. + if (!dma_base) {
  4609. + dev_err(&pdev->dev, "cannot map DMA region\n");
  4610. + ret = -ENOMEM;
  4611. + } else {
  4612. + /* use module parameter if one was provided */
  4613. + if (dmachans > 0)
  4614. + vc_dmaman_init(dmaman, dma_base,
  4615. + dmachans);
  4616. + else
  4617. + vc_dmaman_init(dmaman, dma_base,
  4618. + DEFAULT_DMACHAN_BITMAP);
  4619. +
  4620. + platform_set_drvdata(pdev, dmaman);
  4621. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  4622. +
  4623. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  4624. + "at %p\n", dma_base);
  4625. + }
  4626. + }
  4627. + }
  4628. + if (ret != 0) {
  4629. + if (dma_base)
  4630. + iounmap(dma_base);
  4631. + if (dma_res && have_dma_region)
  4632. + release_mem_region(dma_res->start,
  4633. + resource_size(dma_res));
  4634. + if (dmaman)
  4635. + kfree(dmaman);
  4636. + }
  4637. + return ret;
  4638. +}
  4639. +
  4640. +static int bcm_dmaman_remove(struct platform_device *pdev)
  4641. +{
  4642. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  4643. +
  4644. + platform_set_drvdata(pdev, NULL);
  4645. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  4646. + kfree(dmaman);
  4647. +
  4648. + return 0;
  4649. +}
  4650. +
  4651. +static struct platform_driver bcm_dmaman_driver = {
  4652. + .probe = bcm_dmaman_probe,
  4653. + .remove = bcm_dmaman_remove,
  4654. +
  4655. + .driver = {
  4656. + .name = DRIVER_NAME,
  4657. + .owner = THIS_MODULE,
  4658. + },
  4659. +};
  4660. +
  4661. +/*****************************************************************************\
  4662. + * *
  4663. + * Driver init/exit *
  4664. + * *
  4665. +\*****************************************************************************/
  4666. +
  4667. +static int __init bcm_dmaman_drv_init(void)
  4668. +{
  4669. + int ret;
  4670. +
  4671. + ret = platform_driver_register(&bcm_dmaman_driver);
  4672. + if (ret != 0) {
  4673. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  4674. + "on platform\n");
  4675. + }
  4676. +
  4677. + return ret;
  4678. +}
  4679. +
  4680. +static void __exit bcm_dmaman_drv_exit(void)
  4681. +{
  4682. + platform_driver_unregister(&bcm_dmaman_driver);
  4683. +}
  4684. +
  4685. +module_init(bcm_dmaman_drv_init);
  4686. +module_exit(bcm_dmaman_drv_exit);
  4687. +
  4688. +module_param(dmachans, int, 0644);
  4689. +
  4690. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  4691. +MODULE_DESCRIPTION("DMA channel manager driver");
  4692. +MODULE_LICENSE("GPL");
  4693. +
  4694. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  4695. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/arm_control.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h
  4696. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  4697. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h 2014-04-24 15:35:00.777527936 +0200
  4698. @@ -0,0 +1,419 @@
  4699. +/*
  4700. + * linux/arch/arm/mach-bcm2708/arm_control.h
  4701. + *
  4702. + * Copyright (C) 2010 Broadcom
  4703. + *
  4704. + * This program is free software; you can redistribute it and/or modify
  4705. + * it under the terms of the GNU General Public License as published by
  4706. + * the Free Software Foundation; either version 2 of the License, or
  4707. + * (at your option) any later version.
  4708. + *
  4709. + * This program is distributed in the hope that it will be useful,
  4710. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4711. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4712. + * GNU General Public License for more details.
  4713. + *
  4714. + * You should have received a copy of the GNU General Public License
  4715. + * along with this program; if not, write to the Free Software
  4716. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4717. + */
  4718. +
  4719. +#ifndef __BCM2708_ARM_CONTROL_H
  4720. +#define __BCM2708_ARM_CONTROL_H
  4721. +
  4722. +/*
  4723. + * Definitions and addresses for the ARM CONTROL logic
  4724. + * This file is manually generated.
  4725. + */
  4726. +
  4727. +#define ARM_BASE 0x7E00B000
  4728. +
  4729. +/* Basic configuration */
  4730. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  4731. +#define ARM_C0_SIZ128M 0x00000000
  4732. +#define ARM_C0_SIZ256M 0x00000001
  4733. +#define ARM_C0_SIZ512M 0x00000002
  4734. +#define ARM_C0_SIZ1G 0x00000003
  4735. +#define ARM_C0_BRESP0 0x00000000
  4736. +#define ARM_C0_BRESP1 0x00000004
  4737. +#define ARM_C0_BRESP2 0x00000008
  4738. +#define ARM_C0_BOOTHI 0x00000010
  4739. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  4740. +#define ARM_C0_FULLPERI 0x00000040
  4741. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  4742. +#define ARM_C0_JTAGMASK 0x00000E00
  4743. +#define ARM_C0_JTAGOFF 0x00000000
  4744. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  4745. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  4746. +#define ARM_C0_APROTMSK 0x0000F000
  4747. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  4748. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  4749. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  4750. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  4751. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  4752. +#define ARM_C0_PRIO_L2 0x0F000000
  4753. +#define ARM_C0_PRIO_UC 0xF0000000
  4754. +
  4755. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  4756. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  4757. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  4758. +
  4759. +
  4760. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  4761. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  4762. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  4763. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  4764. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  4765. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  4766. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  4767. +
  4768. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  4769. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  4770. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  4771. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  4772. +
  4773. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  4774. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  4775. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  4776. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  4777. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  4778. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  4779. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  4780. +
  4781. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  4782. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  4783. +#define ARM_IDVAL 0x364D5241
  4784. +
  4785. +/* Translation memory */
  4786. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  4787. +/* 32 locations: 0x100.. 0x17F */
  4788. +/* 32 spare means we CAN go to 64 pages.... */
  4789. +
  4790. +
  4791. +/* Interrupts */
  4792. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  4793. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  4794. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  4795. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  4796. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  4797. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  4798. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  4799. +
  4800. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  4801. +/* todo: all I1_interrupt sources */
  4802. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  4803. +/* todo: all I2_interrupt sources */
  4804. +
  4805. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  4806. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  4807. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  4808. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  4809. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  4810. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  4811. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  4812. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  4813. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  4814. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  4815. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  4816. +
  4817. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  4818. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  4819. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  4820. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  4821. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  4822. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  4823. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  4824. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  4825. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  4826. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  4827. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  4828. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  4829. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  4830. +
  4831. +/* Timer */
  4832. +/* For reg. fields see sp804 spec. */
  4833. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  4834. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  4835. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  4836. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  4837. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  4838. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  4839. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  4840. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  4841. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  4842. +
  4843. +#define TIMER_CTRL_ONESHOT (1 << 0)
  4844. +#define TIMER_CTRL_32BIT (1 << 1)
  4845. +#define TIMER_CTRL_DIV1 (0 << 2)
  4846. +#define TIMER_CTRL_DIV16 (1 << 2)
  4847. +#define TIMER_CTRL_DIV256 (2 << 2)
  4848. +#define TIMER_CTRL_IE (1 << 5)
  4849. +#define TIMER_CTRL_PERIODIC (1 << 6)
  4850. +#define TIMER_CTRL_ENABLE (1 << 7)
  4851. +#define TIMER_CTRL_DBGHALT (1 << 8)
  4852. +#define TIMER_CTRL_ENAFREE (1 << 9)
  4853. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  4854. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  4855. +
  4856. +/* Semaphores, Doorbells, Mailboxes */
  4857. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  4858. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  4859. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  4860. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  4861. +
  4862. +/* MAILBOXES
  4863. + * Register flags are common across all
  4864. + * owner registers. See end of this section
  4865. + *
  4866. + * Semaphores, Doorbells, Mailboxes Owner 0
  4867. + *
  4868. + */
  4869. +
  4870. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  4871. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  4872. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  4873. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  4874. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  4875. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  4876. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  4877. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  4878. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  4879. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  4880. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  4881. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  4882. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  4883. +/* MAILBOX 0 access in Owner 0 area */
  4884. +/* Some addresses should ONLY be used by owner 0 */
  4885. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  4886. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  4887. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  4888. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  4889. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  4890. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  4891. +/* MAILBOX 1 access in Owner 0 area */
  4892. +/* Owner 0 should only WRITE to this mailbox */
  4893. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  4894. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  4895. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  4896. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  4897. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  4898. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  4899. +/* General SEM, BELL, MAIL config/status */
  4900. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  4901. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  4902. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  4903. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  4904. +
  4905. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  4906. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  4907. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  4908. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  4909. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  4910. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  4911. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  4912. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  4913. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  4914. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  4915. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  4916. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  4917. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  4918. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  4919. +/* MAILBOX 0 access in Owner 0 area */
  4920. +/* Owner 1 should only WRITE to this mailbox */
  4921. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  4922. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  4923. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  4924. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  4925. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  4926. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  4927. +/* MAILBOX 1 access in Owner 0 area */
  4928. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  4929. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  4930. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  4931. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  4932. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  4933. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  4934. +/* General SEM, BELL, MAIL config/status */
  4935. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  4936. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  4937. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  4938. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  4939. +
  4940. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  4941. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  4942. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  4943. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  4944. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  4945. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  4946. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  4947. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  4948. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  4949. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  4950. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  4951. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  4952. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  4953. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  4954. +/* MAILBOX 0 access in Owner 2 area */
  4955. +/* Owner 2 should only WRITE to this mailbox */
  4956. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  4957. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  4958. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  4959. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  4960. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  4961. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  4962. +/* MAILBOX 1 access in Owner 2 area */
  4963. +/* Owner 2 should only WRITE to this mailbox */
  4964. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  4965. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  4966. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  4967. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  4968. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  4969. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  4970. +/* General SEM, BELL, MAIL config/status */
  4971. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  4972. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  4973. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  4974. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  4975. +
  4976. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  4977. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  4978. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  4979. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  4980. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  4981. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  4982. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  4983. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  4984. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  4985. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  4986. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  4987. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  4988. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  4989. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  4990. +/* MAILBOX 0 access in Owner 3 area */
  4991. +/* Owner 3 should only WRITE to this mailbox */
  4992. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  4993. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  4994. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  4995. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  4996. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  4997. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  4998. +/* MAILBOX 1 access in Owner 3 area */
  4999. +/* Owner 3 should only WRITE to this mailbox */
  5000. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  5001. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  5002. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  5003. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  5004. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  5005. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  5006. +/* General SEM, BELL, MAIL config/status */
  5007. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  5008. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  5009. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  5010. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  5011. +
  5012. +
  5013. +
  5014. +/* Mailbox flags. Valid for all owners */
  5015. +
  5016. +/* Mailbox status register (...0x98) */
  5017. +#define ARM_MS_FULL 0x80000000
  5018. +#define ARM_MS_EMPTY 0x40000000
  5019. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  5020. +
  5021. +/* MAILBOX config/status register (...0x9C) */
  5022. +/* ANY write to this register clears the error bits! */
  5023. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  5024. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  5025. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  5026. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  5027. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  5028. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  5029. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  5030. +/* Bit 7 is unused */
  5031. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  5032. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  5033. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  5034. +
  5035. +/* Semaphore clear/debug register (...0xE0) */
  5036. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  5037. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  5038. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  5039. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  5040. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  5041. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  5042. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  5043. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  5044. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  5045. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  5046. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  5047. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  5048. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  5049. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  5050. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  5051. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  5052. +
  5053. +/* Doorbells clear/debug register (...0xE4) */
  5054. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  5055. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  5056. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  5057. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  5058. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  5059. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  5060. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  5061. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  5062. +
  5063. +/* MY IRQS register (...0xF8) */
  5064. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  5065. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  5066. +
  5067. +/* ALL IRQS register (...0xF8) */
  5068. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  5069. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  5070. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  5071. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  5072. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  5073. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  5074. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  5075. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  5076. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  5077. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  5078. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  5079. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  5080. +/* */
  5081. +/* ARM JTAG BASH */
  5082. +/* */
  5083. +#define AJB_BASE 0x7e2000c0
  5084. +
  5085. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  5086. +#define AJB_BITS0 0x000000
  5087. +#define AJB_BITS4 0x000004
  5088. +#define AJB_BITS8 0x000008
  5089. +#define AJB_BITS12 0x00000C
  5090. +#define AJB_BITS16 0x000010
  5091. +#define AJB_BITS20 0x000014
  5092. +#define AJB_BITS24 0x000018
  5093. +#define AJB_BITS28 0x00001C
  5094. +#define AJB_BITS32 0x000020
  5095. +#define AJB_BITS34 0x000022
  5096. +#define AJB_OUT_MS 0x000040
  5097. +#define AJB_OUT_LS 0x000000
  5098. +#define AJB_INV_CLK 0x000080
  5099. +#define AJB_D0_RISE 0x000100
  5100. +#define AJB_D0_FALL 0x000000
  5101. +#define AJB_D1_RISE 0x000200
  5102. +#define AJB_D1_FALL 0x000000
  5103. +#define AJB_IN_RISE 0x000400
  5104. +#define AJB_IN_FALL 0x000000
  5105. +#define AJB_ENABLE 0x000800
  5106. +#define AJB_HOLD0 0x000000
  5107. +#define AJB_HOLD1 0x001000
  5108. +#define AJB_HOLD2 0x002000
  5109. +#define AJB_HOLD3 0x003000
  5110. +#define AJB_RESETN 0x004000
  5111. +#define AJB_CLKSHFT 16
  5112. +#define AJB_BUSY 0x80000000
  5113. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  5114. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  5115. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  5116. +
  5117. +#endif
  5118. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/arm_power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5119. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  5120. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h 2014-04-24 15:35:00.777527936 +0200
  5121. @@ -0,0 +1,60 @@
  5122. +/*
  5123. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5124. + *
  5125. + * Copyright (C) 2010 Broadcom
  5126. + *
  5127. + * This program is free software; you can redistribute it and/or modify
  5128. + * it under the terms of the GNU General Public License as published by
  5129. + * the Free Software Foundation; either version 2 of the License, or
  5130. + * (at your option) any later version.
  5131. + *
  5132. + * This program is distributed in the hope that it will be useful,
  5133. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5134. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5135. + * GNU General Public License for more details.
  5136. + *
  5137. + * You should have received a copy of the GNU General Public License
  5138. + * along with this program; if not, write to the Free Software
  5139. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5140. + */
  5141. +
  5142. +#ifndef _ARM_POWER_H
  5143. +#define _ARM_POWER_H
  5144. +
  5145. +/* Use meaningful names on each side */
  5146. +#ifdef __VIDEOCORE__
  5147. +#define PREFIX(x) ARM_##x
  5148. +#else
  5149. +#define PREFIX(x) BCM_##x
  5150. +#endif
  5151. +
  5152. +enum {
  5153. + PREFIX(POWER_SDCARD_BIT),
  5154. + PREFIX(POWER_UART_BIT),
  5155. + PREFIX(POWER_MINIUART_BIT),
  5156. + PREFIX(POWER_USB_BIT),
  5157. + PREFIX(POWER_I2C0_BIT),
  5158. + PREFIX(POWER_I2C1_BIT),
  5159. + PREFIX(POWER_I2C2_BIT),
  5160. + PREFIX(POWER_SPI_BIT),
  5161. + PREFIX(POWER_CCP2TX_BIT),
  5162. +
  5163. + PREFIX(POWER_MAX)
  5164. +};
  5165. +
  5166. +enum {
  5167. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  5168. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  5169. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  5170. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  5171. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  5172. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  5173. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  5174. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  5175. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  5176. +
  5177. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  5178. + PREFIX(POWER_NONE) = 0
  5179. +};
  5180. +
  5181. +#endif
  5182. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/clkdev.h linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h
  5183. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  5184. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h 2014-04-24 15:35:00.777527936 +0200
  5185. @@ -0,0 +1,7 @@
  5186. +#ifndef __ASM_MACH_CLKDEV_H
  5187. +#define __ASM_MACH_CLKDEV_H
  5188. +
  5189. +#define __clk_get(clk) ({ 1; })
  5190. +#define __clk_put(clk) do { } while (0)
  5191. +
  5192. +#endif
  5193. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/debug-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5194. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  5195. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S 2014-04-24 16:04:30.051029784 +0200
  5196. @@ -0,0 +1,22 @@
  5197. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5198. + *
  5199. + * Debugging macro include header
  5200. + *
  5201. + * Copyright (C) 2010 Broadcom
  5202. + * Copyright (C) 1994-1999 Russell King
  5203. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  5204. + *
  5205. + * This program is free software; you can redistribute it and/or modify
  5206. + * it under the terms of the GNU General Public License version 2 as
  5207. + * published by the Free Software Foundation.
  5208. + *
  5209. +*/
  5210. +
  5211. +#include <mach/platform.h>
  5212. +
  5213. + .macro addruart, rp, rv, tmp
  5214. + ldr \rp, =UART0_BASE
  5215. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  5216. + .endm
  5217. +
  5218. +#include <debug/pl01x.S>
  5219. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/dma.h linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h
  5220. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  5221. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h 2014-04-24 15:35:00.777527936 +0200
  5222. @@ -0,0 +1,90 @@
  5223. +/*
  5224. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  5225. + *
  5226. + * Copyright (C) 2010 Broadcom
  5227. + *
  5228. + * This program is free software; you can redistribute it and/or modify
  5229. + * it under the terms of the GNU General Public License version 2 as
  5230. + * published by the Free Software Foundation.
  5231. + */
  5232. +
  5233. +
  5234. +#ifndef _MACH_BCM2708_DMA_H
  5235. +#define _MACH_BCM2708_DMA_H
  5236. +
  5237. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  5238. +
  5239. +/* DMA CS Control and Status bits */
  5240. +#define BCM2708_DMA_ACTIVE (1 << 0)
  5241. +#define BCM2708_DMA_INT (1 << 2)
  5242. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  5243. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  5244. +#define BCM2708_DMA_ERR (1 << 8)
  5245. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  5246. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  5247. +
  5248. +/* DMA control block "info" field bits */
  5249. +#define BCM2708_DMA_INT_EN (1 << 0)
  5250. +#define BCM2708_DMA_TDMODE (1 << 1)
  5251. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  5252. +#define BCM2708_DMA_D_INC (1 << 4)
  5253. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  5254. +#define BCM2708_DMA_D_DREQ (1 << 6)
  5255. +#define BCM2708_DMA_S_INC (1 << 8)
  5256. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  5257. +#define BCM2708_DMA_S_DREQ (1 << 10)
  5258. +
  5259. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  5260. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  5261. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  5262. +
  5263. +#define BCM2708_DMA_DREQ_EMMC 11
  5264. +#define BCM2708_DMA_DREQ_SDHOST 13
  5265. +
  5266. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  5267. +#define BCM2708_DMA_ADDR 0x04
  5268. +/* the current control block appears in the following registers - read only */
  5269. +#define BCM2708_DMA_INFO 0x08
  5270. +#define BCM2708_DMA_SOURCE_AD 0x0c
  5271. +#define BCM2708_DMA_DEST_AD 0x10
  5272. +#define BCM2708_DMA_NEXTCB 0x1C
  5273. +#define BCM2708_DMA_DEBUG 0x20
  5274. +
  5275. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  5276. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  5277. +
  5278. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  5279. +
  5280. +struct bcm2708_dma_cb {
  5281. + unsigned long info;
  5282. + unsigned long src;
  5283. + unsigned long dst;
  5284. + unsigned long length;
  5285. + unsigned long stride;
  5286. + unsigned long next;
  5287. + unsigned long pad[2];
  5288. +};
  5289. +struct scatterlist;
  5290. +
  5291. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  5292. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  5293. + dma_addr_t control_block);
  5294. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  5295. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  5296. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  5297. +
  5298. +/* When listing features we can ask for when allocating DMA channels give
  5299. + those with higher priority smaller ordinal numbers */
  5300. +#define BCM_DMA_FEATURE_FAST_ORD 0
  5301. +#define BCM_DMA_FEATURE_BULK_ORD 1
  5302. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  5303. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  5304. +#define BCM_DMA_FEATURE_COUNT 2
  5305. +
  5306. +/* return channel no or -ve error */
  5307. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  5308. + void __iomem **out_dma_base, int *out_dma_irq);
  5309. +extern int bcm_dma_chan_free(int channel);
  5310. +
  5311. +
  5312. +#endif /* _MACH_BCM2708_DMA_H */
  5313. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/entry-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5314. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  5315. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S 2014-04-24 15:35:00.777527936 +0200
  5316. @@ -0,0 +1,69 @@
  5317. +/*
  5318. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5319. + *
  5320. + * Low-level IRQ helper macros for BCM2708 platforms
  5321. + *
  5322. + * Copyright (C) 2010 Broadcom
  5323. + *
  5324. + * This program is free software; you can redistribute it and/or modify
  5325. + * it under the terms of the GNU General Public License as published by
  5326. + * the Free Software Foundation; either version 2 of the License, or
  5327. + * (at your option) any later version.
  5328. + *
  5329. + * This program is distributed in the hope that it will be useful,
  5330. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5331. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5332. + * GNU General Public License for more details.
  5333. + *
  5334. + * You should have received a copy of the GNU General Public License
  5335. + * along with this program; if not, write to the Free Software
  5336. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5337. + */
  5338. +#include <mach/hardware.h>
  5339. +
  5340. + .macro disable_fiq
  5341. + .endm
  5342. +
  5343. + .macro get_irqnr_preamble, base, tmp
  5344. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  5345. + .endm
  5346. +
  5347. + .macro arch_ret_to_user, tmp1, tmp2
  5348. + .endm
  5349. +
  5350. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  5351. + /* get masked status */
  5352. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  5353. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  5354. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  5355. + /* clear bits 8 and 9, and test */
  5356. + bics \irqstat, \irqstat, #0x300
  5357. + bne 1010f
  5358. +
  5359. + tst \tmp, #0x100
  5360. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  5361. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  5362. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5363. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  5364. + bicne \irqstat, #((1<<18) | (1<<19))
  5365. + bne 1010f
  5366. +
  5367. + tst \tmp, #0x200
  5368. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  5369. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  5370. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5371. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  5372. + bicne \irqstat, #((1<<30))
  5373. + beq 1020f
  5374. +
  5375. +1010:
  5376. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  5377. + @ N.B. CLZ is an ARM5 instruction.
  5378. + sub \tmp, \irqstat, #1
  5379. + eor \irqstat, \irqstat, \tmp
  5380. + clz \tmp, \irqstat
  5381. + sub \irqnr, \tmp
  5382. +
  5383. +1020: @ EQ will be set if no irqs pending
  5384. +
  5385. + .endm
  5386. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/frc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h
  5387. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  5388. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h 2014-04-24 15:35:00.777527936 +0200
  5389. @@ -0,0 +1,38 @@
  5390. +/*
  5391. + * arch/arm/mach-bcm2708/include/mach/timex.h
  5392. + *
  5393. + * BCM2708 free running counter (timer)
  5394. + *
  5395. + * Copyright (C) 2010 Broadcom
  5396. + *
  5397. + * This program is free software; you can redistribute it and/or modify
  5398. + * it under the terms of the GNU General Public License as published by
  5399. + * the Free Software Foundation; either version 2 of the License, or
  5400. + * (at your option) any later version.
  5401. + *
  5402. + * This program is distributed in the hope that it will be useful,
  5403. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5404. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5405. + * GNU General Public License for more details.
  5406. + *
  5407. + * You should have received a copy of the GNU General Public License
  5408. + * along with this program; if not, write to the Free Software
  5409. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5410. + */
  5411. +
  5412. +#ifndef _MACH_FRC_H
  5413. +#define _MACH_FRC_H
  5414. +
  5415. +#define FRC_TICK_RATE (1000000)
  5416. +
  5417. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  5418. + (slightly faster than frc_clock_ticks63()
  5419. + */
  5420. +extern unsigned long frc_clock_ticks32(void);
  5421. +
  5422. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  5423. + * Note - top bit should be ignored (see cnt32_to_63)
  5424. + */
  5425. +extern unsigned long long frc_clock_ticks63(void);
  5426. +
  5427. +#endif
  5428. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/gpio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h
  5429. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  5430. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h 2014-04-24 16:04:30.051029784 +0200
  5431. @@ -0,0 +1,17 @@
  5432. +/*
  5433. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  5434. + *
  5435. + * This file is licensed under the terms of the GNU General Public
  5436. + * License version 2. This program is licensed "as is" without any
  5437. + * warranty of any kind, whether express or implied.
  5438. + */
  5439. +
  5440. +#ifndef __ASM_ARCH_GPIO_H
  5441. +#define __ASM_ARCH_GPIO_H
  5442. +
  5443. +#define BCM2708_NR_GPIOS 54 // number of gpio lines
  5444. +
  5445. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  5446. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  5447. +
  5448. +#endif
  5449. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/hardware.h linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h
  5450. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  5451. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h 2014-04-24 15:35:00.777527936 +0200
  5452. @@ -0,0 +1,28 @@
  5453. +/*
  5454. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  5455. + *
  5456. + * This file contains the hardware definitions of the BCM2708 devices.
  5457. + *
  5458. + * Copyright (C) 2010 Broadcom
  5459. + *
  5460. + * This program is free software; you can redistribute it and/or modify
  5461. + * it under the terms of the GNU General Public License as published by
  5462. + * the Free Software Foundation; either version 2 of the License, or
  5463. + * (at your option) any later version.
  5464. + *
  5465. + * This program is distributed in the hope that it will be useful,
  5466. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5467. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5468. + * GNU General Public License for more details.
  5469. + *
  5470. + * You should have received a copy of the GNU General Public License
  5471. + * along with this program; if not, write to the Free Software
  5472. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5473. + */
  5474. +#ifndef __ASM_ARCH_HARDWARE_H
  5475. +#define __ASM_ARCH_HARDWARE_H
  5476. +
  5477. +#include <asm/sizes.h>
  5478. +#include <mach/platform.h>
  5479. +
  5480. +#endif
  5481. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/io.h linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h
  5482. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  5483. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h 2014-04-24 15:35:00.777527936 +0200
  5484. @@ -0,0 +1,27 @@
  5485. +/*
  5486. + * arch/arm/mach-bcm2708/include/mach/io.h
  5487. + *
  5488. + * Copyright (C) 2003 ARM Limited
  5489. + *
  5490. + * This program is free software; you can redistribute it and/or modify
  5491. + * it under the terms of the GNU General Public License as published by
  5492. + * the Free Software Foundation; either version 2 of the License, or
  5493. + * (at your option) any later version.
  5494. + *
  5495. + * This program is distributed in the hope that it will be useful,
  5496. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5497. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5498. + * GNU General Public License for more details.
  5499. + *
  5500. + * You should have received a copy of the GNU General Public License
  5501. + * along with this program; if not, write to the Free Software
  5502. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5503. + */
  5504. +#ifndef __ASM_ARM_ARCH_IO_H
  5505. +#define __ASM_ARM_ARCH_IO_H
  5506. +
  5507. +#define IO_SPACE_LIMIT 0xffffffff
  5508. +
  5509. +#define __io(a) __typesafe_io(a)
  5510. +
  5511. +#endif
  5512. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/irqs.h linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h
  5513. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  5514. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h 2014-04-24 16:04:30.051029784 +0200
  5515. @@ -0,0 +1,200 @@
  5516. +/*
  5517. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  5518. + *
  5519. + * Copyright (C) 2010 Broadcom
  5520. + * Copyright (C) 2003 ARM Limited
  5521. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  5522. + *
  5523. + * This program is free software; you can redistribute it and/or modify
  5524. + * it under the terms of the GNU General Public License as published by
  5525. + * the Free Software Foundation; either version 2 of the License, or
  5526. + * (at your option) any later version.
  5527. + *
  5528. + * This program is distributed in the hope that it will be useful,
  5529. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5530. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5531. + * GNU General Public License for more details.
  5532. + *
  5533. + * You should have received a copy of the GNU General Public License
  5534. + * along with this program; if not, write to the Free Software
  5535. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5536. + */
  5537. +
  5538. +#ifndef _BCM2708_IRQS_H_
  5539. +#define _BCM2708_IRQS_H_
  5540. +
  5541. +#include <mach/platform.h>
  5542. +
  5543. +/*
  5544. + * IRQ interrupts definitions are the same as the INT definitions
  5545. + * held within platform.h
  5546. + */
  5547. +#define IRQ_ARMCTRL_START 0
  5548. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  5549. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  5550. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  5551. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  5552. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  5553. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  5554. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  5555. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  5556. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  5557. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  5558. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  5559. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  5560. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  5561. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  5562. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  5563. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  5564. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  5565. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  5566. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  5567. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  5568. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  5569. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  5570. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  5571. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  5572. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  5573. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  5574. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  5575. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  5576. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  5577. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  5578. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  5579. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  5580. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  5581. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  5582. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  5583. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  5584. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  5585. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  5586. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  5587. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  5588. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  5589. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  5590. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  5591. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  5592. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  5593. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  5594. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  5595. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  5596. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  5597. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  5598. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  5599. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  5600. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  5601. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  5602. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  5603. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  5604. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  5605. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  5606. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  5607. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  5608. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  5609. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  5610. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  5611. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  5612. +
  5613. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  5614. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  5615. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  5616. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  5617. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  5618. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  5619. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  5620. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  5621. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  5622. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  5623. +
  5624. +#define FIQ_START HARD_IRQS
  5625. +
  5626. +/*
  5627. + * FIQ interrupts definitions are the same as the INT definitions.
  5628. + */
  5629. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  5630. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  5631. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  5632. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  5633. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  5634. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  5635. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  5636. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  5637. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  5638. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  5639. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  5640. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  5641. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  5642. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  5643. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  5644. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  5645. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  5646. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  5647. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  5648. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  5649. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  5650. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  5651. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  5652. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  5653. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  5654. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  5655. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  5656. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  5657. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  5658. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  5659. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  5660. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  5661. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  5662. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  5663. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  5664. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  5665. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  5666. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  5667. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  5668. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  5669. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  5670. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  5671. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  5672. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  5673. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  5674. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  5675. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  5676. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  5677. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  5678. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  5679. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  5680. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  5681. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  5682. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  5683. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  5684. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  5685. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  5686. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  5687. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  5688. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  5689. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  5690. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  5691. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  5692. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  5693. +
  5694. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  5695. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  5696. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  5697. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  5698. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  5699. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  5700. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  5701. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  5702. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  5703. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  5704. +
  5705. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  5706. +
  5707. +#define HARD_IRQS (64 + 21)
  5708. +#define FIQ_IRQS (64 + 21)
  5709. +#define GPIO_IRQS (32*5)
  5710. +#define SPARE_IRQS (64)
  5711. +
  5712. +#define NR_IRQS HARD_IRQS+FIQ_IRQS+GPIO_IRQS+SPARE_IRQS
  5713. +
  5714. +
  5715. +#endif /* _BCM2708_IRQS_H_ */
  5716. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/memory.h linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h
  5717. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  5718. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h 2014-04-24 15:35:00.777527936 +0200
  5719. @@ -0,0 +1,57 @@
  5720. +/*
  5721. + * arch/arm/mach-bcm2708/include/mach/memory.h
  5722. + *
  5723. + * Copyright (C) 2010 Broadcom
  5724. + *
  5725. + * This program is free software; you can redistribute it and/or modify
  5726. + * it under the terms of the GNU General Public License as published by
  5727. + * the Free Software Foundation; either version 2 of the License, or
  5728. + * (at your option) any later version.
  5729. + *
  5730. + * This program is distributed in the hope that it will be useful,
  5731. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5732. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5733. + * GNU General Public License for more details.
  5734. + *
  5735. + * You should have received a copy of the GNU General Public License
  5736. + * along with this program; if not, write to the Free Software
  5737. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5738. + */
  5739. +#ifndef __ASM_ARCH_MEMORY_H
  5740. +#define __ASM_ARCH_MEMORY_H
  5741. +
  5742. +/* Memory overview:
  5743. +
  5744. + [ARMcore] <--virtual addr-->
  5745. + [ARMmmu] <--physical addr-->
  5746. + [GERTmap] <--bus add-->
  5747. + [VCperiph]
  5748. +
  5749. +*/
  5750. +
  5751. +/*
  5752. + * Physical DRAM offset.
  5753. + */
  5754. +#define PLAT_PHYS_OFFSET UL(0x00000000)
  5755. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  5756. +
  5757. +#ifdef CONFIG_BCM2708_NOL2CACHE
  5758. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  5759. +#else
  5760. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  5761. +#endif
  5762. +
  5763. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  5764. + * will provide the offset into this area as well as setting the bits that
  5765. + * stop the L1 and L2 cache from being used
  5766. + *
  5767. + * WARNING: this only works because the ARM is given memory at a fixed location
  5768. + * (ARMMEM_OFFSET)
  5769. + */
  5770. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  5771. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  5772. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  5773. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - PLAT_PHYS_OFFSET))
  5774. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - PLAT_PHYS_OFFSET))
  5775. +
  5776. +#endif
  5777. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/platform.h linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h
  5778. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  5779. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h 2014-04-24 15:35:00.777527936 +0200
  5780. @@ -0,0 +1,228 @@
  5781. +/*
  5782. + * arch/arm/mach-bcm2708/include/mach/platform.h
  5783. + *
  5784. + * Copyright (C) 2010 Broadcom
  5785. + *
  5786. + * This program is free software; you can redistribute it and/or modify
  5787. + * it under the terms of the GNU General Public License as published by
  5788. + * the Free Software Foundation; either version 2 of the License, or
  5789. + * (at your option) any later version.
  5790. + *
  5791. + * This program is distributed in the hope that it will be useful,
  5792. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5793. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5794. + * GNU General Public License for more details.
  5795. + *
  5796. + * You should have received a copy of the GNU General Public License
  5797. + * along with this program; if not, write to the Free Software
  5798. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5799. + */
  5800. +
  5801. +#ifndef _BCM2708_PLATFORM_H
  5802. +#define _BCM2708_PLATFORM_H
  5803. +
  5804. +
  5805. +/* macros to get at IO space when running virtually */
  5806. +#define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  5807. +
  5808. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  5809. +
  5810. +
  5811. +/*
  5812. + * SDRAM
  5813. + */
  5814. +#define BCM2708_SDRAM_BASE 0x00000000
  5815. +
  5816. +/*
  5817. + * Logic expansion modules
  5818. + *
  5819. + */
  5820. +
  5821. +
  5822. +/* ------------------------------------------------------------------------
  5823. + * BCM2708 ARMCTRL Registers
  5824. + * ------------------------------------------------------------------------
  5825. + */
  5826. +
  5827. +#define HW_REGISTER_RW(addr) (addr)
  5828. +#define HW_REGISTER_RO(addr) (addr)
  5829. +
  5830. +#include "arm_control.h"
  5831. +#undef ARM_BASE
  5832. +
  5833. +/*
  5834. + * Definitions and addresses for the ARM CONTROL logic
  5835. + * This file is manually generated.
  5836. + */
  5837. +
  5838. +#define BCM2708_PERI_BASE 0x20000000
  5839. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  5840. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  5841. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  5842. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  5843. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  5844. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  5845. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  5846. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  5847. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  5848. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  5849. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  5850. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  5851. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  5852. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  5853. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  5854. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  5855. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  5856. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  5857. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  5858. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  5859. +
  5860. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  5861. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  5862. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  5863. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  5864. +
  5865. +
  5866. +/*
  5867. + * Interrupt assignments
  5868. + */
  5869. +
  5870. +#define ARM_IRQ1_BASE 0
  5871. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  5872. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  5873. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  5874. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  5875. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  5876. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  5877. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  5878. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  5879. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  5880. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  5881. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  5882. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  5883. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  5884. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  5885. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  5886. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  5887. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  5888. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  5889. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  5890. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  5891. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  5892. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  5893. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  5894. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  5895. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  5896. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  5897. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  5898. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  5899. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  5900. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  5901. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  5902. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  5903. +
  5904. +#define ARM_IRQ2_BASE 32
  5905. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  5906. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  5907. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  5908. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  5909. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  5910. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  5911. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  5912. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  5913. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  5914. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  5915. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  5916. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  5917. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  5918. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  5919. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  5920. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  5921. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  5922. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  5923. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  5924. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  5925. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  5926. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  5927. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  5928. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  5929. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  5930. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  5931. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  5932. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  5933. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  5934. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  5935. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  5936. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  5937. +
  5938. +#define ARM_IRQ0_BASE 64
  5939. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  5940. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  5941. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  5942. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  5943. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  5944. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  5945. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  5946. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  5947. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  5948. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  5949. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  5950. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  5951. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  5952. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  5953. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  5954. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  5955. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  5956. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  5957. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  5958. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  5959. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  5960. +
  5961. +#define MAXIRQNUM (32 + 32 + 20)
  5962. +#define MAXFIQNUM (32 + 32 + 20)
  5963. +
  5964. +#define MAX_TIMER 2
  5965. +#define MAX_PERIOD 699050
  5966. +#define TICKS_PER_uSEC 1
  5967. +
  5968. +/*
  5969. + * These are useconds NOT ticks.
  5970. + *
  5971. + */
  5972. +#define mSEC_1 1000
  5973. +#define mSEC_5 (mSEC_1 * 5)
  5974. +#define mSEC_10 (mSEC_1 * 10)
  5975. +#define mSEC_25 (mSEC_1 * 25)
  5976. +#define SEC_1 (mSEC_1 * 1000)
  5977. +
  5978. +/*
  5979. + * Watchdog
  5980. + */
  5981. +#define PM_RSTC (PM_BASE+0x1c)
  5982. +#define PM_RSTS (PM_BASE+0x20)
  5983. +#define PM_WDOG (PM_BASE+0x24)
  5984. +
  5985. +#define PM_WDOG_RESET 0000000000
  5986. +#define PM_PASSWORD 0x5a000000
  5987. +#define PM_WDOG_TIME_SET 0x000fffff
  5988. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  5989. +#define PM_RSTC_WRCFG_SET 0x00000030
  5990. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  5991. +#define PM_RSTC_RESET 0x00000102
  5992. +
  5993. +#define PM_RSTS_HADPOR_SET 0x00001000
  5994. +#define PM_RSTS_HADSRH_SET 0x00000400
  5995. +#define PM_RSTS_HADSRF_SET 0x00000200
  5996. +#define PM_RSTS_HADSRQ_SET 0x00000100
  5997. +#define PM_RSTS_HADWRH_SET 0x00000040
  5998. +#define PM_RSTS_HADWRF_SET 0x00000020
  5999. +#define PM_RSTS_HADWRQ_SET 0x00000010
  6000. +#define PM_RSTS_HADDRH_SET 0x00000004
  6001. +#define PM_RSTS_HADDRF_SET 0x00000002
  6002. +#define PM_RSTS_HADDRQ_SET 0x00000001
  6003. +
  6004. +#define UART0_CLOCK 3000000
  6005. +
  6006. +#endif
  6007. +
  6008. +/* END */
  6009. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h
  6010. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  6011. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h 2014-04-24 15:35:00.777527936 +0200
  6012. @@ -0,0 +1,26 @@
  6013. +/*
  6014. + * linux/arch/arm/mach-bcm2708/power.h
  6015. + *
  6016. + * Copyright (C) 2010 Broadcom
  6017. + *
  6018. + * This program is free software; you can redistribute it and/or modify
  6019. + * it under the terms of the GNU General Public License version 2 as
  6020. + * published by the Free Software Foundation.
  6021. + *
  6022. + * This device provides a shared mechanism for controlling the power to
  6023. + * VideoCore subsystems.
  6024. + */
  6025. +
  6026. +#ifndef _MACH_BCM2708_POWER_H
  6027. +#define _MACH_BCM2708_POWER_H
  6028. +
  6029. +#include <linux/types.h>
  6030. +#include <mach/arm_power.h>
  6031. +
  6032. +typedef unsigned int BCM_POWER_HANDLE_T;
  6033. +
  6034. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  6035. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  6036. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  6037. +
  6038. +#endif
  6039. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/system.h linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h
  6040. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  6041. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h 2014-04-24 15:35:00.777527936 +0200
  6042. @@ -0,0 +1,38 @@
  6043. +/*
  6044. + * arch/arm/mach-bcm2708/include/mach/system.h
  6045. + *
  6046. + * Copyright (C) 2010 Broadcom
  6047. + * Copyright (C) 2003 ARM Limited
  6048. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  6049. + *
  6050. + * This program is free software; you can redistribute it and/or modify
  6051. + * it under the terms of the GNU General Public License as published by
  6052. + * the Free Software Foundation; either version 2 of the License, or
  6053. + * (at your option) any later version.
  6054. + *
  6055. + * This program is distributed in the hope that it will be useful,
  6056. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6057. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6058. + * GNU General Public License for more details.
  6059. + *
  6060. + * You should have received a copy of the GNU General Public License
  6061. + * along with this program; if not, write to the Free Software
  6062. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6063. + */
  6064. +#ifndef __ASM_ARCH_SYSTEM_H
  6065. +#define __ASM_ARCH_SYSTEM_H
  6066. +
  6067. +#include <linux/io.h>
  6068. +#include <mach/hardware.h>
  6069. +#include <mach/platform.h>
  6070. +
  6071. +static inline void arch_idle(void)
  6072. +{
  6073. + /*
  6074. + * This should do all the clock switching
  6075. + * and wait for interrupt tricks
  6076. + */
  6077. + cpu_do_idle();
  6078. +}
  6079. +
  6080. +#endif
  6081. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/timex.h linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h
  6082. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  6083. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h 2014-04-24 15:35:00.777527936 +0200
  6084. @@ -0,0 +1,23 @@
  6085. +/*
  6086. + * arch/arm/mach-bcm2708/include/mach/timex.h
  6087. + *
  6088. + * BCM2708 sysem clock frequency
  6089. + *
  6090. + * Copyright (C) 2010 Broadcom
  6091. + *
  6092. + * This program is free software; you can redistribute it and/or modify
  6093. + * it under the terms of the GNU General Public License as published by
  6094. + * the Free Software Foundation; either version 2 of the License, or
  6095. + * (at your option) any later version.
  6096. + *
  6097. + * This program is distributed in the hope that it will be useful,
  6098. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6099. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6100. + * GNU General Public License for more details.
  6101. + *
  6102. + * You should have received a copy of the GNU General Public License
  6103. + * along with this program; if not, write to the Free Software
  6104. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6105. + */
  6106. +
  6107. +#define CLOCK_TICK_RATE (1000000)
  6108. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/uncompress.h linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h
  6109. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  6110. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h 2014-04-24 16:04:30.051029784 +0200
  6111. @@ -0,0 +1,84 @@
  6112. +/*
  6113. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  6114. + *
  6115. + * Copyright (C) 2010 Broadcom
  6116. + * Copyright (C) 2003 ARM Limited
  6117. + *
  6118. + * This program is free software; you can redistribute it and/or modify
  6119. + * it under the terms of the GNU General Public License as published by
  6120. + * the Free Software Foundation; either version 2 of the License, or
  6121. + * (at your option) any later version.
  6122. + *
  6123. + * This program is distributed in the hope that it will be useful,
  6124. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6125. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6126. + * GNU General Public License for more details.
  6127. + *
  6128. + * You should have received a copy of the GNU General Public License
  6129. + * along with this program; if not, write to the Free Software
  6130. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6131. + */
  6132. +
  6133. +#include <linux/io.h>
  6134. +#include <linux/amba/serial.h>
  6135. +#include <mach/hardware.h>
  6136. +
  6137. +#define UART_BAUD 115200
  6138. +
  6139. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  6140. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  6141. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  6142. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  6143. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  6144. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  6145. +
  6146. +/*
  6147. + * This does not append a newline
  6148. + */
  6149. +static inline void putc(int c)
  6150. +{
  6151. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  6152. + barrier();
  6153. +
  6154. + __raw_writel(c, BCM2708_UART_DR);
  6155. +}
  6156. +
  6157. +static inline void flush(void)
  6158. +{
  6159. + int fr;
  6160. +
  6161. + do {
  6162. + fr = __raw_readl(BCM2708_UART_FR);
  6163. + barrier();
  6164. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  6165. +}
  6166. +
  6167. +static inline void arch_decomp_setup(void)
  6168. +{
  6169. + int temp, div, rem, frac;
  6170. +
  6171. + temp = 16 * UART_BAUD;
  6172. + div = UART0_CLOCK / temp;
  6173. + rem = UART0_CLOCK % temp;
  6174. + temp = (8 * rem) / UART_BAUD;
  6175. + frac = (temp >> 1) + (temp & 1);
  6176. +
  6177. + /* Make sure the UART is disabled before we start */
  6178. + __raw_writel(0, BCM2708_UART_CR);
  6179. +
  6180. + /* Set the baud rate */
  6181. + __raw_writel(div, BCM2708_UART_IBRD);
  6182. + __raw_writel(frac, BCM2708_UART_FBRD);
  6183. +
  6184. + /* Set the UART to 8n1, FIFO enabled */
  6185. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  6186. +
  6187. + /* Enable the UART */
  6188. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  6189. + BCM2708_UART_CR);
  6190. +}
  6191. +
  6192. +/*
  6193. + * nothing to do
  6194. + */
  6195. +#define arch_decomp_wdog()
  6196. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/vcio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h
  6197. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  6198. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h 2014-04-24 16:04:30.051029784 +0200
  6199. @@ -0,0 +1,141 @@
  6200. +/*
  6201. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  6202. + *
  6203. + * Copyright (C) 2010 Broadcom
  6204. + *
  6205. + * This program is free software; you can redistribute it and/or modify
  6206. + * it under the terms of the GNU General Public License as published by
  6207. + * the Free Software Foundation; either version 2 of the License, or
  6208. + * (at your option) any later version.
  6209. + *
  6210. + * This program is distributed in the hope that it will be useful,
  6211. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6212. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6213. + * GNU General Public License for more details.
  6214. + *
  6215. + * You should have received a copy of the GNU General Public License
  6216. + * along with this program; if not, write to the Free Software
  6217. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6218. + */
  6219. +#ifndef _MACH_BCM2708_VCIO_H
  6220. +#define _MACH_BCM2708_VCIO_H
  6221. +
  6222. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  6223. + * (semaphores, doorbells, mailboxes)
  6224. + */
  6225. +
  6226. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  6227. +
  6228. +/* Constants shared with the ARM identifying separate mailbox channels */
  6229. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  6230. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  6231. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  6232. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  6233. +#define MBOX_CHAN_COUNT 9
  6234. +
  6235. +/* Mailbox property tags */
  6236. +enum {
  6237. + VCMSG_PROPERTY_END = 0x00000000,
  6238. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  6239. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  6240. + VCMSG_GET_BOARD_REVISION = 0x00020002,
  6241. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00020003,
  6242. + VCMSG_GET_BOARD_SERIAL = 0x00020004,
  6243. + VCMSG_GET_ARM_MEMORY = 0x00020005,
  6244. + VCMSG_GET_VC_MEMORY = 0x00020006,
  6245. + VCMSG_GET_CLOCKS = 0x00020007,
  6246. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  6247. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  6248. + VCMSG_GET_POWER_STATE = 0x00020001,
  6249. + VCMSG_GET_TIMING = 0x00020002,
  6250. + VCMSG_SET_POWER_STATE = 0x00028001,
  6251. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  6252. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  6253. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  6254. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  6255. + VCMSG_GET_VOLTAGE = 0x00030003,
  6256. + VCMSG_SET_VOLTAGE = 0x00038003,
  6257. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  6258. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  6259. + VCMSG_GET_TEMPERATURE = 0x00030006,
  6260. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  6261. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  6262. + VCMSG_GET_TURBO = 0x00030009,
  6263. + VCMSG_SET_TURBO = 0x00038009,
  6264. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  6265. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  6266. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  6267. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  6268. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  6269. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  6270. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  6271. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  6272. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  6273. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  6274. + VCMSG_GET_DEPTH = 0x00040005,
  6275. + VCMSG_TST_DEPTH = 0x00044005,
  6276. + VCMSG_SET_DEPTH = 0x00048005,
  6277. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  6278. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  6279. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  6280. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  6281. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  6282. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  6283. + VCMSG_GET_PITCH = 0x00040008,
  6284. + VCMSG_TST_PITCH = 0x00044008,
  6285. + VCMSG_SET_PITCH = 0x00048008,
  6286. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  6287. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  6288. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  6289. + VCMSG_GET_OVERSCAN = 0x0004000a,
  6290. + VCMSG_TST_OVERSCAN = 0x0004400a,
  6291. + VCMSG_SET_OVERSCAN = 0x0004800a,
  6292. + VCMSG_GET_PALETTE = 0x0004000b,
  6293. + VCMSG_TST_PALETTE = 0x0004400b,
  6294. + VCMSG_SET_PALETTE = 0x0004800b,
  6295. + VCMSG_GET_LAYER = 0x0004000c,
  6296. + VCMSG_TST_LAYER = 0x0004400c,
  6297. + VCMSG_SET_LAYER = 0x0004800c,
  6298. + VCMSG_GET_TRANSFORM = 0x0004000d,
  6299. + VCMSG_TST_TRANSFORM = 0x0004400d,
  6300. + VCMSG_SET_TRANSFORM = 0x0004800d,
  6301. +};
  6302. +
  6303. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  6304. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  6305. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  6306. +
  6307. +#include <linux/ioctl.h>
  6308. +
  6309. +/*
  6310. + * The major device number. We can't rely on dynamic
  6311. + * registration any more, because ioctls need to know
  6312. + * it.
  6313. + */
  6314. +#define MAJOR_NUM 100
  6315. +
  6316. +/*
  6317. + * Set the message of the device driver
  6318. + */
  6319. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  6320. +/*
  6321. + * _IOWR means that we're creating an ioctl command
  6322. + * number for passing information from a user process
  6323. + * to the kernel module and from the kernel module to user process
  6324. + *
  6325. + * The first arguments, MAJOR_NUM, is the major device
  6326. + * number we're using.
  6327. + *
  6328. + * The second argument is the number of the command
  6329. + * (there could be several with different meanings).
  6330. + *
  6331. + * The third argument is the type we want to get from
  6332. + * the process to the kernel.
  6333. + */
  6334. +
  6335. +/*
  6336. + * The name of the device file
  6337. + */
  6338. +#define DEVICE_FILE_NAME "char_dev"
  6339. +
  6340. +#endif
  6341. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/vc_mem.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h
  6342. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  6343. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h 2014-04-24 16:04:30.051029784 +0200
  6344. @@ -0,0 +1,35 @@
  6345. +/*****************************************************************************
  6346. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  6347. +*
  6348. +* Unless you and Broadcom execute a separate written software license
  6349. +* agreement governing use of this software, this software is licensed to you
  6350. +* under the terms of the GNU General Public License version 2, available at
  6351. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  6352. +*
  6353. +* Notwithstanding the above, under no circumstances may you combine this
  6354. +* software in any way with any other Broadcom software provided under a
  6355. +* license other than the GPL, without Broadcom's express prior written
  6356. +* consent.
  6357. +*****************************************************************************/
  6358. +
  6359. +#if !defined( VC_MEM_H )
  6360. +#define VC_MEM_H
  6361. +
  6362. +#include <linux/ioctl.h>
  6363. +
  6364. +#define VC_MEM_IOC_MAGIC 'v'
  6365. +
  6366. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  6367. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  6368. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  6369. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  6370. +
  6371. +#if defined( __KERNEL__ )
  6372. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  6373. +
  6374. +extern unsigned long mm_vc_mem_phys_addr;
  6375. +extern unsigned int mm_vc_mem_size;
  6376. +extern int vc_mem_get_current_size( void );
  6377. +#endif
  6378. +
  6379. +#endif /* VC_MEM_H */
  6380. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/include/mach/vmalloc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h
  6381. --- linux-3.12.18/arch/arm/mach-bcm2708/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  6382. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h 2014-04-24 15:35:00.777527936 +0200
  6383. @@ -0,0 +1,20 @@
  6384. +/*
  6385. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  6386. + *
  6387. + * Copyright (C) 2010 Broadcom
  6388. + *
  6389. + * This program is free software; you can redistribute it and/or modify
  6390. + * it under the terms of the GNU General Public License as published by
  6391. + * the Free Software Foundation; either version 2 of the License, or
  6392. + * (at your option) any later version.
  6393. + *
  6394. + * This program is distributed in the hope that it will be useful,
  6395. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6396. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6397. + * GNU General Public License for more details.
  6398. + *
  6399. + * You should have received a copy of the GNU General Public License
  6400. + * along with this program; if not, write to the Free Software
  6401. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6402. + */
  6403. +#define VMALLOC_END (0xe8000000)
  6404. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/Kconfig linux-rpi/arch/arm/mach-bcm2708/Kconfig
  6405. --- linux-3.12.18/arch/arm/mach-bcm2708/Kconfig 1970-01-01 01:00:00.000000000 +0100
  6406. +++ linux-rpi/arch/arm/mach-bcm2708/Kconfig 2014-04-24 16:04:30.051029784 +0200
  6407. @@ -0,0 +1,41 @@
  6408. +menu "Broadcom BCM2708 Implementations"
  6409. + depends on ARCH_BCM2708
  6410. +
  6411. +config MACH_BCM2708
  6412. + bool "Broadcom BCM2708 Development Platform"
  6413. + select NEED_MACH_MEMORY_H
  6414. + select NEED_MACH_IO_H
  6415. + select CPU_V6
  6416. + help
  6417. + Include support for the Broadcom(R) BCM2708 platform.
  6418. +
  6419. +config BCM2708_GPIO
  6420. + bool "BCM2708 gpio support"
  6421. + depends on MACH_BCM2708
  6422. + select ARCH_REQUIRE_GPIOLIB
  6423. + default y
  6424. + help
  6425. + Include support for the Broadcom(R) BCM2708 gpio.
  6426. +
  6427. +config BCM2708_VCMEM
  6428. + bool "Videocore Memory"
  6429. + depends on MACH_BCM2708
  6430. + default y
  6431. + help
  6432. + Helper for videocore memory access and total size allocation.
  6433. +
  6434. +config BCM2708_NOL2CACHE
  6435. + bool "Videocore L2 cache disable"
  6436. + depends on MACH_BCM2708
  6437. + default n
  6438. + help
  6439. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  6440. +
  6441. +config BCM2708_SPIDEV
  6442. + bool "Bind spidev to SPI0 master"
  6443. + depends on MACH_BCM2708
  6444. + depends on SPI
  6445. + default y
  6446. + help
  6447. + Binds spidev driver to the SPI0 master
  6448. +endmenu
  6449. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/Makefile linux-rpi/arch/arm/mach-bcm2708/Makefile
  6450. --- linux-3.12.18/arch/arm/mach-bcm2708/Makefile 1970-01-01 01:00:00.000000000 +0100
  6451. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile 2014-04-24 16:04:30.051029784 +0200
  6452. @@ -0,0 +1,7 @@
  6453. +#
  6454. +# Makefile for the linux kernel.
  6455. +#
  6456. +
  6457. +obj-$(CONFIG_MACH_BCM2708) += clock.o bcm2708.o armctrl.o vcio.o power.o dma.o
  6458. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  6459. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  6460. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/Makefile.boot linux-rpi/arch/arm/mach-bcm2708/Makefile.boot
  6461. --- linux-3.12.18/arch/arm/mach-bcm2708/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  6462. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile.boot 2014-04-24 15:35:00.773527891 +0200
  6463. @@ -0,0 +1,3 @@
  6464. + zreladdr-y := 0x00008000
  6465. +params_phys-y := 0x00000100
  6466. +initrd_phys-y := 0x00800000
  6467. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/power.c linux-rpi/arch/arm/mach-bcm2708/power.c
  6468. --- linux-3.12.18/arch/arm/mach-bcm2708/power.c 1970-01-01 01:00:00.000000000 +0100
  6469. +++ linux-rpi/arch/arm/mach-bcm2708/power.c 2014-04-24 15:35:00.777527936 +0200
  6470. @@ -0,0 +1,194 @@
  6471. +/*
  6472. + * linux/arch/arm/mach-bcm2708/power.c
  6473. + *
  6474. + * Copyright (C) 2010 Broadcom
  6475. + *
  6476. + * This program is free software; you can redistribute it and/or modify
  6477. + * it under the terms of the GNU General Public License version 2 as
  6478. + * published by the Free Software Foundation.
  6479. + *
  6480. + * This device provides a shared mechanism for controlling the power to
  6481. + * VideoCore subsystems.
  6482. + */
  6483. +
  6484. +#include <linux/module.h>
  6485. +#include <linux/semaphore.h>
  6486. +#include <linux/bug.h>
  6487. +#include <mach/power.h>
  6488. +#include <mach/vcio.h>
  6489. +#include <mach/arm_power.h>
  6490. +
  6491. +#define DRIVER_NAME "bcm2708_power"
  6492. +
  6493. +#define BCM_POWER_MAXCLIENTS 4
  6494. +#define BCM_POWER_NOCLIENT (1<<31)
  6495. +
  6496. +/* Some drivers expect there devices to be permanently powered */
  6497. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  6498. +
  6499. +#if 1
  6500. +#define DPRINTK printk
  6501. +#else
  6502. +#define DPRINTK if (0) printk
  6503. +#endif
  6504. +
  6505. +struct state_struct {
  6506. + uint32_t global_request;
  6507. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  6508. + struct semaphore client_mutex;
  6509. + struct semaphore mutex;
  6510. +} g_state;
  6511. +
  6512. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  6513. +{
  6514. + BCM_POWER_HANDLE_T i;
  6515. + int ret = -EBUSY;
  6516. +
  6517. + down(&g_state.client_mutex);
  6518. +
  6519. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  6520. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  6521. + g_state.client_request[i] = BCM_POWER_NONE;
  6522. + *handle = i;
  6523. + ret = 0;
  6524. + break;
  6525. + }
  6526. + }
  6527. +
  6528. + up(&g_state.client_mutex);
  6529. +
  6530. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  6531. +
  6532. + return ret;
  6533. +}
  6534. +EXPORT_SYMBOL_GPL(bcm_power_open);
  6535. +
  6536. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  6537. +{
  6538. + int rc = 0;
  6539. +
  6540. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  6541. +
  6542. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  6543. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  6544. + if (down_interruptible(&g_state.mutex) != 0) {
  6545. + DPRINTK("bcm_power_request -> interrupted\n");
  6546. + return -EINTR;
  6547. + }
  6548. +
  6549. + if (request != g_state.client_request[handle]) {
  6550. + uint32_t others_request = 0;
  6551. + uint32_t global_request;
  6552. + BCM_POWER_HANDLE_T i;
  6553. +
  6554. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  6555. + if (i != handle)
  6556. + others_request |=
  6557. + g_state.client_request[i];
  6558. + }
  6559. + others_request &= ~BCM_POWER_NOCLIENT;
  6560. +
  6561. + global_request = request | others_request;
  6562. + if (global_request != g_state.global_request) {
  6563. + uint32_t actual;
  6564. +
  6565. + /* Send a request to VideoCore */
  6566. + bcm_mailbox_write(MBOX_CHAN_POWER,
  6567. + global_request << 4);
  6568. +
  6569. + /* Wait for a response during power-up */
  6570. + if (global_request & ~g_state.global_request) {
  6571. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  6572. + &actual);
  6573. + DPRINTK
  6574. + ("bcm_mailbox_read -> %08x, %d\n",
  6575. + actual, rc);
  6576. + actual >>= 4;
  6577. + } else {
  6578. + rc = 0;
  6579. + actual = global_request;
  6580. + }
  6581. +
  6582. + if (rc == 0) {
  6583. + if (actual != global_request) {
  6584. + printk(KERN_ERR
  6585. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  6586. + __func__,
  6587. + g_state.global_request,
  6588. + global_request, actual, request, others_request);
  6589. + /* A failure */
  6590. + BUG_ON((others_request & actual)
  6591. + != others_request);
  6592. + request &= actual;
  6593. + rc = -EIO;
  6594. + }
  6595. +
  6596. + g_state.global_request = actual;
  6597. + g_state.client_request[handle] =
  6598. + request;
  6599. + }
  6600. + }
  6601. + }
  6602. + up(&g_state.mutex);
  6603. + } else {
  6604. + rc = -EINVAL;
  6605. + }
  6606. + DPRINTK("bcm_power_request -> %d\n", rc);
  6607. + return rc;
  6608. +}
  6609. +EXPORT_SYMBOL_GPL(bcm_power_request);
  6610. +
  6611. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  6612. +{
  6613. + int rc;
  6614. +
  6615. + DPRINTK("bcm_power_close(%d)\n", handle);
  6616. +
  6617. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  6618. + if (rc == 0)
  6619. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  6620. +
  6621. + return rc;
  6622. +}
  6623. +EXPORT_SYMBOL_GPL(bcm_power_close);
  6624. +
  6625. +static int __init bcm_power_init(void)
  6626. +{
  6627. +#if defined(BCM_POWER_ALWAYS_ON)
  6628. + BCM_POWER_HANDLE_T always_on_handle;
  6629. +#endif
  6630. + int rc = 0;
  6631. + int i;
  6632. +
  6633. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  6634. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  6635. +
  6636. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  6637. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  6638. +
  6639. + sema_init(&g_state.client_mutex, 1);
  6640. + sema_init(&g_state.mutex, 1);
  6641. +
  6642. + g_state.global_request = 0;
  6643. +
  6644. +#if defined(BCM_POWER_ALWAYS_ON)
  6645. + if (BCM_POWER_ALWAYS_ON) {
  6646. + bcm_power_open(&always_on_handle);
  6647. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  6648. + }
  6649. +#endif
  6650. +
  6651. + return rc;
  6652. +}
  6653. +
  6654. +static void __exit bcm_power_exit(void)
  6655. +{
  6656. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  6657. +}
  6658. +
  6659. +arch_initcall(bcm_power_init); /* Initialize early */
  6660. +module_exit(bcm_power_exit);
  6661. +
  6662. +MODULE_AUTHOR("Phil Elwell");
  6663. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  6664. +MODULE_LICENSE("GPL");
  6665. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/vcio.c linux-rpi/arch/arm/mach-bcm2708/vcio.c
  6666. --- linux-3.12.18/arch/arm/mach-bcm2708/vcio.c 1970-01-01 01:00:00.000000000 +0100
  6667. +++ linux-rpi/arch/arm/mach-bcm2708/vcio.c 2014-04-24 16:04:30.051029784 +0200
  6668. @@ -0,0 +1,474 @@
  6669. +/*
  6670. + * linux/arch/arm/mach-bcm2708/vcio.c
  6671. + *
  6672. + * Copyright (C) 2010 Broadcom
  6673. + *
  6674. + * This program is free software; you can redistribute it and/or modify
  6675. + * it under the terms of the GNU General Public License version 2 as
  6676. + * published by the Free Software Foundation.
  6677. + *
  6678. + * This device provides a shared mechanism for writing to the mailboxes,
  6679. + * semaphores, doorbells etc. that are shared between the ARM and the
  6680. + * VideoCore processor
  6681. + */
  6682. +
  6683. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  6684. +#define SUPPORT_SYSRQ
  6685. +#endif
  6686. +
  6687. +#include <linux/module.h>
  6688. +#include <linux/console.h>
  6689. +#include <linux/serial_core.h>
  6690. +#include <linux/serial.h>
  6691. +#include <linux/errno.h>
  6692. +#include <linux/device.h>
  6693. +#include <linux/init.h>
  6694. +#include <linux/mm.h>
  6695. +#include <linux/dma-mapping.h>
  6696. +#include <linux/platform_device.h>
  6697. +#include <linux/sysrq.h>
  6698. +#include <linux/delay.h>
  6699. +#include <linux/slab.h>
  6700. +#include <linux/interrupt.h>
  6701. +#include <linux/irq.h>
  6702. +
  6703. +#include <linux/io.h>
  6704. +
  6705. +#include <mach/vcio.h>
  6706. +#include <mach/platform.h>
  6707. +
  6708. +#include <asm/uaccess.h>
  6709. +
  6710. +
  6711. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  6712. +
  6713. +/* ----------------------------------------------------------------------
  6714. + * Mailbox
  6715. + * -------------------------------------------------------------------- */
  6716. +
  6717. +/* offsets from a mail box base address */
  6718. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  6719. +#define MAIL_RD 0x00 /* read - and next 4 words */
  6720. +#define MAIL_POL 0x10 /* read without popping the fifo */
  6721. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  6722. +#define MAIL_STA 0x18 /* status */
  6723. +#define MAIL_CNF 0x1C /* configuration */
  6724. +
  6725. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  6726. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  6727. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  6728. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  6729. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  6730. +
  6731. +#define MBOX_MAGIC 0xd0d0c0de
  6732. +
  6733. +struct vc_mailbox {
  6734. + struct device *dev; /* parent device */
  6735. + void __iomem *status;
  6736. + void __iomem *config;
  6737. + void __iomem *read;
  6738. + void __iomem *write;
  6739. + uint32_t msg[MBOX_CHAN_COUNT];
  6740. + struct semaphore sema[MBOX_CHAN_COUNT];
  6741. + uint32_t magic;
  6742. +};
  6743. +
  6744. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  6745. + uint32_t addr_mbox)
  6746. +{
  6747. + int i;
  6748. +
  6749. + mbox_out->dev = dev;
  6750. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  6751. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  6752. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  6753. + /* Write to the other mailbox */
  6754. + mbox_out->write =
  6755. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  6756. + MAIL_WRT);
  6757. +
  6758. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  6759. + mbox_out->msg[i] = 0;
  6760. + sema_init(&mbox_out->sema[i], 0);
  6761. + }
  6762. +
  6763. + /* Enable the interrupt on data reception */
  6764. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  6765. +
  6766. + mbox_out->magic = MBOX_MAGIC;
  6767. +}
  6768. +
  6769. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  6770. +{
  6771. + int rc;
  6772. +
  6773. + if (mbox->magic != MBOX_MAGIC)
  6774. + rc = -EINVAL;
  6775. + else {
  6776. + /* wait for the mailbox FIFO to have some space in it */
  6777. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  6778. + cpu_relax();
  6779. +
  6780. + writel(MBOX_MSG(chan, data28), mbox->write);
  6781. + rc = 0;
  6782. + }
  6783. + return rc;
  6784. +}
  6785. +
  6786. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  6787. +{
  6788. + int rc;
  6789. +
  6790. + if (mbox->magic != MBOX_MAGIC)
  6791. + rc = -EINVAL;
  6792. + else {
  6793. + down(&mbox->sema[chan]);
  6794. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  6795. + mbox->msg[chan] = 0;
  6796. + rc = 0;
  6797. + }
  6798. + return rc;
  6799. +}
  6800. +
  6801. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  6802. +{
  6803. + /* wait for the mailbox FIFO to have some data in it */
  6804. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  6805. + int status = readl(mbox->status);
  6806. + int ret = IRQ_NONE;
  6807. +
  6808. + while (!(status & ARM_MS_EMPTY)) {
  6809. + uint32_t msg = readl(mbox->read);
  6810. + int chan = MBOX_CHAN(msg);
  6811. + if (chan < MBOX_CHAN_COUNT) {
  6812. + if (mbox->msg[chan]) {
  6813. + /* Overflow */
  6814. + printk(KERN_ERR DRIVER_NAME
  6815. + ": mbox chan %d overflow - drop %08x\n",
  6816. + chan, msg);
  6817. + } else {
  6818. + mbox->msg[chan] = (msg | 0xf);
  6819. + up(&mbox->sema[chan]);
  6820. + }
  6821. + } else {
  6822. + printk(KERN_ERR DRIVER_NAME
  6823. + ": invalid channel selector (msg %08x)\n", msg);
  6824. + }
  6825. + ret = IRQ_HANDLED;
  6826. + status = readl(mbox->status);
  6827. + }
  6828. + return ret;
  6829. +}
  6830. +
  6831. +static struct irqaction mbox_irqaction = {
  6832. + .name = "ARM Mailbox IRQ",
  6833. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  6834. + .handler = mbox_irq,
  6835. +};
  6836. +
  6837. +/* ----------------------------------------------------------------------
  6838. + * Mailbox Methods
  6839. + * -------------------------------------------------------------------- */
  6840. +
  6841. +static struct device *mbox_dev; /* we assume there's only one! */
  6842. +
  6843. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  6844. +{
  6845. + int rc;
  6846. +
  6847. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  6848. + device_lock(dev);
  6849. + rc = mbox_write(mailbox, chan, data28);
  6850. + device_unlock(dev);
  6851. +
  6852. + return rc;
  6853. +}
  6854. +
  6855. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  6856. +{
  6857. + int rc;
  6858. +
  6859. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  6860. + device_lock(dev);
  6861. + rc = mbox_read(mailbox, chan, data28);
  6862. + device_unlock(dev);
  6863. +
  6864. + return rc;
  6865. +}
  6866. +
  6867. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  6868. +{
  6869. + if (mbox_dev)
  6870. + return dev_mbox_write(mbox_dev, chan, data28);
  6871. + else
  6872. + return -ENODEV;
  6873. +}
  6874. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  6875. +
  6876. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  6877. +{
  6878. + if (mbox_dev)
  6879. + return dev_mbox_read(mbox_dev, chan, data28);
  6880. + else
  6881. + return -ENODEV;
  6882. +}
  6883. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  6884. +
  6885. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  6886. +{
  6887. + mbox_dev = dev;
  6888. +}
  6889. +
  6890. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  6891. +{
  6892. + if ( (uint32_t)src < TASK_SIZE)
  6893. + {
  6894. + return copy_from_user(dst, src, size);
  6895. + }
  6896. + else
  6897. + {
  6898. + memcpy( dst, src, size );
  6899. + return 0;
  6900. + }
  6901. +}
  6902. +
  6903. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  6904. +{
  6905. + if ( (uint32_t)dst < TASK_SIZE)
  6906. + {
  6907. + return copy_to_user(dst, src, size);
  6908. + }
  6909. + else
  6910. + {
  6911. + memcpy( dst, src, size );
  6912. + return 0;
  6913. + }
  6914. +}
  6915. +
  6916. +static DEFINE_MUTEX(mailbox_lock);
  6917. +extern int bcm_mailbox_property(void *data, int size)
  6918. +{
  6919. + uint32_t success;
  6920. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  6921. + void *mem_kern; /* the memory address accessed from driver */
  6922. + int s = 0;
  6923. +
  6924. + mutex_lock(&mailbox_lock);
  6925. + /* allocate some memory for the messages communicating with GPU */
  6926. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  6927. + if (mem_kern) {
  6928. + /* create the message */
  6929. + mbox_copy_from_user(mem_kern, data, size);
  6930. +
  6931. + /* send the message */
  6932. + wmb();
  6933. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  6934. + if (s == 0) {
  6935. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  6936. + }
  6937. + if (s == 0) {
  6938. + /* copy the response */
  6939. + rmb();
  6940. + mbox_copy_to_user(data, mem_kern, size);
  6941. + }
  6942. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  6943. + } else {
  6944. + s = -ENOMEM;
  6945. + }
  6946. + if (s != 0)
  6947. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  6948. +
  6949. + mutex_unlock(&mailbox_lock);
  6950. + return s;
  6951. +}
  6952. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  6953. +
  6954. +/* ----------------------------------------------------------------------
  6955. + * Platform Device for Mailbox
  6956. + * -------------------------------------------------------------------- */
  6957. +
  6958. +/*
  6959. + * Is the device open right now? Used to prevent
  6960. + * concurent access into the same device
  6961. + */
  6962. +static int Device_Open = 0;
  6963. +
  6964. +/*
  6965. + * This is called whenever a process attempts to open the device file
  6966. + */
  6967. +static int device_open(struct inode *inode, struct file *file)
  6968. +{
  6969. + /*
  6970. + * We don't want to talk to two processes at the same time
  6971. + */
  6972. + if (Device_Open)
  6973. + return -EBUSY;
  6974. +
  6975. + Device_Open++;
  6976. + /*
  6977. + * Initialize the message
  6978. + */
  6979. + try_module_get(THIS_MODULE);
  6980. + return 0;
  6981. +}
  6982. +
  6983. +static int device_release(struct inode *inode, struct file *file)
  6984. +{
  6985. + /*
  6986. + * We're now ready for our next caller
  6987. + */
  6988. + Device_Open--;
  6989. +
  6990. + module_put(THIS_MODULE);
  6991. + return 0;
  6992. +}
  6993. +
  6994. +/*
  6995. + * This function is called whenever a process tries to do an ioctl on our
  6996. + * device file. We get two extra parameters (additional to the inode and file
  6997. + * structures, which all device functions get): the number of the ioctl called
  6998. + * and the parameter given to the ioctl function.
  6999. + *
  7000. + * If the ioctl is write or read/write (meaning output is returned to the
  7001. + * calling process), the ioctl call returns the output of this function.
  7002. + *
  7003. + */
  7004. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  7005. + unsigned int ioctl_num, /* number and param for ioctl */
  7006. + unsigned long ioctl_param)
  7007. +{
  7008. + unsigned size;
  7009. + /*
  7010. + * Switch according to the ioctl called
  7011. + */
  7012. + switch (ioctl_num) {
  7013. + case IOCTL_MBOX_PROPERTY:
  7014. + /*
  7015. + * Receive a pointer to a message (in user space) and set that
  7016. + * to be the device's message. Get the parameter given to
  7017. + * ioctl by the process.
  7018. + */
  7019. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  7020. + return bcm_mailbox_property((void *)ioctl_param, size);
  7021. + break;
  7022. + default:
  7023. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  7024. + return -EINVAL;
  7025. + }
  7026. +
  7027. + return 0;
  7028. +}
  7029. +
  7030. +/* Module Declarations */
  7031. +
  7032. +/*
  7033. + * This structure will hold the functions to be called
  7034. + * when a process does something to the device we
  7035. + * created. Since a pointer to this structure is kept in
  7036. + * the devices table, it can't be local to
  7037. + * init_module. NULL is for unimplemented functios.
  7038. + */
  7039. +struct file_operations fops = {
  7040. + .unlocked_ioctl = device_ioctl,
  7041. + .open = device_open,
  7042. + .release = device_release, /* a.k.a. close */
  7043. +};
  7044. +
  7045. +static int bcm_vcio_probe(struct platform_device *pdev)
  7046. +{
  7047. + int ret = 0;
  7048. + struct vc_mailbox *mailbox;
  7049. +
  7050. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  7051. + if (NULL == mailbox) {
  7052. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  7053. + "mailbox memory\n");
  7054. + ret = -ENOMEM;
  7055. + } else {
  7056. + struct resource *res;
  7057. +
  7058. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  7059. + if (res == NULL) {
  7060. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  7061. + "resource\n");
  7062. + ret = -ENODEV;
  7063. + kfree(mailbox);
  7064. + } else {
  7065. + /* should be based on the registers from res really */
  7066. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  7067. +
  7068. + platform_set_drvdata(pdev, mailbox);
  7069. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  7070. +
  7071. + mbox_irqaction.dev_id = mailbox;
  7072. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  7073. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  7074. + __io_address(ARM_0_MAIL0_RD));
  7075. + }
  7076. + }
  7077. +
  7078. + if (ret == 0) {
  7079. + /*
  7080. + * Register the character device
  7081. + */
  7082. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  7083. +
  7084. + /*
  7085. + * Negative values signify an error
  7086. + */
  7087. + if (ret < 0) {
  7088. + printk(KERN_ERR DRIVER_NAME
  7089. + "Failed registering the character device %d\n", ret);
  7090. + return ret;
  7091. + }
  7092. + }
  7093. + return ret;
  7094. +}
  7095. +
  7096. +static int bcm_vcio_remove(struct platform_device *pdev)
  7097. +{
  7098. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  7099. +
  7100. + platform_set_drvdata(pdev, NULL);
  7101. + kfree(mailbox);
  7102. +
  7103. + return 0;
  7104. +}
  7105. +
  7106. +static struct platform_driver bcm_mbox_driver = {
  7107. + .probe = bcm_vcio_probe,
  7108. + .remove = bcm_vcio_remove,
  7109. +
  7110. + .driver = {
  7111. + .name = DRIVER_NAME,
  7112. + .owner = THIS_MODULE,
  7113. + },
  7114. +};
  7115. +
  7116. +static int __init bcm_mbox_init(void)
  7117. +{
  7118. + int ret;
  7119. +
  7120. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  7121. +
  7122. + ret = platform_driver_register(&bcm_mbox_driver);
  7123. + if (ret != 0) {
  7124. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  7125. + "on platform\n");
  7126. + }
  7127. +
  7128. + return ret;
  7129. +}
  7130. +
  7131. +static void __exit bcm_mbox_exit(void)
  7132. +{
  7133. + platform_driver_unregister(&bcm_mbox_driver);
  7134. +}
  7135. +
  7136. +arch_initcall(bcm_mbox_init); /* Initialize early */
  7137. +module_exit(bcm_mbox_exit);
  7138. +
  7139. +MODULE_AUTHOR("Gray Girling");
  7140. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  7141. +MODULE_LICENSE("GPL");
  7142. +MODULE_ALIAS("platform:bcm-mbox");
  7143. diff -Nur linux-3.12.18/arch/arm/mach-bcm2708/vc_mem.c linux-rpi/arch/arm/mach-bcm2708/vc_mem.c
  7144. --- linux-3.12.18/arch/arm/mach-bcm2708/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  7145. +++ linux-rpi/arch/arm/mach-bcm2708/vc_mem.c 2014-04-24 15:35:00.777527936 +0200
  7146. @@ -0,0 +1,432 @@
  7147. +/*****************************************************************************
  7148. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  7149. +*
  7150. +* Unless you and Broadcom execute a separate written software license
  7151. +* agreement governing use of this software, this software is licensed to you
  7152. +* under the terms of the GNU General Public License version 2, available at
  7153. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  7154. +*
  7155. +* Notwithstanding the above, under no circumstances may you combine this
  7156. +* software in any way with any other Broadcom software provided under a
  7157. +* license other than the GPL, without Broadcom's express prior written
  7158. +* consent.
  7159. +*****************************************************************************/
  7160. +
  7161. +#include <linux/kernel.h>
  7162. +#include <linux/module.h>
  7163. +#include <linux/fs.h>
  7164. +#include <linux/device.h>
  7165. +#include <linux/cdev.h>
  7166. +#include <linux/mm.h>
  7167. +#include <linux/slab.h>
  7168. +#include <linux/debugfs.h>
  7169. +#include <asm/uaccess.h>
  7170. +#include <linux/dma-mapping.h>
  7171. +
  7172. +#ifdef CONFIG_ARCH_KONA
  7173. +#include <chal/chal_ipc.h>
  7174. +#elif CONFIG_ARCH_BCM2708
  7175. +#else
  7176. +#include <csp/chal_ipc.h>
  7177. +#endif
  7178. +
  7179. +#include "mach/vc_mem.h"
  7180. +#include <mach/vcio.h>
  7181. +
  7182. +#define DRIVER_NAME "vc-mem"
  7183. +
  7184. +// Device (/dev) related variables
  7185. +static dev_t vc_mem_devnum = 0;
  7186. +static struct class *vc_mem_class = NULL;
  7187. +static struct cdev vc_mem_cdev;
  7188. +static int vc_mem_inited = 0;
  7189. +
  7190. +#ifdef CONFIG_DEBUG_FS
  7191. +static struct dentry *vc_mem_debugfs_entry;
  7192. +#endif
  7193. +
  7194. +/*
  7195. + * Videocore memory addresses and size
  7196. + *
  7197. + * Drivers that wish to know the videocore memory addresses and sizes should
  7198. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  7199. + * headers. This allows the other drivers to not be tied down to a a certain
  7200. + * address/size at compile time.
  7201. + *
  7202. + * In the future, the goal is to have the videocore memory virtual address and
  7203. + * size be calculated at boot time rather than at compile time. The decision of
  7204. + * where the videocore memory resides and its size would be in the hands of the
  7205. + * bootloader (and/or kernel). When that happens, the values of these variables
  7206. + * would be calculated and assigned in the init function.
  7207. + */
  7208. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  7209. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  7210. +unsigned int mm_vc_mem_size = 0;
  7211. +unsigned int mm_vc_mem_base = 0;
  7212. +
  7213. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  7214. +EXPORT_SYMBOL(mm_vc_mem_size);
  7215. +EXPORT_SYMBOL(mm_vc_mem_base);
  7216. +
  7217. +static uint phys_addr = 0;
  7218. +static uint mem_size = 0;
  7219. +static uint mem_base = 0;
  7220. +
  7221. +
  7222. +/****************************************************************************
  7223. +*
  7224. +* vc_mem_open
  7225. +*
  7226. +***************************************************************************/
  7227. +
  7228. +static int
  7229. +vc_mem_open(struct inode *inode, struct file *file)
  7230. +{
  7231. + (void) inode;
  7232. + (void) file;
  7233. +
  7234. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7235. +
  7236. + return 0;
  7237. +}
  7238. +
  7239. +/****************************************************************************
  7240. +*
  7241. +* vc_mem_release
  7242. +*
  7243. +***************************************************************************/
  7244. +
  7245. +static int
  7246. +vc_mem_release(struct inode *inode, struct file *file)
  7247. +{
  7248. + (void) inode;
  7249. + (void) file;
  7250. +
  7251. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7252. +
  7253. + return 0;
  7254. +}
  7255. +
  7256. +/****************************************************************************
  7257. +*
  7258. +* vc_mem_get_size
  7259. +*
  7260. +***************************************************************************/
  7261. +
  7262. +static void
  7263. +vc_mem_get_size(void)
  7264. +{
  7265. +}
  7266. +
  7267. +/****************************************************************************
  7268. +*
  7269. +* vc_mem_get_base
  7270. +*
  7271. +***************************************************************************/
  7272. +
  7273. +static void
  7274. +vc_mem_get_base(void)
  7275. +{
  7276. +}
  7277. +
  7278. +/****************************************************************************
  7279. +*
  7280. +* vc_mem_get_current_size
  7281. +*
  7282. +***************************************************************************/
  7283. +
  7284. +int
  7285. +vc_mem_get_current_size(void)
  7286. +{
  7287. + return mm_vc_mem_size;
  7288. +}
  7289. +
  7290. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  7291. +
  7292. +/****************************************************************************
  7293. +*
  7294. +* vc_mem_ioctl
  7295. +*
  7296. +***************************************************************************/
  7297. +
  7298. +static long
  7299. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  7300. +{
  7301. + int rc = 0;
  7302. +
  7303. + (void) cmd;
  7304. + (void) arg;
  7305. +
  7306. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7307. +
  7308. + switch (cmd) {
  7309. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  7310. + {
  7311. + pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
  7312. + __func__, (void *) mm_vc_mem_phys_addr);
  7313. +
  7314. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  7315. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  7316. + rc = -EFAULT;
  7317. + }
  7318. + break;
  7319. + }
  7320. + case VC_MEM_IOC_MEM_SIZE:
  7321. + {
  7322. + // Get the videocore memory size first
  7323. + vc_mem_get_size();
  7324. +
  7325. + pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
  7326. + mm_vc_mem_size);
  7327. +
  7328. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  7329. + sizeof (mm_vc_mem_size)) != 0) {
  7330. + rc = -EFAULT;
  7331. + }
  7332. + break;
  7333. + }
  7334. + case VC_MEM_IOC_MEM_BASE:
  7335. + {
  7336. + // Get the videocore memory base
  7337. + vc_mem_get_base();
  7338. +
  7339. + pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
  7340. + mm_vc_mem_base);
  7341. +
  7342. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  7343. + sizeof (mm_vc_mem_base)) != 0) {
  7344. + rc = -EFAULT;
  7345. + }
  7346. + break;
  7347. + }
  7348. + case VC_MEM_IOC_MEM_LOAD:
  7349. + {
  7350. + // Get the videocore memory base
  7351. + vc_mem_get_base();
  7352. +
  7353. + pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
  7354. + mm_vc_mem_base);
  7355. +
  7356. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  7357. + sizeof (mm_vc_mem_base)) != 0) {
  7358. + rc = -EFAULT;
  7359. + }
  7360. + break;
  7361. + }
  7362. + default:
  7363. + {
  7364. + return -ENOTTY;
  7365. + }
  7366. + }
  7367. + pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
  7368. +
  7369. + return rc;
  7370. +}
  7371. +
  7372. +/****************************************************************************
  7373. +*
  7374. +* vc_mem_mmap
  7375. +*
  7376. +***************************************************************************/
  7377. +
  7378. +static int
  7379. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  7380. +{
  7381. + int rc = 0;
  7382. + unsigned long length = vma->vm_end - vma->vm_start;
  7383. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  7384. +
  7385. + pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
  7386. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  7387. + (long) vma->vm_pgoff);
  7388. +
  7389. + if (offset + length > mm_vc_mem_size) {
  7390. + pr_err("%s: length %ld is too big\n", __func__, length);
  7391. + return -EINVAL;
  7392. + }
  7393. + // Do not cache the memory map
  7394. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  7395. +
  7396. + rc = remap_pfn_range(vma, vma->vm_start,
  7397. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  7398. + vma->vm_pgoff, length, vma->vm_page_prot);
  7399. + if (rc != 0) {
  7400. + pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
  7401. + }
  7402. +
  7403. + return rc;
  7404. +}
  7405. +
  7406. +/****************************************************************************
  7407. +*
  7408. +* File Operations for the driver.
  7409. +*
  7410. +***************************************************************************/
  7411. +
  7412. +static const struct file_operations vc_mem_fops = {
  7413. + .owner = THIS_MODULE,
  7414. + .open = vc_mem_open,
  7415. + .release = vc_mem_release,
  7416. + .unlocked_ioctl = vc_mem_ioctl,
  7417. + .mmap = vc_mem_mmap,
  7418. +};
  7419. +
  7420. +#ifdef CONFIG_DEBUG_FS
  7421. +static void vc_mem_debugfs_deinit(void)
  7422. +{
  7423. + debugfs_remove_recursive(vc_mem_debugfs_entry);
  7424. + vc_mem_debugfs_entry = NULL;
  7425. +}
  7426. +
  7427. +
  7428. +static int vc_mem_debugfs_init(
  7429. + struct device *dev)
  7430. +{
  7431. + vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
  7432. + if (!vc_mem_debugfs_entry) {
  7433. + dev_warn(dev, "could not create debugfs entry\n");
  7434. + return -EFAULT;
  7435. + }
  7436. +
  7437. + if (!debugfs_create_x32("vc_mem_phys_addr",
  7438. + 0444,
  7439. + vc_mem_debugfs_entry,
  7440. + (u32 *)&mm_vc_mem_phys_addr)) {
  7441. + dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
  7442. + __func__);
  7443. + goto fail;
  7444. + }
  7445. +
  7446. + if (!debugfs_create_x32("vc_mem_size",
  7447. + 0444,
  7448. + vc_mem_debugfs_entry,
  7449. + (u32 *)&mm_vc_mem_size)) {
  7450. + dev_warn(dev, "%s:could not create vc_mem_size entry\n",
  7451. + __func__);
  7452. + goto fail;
  7453. + }
  7454. +
  7455. + if (!debugfs_create_x32("vc_mem_base",
  7456. + 0444,
  7457. + vc_mem_debugfs_entry,
  7458. + (u32 *)&mm_vc_mem_base)) {
  7459. + dev_warn(dev, "%s:could not create vc_mem_base entry\n",
  7460. + __func__);
  7461. + goto fail;
  7462. + }
  7463. +
  7464. + return 0;
  7465. +
  7466. +fail:
  7467. + vc_mem_debugfs_deinit();
  7468. + return -EFAULT;
  7469. +}
  7470. +
  7471. +#endif /* CONFIG_DEBUG_FS */
  7472. +
  7473. +
  7474. +/****************************************************************************
  7475. +*
  7476. +* vc_mem_init
  7477. +*
  7478. +***************************************************************************/
  7479. +
  7480. +static int __init
  7481. +vc_mem_init(void)
  7482. +{
  7483. + int rc = -EFAULT;
  7484. + struct device *dev;
  7485. +
  7486. + pr_debug("%s: called\n", __func__);
  7487. +
  7488. + mm_vc_mem_phys_addr = phys_addr;
  7489. + mm_vc_mem_size = mem_size;
  7490. + mm_vc_mem_base = mem_base;
  7491. +
  7492. + vc_mem_get_size();
  7493. +
  7494. + pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  7495. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  7496. +
  7497. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  7498. + pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
  7499. + __func__, rc);
  7500. + goto out_err;
  7501. + }
  7502. +
  7503. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  7504. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  7505. + pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
  7506. + goto out_unregister;
  7507. + }
  7508. +
  7509. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  7510. + if (IS_ERR(vc_mem_class)) {
  7511. + rc = PTR_ERR(vc_mem_class);
  7512. + pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
  7513. + goto out_cdev_del;
  7514. + }
  7515. +
  7516. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  7517. + DRIVER_NAME);
  7518. + if (IS_ERR(dev)) {
  7519. + rc = PTR_ERR(dev);
  7520. + pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
  7521. + goto out_class_destroy;
  7522. + }
  7523. +
  7524. +#ifdef CONFIG_DEBUG_FS
  7525. + /* don't fail if the debug entries cannot be created */
  7526. + vc_mem_debugfs_init(dev);
  7527. +#endif
  7528. +
  7529. + vc_mem_inited = 1;
  7530. + return 0;
  7531. +
  7532. + device_destroy(vc_mem_class, vc_mem_devnum);
  7533. +
  7534. + out_class_destroy:
  7535. + class_destroy(vc_mem_class);
  7536. + vc_mem_class = NULL;
  7537. +
  7538. + out_cdev_del:
  7539. + cdev_del(&vc_mem_cdev);
  7540. +
  7541. + out_unregister:
  7542. + unregister_chrdev_region(vc_mem_devnum, 1);
  7543. +
  7544. + out_err:
  7545. + return -1;
  7546. +}
  7547. +
  7548. +/****************************************************************************
  7549. +*
  7550. +* vc_mem_exit
  7551. +*
  7552. +***************************************************************************/
  7553. +
  7554. +static void __exit
  7555. +vc_mem_exit(void)
  7556. +{
  7557. + pr_debug("%s: called\n", __func__);
  7558. +
  7559. + if (vc_mem_inited) {
  7560. +#if CONFIG_DEBUG_FS
  7561. + vc_mem_debugfs_deinit();
  7562. +#endif
  7563. + device_destroy(vc_mem_class, vc_mem_devnum);
  7564. + class_destroy(vc_mem_class);
  7565. + cdev_del(&vc_mem_cdev);
  7566. + unregister_chrdev_region(vc_mem_devnum, 1);
  7567. + }
  7568. +}
  7569. +
  7570. +module_init(vc_mem_init);
  7571. +module_exit(vc_mem_exit);
  7572. +MODULE_LICENSE("GPL");
  7573. +MODULE_AUTHOR("Broadcom Corporation");
  7574. +
  7575. +module_param(phys_addr, uint, 0644);
  7576. +module_param(mem_size, uint, 0644);
  7577. +module_param(mem_base, uint, 0644);
  7578. +
  7579. diff -Nur linux-3.12.18/arch/arm/Makefile linux-rpi/arch/arm/Makefile
  7580. --- linux-3.12.18/arch/arm/Makefile 2014-04-18 11:14:28.000000000 +0200
  7581. +++ linux-rpi/arch/arm/Makefile 2014-04-24 16:04:29.515024597 +0200
  7582. @@ -146,6 +146,7 @@
  7583. # by CONFIG_* macro name.
  7584. machine-$(CONFIG_ARCH_AT91) += at91
  7585. machine-$(CONFIG_ARCH_BCM) += bcm
  7586. +machine-$(CONFIG_ARCH_BCM2708) += bcm2708
  7587. machine-$(CONFIG_ARCH_BCM2835) += bcm2835
  7588. machine-$(CONFIG_ARCH_CLPS711X) += clps711x
  7589. machine-$(CONFIG_ARCH_CNS3XXX) += cns3xxx
  7590. diff -Nur linux-3.12.18/arch/arm/mm/Kconfig linux-rpi/arch/arm/mm/Kconfig
  7591. --- linux-3.12.18/arch/arm/mm/Kconfig 2014-04-18 11:14:28.000000000 +0200
  7592. +++ linux-rpi/arch/arm/mm/Kconfig 2014-04-24 16:04:31.615044915 +0200
  7593. @@ -358,7 +358,7 @@
  7594. # ARMv6
  7595. config CPU_V6
  7596. - bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX
  7597. + bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX || MACH_BCM2708
  7598. select CPU_32v6
  7599. select CPU_ABRT_EV6
  7600. select CPU_CACHE_V6
  7601. diff -Nur linux-3.12.18/arch/arm/mm/proc-v6.S linux-rpi/arch/arm/mm/proc-v6.S
  7602. --- linux-3.12.18/arch/arm/mm/proc-v6.S 2014-04-18 11:14:28.000000000 +0200
  7603. +++ linux-rpi/arch/arm/mm/proc-v6.S 2014-04-24 16:04:31.627045031 +0200
  7604. @@ -73,10 +73,19 @@
  7605. *
  7606. * IRQs are already disabled.
  7607. */
  7608. +
  7609. +/* See jira SW-5991 for details of this workaround */
  7610. ENTRY(cpu_v6_do_idle)
  7611. - mov r1, #0
  7612. - mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  7613. - mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  7614. + .align 5
  7615. + mov r1, #2
  7616. +1: subs r1, #1
  7617. + nop
  7618. + mcreq p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  7619. + mcreq p15, 0, r1, c7, c0, 4 @ wait for interrupt
  7620. + nop
  7621. + nop
  7622. + nop
  7623. + bne 1b
  7624. mov pc, lr
  7625. ENTRY(cpu_v6_dcache_clean_area)
  7626. diff -Nur linux-3.12.18/arch/arm/tools/mach-types linux-rpi/arch/arm/tools/mach-types
  7627. --- linux-3.12.18/arch/arm/tools/mach-types 2014-04-18 11:14:28.000000000 +0200
  7628. +++ linux-rpi/arch/arm/tools/mach-types 2014-04-24 15:35:00.985530254 +0200
  7629. @@ -522,6 +522,7 @@
  7630. prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
  7631. paz00 MACH_PAZ00 PAZ00 3128
  7632. acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
  7633. +bcm2708 MACH_BCM2708 BCM2708 3138
  7634. ag5evm MACH_AG5EVM AG5EVM 3189
  7635. ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
  7636. wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
  7637. diff -Nur linux-3.12.18/arch/m68k/Kconfig linux-rpi/arch/m68k/Kconfig
  7638. --- linux-3.12.18/arch/m68k/Kconfig 2014-04-18 11:14:28.000000000 +0200
  7639. +++ linux-rpi/arch/m68k/Kconfig 2014-04-24 16:04:32.771056098 +0200
  7640. @@ -16,7 +16,6 @@
  7641. select FPU if MMU
  7642. select ARCH_WANT_IPC_PARSE_VERSION
  7643. select ARCH_USES_GETTIMEOFFSET if MMU && !COLDFIRE
  7644. - select HAVE_FUTEX_CMPXCHG if MMU && FUTEX
  7645. select HAVE_MOD_ARCH_SPECIFIC
  7646. select MODULES_USE_ELF_REL
  7647. select MODULES_USE_ELF_RELA
  7648. diff -Nur linux-3.12.18/arch/s390/Kconfig linux-rpi/arch/s390/Kconfig
  7649. --- linux-3.12.18/arch/s390/Kconfig 2014-04-18 11:14:28.000000000 +0200
  7650. +++ linux-rpi/arch/s390/Kconfig 2014-04-24 16:04:33.891066931 +0200
  7651. @@ -116,7 +116,6 @@
  7652. select HAVE_FUNCTION_GRAPH_TRACER
  7653. select HAVE_FUNCTION_TRACER
  7654. select HAVE_FUNCTION_TRACE_MCOUNT_TEST
  7655. - select HAVE_FUTEX_CMPXCHG if FUTEX
  7656. select HAVE_KERNEL_BZIP2
  7657. select HAVE_KERNEL_GZIP
  7658. select HAVE_KERNEL_LZ4
  7659. diff -Nur linux-3.12.18/arch/x86/crypto/ghash-clmulni-intel_asm.S linux-rpi/arch/x86/crypto/ghash-clmulni-intel_asm.S
  7660. --- linux-3.12.18/arch/x86/crypto/ghash-clmulni-intel_asm.S 2014-04-18 11:14:28.000000000 +0200
  7661. +++ linux-rpi/arch/x86/crypto/ghash-clmulni-intel_asm.S 2014-04-24 16:04:34.051068479 +0200
  7662. @@ -24,6 +24,10 @@
  7663. .align 16
  7664. .Lbswap_mask:
  7665. .octa 0x000102030405060708090a0b0c0d0e0f
  7666. +.Lpoly:
  7667. + .octa 0xc2000000000000000000000000000001
  7668. +.Ltwo_one:
  7669. + .octa 0x00000001000000000000000000000001
  7670. #define DATA %xmm0
  7671. #define SHASH %xmm1
  7672. @@ -130,3 +134,28 @@
  7673. .Lupdate_just_ret:
  7674. ret
  7675. ENDPROC(clmul_ghash_update)
  7676. +
  7677. +/*
  7678. + * void clmul_ghash_setkey(be128 *shash, const u8 *key);
  7679. + *
  7680. + * Calculate hash_key << 1 mod poly
  7681. + */
  7682. +ENTRY(clmul_ghash_setkey)
  7683. + movaps .Lbswap_mask, BSWAP
  7684. + movups (%rsi), %xmm0
  7685. + PSHUFB_XMM BSWAP %xmm0
  7686. + movaps %xmm0, %xmm1
  7687. + psllq $1, %xmm0
  7688. + psrlq $63, %xmm1
  7689. + movaps %xmm1, %xmm2
  7690. + pslldq $8, %xmm1
  7691. + psrldq $8, %xmm2
  7692. + por %xmm1, %xmm0
  7693. + # reduction
  7694. + pshufd $0b00100100, %xmm2, %xmm1
  7695. + pcmpeqd .Ltwo_one, %xmm1
  7696. + pand .Lpoly, %xmm1
  7697. + pxor %xmm1, %xmm0
  7698. + movups %xmm0, (%rdi)
  7699. + ret
  7700. +ENDPROC(clmul_ghash_setkey)
  7701. diff -Nur linux-3.12.18/arch/x86/crypto/ghash-clmulni-intel_glue.c linux-rpi/arch/x86/crypto/ghash-clmulni-intel_glue.c
  7702. --- linux-3.12.18/arch/x86/crypto/ghash-clmulni-intel_glue.c 2014-04-18 11:14:28.000000000 +0200
  7703. +++ linux-rpi/arch/x86/crypto/ghash-clmulni-intel_glue.c 2014-04-24 16:04:34.051068479 +0200
  7704. @@ -30,6 +30,8 @@
  7705. void clmul_ghash_update(char *dst, const char *src, unsigned int srclen,
  7706. const be128 *shash);
  7707. +void clmul_ghash_setkey(be128 *shash, const u8 *key);
  7708. +
  7709. struct ghash_async_ctx {
  7710. struct cryptd_ahash *cryptd_tfm;
  7711. };
  7712. @@ -56,23 +58,13 @@
  7713. const u8 *key, unsigned int keylen)
  7714. {
  7715. struct ghash_ctx *ctx = crypto_shash_ctx(tfm);
  7716. - be128 *x = (be128 *)key;
  7717. - u64 a, b;
  7718. if (keylen != GHASH_BLOCK_SIZE) {
  7719. crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
  7720. return -EINVAL;
  7721. }
  7722. - /* perform multiplication by 'x' in GF(2^128) */
  7723. - a = be64_to_cpu(x->a);
  7724. - b = be64_to_cpu(x->b);
  7725. -
  7726. - ctx->shash.a = (__be64)((b << 1) | (a >> 63));
  7727. - ctx->shash.b = (__be64)((a << 1) | (b >> 63));
  7728. -
  7729. - if (a >> 63)
  7730. - ctx->shash.b ^= cpu_to_be64(0xc2);
  7731. + clmul_ghash_setkey(&ctx->shash, key);
  7732. return 0;
  7733. }
  7734. diff -Nur linux-3.12.18/Documentation/devicetree/bindings/net/micrel-ks8851.txt linux-rpi/Documentation/devicetree/bindings/net/micrel-ks8851.txt
  7735. --- linux-3.12.18/Documentation/devicetree/bindings/net/micrel-ks8851.txt 2014-04-18 11:14:28.000000000 +0200
  7736. +++ linux-rpi/Documentation/devicetree/bindings/net/micrel-ks8851.txt 2014-04-24 16:04:28.323013063 +0200
  7737. @@ -7,4 +7,3 @@
  7738. Optional properties:
  7739. - local-mac-address : Ethernet mac address to use
  7740. -- vdd-supply: supply for Ethernet mac
  7741. diff -Nur linux-3.12.18/Documentation/video4linux/bcm2835-v4l2.txt linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt
  7742. --- linux-3.12.18/Documentation/video4linux/bcm2835-v4l2.txt 1970-01-01 01:00:00.000000000 +0100
  7743. +++ linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt 2014-04-24 15:35:00.565525573 +0200
  7744. @@ -0,0 +1,60 @@
  7745. +
  7746. +BCM2835 (aka Raspberry Pi) V4L2 driver
  7747. +======================================
  7748. +
  7749. +1. Copyright
  7750. +============
  7751. +
  7752. +Copyright © 2013 Raspberry Pi (Trading) Ltd.
  7753. +
  7754. +2. License
  7755. +==========
  7756. +
  7757. +This program is free software; you can redistribute it and/or modify
  7758. +it under the terms of the GNU General Public License as published by
  7759. +the Free Software Foundation; either version 2 of the License, or
  7760. +(at your option) any later version.
  7761. +
  7762. +This program is distributed in the hope that it will be useful,
  7763. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  7764. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7765. +GNU General Public License for more details.
  7766. +
  7767. +You should have received a copy of the GNU General Public License
  7768. +along with this program; if not, write to the Free Software
  7769. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  7770. +
  7771. +3. Quick Start
  7772. +==============
  7773. +
  7774. +You need a version 1.0 or later of v4l2-ctl, available from:
  7775. + git://git.linuxtv.org/v4l-utils.git
  7776. +
  7777. +$ sudo modprobe bcm2835-v4l2
  7778. +
  7779. +Turn on the overlay:
  7780. +
  7781. +$ v4l2-ctl --overlay=1
  7782. +
  7783. +Turn off the overlay:
  7784. +
  7785. +$ v4l2-ctl --overlay=0
  7786. +
  7787. +Set the capture format for video:
  7788. +
  7789. +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
  7790. +
  7791. +(Note: 1088 not 1080).
  7792. +
  7793. +Capture:
  7794. +
  7795. +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
  7796. +
  7797. +Stills capture:
  7798. +
  7799. +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
  7800. +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
  7801. +
  7802. +List of available formats:
  7803. +
  7804. +$ v4l2-ctl --list-formats
  7805. diff -Nur linux-3.12.18/drivers/block/floppy.c linux-rpi/drivers/block/floppy.c
  7806. --- linux-3.12.18/drivers/block/floppy.c 2014-04-18 11:14:28.000000000 +0200
  7807. +++ linux-rpi/drivers/block/floppy.c 2014-04-24 15:35:02.077542424 +0200
  7808. @@ -3691,12 +3691,9 @@
  7809. if (!(mode & FMODE_NDELAY)) {
  7810. if (mode & (FMODE_READ|FMODE_WRITE)) {
  7811. UDRS->last_checked = 0;
  7812. - clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
  7813. check_disk_change(bdev);
  7814. if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags))
  7815. goto out;
  7816. - if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags))
  7817. - goto out;
  7818. }
  7819. res = -EROFS;
  7820. if ((mode & FMODE_WRITE) &&
  7821. @@ -3749,29 +3746,17 @@
  7822. * a disk in the drive, and whether that disk is writable.
  7823. */
  7824. -struct rb0_cbdata {
  7825. - int drive;
  7826. - struct completion complete;
  7827. -};
  7828. -
  7829. -static void floppy_rb0_cb(struct bio *bio, int err)
  7830. +static void floppy_rb0_complete(struct bio *bio, int err)
  7831. {
  7832. - struct rb0_cbdata *cbdata = (struct rb0_cbdata *)bio->bi_private;
  7833. - int drive = cbdata->drive;
  7834. -
  7835. - if (err) {
  7836. - pr_info("floppy: error %d while reading block 0", err);
  7837. - set_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
  7838. - }
  7839. - complete(&cbdata->complete);
  7840. + complete((struct completion *)bio->bi_private);
  7841. }
  7842. -static int __floppy_read_block_0(struct block_device *bdev, int drive)
  7843. +static int __floppy_read_block_0(struct block_device *bdev)
  7844. {
  7845. struct bio bio;
  7846. struct bio_vec bio_vec;
  7847. + struct completion complete;
  7848. struct page *page;
  7849. - struct rb0_cbdata cbdata;
  7850. size_t size;
  7851. page = alloc_page(GFP_NOIO);
  7852. @@ -3784,8 +3769,6 @@
  7853. if (!size)
  7854. size = 1024;
  7855. - cbdata.drive = drive;
  7856. -
  7857. bio_init(&bio);
  7858. bio.bi_io_vec = &bio_vec;
  7859. bio_vec.bv_page = page;
  7860. @@ -3796,14 +3779,13 @@
  7861. bio.bi_bdev = bdev;
  7862. bio.bi_sector = 0;
  7863. bio.bi_flags = (1 << BIO_QUIET);
  7864. - bio.bi_private = &cbdata;
  7865. - bio.bi_end_io = floppy_rb0_cb;
  7866. + init_completion(&complete);
  7867. + bio.bi_private = &complete;
  7868. + bio.bi_end_io = floppy_rb0_complete;
  7869. submit_bio(READ, &bio);
  7870. process_fd_request();
  7871. -
  7872. - init_completion(&cbdata.complete);
  7873. - wait_for_completion(&cbdata.complete);
  7874. + wait_for_completion(&complete);
  7875. __free_page(page);
  7876. @@ -3845,7 +3827,7 @@
  7877. UDRS->generation++;
  7878. if (drive_no_geom(drive)) {
  7879. /* auto-sensing */
  7880. - res = __floppy_read_block_0(opened_bdev[drive], drive);
  7881. + res = __floppy_read_block_0(opened_bdev[drive]);
  7882. } else {
  7883. if (cf)
  7884. poll_drive(false, FD_RAW_NEED_DISK);
  7885. diff -Nur linux-3.12.18/drivers/char/broadcom/Kconfig linux-rpi/drivers/char/broadcom/Kconfig
  7886. --- linux-3.12.18/drivers/char/broadcom/Kconfig 1970-01-01 01:00:00.000000000 +0100
  7887. +++ linux-rpi/drivers/char/broadcom/Kconfig 2014-04-24 16:04:34.339071265 +0200
  7888. @@ -0,0 +1,16 @@
  7889. +#
  7890. +# Broadcom char driver config
  7891. +#
  7892. +
  7893. +menuconfig BRCM_CHAR_DRIVERS
  7894. + bool "Broadcom Char Drivers"
  7895. + help
  7896. + Broadcom's char drivers
  7897. +
  7898. +config BCM_VC_CMA
  7899. + bool "Videocore CMA"
  7900. + depends on CMA && BRCM_CHAR_DRIVERS && BCM2708_VCHIQ
  7901. + default n
  7902. + help
  7903. + Helper for videocore CMA access.
  7904. +
  7905. diff -Nur linux-3.12.18/drivers/char/broadcom/Makefile linux-rpi/drivers/char/broadcom/Makefile
  7906. --- linux-3.12.18/drivers/char/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
  7907. +++ linux-rpi/drivers/char/broadcom/Makefile 2014-04-24 16:04:34.339071265 +0200
  7908. @@ -0,0 +1 @@
  7909. +obj-$(CONFIG_BCM_VC_CMA) += vc_cma/
  7910. diff -Nur linux-3.12.18/drivers/char/broadcom/vc_cma/Makefile linux-rpi/drivers/char/broadcom/vc_cma/Makefile
  7911. --- linux-3.12.18/drivers/char/broadcom/vc_cma/Makefile 1970-01-01 01:00:00.000000000 +0100
  7912. +++ linux-rpi/drivers/char/broadcom/vc_cma/Makefile 2014-04-24 16:04:34.339071265 +0200
  7913. @@ -0,0 +1,14 @@
  7914. +ccflags-y += -Wall -Wstrict-prototypes -Wno-trigraphs
  7915. +ccflags-y += -Werror
  7916. +ccflags-y += -Iinclude/linux/broadcom
  7917. +ccflags-y += -Idrivers/misc/vc04_services
  7918. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchi
  7919. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchiq_arm
  7920. +
  7921. +ccflags-y += -D__KERNEL__
  7922. +ccflags-y += -D__linux__
  7923. +ccflags-y += -Werror
  7924. +
  7925. +obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
  7926. +
  7927. +vc-cma-objs := vc_cma.o
  7928. diff -Nur linux-3.12.18/drivers/char/broadcom/vc_cma/vc_cma.c linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c
  7929. --- linux-3.12.18/drivers/char/broadcom/vc_cma/vc_cma.c 1970-01-01 01:00:00.000000000 +0100
  7930. +++ linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c 2014-04-24 16:04:34.339071265 +0200
  7931. @@ -0,0 +1,1143 @@
  7932. +/**
  7933. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  7934. + *
  7935. + * Redistribution and use in source and binary forms, with or without
  7936. + * modification, are permitted provided that the following conditions
  7937. + * are met:
  7938. + * 1. Redistributions of source code must retain the above copyright
  7939. + * notice, this list of conditions, and the following disclaimer,
  7940. + * without modification.
  7941. + * 2. Redistributions in binary form must reproduce the above copyright
  7942. + * notice, this list of conditions and the following disclaimer in the
  7943. + * documentation and/or other materials provided with the distribution.
  7944. + * 3. The names of the above-listed copyright holders may not be used
  7945. + * to endorse or promote products derived from this software without
  7946. + * specific prior written permission.
  7947. + *
  7948. + * ALTERNATIVELY, this software may be distributed under the terms of the
  7949. + * GNU General Public License ("GPL") version 2, as published by the Free
  7950. + * Software Foundation.
  7951. + *
  7952. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  7953. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  7954. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  7955. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  7956. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  7957. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  7958. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  7959. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7960. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7961. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  7962. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7963. + */
  7964. +
  7965. +#include <linux/kernel.h>
  7966. +#include <linux/module.h>
  7967. +#include <linux/kthread.h>
  7968. +#include <linux/fs.h>
  7969. +#include <linux/device.h>
  7970. +#include <linux/cdev.h>
  7971. +#include <linux/mm.h>
  7972. +#include <linux/proc_fs.h>
  7973. +#include <linux/seq_file.h>
  7974. +#include <linux/dma-mapping.h>
  7975. +#include <linux/dma-contiguous.h>
  7976. +#include <linux/platform_device.h>
  7977. +#include <linux/uaccess.h>
  7978. +#include <asm/cacheflush.h>
  7979. +
  7980. +#include "vc_cma.h"
  7981. +
  7982. +#include "vchiq_util.h"
  7983. +#include "vchiq_connected.h"
  7984. +//#include "debug_sym.h"
  7985. +//#include "vc_mem.h"
  7986. +
  7987. +#define DRIVER_NAME "vc-cma"
  7988. +
  7989. +#define LOG_DBG(fmt, ...) \
  7990. + if (vc_cma_debug) \
  7991. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  7992. +#define LOG_ERR(fmt, ...) \
  7993. + printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
  7994. +
  7995. +#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
  7996. +#define VC_CMA_VERSION 2
  7997. +
  7998. +#define VC_CMA_CHUNK_ORDER 6 /* 256K */
  7999. +#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
  8000. +#define VC_CMA_MAX_PARAMS_PER_MSG \
  8001. + ((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
  8002. +#define VC_CMA_RESERVE_COUNT_MAX 16
  8003. +
  8004. +#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
  8005. +
  8006. +#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
  8007. +
  8008. +#define loud_error(...) \
  8009. + LOG_ERR("===== " __VA_ARGS__)
  8010. +
  8011. +enum {
  8012. + VC_CMA_MSG_QUIT,
  8013. + VC_CMA_MSG_OPEN,
  8014. + VC_CMA_MSG_TICK,
  8015. + VC_CMA_MSG_ALLOC, /* chunk count */
  8016. + VC_CMA_MSG_FREE, /* chunk, chunk, ... */
  8017. + VC_CMA_MSG_ALLOCATED, /* chunk, chunk, ... */
  8018. + VC_CMA_MSG_REQUEST_ALLOC, /* chunk count */
  8019. + VC_CMA_MSG_REQUEST_FREE, /* chunk count */
  8020. + VC_CMA_MSG_RESERVE, /* bytes lo, bytes hi */
  8021. + VC_CMA_MSG_UPDATE_RESERVE,
  8022. + VC_CMA_MSG_MAX
  8023. +};
  8024. +
  8025. +struct cma_msg {
  8026. + unsigned short type;
  8027. + unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
  8028. +};
  8029. +
  8030. +struct vc_cma_reserve_user {
  8031. + unsigned int pid;
  8032. + unsigned int reserve;
  8033. +};
  8034. +
  8035. +/* Device (/dev) related variables */
  8036. +static dev_t vc_cma_devnum;
  8037. +static struct class *vc_cma_class;
  8038. +static struct cdev vc_cma_cdev;
  8039. +static int vc_cma_inited;
  8040. +static int vc_cma_debug;
  8041. +
  8042. +/* Proc entry */
  8043. +static struct proc_dir_entry *vc_cma_proc_entry;
  8044. +
  8045. +phys_addr_t vc_cma_base;
  8046. +struct page *vc_cma_base_page;
  8047. +unsigned int vc_cma_size;
  8048. +EXPORT_SYMBOL(vc_cma_size);
  8049. +unsigned int vc_cma_initial;
  8050. +unsigned int vc_cma_chunks;
  8051. +unsigned int vc_cma_chunks_used;
  8052. +unsigned int vc_cma_chunks_reserved;
  8053. +
  8054. +static int in_loud_error;
  8055. +
  8056. +unsigned int vc_cma_reserve_total;
  8057. +unsigned int vc_cma_reserve_count;
  8058. +struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
  8059. +static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
  8060. +static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
  8061. +
  8062. +static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
  8063. +static struct platform_device vc_cma_device = {
  8064. + .name = "vc-cma",
  8065. + .id = 0,
  8066. + .dev = {
  8067. + .dma_mask = &vc_cma_dma_mask,
  8068. + .coherent_dma_mask = DMA_BIT_MASK(32),
  8069. + },
  8070. +};
  8071. +
  8072. +static VCHIQ_INSTANCE_T cma_instance;
  8073. +static VCHIQ_SERVICE_HANDLE_T cma_service;
  8074. +static VCHIU_QUEUE_T cma_msg_queue;
  8075. +static struct task_struct *cma_worker;
  8076. +
  8077. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
  8078. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
  8079. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  8080. + VCHIQ_HEADER_T * header,
  8081. + VCHIQ_SERVICE_HANDLE_T service,
  8082. + void *bulk_userdata);
  8083. +static void send_vc_msg(unsigned short type,
  8084. + unsigned short param1, unsigned short param2);
  8085. +static bool send_worker_msg(VCHIQ_HEADER_T * msg);
  8086. +
  8087. +static int early_vc_cma_mem(char *p)
  8088. +{
  8089. + unsigned int new_size;
  8090. + printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
  8091. + vc_cma_size = memparse(p, &p);
  8092. + vc_cma_initial = vc_cma_size;
  8093. + if (*p == '/')
  8094. + vc_cma_size = memparse(p + 1, &p);
  8095. + if (*p == '@')
  8096. + vc_cma_base = memparse(p + 1, &p);
  8097. +
  8098. + new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
  8099. + & ~(VC_CMA_CHUNK_SIZE - 1);
  8100. + if (new_size > vc_cma_size)
  8101. + vc_cma_size = 0;
  8102. + vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
  8103. + & ~(VC_CMA_CHUNK_SIZE - 1);
  8104. + if (vc_cma_initial > vc_cma_size)
  8105. + vc_cma_initial = vc_cma_size;
  8106. + vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
  8107. + & ~(VC_CMA_CHUNK_SIZE - 1);
  8108. +
  8109. + printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
  8110. + vc_cma_size, (unsigned int)vc_cma_base);
  8111. +
  8112. + return 0;
  8113. +}
  8114. +
  8115. +early_param("vc-cma-mem", early_vc_cma_mem);
  8116. +
  8117. +void vc_cma_early_init(void)
  8118. +{
  8119. + LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
  8120. + if (vc_cma_size) {
  8121. + int rc = platform_device_register(&vc_cma_device);
  8122. + LOG_DBG("platform_device_register -> %d", rc);
  8123. + }
  8124. +}
  8125. +
  8126. +void vc_cma_reserve(void)
  8127. +{
  8128. + /* if vc_cma_size is set, then declare vc CMA area of the same
  8129. + * size from the end of memory
  8130. + */
  8131. + if (vc_cma_size) {
  8132. + if (dma_declare_contiguous(NULL /*&vc_cma_device.dev*/, vc_cma_size,
  8133. + vc_cma_base, 0) == 0) {
  8134. + } else {
  8135. + LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
  8136. + vc_cma_size, (unsigned int)vc_cma_base);
  8137. + vc_cma_size = 0;
  8138. + }
  8139. + }
  8140. + vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
  8141. +}
  8142. +
  8143. +/****************************************************************************
  8144. +*
  8145. +* vc_cma_open
  8146. +*
  8147. +***************************************************************************/
  8148. +
  8149. +static int vc_cma_open(struct inode *inode, struct file *file)
  8150. +{
  8151. + (void)inode;
  8152. + (void)file;
  8153. +
  8154. + return 0;
  8155. +}
  8156. +
  8157. +/****************************************************************************
  8158. +*
  8159. +* vc_cma_release
  8160. +*
  8161. +***************************************************************************/
  8162. +
  8163. +static int vc_cma_release(struct inode *inode, struct file *file)
  8164. +{
  8165. + (void)inode;
  8166. + (void)file;
  8167. +
  8168. + vc_cma_set_reserve(0, current->tgid);
  8169. +
  8170. + return 0;
  8171. +}
  8172. +
  8173. +/****************************************************************************
  8174. +*
  8175. +* vc_cma_ioctl
  8176. +*
  8177. +***************************************************************************/
  8178. +
  8179. +static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  8180. +{
  8181. + int rc = 0;
  8182. +
  8183. + (void)cmd;
  8184. + (void)arg;
  8185. +
  8186. + switch (cmd) {
  8187. + case VC_CMA_IOC_RESERVE:
  8188. + rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
  8189. + if (rc >= 0)
  8190. + rc = 0;
  8191. + break;
  8192. + default:
  8193. + LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
  8194. + return -ENOTTY;
  8195. + }
  8196. +
  8197. + return rc;
  8198. +}
  8199. +
  8200. +/****************************************************************************
  8201. +*
  8202. +* File Operations for the driver.
  8203. +*
  8204. +***************************************************************************/
  8205. +
  8206. +static const struct file_operations vc_cma_fops = {
  8207. + .owner = THIS_MODULE,
  8208. + .open = vc_cma_open,
  8209. + .release = vc_cma_release,
  8210. + .unlocked_ioctl = vc_cma_ioctl,
  8211. +};
  8212. +
  8213. +/****************************************************************************
  8214. +*
  8215. +* vc_cma_proc_open
  8216. +*
  8217. +***************************************************************************/
  8218. +
  8219. +static int vc_cma_show_info(struct seq_file *m, void *v)
  8220. +{
  8221. + int i;
  8222. +
  8223. + seq_printf(m, "Videocore CMA:\n");
  8224. + seq_printf(m, " Base : %08x\n", (unsigned int)vc_cma_base);
  8225. + seq_printf(m, " Length : %08x\n", vc_cma_size);
  8226. + seq_printf(m, " Initial : %08x\n", vc_cma_initial);
  8227. + seq_printf(m, " Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
  8228. + seq_printf(m, " Chunks : %4d (%d bytes)\n",
  8229. + (int)vc_cma_chunks,
  8230. + (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
  8231. + seq_printf(m, " Used : %4d (%d bytes)\n",
  8232. + (int)vc_cma_chunks_used,
  8233. + (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
  8234. + seq_printf(m, " Reserved : %4d (%d bytes)\n",
  8235. + (unsigned int)vc_cma_chunks_reserved,
  8236. + (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
  8237. +
  8238. + for (i = 0; i < vc_cma_reserve_count; i++) {
  8239. + struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
  8240. + seq_printf(m, " PID %5d: %d bytes\n", user->pid,
  8241. + user->reserve);
  8242. + }
  8243. +
  8244. + seq_printf(m, "\n");
  8245. +
  8246. + return 0;
  8247. +}
  8248. +
  8249. +static int vc_cma_proc_open(struct inode *inode, struct file *file)
  8250. +{
  8251. + return single_open(file, vc_cma_show_info, NULL);
  8252. +}
  8253. +
  8254. +/****************************************************************************
  8255. +*
  8256. +* vc_cma_proc_write
  8257. +*
  8258. +***************************************************************************/
  8259. +
  8260. +static int vc_cma_proc_write(struct file *file,
  8261. + const char __user *buffer,
  8262. + size_t size, loff_t *ppos)
  8263. +{
  8264. + int rc = -EFAULT;
  8265. + char input_str[20];
  8266. +
  8267. + memset(input_str, 0, sizeof(input_str));
  8268. +
  8269. + if (size > sizeof(input_str)) {
  8270. + LOG_ERR("%s: input string length too long", __func__);
  8271. + goto out;
  8272. + }
  8273. +
  8274. + if (copy_from_user(input_str, buffer, size - 1)) {
  8275. + LOG_ERR("%s: failed to get input string", __func__);
  8276. + goto out;
  8277. + }
  8278. +#define ALLOC_STR "alloc"
  8279. +#define FREE_STR "free"
  8280. +#define DEBUG_STR "debug"
  8281. +#define RESERVE_STR "reserve"
  8282. + if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
  8283. + int size;
  8284. + char *p = input_str + strlen(ALLOC_STR);
  8285. +
  8286. + while (*p == ' ')
  8287. + p++;
  8288. + size = memparse(p, NULL);
  8289. + LOG_ERR("/proc/vc-cma: alloc %d", size);
  8290. + if (size)
  8291. + send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
  8292. + size / VC_CMA_CHUNK_SIZE, 0);
  8293. + else
  8294. + LOG_ERR("invalid size '%s'", p);
  8295. + rc = size;
  8296. + } else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
  8297. + int size;
  8298. + char *p = input_str + strlen(FREE_STR);
  8299. +
  8300. + while (*p == ' ')
  8301. + p++;
  8302. + size = memparse(p, NULL);
  8303. + LOG_ERR("/proc/vc-cma: free %d", size);
  8304. + if (size)
  8305. + send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
  8306. + size / VC_CMA_CHUNK_SIZE, 0);
  8307. + else
  8308. + LOG_ERR("invalid size '%s'", p);
  8309. + rc = size;
  8310. + } else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
  8311. + char *p = input_str + strlen(DEBUG_STR);
  8312. + while (*p == ' ')
  8313. + p++;
  8314. + if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
  8315. + vc_cma_debug = 1;
  8316. + else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
  8317. + vc_cma_debug = 0;
  8318. + LOG_ERR("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
  8319. + rc = size;
  8320. + } else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
  8321. + int size;
  8322. + int reserved;
  8323. + char *p = input_str + strlen(RESERVE_STR);
  8324. + while (*p == ' ')
  8325. + p++;
  8326. + size = memparse(p, NULL);
  8327. +
  8328. + reserved = vc_cma_set_reserve(size, current->tgid);
  8329. + rc = (reserved >= 0) ? size : reserved;
  8330. + }
  8331. +
  8332. +out:
  8333. + return rc;
  8334. +}
  8335. +
  8336. +/****************************************************************************
  8337. +*
  8338. +* File Operations for /proc interface.
  8339. +*
  8340. +***************************************************************************/
  8341. +
  8342. +static const struct file_operations vc_cma_proc_fops = {
  8343. + .open = vc_cma_proc_open,
  8344. + .read = seq_read,
  8345. + .write = vc_cma_proc_write,
  8346. + .llseek = seq_lseek,
  8347. + .release = single_release
  8348. +};
  8349. +
  8350. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
  8351. +{
  8352. + struct vc_cma_reserve_user *user = NULL;
  8353. + int delta = 0;
  8354. + int i;
  8355. +
  8356. + if (down_interruptible(&vc_cma_reserve_mutex))
  8357. + return -ERESTARTSYS;
  8358. +
  8359. + for (i = 0; i < vc_cma_reserve_count; i++) {
  8360. + if (pid == vc_cma_reserve_users[i].pid) {
  8361. + user = &vc_cma_reserve_users[i];
  8362. + delta = reserve - user->reserve;
  8363. + if (reserve)
  8364. + user->reserve = reserve;
  8365. + else {
  8366. + /* Remove this entry by copying downwards */
  8367. + while ((i + 1) < vc_cma_reserve_count) {
  8368. + user[0].pid = user[1].pid;
  8369. + user[0].reserve = user[1].reserve;
  8370. + user++;
  8371. + i++;
  8372. + }
  8373. + vc_cma_reserve_count--;
  8374. + user = NULL;
  8375. + }
  8376. + break;
  8377. + }
  8378. + }
  8379. +
  8380. + if (reserve && !user) {
  8381. + if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
  8382. + LOG_ERR("vc-cma: Too many reservations - "
  8383. + "increase CMA_RESERVE_COUNT_MAX");
  8384. + up(&vc_cma_reserve_mutex);
  8385. + return -EBUSY;
  8386. + }
  8387. + user = &vc_cma_reserve_users[vc_cma_reserve_count];
  8388. + user->pid = pid;
  8389. + user->reserve = reserve;
  8390. + delta = reserve;
  8391. + vc_cma_reserve_count++;
  8392. + }
  8393. +
  8394. + vc_cma_reserve_total += delta;
  8395. +
  8396. + send_vc_msg(VC_CMA_MSG_RESERVE,
  8397. + vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
  8398. +
  8399. + send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
  8400. +
  8401. + LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
  8402. + reserve, pid, vc_cma_reserve_total);
  8403. +
  8404. + up(&vc_cma_reserve_mutex);
  8405. +
  8406. + return vc_cma_reserve_total;
  8407. +}
  8408. +
  8409. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  8410. + VCHIQ_HEADER_T * header,
  8411. + VCHIQ_SERVICE_HANDLE_T service,
  8412. + void *bulk_userdata)
  8413. +{
  8414. + switch (reason) {
  8415. + case VCHIQ_MESSAGE_AVAILABLE:
  8416. + if (!send_worker_msg(header))
  8417. + return VCHIQ_RETRY;
  8418. + break;
  8419. + case VCHIQ_SERVICE_CLOSED:
  8420. + LOG_DBG("CMA service closed");
  8421. + break;
  8422. + default:
  8423. + LOG_ERR("Unexpected CMA callback reason %d", reason);
  8424. + break;
  8425. + }
  8426. + return VCHIQ_SUCCESS;
  8427. +}
  8428. +
  8429. +static void send_vc_msg(unsigned short type,
  8430. + unsigned short param1, unsigned short param2)
  8431. +{
  8432. + unsigned short msg[] = { type, param1, param2 };
  8433. + VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
  8434. + VCHIQ_STATUS_T ret;
  8435. + vchiq_use_service(cma_service);
  8436. + ret = vchiq_queue_message(cma_service, &elem, 1);
  8437. + vchiq_release_service(cma_service);
  8438. + if (ret != VCHIQ_SUCCESS)
  8439. + LOG_ERR("vchiq_queue_message returned %x", ret);
  8440. +}
  8441. +
  8442. +static bool send_worker_msg(VCHIQ_HEADER_T * msg)
  8443. +{
  8444. + if (down_interruptible(&vc_cma_worker_queue_push_mutex))
  8445. + return false;
  8446. + vchiu_queue_push(&cma_msg_queue, msg);
  8447. + up(&vc_cma_worker_queue_push_mutex);
  8448. + return true;
  8449. +}
  8450. +
  8451. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
  8452. +{
  8453. + int i;
  8454. + for (i = 0; i < num_chunks; i++) {
  8455. + struct page *chunk;
  8456. + unsigned int chunk_num;
  8457. + uint8_t *chunk_addr;
  8458. + size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
  8459. +
  8460. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  8461. + PAGES_PER_CHUNK,
  8462. + VC_CMA_CHUNK_ORDER);
  8463. + if (!chunk)
  8464. + break;
  8465. +
  8466. + chunk_addr = page_address(chunk);
  8467. + dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
  8468. + outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
  8469. + chunk_size);
  8470. +
  8471. + chunk_num =
  8472. + (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
  8473. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  8474. + VC_CMA_CHUNK_SIZE) != 0);
  8475. + if (chunk_num >= vc_cma_chunks) {
  8476. + LOG_ERR("%s: ===============================",
  8477. + __func__);
  8478. + LOG_ERR("%s: chunk phys %x, vc_cma %x-%x - "
  8479. + "bad SPARSEMEM configuration?",
  8480. + __func__, (unsigned int)page_to_phys(chunk),
  8481. + vc_cma_base, vc_cma_base + vc_cma_size - 1);
  8482. + LOG_ERR("%s: dev->cma_area = %p\n", __func__,
  8483. + (void*)0/*vc_cma_device.dev.cma_area*/);
  8484. + LOG_ERR("%s: ===============================",
  8485. + __func__);
  8486. + break;
  8487. + }
  8488. + reply->params[i] = chunk_num;
  8489. + vc_cma_chunks_used++;
  8490. + }
  8491. +
  8492. + if (i < num_chunks) {
  8493. + LOG_ERR("%s: dma_alloc_from_contiguous failed "
  8494. + "for %x bytes (alloc %d of %d, %d free)",
  8495. + __func__, VC_CMA_CHUNK_SIZE, i,
  8496. + num_chunks, vc_cma_chunks - vc_cma_chunks_used);
  8497. + num_chunks = i;
  8498. + }
  8499. +
  8500. + LOG_DBG("CMA allocated %d chunks -> %d used",
  8501. + num_chunks, vc_cma_chunks_used);
  8502. + reply->type = VC_CMA_MSG_ALLOCATED;
  8503. +
  8504. + {
  8505. + VCHIQ_ELEMENT_T elem = {
  8506. + reply,
  8507. + offsetof(struct cma_msg, params[0]) +
  8508. + num_chunks * sizeof(reply->params[0])
  8509. + };
  8510. + VCHIQ_STATUS_T ret;
  8511. + vchiq_use_service(cma_service);
  8512. + ret = vchiq_queue_message(cma_service, &elem, 1);
  8513. + vchiq_release_service(cma_service);
  8514. + if (ret != VCHIQ_SUCCESS)
  8515. + LOG_ERR("vchiq_queue_message return " "%x", ret);
  8516. + }
  8517. +
  8518. + return num_chunks;
  8519. +}
  8520. +
  8521. +static int cma_worker_proc(void *param)
  8522. +{
  8523. + static struct cma_msg reply;
  8524. + (void)param;
  8525. +
  8526. + while (1) {
  8527. + VCHIQ_HEADER_T *msg;
  8528. + static struct cma_msg msg_copy;
  8529. + struct cma_msg *cma_msg = &msg_copy;
  8530. + int type, msg_size;
  8531. +
  8532. + msg = vchiu_queue_pop(&cma_msg_queue);
  8533. + if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
  8534. + msg_size = msg->size;
  8535. + memcpy(&msg_copy, msg->data, msg_size);
  8536. + type = cma_msg->type;
  8537. + vchiq_release_message(cma_service, msg);
  8538. + } else {
  8539. + msg_size = 0;
  8540. + type = (int)msg;
  8541. + if (type == VC_CMA_MSG_QUIT)
  8542. + break;
  8543. + else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
  8544. + msg = NULL;
  8545. + cma_msg = NULL;
  8546. + } else {
  8547. + BUG();
  8548. + continue;
  8549. + }
  8550. + }
  8551. +
  8552. + switch (type) {
  8553. + case VC_CMA_MSG_ALLOC:{
  8554. + int num_chunks, free_chunks;
  8555. + num_chunks = cma_msg->params[0];
  8556. + free_chunks =
  8557. + vc_cma_chunks - vc_cma_chunks_used;
  8558. + LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
  8559. + if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
  8560. + LOG_ERR
  8561. + ("CMA_MSG_ALLOC - chunk count (%d) "
  8562. + "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
  8563. + num_chunks,
  8564. + VC_CMA_MAX_PARAMS_PER_MSG);
  8565. + num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
  8566. + }
  8567. +
  8568. + if (num_chunks > free_chunks) {
  8569. + LOG_ERR
  8570. + ("CMA_MSG_ALLOC - chunk count (%d) "
  8571. + "exceeds free chunks (%d)",
  8572. + num_chunks, free_chunks);
  8573. + num_chunks = free_chunks;
  8574. + }
  8575. +
  8576. + vc_cma_alloc_chunks(num_chunks, &reply);
  8577. + }
  8578. + break;
  8579. +
  8580. + case VC_CMA_MSG_FREE:{
  8581. + int chunk_count =
  8582. + (msg_size -
  8583. + offsetof(struct cma_msg,
  8584. + params)) /
  8585. + sizeof(cma_msg->params[0]);
  8586. + int i;
  8587. + BUG_ON(chunk_count <= 0);
  8588. +
  8589. + LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
  8590. + chunk_count, cma_msg->params[0]);
  8591. + for (i = 0; i < chunk_count; i++) {
  8592. + int chunk_num = cma_msg->params[i];
  8593. + struct page *page = vc_cma_base_page +
  8594. + chunk_num * PAGES_PER_CHUNK;
  8595. + if (chunk_num >= vc_cma_chunks) {
  8596. + LOG_ERR
  8597. + ("CMA_MSG_FREE - chunk %d of %d"
  8598. + " (value %x) exceeds maximum "
  8599. + "(%x)", i, chunk_count,
  8600. + chunk_num,
  8601. + vc_cma_chunks - 1);
  8602. + break;
  8603. + }
  8604. +
  8605. + if (!dma_release_from_contiguous
  8606. + (NULL /*&vc_cma_device.dev*/, page,
  8607. + PAGES_PER_CHUNK)) {
  8608. + LOG_ERR
  8609. + ("CMA_MSG_FREE - failed to "
  8610. + "release chunk %d (phys %x, "
  8611. + "page %x)", chunk_num,
  8612. + page_to_phys(page),
  8613. + (unsigned int)page);
  8614. + }
  8615. + vc_cma_chunks_used--;
  8616. + }
  8617. + LOG_DBG("CMA released %d chunks -> %d used",
  8618. + i, vc_cma_chunks_used);
  8619. + }
  8620. + break;
  8621. +
  8622. + case VC_CMA_MSG_UPDATE_RESERVE:{
  8623. + int chunks_needed =
  8624. + ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
  8625. + 1)
  8626. + / VC_CMA_CHUNK_SIZE) -
  8627. + vc_cma_chunks_reserved;
  8628. +
  8629. + LOG_DBG
  8630. + ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
  8631. + chunks_needed);
  8632. +
  8633. + /* Cap the reservations to what is available */
  8634. + if (chunks_needed > 0) {
  8635. + if (chunks_needed >
  8636. + (vc_cma_chunks -
  8637. + vc_cma_chunks_used))
  8638. + chunks_needed =
  8639. + (vc_cma_chunks -
  8640. + vc_cma_chunks_used);
  8641. +
  8642. + chunks_needed =
  8643. + vc_cma_alloc_chunks(chunks_needed,
  8644. + &reply);
  8645. + }
  8646. +
  8647. + LOG_DBG
  8648. + ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
  8649. + chunks_needed);
  8650. + vc_cma_chunks_reserved += chunks_needed;
  8651. + }
  8652. + break;
  8653. +
  8654. + default:
  8655. + LOG_ERR("unexpected msg type %d", type);
  8656. + break;
  8657. + }
  8658. + }
  8659. +
  8660. + LOG_DBG("quitting...");
  8661. + return 0;
  8662. +}
  8663. +
  8664. +/****************************************************************************
  8665. +*
  8666. +* vc_cma_connected_init
  8667. +*
  8668. +* This function is called once the videocore has been connected.
  8669. +*
  8670. +***************************************************************************/
  8671. +
  8672. +static void vc_cma_connected_init(void)
  8673. +{
  8674. + VCHIQ_SERVICE_PARAMS_T service_params;
  8675. +
  8676. + LOG_DBG("vc_cma_connected_init");
  8677. +
  8678. + if (!vchiu_queue_init(&cma_msg_queue, 16)) {
  8679. + LOG_ERR("could not create CMA msg queue");
  8680. + goto fail_queue;
  8681. + }
  8682. +
  8683. + if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
  8684. + goto fail_vchiq_init;
  8685. +
  8686. + vchiq_connect(cma_instance);
  8687. +
  8688. + service_params.fourcc = VC_CMA_FOURCC;
  8689. + service_params.callback = cma_service_callback;
  8690. + service_params.userdata = NULL;
  8691. + service_params.version = VC_CMA_VERSION;
  8692. + service_params.version_min = VC_CMA_VERSION;
  8693. +
  8694. + if (vchiq_open_service(cma_instance, &service_params,
  8695. + &cma_service) != VCHIQ_SUCCESS) {
  8696. + LOG_ERR("failed to open service - already in use?");
  8697. + goto fail_vchiq_open;
  8698. + }
  8699. +
  8700. + vchiq_release_service(cma_service);
  8701. +
  8702. + cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
  8703. + if (!cma_worker) {
  8704. + LOG_ERR("could not create CMA worker thread");
  8705. + goto fail_worker;
  8706. + }
  8707. + set_user_nice(cma_worker, -20);
  8708. + wake_up_process(cma_worker);
  8709. +
  8710. + return;
  8711. +
  8712. +fail_worker:
  8713. + vchiq_close_service(cma_service);
  8714. +fail_vchiq_open:
  8715. + vchiq_shutdown(cma_instance);
  8716. +fail_vchiq_init:
  8717. + vchiu_queue_delete(&cma_msg_queue);
  8718. +fail_queue:
  8719. + return;
  8720. +}
  8721. +
  8722. +void
  8723. +loud_error_header(void)
  8724. +{
  8725. + if (in_loud_error)
  8726. + return;
  8727. +
  8728. + LOG_ERR("============================================================"
  8729. + "================");
  8730. + LOG_ERR("============================================================"
  8731. + "================");
  8732. + LOG_ERR("=====");
  8733. +
  8734. + in_loud_error = 1;
  8735. +}
  8736. +
  8737. +void
  8738. +loud_error_footer(void)
  8739. +{
  8740. + if (!in_loud_error)
  8741. + return;
  8742. +
  8743. + LOG_ERR("=====");
  8744. + LOG_ERR("============================================================"
  8745. + "================");
  8746. + LOG_ERR("============================================================"
  8747. + "================");
  8748. +
  8749. + in_loud_error = 0;
  8750. +}
  8751. +
  8752. +#if 1
  8753. +static int check_cma_config(void) { return 1; }
  8754. +#else
  8755. +static int
  8756. +read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
  8757. + const char *symbol,
  8758. + void *buf, size_t bufsize)
  8759. +{
  8760. + VC_MEM_ADDR_T vcMemAddr;
  8761. + size_t vcMemSize;
  8762. + uint8_t *mapAddr;
  8763. + off_t vcMapAddr;
  8764. +
  8765. + if (!LookupVideoCoreSymbol(handle, symbol,
  8766. + &vcMemAddr,
  8767. + &vcMemSize)) {
  8768. + loud_error_header();
  8769. + loud_error(
  8770. + "failed to find VC symbol \"%s\".",
  8771. + symbol);
  8772. + loud_error_footer();
  8773. + return 0;
  8774. + }
  8775. +
  8776. + if (vcMemSize != bufsize) {
  8777. + loud_error_header();
  8778. + loud_error(
  8779. + "VC symbol \"%s\" is the wrong size.",
  8780. + symbol);
  8781. + loud_error_footer();
  8782. + return 0;
  8783. + }
  8784. +
  8785. + vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
  8786. + vcMapAddr += mm_vc_mem_phys_addr;
  8787. + mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
  8788. + if (mapAddr == 0) {
  8789. + loud_error_header();
  8790. + loud_error(
  8791. + "failed to ioremap \"%s\" @ 0x%x "
  8792. + "(phys: 0x%x, size: %u).",
  8793. + symbol,
  8794. + (unsigned int)vcMapAddr,
  8795. + (unsigned int)vcMemAddr,
  8796. + (unsigned int)vcMemSize);
  8797. + loud_error_footer();
  8798. + return 0;
  8799. + }
  8800. +
  8801. + memcpy(buf, mapAddr, bufsize);
  8802. + iounmap(mapAddr);
  8803. +
  8804. + return 1;
  8805. +}
  8806. +
  8807. +
  8808. +static int
  8809. +check_cma_config(void)
  8810. +{
  8811. + VC_MEM_ACCESS_HANDLE_T mem_hndl;
  8812. + VC_MEM_ADDR_T mempool_start;
  8813. + VC_MEM_ADDR_T mempool_end;
  8814. + VC_MEM_ADDR_T mempool_offline_start;
  8815. + VC_MEM_ADDR_T mempool_offline_end;
  8816. + VC_MEM_ADDR_T cam_alloc_base;
  8817. + VC_MEM_ADDR_T cam_alloc_size;
  8818. + VC_MEM_ADDR_T cam_alloc_end;
  8819. + int success = 0;
  8820. +
  8821. + if (OpenVideoCoreMemory(&mem_hndl) != 0)
  8822. + goto out;
  8823. +
  8824. + /* Read the relevant VideoCore variables */
  8825. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
  8826. + &mempool_start,
  8827. + sizeof(mempool_start)))
  8828. + goto close;
  8829. +
  8830. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
  8831. + &mempool_end,
  8832. + sizeof(mempool_end)))
  8833. + goto close;
  8834. +
  8835. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
  8836. + &mempool_offline_start,
  8837. + sizeof(mempool_offline_start)))
  8838. + goto close;
  8839. +
  8840. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
  8841. + &mempool_offline_end,
  8842. + sizeof(mempool_offline_end)))
  8843. + goto close;
  8844. +
  8845. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
  8846. + &cam_alloc_base,
  8847. + sizeof(cam_alloc_base)))
  8848. + goto close;
  8849. +
  8850. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
  8851. + &cam_alloc_size,
  8852. + sizeof(cam_alloc_size)))
  8853. + goto close;
  8854. +
  8855. + cam_alloc_end = cam_alloc_base + cam_alloc_size;
  8856. +
  8857. + success = 1;
  8858. +
  8859. + /* Now the sanity checks */
  8860. + if (!mempool_offline_start)
  8861. + mempool_offline_start = mempool_start;
  8862. + if (!mempool_offline_end)
  8863. + mempool_offline_end = mempool_end;
  8864. +
  8865. + if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
  8866. + loud_error_header();
  8867. + loud_error(
  8868. + "__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
  8869. + "vc_cma_base(%x)",
  8870. + mempool_offline_start,
  8871. + VCADDR_TO_PHYSADDR(mempool_offline_start),
  8872. + vc_cma_base);
  8873. + success = 0;
  8874. + }
  8875. +
  8876. + if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
  8877. + (vc_cma_base + vc_cma_size)) {
  8878. + loud_error_header();
  8879. + loud_error(
  8880. + "__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
  8881. + "vc_cma_base(%x) + vc_cma_size(%x) = %x",
  8882. + mempool_offline_start,
  8883. + VCADDR_TO_PHYSADDR(mempool_offline_end),
  8884. + vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
  8885. + success = 0;
  8886. + }
  8887. +
  8888. + if (mempool_end < mempool_start) {
  8889. + loud_error_header();
  8890. + loud_error(
  8891. + "__MEMPOOL_END(%x) must not be before "
  8892. + "__MEMPOOL_START(%x)",
  8893. + mempool_end,
  8894. + mempool_start);
  8895. + success = 0;
  8896. + }
  8897. +
  8898. + if (mempool_offline_end < mempool_offline_start) {
  8899. + loud_error_header();
  8900. + loud_error(
  8901. + "__MEMPOOL_OFFLINE_END(%x) must not be before "
  8902. + "__MEMPOOL_OFFLINE_START(%x)",
  8903. + mempool_offline_end,
  8904. + mempool_offline_start);
  8905. + success = 0;
  8906. + }
  8907. +
  8908. + if (mempool_offline_start < mempool_start) {
  8909. + loud_error_header();
  8910. + loud_error(
  8911. + "__MEMPOOL_OFFLINE_START(%x) must not be before "
  8912. + "__MEMPOOL_START(%x)",
  8913. + mempool_offline_start,
  8914. + mempool_start);
  8915. + success = 0;
  8916. + }
  8917. +
  8918. + if (mempool_offline_end > mempool_end) {
  8919. + loud_error_header();
  8920. + loud_error(
  8921. + "__MEMPOOL_OFFLINE_END(%x) must not be after "
  8922. + "__MEMPOOL_END(%x)",
  8923. + mempool_offline_end,
  8924. + mempool_end);
  8925. + success = 0;
  8926. + }
  8927. +
  8928. + if ((cam_alloc_base < mempool_end) &&
  8929. + (cam_alloc_end > mempool_start)) {
  8930. + loud_error_header();
  8931. + loud_error(
  8932. + "cam_alloc pool(%x-%x) overlaps "
  8933. + "mempool(%x-%x)",
  8934. + cam_alloc_base, cam_alloc_end,
  8935. + mempool_start, mempool_end);
  8936. + success = 0;
  8937. + }
  8938. +
  8939. + loud_error_footer();
  8940. +
  8941. +close:
  8942. + CloseVideoCoreMemory(mem_hndl);
  8943. +
  8944. +out:
  8945. + return success;
  8946. +}
  8947. +#endif
  8948. +
  8949. +static int vc_cma_init(void)
  8950. +{
  8951. + int rc = -EFAULT;
  8952. + struct device *dev;
  8953. +
  8954. + if (!check_cma_config())
  8955. + goto out_release;
  8956. +
  8957. + printk(KERN_INFO "vc-cma: Videocore CMA driver\n");
  8958. + printk(KERN_INFO "vc-cma: vc_cma_base = 0x%08x\n", vc_cma_base);
  8959. + printk(KERN_INFO "vc-cma: vc_cma_size = 0x%08x (%u MiB)\n",
  8960. + vc_cma_size, vc_cma_size / (1024 * 1024));
  8961. + printk(KERN_INFO "vc-cma: vc_cma_initial = 0x%08x (%u MiB)\n",
  8962. + vc_cma_initial, vc_cma_initial / (1024 * 1024));
  8963. +
  8964. + vc_cma_base_page = phys_to_page(vc_cma_base);
  8965. +
  8966. + if (vc_cma_chunks) {
  8967. + int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
  8968. +
  8969. + for (vc_cma_chunks_used = 0;
  8970. + vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
  8971. + struct page *chunk;
  8972. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  8973. + PAGES_PER_CHUNK,
  8974. + VC_CMA_CHUNK_ORDER);
  8975. + if (!chunk)
  8976. + break;
  8977. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  8978. + VC_CMA_CHUNK_SIZE) != 0);
  8979. + }
  8980. + if (vc_cma_chunks_used != chunks_needed) {
  8981. + LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
  8982. + "bytes, allocation %d of %d)",
  8983. + __func__, VC_CMA_CHUNK_SIZE,
  8984. + vc_cma_chunks_used, chunks_needed);
  8985. + goto out_release;
  8986. + }
  8987. +
  8988. + vchiq_add_connected_callback(vc_cma_connected_init);
  8989. + }
  8990. +
  8991. + rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
  8992. + if (rc < 0) {
  8993. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  8994. + goto out_release;
  8995. + }
  8996. +
  8997. + cdev_init(&vc_cma_cdev, &vc_cma_fops);
  8998. + rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
  8999. + if (rc != 0) {
  9000. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  9001. + goto out_unregister;
  9002. + }
  9003. +
  9004. + vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
  9005. + if (IS_ERR(vc_cma_class)) {
  9006. + rc = PTR_ERR(vc_cma_class);
  9007. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  9008. + goto out_cdev_del;
  9009. + }
  9010. +
  9011. + dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
  9012. + DRIVER_NAME);
  9013. + if (IS_ERR(dev)) {
  9014. + rc = PTR_ERR(dev);
  9015. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  9016. + goto out_class_destroy;
  9017. + }
  9018. +
  9019. + vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
  9020. + if (vc_cma_proc_entry == NULL) {
  9021. + rc = -EFAULT;
  9022. + LOG_ERR("%s: proc_create failed", __func__);
  9023. + goto out_device_destroy;
  9024. + }
  9025. +
  9026. + vc_cma_inited = 1;
  9027. + return 0;
  9028. +
  9029. +out_device_destroy:
  9030. + device_destroy(vc_cma_class, vc_cma_devnum);
  9031. +
  9032. +out_class_destroy:
  9033. + class_destroy(vc_cma_class);
  9034. + vc_cma_class = NULL;
  9035. +
  9036. +out_cdev_del:
  9037. + cdev_del(&vc_cma_cdev);
  9038. +
  9039. +out_unregister:
  9040. + unregister_chrdev_region(vc_cma_devnum, 1);
  9041. +
  9042. +out_release:
  9043. + /* It is tempting to try to clean up by calling
  9044. + dma_release_from_contiguous for all allocated chunks, but it isn't
  9045. + a very safe thing to do. If vc_cma_initial is non-zero it is because
  9046. + VideoCore is already using that memory, so giving it back to Linux
  9047. + is likely to be fatal.
  9048. + */
  9049. + return -1;
  9050. +}
  9051. +
  9052. +/****************************************************************************
  9053. +*
  9054. +* vc_cma_exit
  9055. +*
  9056. +***************************************************************************/
  9057. +
  9058. +static void __exit vc_cma_exit(void)
  9059. +{
  9060. + LOG_DBG("%s: called", __func__);
  9061. +
  9062. + if (vc_cma_inited) {
  9063. + remove_proc_entry(DRIVER_NAME, NULL);
  9064. + device_destroy(vc_cma_class, vc_cma_devnum);
  9065. + class_destroy(vc_cma_class);
  9066. + cdev_del(&vc_cma_cdev);
  9067. + unregister_chrdev_region(vc_cma_devnum, 1);
  9068. + }
  9069. +}
  9070. +
  9071. +module_init(vc_cma_init);
  9072. +module_exit(vc_cma_exit);
  9073. +MODULE_LICENSE("GPL");
  9074. +MODULE_AUTHOR("Broadcom Corporation");
  9075. diff -Nur linux-3.12.18/drivers/char/hw_random/bcm2708-rng.c linux-rpi/drivers/char/hw_random/bcm2708-rng.c
  9076. --- linux-3.12.18/drivers/char/hw_random/bcm2708-rng.c 1970-01-01 01:00:00.000000000 +0100
  9077. +++ linux-rpi/drivers/char/hw_random/bcm2708-rng.c 2014-04-24 15:35:02.101542691 +0200
  9078. @@ -0,0 +1,117 @@
  9079. +/**
  9080. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  9081. + *
  9082. + * Redistribution and use in source and binary forms, with or without
  9083. + * modification, are permitted provided that the following conditions
  9084. + * are met:
  9085. + * 1. Redistributions of source code must retain the above copyright
  9086. + * notice, this list of conditions, and the following disclaimer,
  9087. + * without modification.
  9088. + * 2. Redistributions in binary form must reproduce the above copyright
  9089. + * notice, this list of conditions and the following disclaimer in the
  9090. + * documentation and/or other materials provided with the distribution.
  9091. + * 3. The names of the above-listed copyright holders may not be used
  9092. + * to endorse or promote products derived from this software without
  9093. + * specific prior written permission.
  9094. + *
  9095. + * ALTERNATIVELY, this software may be distributed under the terms of the
  9096. + * GNU General Public License ("GPL") version 2, as published by the Free
  9097. + * Software Foundation.
  9098. + *
  9099. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  9100. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  9101. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  9102. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  9103. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  9104. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  9105. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  9106. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  9107. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  9108. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  9109. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9110. + */
  9111. +
  9112. +#include <linux/kernel.h>
  9113. +#include <linux/module.h>
  9114. +#include <linux/init.h>
  9115. +#include <linux/hw_random.h>
  9116. +#include <linux/printk.h>
  9117. +
  9118. +#include <asm/io.h>
  9119. +#include <mach/hardware.h>
  9120. +#include <mach/platform.h>
  9121. +
  9122. +#define RNG_CTRL (0x0)
  9123. +#define RNG_STATUS (0x4)
  9124. +#define RNG_DATA (0x8)
  9125. +#define RNG_FF_THRESHOLD (0xc)
  9126. +
  9127. +/* enable rng */
  9128. +#define RNG_RBGEN 0x1
  9129. +/* double speed, less random mode */
  9130. +#define RNG_RBG2X 0x2
  9131. +
  9132. +/* the initial numbers generated are "less random" so will be discarded */
  9133. +#define RNG_WARMUP_COUNT 0x40000
  9134. +
  9135. +static int bcm2708_rng_data_read(struct hwrng *rng, u32 *buffer)
  9136. +{
  9137. + void __iomem *rng_base = (void __iomem *)rng->priv;
  9138. + unsigned words;
  9139. + /* wait for a random number to be in fifo */
  9140. + do {
  9141. + words = __raw_readl(rng_base + RNG_STATUS)>>24;
  9142. + }
  9143. + while (words == 0);
  9144. + /* read the random number */
  9145. + *buffer = __raw_readl(rng_base + RNG_DATA);
  9146. + return 4;
  9147. +}
  9148. +
  9149. +static struct hwrng bcm2708_rng_ops = {
  9150. + .name = "bcm2708",
  9151. + .data_read = bcm2708_rng_data_read,
  9152. +};
  9153. +
  9154. +static int __init bcm2708_rng_init(void)
  9155. +{
  9156. + void __iomem *rng_base;
  9157. + int err;
  9158. +
  9159. + /* map peripheral */
  9160. + rng_base = ioremap(RNG_BASE, 0x10);
  9161. + pr_info("bcm2708_rng_init=%p\n", rng_base);
  9162. + if (!rng_base) {
  9163. + pr_err("bcm2708_rng_init failed to ioremap\n");
  9164. + return -ENOMEM;
  9165. + }
  9166. + bcm2708_rng_ops.priv = (unsigned long)rng_base;
  9167. + /* register driver */
  9168. + err = hwrng_register(&bcm2708_rng_ops);
  9169. + if (err) {
  9170. + pr_err("bcm2708_rng_init hwrng_register()=%d\n", err);
  9171. + iounmap(rng_base);
  9172. + } else {
  9173. + /* set warm-up count & enable */
  9174. + __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
  9175. + __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
  9176. + }
  9177. + return err;
  9178. +}
  9179. +
  9180. +static void __exit bcm2708_rng_exit(void)
  9181. +{
  9182. + void __iomem *rng_base = (void __iomem *)bcm2708_rng_ops.priv;
  9183. + pr_info("bcm2708_rng_exit\n");
  9184. + /* disable rng hardware */
  9185. + __raw_writel(0, rng_base + RNG_CTRL);
  9186. + /* unregister driver */
  9187. + hwrng_unregister(&bcm2708_rng_ops);
  9188. + iounmap(rng_base);
  9189. +}
  9190. +
  9191. +module_init(bcm2708_rng_init);
  9192. +module_exit(bcm2708_rng_exit);
  9193. +
  9194. +MODULE_DESCRIPTION("BCM2708 H/W Random Number Generator (RNG) driver");
  9195. +MODULE_LICENSE("GPL and additional rights");
  9196. diff -Nur linux-3.12.18/drivers/char/hw_random/Kconfig linux-rpi/drivers/char/hw_random/Kconfig
  9197. --- linux-3.12.18/drivers/char/hw_random/Kconfig 2014-04-18 11:14:28.000000000 +0200
  9198. +++ linux-rpi/drivers/char/hw_random/Kconfig 2014-04-24 16:04:34.339071265 +0200
  9199. @@ -314,3 +314,14 @@
  9200. module will be called tpm-rng.
  9201. If unsure, say Y.
  9202. +
  9203. +config HW_RANDOM_BCM2708
  9204. + tristate "BCM2708 generic true random number generator support"
  9205. + depends on HW_RANDOM && ARCH_BCM2708
  9206. + ---help---
  9207. + This driver provides the kernel-side support for the BCM2708 hardware.
  9208. +
  9209. + To compile this driver as a module, choose M here: the
  9210. + module will be called bcm2708-rng.
  9211. +
  9212. + If unsure, say N.
  9213. diff -Nur linux-3.12.18/drivers/char/hw_random/Makefile linux-rpi/drivers/char/hw_random/Makefile
  9214. --- linux-3.12.18/drivers/char/hw_random/Makefile 2014-04-18 11:14:28.000000000 +0200
  9215. +++ linux-rpi/drivers/char/hw_random/Makefile 2014-04-24 15:35:02.101542691 +0200
  9216. @@ -27,3 +27,4 @@
  9217. obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
  9218. obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
  9219. obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
  9220. +obj-$(CONFIG_HW_RANDOM_BCM2708) += bcm2708-rng.o
  9221. diff -Nur linux-3.12.18/drivers/char/ipmi/ipmi_bt_sm.c linux-rpi/drivers/char/ipmi/ipmi_bt_sm.c
  9222. --- linux-3.12.18/drivers/char/ipmi/ipmi_bt_sm.c 2014-04-18 11:14:28.000000000 +0200
  9223. +++ linux-rpi/drivers/char/ipmi/ipmi_bt_sm.c 2014-04-24 15:35:02.105542736 +0200
  9224. @@ -352,7 +352,7 @@
  9225. static inline int read_all_bytes(struct si_sm_data *bt)
  9226. {
  9227. - unsigned int i;
  9228. + unsigned char i;
  9229. /*
  9230. * length is "framing info", minimum = 4: NetFn, Seq, Cmd, cCode.
  9231. diff -Nur linux-3.12.18/drivers/char/Kconfig linux-rpi/drivers/char/Kconfig
  9232. --- linux-3.12.18/drivers/char/Kconfig 2014-04-18 11:14:28.000000000 +0200
  9233. +++ linux-rpi/drivers/char/Kconfig 2014-04-24 16:04:34.335071226 +0200
  9234. @@ -574,6 +574,8 @@
  9235. source "drivers/s390/char/Kconfig"
  9236. +source "drivers/char/broadcom/Kconfig"
  9237. +
  9238. config MSM_SMD_PKT
  9239. bool "Enable device interface for some SMD packet ports"
  9240. default n
  9241. diff -Nur linux-3.12.18/drivers/char/Makefile linux-rpi/drivers/char/Makefile
  9242. --- linux-3.12.18/drivers/char/Makefile 2014-04-18 11:14:28.000000000 +0200
  9243. +++ linux-rpi/drivers/char/Makefile 2014-04-24 16:04:34.335071226 +0200
  9244. @@ -62,3 +62,5 @@
  9245. js-rtc-y = rtc.o
  9246. obj-$(CONFIG_TILE_SROM) += tile-srom.o
  9247. +
  9248. +obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/
  9249. diff -Nur linux-3.12.18/drivers/cpufreq/bcm2835-cpufreq.c linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c
  9250. --- linux-3.12.18/drivers/cpufreq/bcm2835-cpufreq.c 1970-01-01 01:00:00.000000000 +0100
  9251. +++ linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c 2014-04-24 16:04:34.575073548 +0200
  9252. @@ -0,0 +1,239 @@
  9253. +/*****************************************************************************
  9254. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  9255. +*
  9256. +* Unless you and Broadcom execute a separate written software license
  9257. +* agreement governing use of this software, this software is licensed to you
  9258. +* under the terms of the GNU General Public License version 2, available at
  9259. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  9260. +*
  9261. +* Notwithstanding the above, under no circumstances may you combine this
  9262. +* software in any way with any other Broadcom software provided under a
  9263. +* license other than the GPL, without Broadcom's express prior written
  9264. +* consent.
  9265. +*****************************************************************************/
  9266. +
  9267. +/*****************************************************************************
  9268. +* FILENAME: bcm2835-cpufreq.h
  9269. +* DESCRIPTION: This driver dynamically manages the CPU Frequency of the ARM
  9270. +* processor. Messages are sent to Videocore either setting or requesting the
  9271. +* frequency of the ARM in order to match an appropiate frequency to the current
  9272. +* usage of the processor. The policy which selects the frequency to use is
  9273. +* defined in the kernel .config file, but can be changed during runtime.
  9274. +*****************************************************************************/
  9275. +
  9276. +/* ---------- INCLUDES ---------- */
  9277. +#include <linux/kernel.h>
  9278. +#include <linux/init.h>
  9279. +#include <linux/module.h>
  9280. +#include <linux/cpufreq.h>
  9281. +#include <mach/vcio.h>
  9282. +
  9283. +/* ---------- DEFINES ---------- */
  9284. +/*#define CPUFREQ_DEBUG_ENABLE*/ /* enable debugging */
  9285. +#define MODULE_NAME "bcm2835-cpufreq"
  9286. +
  9287. +#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */
  9288. +
  9289. +/* debug printk macros */
  9290. +#ifdef CPUFREQ_DEBUG_ENABLE
  9291. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  9292. +#else
  9293. +#define print_debug(fmt,...)
  9294. +#endif
  9295. +#define print_err(fmt,...) pr_err("%s:%s:%d: "fmt, MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  9296. +#define print_info(fmt,...) pr_info("%s: "fmt, MODULE_NAME, ##__VA_ARGS__)
  9297. +
  9298. +/* tag part of the message */
  9299. +struct vc_msg_tag {
  9300. + uint32_t tag_id; /* the message id */
  9301. + uint32_t buffer_size; /* size of the buffer (which in this case is always 8 bytes) */
  9302. + uint32_t data_size; /* amount of data being sent or received */
  9303. + uint32_t dev_id; /* the ID of the clock/voltage to get or set */
  9304. + uint32_t val; /* the value (e.g. rate (in Hz)) to set */
  9305. +};
  9306. +
  9307. +/* message structure to be sent to videocore */
  9308. +struct vc_msg {
  9309. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  9310. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  9311. + struct vc_msg_tag tag; /* the tag structure above to make */
  9312. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  9313. +};
  9314. +
  9315. +/* ---------- GLOBALS ---------- */
  9316. +static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */
  9317. +
  9318. +/*
  9319. + ===============================================
  9320. + clk_rate either gets or sets the clock rates.
  9321. + ===============================================
  9322. +*/
  9323. +static uint32_t bcm2835_cpufreq_set_clock(int cur_rate, int arm_rate)
  9324. +{
  9325. + int s, actual_rate=0;
  9326. + struct vc_msg msg;
  9327. +
  9328. + /* wipe all previous message data */
  9329. + memset(&msg, 0, sizeof msg);
  9330. +
  9331. + msg.msg_size = sizeof msg;
  9332. +
  9333. + msg.tag.tag_id = VCMSG_SET_CLOCK_RATE;
  9334. + msg.tag.buffer_size = 8;
  9335. + msg.tag.data_size = 8; /* we're sending the clock ID and the new rates which is a total of 2 words */
  9336. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  9337. + msg.tag.val = arm_rate * 1000;
  9338. +
  9339. + /* send the message */
  9340. + s = bcm_mailbox_property(&msg, sizeof msg);
  9341. +
  9342. + /* check if it was all ok and return the rate in KHz */
  9343. + if (s == 0 && (msg.request_code & 0x80000000))
  9344. + actual_rate = msg.tag.val/1000;
  9345. +
  9346. + print_debug("Setting new frequency = %d -> %d (actual %d)\n", cur_rate, arm_rate, actual_rate);
  9347. + return actual_rate;
  9348. +}
  9349. +
  9350. +static uint32_t bcm2835_cpufreq_get_clock(int tag)
  9351. +{
  9352. + int s;
  9353. + int arm_rate = 0;
  9354. + struct vc_msg msg;
  9355. +
  9356. + /* wipe all previous message data */
  9357. + memset(&msg, 0, sizeof msg);
  9358. +
  9359. + msg.msg_size = sizeof msg;
  9360. + msg.tag.tag_id = tag;
  9361. + msg.tag.buffer_size = 8;
  9362. + msg.tag.data_size = 4; /* we're just sending the clock ID which is one word long */
  9363. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  9364. +
  9365. + /* send the message */
  9366. + s = bcm_mailbox_property(&msg, sizeof msg);
  9367. +
  9368. + /* check if it was all ok and return the rate in KHz */
  9369. + if (s == 0 && (msg.request_code & 0x80000000))
  9370. + arm_rate = msg.tag.val/1000;
  9371. +
  9372. + print_debug("%s frequency = %d\n",
  9373. + tag == VCMSG_GET_CLOCK_RATE ? "Current":
  9374. + tag == VCMSG_GET_MIN_CLOCK ? "Min":
  9375. + tag == VCMSG_GET_MAX_CLOCK ? "Max":
  9376. + "Unexpected", arm_rate);
  9377. +
  9378. + return arm_rate;
  9379. +}
  9380. +
  9381. +/*
  9382. + ====================================================
  9383. + Module Initialisation registers the cpufreq driver
  9384. + ====================================================
  9385. +*/
  9386. +static int __init bcm2835_cpufreq_module_init(void)
  9387. +{
  9388. + print_debug("IN\n");
  9389. + return cpufreq_register_driver(&bcm2835_cpufreq_driver);
  9390. +}
  9391. +
  9392. +/*
  9393. + =============
  9394. + Module exit
  9395. + =============
  9396. +*/
  9397. +static void __exit bcm2835_cpufreq_module_exit(void)
  9398. +{
  9399. + print_debug("IN\n");
  9400. + cpufreq_unregister_driver(&bcm2835_cpufreq_driver);
  9401. + return;
  9402. +}
  9403. +
  9404. +/*
  9405. + ==============================================================
  9406. + Initialisation function sets up the CPU policy for first use
  9407. + ==============================================================
  9408. +*/
  9409. +static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
  9410. +{
  9411. + /* measured value of how long it takes to change frequency */
  9412. + policy->cpuinfo.transition_latency = 355000; /* ns */
  9413. +
  9414. + /* now find out what the maximum and minimum frequencies are */
  9415. + policy->min = policy->cpuinfo.min_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MIN_CLOCK);
  9416. + policy->max = policy->cpuinfo.max_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MAX_CLOCK);
  9417. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9418. +
  9419. + print_info("min=%d max=%d cur=%d\n", policy->min, policy->max, policy->cur);
  9420. + return 0;
  9421. +}
  9422. +
  9423. +/*
  9424. + =================================================================================
  9425. + Target function chooses the most appropriate frequency from the table to enable
  9426. + =================================================================================
  9427. +*/
  9428. +
  9429. +static int bcm2835_cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation)
  9430. +{
  9431. + unsigned int target = target_freq;
  9432. +#ifdef CPUFREQ_DEBUG_ENABLE
  9433. + unsigned int cur = policy->cur;
  9434. +#endif
  9435. + print_debug("%s: min=%d max=%d cur=%d target=%d\n",policy->governor->name,policy->min,policy->max,policy->cur,target_freq);
  9436. +
  9437. + /* if we are above min and using ondemand, then just use max */
  9438. + if (strcmp("ondemand", policy->governor->name)==0 && target > policy->min)
  9439. + target = policy->max;
  9440. + /* if the frequency is the same, just quit */
  9441. + if (target == policy->cur)
  9442. + return 0;
  9443. +
  9444. + /* otherwise were good to set the clock frequency */
  9445. + policy->cur = bcm2835_cpufreq_set_clock(policy->cur, target);
  9446. +
  9447. + if (!policy->cur)
  9448. + {
  9449. + print_err("Error occurred setting a new frequency (%d)!\n", target);
  9450. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9451. + return -EINVAL;
  9452. + }
  9453. + print_debug("Freq %d->%d (min=%d max=%d target=%d request=%d)\n", cur, policy->cur, policy->min, policy->max, target_freq, target);
  9454. + return 0;
  9455. +}
  9456. +
  9457. +static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
  9458. +{
  9459. + unsigned int actual_rate = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9460. + print_debug("cpu=%d\n", actual_rate);
  9461. + return actual_rate;
  9462. +}
  9463. +
  9464. +/*
  9465. + =================================================================================
  9466. + Verify ensures that when a policy is changed, it is suitable for the CPU to use
  9467. + =================================================================================
  9468. +*/
  9469. +
  9470. +static int bcm2835_cpufreq_driver_verify(struct cpufreq_policy *policy)
  9471. +{
  9472. + print_info("switching to governor %s\n", policy->governor->name);
  9473. + return 0;
  9474. +}
  9475. +
  9476. +
  9477. +/* the CPUFreq driver */
  9478. +static struct cpufreq_driver bcm2835_cpufreq_driver = {
  9479. + .name = "BCM2835 CPUFreq",
  9480. + .init = bcm2835_cpufreq_driver_init,
  9481. + .verify = bcm2835_cpufreq_driver_verify,
  9482. + .target = bcm2835_cpufreq_driver_target,
  9483. + .get = bcm2835_cpufreq_driver_get
  9484. +};
  9485. +
  9486. +MODULE_AUTHOR("Dorian Peake and Dom Cobley");
  9487. +MODULE_DESCRIPTION("CPU frequency driver for BCM2835 chip");
  9488. +MODULE_LICENSE("GPL");
  9489. +
  9490. +module_init(bcm2835_cpufreq_module_init);
  9491. +module_exit(bcm2835_cpufreq_module_exit);
  9492. diff -Nur linux-3.12.18/drivers/cpufreq/Kconfig.arm linux-rpi/drivers/cpufreq/Kconfig.arm
  9493. --- linux-3.12.18/drivers/cpufreq/Kconfig.arm 2014-04-18 11:14:28.000000000 +0200
  9494. +++ linux-rpi/drivers/cpufreq/Kconfig.arm 2014-04-24 16:04:34.575073548 +0200
  9495. @@ -228,6 +228,14 @@
  9496. help
  9497. This adds the CPUFreq driver support for SPEAr SOCs.
  9498. +config ARM_BCM2835_CPUFREQ
  9499. + bool "BCM2835 Driver"
  9500. + default y
  9501. + help
  9502. + This adds the CPUFreq driver for BCM2835
  9503. +
  9504. + If in doubt, say N.
  9505. +
  9506. config ARM_TEGRA_CPUFREQ
  9507. bool "TEGRA CPUFreq support"
  9508. depends on ARCH_TEGRA
  9509. diff -Nur linux-3.12.18/drivers/cpufreq/Makefile linux-rpi/drivers/cpufreq/Makefile
  9510. --- linux-3.12.18/drivers/cpufreq/Makefile 2014-04-18 11:14:28.000000000 +0200
  9511. +++ linux-rpi/drivers/cpufreq/Makefile 2014-04-24 16:04:34.575073548 +0200
  9512. @@ -76,6 +76,7 @@
  9513. obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o
  9514. obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
  9515. obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
  9516. +obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
  9517. obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o
  9518. ##################################################################################
  9519. diff -Nur linux-3.12.18/drivers/cpufreq/powernow-k6.c linux-rpi/drivers/cpufreq/powernow-k6.c
  9520. --- linux-3.12.18/drivers/cpufreq/powernow-k6.c 2014-04-18 11:14:28.000000000 +0200
  9521. +++ linux-rpi/drivers/cpufreq/powernow-k6.c 2014-04-24 16:04:34.587073663 +0200
  9522. @@ -26,108 +26,41 @@
  9523. static unsigned int busfreq; /* FSB, in 10 kHz */
  9524. static unsigned int max_multiplier;
  9525. -static unsigned int param_busfreq = 0;
  9526. -static unsigned int param_max_multiplier = 0;
  9527. -
  9528. -module_param_named(max_multiplier, param_max_multiplier, uint, S_IRUGO);
  9529. -MODULE_PARM_DESC(max_multiplier, "Maximum multiplier (allowed values: 20 30 35 40 45 50 55 60)");
  9530. -
  9531. -module_param_named(bus_frequency, param_busfreq, uint, S_IRUGO);
  9532. -MODULE_PARM_DESC(bus_frequency, "Bus frequency in kHz");
  9533. /* Clock ratio multiplied by 10 - see table 27 in AMD#23446 */
  9534. static struct cpufreq_frequency_table clock_ratio[] = {
  9535. - {60, /* 110 -> 6.0x */ 0},
  9536. - {55, /* 011 -> 5.5x */ 0},
  9537. - {50, /* 001 -> 5.0x */ 0},
  9538. {45, /* 000 -> 4.5x */ 0},
  9539. + {50, /* 001 -> 5.0x */ 0},
  9540. {40, /* 010 -> 4.0x */ 0},
  9541. - {35, /* 111 -> 3.5x */ 0},
  9542. - {30, /* 101 -> 3.0x */ 0},
  9543. + {55, /* 011 -> 5.5x */ 0},
  9544. {20, /* 100 -> 2.0x */ 0},
  9545. + {30, /* 101 -> 3.0x */ 0},
  9546. + {60, /* 110 -> 6.0x */ 0},
  9547. + {35, /* 111 -> 3.5x */ 0},
  9548. {0, CPUFREQ_TABLE_END}
  9549. };
  9550. -static const u8 index_to_register[8] = { 6, 3, 1, 0, 2, 7, 5, 4 };
  9551. -static const u8 register_to_index[8] = { 3, 2, 4, 1, 7, 6, 0, 5 };
  9552. -
  9553. -static const struct {
  9554. - unsigned freq;
  9555. - unsigned mult;
  9556. -} usual_frequency_table[] = {
  9557. - { 400000, 40 }, // 100 * 4
  9558. - { 450000, 45 }, // 100 * 4.5
  9559. - { 475000, 50 }, // 95 * 5
  9560. - { 500000, 50 }, // 100 * 5
  9561. - { 506250, 45 }, // 112.5 * 4.5
  9562. - { 533500, 55 }, // 97 * 5.5
  9563. - { 550000, 55 }, // 100 * 5.5
  9564. - { 562500, 50 }, // 112.5 * 5
  9565. - { 570000, 60 }, // 95 * 6
  9566. - { 600000, 60 }, // 100 * 6
  9567. - { 618750, 55 }, // 112.5 * 5.5
  9568. - { 660000, 55 }, // 120 * 5.5
  9569. - { 675000, 60 }, // 112.5 * 6
  9570. - { 720000, 60 }, // 120 * 6
  9571. -};
  9572. -
  9573. -#define FREQ_RANGE 3000
  9574. /**
  9575. * powernow_k6_get_cpu_multiplier - returns the current FSB multiplier
  9576. *
  9577. - * Returns the current setting of the frequency multiplier. Core clock
  9578. + * Returns the current setting of the frequency multiplier. Core clock
  9579. * speed is frequency of the Front-Side Bus multiplied with this value.
  9580. */
  9581. static int powernow_k6_get_cpu_multiplier(void)
  9582. {
  9583. - unsigned long invalue = 0;
  9584. + u64 invalue = 0;
  9585. u32 msrval;
  9586. - local_irq_disable();
  9587. -
  9588. msrval = POWERNOW_IOPORT + 0x1;
  9589. wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
  9590. invalue = inl(POWERNOW_IOPORT + 0x8);
  9591. msrval = POWERNOW_IOPORT + 0x0;
  9592. wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
  9593. - local_irq_enable();
  9594. -
  9595. - return clock_ratio[register_to_index[(invalue >> 5)&7]].driver_data;
  9596. + return clock_ratio[(invalue >> 5)&7].driver_data;
  9597. }
  9598. -static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
  9599. -{
  9600. - unsigned long outvalue, invalue;
  9601. - unsigned long msrval;
  9602. - unsigned long cr0;
  9603. -
  9604. - /* we now need to transform best_i to the BVC format, see AMD#23446 */
  9605. -
  9606. - /*
  9607. - * The processor doesn't respond to inquiry cycles while changing the
  9608. - * frequency, so we must disable cache.
  9609. - */
  9610. - local_irq_disable();
  9611. - cr0 = read_cr0();
  9612. - write_cr0(cr0 | X86_CR0_CD);
  9613. - wbinvd();
  9614. -
  9615. - outvalue = (1<<12) | (1<<10) | (1<<9) | (index_to_register[best_i]<<5);
  9616. -
  9617. - msrval = POWERNOW_IOPORT + 0x1;
  9618. - wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
  9619. - invalue = inl(POWERNOW_IOPORT + 0x8);
  9620. - invalue = invalue & 0x1f;
  9621. - outvalue = outvalue | invalue;
  9622. - outl(outvalue, (POWERNOW_IOPORT + 0x8));
  9623. - msrval = POWERNOW_IOPORT + 0x0;
  9624. - wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
  9625. -
  9626. - write_cr0(cr0);
  9627. - local_irq_enable();
  9628. -}
  9629. /**
  9630. * powernow_k6_set_state - set the PowerNow! multiplier
  9631. @@ -138,6 +71,8 @@
  9632. static void powernow_k6_set_state(struct cpufreq_policy *policy,
  9633. unsigned int best_i)
  9634. {
  9635. + unsigned long outvalue = 0, invalue = 0;
  9636. + unsigned long msrval;
  9637. struct cpufreq_freqs freqs;
  9638. if (clock_ratio[best_i].driver_data > max_multiplier) {
  9639. @@ -150,7 +85,18 @@
  9640. cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
  9641. - powernow_k6_set_cpu_multiplier(best_i);
  9642. + /* we now need to transform best_i to the BVC format, see AMD#23446 */
  9643. +
  9644. + outvalue = (1<<12) | (1<<10) | (1<<9) | (best_i<<5);
  9645. +
  9646. + msrval = POWERNOW_IOPORT + 0x1;
  9647. + wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
  9648. + invalue = inl(POWERNOW_IOPORT + 0x8);
  9649. + invalue = invalue & 0xf;
  9650. + outvalue = outvalue | invalue;
  9651. + outl(outvalue , (POWERNOW_IOPORT + 0x8));
  9652. + msrval = POWERNOW_IOPORT + 0x0;
  9653. + wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
  9654. cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
  9655. @@ -195,57 +141,18 @@
  9656. return 0;
  9657. }
  9658. +
  9659. static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
  9660. {
  9661. unsigned int i, f;
  9662. int result;
  9663. - unsigned khz;
  9664. if (policy->cpu != 0)
  9665. return -ENODEV;
  9666. - max_multiplier = 0;
  9667. - khz = cpu_khz;
  9668. - for (i = 0; i < ARRAY_SIZE(usual_frequency_table); i++) {
  9669. - if (khz >= usual_frequency_table[i].freq - FREQ_RANGE &&
  9670. - khz <= usual_frequency_table[i].freq + FREQ_RANGE) {
  9671. - khz = usual_frequency_table[i].freq;
  9672. - max_multiplier = usual_frequency_table[i].mult;
  9673. - break;
  9674. - }
  9675. - }
  9676. - if (param_max_multiplier) {
  9677. - for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) {
  9678. - if (clock_ratio[i].driver_data == param_max_multiplier) {
  9679. - max_multiplier = param_max_multiplier;
  9680. - goto have_max_multiplier;
  9681. - }
  9682. - }
  9683. - printk(KERN_ERR "powernow-k6: invalid max_multiplier parameter, valid parameters 20, 30, 35, 40, 45, 50, 55, 60\n");
  9684. - return -EINVAL;
  9685. - }
  9686. -
  9687. - if (!max_multiplier) {
  9688. - printk(KERN_WARNING "powernow-k6: unknown frequency %u, cannot determine current multiplier\n", khz);
  9689. - printk(KERN_WARNING "powernow-k6: use module parameters max_multiplier and bus_frequency\n");
  9690. - return -EOPNOTSUPP;
  9691. - }
  9692. -
  9693. -have_max_multiplier:
  9694. - param_max_multiplier = max_multiplier;
  9695. -
  9696. - if (param_busfreq) {
  9697. - if (param_busfreq >= 50000 && param_busfreq <= 150000) {
  9698. - busfreq = param_busfreq / 10;
  9699. - goto have_busfreq;
  9700. - }
  9701. - printk(KERN_ERR "powernow-k6: invalid bus_frequency parameter, allowed range 50000 - 150000 kHz\n");
  9702. - return -EINVAL;
  9703. - }
  9704. -
  9705. - busfreq = khz / max_multiplier;
  9706. -have_busfreq:
  9707. - param_busfreq = busfreq * 10;
  9708. + /* get frequencies */
  9709. + max_multiplier = powernow_k6_get_cpu_multiplier();
  9710. + busfreq = cpu_khz / max_multiplier;
  9711. /* table init */
  9712. for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) {
  9713. @@ -257,7 +164,7 @@
  9714. }
  9715. /* cpuinfo and default policy values */
  9716. - policy->cpuinfo.transition_latency = 500000;
  9717. + policy->cpuinfo.transition_latency = 200000;
  9718. policy->cur = busfreq * max_multiplier;
  9719. result = cpufreq_frequency_table_cpuinfo(policy, clock_ratio);
  9720. diff -Nur linux-3.12.18/drivers/dma/bcm2708-dmaengine.c linux-rpi/drivers/dma/bcm2708-dmaengine.c
  9721. --- linux-3.12.18/drivers/dma/bcm2708-dmaengine.c 1970-01-01 01:00:00.000000000 +0100
  9722. +++ linux-rpi/drivers/dma/bcm2708-dmaengine.c 2014-04-24 16:04:34.615073934 +0200
  9723. @@ -0,0 +1,588 @@
  9724. +/*
  9725. + * BCM2708 DMA engine support
  9726. + *
  9727. + * This driver only supports cyclic DMA transfers
  9728. + * as needed for the I2S module.
  9729. + *
  9730. + * Author: Florian Meier <florian.meier@koalo.de>
  9731. + * Copyright 2013
  9732. + *
  9733. + * Based on
  9734. + * OMAP DMAengine support by Russell King
  9735. + *
  9736. + * BCM2708 DMA Driver
  9737. + * Copyright (C) 2010 Broadcom
  9738. + *
  9739. + * Raspberry Pi PCM I2S ALSA Driver
  9740. + * Copyright (c) by Phil Poole 2013
  9741. + *
  9742. + * MARVELL MMP Peripheral DMA Driver
  9743. + * Copyright 2012 Marvell International Ltd.
  9744. + *
  9745. + * This program is free software; you can redistribute it and/or modify
  9746. + * it under the terms of the GNU General Public License as published by
  9747. + * the Free Software Foundation; either version 2 of the License, or
  9748. + * (at your option) any later version.
  9749. + *
  9750. + * This program is distributed in the hope that it will be useful,
  9751. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9752. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9753. + * GNU General Public License for more details.
  9754. + */
  9755. +#include <linux/dmaengine.h>
  9756. +#include <linux/dma-mapping.h>
  9757. +#include <linux/err.h>
  9758. +#include <linux/init.h>
  9759. +#include <linux/interrupt.h>
  9760. +#include <linux/list.h>
  9761. +#include <linux/module.h>
  9762. +#include <linux/platform_device.h>
  9763. +#include <linux/slab.h>
  9764. +#include <linux/io.h>
  9765. +#include <linux/spinlock.h>
  9766. +#include <linux/irq.h>
  9767. +
  9768. +#include "virt-dma.h"
  9769. +
  9770. +#include <mach/dma.h>
  9771. +#include <mach/irqs.h>
  9772. +
  9773. +struct bcm2708_dmadev {
  9774. + struct dma_device ddev;
  9775. + spinlock_t lock;
  9776. + void __iomem *base;
  9777. + struct device_dma_parameters dma_parms;
  9778. +};
  9779. +
  9780. +struct bcm2708_chan {
  9781. + struct virt_dma_chan vc;
  9782. + struct list_head node;
  9783. +
  9784. + struct dma_slave_config cfg;
  9785. + bool cyclic;
  9786. +
  9787. + int ch;
  9788. + struct bcm2708_desc *desc;
  9789. +
  9790. + void __iomem *chan_base;
  9791. + int irq_number;
  9792. +};
  9793. +
  9794. +struct bcm2708_desc {
  9795. + struct virt_dma_desc vd;
  9796. + enum dma_transfer_direction dir;
  9797. +
  9798. + unsigned int control_block_size;
  9799. + struct bcm2708_dma_cb *control_block_base;
  9800. + dma_addr_t control_block_base_phys;
  9801. +
  9802. + unsigned frames;
  9803. + size_t size;
  9804. +};
  9805. +
  9806. +#define BCM2708_DMA_DATA_TYPE_S8 1
  9807. +#define BCM2708_DMA_DATA_TYPE_S16 2
  9808. +#define BCM2708_DMA_DATA_TYPE_S32 4
  9809. +#define BCM2708_DMA_DATA_TYPE_S128 16
  9810. +
  9811. +static inline struct bcm2708_dmadev *to_bcm2708_dma_dev(struct dma_device *d)
  9812. +{
  9813. + return container_of(d, struct bcm2708_dmadev, ddev);
  9814. +}
  9815. +
  9816. +static inline struct bcm2708_chan *to_bcm2708_dma_chan(struct dma_chan *c)
  9817. +{
  9818. + return container_of(c, struct bcm2708_chan, vc.chan);
  9819. +}
  9820. +
  9821. +static inline struct bcm2708_desc *to_bcm2708_dma_desc(
  9822. + struct dma_async_tx_descriptor *t)
  9823. +{
  9824. + return container_of(t, struct bcm2708_desc, vd.tx);
  9825. +}
  9826. +
  9827. +static void bcm2708_dma_desc_free(struct virt_dma_desc *vd)
  9828. +{
  9829. + struct bcm2708_desc *desc = container_of(vd, struct bcm2708_desc, vd);
  9830. + dma_free_coherent(desc->vd.tx.chan->device->dev,
  9831. + desc->control_block_size,
  9832. + desc->control_block_base,
  9833. + desc->control_block_base_phys);
  9834. + kfree(desc);
  9835. +}
  9836. +
  9837. +static void bcm2708_dma_start_desc(struct bcm2708_chan *c)
  9838. +{
  9839. + struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
  9840. + struct bcm2708_desc *d;
  9841. +
  9842. + if (!vd) {
  9843. + c->desc = NULL;
  9844. + return;
  9845. + }
  9846. +
  9847. + list_del(&vd->node);
  9848. +
  9849. + c->desc = d = to_bcm2708_dma_desc(&vd->tx);
  9850. +
  9851. + bcm_dma_start(c->chan_base, d->control_block_base_phys);
  9852. +}
  9853. +
  9854. +static irqreturn_t bcm2708_dma_callback(int irq, void *data)
  9855. +{
  9856. + struct bcm2708_chan *c = data;
  9857. + struct bcm2708_desc *d;
  9858. + unsigned long flags;
  9859. +
  9860. + spin_lock_irqsave(&c->vc.lock, flags);
  9861. +
  9862. + /* Acknowledge interrupt */
  9863. + writel(BCM2708_DMA_INT, c->chan_base + BCM2708_DMA_CS);
  9864. +
  9865. + d = c->desc;
  9866. +
  9867. + if (d) {
  9868. + /* TODO Only works for cyclic DMA */
  9869. + vchan_cyclic_callback(&d->vd);
  9870. + }
  9871. +
  9872. + /* Keep the DMA engine running */
  9873. + dsb(); /* ARM synchronization barrier */
  9874. + writel(BCM2708_DMA_ACTIVE, c->chan_base + BCM2708_DMA_CS);
  9875. +
  9876. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9877. +
  9878. + return IRQ_HANDLED;
  9879. +}
  9880. +
  9881. +static int bcm2708_dma_alloc_chan_resources(struct dma_chan *chan)
  9882. +{
  9883. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9884. +
  9885. + return request_irq(c->irq_number,
  9886. + bcm2708_dma_callback, 0, "DMA IRQ", c);
  9887. +}
  9888. +
  9889. +static void bcm2708_dma_free_chan_resources(struct dma_chan *chan)
  9890. +{
  9891. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9892. +
  9893. + vchan_free_chan_resources(&c->vc);
  9894. + free_irq(c->irq_number, c);
  9895. +
  9896. + dev_dbg(c->vc.chan.device->dev, "Freeing DMA channel %u\n", c->ch);
  9897. +}
  9898. +
  9899. +static size_t bcm2708_dma_desc_size(struct bcm2708_desc *d)
  9900. +{
  9901. + return d->size;
  9902. +}
  9903. +
  9904. +static size_t bcm2708_dma_desc_size_pos(struct bcm2708_desc *d, dma_addr_t addr)
  9905. +{
  9906. + unsigned i;
  9907. + size_t size;
  9908. +
  9909. + for (size = i = 0; i < d->frames; i++) {
  9910. + struct bcm2708_dma_cb *control_block =
  9911. + &d->control_block_base[i];
  9912. + size_t this_size = control_block->length;
  9913. + dma_addr_t dma;
  9914. +
  9915. + if (d->dir == DMA_DEV_TO_MEM)
  9916. + dma = control_block->dst;
  9917. + else
  9918. + dma = control_block->src;
  9919. +
  9920. + if (size)
  9921. + size += this_size;
  9922. + else if (addr >= dma && addr < dma + this_size)
  9923. + size += dma + this_size - addr;
  9924. + }
  9925. +
  9926. + return size;
  9927. +}
  9928. +
  9929. +static enum dma_status bcm2708_dma_tx_status(struct dma_chan *chan,
  9930. + dma_cookie_t cookie, struct dma_tx_state *txstate)
  9931. +{
  9932. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9933. + struct virt_dma_desc *vd;
  9934. + enum dma_status ret;
  9935. + unsigned long flags;
  9936. +
  9937. + ret = dma_cookie_status(chan, cookie, txstate);
  9938. + if (ret == DMA_SUCCESS || !txstate)
  9939. + return ret;
  9940. +
  9941. + spin_lock_irqsave(&c->vc.lock, flags);
  9942. + vd = vchan_find_desc(&c->vc, cookie);
  9943. + if (vd) {
  9944. + txstate->residue =
  9945. + bcm2708_dma_desc_size(to_bcm2708_dma_desc(&vd->tx));
  9946. + } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
  9947. + struct bcm2708_desc *d = c->desc;
  9948. + dma_addr_t pos;
  9949. +
  9950. + if (d->dir == DMA_MEM_TO_DEV)
  9951. + pos = readl(c->chan_base + BCM2708_DMA_SOURCE_AD);
  9952. + else if (d->dir == DMA_DEV_TO_MEM)
  9953. + pos = readl(c->chan_base + BCM2708_DMA_DEST_AD);
  9954. + else
  9955. + pos = 0;
  9956. +
  9957. + txstate->residue = bcm2708_dma_desc_size_pos(d, pos);
  9958. + } else {
  9959. + txstate->residue = 0;
  9960. + }
  9961. +
  9962. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9963. +
  9964. + return ret;
  9965. +}
  9966. +
  9967. +static void bcm2708_dma_issue_pending(struct dma_chan *chan)
  9968. +{
  9969. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9970. + unsigned long flags;
  9971. +
  9972. + c->cyclic = true; /* Nothing else is implemented */
  9973. +
  9974. + spin_lock_irqsave(&c->vc.lock, flags);
  9975. + if (vchan_issue_pending(&c->vc) && !c->desc)
  9976. + bcm2708_dma_start_desc(c);
  9977. +
  9978. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9979. +}
  9980. +
  9981. +static struct dma_async_tx_descriptor *bcm2708_dma_prep_dma_cyclic(
  9982. + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  9983. + size_t period_len, enum dma_transfer_direction direction,
  9984. + unsigned long flags, void *context)
  9985. +{
  9986. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9987. + enum dma_slave_buswidth dev_width;
  9988. + struct bcm2708_desc *d;
  9989. + dma_addr_t dev_addr;
  9990. + unsigned es, sync_type;
  9991. + unsigned frame;
  9992. +
  9993. + /* Grab configuration */
  9994. + if (direction == DMA_DEV_TO_MEM) {
  9995. + dev_addr = c->cfg.src_addr;
  9996. + dev_width = c->cfg.src_addr_width;
  9997. + sync_type = BCM2708_DMA_S_DREQ;
  9998. + } else if (direction == DMA_MEM_TO_DEV) {
  9999. + dev_addr = c->cfg.dst_addr;
  10000. + dev_width = c->cfg.dst_addr_width;
  10001. + sync_type = BCM2708_DMA_D_DREQ;
  10002. + } else {
  10003. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  10004. + return NULL;
  10005. + }
  10006. +
  10007. + /* Bus width translates to the element size (ES) */
  10008. + switch (dev_width) {
  10009. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  10010. + es = BCM2708_DMA_DATA_TYPE_S32;
  10011. + break;
  10012. + default:
  10013. + return NULL;
  10014. + }
  10015. +
  10016. + /* Now allocate and setup the descriptor. */
  10017. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  10018. + if (!d)
  10019. + return NULL;
  10020. +
  10021. + d->dir = direction;
  10022. + d->frames = buf_len / period_len;
  10023. +
  10024. + /* Allocate memory for control blocks */
  10025. + d->control_block_size = d->frames * sizeof(struct bcm2708_dma_cb);
  10026. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  10027. + d->control_block_size, &d->control_block_base_phys,
  10028. + GFP_NOWAIT);
  10029. +
  10030. + if (!d->control_block_base) {
  10031. + kfree(d);
  10032. + return NULL;
  10033. + }
  10034. +
  10035. + /*
  10036. + * Iterate over all frames, create a control block
  10037. + * for each frame and link them together.
  10038. + */
  10039. + for (frame = 0; frame < d->frames; frame++) {
  10040. + struct bcm2708_dma_cb *control_block =
  10041. + &d->control_block_base[frame];
  10042. +
  10043. + /* Setup adresses */
  10044. + if (d->dir == DMA_DEV_TO_MEM) {
  10045. + control_block->info = BCM2708_DMA_D_INC;
  10046. + control_block->src = dev_addr;
  10047. + control_block->dst = buf_addr + frame * period_len;
  10048. + } else {
  10049. + control_block->info = BCM2708_DMA_S_INC;
  10050. + control_block->src = buf_addr + frame * period_len;
  10051. + control_block->dst = dev_addr;
  10052. + }
  10053. +
  10054. + /* Enable interrupt */
  10055. + control_block->info |= BCM2708_DMA_INT_EN;
  10056. +
  10057. + /* Setup synchronization */
  10058. + if (sync_type != 0)
  10059. + control_block->info |= sync_type;
  10060. +
  10061. + /* Setup DREQ channel */
  10062. + if (c->cfg.slave_id != 0)
  10063. + control_block->info |=
  10064. + BCM2708_DMA_PER_MAP(c->cfg.slave_id);
  10065. +
  10066. + /* Length of a frame */
  10067. + control_block->length = period_len;
  10068. + d->size += control_block->length;
  10069. +
  10070. + /*
  10071. + * Next block is the next frame.
  10072. + * This DMA engine driver currently only supports cyclic DMA.
  10073. + * Therefore, wrap around at number of frames.
  10074. + */
  10075. + control_block->next = d->control_block_base_phys +
  10076. + sizeof(struct bcm2708_dma_cb)
  10077. + * ((frame + 1) % d->frames);
  10078. + }
  10079. +
  10080. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  10081. +}
  10082. +
  10083. +static int bcm2708_dma_slave_config(struct bcm2708_chan *c,
  10084. + struct dma_slave_config *cfg)
  10085. +{
  10086. + if ((cfg->direction == DMA_DEV_TO_MEM &&
  10087. + cfg->src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  10088. + (cfg->direction == DMA_MEM_TO_DEV &&
  10089. + cfg->dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  10090. + !is_slave_direction(cfg->direction)) {
  10091. + return -EINVAL;
  10092. + }
  10093. +
  10094. + c->cfg = *cfg;
  10095. +
  10096. + return 0;
  10097. +}
  10098. +
  10099. +static int bcm2708_dma_terminate_all(struct bcm2708_chan *c)
  10100. +{
  10101. + struct bcm2708_dmadev *d = to_bcm2708_dma_dev(c->vc.chan.device);
  10102. + unsigned long flags;
  10103. + int timeout = 10000;
  10104. + LIST_HEAD(head);
  10105. +
  10106. + spin_lock_irqsave(&c->vc.lock, flags);
  10107. +
  10108. + /* Prevent this channel being scheduled */
  10109. + spin_lock(&d->lock);
  10110. + list_del_init(&c->node);
  10111. + spin_unlock(&d->lock);
  10112. +
  10113. + /*
  10114. + * Stop DMA activity: we assume the callback will not be called
  10115. + * after bcm_dma_abort() returns (even if it does, it will see
  10116. + * c->desc is NULL and exit.)
  10117. + */
  10118. + if (c->desc) {
  10119. + c->desc = NULL;
  10120. + bcm_dma_abort(c->chan_base);
  10121. +
  10122. + /* Wait for stopping */
  10123. + while (timeout > 0) {
  10124. + timeout--;
  10125. + if (!(readl(c->chan_base + BCM2708_DMA_CS) &
  10126. + BCM2708_DMA_ACTIVE))
  10127. + break;
  10128. +
  10129. + cpu_relax();
  10130. + }
  10131. +
  10132. + if (timeout <= 0)
  10133. + dev_err(d->ddev.dev, "DMA transfer could not be terminated\n");
  10134. + }
  10135. +
  10136. + vchan_get_all_descriptors(&c->vc, &head);
  10137. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10138. + vchan_dma_desc_free_list(&c->vc, &head);
  10139. +
  10140. + return 0;
  10141. +}
  10142. +
  10143. +static int bcm2708_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  10144. + unsigned long arg)
  10145. +{
  10146. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10147. +
  10148. + switch (cmd) {
  10149. + case DMA_SLAVE_CONFIG:
  10150. + return bcm2708_dma_slave_config(c,
  10151. + (struct dma_slave_config *)arg);
  10152. +
  10153. + case DMA_TERMINATE_ALL:
  10154. + return bcm2708_dma_terminate_all(c);
  10155. +
  10156. + default:
  10157. + return -ENXIO;
  10158. + }
  10159. +}
  10160. +
  10161. +static int bcm2708_dma_chan_init(struct bcm2708_dmadev *d, void __iomem* chan_base,
  10162. + int chan_id, int irq)
  10163. +{
  10164. + struct bcm2708_chan *c;
  10165. +
  10166. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  10167. + if (!c)
  10168. + return -ENOMEM;
  10169. +
  10170. + c->vc.desc_free = bcm2708_dma_desc_free;
  10171. + vchan_init(&c->vc, &d->ddev);
  10172. + INIT_LIST_HEAD(&c->node);
  10173. +
  10174. + d->ddev.chancnt++;
  10175. +
  10176. + c->chan_base = chan_base;
  10177. + c->ch = chan_id;
  10178. + c->irq_number = irq;
  10179. +
  10180. + return 0;
  10181. +}
  10182. +
  10183. +static void bcm2708_dma_free(struct bcm2708_dmadev *od)
  10184. +{
  10185. + while (!list_empty(&od->ddev.channels)) {
  10186. + struct bcm2708_chan *c = list_first_entry(&od->ddev.channels,
  10187. + struct bcm2708_chan, vc.chan.device_node);
  10188. +
  10189. + list_del(&c->vc.chan.device_node);
  10190. + tasklet_kill(&c->vc.task);
  10191. + }
  10192. +}
  10193. +
  10194. +static int bcm2708_dma_probe(struct platform_device *pdev)
  10195. +{
  10196. + struct bcm2708_dmadev *od;
  10197. + int rc, i;
  10198. +
  10199. + if (!pdev->dev.dma_mask)
  10200. + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  10201. +
  10202. + rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  10203. + if (rc)
  10204. + return rc;
  10205. + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  10206. +
  10207. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  10208. + if (!od)
  10209. + return -ENOMEM;
  10210. +
  10211. + pdev->dev.dma_parms = &od->dma_parms;
  10212. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  10213. +
  10214. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  10215. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  10216. + od->ddev.device_alloc_chan_resources = bcm2708_dma_alloc_chan_resources;
  10217. + od->ddev.device_free_chan_resources = bcm2708_dma_free_chan_resources;
  10218. + od->ddev.device_tx_status = bcm2708_dma_tx_status;
  10219. + od->ddev.device_issue_pending = bcm2708_dma_issue_pending;
  10220. + od->ddev.device_prep_dma_cyclic = bcm2708_dma_prep_dma_cyclic;
  10221. + od->ddev.device_control = bcm2708_dma_control;
  10222. + od->ddev.dev = &pdev->dev;
  10223. + INIT_LIST_HEAD(&od->ddev.channels);
  10224. + spin_lock_init(&od->lock);
  10225. +
  10226. + platform_set_drvdata(pdev, od);
  10227. +
  10228. + for (i = 0; i < 16; i++) {
  10229. + void __iomem* chan_base;
  10230. + int chan_id, irq;
  10231. +
  10232. + chan_id = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  10233. + &chan_base,
  10234. + &irq);
  10235. +
  10236. + if (chan_id < 0)
  10237. + break;
  10238. +
  10239. + rc = bcm2708_dma_chan_init(od, chan_base, chan_id, irq);
  10240. + if (rc) {
  10241. + bcm2708_dma_free(od);
  10242. + return rc;
  10243. + }
  10244. + }
  10245. +
  10246. + rc = dma_async_device_register(&od->ddev);
  10247. + if (rc) {
  10248. + dev_err(&pdev->dev,
  10249. + "Failed to register slave DMA engine device: %d\n", rc);
  10250. + bcm2708_dma_free(od);
  10251. + return rc;
  10252. + }
  10253. +
  10254. + dev_dbg(&pdev->dev, "Load BCM2708 DMA engine driver\n");
  10255. +
  10256. + return rc;
  10257. +}
  10258. +
  10259. +static int bcm2708_dma_remove(struct platform_device *pdev)
  10260. +{
  10261. + struct bcm2708_dmadev *od = platform_get_drvdata(pdev);
  10262. +
  10263. + dma_async_device_unregister(&od->ddev);
  10264. + bcm2708_dma_free(od);
  10265. +
  10266. + return 0;
  10267. +}
  10268. +
  10269. +static struct platform_driver bcm2708_dma_driver = {
  10270. + .probe = bcm2708_dma_probe,
  10271. + .remove = bcm2708_dma_remove,
  10272. + .driver = {
  10273. + .name = "bcm2708-dmaengine",
  10274. + .owner = THIS_MODULE,
  10275. + },
  10276. +};
  10277. +
  10278. +static struct platform_device *pdev;
  10279. +
  10280. +static const struct platform_device_info bcm2708_dma_dev_info = {
  10281. + .name = "bcm2708-dmaengine",
  10282. + .id = -1,
  10283. +};
  10284. +
  10285. +static int bcm2708_dma_init(void)
  10286. +{
  10287. + int rc = platform_driver_register(&bcm2708_dma_driver);
  10288. +
  10289. + if (rc == 0) {
  10290. + pdev = platform_device_register_full(&bcm2708_dma_dev_info);
  10291. + if (IS_ERR(pdev)) {
  10292. + platform_driver_unregister(&bcm2708_dma_driver);
  10293. + rc = PTR_ERR(pdev);
  10294. + }
  10295. + }
  10296. +
  10297. + return rc;
  10298. +}
  10299. +subsys_initcall(bcm2708_dma_init);
  10300. +
  10301. +static void __exit bcm2708_dma_exit(void)
  10302. +{
  10303. + platform_device_unregister(pdev);
  10304. + platform_driver_unregister(&bcm2708_dma_driver);
  10305. +}
  10306. +module_exit(bcm2708_dma_exit);
  10307. +
  10308. +MODULE_ALIAS("platform:bcm2708-dma");
  10309. +MODULE_DESCRIPTION("BCM2708 DMA engine driver");
  10310. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  10311. +MODULE_LICENSE("GPL v2");
  10312. diff -Nur linux-3.12.18/drivers/dma/Kconfig linux-rpi/drivers/dma/Kconfig
  10313. --- linux-3.12.18/drivers/dma/Kconfig 2014-04-18 11:14:28.000000000 +0200
  10314. +++ linux-rpi/drivers/dma/Kconfig 2014-04-24 16:04:34.615073934 +0200
  10315. @@ -288,6 +288,12 @@
  10316. select DMA_ENGINE
  10317. select DMA_VIRTUAL_CHANNELS
  10318. +config DMA_BCM2708
  10319. + tristate "BCM2708 DMA engine support"
  10320. + depends on MACH_BCM2708
  10321. + select DMA_ENGINE
  10322. + select DMA_VIRTUAL_CHANNELS
  10323. +
  10324. config TI_CPPI41
  10325. tristate "AM33xx CPPI41 DMA support"
  10326. depends on ARCH_OMAP
  10327. diff -Nur linux-3.12.18/drivers/dma/Makefile linux-rpi/drivers/dma/Makefile
  10328. --- linux-3.12.18/drivers/dma/Makefile 2014-04-18 11:14:28.000000000 +0200
  10329. +++ linux-rpi/drivers/dma/Makefile 2014-04-24 16:04:34.615073934 +0200
  10330. @@ -37,6 +37,7 @@
  10331. obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o
  10332. obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
  10333. obj-$(CONFIG_DMA_OMAP) += omap-dma.o
  10334. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  10335. obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
  10336. obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
  10337. obj-$(CONFIG_TI_CPPI41) += cppi41.o
  10338. diff -Nur linux-3.12.18/drivers/gpu/drm/cirrus/cirrus_fbdev.c linux-rpi/drivers/gpu/drm/cirrus/cirrus_fbdev.c
  10339. --- linux-3.12.18/drivers/gpu/drm/cirrus/cirrus_fbdev.c 2014-04-18 11:14:28.000000000 +0200
  10340. +++ linux-rpi/drivers/gpu/drm/cirrus/cirrus_fbdev.c 2014-04-24 16:04:34.791075636 +0200
  10341. @@ -233,9 +233,6 @@
  10342. info->apertures->ranges[0].base = cdev->dev->mode_config.fb_base;
  10343. info->apertures->ranges[0].size = cdev->mc.vram_size;
  10344. - info->fix.smem_start = cdev->dev->mode_config.fb_base;
  10345. - info->fix.smem_len = cdev->mc.vram_size;
  10346. -
  10347. info->screen_base = sysram;
  10348. info->screen_size = size;
  10349. diff -Nur linux-3.12.18/drivers/gpu/drm/cirrus/cirrus_mode.c linux-rpi/drivers/gpu/drm/cirrus/cirrus_mode.c
  10350. --- linux-3.12.18/drivers/gpu/drm/cirrus/cirrus_mode.c 2014-04-18 11:14:28.000000000 +0200
  10351. +++ linux-rpi/drivers/gpu/drm/cirrus/cirrus_mode.c 2014-04-24 15:35:02.193543716 +0200
  10352. @@ -494,12 +494,13 @@
  10353. int cirrus_vga_get_modes(struct drm_connector *connector)
  10354. {
  10355. - int count;
  10356. -
  10357. /* Just add a static list of modes */
  10358. - count = drm_add_modes_noedid(connector, 1280, 1024);
  10359. - drm_set_preferred_mode(connector, 1024, 768);
  10360. - return count;
  10361. + drm_add_modes_noedid(connector, 640, 480);
  10362. + drm_add_modes_noedid(connector, 800, 600);
  10363. + drm_add_modes_noedid(connector, 1024, 768);
  10364. + drm_add_modes_noedid(connector, 1280, 1024);
  10365. +
  10366. + return 4;
  10367. }
  10368. static int cirrus_vga_mode_valid(struct drm_connector *connector,
  10369. diff -Nur linux-3.12.18/drivers/gpu/drm/drm_edid.c linux-rpi/drivers/gpu/drm/drm_edid.c
  10370. --- linux-3.12.18/drivers/gpu/drm/drm_edid.c 2014-04-18 11:14:28.000000000 +0200
  10371. +++ linux-rpi/drivers/gpu/drm/drm_edid.c 2014-04-24 16:04:34.795075675 +0200
  10372. @@ -3296,19 +3296,6 @@
  10373. }
  10374. EXPORT_SYMBOL(drm_add_modes_noedid);
  10375. -void drm_set_preferred_mode(struct drm_connector *connector,
  10376. - int hpref, int vpref)
  10377. -{
  10378. - struct drm_display_mode *mode;
  10379. -
  10380. - list_for_each_entry(mode, &connector->probed_modes, head) {
  10381. - if (drm_mode_width(mode) == hpref &&
  10382. - drm_mode_height(mode) == vpref)
  10383. - mode->type |= DRM_MODE_TYPE_PREFERRED;
  10384. - }
  10385. -}
  10386. -EXPORT_SYMBOL(drm_set_preferred_mode);
  10387. -
  10388. /**
  10389. * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
  10390. * data from a DRM display mode
  10391. diff -Nur linux-3.12.18/drivers/gpu/drm/drm_fb_helper.c linux-rpi/drivers/gpu/drm/drm_fb_helper.c
  10392. --- linux-3.12.18/drivers/gpu/drm/drm_fb_helper.c 2014-04-18 11:14:28.000000000 +0200
  10393. +++ linux-rpi/drivers/gpu/drm/drm_fb_helper.c 2014-04-24 16:04:34.795075675 +0200
  10394. @@ -1163,7 +1163,6 @@
  10395. {
  10396. struct drm_cmdline_mode *cmdline_mode;
  10397. struct drm_display_mode *mode = NULL;
  10398. - bool prefer_non_interlace;
  10399. cmdline_mode = &fb_helper_conn->cmdline_mode;
  10400. if (cmdline_mode->specified == false)
  10401. @@ -1175,8 +1174,6 @@
  10402. if (cmdline_mode->rb || cmdline_mode->margins)
  10403. goto create_mode;
  10404. - prefer_non_interlace = !cmdline_mode->interlace;
  10405. - again:
  10406. list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
  10407. /* check width/height */
  10408. if (mode->hdisplay != cmdline_mode->xres ||
  10409. @@ -1191,18 +1188,10 @@
  10410. if (cmdline_mode->interlace) {
  10411. if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
  10412. continue;
  10413. - } else if (prefer_non_interlace) {
  10414. - if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  10415. - continue;
  10416. }
  10417. return mode;
  10418. }
  10419. - if (prefer_non_interlace) {
  10420. - prefer_non_interlace = false;
  10421. - goto again;
  10422. - }
  10423. -
  10424. create_mode:
  10425. mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev,
  10426. cmdline_mode);
  10427. diff -Nur linux-3.12.18/drivers/gpu/drm/i915/intel_display.c linux-rpi/drivers/gpu/drm/i915/intel_display.c
  10428. --- linux-3.12.18/drivers/gpu/drm/i915/intel_display.c 2014-04-18 11:14:28.000000000 +0200
  10429. +++ linux-rpi/drivers/gpu/drm/i915/intel_display.c 2014-04-24 16:04:34.827075985 +0200
  10430. @@ -10073,7 +10073,8 @@
  10431. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  10432. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  10433. - /* 830 needs to leave pipe A & dpll A up */
  10434. + /* 830/845 need to leave pipe A & dpll A up */
  10435. + { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  10436. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  10437. /* Lenovo U160 cannot use SSC on LVDS */
  10438. diff -Nur linux-3.12.18/drivers/gpu/drm/radeon/dce6_afmt.c linux-rpi/drivers/gpu/drm/radeon/dce6_afmt.c
  10439. --- linux-3.12.18/drivers/gpu/drm/radeon/dce6_afmt.c 2014-04-18 11:14:28.000000000 +0200
  10440. +++ linux-rpi/drivers/gpu/drm/radeon/dce6_afmt.c 2014-04-24 16:04:34.959077261 +0200
  10441. @@ -226,15 +226,13 @@
  10442. return !ASIC_IS_NODCE(rdev);
  10443. }
  10444. -void dce6_audio_enable(struct radeon_device *rdev,
  10445. - struct r600_audio_pin *pin,
  10446. - bool enable)
  10447. +static void dce6_audio_enable(struct radeon_device *rdev,
  10448. + struct r600_audio_pin *pin,
  10449. + bool enable)
  10450. {
  10451. - if (!pin)
  10452. - return;
  10453. -
  10454. WREG32_ENDPOINT(pin->offset, AZ_F0_CODEC_PIN_CONTROL_HOTPLUG_CONTROL,
  10455. enable ? AUDIO_ENABLED : 0);
  10456. + DRM_INFO("%s audio %d support\n", enable ? "Enabling" : "Disabling", pin->id);
  10457. }
  10458. static const u32 pin_offsets[7] =
  10459. @@ -271,8 +269,7 @@
  10460. rdev->audio.pin[i].connected = false;
  10461. rdev->audio.pin[i].offset = pin_offsets[i];
  10462. rdev->audio.pin[i].id = i;
  10463. - /* disable audio. it will be set up later */
  10464. - dce6_audio_enable(rdev, &rdev->audio.pin[i], false);
  10465. + dce6_audio_enable(rdev, &rdev->audio.pin[i], true);
  10466. }
  10467. return 0;
  10468. diff -Nur linux-3.12.18/drivers/gpu/drm/radeon/evergreen_hdmi.c linux-rpi/drivers/gpu/drm/radeon/evergreen_hdmi.c
  10469. --- linux-3.12.18/drivers/gpu/drm/radeon/evergreen_hdmi.c 2014-04-18 11:14:28.000000000 +0200
  10470. +++ linux-rpi/drivers/gpu/drm/radeon/evergreen_hdmi.c 2014-04-24 16:04:34.959077261 +0200
  10471. @@ -257,15 +257,6 @@
  10472. return;
  10473. offset = dig->afmt->offset;
  10474. - /* disable audio prior to setting up hw */
  10475. - if (ASIC_IS_DCE6(rdev)) {
  10476. - dig->afmt->pin = dce6_audio_get_pin(rdev);
  10477. - dce6_audio_enable(rdev, dig->afmt->pin, false);
  10478. - } else {
  10479. - dig->afmt->pin = r600_audio_get_pin(rdev);
  10480. - r600_audio_enable(rdev, dig->afmt->pin, false);
  10481. - }
  10482. -
  10483. evergreen_audio_set_dto(encoder, mode->clock);
  10484. WREG32(HDMI_VBI_PACKET_CONTROL + offset,
  10485. @@ -367,16 +358,12 @@
  10486. WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
  10487. WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001);
  10488. WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001);
  10489. -
  10490. - /* enable audio after to setting up hw */
  10491. - if (ASIC_IS_DCE6(rdev))
  10492. - dce6_audio_enable(rdev, dig->afmt->pin, true);
  10493. - else
  10494. - r600_audio_enable(rdev, dig->afmt->pin, true);
  10495. }
  10496. void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable)
  10497. {
  10498. + struct drm_device *dev = encoder->dev;
  10499. + struct radeon_device *rdev = dev->dev_private;
  10500. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  10501. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  10502. @@ -389,6 +376,15 @@
  10503. if (!enable && !dig->afmt->enabled)
  10504. return;
  10505. + if (enable) {
  10506. + if (ASIC_IS_DCE6(rdev))
  10507. + dig->afmt->pin = dce6_audio_get_pin(rdev);
  10508. + else
  10509. + dig->afmt->pin = r600_audio_get_pin(rdev);
  10510. + } else {
  10511. + dig->afmt->pin = NULL;
  10512. + }
  10513. +
  10514. dig->afmt->enabled = enable;
  10515. DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n",
  10516. diff -Nur linux-3.12.18/drivers/gpu/drm/radeon/r600_audio.c linux-rpi/drivers/gpu/drm/radeon/r600_audio.c
  10517. --- linux-3.12.18/drivers/gpu/drm/radeon/r600_audio.c 2014-04-18 11:14:28.000000000 +0200
  10518. +++ linux-rpi/drivers/gpu/drm/radeon/r600_audio.c 2014-04-24 16:04:34.967077338 +0200
  10519. @@ -142,15 +142,12 @@
  10520. }
  10521. /* enable the audio stream */
  10522. -void r600_audio_enable(struct radeon_device *rdev,
  10523. - struct r600_audio_pin *pin,
  10524. - bool enable)
  10525. +static void r600_audio_enable(struct radeon_device *rdev,
  10526. + struct r600_audio_pin *pin,
  10527. + bool enable)
  10528. {
  10529. u32 value = 0;
  10530. - if (!pin)
  10531. - return;
  10532. -
  10533. if (ASIC_IS_DCE4(rdev)) {
  10534. if (enable) {
  10535. value |= 0x81000000; /* Required to enable audio */
  10536. @@ -161,6 +158,7 @@
  10537. WREG32_P(R600_AUDIO_ENABLE,
  10538. enable ? 0x81000000 : 0x0, ~0x81000000);
  10539. }
  10540. + DRM_INFO("%s audio %d support\n", enable ? "Enabling" : "Disabling", pin->id);
  10541. }
  10542. /*
  10543. @@ -180,8 +178,8 @@
  10544. rdev->audio.pin[0].status_bits = 0;
  10545. rdev->audio.pin[0].category_code = 0;
  10546. rdev->audio.pin[0].id = 0;
  10547. - /* disable audio. it will be set up later */
  10548. - r600_audio_enable(rdev, &rdev->audio.pin[0], false);
  10549. +
  10550. + r600_audio_enable(rdev, &rdev->audio.pin[0], true);
  10551. return 0;
  10552. }
  10553. diff -Nur linux-3.12.18/drivers/gpu/drm/radeon/r600_hdmi.c linux-rpi/drivers/gpu/drm/radeon/r600_hdmi.c
  10554. --- linux-3.12.18/drivers/gpu/drm/radeon/r600_hdmi.c 2014-04-18 11:14:28.000000000 +0200
  10555. +++ linux-rpi/drivers/gpu/drm/radeon/r600_hdmi.c 2014-04-24 16:04:34.967077338 +0200
  10556. @@ -329,6 +329,9 @@
  10557. u8 *sadb;
  10558. int sad_count;
  10559. + /* XXX: setting this register causes hangs on some asics */
  10560. + return;
  10561. +
  10562. list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
  10563. if (connector->encoder == encoder)
  10564. radeon_connector = to_radeon_connector(connector);
  10565. @@ -443,10 +446,6 @@
  10566. return;
  10567. offset = dig->afmt->offset;
  10568. - /* disable audio prior to setting up hw */
  10569. - dig->afmt->pin = r600_audio_get_pin(rdev);
  10570. - r600_audio_enable(rdev, dig->afmt->pin, false);
  10571. -
  10572. r600_audio_set_dto(encoder, mode->clock);
  10573. WREG32(HDMI0_VBI_PACKET_CONTROL + offset,
  10574. @@ -518,9 +517,6 @@
  10575. WREG32(HDMI0_RAMP_CONTROL3 + offset, 0x00000001);
  10576. r600_hdmi_audio_workaround(encoder);
  10577. -
  10578. - /* enable audio after to setting up hw */
  10579. - r600_audio_enable(rdev, dig->afmt->pin, true);
  10580. }
  10581. /*
  10582. @@ -641,6 +637,11 @@
  10583. if (!enable && !dig->afmt->enabled)
  10584. return;
  10585. + if (enable)
  10586. + dig->afmt->pin = r600_audio_get_pin(rdev);
  10587. + else
  10588. + dig->afmt->pin = NULL;
  10589. +
  10590. /* Older chipsets require setting HDMI and routing manually */
  10591. if (!ASIC_IS_DCE3(rdev)) {
  10592. if (enable)
  10593. diff -Nur linux-3.12.18/drivers/gpu/drm/radeon/radeon.h linux-rpi/drivers/gpu/drm/radeon/radeon.h
  10594. --- linux-3.12.18/drivers/gpu/drm/radeon/radeon.h 2014-04-18 11:14:28.000000000 +0200
  10595. +++ linux-rpi/drivers/gpu/drm/radeon/radeon.h 2014-04-24 16:04:34.971077377 +0200
  10596. @@ -2717,12 +2717,6 @@
  10597. void r600_audio_update_hdmi(struct work_struct *work);
  10598. struct r600_audio_pin *r600_audio_get_pin(struct radeon_device *rdev);
  10599. struct r600_audio_pin *dce6_audio_get_pin(struct radeon_device *rdev);
  10600. -void r600_audio_enable(struct radeon_device *rdev,
  10601. - struct r600_audio_pin *pin,
  10602. - bool enable);
  10603. -void dce6_audio_enable(struct radeon_device *rdev,
  10604. - struct r600_audio_pin *pin,
  10605. - bool enable);
  10606. /*
  10607. * R600 vram scratch functions
  10608. diff -Nur linux-3.12.18/drivers/hwmon/bcm2835-hwmon.c linux-rpi/drivers/hwmon/bcm2835-hwmon.c
  10609. --- linux-3.12.18/drivers/hwmon/bcm2835-hwmon.c 1970-01-01 01:00:00.000000000 +0100
  10610. +++ linux-rpi/drivers/hwmon/bcm2835-hwmon.c 2014-04-24 15:35:02.349545454 +0200
  10611. @@ -0,0 +1,219 @@
  10612. +/*****************************************************************************
  10613. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10614. +*
  10615. +* Unless you and Broadcom execute a separate written software license
  10616. +* agreement governing use of this software, this software is licensed to you
  10617. +* under the terms of the GNU General Public License version 2, available at
  10618. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10619. +*
  10620. +* Notwithstanding the above, under no circumstances may you combine this
  10621. +* software in any way with any other Broadcom software provided under a
  10622. +* license other than the GPL, without Broadcom's express prior written
  10623. +* consent.
  10624. +*****************************************************************************/
  10625. +
  10626. +#include <linux/kernel.h>
  10627. +#include <linux/module.h>
  10628. +#include <linux/init.h>
  10629. +#include <linux/hwmon.h>
  10630. +#include <linux/hwmon-sysfs.h>
  10631. +#include <linux/platform_device.h>
  10632. +#include <linux/sysfs.h>
  10633. +#include <mach/vcio.h>
  10634. +#include <linux/slab.h>
  10635. +#include <linux/err.h>
  10636. +
  10637. +#define MODULE_NAME "bcm2835_hwmon"
  10638. +
  10639. +/*#define HWMON_DEBUG_ENABLE*/
  10640. +
  10641. +#ifdef HWMON_DEBUG_ENABLE
  10642. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  10643. +#else
  10644. +#define print_debug(fmt,...)
  10645. +#endif
  10646. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  10647. +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
  10648. +
  10649. +#define VC_TAG_GET_TEMP 0x00030006
  10650. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  10651. +
  10652. +/* --- STRUCTS --- */
  10653. +struct bcm2835_hwmon_data {
  10654. + struct device *hwmon_dev;
  10655. +};
  10656. +
  10657. +/* tag part of the message */
  10658. +struct vc_msg_tag {
  10659. + uint32_t tag_id; /* the tag ID for the temperature */
  10660. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  10661. + uint32_t request_code; /* identifies message as a request (should be 0) */
  10662. + uint32_t id; /* extra ID field (should be 0) */
  10663. + uint32_t val; /* returned value of the temperature */
  10664. +};
  10665. +
  10666. +/* message structure to be sent to videocore */
  10667. +struct vc_msg {
  10668. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  10669. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  10670. + struct vc_msg_tag tag; /* the tag structure above to make */
  10671. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  10672. +};
  10673. +
  10674. +typedef enum {
  10675. + TEMP,
  10676. + MAX_TEMP,
  10677. +} temp_type;
  10678. +
  10679. +/* --- PROTOTYPES --- */
  10680. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
  10681. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
  10682. +
  10683. +/* --- GLOBALS --- */
  10684. +
  10685. +static struct bcm2835_hwmon_data *bcm2835_data;
  10686. +static struct platform_driver bcm2835_hwmon_driver;
  10687. +
  10688. +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
  10689. +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
  10690. +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
  10691. +
  10692. +static struct attribute* bcm2835_attributes[] = {
  10693. + &sensor_dev_attr_name.dev_attr.attr,
  10694. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  10695. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  10696. + NULL,
  10697. +};
  10698. +
  10699. +static struct attribute_group bcm2835_attr_group = {
  10700. + .attrs = bcm2835_attributes,
  10701. +};
  10702. +
  10703. +/* --- FUNCTIONS --- */
  10704. +
  10705. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
  10706. +{
  10707. + return sprintf(buf,"bcm2835_hwmon\n");
  10708. +}
  10709. +
  10710. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
  10711. +{
  10712. + struct vc_msg msg;
  10713. + int result;
  10714. + uint temp = 0;
  10715. + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
  10716. +
  10717. + print_debug("IN");
  10718. +
  10719. + /* wipe all previous message data */
  10720. + memset(&msg, 0, sizeof msg);
  10721. +
  10722. + /* determine the message type */
  10723. + if(index == TEMP)
  10724. + msg.tag.tag_id = VC_TAG_GET_TEMP;
  10725. + else if (index == MAX_TEMP)
  10726. + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
  10727. + else
  10728. + {
  10729. + print_debug("Unknown temperature message!");
  10730. + return -EINVAL;
  10731. + }
  10732. +
  10733. + msg.msg_size = sizeof msg;
  10734. + msg.tag.buffer_size = 8;
  10735. +
  10736. + /* send the message */
  10737. + result = bcm_mailbox_property(&msg, sizeof msg);
  10738. +
  10739. + /* check if it was all ok and return the rate in milli degrees C */
  10740. + if (result == 0 && (msg.request_code & 0x80000000))
  10741. + temp = (uint)msg.tag.val;
  10742. + #ifdef HWMON_DEBUG_ENABLE
  10743. + else
  10744. + print_debug("Failed to get temperature!");
  10745. + #endif
  10746. + print_debug("Got temperature as %u",temp);
  10747. + print_debug("OUT");
  10748. + return sprintf(buf, "%u\n", temp);
  10749. +}
  10750. +
  10751. +
  10752. +static int bcm2835_hwmon_probe(struct platform_device *pdev)
  10753. +{
  10754. + int err;
  10755. +
  10756. + print_debug("IN");
  10757. + print_debug("HWMON Driver has been probed!");
  10758. +
  10759. + /* check that the device isn't null!*/
  10760. + if(pdev == NULL)
  10761. + {
  10762. + print_debug("Platform device is empty!");
  10763. + return -ENODEV;
  10764. + }
  10765. +
  10766. + /* allocate memory for neccessary data */
  10767. + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
  10768. + if(!bcm2835_data)
  10769. + {
  10770. + print_debug("Unable to allocate memory for hwmon data!");
  10771. + err = -ENOMEM;
  10772. + goto kzalloc_error;
  10773. + }
  10774. +
  10775. + /* create the sysfs files */
  10776. + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
  10777. + {
  10778. + print_debug("Unable to create sysfs files!");
  10779. + err = -EFAULT;
  10780. + goto sysfs_error;
  10781. + }
  10782. +
  10783. + /* register the hwmon device */
  10784. + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
  10785. + if (IS_ERR(bcm2835_data->hwmon_dev))
  10786. + {
  10787. + err = PTR_ERR(bcm2835_data->hwmon_dev);
  10788. + goto hwmon_error;
  10789. + }
  10790. + print_debug("OUT");
  10791. + return 0;
  10792. +
  10793. + /* error goto's */
  10794. + hwmon_error:
  10795. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  10796. +
  10797. + sysfs_error:
  10798. + kfree(bcm2835_data);
  10799. +
  10800. + kzalloc_error:
  10801. +
  10802. + return err;
  10803. +
  10804. +}
  10805. +
  10806. +static int bcm2835_hwmon_remove(struct platform_device *pdev)
  10807. +{
  10808. + print_debug("IN");
  10809. + hwmon_device_unregister(bcm2835_data->hwmon_dev);
  10810. +
  10811. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  10812. + print_debug("OUT");
  10813. + return 0;
  10814. +}
  10815. +
  10816. +/* Hwmon Driver */
  10817. +static struct platform_driver bcm2835_hwmon_driver = {
  10818. + .probe = bcm2835_hwmon_probe,
  10819. + .remove = bcm2835_hwmon_remove,
  10820. + .driver = {
  10821. + .name = "bcm2835_hwmon",
  10822. + .owner = THIS_MODULE,
  10823. + },
  10824. +};
  10825. +
  10826. +MODULE_LICENSE("GPL");
  10827. +MODULE_AUTHOR("Dorian Peake");
  10828. +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
  10829. +
  10830. +module_platform_driver(bcm2835_hwmon_driver);
  10831. diff -Nur linux-3.12.18/drivers/hwmon/Kconfig linux-rpi/drivers/hwmon/Kconfig
  10832. --- linux-3.12.18/drivers/hwmon/Kconfig 2014-04-18 11:14:28.000000000 +0200
  10833. +++ linux-rpi/drivers/hwmon/Kconfig 2014-04-24 16:04:35.299080549 +0200
  10834. @@ -1553,6 +1553,16 @@
  10835. help
  10836. Support for the A/D converter on MC13783 and MC13892 PMIC.
  10837. +config SENSORS_BCM2835
  10838. + depends on THERMAL_BCM2835=n
  10839. + tristate "Broadcom BCM2835 HWMON Driver"
  10840. + help
  10841. + If you say yes here you get support for the hardware
  10842. + monitoring features of the BCM2835 Chip
  10843. +
  10844. + This driver can also be built as a module. If so, the module
  10845. + will be called bcm2835-hwmon.
  10846. +
  10847. if ACPI
  10848. comment "ACPI drivers"
  10849. diff -Nur linux-3.12.18/drivers/hwmon/Makefile linux-rpi/drivers/hwmon/Makefile
  10850. --- linux-3.12.18/drivers/hwmon/Makefile 2014-04-18 11:14:28.000000000 +0200
  10851. +++ linux-rpi/drivers/hwmon/Makefile 2014-04-24 16:04:35.299080549 +0200
  10852. @@ -142,6 +142,7 @@
  10853. obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
  10854. obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
  10855. obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
  10856. +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
  10857. obj-$(CONFIG_PMBUS) += pmbus/
  10858. diff -Nur linux-3.12.18/drivers/i2c/busses/i2c-bcm2708.c linux-rpi/drivers/i2c/busses/i2c-bcm2708.c
  10859. --- linux-3.12.18/drivers/i2c/busses/i2c-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  10860. +++ linux-rpi/drivers/i2c/busses/i2c-bcm2708.c 2014-04-24 16:04:35.311080666 +0200
  10861. @@ -0,0 +1,408 @@
  10862. +/*
  10863. + * Driver for Broadcom BCM2708 BSC Controllers
  10864. + *
  10865. + * Copyright (C) 2012 Chris Boot & Frank Buss
  10866. + *
  10867. + * This driver is inspired by:
  10868. + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
  10869. + *
  10870. + * This program is free software; you can redistribute it and/or modify
  10871. + * it under the terms of the GNU General Public License as published by
  10872. + * the Free Software Foundation; either version 2 of the License, or
  10873. + * (at your option) any later version.
  10874. + *
  10875. + * This program is distributed in the hope that it will be useful,
  10876. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10877. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10878. + * GNU General Public License for more details.
  10879. + *
  10880. + * You should have received a copy of the GNU General Public License
  10881. + * along with this program; if not, write to the Free Software
  10882. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  10883. + */
  10884. +
  10885. +#include <linux/kernel.h>
  10886. +#include <linux/module.h>
  10887. +#include <linux/spinlock.h>
  10888. +#include <linux/clk.h>
  10889. +#include <linux/err.h>
  10890. +#include <linux/platform_device.h>
  10891. +#include <linux/io.h>
  10892. +#include <linux/slab.h>
  10893. +#include <linux/i2c.h>
  10894. +#include <linux/interrupt.h>
  10895. +#include <linux/sched.h>
  10896. +#include <linux/wait.h>
  10897. +
  10898. +/* BSC register offsets */
  10899. +#define BSC_C 0x00
  10900. +#define BSC_S 0x04
  10901. +#define BSC_DLEN 0x08
  10902. +#define BSC_A 0x0c
  10903. +#define BSC_FIFO 0x10
  10904. +#define BSC_DIV 0x14
  10905. +#define BSC_DEL 0x18
  10906. +#define BSC_CLKT 0x1c
  10907. +
  10908. +/* Bitfields in BSC_C */
  10909. +#define BSC_C_I2CEN 0x00008000
  10910. +#define BSC_C_INTR 0x00000400
  10911. +#define BSC_C_INTT 0x00000200
  10912. +#define BSC_C_INTD 0x00000100
  10913. +#define BSC_C_ST 0x00000080
  10914. +#define BSC_C_CLEAR_1 0x00000020
  10915. +#define BSC_C_CLEAR_2 0x00000010
  10916. +#define BSC_C_READ 0x00000001
  10917. +
  10918. +/* Bitfields in BSC_S */
  10919. +#define BSC_S_CLKT 0x00000200
  10920. +#define BSC_S_ERR 0x00000100
  10921. +#define BSC_S_RXF 0x00000080
  10922. +#define BSC_S_TXE 0x00000040
  10923. +#define BSC_S_RXD 0x00000020
  10924. +#define BSC_S_TXD 0x00000010
  10925. +#define BSC_S_RXR 0x00000008
  10926. +#define BSC_S_TXW 0x00000004
  10927. +#define BSC_S_DONE 0x00000002
  10928. +#define BSC_S_TA 0x00000001
  10929. +
  10930. +#define I2C_TIMEOUT_MS 150
  10931. +
  10932. +#define DRV_NAME "bcm2708_i2c"
  10933. +
  10934. +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  10935. +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  10936. +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  10937. +
  10938. +
  10939. +struct bcm2708_i2c {
  10940. + struct i2c_adapter adapter;
  10941. +
  10942. + spinlock_t lock;
  10943. + void __iomem *base;
  10944. + int irq;
  10945. + struct clk *clk;
  10946. +
  10947. + struct completion done;
  10948. +
  10949. + struct i2c_msg *msg;
  10950. + int pos;
  10951. + int nmsgs;
  10952. + bool error;
  10953. +};
  10954. +
  10955. +/*
  10956. + * This function sets the ALT mode on the I2C pins so that we can use them with
  10957. + * the BSC hardware.
  10958. + *
  10959. + * FIXME: This is a hack. Use pinmux / pinctrl.
  10960. + */
  10961. +static void bcm2708_i2c_init_pinmode(int id)
  10962. +{
  10963. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  10964. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  10965. +
  10966. + int pin;
  10967. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  10968. +
  10969. + BUG_ON(id != 0 && id != 1);
  10970. + /* BSC0 is on GPIO 0 & 1, BSC1 is on GPIO 2 & 3 */
  10971. + for (pin = id*2+0; pin <= id*2+1; pin++) {
  10972. +printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  10973. + INP_GPIO(pin); /* set mode to GPIO input first */
  10974. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  10975. + }
  10976. +
  10977. + iounmap(gpio);
  10978. +
  10979. +#undef INP_GPIO
  10980. +#undef SET_GPIO_ALT
  10981. +}
  10982. +
  10983. +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
  10984. +{
  10985. + return readl(bi->base + reg);
  10986. +}
  10987. +
  10988. +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
  10989. +{
  10990. + writel(val, bi->base + reg);
  10991. +}
  10992. +
  10993. +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
  10994. +{
  10995. + bcm2708_wr(bi, BSC_C, 0);
  10996. + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
  10997. +}
  10998. +
  10999. +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  11000. +{
  11001. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  11002. + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  11003. +}
  11004. +
  11005. +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  11006. +{
  11007. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  11008. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  11009. +}
  11010. +
  11011. +static inline void bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  11012. +{
  11013. + unsigned long bus_hz;
  11014. + u32 cdiv;
  11015. + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  11016. +
  11017. + bus_hz = clk_get_rate(bi->clk);
  11018. + cdiv = bus_hz / baudrate;
  11019. +
  11020. + if (bi->msg->flags & I2C_M_RD)
  11021. + c |= BSC_C_INTR | BSC_C_READ;
  11022. + else
  11023. + c |= BSC_C_INTT;
  11024. +
  11025. + bcm2708_wr(bi, BSC_DIV, cdiv);
  11026. + bcm2708_wr(bi, BSC_A, bi->msg->addr);
  11027. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  11028. + bcm2708_wr(bi, BSC_C, c);
  11029. +}
  11030. +
  11031. +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
  11032. +{
  11033. + struct bcm2708_i2c *bi = dev_id;
  11034. + bool handled = true;
  11035. + u32 s;
  11036. +
  11037. + spin_lock(&bi->lock);
  11038. +
  11039. + /* we may see camera interrupts on the "other" I2C channel
  11040. + Just return if we've not sent anything */
  11041. + if (!bi->nmsgs || !bi->msg )
  11042. + goto early_exit;
  11043. +
  11044. + s = bcm2708_rd(bi, BSC_S);
  11045. +
  11046. + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
  11047. + bcm2708_bsc_reset(bi);
  11048. + bi->error = true;
  11049. +
  11050. + /* wake up our bh */
  11051. + complete(&bi->done);
  11052. + } else if (s & BSC_S_DONE) {
  11053. + bi->nmsgs--;
  11054. +
  11055. + if (bi->msg->flags & I2C_M_RD)
  11056. + bcm2708_bsc_fifo_drain(bi);
  11057. +
  11058. + bcm2708_bsc_reset(bi);
  11059. +
  11060. + if (bi->nmsgs) {
  11061. + /* advance to next message */
  11062. + bi->msg++;
  11063. + bi->pos = 0;
  11064. + bcm2708_bsc_setup(bi);
  11065. + } else {
  11066. + /* wake up our bh */
  11067. + complete(&bi->done);
  11068. + }
  11069. + } else if (s & BSC_S_TXW) {
  11070. + bcm2708_bsc_fifo_fill(bi);
  11071. + } else if (s & BSC_S_RXR) {
  11072. + bcm2708_bsc_fifo_drain(bi);
  11073. + } else {
  11074. + handled = false;
  11075. + }
  11076. +
  11077. +early_exit:
  11078. + spin_unlock(&bi->lock);
  11079. +
  11080. + return handled ? IRQ_HANDLED : IRQ_NONE;
  11081. +}
  11082. +
  11083. +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
  11084. + struct i2c_msg *msgs, int num)
  11085. +{
  11086. + struct bcm2708_i2c *bi = adap->algo_data;
  11087. + unsigned long flags;
  11088. + int ret;
  11089. +
  11090. + spin_lock_irqsave(&bi->lock, flags);
  11091. +
  11092. + INIT_COMPLETION(bi->done);
  11093. + bi->msg = msgs;
  11094. + bi->pos = 0;
  11095. + bi->nmsgs = num;
  11096. + bi->error = false;
  11097. +
  11098. + spin_unlock_irqrestore(&bi->lock, flags);
  11099. +
  11100. + bcm2708_bsc_setup(bi);
  11101. +
  11102. + ret = wait_for_completion_timeout(&bi->done,
  11103. + msecs_to_jiffies(I2C_TIMEOUT_MS));
  11104. + if (ret == 0) {
  11105. + dev_err(&adap->dev, "transfer timed out\n");
  11106. + spin_lock_irqsave(&bi->lock, flags);
  11107. + bcm2708_bsc_reset(bi);
  11108. + spin_unlock_irqrestore(&bi->lock, flags);
  11109. + return -ETIMEDOUT;
  11110. + }
  11111. +
  11112. + return bi->error ? -EIO : num;
  11113. +}
  11114. +
  11115. +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
  11116. +{
  11117. + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
  11118. +}
  11119. +
  11120. +static struct i2c_algorithm bcm2708_i2c_algorithm = {
  11121. + .master_xfer = bcm2708_i2c_master_xfer,
  11122. + .functionality = bcm2708_i2c_functionality,
  11123. +};
  11124. +
  11125. +static int bcm2708_i2c_probe(struct platform_device *pdev)
  11126. +{
  11127. + struct resource *regs;
  11128. + int irq, err = -ENOMEM;
  11129. + struct clk *clk;
  11130. + struct bcm2708_i2c *bi;
  11131. + struct i2c_adapter *adap;
  11132. +
  11133. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  11134. + if (!regs) {
  11135. + dev_err(&pdev->dev, "could not get IO memory\n");
  11136. + return -ENXIO;
  11137. + }
  11138. +
  11139. + irq = platform_get_irq(pdev, 0);
  11140. + if (irq < 0) {
  11141. + dev_err(&pdev->dev, "could not get IRQ\n");
  11142. + return irq;
  11143. + }
  11144. +
  11145. + clk = clk_get(&pdev->dev, NULL);
  11146. + if (IS_ERR(clk)) {
  11147. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  11148. + return PTR_ERR(clk);
  11149. + }
  11150. +
  11151. + bcm2708_i2c_init_pinmode(pdev->id);
  11152. +
  11153. + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
  11154. + if (!bi)
  11155. + goto out_clk_put;
  11156. +
  11157. + platform_set_drvdata(pdev, bi);
  11158. +
  11159. + adap = &bi->adapter;
  11160. + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
  11161. + adap->algo = &bcm2708_i2c_algorithm;
  11162. + adap->algo_data = bi;
  11163. + adap->dev.parent = &pdev->dev;
  11164. + adap->nr = pdev->id;
  11165. + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  11166. +
  11167. + switch (pdev->id) {
  11168. + case 0:
  11169. + adap->class = I2C_CLASS_HWMON;
  11170. + break;
  11171. + case 1:
  11172. + adap->class = I2C_CLASS_DDC;
  11173. + break;
  11174. + default:
  11175. + dev_err(&pdev->dev, "can only bind to BSC 0 or 1\n");
  11176. + err = -ENXIO;
  11177. + goto out_free_bi;
  11178. + }
  11179. +
  11180. + spin_lock_init(&bi->lock);
  11181. + init_completion(&bi->done);
  11182. +
  11183. + bi->base = ioremap(regs->start, resource_size(regs));
  11184. + if (!bi->base) {
  11185. + dev_err(&pdev->dev, "could not remap memory\n");
  11186. + goto out_free_bi;
  11187. + }
  11188. +
  11189. + bi->irq = irq;
  11190. + bi->clk = clk;
  11191. +
  11192. + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
  11193. + dev_name(&pdev->dev), bi);
  11194. + if (err) {
  11195. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  11196. + goto out_iounmap;
  11197. + }
  11198. +
  11199. + bcm2708_bsc_reset(bi);
  11200. +
  11201. + err = i2c_add_numbered_adapter(adap);
  11202. + if (err < 0) {
  11203. + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
  11204. + goto out_free_irq;
  11205. + }
  11206. +
  11207. + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %dk)\n",
  11208. + pdev->id, (unsigned long)regs->start, irq, baudrate/1000);
  11209. +
  11210. + return 0;
  11211. +
  11212. +out_free_irq:
  11213. + free_irq(bi->irq, bi);
  11214. +out_iounmap:
  11215. + iounmap(bi->base);
  11216. +out_free_bi:
  11217. + kfree(bi);
  11218. +out_clk_put:
  11219. + clk_put(clk);
  11220. + return err;
  11221. +}
  11222. +
  11223. +static int bcm2708_i2c_remove(struct platform_device *pdev)
  11224. +{
  11225. + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
  11226. +
  11227. + platform_set_drvdata(pdev, NULL);
  11228. +
  11229. + i2c_del_adapter(&bi->adapter);
  11230. + free_irq(bi->irq, bi);
  11231. + iounmap(bi->base);
  11232. + clk_disable(bi->clk);
  11233. + clk_put(bi->clk);
  11234. + kfree(bi);
  11235. +
  11236. + return 0;
  11237. +}
  11238. +
  11239. +static struct platform_driver bcm2708_i2c_driver = {
  11240. + .driver = {
  11241. + .name = DRV_NAME,
  11242. + .owner = THIS_MODULE,
  11243. + },
  11244. + .probe = bcm2708_i2c_probe,
  11245. + .remove = bcm2708_i2c_remove,
  11246. +};
  11247. +
  11248. +// module_platform_driver(bcm2708_i2c_driver);
  11249. +
  11250. +
  11251. +static int __init bcm2708_i2c_init(void)
  11252. +{
  11253. + return platform_driver_register(&bcm2708_i2c_driver);
  11254. +}
  11255. +
  11256. +static void __exit bcm2708_i2c_exit(void)
  11257. +{
  11258. + platform_driver_unregister(&bcm2708_i2c_driver);
  11259. +}
  11260. +
  11261. +module_init(bcm2708_i2c_init);
  11262. +module_exit(bcm2708_i2c_exit);
  11263. +
  11264. +
  11265. +
  11266. +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
  11267. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  11268. +MODULE_LICENSE("GPL v2");
  11269. +MODULE_ALIAS("platform:" DRV_NAME);
  11270. diff -Nur linux-3.12.18/drivers/i2c/busses/Kconfig linux-rpi/drivers/i2c/busses/Kconfig
  11271. --- linux-3.12.18/drivers/i2c/busses/Kconfig 2014-04-18 11:14:28.000000000 +0200
  11272. +++ linux-rpi/drivers/i2c/busses/Kconfig 2014-04-24 16:04:35.311080666 +0200
  11273. @@ -347,6 +347,25 @@
  11274. This support is also available as a module. If so, the module
  11275. will be called i2c-bcm2835.
  11276. +config I2C_BCM2708
  11277. + tristate "BCM2708 BSC"
  11278. + depends on MACH_BCM2708
  11279. + help
  11280. + Enabling this option will add BSC (Broadcom Serial Controller)
  11281. + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
  11282. + with I2C/TWI/SMBus.
  11283. +
  11284. +config I2C_BCM2708_BAUDRATE
  11285. + prompt "BCM2708 I2C baudrate"
  11286. + depends on I2C_BCM2708
  11287. + int
  11288. + default 100000
  11289. + help
  11290. + Set the I2C baudrate. This will alter the default value. A
  11291. + different baudrate can be set by using a module parameter as well. If
  11292. + no parameter is provided when loading, this is the value that will be
  11293. + used.
  11294. +
  11295. config I2C_BLACKFIN_TWI
  11296. tristate "Blackfin TWI I2C support"
  11297. depends on BLACKFIN
  11298. diff -Nur linux-3.12.18/drivers/i2c/busses/Makefile linux-rpi/drivers/i2c/busses/Makefile
  11299. --- linux-3.12.18/drivers/i2c/busses/Makefile 2014-04-18 11:14:28.000000000 +0200
  11300. +++ linux-rpi/drivers/i2c/busses/Makefile 2014-04-24 16:04:35.311080666 +0200
  11301. @@ -32,6 +32,7 @@
  11302. obj-$(CONFIG_I2C_AT91) += i2c-at91.o
  11303. obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  11304. obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
  11305. +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
  11306. obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
  11307. obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
  11308. obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
  11309. diff -Nur linux-3.12.18/drivers/isdn/isdnloop/isdnloop.c linux-rpi/drivers/isdn/isdnloop/isdnloop.c
  11310. --- linux-3.12.18/drivers/isdn/isdnloop/isdnloop.c 2014-04-18 11:14:28.000000000 +0200
  11311. +++ linux-rpi/drivers/isdn/isdnloop/isdnloop.c 2014-04-24 16:04:36.039087706 +0200
  11312. @@ -518,9 +518,9 @@
  11313. static void
  11314. isdnloop_fake_err(isdnloop_card *card)
  11315. {
  11316. - char buf[64];
  11317. + char buf[60];
  11318. - snprintf(buf, sizeof(buf), "E%s", card->omsg);
  11319. + sprintf(buf, "E%s", card->omsg);
  11320. isdnloop_fake(card, buf, -1);
  11321. isdnloop_fake(card, "NAK", -1);
  11322. }
  11323. @@ -903,8 +903,6 @@
  11324. case 7:
  11325. /* 0x;EAZ */
  11326. p += 3;
  11327. - if (strlen(p) >= sizeof(card->eazlist[0]))
  11328. - break;
  11329. strcpy(card->eazlist[ch - 1], p);
  11330. break;
  11331. case 8:
  11332. @@ -1072,12 +1070,6 @@
  11333. return -EBUSY;
  11334. if (copy_from_user((char *) &sdef, (char *) sdefp, sizeof(sdef)))
  11335. return -EFAULT;
  11336. -
  11337. - for (i = 0; i < 3; i++) {
  11338. - if (!memchr(sdef.num[i], 0, sizeof(sdef.num[i])))
  11339. - return -EINVAL;
  11340. - }
  11341. -
  11342. spin_lock_irqsave(&card->isdnloop_lock, flags);
  11343. switch (sdef.ptype) {
  11344. case ISDN_PTYPE_EURO:
  11345. @@ -1135,7 +1127,7 @@
  11346. {
  11347. ulong a;
  11348. int i;
  11349. - char cbuf[80];
  11350. + char cbuf[60];
  11351. isdn_ctrl cmd;
  11352. isdnloop_cdef cdef;
  11353. @@ -1200,6 +1192,7 @@
  11354. break;
  11355. if ((c->arg & 255) < ISDNLOOP_BCH) {
  11356. char *p;
  11357. + char dial[50];
  11358. char dcode[4];
  11359. a = c->arg;
  11360. @@ -1211,10 +1204,10 @@
  11361. } else
  11362. /* Normal Dial */
  11363. strcpy(dcode, "CAL");
  11364. - snprintf(cbuf, sizeof(cbuf),
  11365. - "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
  11366. - dcode, p, c->parm.setup.si1,
  11367. - c->parm.setup.si2, c->parm.setup.eazmsn);
  11368. + strcpy(dial, p);
  11369. + sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
  11370. + dcode, dial, c->parm.setup.si1,
  11371. + c->parm.setup.si2, c->parm.setup.eazmsn);
  11372. i = isdnloop_writecmd(cbuf, strlen(cbuf), 0, card);
  11373. }
  11374. break;
  11375. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/bcm2835-camera.c linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c
  11376. --- linux-3.12.18/drivers/media/platform/bcm2835/bcm2835-camera.c 1970-01-01 01:00:00.000000000 +0100
  11377. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c 2014-04-24 16:04:36.447091651 +0200
  11378. @@ -0,0 +1,1719 @@
  11379. +/*
  11380. + * Broadcom BM2835 V4L2 driver
  11381. + *
  11382. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  11383. + *
  11384. + * This file is subject to the terms and conditions of the GNU General Public
  11385. + * License. See the file COPYING in the main directory of this archive
  11386. + * for more details.
  11387. + *
  11388. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  11389. + * Dave Stevenson <dsteve@broadcom.com>
  11390. + * Simon Mellor <simellor@broadcom.com>
  11391. + * Luke Diamand <luked@broadcom.com>
  11392. + */
  11393. +
  11394. +#include <linux/errno.h>
  11395. +#include <linux/kernel.h>
  11396. +#include <linux/module.h>
  11397. +#include <linux/slab.h>
  11398. +#include <media/videobuf2-vmalloc.h>
  11399. +#include <media/videobuf2-dma-contig.h>
  11400. +#include <media/v4l2-device.h>
  11401. +#include <media/v4l2-ioctl.h>
  11402. +#include <media/v4l2-ctrls.h>
  11403. +#include <media/v4l2-fh.h>
  11404. +#include <media/v4l2-event.h>
  11405. +#include <media/v4l2-common.h>
  11406. +#include <linux/delay.h>
  11407. +
  11408. +#include "mmal-common.h"
  11409. +#include "mmal-encodings.h"
  11410. +#include "mmal-vchiq.h"
  11411. +#include "mmal-msg.h"
  11412. +#include "mmal-parameters.h"
  11413. +#include "bcm2835-camera.h"
  11414. +
  11415. +#define BM2835_MMAL_VERSION "0.0.2"
  11416. +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  11417. +#define MIN_WIDTH 16
  11418. +#define MIN_HEIGHT 16
  11419. +#define MAX_WIDTH 2592
  11420. +#define MAX_HEIGHT 1944
  11421. +#define MIN_BUFFER_SIZE (80*1024)
  11422. +
  11423. +#define MAX_VIDEO_MODE_WIDTH 1280
  11424. +#define MAX_VIDEO_MODE_HEIGHT 720
  11425. +
  11426. +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  11427. +MODULE_AUTHOR("Vincent Sanders");
  11428. +MODULE_LICENSE("GPL");
  11429. +MODULE_VERSION(BM2835_MMAL_VERSION);
  11430. +
  11431. +int bcm2835_v4l2_debug;
  11432. +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  11433. +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  11434. +
  11435. +static struct bm2835_mmal_dev *gdev; /* global device data */
  11436. +
  11437. +#define FPS_MIN 1
  11438. +#define FPS_MAX 90
  11439. +
  11440. +/* timeperframe: min/max and default */
  11441. +static const struct v4l2_fract
  11442. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  11443. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  11444. + tpf_default = {.numerator = 1000, .denominator = 30000};
  11445. +
  11446. +/* video formats */
  11447. +static struct mmal_fmt formats[] = {
  11448. + {
  11449. + .name = "4:2:0, packed YUV",
  11450. + .fourcc = V4L2_PIX_FMT_YUV420,
  11451. + .flags = 0,
  11452. + .mmal = MMAL_ENCODING_I420,
  11453. + .depth = 12,
  11454. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11455. + },
  11456. + {
  11457. + .name = "4:2:2, packed, YUYV",
  11458. + .fourcc = V4L2_PIX_FMT_YUYV,
  11459. + .flags = 0,
  11460. + .mmal = MMAL_ENCODING_YUYV,
  11461. + .depth = 16,
  11462. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11463. + },
  11464. + {
  11465. + .name = "RGB24 (LE)",
  11466. + .fourcc = V4L2_PIX_FMT_RGB24,
  11467. + .flags = 0,
  11468. + .mmal = MMAL_ENCODING_BGR24,
  11469. + .depth = 24,
  11470. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11471. + },
  11472. + {
  11473. + .name = "JPEG",
  11474. + .fourcc = V4L2_PIX_FMT_JPEG,
  11475. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  11476. + .mmal = MMAL_ENCODING_JPEG,
  11477. + .depth = 8,
  11478. + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  11479. + },
  11480. + {
  11481. + .name = "H264",
  11482. + .fourcc = V4L2_PIX_FMT_H264,
  11483. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  11484. + .mmal = MMAL_ENCODING_H264,
  11485. + .depth = 8,
  11486. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  11487. + },
  11488. + {
  11489. + .name = "MJPEG",
  11490. + .fourcc = V4L2_PIX_FMT_MJPEG,
  11491. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  11492. + .mmal = MMAL_ENCODING_MJPEG,
  11493. + .depth = 8,
  11494. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  11495. + },
  11496. + {
  11497. + .name = "4:2:2, packed, YVYU",
  11498. + .fourcc = V4L2_PIX_FMT_YVYU,
  11499. + .flags = 0,
  11500. + .mmal = MMAL_ENCODING_YVYU,
  11501. + .depth = 16,
  11502. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11503. + },
  11504. + {
  11505. + .name = "4:2:2, packed, VYUY",
  11506. + .fourcc = V4L2_PIX_FMT_VYUY,
  11507. + .flags = 0,
  11508. + .mmal = MMAL_ENCODING_VYUY,
  11509. + .depth = 16,
  11510. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11511. + },
  11512. + {
  11513. + .name = "4:2:2, packed, UYVY",
  11514. + .fourcc = V4L2_PIX_FMT_UYVY,
  11515. + .flags = 0,
  11516. + .mmal = MMAL_ENCODING_UYVY,
  11517. + .depth = 16,
  11518. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11519. + },
  11520. + {
  11521. + .name = "4:2:0, packed, NV12",
  11522. + .fourcc = V4L2_PIX_FMT_NV12,
  11523. + .flags = 0,
  11524. + .mmal = MMAL_ENCODING_NV12,
  11525. + .depth = 12,
  11526. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11527. + },
  11528. + {
  11529. + .name = "RGB24 (BE)",
  11530. + .fourcc = V4L2_PIX_FMT_BGR24,
  11531. + .flags = 0,
  11532. + .mmal = MMAL_ENCODING_RGB24,
  11533. + .depth = 24,
  11534. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11535. + },
  11536. + {
  11537. + .name = "4:2:0, packed YVU",
  11538. + .fourcc = V4L2_PIX_FMT_YVU420,
  11539. + .flags = 0,
  11540. + .mmal = MMAL_ENCODING_YV12,
  11541. + .depth = 12,
  11542. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11543. + },
  11544. + {
  11545. + .name = "4:2:0, packed, NV21",
  11546. + .fourcc = V4L2_PIX_FMT_NV21,
  11547. + .flags = 0,
  11548. + .mmal = MMAL_ENCODING_NV21,
  11549. + .depth = 12,
  11550. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11551. + },
  11552. +};
  11553. +
  11554. +static struct mmal_fmt *get_format(struct v4l2_format *f)
  11555. +{
  11556. + struct mmal_fmt *fmt;
  11557. + unsigned int k;
  11558. +
  11559. + for (k = 0; k < ARRAY_SIZE(formats); k++) {
  11560. + fmt = &formats[k];
  11561. + if (fmt->fourcc == f->fmt.pix.pixelformat)
  11562. + break;
  11563. + }
  11564. +
  11565. + if (k == ARRAY_SIZE(formats))
  11566. + return NULL;
  11567. +
  11568. + return &formats[k];
  11569. +}
  11570. +
  11571. +/* ------------------------------------------------------------------
  11572. + Videobuf queue operations
  11573. + ------------------------------------------------------------------*/
  11574. +
  11575. +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  11576. + unsigned int *nbuffers, unsigned int *nplanes,
  11577. + unsigned int sizes[], void *alloc_ctxs[])
  11578. +{
  11579. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11580. + unsigned long size;
  11581. +
  11582. + /* refuse queue setup if port is not configured */
  11583. + if (dev->capture.port == NULL) {
  11584. + v4l2_err(&dev->v4l2_dev,
  11585. + "%s: capture port not configured\n", __func__);
  11586. + return -EINVAL;
  11587. + }
  11588. +
  11589. + size = dev->capture.port->current_buffer.size;
  11590. + if (size == 0) {
  11591. + v4l2_err(&dev->v4l2_dev,
  11592. + "%s: capture port buffer size is zero\n", __func__);
  11593. + return -EINVAL;
  11594. + }
  11595. +
  11596. + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
  11597. + *nbuffers = (dev->capture.port->current_buffer.num + 2);
  11598. +
  11599. + *nplanes = 1;
  11600. +
  11601. + sizes[0] = size;
  11602. +
  11603. + /*
  11604. + * videobuf2-vmalloc allocator is context-less so no need to set
  11605. + * alloc_ctxs array.
  11606. + */
  11607. +
  11608. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11609. + __func__, dev);
  11610. +
  11611. + return 0;
  11612. +}
  11613. +
  11614. +static int buffer_prepare(struct vb2_buffer *vb)
  11615. +{
  11616. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  11617. + unsigned long size;
  11618. +
  11619. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11620. + __func__, dev);
  11621. +
  11622. + BUG_ON(dev->capture.port == NULL);
  11623. + BUG_ON(dev->capture.fmt == NULL);
  11624. +
  11625. + size = dev->capture.stride * dev->capture.height;
  11626. + if (vb2_plane_size(vb, 0) < size) {
  11627. + v4l2_err(&dev->v4l2_dev,
  11628. + "%s data will not fit into plane (%lu < %lu)\n",
  11629. + __func__, vb2_plane_size(vb, 0), size);
  11630. + return -EINVAL;
  11631. + }
  11632. +
  11633. + return 0;
  11634. +}
  11635. +
  11636. +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
  11637. +{
  11638. + return dev->capture.camera_port ==
  11639. + &dev->
  11640. + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
  11641. +}
  11642. +
  11643. +static void buffer_cb(struct vchiq_mmal_instance *instance,
  11644. + struct vchiq_mmal_port *port,
  11645. + int status,
  11646. + struct mmal_buffer *buf,
  11647. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
  11648. +{
  11649. + struct bm2835_mmal_dev *dev = port->cb_ctx;
  11650. +
  11651. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11652. + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
  11653. + __func__, status, buf, length, mmal_flags, pts);
  11654. +
  11655. + if (status != 0) {
  11656. + /* error in transfer */
  11657. + if (buf != NULL) {
  11658. + /* there was a buffer with the error so return it */
  11659. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  11660. + }
  11661. + return;
  11662. + } else if (length == 0) {
  11663. + /* stream ended */
  11664. + if (buf != NULL) {
  11665. + /* this should only ever happen if the port is
  11666. + * disabled and there are buffers still queued
  11667. + */
  11668. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  11669. + pr_debug("Empty buffer");
  11670. + } else if (dev->capture.frame_count) {
  11671. + /* grab another frame */
  11672. + if (is_capturing(dev)) {
  11673. + pr_debug("Grab another frame");
  11674. + vchiq_mmal_port_parameter_set(
  11675. + instance,
  11676. + dev->capture.
  11677. + camera_port,
  11678. + MMAL_PARAMETER_CAPTURE,
  11679. + &dev->capture.
  11680. + frame_count,
  11681. + sizeof(dev->capture.frame_count));
  11682. + }
  11683. + } else {
  11684. + /* signal frame completion */
  11685. + complete(&dev->capture.frame_cmplt);
  11686. + }
  11687. + } else {
  11688. + if (dev->capture.frame_count) {
  11689. + if (dev->capture.vc_start_timestamp != -1 &&
  11690. + pts != 0) {
  11691. + s64 runtime_us = pts -
  11692. + dev->capture.vc_start_timestamp;
  11693. + u32 div = 0;
  11694. + u32 rem = 0;
  11695. +
  11696. + div =
  11697. + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
  11698. + buf->vb.v4l2_buf.timestamp.tv_sec =
  11699. + dev->capture.kernel_start_ts.tv_sec - 1 +
  11700. + div;
  11701. + buf->vb.v4l2_buf.timestamp.tv_usec =
  11702. + dev->capture.kernel_start_ts.tv_usec + rem;
  11703. +
  11704. + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
  11705. + USEC_PER_SEC) {
  11706. + buf->vb.v4l2_buf.timestamp.tv_sec++;
  11707. + buf->vb.v4l2_buf.timestamp.tv_usec -=
  11708. + USEC_PER_SEC;
  11709. + }
  11710. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11711. + "Convert start time %d.%06d and %llu "
  11712. + "with offset %llu to %d.%06d\n",
  11713. + (int)dev->capture.kernel_start_ts.
  11714. + tv_sec,
  11715. + (int)dev->capture.kernel_start_ts.
  11716. + tv_usec,
  11717. + dev->capture.vc_start_timestamp, pts,
  11718. + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
  11719. + (int)buf->vb.v4l2_buf.timestamp.
  11720. + tv_usec);
  11721. + } else {
  11722. + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
  11723. + }
  11724. +
  11725. + vb2_set_plane_payload(&buf->vb, 0, length);
  11726. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
  11727. +
  11728. + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
  11729. + is_capturing(dev)) {
  11730. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11731. + "Grab another frame as buffer has EOS");
  11732. + vchiq_mmal_port_parameter_set(
  11733. + instance,
  11734. + dev->capture.
  11735. + camera_port,
  11736. + MMAL_PARAMETER_CAPTURE,
  11737. + &dev->capture.
  11738. + frame_count,
  11739. + sizeof(dev->capture.frame_count));
  11740. + }
  11741. + } else {
  11742. + /* signal frame completion */
  11743. + complete(&dev->capture.frame_cmplt);
  11744. + }
  11745. + }
  11746. +}
  11747. +
  11748. +static int enable_camera(struct bm2835_mmal_dev *dev)
  11749. +{
  11750. + int ret;
  11751. + if (!dev->camera_use_count) {
  11752. + ret = vchiq_mmal_component_enable(
  11753. + dev->instance,
  11754. + dev->component[MMAL_COMPONENT_CAMERA]);
  11755. + if (ret < 0) {
  11756. + v4l2_err(&dev->v4l2_dev,
  11757. + "Failed enabling camera, ret %d\n", ret);
  11758. + return -EINVAL;
  11759. + }
  11760. + }
  11761. + dev->camera_use_count++;
  11762. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11763. + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
  11764. + dev->camera_use_count);
  11765. + return 0;
  11766. +}
  11767. +
  11768. +static int disable_camera(struct bm2835_mmal_dev *dev)
  11769. +{
  11770. + int ret;
  11771. + if (!dev->camera_use_count) {
  11772. + v4l2_err(&dev->v4l2_dev,
  11773. + "Disabled the camera when already disabled\n");
  11774. + return -EINVAL;
  11775. + }
  11776. + dev->camera_use_count--;
  11777. + if (!dev->camera_use_count) {
  11778. + unsigned int i = 0xFFFFFFFF;
  11779. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11780. + "Disabling camera\n");
  11781. + ret =
  11782. + vchiq_mmal_component_disable(
  11783. + dev->instance,
  11784. + dev->component[MMAL_COMPONENT_CAMERA]);
  11785. + if (ret < 0) {
  11786. + v4l2_err(&dev->v4l2_dev,
  11787. + "Failed disabling camera, ret %d\n", ret);
  11788. + return -EINVAL;
  11789. + }
  11790. + vchiq_mmal_port_parameter_set(
  11791. + dev->instance,
  11792. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  11793. + MMAL_PARAMETER_CAMERA_NUM, &i,
  11794. + sizeof(i));
  11795. + }
  11796. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11797. + "Camera refcount now %d\n", dev->camera_use_count);
  11798. + return 0;
  11799. +}
  11800. +
  11801. +static void buffer_queue(struct vb2_buffer *vb)
  11802. +{
  11803. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  11804. + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
  11805. + int ret;
  11806. +
  11807. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11808. + "%s: dev:%p buf:%p\n", __func__, dev, buf);
  11809. +
  11810. + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
  11811. + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
  11812. +
  11813. + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
  11814. + if (ret < 0)
  11815. + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
  11816. + __func__);
  11817. +}
  11818. +
  11819. +static int start_streaming(struct vb2_queue *vq, unsigned int count)
  11820. +{
  11821. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11822. + int ret;
  11823. + int parameter_size;
  11824. +
  11825. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11826. + __func__, dev);
  11827. +
  11828. + /* ensure a format has actually been set */
  11829. + if (dev->capture.port == NULL)
  11830. + return -EINVAL;
  11831. +
  11832. + if (enable_camera(dev) < 0) {
  11833. + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
  11834. + return -EINVAL;
  11835. + }
  11836. +
  11837. + /*init_completion(&dev->capture.frame_cmplt); */
  11838. +
  11839. + /* enable frame capture */
  11840. + dev->capture.frame_count = 1;
  11841. +
  11842. + /* if the preview is not already running, wait for a few frames for AGC
  11843. + * to settle down.
  11844. + */
  11845. + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
  11846. + msleep(300);
  11847. +
  11848. + /* enable the connection from camera to encoder (if applicable) */
  11849. + if (dev->capture.camera_port != dev->capture.port
  11850. + && dev->capture.camera_port) {
  11851. + ret = vchiq_mmal_port_enable(dev->instance,
  11852. + dev->capture.camera_port, NULL);
  11853. + if (ret) {
  11854. + v4l2_err(&dev->v4l2_dev,
  11855. + "Failed to enable encode tunnel - error %d\n",
  11856. + ret);
  11857. + return -1;
  11858. + }
  11859. + }
  11860. +
  11861. + /* Get VC timestamp at this point in time */
  11862. + parameter_size = sizeof(dev->capture.vc_start_timestamp);
  11863. + if (vchiq_mmal_port_parameter_get(dev->instance,
  11864. + dev->capture.camera_port,
  11865. + MMAL_PARAMETER_SYSTEM_TIME,
  11866. + &dev->capture.vc_start_timestamp,
  11867. + &parameter_size)) {
  11868. + v4l2_err(&dev->v4l2_dev,
  11869. + "Failed to get VC start time - update your VC f/w\n");
  11870. +
  11871. + /* Flag to indicate just to rely on kernel timestamps */
  11872. + dev->capture.vc_start_timestamp = -1;
  11873. + } else
  11874. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11875. + "Start time %lld size %d\n",
  11876. + dev->capture.vc_start_timestamp, parameter_size);
  11877. +
  11878. + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
  11879. +
  11880. + /* enable the camera port */
  11881. + dev->capture.port->cb_ctx = dev;
  11882. + ret =
  11883. + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  11884. + if (ret) {
  11885. + v4l2_err(&dev->v4l2_dev,
  11886. + "Failed to enable capture port - error %d. "
  11887. + "Disabling camera port again\n", ret);
  11888. +
  11889. + vchiq_mmal_port_disable(dev->instance,
  11890. + dev->capture.camera_port);
  11891. + if (disable_camera(dev) < 0) {
  11892. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  11893. + return -EINVAL;
  11894. + }
  11895. + return -1;
  11896. + }
  11897. +
  11898. + /* capture the first frame */
  11899. + vchiq_mmal_port_parameter_set(dev->instance,
  11900. + dev->capture.camera_port,
  11901. + MMAL_PARAMETER_CAPTURE,
  11902. + &dev->capture.frame_count,
  11903. + sizeof(dev->capture.frame_count));
  11904. + return 0;
  11905. +}
  11906. +
  11907. +/* abort streaming and wait for last buffer */
  11908. +static int stop_streaming(struct vb2_queue *vq)
  11909. +{
  11910. + int ret;
  11911. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11912. +
  11913. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11914. + __func__, dev);
  11915. +
  11916. + init_completion(&dev->capture.frame_cmplt);
  11917. + dev->capture.frame_count = 0;
  11918. +
  11919. + /* ensure a format has actually been set */
  11920. + if (dev->capture.port == NULL)
  11921. + return -EINVAL;
  11922. +
  11923. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  11924. +
  11925. + /* stop capturing frames */
  11926. + vchiq_mmal_port_parameter_set(dev->instance,
  11927. + dev->capture.camera_port,
  11928. + MMAL_PARAMETER_CAPTURE,
  11929. + &dev->capture.frame_count,
  11930. + sizeof(dev->capture.frame_count));
  11931. +
  11932. + /* wait for last frame to complete */
  11933. + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
  11934. + if (ret <= 0)
  11935. + v4l2_err(&dev->v4l2_dev,
  11936. + "error %d waiting for frame completion\n", ret);
  11937. +
  11938. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11939. + "disabling connection\n");
  11940. +
  11941. + /* disable the connection from camera to encoder */
  11942. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
  11943. + if (!ret && dev->capture.camera_port != dev->capture.port) {
  11944. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11945. + "disabling port\n");
  11946. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
  11947. + } else if (dev->capture.camera_port != dev->capture.port) {
  11948. + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
  11949. + ret);
  11950. + }
  11951. +
  11952. + if (disable_camera(dev) < 0) {
  11953. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  11954. + return -EINVAL;
  11955. + }
  11956. +
  11957. + return ret;
  11958. +}
  11959. +
  11960. +static void bm2835_mmal_lock(struct vb2_queue *vq)
  11961. +{
  11962. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11963. + mutex_lock(&dev->mutex);
  11964. +}
  11965. +
  11966. +static void bm2835_mmal_unlock(struct vb2_queue *vq)
  11967. +{
  11968. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11969. + mutex_unlock(&dev->mutex);
  11970. +}
  11971. +
  11972. +static struct vb2_ops bm2835_mmal_video_qops = {
  11973. + .queue_setup = queue_setup,
  11974. + .buf_prepare = buffer_prepare,
  11975. + .buf_queue = buffer_queue,
  11976. + .start_streaming = start_streaming,
  11977. + .stop_streaming = stop_streaming,
  11978. + .wait_prepare = bm2835_mmal_unlock,
  11979. + .wait_finish = bm2835_mmal_lock,
  11980. +};
  11981. +
  11982. +/* ------------------------------------------------------------------
  11983. + IOCTL operations
  11984. + ------------------------------------------------------------------*/
  11985. +
  11986. +/* overlay ioctl */
  11987. +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  11988. + struct v4l2_fmtdesc *f)
  11989. +{
  11990. + struct mmal_fmt *fmt;
  11991. +
  11992. + if (f->index >= ARRAY_SIZE(formats))
  11993. + return -EINVAL;
  11994. +
  11995. + fmt = &formats[f->index];
  11996. +
  11997. + strlcpy(f->description, fmt->name, sizeof(f->description));
  11998. + f->pixelformat = fmt->fourcc;
  11999. + f->flags = fmt->flags;
  12000. +
  12001. + return 0;
  12002. +}
  12003. +
  12004. +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
  12005. + struct v4l2_format *f)
  12006. +{
  12007. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12008. +
  12009. + f->fmt.win = dev->overlay;
  12010. +
  12011. + return 0;
  12012. +}
  12013. +
  12014. +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  12015. + struct v4l2_format *f)
  12016. +{
  12017. + /* Only support one format so get the current one. */
  12018. + vidioc_g_fmt_vid_overlay(file, priv, f);
  12019. +
  12020. + /* todo: allow the size and/or offset to be changed. */
  12021. + return 0;
  12022. +}
  12023. +
  12024. +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
  12025. + struct v4l2_format *f)
  12026. +{
  12027. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12028. +
  12029. + vidioc_try_fmt_vid_overlay(file, priv, f);
  12030. +
  12031. + dev->overlay = f->fmt.win;
  12032. +
  12033. + /* todo: program the preview port parameters */
  12034. + return 0;
  12035. +}
  12036. +
  12037. +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
  12038. +{
  12039. + int ret;
  12040. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12041. + struct vchiq_mmal_port *src;
  12042. + struct vchiq_mmal_port *dst;
  12043. + struct mmal_parameter_displayregion prev_config = {
  12044. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  12045. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  12046. + .layer = PREVIEW_LAYER,
  12047. + .alpha = 255,
  12048. + .fullscreen = 0,
  12049. + .dest_rect = {
  12050. + .x = dev->overlay.w.left,
  12051. + .y = dev->overlay.w.top,
  12052. + .width = dev->overlay.w.width,
  12053. + .height = dev->overlay.w.height,
  12054. + },
  12055. + };
  12056. +
  12057. + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  12058. + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  12059. + return 0; /* already in requested state */
  12060. +
  12061. + src =
  12062. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12063. + output[MMAL_CAMERA_PORT_PREVIEW];
  12064. +
  12065. + if (!on) {
  12066. + /* disconnect preview ports and disable component */
  12067. + ret = vchiq_mmal_port_disable(dev->instance, src);
  12068. + if (!ret)
  12069. + ret =
  12070. + vchiq_mmal_port_connect_tunnel(dev->instance, src,
  12071. + NULL);
  12072. + if (ret >= 0)
  12073. + ret = vchiq_mmal_component_disable(
  12074. + dev->instance,
  12075. + dev->component[MMAL_COMPONENT_PREVIEW]);
  12076. +
  12077. + disable_camera(dev);
  12078. + return ret;
  12079. + }
  12080. +
  12081. + /* set preview port format and connect it to output */
  12082. + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
  12083. +
  12084. + ret = vchiq_mmal_port_set_format(dev->instance, src);
  12085. + if (ret < 0)
  12086. + goto error;
  12087. +
  12088. + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  12089. + MMAL_PARAMETER_DISPLAYREGION,
  12090. + &prev_config, sizeof(prev_config));
  12091. + if (ret < 0)
  12092. + goto error;
  12093. +
  12094. + if (enable_camera(dev) < 0)
  12095. + goto error;
  12096. +
  12097. + ret = vchiq_mmal_component_enable(
  12098. + dev->instance,
  12099. + dev->component[MMAL_COMPONENT_PREVIEW]);
  12100. + if (ret < 0)
  12101. + goto error;
  12102. +
  12103. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
  12104. + src, dst);
  12105. + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
  12106. + if (!ret)
  12107. + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
  12108. +error:
  12109. + return ret;
  12110. +}
  12111. +
  12112. +static int vidioc_g_fbuf(struct file *file, void *fh,
  12113. + struct v4l2_framebuffer *a)
  12114. +{
  12115. + /* The video overlay must stay within the framebuffer and can't be
  12116. + positioned independently. */
  12117. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12118. + struct vchiq_mmal_port *preview_port =
  12119. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12120. + output[MMAL_CAMERA_PORT_PREVIEW];
  12121. + a->flags = V4L2_FBUF_FLAG_OVERLAY;
  12122. + a->fmt.width = preview_port->es.video.width;
  12123. + a->fmt.height = preview_port->es.video.height;
  12124. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  12125. + a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
  12126. + a->fmt.sizeimage = (preview_port->es.video.width *
  12127. + preview_port->es.video.height * 3)>>1;
  12128. + a->fmt.colorspace = V4L2_COLORSPACE_JPEG;
  12129. +
  12130. + return 0;
  12131. +}
  12132. +
  12133. +/* input ioctls */
  12134. +static int vidioc_enum_input(struct file *file, void *priv,
  12135. + struct v4l2_input *inp)
  12136. +{
  12137. + /* only a single camera input */
  12138. + if (inp->index != 0)
  12139. + return -EINVAL;
  12140. +
  12141. + inp->type = V4L2_INPUT_TYPE_CAMERA;
  12142. + sprintf(inp->name, "Camera %u", inp->index);
  12143. + return 0;
  12144. +}
  12145. +
  12146. +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  12147. +{
  12148. + *i = 0;
  12149. + return 0;
  12150. +}
  12151. +
  12152. +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  12153. +{
  12154. + if (i != 0)
  12155. + return -EINVAL;
  12156. +
  12157. + return 0;
  12158. +}
  12159. +
  12160. +/* capture ioctls */
  12161. +static int vidioc_querycap(struct file *file, void *priv,
  12162. + struct v4l2_capability *cap)
  12163. +{
  12164. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12165. + u32 major;
  12166. + u32 minor;
  12167. +
  12168. + vchiq_mmal_version(dev->instance, &major, &minor);
  12169. +
  12170. + strcpy(cap->driver, "bm2835 mmal");
  12171. + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
  12172. + major, minor);
  12173. +
  12174. + snprintf(cap->bus_info, sizeof(cap->bus_info),
  12175. + "platform:%s", dev->v4l2_dev.name);
  12176. + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
  12177. + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
  12178. + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  12179. +
  12180. + return 0;
  12181. +}
  12182. +
  12183. +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  12184. + struct v4l2_fmtdesc *f)
  12185. +{
  12186. + struct mmal_fmt *fmt;
  12187. +
  12188. + if (f->index >= ARRAY_SIZE(formats))
  12189. + return -EINVAL;
  12190. +
  12191. + fmt = &formats[f->index];
  12192. +
  12193. + strlcpy(f->description, fmt->name, sizeof(f->description));
  12194. + f->pixelformat = fmt->fourcc;
  12195. + f->flags = fmt->flags;
  12196. +
  12197. + return 0;
  12198. +}
  12199. +
  12200. +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  12201. + struct v4l2_format *f)
  12202. +{
  12203. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12204. +
  12205. + f->fmt.pix.width = dev->capture.width;
  12206. + f->fmt.pix.height = dev->capture.height;
  12207. + f->fmt.pix.field = V4L2_FIELD_NONE;
  12208. + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  12209. + f->fmt.pix.bytesperline =
  12210. + (f->fmt.pix.width * dev->capture.fmt->depth) >> 3;
  12211. + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  12212. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_JPEG
  12213. + && f->fmt.pix.sizeimage < (100 << 10)) {
  12214. + /* Need a minimum size for JPEG to account for EXIF. */
  12215. + f->fmt.pix.sizeimage = (100 << 10);
  12216. + }
  12217. +
  12218. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_YUYV ||
  12219. + dev->capture.fmt->fourcc == V4L2_PIX_FMT_UYVY)
  12220. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  12221. + else
  12222. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  12223. + f->fmt.pix.priv = 0;
  12224. +
  12225. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  12226. + __func__);
  12227. + return 0;
  12228. +}
  12229. +
  12230. +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  12231. + struct v4l2_format *f)
  12232. +{
  12233. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12234. + struct mmal_fmt *mfmt;
  12235. +
  12236. + mfmt = get_format(f);
  12237. + if (!mfmt) {
  12238. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12239. + "Fourcc format (0x%08x) unknown.\n",
  12240. + f->fmt.pix.pixelformat);
  12241. + f->fmt.pix.pixelformat = formats[0].fourcc;
  12242. + mfmt = get_format(f);
  12243. + }
  12244. +
  12245. + f->fmt.pix.field = V4L2_FIELD_NONE;
  12246. + /* image must be a multiple of 32 pixels wide and 16 lines high */
  12247. + v4l_bound_align_image(&f->fmt.pix.width, 48, MAX_WIDTH, 5,
  12248. + &f->fmt.pix.height, 32, MAX_HEIGHT, 4, 0);
  12249. + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth) >> 3;
  12250. + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  12251. + if (f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  12252. + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  12253. +
  12254. + if (mfmt->fourcc == V4L2_PIX_FMT_YUYV ||
  12255. + mfmt->fourcc == V4L2_PIX_FMT_UYVY)
  12256. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  12257. + else
  12258. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  12259. + f->fmt.pix.priv = 0;
  12260. +
  12261. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  12262. + __func__);
  12263. + return 0;
  12264. +}
  12265. +
  12266. +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
  12267. + struct v4l2_format *f)
  12268. +{
  12269. + int ret;
  12270. + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
  12271. + struct vchiq_mmal_component *encode_component = NULL;
  12272. + struct mmal_fmt *mfmt = get_format(f);
  12273. +
  12274. + BUG_ON(!mfmt);
  12275. +
  12276. + if (dev->capture.encode_component) {
  12277. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12278. + "vid_cap - disconnect previous tunnel\n");
  12279. +
  12280. + /* Disconnect any previous connection */
  12281. + vchiq_mmal_port_connect_tunnel(dev->instance,
  12282. + dev->capture.camera_port, NULL);
  12283. + dev->capture.camera_port = NULL;
  12284. + ret = vchiq_mmal_component_disable(dev->instance,
  12285. + dev->capture.
  12286. + encode_component);
  12287. + if (ret)
  12288. + v4l2_err(&dev->v4l2_dev,
  12289. + "Failed to disable encode component %d\n",
  12290. + ret);
  12291. +
  12292. + dev->capture.encode_component = NULL;
  12293. + }
  12294. + /* format dependant port setup */
  12295. + switch (mfmt->mmal_component) {
  12296. + case MMAL_COMPONENT_CAMERA:
  12297. + /* Make a further decision on port based on resolution */
  12298. + if (f->fmt.pix.width <= MAX_VIDEO_MODE_WIDTH
  12299. + && f->fmt.pix.height <= MAX_VIDEO_MODE_HEIGHT)
  12300. + camera_port = port =
  12301. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12302. + output[MMAL_CAMERA_PORT_VIDEO];
  12303. + else
  12304. + camera_port = port =
  12305. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12306. + output[MMAL_CAMERA_PORT_CAPTURE];
  12307. + break;
  12308. + case MMAL_COMPONENT_IMAGE_ENCODE:
  12309. + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
  12310. + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  12311. + camera_port =
  12312. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12313. + output[MMAL_CAMERA_PORT_CAPTURE];
  12314. + break;
  12315. + case MMAL_COMPONENT_VIDEO_ENCODE:
  12316. + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
  12317. + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  12318. + camera_port =
  12319. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12320. + output[MMAL_CAMERA_PORT_VIDEO];
  12321. + break;
  12322. + default:
  12323. + break;
  12324. + }
  12325. +
  12326. + if (!port)
  12327. + return -EINVAL;
  12328. +
  12329. + if (encode_component)
  12330. + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
  12331. + else
  12332. + camera_port->format.encoding = mfmt->mmal;
  12333. +
  12334. + camera_port->format.encoding_variant = 0;
  12335. + camera_port->es.video.width = f->fmt.pix.width;
  12336. + camera_port->es.video.height = f->fmt.pix.height;
  12337. + camera_port->es.video.crop.x = 0;
  12338. + camera_port->es.video.crop.y = 0;
  12339. + camera_port->es.video.crop.width = f->fmt.pix.width;
  12340. + camera_port->es.video.crop.height = f->fmt.pix.height;
  12341. + camera_port->es.video.frame_rate.num = 0;
  12342. + camera_port->es.video.frame_rate.den = 1;
  12343. +
  12344. + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  12345. +
  12346. + if (!ret
  12347. + && camera_port ==
  12348. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12349. + output[MMAL_CAMERA_PORT_VIDEO]) {
  12350. + bool overlay_enabled =
  12351. + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
  12352. + struct vchiq_mmal_port *preview_port =
  12353. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12354. + output[MMAL_CAMERA_PORT_PREVIEW];
  12355. + /* Preview and encode ports need to match on resolution */
  12356. + if (overlay_enabled) {
  12357. + /* Need to disable the overlay before we can update
  12358. + * the resolution
  12359. + */
  12360. + ret =
  12361. + vchiq_mmal_port_disable(dev->instance,
  12362. + preview_port);
  12363. + if (!ret)
  12364. + ret =
  12365. + vchiq_mmal_port_connect_tunnel(
  12366. + dev->instance,
  12367. + preview_port,
  12368. + NULL);
  12369. + }
  12370. + preview_port->es.video.width = f->fmt.pix.width;
  12371. + preview_port->es.video.height = f->fmt.pix.height;
  12372. + preview_port->es.video.crop.x = 0;
  12373. + preview_port->es.video.crop.y = 0;
  12374. + preview_port->es.video.crop.width = f->fmt.pix.width;
  12375. + preview_port->es.video.crop.height = f->fmt.pix.height;
  12376. + preview_port->es.video.frame_rate.num =
  12377. + dev->capture.timeperframe.denominator;
  12378. + preview_port->es.video.frame_rate.den =
  12379. + dev->capture.timeperframe.numerator;
  12380. + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  12381. + if (overlay_enabled) {
  12382. + ret = vchiq_mmal_port_connect_tunnel(
  12383. + dev->instance,
  12384. + preview_port,
  12385. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  12386. + if (!ret)
  12387. + ret = vchiq_mmal_port_enable(dev->instance,
  12388. + preview_port,
  12389. + NULL);
  12390. + }
  12391. + }
  12392. +
  12393. + if (ret) {
  12394. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12395. + "%s failed to set format\n", __func__);
  12396. + /* ensure capture is not going to be tried */
  12397. + dev->capture.port = NULL;
  12398. + } else {
  12399. + if (encode_component) {
  12400. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12401. + "vid_cap - set up encode comp\n");
  12402. +
  12403. + /* configure buffering */
  12404. + camera_port->current_buffer.size =
  12405. + camera_port->recommended_buffer.size;
  12406. + camera_port->current_buffer.num =
  12407. + camera_port->recommended_buffer.num;
  12408. +
  12409. + ret =
  12410. + vchiq_mmal_port_connect_tunnel(
  12411. + dev->instance,
  12412. + camera_port,
  12413. + &encode_component->input[0]);
  12414. + if (ret) {
  12415. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12416. + &dev->v4l2_dev,
  12417. + "%s failed to create connection\n",
  12418. + __func__);
  12419. + /* ensure capture is not going to be tried */
  12420. + dev->capture.port = NULL;
  12421. + } else {
  12422. + port->es.video.width = f->fmt.pix.width;
  12423. + port->es.video.height = f->fmt.pix.height;
  12424. + port->es.video.crop.x = 0;
  12425. + port->es.video.crop.y = 0;
  12426. + port->es.video.crop.width = f->fmt.pix.width;
  12427. + port->es.video.crop.height = f->fmt.pix.height;
  12428. + port->es.video.frame_rate.num =
  12429. + dev->capture.timeperframe.denominator;
  12430. + port->es.video.frame_rate.den =
  12431. + dev->capture.timeperframe.numerator;
  12432. +
  12433. + port->format.encoding = mfmt->mmal;
  12434. + port->format.encoding_variant = 0;
  12435. + /* Set any encoding specific parameters */
  12436. + switch (mfmt->mmal_component) {
  12437. + case MMAL_COMPONENT_VIDEO_ENCODE:
  12438. + port->format.bitrate =
  12439. + dev->capture.encode_bitrate;
  12440. + break;
  12441. + case MMAL_COMPONENT_IMAGE_ENCODE:
  12442. + /* Could set EXIF parameters here */
  12443. + break;
  12444. + default:
  12445. + break;
  12446. + }
  12447. + ret = vchiq_mmal_port_set_format(dev->instance,
  12448. + port);
  12449. + if (ret)
  12450. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12451. + &dev->v4l2_dev,
  12452. + "%s failed to set format\n",
  12453. + __func__);
  12454. + }
  12455. +
  12456. + if (!ret) {
  12457. + ret = vchiq_mmal_component_enable(
  12458. + dev->instance,
  12459. + encode_component);
  12460. + if (ret) {
  12461. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12462. + &dev->v4l2_dev,
  12463. + "%s Failed to enable encode components\n",
  12464. + __func__);
  12465. + }
  12466. + }
  12467. + if (!ret) {
  12468. + /* configure buffering */
  12469. + port->current_buffer.num = 1;
  12470. + port->current_buffer.size =
  12471. + f->fmt.pix.sizeimage;
  12472. + if (port->format.encoding ==
  12473. + MMAL_ENCODING_JPEG) {
  12474. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12475. + &dev->v4l2_dev,
  12476. + "JPG - buf size now %d was %d\n",
  12477. + f->fmt.pix.sizeimage,
  12478. + port->current_buffer.size);
  12479. + port->current_buffer.size =
  12480. + (f->fmt.pix.sizeimage <
  12481. + (100 << 10))
  12482. + ? (100 << 10) : f->fmt.pix.
  12483. + sizeimage;
  12484. + }
  12485. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12486. + &dev->v4l2_dev,
  12487. + "vid_cap - cur_buf.size set to %d\n",
  12488. + f->fmt.pix.sizeimage);
  12489. + port->current_buffer.alignment = 0;
  12490. + }
  12491. + } else {
  12492. + /* configure buffering */
  12493. + camera_port->current_buffer.num = 1;
  12494. + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
  12495. + camera_port->current_buffer.alignment = 0;
  12496. + }
  12497. +
  12498. + if (!ret) {
  12499. + dev->capture.fmt = mfmt;
  12500. + dev->capture.stride = f->fmt.pix.bytesperline;
  12501. + dev->capture.width = camera_port->es.video.crop.width;
  12502. + dev->capture.height = camera_port->es.video.crop.height;
  12503. +
  12504. + /* select port for capture */
  12505. + dev->capture.port = port;
  12506. + dev->capture.camera_port = camera_port;
  12507. + dev->capture.encode_component = encode_component;
  12508. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12509. + &dev->v4l2_dev,
  12510. + "Set dev->capture.fmt %08X, %dx%d, stride %d",
  12511. + port->format.encoding,
  12512. + dev->capture.width, dev->capture.height,
  12513. + dev->capture.stride);
  12514. + }
  12515. + }
  12516. +
  12517. + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
  12518. + return ret;
  12519. +}
  12520. +
  12521. +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  12522. + struct v4l2_format *f)
  12523. +{
  12524. + int ret;
  12525. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12526. + struct mmal_fmt *mfmt;
  12527. +
  12528. + /* try the format to set valid parameters */
  12529. + ret = vidioc_try_fmt_vid_cap(file, priv, f);
  12530. + if (ret) {
  12531. + v4l2_err(&dev->v4l2_dev,
  12532. + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
  12533. + return ret;
  12534. + }
  12535. +
  12536. + /* if a capture is running refuse to set format */
  12537. + if (vb2_is_busy(&dev->capture.vb_vidq)) {
  12538. + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
  12539. + return -EBUSY;
  12540. + }
  12541. +
  12542. + /* If the format is unsupported v4l2 says we should switch to
  12543. + * a supported one and not return an error. */
  12544. + mfmt = get_format(f);
  12545. + if (!mfmt) {
  12546. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12547. + "Fourcc format (0x%08x) unknown.\n",
  12548. + f->fmt.pix.pixelformat);
  12549. + f->fmt.pix.pixelformat = formats[0].fourcc;
  12550. + mfmt = get_format(f);
  12551. + }
  12552. +
  12553. + ret = mmal_setup_components(dev, f);
  12554. + if (ret != 0) {
  12555. + v4l2_err(&dev->v4l2_dev,
  12556. + "%s: failed to setup mmal components: %d\n",
  12557. + __func__, ret);
  12558. + ret = -EINVAL;
  12559. + }
  12560. +
  12561. + return ret;
  12562. +}
  12563. +
  12564. +int vidioc_enum_framesizes(struct file *file, void *fh,
  12565. + struct v4l2_frmsizeenum *fsize)
  12566. +{
  12567. + static const struct v4l2_frmsize_stepwise sizes = {
  12568. + MIN_WIDTH, MAX_WIDTH, 2,
  12569. + MIN_HEIGHT, MAX_HEIGHT, 2
  12570. + };
  12571. + int i;
  12572. +
  12573. + if (fsize->index)
  12574. + return -EINVAL;
  12575. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  12576. + if (formats[i].fourcc == fsize->pixel_format)
  12577. + break;
  12578. + if (i == ARRAY_SIZE(formats))
  12579. + return -EINVAL;
  12580. + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  12581. + fsize->stepwise = sizes;
  12582. + return 0;
  12583. +}
  12584. +
  12585. +/* timeperframe is arbitrary and continous */
  12586. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  12587. + struct v4l2_frmivalenum *fival)
  12588. +{
  12589. + int i;
  12590. +
  12591. + if (fival->index)
  12592. + return -EINVAL;
  12593. +
  12594. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  12595. + if (formats[i].fourcc == fival->pixel_format)
  12596. + break;
  12597. + if (i == ARRAY_SIZE(formats))
  12598. + return -EINVAL;
  12599. +
  12600. + /* regarding width & height - we support any within range */
  12601. + if (fival->width < MIN_WIDTH || fival->width > MAX_WIDTH ||
  12602. + fival->height < MIN_HEIGHT || fival->height > MAX_HEIGHT)
  12603. + return -EINVAL;
  12604. +
  12605. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  12606. +
  12607. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  12608. + fival->stepwise.min = tpf_min;
  12609. + fival->stepwise.max = tpf_max;
  12610. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  12611. +
  12612. + return 0;
  12613. +}
  12614. +
  12615. +static int vidioc_g_parm(struct file *file, void *priv,
  12616. + struct v4l2_streamparm *parm)
  12617. +{
  12618. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12619. +
  12620. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  12621. + return -EINVAL;
  12622. +
  12623. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  12624. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  12625. + parm->parm.capture.readbuffers = 1;
  12626. + return 0;
  12627. +}
  12628. +
  12629. +#define FRACT_CMP(a, OP, b) \
  12630. + ((u64)(a).numerator * (b).denominator OP \
  12631. + (u64)(b).numerator * (a).denominator)
  12632. +
  12633. +static int vidioc_s_parm(struct file *file, void *priv,
  12634. + struct v4l2_streamparm *parm)
  12635. +{
  12636. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12637. + struct v4l2_fract tpf;
  12638. + struct mmal_parameter_rational fps_param;
  12639. +
  12640. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  12641. + return -EINVAL;
  12642. +
  12643. + tpf = parm->parm.capture.timeperframe;
  12644. +
  12645. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  12646. + tpf = tpf.denominator ? tpf : tpf_default;
  12647. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  12648. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  12649. +
  12650. + dev->capture.timeperframe = tpf;
  12651. + parm->parm.capture.timeperframe = tpf;
  12652. + parm->parm.capture.readbuffers = 1;
  12653. +
  12654. + fps_param.num = 0; /* Select variable fps, and then use
  12655. + * FPS_RANGE to select the actual limits.
  12656. + */
  12657. + fps_param.den = 1;
  12658. + set_framerate_params(dev);
  12659. +
  12660. + return 0;
  12661. +}
  12662. +
  12663. +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  12664. + /* overlay */
  12665. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  12666. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  12667. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  12668. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  12669. + .vidioc_overlay = vidioc_overlay,
  12670. + .vidioc_g_fbuf = vidioc_g_fbuf,
  12671. +
  12672. + /* inputs */
  12673. + .vidioc_enum_input = vidioc_enum_input,
  12674. + .vidioc_g_input = vidioc_g_input,
  12675. + .vidioc_s_input = vidioc_s_input,
  12676. +
  12677. + /* capture */
  12678. + .vidioc_querycap = vidioc_querycap,
  12679. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  12680. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  12681. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  12682. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  12683. +
  12684. + /* buffer management */
  12685. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  12686. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  12687. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  12688. + .vidioc_querybuf = vb2_ioctl_querybuf,
  12689. + .vidioc_qbuf = vb2_ioctl_qbuf,
  12690. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  12691. + .vidioc_enum_framesizes = vidioc_enum_framesizes,
  12692. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  12693. + .vidioc_g_parm = vidioc_g_parm,
  12694. + .vidioc_s_parm = vidioc_s_parm,
  12695. + .vidioc_streamon = vb2_ioctl_streamon,
  12696. + .vidioc_streamoff = vb2_ioctl_streamoff,
  12697. +
  12698. + .vidioc_log_status = v4l2_ctrl_log_status,
  12699. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  12700. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  12701. +};
  12702. +
  12703. +/* ------------------------------------------------------------------
  12704. + Driver init/finalise
  12705. + ------------------------------------------------------------------*/
  12706. +
  12707. +static const struct v4l2_file_operations camera0_fops = {
  12708. + .owner = THIS_MODULE,
  12709. + .open = v4l2_fh_open,
  12710. + .release = vb2_fop_release,
  12711. + .read = vb2_fop_read,
  12712. + .poll = vb2_fop_poll,
  12713. + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  12714. + .mmap = vb2_fop_mmap,
  12715. +};
  12716. +
  12717. +static struct video_device vdev_template = {
  12718. + .name = "camera0",
  12719. + .fops = &camera0_fops,
  12720. + .ioctl_ops = &camera0_ioctl_ops,
  12721. + .release = video_device_release_empty,
  12722. +};
  12723. +
  12724. +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  12725. + struct vchiq_mmal_component *camera)
  12726. +{
  12727. + int ret;
  12728. + struct mmal_parameter_camera_config cam_config = {
  12729. + .max_stills_w = MAX_WIDTH,
  12730. + .max_stills_h = MAX_HEIGHT,
  12731. + .stills_yuv422 = 1,
  12732. + .one_shot_stills = 1,
  12733. + .max_preview_video_w = 1920,
  12734. + .max_preview_video_h = 1088,
  12735. + .num_preview_video_frames = 3,
  12736. + .stills_capture_circular_buffer_height = 0,
  12737. + .fast_preview_resume = 0,
  12738. + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
  12739. + };
  12740. +
  12741. + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
  12742. + MMAL_PARAMETER_CAMERA_CONFIG,
  12743. + &cam_config, sizeof(cam_config));
  12744. + return ret;
  12745. +}
  12746. +
  12747. +/* MMAL instance and component init */
  12748. +static int __init mmal_init(struct bm2835_mmal_dev *dev)
  12749. +{
  12750. + int ret;
  12751. + struct mmal_es_format *format;
  12752. +
  12753. + ret = vchiq_mmal_init(&dev->instance);
  12754. + if (ret < 0)
  12755. + return ret;
  12756. +
  12757. + /* get the camera component ready */
  12758. + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
  12759. + &dev->component[MMAL_COMPONENT_CAMERA]);
  12760. + if (ret < 0)
  12761. + goto unreg_mmal;
  12762. +
  12763. + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
  12764. + MMAL_CAMERA_PORT_COUNT) {
  12765. + ret = -EINVAL;
  12766. + goto unreg_camera;
  12767. + }
  12768. +
  12769. + ret = set_camera_parameters(dev->instance,
  12770. + dev->component[MMAL_COMPONENT_CAMERA]);
  12771. + if (ret < 0)
  12772. + goto unreg_camera;
  12773. +
  12774. + format =
  12775. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12776. + output[MMAL_CAMERA_PORT_PREVIEW].format;
  12777. +
  12778. + format->encoding = MMAL_ENCODING_OPAQUE;
  12779. + format->encoding_variant = MMAL_ENCODING_I420;
  12780. +
  12781. + format->es->video.width = 1024;
  12782. + format->es->video.height = 768;
  12783. + format->es->video.crop.x = 0;
  12784. + format->es->video.crop.y = 0;
  12785. + format->es->video.crop.width = 1024;
  12786. + format->es->video.crop.height = 768;
  12787. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  12788. + format->es->video.frame_rate.den = 1;
  12789. +
  12790. + format =
  12791. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12792. + output[MMAL_CAMERA_PORT_VIDEO].format;
  12793. +
  12794. + format->encoding = MMAL_ENCODING_OPAQUE;
  12795. + format->encoding_variant = MMAL_ENCODING_I420;
  12796. +
  12797. + format->es->video.width = 1024;
  12798. + format->es->video.height = 768;
  12799. + format->es->video.crop.x = 0;
  12800. + format->es->video.crop.y = 0;
  12801. + format->es->video.crop.width = 1024;
  12802. + format->es->video.crop.height = 768;
  12803. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  12804. + format->es->video.frame_rate.den = 1;
  12805. +
  12806. + format =
  12807. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12808. + output[MMAL_CAMERA_PORT_CAPTURE].format;
  12809. +
  12810. + format->encoding = MMAL_ENCODING_OPAQUE;
  12811. +
  12812. + format->es->video.width = 2592;
  12813. + format->es->video.height = 1944;
  12814. + format->es->video.crop.x = 0;
  12815. + format->es->video.crop.y = 0;
  12816. + format->es->video.crop.width = 2592;
  12817. + format->es->video.crop.height = 1944;
  12818. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  12819. + format->es->video.frame_rate.den = 1;
  12820. +
  12821. + dev->capture.width = format->es->video.width;
  12822. + dev->capture.height = format->es->video.height;
  12823. + dev->capture.fmt = &formats[0];
  12824. + dev->capture.encode_component = NULL;
  12825. + dev->capture.timeperframe = tpf_default;
  12826. + dev->capture.enc_profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
  12827. + dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
  12828. +
  12829. + /* get the preview component ready */
  12830. + ret = vchiq_mmal_component_init(
  12831. + dev->instance, "ril.video_render",
  12832. + &dev->component[MMAL_COMPONENT_PREVIEW]);
  12833. + if (ret < 0)
  12834. + goto unreg_camera;
  12835. +
  12836. + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
  12837. + ret = -EINVAL;
  12838. + pr_debug("too few input ports %d needed %d\n",
  12839. + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
  12840. + goto unreg_preview;
  12841. + }
  12842. +
  12843. + /* get the image encoder component ready */
  12844. + ret = vchiq_mmal_component_init(
  12845. + dev->instance, "ril.image_encode",
  12846. + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12847. + if (ret < 0)
  12848. + goto unreg_preview;
  12849. +
  12850. + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
  12851. + ret = -EINVAL;
  12852. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  12853. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
  12854. + 1);
  12855. + goto unreg_image_encoder;
  12856. + }
  12857. +
  12858. + /* get the video encoder component ready */
  12859. + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
  12860. + &dev->
  12861. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12862. + if (ret < 0)
  12863. + goto unreg_image_encoder;
  12864. +
  12865. + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
  12866. + ret = -EINVAL;
  12867. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  12868. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
  12869. + 1);
  12870. + goto unreg_vid_encoder;
  12871. + }
  12872. +
  12873. + {
  12874. + struct vchiq_mmal_port *encoder_port =
  12875. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  12876. + encoder_port->format.encoding = MMAL_ENCODING_H264;
  12877. + ret = vchiq_mmal_port_set_format(dev->instance,
  12878. + encoder_port);
  12879. + }
  12880. +
  12881. + {
  12882. + unsigned int enable = 1;
  12883. + vchiq_mmal_port_parameter_set(
  12884. + dev->instance,
  12885. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  12886. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  12887. + &enable, sizeof(enable));
  12888. +
  12889. + vchiq_mmal_port_parameter_set(dev->instance,
  12890. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  12891. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  12892. + &enable,
  12893. + sizeof(enable));
  12894. + }
  12895. + ret = bm2835_mmal_set_all_camera_controls(dev);
  12896. + if (ret < 0)
  12897. + goto unreg_vid_encoder;
  12898. +
  12899. + return 0;
  12900. +
  12901. +unreg_vid_encoder:
  12902. + pr_err("Cleanup: Destroy video encoder\n");
  12903. + vchiq_mmal_component_finalise(
  12904. + dev->instance,
  12905. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12906. +
  12907. +unreg_image_encoder:
  12908. + pr_err("Cleanup: Destroy image encoder\n");
  12909. + vchiq_mmal_component_finalise(
  12910. + dev->instance,
  12911. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12912. +
  12913. +unreg_preview:
  12914. + pr_err("Cleanup: Destroy video render\n");
  12915. + vchiq_mmal_component_finalise(dev->instance,
  12916. + dev->component[MMAL_COMPONENT_PREVIEW]);
  12917. +
  12918. +unreg_camera:
  12919. + pr_err("Cleanup: Destroy camera\n");
  12920. + vchiq_mmal_component_finalise(dev->instance,
  12921. + dev->component[MMAL_COMPONENT_CAMERA]);
  12922. +
  12923. +unreg_mmal:
  12924. + vchiq_mmal_finalise(dev->instance);
  12925. + return ret;
  12926. +}
  12927. +
  12928. +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
  12929. + struct video_device *vfd)
  12930. +{
  12931. + int ret;
  12932. +
  12933. + *vfd = vdev_template;
  12934. +
  12935. + vfd->v4l2_dev = &dev->v4l2_dev;
  12936. +
  12937. + vfd->lock = &dev->mutex;
  12938. +
  12939. + vfd->queue = &dev->capture.vb_vidq;
  12940. +
  12941. + set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  12942. +
  12943. + /* video device needs to be able to access instance data */
  12944. + video_set_drvdata(vfd, dev);
  12945. +
  12946. + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  12947. + if (ret < 0)
  12948. + return ret;
  12949. +
  12950. + v4l2_info(vfd->v4l2_dev, "V4L2 device registered as %s\n",
  12951. + video_device_node_name(vfd));
  12952. +
  12953. + return 0;
  12954. +}
  12955. +
  12956. +static struct v4l2_format default_v4l2_format = {
  12957. + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  12958. + .fmt.pix.width = 1024,
  12959. + .fmt.pix.bytesperline = 1024 * 3 / 2,
  12960. + .fmt.pix.height = 768,
  12961. + .fmt.pix.sizeimage = 1<<18,
  12962. +};
  12963. +
  12964. +static int __init bm2835_mmal_init(void)
  12965. +{
  12966. + int ret;
  12967. + struct bm2835_mmal_dev *dev;
  12968. + struct vb2_queue *q;
  12969. +
  12970. + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  12971. + if (!dev)
  12972. + return -ENOMEM;
  12973. +
  12974. + /* setup device defaults */
  12975. + dev->overlay.w.left = 150;
  12976. + dev->overlay.w.top = 50;
  12977. + dev->overlay.w.width = 1024;
  12978. + dev->overlay.w.height = 768;
  12979. + dev->overlay.clipcount = 0;
  12980. + dev->overlay.field = V4L2_FIELD_NONE;
  12981. +
  12982. + dev->capture.fmt = &formats[3]; /* JPEG */
  12983. +
  12984. + /* v4l device registration */
  12985. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  12986. + "%s", BM2835_MMAL_MODULE_NAME);
  12987. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  12988. + if (ret)
  12989. + goto free_dev;
  12990. +
  12991. + /* setup v4l controls */
  12992. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  12993. + if (ret < 0)
  12994. + goto unreg_dev;
  12995. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  12996. +
  12997. + /* mmal init */
  12998. + ret = mmal_init(dev);
  12999. + if (ret < 0)
  13000. + goto unreg_dev;
  13001. +
  13002. + /* initialize queue */
  13003. + q = &dev->capture.vb_vidq;
  13004. + memset(q, 0, sizeof(*q));
  13005. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  13006. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  13007. + q->drv_priv = dev;
  13008. + q->buf_struct_size = sizeof(struct mmal_buffer);
  13009. + q->ops = &bm2835_mmal_video_qops;
  13010. + q->mem_ops = &vb2_vmalloc_memops;
  13011. + q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  13012. + ret = vb2_queue_init(q);
  13013. + if (ret < 0)
  13014. + goto unreg_dev;
  13015. +
  13016. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  13017. + mutex_init(&dev->mutex);
  13018. +
  13019. + /* initialise video devices */
  13020. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  13021. + if (ret < 0)
  13022. + goto unreg_dev;
  13023. +
  13024. + ret = mmal_setup_components(dev, &default_v4l2_format);
  13025. + if (ret < 0) {
  13026. + v4l2_err(&dev->v4l2_dev,
  13027. + "%s: could not setup components\n", __func__);
  13028. + goto unreg_dev;
  13029. + }
  13030. +
  13031. + v4l2_info(&dev->v4l2_dev,
  13032. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  13033. + BM2835_MMAL_VERSION);
  13034. +
  13035. + gdev = dev;
  13036. + return 0;
  13037. +
  13038. +unreg_dev:
  13039. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  13040. + v4l2_device_unregister(&dev->v4l2_dev);
  13041. +
  13042. +free_dev:
  13043. + kfree(dev);
  13044. +
  13045. + v4l2_err(&dev->v4l2_dev,
  13046. + "%s: error %d while loading driver\n",
  13047. + BM2835_MMAL_MODULE_NAME, ret);
  13048. +
  13049. + return ret;
  13050. +}
  13051. +
  13052. +static void __exit bm2835_mmal_exit(void)
  13053. +{
  13054. + if (!gdev)
  13055. + return;
  13056. +
  13057. + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  13058. + video_device_node_name(&gdev->vdev));
  13059. +
  13060. + video_unregister_device(&gdev->vdev);
  13061. +
  13062. + if (gdev->capture.encode_component) {
  13063. + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  13064. + "mmal_exit - disconnect tunnel\n");
  13065. + vchiq_mmal_port_connect_tunnel(gdev->instance,
  13066. + gdev->capture.camera_port, NULL);
  13067. + vchiq_mmal_component_disable(gdev->instance,
  13068. + gdev->capture.encode_component);
  13069. + }
  13070. + vchiq_mmal_component_disable(gdev->instance,
  13071. + gdev->component[MMAL_COMPONENT_CAMERA]);
  13072. +
  13073. + vchiq_mmal_component_finalise(gdev->instance,
  13074. + gdev->
  13075. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  13076. +
  13077. + vchiq_mmal_component_finalise(gdev->instance,
  13078. + gdev->
  13079. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  13080. +
  13081. + vchiq_mmal_component_finalise(gdev->instance,
  13082. + gdev->component[MMAL_COMPONENT_PREVIEW]);
  13083. +
  13084. + vchiq_mmal_component_finalise(gdev->instance,
  13085. + gdev->component[MMAL_COMPONENT_CAMERA]);
  13086. +
  13087. + vchiq_mmal_finalise(gdev->instance);
  13088. +
  13089. + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  13090. +
  13091. + v4l2_device_unregister(&gdev->v4l2_dev);
  13092. +
  13093. + kfree(gdev);
  13094. +}
  13095. +
  13096. +module_init(bm2835_mmal_init);
  13097. +module_exit(bm2835_mmal_exit);
  13098. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/bcm2835-camera.h linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h
  13099. --- linux-3.12.18/drivers/media/platform/bcm2835/bcm2835-camera.h 1970-01-01 01:00:00.000000000 +0100
  13100. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h 2014-04-24 15:35:02.713549510 +0200
  13101. @@ -0,0 +1,125 @@
  13102. +/*
  13103. + * Broadcom BM2835 V4L2 driver
  13104. + *
  13105. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13106. + *
  13107. + * This file is subject to the terms and conditions of the GNU General Public
  13108. + * License. See the file COPYING in the main directory of this archive
  13109. + * for more details.
  13110. + *
  13111. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13112. + * Dave Stevenson <dsteve@broadcom.com>
  13113. + * Simon Mellor <simellor@broadcom.com>
  13114. + * Luke Diamand <luked@broadcom.com>
  13115. + *
  13116. + * core driver device
  13117. + */
  13118. +
  13119. +#define V4L2_CTRL_COUNT 27 /* number of v4l controls */
  13120. +
  13121. +enum {
  13122. + MMAL_COMPONENT_CAMERA = 0,
  13123. + MMAL_COMPONENT_PREVIEW,
  13124. + MMAL_COMPONENT_IMAGE_ENCODE,
  13125. + MMAL_COMPONENT_VIDEO_ENCODE,
  13126. + MMAL_COMPONENT_COUNT
  13127. +};
  13128. +
  13129. +enum {
  13130. + MMAL_CAMERA_PORT_PREVIEW = 0,
  13131. + MMAL_CAMERA_PORT_VIDEO,
  13132. + MMAL_CAMERA_PORT_CAPTURE,
  13133. + MMAL_CAMERA_PORT_COUNT
  13134. +};
  13135. +
  13136. +#define PREVIEW_LAYER 2
  13137. +
  13138. +extern int bcm2835_v4l2_debug;
  13139. +
  13140. +struct bm2835_mmal_dev {
  13141. + /* v4l2 devices */
  13142. + struct v4l2_device v4l2_dev;
  13143. + struct video_device vdev;
  13144. + struct mutex mutex;
  13145. +
  13146. + /* controls */
  13147. + struct v4l2_ctrl_handler ctrl_handler;
  13148. + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  13149. + enum v4l2_scene_mode scene_mode;
  13150. + struct mmal_colourfx colourfx;
  13151. + int hflip;
  13152. + int vflip;
  13153. + int red_gain;
  13154. + int blue_gain;
  13155. + enum mmal_parameter_exposuremode exposure_mode_user;
  13156. + enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
  13157. + /* active exposure mode may differ if selected via a scene mode */
  13158. + enum mmal_parameter_exposuremode exposure_mode_active;
  13159. + enum mmal_parameter_exposuremeteringmode metering_mode;
  13160. + unsigned int manual_shutter_speed;
  13161. + bool exp_auto_priority;
  13162. +
  13163. + /* allocated mmal instance and components */
  13164. + struct vchiq_mmal_instance *instance;
  13165. + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
  13166. + int camera_use_count;
  13167. +
  13168. + struct v4l2_window overlay;
  13169. +
  13170. + struct {
  13171. + unsigned int width; /* width */
  13172. + unsigned int height; /* height */
  13173. + unsigned int stride; /* stride */
  13174. + struct mmal_fmt *fmt;
  13175. + struct v4l2_fract timeperframe;
  13176. +
  13177. + /* H264 encode bitrate */
  13178. + int encode_bitrate;
  13179. + /* H264 bitrate mode. CBR/VBR */
  13180. + int encode_bitrate_mode;
  13181. + /* H264 profile */
  13182. + enum v4l2_mpeg_video_h264_profile enc_profile;
  13183. + /* H264 level */
  13184. + enum v4l2_mpeg_video_h264_level enc_level;
  13185. + /* JPEG Q-factor */
  13186. + int q_factor;
  13187. +
  13188. + struct vb2_queue vb_vidq;
  13189. +
  13190. + /* VC start timestamp for streaming */
  13191. + s64 vc_start_timestamp;
  13192. + /* Kernel start timestamp for streaming */
  13193. + struct timeval kernel_start_ts;
  13194. +
  13195. + struct vchiq_mmal_port *port; /* port being used for capture */
  13196. + /* camera port being used for capture */
  13197. + struct vchiq_mmal_port *camera_port;
  13198. + /* component being used for encode */
  13199. + struct vchiq_mmal_component *encode_component;
  13200. + /* number of frames remaining which driver should capture */
  13201. + unsigned int frame_count;
  13202. + /* last frame completion */
  13203. + struct completion frame_cmplt;
  13204. +
  13205. + } capture;
  13206. +
  13207. +};
  13208. +
  13209. +int bm2835_mmal_init_controls(
  13210. + struct bm2835_mmal_dev *dev,
  13211. + struct v4l2_ctrl_handler *hdl);
  13212. +
  13213. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  13214. +int set_framerate_params(struct bm2835_mmal_dev *dev);
  13215. +
  13216. +/* Debug helpers */
  13217. +
  13218. +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
  13219. +{ \
  13220. + v4l2_dbg(level, debug, dev, \
  13221. +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
  13222. + desc == NULL ? "" : desc, \
  13223. + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
  13224. + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  13225. + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  13226. +}
  13227. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/controls.c linux-rpi/drivers/media/platform/bcm2835/controls.c
  13228. --- linux-3.12.18/drivers/media/platform/bcm2835/controls.c 1970-01-01 01:00:00.000000000 +0100
  13229. +++ linux-rpi/drivers/media/platform/bcm2835/controls.c 2014-04-24 15:35:02.713549510 +0200
  13230. @@ -0,0 +1,1315 @@
  13231. +/*
  13232. + * Broadcom BM2835 V4L2 driver
  13233. + *
  13234. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13235. + *
  13236. + * This file is subject to the terms and conditions of the GNU General Public
  13237. + * License. See the file COPYING in the main directory of this archive
  13238. + * for more details.
  13239. + *
  13240. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13241. + * Dave Stevenson <dsteve@broadcom.com>
  13242. + * Simon Mellor <simellor@broadcom.com>
  13243. + * Luke Diamand <luked@broadcom.com>
  13244. + */
  13245. +
  13246. +#include <linux/errno.h>
  13247. +#include <linux/kernel.h>
  13248. +#include <linux/module.h>
  13249. +#include <linux/slab.h>
  13250. +#include <media/videobuf2-vmalloc.h>
  13251. +#include <media/v4l2-device.h>
  13252. +#include <media/v4l2-ioctl.h>
  13253. +#include <media/v4l2-ctrls.h>
  13254. +#include <media/v4l2-fh.h>
  13255. +#include <media/v4l2-event.h>
  13256. +#include <media/v4l2-common.h>
  13257. +
  13258. +#include "mmal-common.h"
  13259. +#include "mmal-vchiq.h"
  13260. +#include "mmal-parameters.h"
  13261. +#include "bcm2835-camera.h"
  13262. +
  13263. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  13264. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  13265. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  13266. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  13267. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  13268. + * -4 to +4
  13269. + */
  13270. +static const s64 ev_bias_qmenu[] = {
  13271. + -4000, -3667, -3333,
  13272. + -3000, -2667, -2333,
  13273. + -2000, -1667, -1333,
  13274. + -1000, -667, -333,
  13275. + 0, 333, 667,
  13276. + 1000, 1333, 1667,
  13277. + 2000, 2333, 2667,
  13278. + 3000, 3333, 3667,
  13279. + 4000
  13280. +};
  13281. +
  13282. +/* Supported ISO values
  13283. + * ISOO = auto ISO
  13284. + */
  13285. +static const s64 iso_qmenu[] = {
  13286. + 0, 100, 200, 400, 800,
  13287. +};
  13288. +
  13289. +static const s64 mains_freq_qmenu[] = {
  13290. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  13291. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  13292. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  13293. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  13294. +};
  13295. +
  13296. +/* Supported video encode modes */
  13297. +static const s64 bitrate_mode_qmenu[] = {
  13298. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  13299. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  13300. +};
  13301. +
  13302. +enum bm2835_mmal_ctrl_type {
  13303. + MMAL_CONTROL_TYPE_STD,
  13304. + MMAL_CONTROL_TYPE_STD_MENU,
  13305. + MMAL_CONTROL_TYPE_INT_MENU,
  13306. + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
  13307. +};
  13308. +
  13309. +struct bm2835_mmal_v4l2_ctrl;
  13310. +
  13311. +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
  13312. + struct bm2835_mmal_dev *dev,
  13313. + struct v4l2_ctrl *ctrl,
  13314. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
  13315. +
  13316. +struct bm2835_mmal_v4l2_ctrl {
  13317. + u32 id; /* v4l2 control identifier */
  13318. + enum bm2835_mmal_ctrl_type type;
  13319. + /* control minimum value or
  13320. + * mask for MMAL_CONTROL_TYPE_STD_MENU */
  13321. + s32 min;
  13322. + s32 max; /* maximum value of control */
  13323. + s32 def; /* default value of control */
  13324. + s32 step; /* step size of the control */
  13325. + const s64 *imenu; /* integer menu array */
  13326. + u32 mmal_id; /* mmal parameter id */
  13327. + bm2835_mmal_v4l2_ctrl_cb *setter;
  13328. + bool ignore_errors;
  13329. +};
  13330. +
  13331. +struct v4l2_to_mmal_effects_setting {
  13332. + u32 v4l2_effect;
  13333. + u32 mmal_effect;
  13334. + s32 col_fx_enable;
  13335. + s32 col_fx_fixed_cbcr;
  13336. + u32 u;
  13337. + u32 v;
  13338. + u32 num_effect_params;
  13339. + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
  13340. +};
  13341. +
  13342. +static const struct v4l2_to_mmal_effects_setting
  13343. + v4l2_to_mmal_effects_values[] = {
  13344. + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
  13345. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13346. + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
  13347. + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
  13348. + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
  13349. + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
  13350. + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
  13351. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13352. + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
  13353. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13354. + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
  13355. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13356. + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
  13357. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13358. + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  13359. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13360. + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
  13361. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13362. + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
  13363. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13364. + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
  13365. + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
  13366. + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
  13367. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13368. + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
  13369. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13370. + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
  13371. + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
  13372. + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  13373. + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
  13374. + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
  13375. + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  13376. +};
  13377. +
  13378. +struct v4l2_mmal_scene_config {
  13379. + enum v4l2_scene_mode v4l2_scene;
  13380. + enum mmal_parameter_exposuremode exposure_mode;
  13381. + enum mmal_parameter_exposuremeteringmode metering_mode;
  13382. +};
  13383. +
  13384. +static const struct v4l2_mmal_scene_config scene_configs[] = {
  13385. + /* V4L2_SCENE_MODE_NONE automatically added */
  13386. + {
  13387. + V4L2_SCENE_MODE_NIGHT,
  13388. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  13389. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  13390. + },
  13391. + {
  13392. + V4L2_SCENE_MODE_SPORTS,
  13393. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  13394. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  13395. + },
  13396. +};
  13397. +
  13398. +/* control handlers*/
  13399. +
  13400. +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
  13401. + struct v4l2_ctrl *ctrl,
  13402. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13403. +{
  13404. + struct mmal_parameter_rational rational_value;
  13405. + struct vchiq_mmal_port *control;
  13406. +
  13407. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13408. +
  13409. + rational_value.num = ctrl->val;
  13410. + rational_value.den = 100;
  13411. +
  13412. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13413. + mmal_ctrl->mmal_id,
  13414. + &rational_value,
  13415. + sizeof(rational_value));
  13416. +}
  13417. +
  13418. +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
  13419. + struct v4l2_ctrl *ctrl,
  13420. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13421. +{
  13422. + u32 u32_value;
  13423. + struct vchiq_mmal_port *control;
  13424. +
  13425. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13426. +
  13427. + u32_value = ctrl->val;
  13428. +
  13429. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13430. + mmal_ctrl->mmal_id,
  13431. + &u32_value, sizeof(u32_value));
  13432. +}
  13433. +
  13434. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  13435. + struct v4l2_ctrl *ctrl,
  13436. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13437. +{
  13438. + u32 u32_value;
  13439. + struct vchiq_mmal_port *control;
  13440. +
  13441. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  13442. + return 1;
  13443. +
  13444. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13445. +
  13446. + u32_value = mmal_ctrl->imenu[ctrl->val];
  13447. +
  13448. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13449. + mmal_ctrl->mmal_id,
  13450. + &u32_value, sizeof(u32_value));
  13451. +}
  13452. +
  13453. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  13454. + struct v4l2_ctrl *ctrl,
  13455. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13456. +{
  13457. + s32 s32_value;
  13458. + struct vchiq_mmal_port *control;
  13459. +
  13460. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13461. +
  13462. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  13463. +
  13464. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13465. + mmal_ctrl->mmal_id,
  13466. + &s32_value, sizeof(s32_value));
  13467. +}
  13468. +
  13469. +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  13470. + struct v4l2_ctrl *ctrl,
  13471. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13472. +{
  13473. + int ret;
  13474. + u32 u32_value;
  13475. + struct vchiq_mmal_component *camera;
  13476. +
  13477. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  13478. +
  13479. + u32_value = ((ctrl->val % 360) / 90) * 90;
  13480. +
  13481. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  13482. + mmal_ctrl->mmal_id,
  13483. + &u32_value, sizeof(u32_value));
  13484. + if (ret < 0)
  13485. + return ret;
  13486. +
  13487. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  13488. + mmal_ctrl->mmal_id,
  13489. + &u32_value, sizeof(u32_value));
  13490. + if (ret < 0)
  13491. + return ret;
  13492. +
  13493. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  13494. + mmal_ctrl->mmal_id,
  13495. + &u32_value, sizeof(u32_value));
  13496. +
  13497. + return ret;
  13498. +}
  13499. +
  13500. +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
  13501. + struct v4l2_ctrl *ctrl,
  13502. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13503. +{
  13504. + int ret;
  13505. + u32 u32_value;
  13506. + struct vchiq_mmal_component *camera;
  13507. +
  13508. + if (ctrl->id == V4L2_CID_HFLIP)
  13509. + dev->hflip = ctrl->val;
  13510. + else
  13511. + dev->vflip = ctrl->val;
  13512. +
  13513. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  13514. +
  13515. + if (dev->hflip && dev->vflip)
  13516. + u32_value = MMAL_PARAM_MIRROR_BOTH;
  13517. + else if (dev->hflip)
  13518. + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
  13519. + else if (dev->vflip)
  13520. + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
  13521. + else
  13522. + u32_value = MMAL_PARAM_MIRROR_NONE;
  13523. +
  13524. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  13525. + mmal_ctrl->mmal_id,
  13526. + &u32_value, sizeof(u32_value));
  13527. + if (ret < 0)
  13528. + return ret;
  13529. +
  13530. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  13531. + mmal_ctrl->mmal_id,
  13532. + &u32_value, sizeof(u32_value));
  13533. + if (ret < 0)
  13534. + return ret;
  13535. +
  13536. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  13537. + mmal_ctrl->mmal_id,
  13538. + &u32_value, sizeof(u32_value));
  13539. +
  13540. + return ret;
  13541. +
  13542. +}
  13543. +
  13544. +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
  13545. + struct v4l2_ctrl *ctrl,
  13546. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13547. +{
  13548. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode_user;
  13549. + u32 shutter_speed = 0;
  13550. + struct vchiq_mmal_port *control;
  13551. + int ret = 0;
  13552. +
  13553. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13554. +
  13555. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  13556. + /* V4L2 is in 100usec increments.
  13557. + * MMAL is 1usec.
  13558. + */
  13559. + dev->manual_shutter_speed = ctrl->val * 100;
  13560. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  13561. + switch (ctrl->val) {
  13562. + case V4L2_EXPOSURE_AUTO:
  13563. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  13564. + break;
  13565. +
  13566. + case V4L2_EXPOSURE_MANUAL:
  13567. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  13568. + break;
  13569. + }
  13570. + dev->exposure_mode_user = exp_mode;
  13571. + dev->exposure_mode_v4l2_user = ctrl->val;
  13572. + } else if (mmal_ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
  13573. + dev->exp_auto_priority = ctrl->val;
  13574. + }
  13575. +
  13576. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  13577. + if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  13578. + shutter_speed = dev->manual_shutter_speed;
  13579. +
  13580. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  13581. + control,
  13582. + MMAL_PARAMETER_SHUTTER_SPEED,
  13583. + &shutter_speed,
  13584. + sizeof(shutter_speed));
  13585. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13586. + control,
  13587. + MMAL_PARAMETER_EXPOSURE_MODE,
  13588. + &exp_mode,
  13589. + sizeof(u32));
  13590. + dev->exposure_mode_active = exp_mode;
  13591. + }
  13592. + /* exposure_dynamic_framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY) should
  13593. + * always apply irrespective of scene mode.
  13594. + */
  13595. + ret += set_framerate_params(dev);
  13596. +
  13597. + return ret;
  13598. +}
  13599. +
  13600. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  13601. + struct v4l2_ctrl *ctrl,
  13602. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13603. +{
  13604. + switch (ctrl->val) {
  13605. + case V4L2_EXPOSURE_METERING_AVERAGE:
  13606. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  13607. + break;
  13608. +
  13609. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  13610. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  13611. + break;
  13612. +
  13613. + case V4L2_EXPOSURE_METERING_SPOT:
  13614. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  13615. + break;
  13616. +
  13617. + /* todo matrix weighting not added to Linux API till 3.9
  13618. + case V4L2_EXPOSURE_METERING_MATRIX:
  13619. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  13620. + break;
  13621. + */
  13622. +
  13623. + }
  13624. +
  13625. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  13626. + struct vchiq_mmal_port *control;
  13627. + u32 u32_value = dev->metering_mode;
  13628. +
  13629. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13630. +
  13631. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13632. + mmal_ctrl->mmal_id,
  13633. + &u32_value, sizeof(u32_value));
  13634. + } else
  13635. + return 0;
  13636. +}
  13637. +
  13638. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  13639. + struct v4l2_ctrl *ctrl,
  13640. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13641. +{
  13642. + u32 u32_value;
  13643. + struct vchiq_mmal_port *control;
  13644. +
  13645. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13646. +
  13647. + switch (ctrl->val) {
  13648. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  13649. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  13650. + break;
  13651. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  13652. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  13653. + break;
  13654. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  13655. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  13656. + break;
  13657. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  13658. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  13659. + break;
  13660. + }
  13661. +
  13662. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13663. + mmal_ctrl->mmal_id,
  13664. + &u32_value, sizeof(u32_value));
  13665. +}
  13666. +
  13667. +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
  13668. + struct v4l2_ctrl *ctrl,
  13669. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13670. +{
  13671. + u32 u32_value;
  13672. + struct vchiq_mmal_port *control;
  13673. +
  13674. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13675. +
  13676. + switch (ctrl->val) {
  13677. + case V4L2_WHITE_BALANCE_MANUAL:
  13678. + u32_value = MMAL_PARAM_AWBMODE_OFF;
  13679. + break;
  13680. +
  13681. + case V4L2_WHITE_BALANCE_AUTO:
  13682. + u32_value = MMAL_PARAM_AWBMODE_AUTO;
  13683. + break;
  13684. +
  13685. + case V4L2_WHITE_BALANCE_INCANDESCENT:
  13686. + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
  13687. + break;
  13688. +
  13689. + case V4L2_WHITE_BALANCE_FLUORESCENT:
  13690. + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
  13691. + break;
  13692. +
  13693. + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
  13694. + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
  13695. + break;
  13696. +
  13697. + case V4L2_WHITE_BALANCE_HORIZON:
  13698. + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
  13699. + break;
  13700. +
  13701. + case V4L2_WHITE_BALANCE_DAYLIGHT:
  13702. + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
  13703. + break;
  13704. +
  13705. + case V4L2_WHITE_BALANCE_FLASH:
  13706. + u32_value = MMAL_PARAM_AWBMODE_FLASH;
  13707. + break;
  13708. +
  13709. + case V4L2_WHITE_BALANCE_CLOUDY:
  13710. + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
  13711. + break;
  13712. +
  13713. + case V4L2_WHITE_BALANCE_SHADE:
  13714. + u32_value = MMAL_PARAM_AWBMODE_SHADE;
  13715. + break;
  13716. +
  13717. + }
  13718. +
  13719. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13720. + mmal_ctrl->mmal_id,
  13721. + &u32_value, sizeof(u32_value));
  13722. +}
  13723. +
  13724. +static int ctrl_set_awb_gains(struct bm2835_mmal_dev *dev,
  13725. + struct v4l2_ctrl *ctrl,
  13726. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13727. +{
  13728. + struct vchiq_mmal_port *control;
  13729. + struct mmal_parameter_awbgains gains;
  13730. +
  13731. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13732. +
  13733. + if (ctrl->id == V4L2_CID_RED_BALANCE)
  13734. + dev->red_gain = ctrl->val;
  13735. + else if (ctrl->id == V4L2_CID_BLUE_BALANCE)
  13736. + dev->blue_gain = ctrl->val;
  13737. +
  13738. + gains.r_gain.num = dev->red_gain;
  13739. + gains.b_gain.num = dev->blue_gain;
  13740. + gains.r_gain.den = gains.b_gain.den = 1000;
  13741. +
  13742. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13743. + mmal_ctrl->mmal_id,
  13744. + &gains, sizeof(gains));
  13745. +}
  13746. +
  13747. +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  13748. + struct v4l2_ctrl *ctrl,
  13749. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13750. +{
  13751. + int ret = -EINVAL;
  13752. + int i, j;
  13753. + struct vchiq_mmal_port *control;
  13754. + struct mmal_parameter_imagefx_parameters imagefx;
  13755. +
  13756. + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
  13757. + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
  13758. +
  13759. + imagefx.effect =
  13760. + v4l2_to_mmal_effects_values[i].mmal_effect;
  13761. + imagefx.num_effect_params =
  13762. + v4l2_to_mmal_effects_values[i].num_effect_params;
  13763. +
  13764. + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
  13765. + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
  13766. +
  13767. + for (j = 0; j < imagefx.num_effect_params; j++)
  13768. + imagefx.effect_parameter[j] =
  13769. + v4l2_to_mmal_effects_values[i].effect_params[j];
  13770. +
  13771. + dev->colourfx.enable =
  13772. + v4l2_to_mmal_effects_values[i].col_fx_enable;
  13773. + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
  13774. + dev->colourfx.u =
  13775. + v4l2_to_mmal_effects_values[i].u;
  13776. + dev->colourfx.v =
  13777. + v4l2_to_mmal_effects_values[i].v;
  13778. + }
  13779. +
  13780. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13781. +
  13782. + ret = vchiq_mmal_port_parameter_set(
  13783. + dev->instance, control,
  13784. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  13785. + &imagefx, sizeof(imagefx));
  13786. + if (ret)
  13787. + goto exit;
  13788. +
  13789. + ret = vchiq_mmal_port_parameter_set(
  13790. + dev->instance, control,
  13791. + MMAL_PARAMETER_COLOUR_EFFECT,
  13792. + &dev->colourfx, sizeof(dev->colourfx));
  13793. + }
  13794. + }
  13795. +
  13796. +exit:
  13797. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13798. + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
  13799. + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
  13800. + dev->colourfx.enable ? "true" : "false",
  13801. + dev->colourfx.u, dev->colourfx.v,
  13802. + ret, (ret == 0 ? 0 : -EINVAL));
  13803. + return (ret == 0 ? 0 : EINVAL);
  13804. +}
  13805. +
  13806. +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
  13807. + struct v4l2_ctrl *ctrl,
  13808. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13809. +{
  13810. + int ret = -EINVAL;
  13811. + struct vchiq_mmal_port *control;
  13812. +
  13813. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13814. +
  13815. + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
  13816. + dev->colourfx.enable = ctrl->val & 0xff;
  13817. +
  13818. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  13819. + MMAL_PARAMETER_COLOUR_EFFECT,
  13820. + &dev->colourfx, sizeof(dev->colourfx));
  13821. +
  13822. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13823. + "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  13824. + __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
  13825. + (ret == 0 ? 0 : -EINVAL));
  13826. + return (ret == 0 ? 0 : EINVAL);
  13827. +}
  13828. +
  13829. +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
  13830. + struct v4l2_ctrl *ctrl,
  13831. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13832. +{
  13833. + int ret;
  13834. + struct vchiq_mmal_port *encoder_out;
  13835. +
  13836. + dev->capture.encode_bitrate = ctrl->val;
  13837. +
  13838. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13839. +
  13840. + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  13841. + mmal_ctrl->mmal_id,
  13842. + &ctrl->val, sizeof(ctrl->val));
  13843. + ret = 0;
  13844. + return ret;
  13845. +}
  13846. +
  13847. +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
  13848. + struct v4l2_ctrl *ctrl,
  13849. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13850. +{
  13851. + u32 bitrate_mode;
  13852. + struct vchiq_mmal_port *encoder_out;
  13853. +
  13854. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13855. +
  13856. + dev->capture.encode_bitrate_mode = ctrl->val;
  13857. + switch (ctrl->val) {
  13858. + default:
  13859. + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
  13860. + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
  13861. + break;
  13862. + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
  13863. + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
  13864. + break;
  13865. + }
  13866. +
  13867. + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  13868. + mmal_ctrl->mmal_id,
  13869. + &bitrate_mode,
  13870. + sizeof(bitrate_mode));
  13871. + return 0;
  13872. +}
  13873. +
  13874. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  13875. + struct v4l2_ctrl *ctrl,
  13876. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13877. +{
  13878. + u32 u32_value;
  13879. + struct vchiq_mmal_port *jpeg_out;
  13880. +
  13881. + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  13882. +
  13883. + u32_value = ctrl->val;
  13884. +
  13885. + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
  13886. + mmal_ctrl->mmal_id,
  13887. + &u32_value, sizeof(u32_value));
  13888. +}
  13889. +
  13890. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  13891. + struct v4l2_ctrl *ctrl,
  13892. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13893. +{
  13894. + u32 u32_value;
  13895. + struct vchiq_mmal_port *vid_enc_ctl;
  13896. +
  13897. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13898. +
  13899. + u32_value = ctrl->val;
  13900. +
  13901. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  13902. + mmal_ctrl->mmal_id,
  13903. + &u32_value, sizeof(u32_value));
  13904. +}
  13905. +
  13906. +static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
  13907. + struct v4l2_ctrl *ctrl,
  13908. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13909. +{
  13910. + struct mmal_parameter_video_profile param;
  13911. + int ret = 0;
  13912. +
  13913. + if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
  13914. + switch (ctrl->val) {
  13915. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  13916. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  13917. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  13918. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  13919. + dev->capture.enc_profile = ctrl->val;
  13920. + break;
  13921. + default:
  13922. + ret = -EINVAL;
  13923. + break;
  13924. + }
  13925. + } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
  13926. + switch (ctrl->val) {
  13927. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  13928. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  13929. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  13930. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  13931. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  13932. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  13933. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  13934. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  13935. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  13936. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  13937. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  13938. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  13939. + dev->capture.enc_level = ctrl->val;
  13940. + break;
  13941. + default:
  13942. + ret = -EINVAL;
  13943. + break;
  13944. + }
  13945. + }
  13946. +
  13947. + if (!ret) {
  13948. + switch (dev->capture.enc_profile) {
  13949. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  13950. + param.profile = MMAL_VIDEO_PROFILE_H264_BASELINE;
  13951. + break;
  13952. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  13953. + param.profile =
  13954. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;
  13955. + break;
  13956. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  13957. + param.profile = MMAL_VIDEO_PROFILE_H264_MAIN;
  13958. + break;
  13959. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  13960. + param.profile = MMAL_VIDEO_PROFILE_H264_HIGH;
  13961. + break;
  13962. + default:
  13963. + /* Should never get here */
  13964. + break;
  13965. + }
  13966. +
  13967. + switch (dev->capture.enc_level) {
  13968. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  13969. + param.level = MMAL_VIDEO_LEVEL_H264_1;
  13970. + break;
  13971. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  13972. + param.level = MMAL_VIDEO_LEVEL_H264_1b;
  13973. + break;
  13974. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  13975. + param.level = MMAL_VIDEO_LEVEL_H264_11;
  13976. + break;
  13977. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  13978. + param.level = MMAL_VIDEO_LEVEL_H264_12;
  13979. + break;
  13980. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  13981. + param.level = MMAL_VIDEO_LEVEL_H264_13;
  13982. + break;
  13983. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  13984. + param.level = MMAL_VIDEO_LEVEL_H264_2;
  13985. + break;
  13986. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  13987. + param.level = MMAL_VIDEO_LEVEL_H264_21;
  13988. + break;
  13989. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  13990. + param.level = MMAL_VIDEO_LEVEL_H264_22;
  13991. + break;
  13992. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  13993. + param.level = MMAL_VIDEO_LEVEL_H264_3;
  13994. + break;
  13995. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  13996. + param.level = MMAL_VIDEO_LEVEL_H264_31;
  13997. + break;
  13998. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  13999. + param.level = MMAL_VIDEO_LEVEL_H264_32;
  14000. + break;
  14001. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  14002. + param.level = MMAL_VIDEO_LEVEL_H264_4;
  14003. + break;
  14004. + default:
  14005. + /* Should never get here */
  14006. + break;
  14007. + }
  14008. +
  14009. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  14010. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
  14011. + mmal_ctrl->mmal_id,
  14012. + &param, sizeof(param));
  14013. + }
  14014. + return ret;
  14015. +}
  14016. +
  14017. +static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
  14018. + struct v4l2_ctrl *ctrl,
  14019. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14020. +{
  14021. + int ret = 0;
  14022. + int shutter_speed;
  14023. + struct vchiq_mmal_port *control;
  14024. +
  14025. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14026. + "scene mode selected %d, was %d\n", ctrl->val,
  14027. + dev->scene_mode);
  14028. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14029. +
  14030. + if (ctrl->val == dev->scene_mode)
  14031. + return 0;
  14032. +
  14033. + if (ctrl->val == V4L2_SCENE_MODE_NONE) {
  14034. + /* Restore all user selections */
  14035. + dev->scene_mode = V4L2_SCENE_MODE_NONE;
  14036. +
  14037. + if (dev->exposure_mode_user == MMAL_PARAM_EXPOSUREMODE_OFF)
  14038. + shutter_speed = dev->manual_shutter_speed;
  14039. + else
  14040. + shutter_speed = 0;
  14041. +
  14042. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14043. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  14044. + __func__, shutter_speed, dev->exposure_mode_user,
  14045. + dev->metering_mode);
  14046. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  14047. + control,
  14048. + MMAL_PARAMETER_SHUTTER_SPEED,
  14049. + &shutter_speed,
  14050. + sizeof(shutter_speed));
  14051. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14052. + control,
  14053. + MMAL_PARAMETER_EXPOSURE_MODE,
  14054. + &dev->exposure_mode_user,
  14055. + sizeof(u32));
  14056. + dev->exposure_mode_active = dev->exposure_mode_user;
  14057. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14058. + control,
  14059. + MMAL_PARAMETER_EXP_METERING_MODE,
  14060. + &dev->metering_mode,
  14061. + sizeof(u32));
  14062. + ret += set_framerate_params(dev);
  14063. + } else {
  14064. + /* Set up scene mode */
  14065. + int i;
  14066. + const struct v4l2_mmal_scene_config *scene = NULL;
  14067. + int shutter_speed;
  14068. + enum mmal_parameter_exposuremode exposure_mode;
  14069. + enum mmal_parameter_exposuremeteringmode metering_mode;
  14070. +
  14071. + for (i = 0; i < ARRAY_SIZE(scene_configs); i++) {
  14072. + if (scene_configs[i].v4l2_scene ==
  14073. + ctrl->val) {
  14074. + scene = &scene_configs[i];
  14075. + break;
  14076. + }
  14077. + }
  14078. + if (i >= ARRAY_SIZE(scene_configs))
  14079. + return -EINVAL;
  14080. +
  14081. + /* Set all the values */
  14082. + dev->scene_mode = ctrl->val;
  14083. +
  14084. + if (scene->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  14085. + shutter_speed = dev->manual_shutter_speed;
  14086. + else
  14087. + shutter_speed = 0;
  14088. + exposure_mode = scene->exposure_mode;
  14089. + metering_mode = scene->metering_mode;
  14090. +
  14091. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14092. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  14093. + __func__, shutter_speed, exposure_mode, metering_mode);
  14094. +
  14095. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  14096. + MMAL_PARAMETER_SHUTTER_SPEED,
  14097. + &shutter_speed,
  14098. + sizeof(shutter_speed));
  14099. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14100. + control,
  14101. + MMAL_PARAMETER_EXPOSURE_MODE,
  14102. + &exposure_mode,
  14103. + sizeof(u32));
  14104. + dev->exposure_mode_active = exposure_mode;
  14105. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  14106. + MMAL_PARAMETER_EXPOSURE_MODE,
  14107. + &exposure_mode,
  14108. + sizeof(u32));
  14109. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  14110. + MMAL_PARAMETER_EXP_METERING_MODE,
  14111. + &metering_mode,
  14112. + sizeof(u32));
  14113. + ret += set_framerate_params(dev);
  14114. + }
  14115. + if (ret) {
  14116. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14117. + "%s: Setting scene to %d, ret=%d\n",
  14118. + __func__, ctrl->val, ret);
  14119. + ret = -EINVAL;
  14120. + }
  14121. + return 0;
  14122. +}
  14123. +
  14124. +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  14125. +{
  14126. + struct bm2835_mmal_dev *dev =
  14127. + container_of(ctrl->handler, struct bm2835_mmal_dev,
  14128. + ctrl_handler);
  14129. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  14130. + int ret;
  14131. +
  14132. + if ((mmal_ctrl == NULL) ||
  14133. + (mmal_ctrl->id != ctrl->id) ||
  14134. + (mmal_ctrl->setter == NULL)) {
  14135. + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
  14136. + return -EINVAL;
  14137. + }
  14138. +
  14139. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  14140. + if (ret)
  14141. + pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n",
  14142. + ctrl->id, mmal_ctrl->mmal_id, ret);
  14143. + if (mmal_ctrl->ignore_errors)
  14144. + ret = 0;
  14145. + return ret;
  14146. +}
  14147. +
  14148. +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  14149. + .s_ctrl = bm2835_mmal_s_ctrl,
  14150. +};
  14151. +
  14152. +
  14153. +
  14154. +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
  14155. + {
  14156. + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  14157. + -100, 100, 0, 1, NULL,
  14158. + MMAL_PARAMETER_SATURATION,
  14159. + &ctrl_set_rational,
  14160. + false
  14161. + },
  14162. + {
  14163. + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  14164. + -100, 100, 0, 1, NULL,
  14165. + MMAL_PARAMETER_SHARPNESS,
  14166. + &ctrl_set_rational,
  14167. + false
  14168. + },
  14169. + {
  14170. + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  14171. + -100, 100, 0, 1, NULL,
  14172. + MMAL_PARAMETER_CONTRAST,
  14173. + &ctrl_set_rational,
  14174. + false
  14175. + },
  14176. + {
  14177. + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  14178. + 0, 100, 50, 1, NULL,
  14179. + MMAL_PARAMETER_BRIGHTNESS,
  14180. + &ctrl_set_rational,
  14181. + false
  14182. + },
  14183. + {
  14184. + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  14185. + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  14186. + MMAL_PARAMETER_ISO,
  14187. + &ctrl_set_value_menu,
  14188. + false
  14189. + },
  14190. + {
  14191. + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  14192. + 0, 1, 0, 1, NULL,
  14193. + MMAL_PARAMETER_VIDEO_STABILISATION,
  14194. + &ctrl_set_value,
  14195. + false
  14196. + },
  14197. +/* {
  14198. + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  14199. + },
  14200. +*/ {
  14201. + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  14202. + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  14203. + MMAL_PARAMETER_EXPOSURE_MODE,
  14204. + &ctrl_set_exposure,
  14205. + false
  14206. + },
  14207. +/* todo this needs mixing in with set exposure
  14208. + {
  14209. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  14210. + },
  14211. + */
  14212. + {
  14213. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  14214. + /* Units of 100usecs */
  14215. + 1, 1*1000*10, 100*10, 1, NULL,
  14216. + MMAL_PARAMETER_SHUTTER_SPEED,
  14217. + &ctrl_set_exposure,
  14218. + false
  14219. + },
  14220. + {
  14221. + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  14222. + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  14223. + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  14224. + MMAL_PARAMETER_EXPOSURE_COMP,
  14225. + &ctrl_set_value_ev,
  14226. + false
  14227. + },
  14228. + {
  14229. + V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD,
  14230. + 0, 1,
  14231. + 0, 1, NULL,
  14232. + 0, /* Dummy MMAL ID as it gets mapped into FPS range*/
  14233. + &ctrl_set_exposure,
  14234. + false
  14235. + },
  14236. + {
  14237. + V4L2_CID_EXPOSURE_METERING,
  14238. + MMAL_CONTROL_TYPE_STD_MENU,
  14239. + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  14240. + MMAL_PARAMETER_EXP_METERING_MODE,
  14241. + &ctrl_set_metering_mode,
  14242. + false
  14243. + },
  14244. + {
  14245. + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  14246. + MMAL_CONTROL_TYPE_STD_MENU,
  14247. + ~0x3ff, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  14248. + MMAL_PARAMETER_AWB_MODE,
  14249. + &ctrl_set_awb_mode,
  14250. + false
  14251. + },
  14252. + {
  14253. + V4L2_CID_RED_BALANCE, MMAL_CONTROL_TYPE_STD,
  14254. + 1, 7999, 1000, 1, NULL,
  14255. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  14256. + &ctrl_set_awb_gains,
  14257. + false
  14258. + },
  14259. + {
  14260. + V4L2_CID_BLUE_BALANCE, MMAL_CONTROL_TYPE_STD,
  14261. + 1, 7999, 1000, 1, NULL,
  14262. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  14263. + &ctrl_set_awb_gains,
  14264. + false
  14265. + },
  14266. + {
  14267. + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  14268. + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  14269. + MMAL_PARAMETER_IMAGE_EFFECT,
  14270. + &ctrl_set_image_effect,
  14271. + false
  14272. + },
  14273. + {
  14274. + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  14275. + 0, 0xffff, 0x8080, 1, NULL,
  14276. + MMAL_PARAMETER_COLOUR_EFFECT,
  14277. + &ctrl_set_colfx,
  14278. + false
  14279. + },
  14280. + {
  14281. + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  14282. + 0, 360, 0, 90, NULL,
  14283. + MMAL_PARAMETER_ROTATION,
  14284. + &ctrl_set_rotate,
  14285. + false
  14286. + },
  14287. + {
  14288. + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  14289. + 0, 1, 0, 1, NULL,
  14290. + MMAL_PARAMETER_MIRROR,
  14291. + &ctrl_set_flip,
  14292. + false
  14293. + },
  14294. + {
  14295. + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  14296. + 0, 1, 0, 1, NULL,
  14297. + MMAL_PARAMETER_MIRROR,
  14298. + &ctrl_set_flip,
  14299. + false
  14300. + },
  14301. + {
  14302. + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  14303. + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  14304. + 0, 0, bitrate_mode_qmenu,
  14305. + MMAL_PARAMETER_RATECONTROL,
  14306. + &ctrl_set_bitrate_mode,
  14307. + false
  14308. + },
  14309. + {
  14310. + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  14311. + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  14312. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  14313. + &ctrl_set_bitrate,
  14314. + false
  14315. + },
  14316. + {
  14317. + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  14318. + 1, 100,
  14319. + 30, 1, NULL,
  14320. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  14321. + &ctrl_set_image_encode_output,
  14322. + false
  14323. + },
  14324. + {
  14325. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  14326. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  14327. + 1, 1, NULL,
  14328. + MMAL_PARAMETER_FLICKER_AVOID,
  14329. + &ctrl_set_flicker_avoidance,
  14330. + false
  14331. + },
  14332. + {
  14333. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  14334. + 0, 1,
  14335. + 0, 1, NULL,
  14336. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  14337. + &ctrl_set_video_encode_param_output,
  14338. + true /* Errors ignored as requires latest firmware to work */
  14339. + },
  14340. + {
  14341. + V4L2_CID_MPEG_VIDEO_H264_PROFILE,
  14342. + MMAL_CONTROL_TYPE_STD_MENU,
  14343. + ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
  14344. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
  14345. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
  14346. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
  14347. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
  14348. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
  14349. + MMAL_PARAMETER_PROFILE,
  14350. + &ctrl_set_video_encode_profile_level,
  14351. + false
  14352. + },
  14353. + {
  14354. + V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
  14355. + ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
  14356. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
  14357. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
  14358. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
  14359. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
  14360. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
  14361. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
  14362. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
  14363. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
  14364. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
  14365. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
  14366. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
  14367. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
  14368. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
  14369. + MMAL_PARAMETER_PROFILE,
  14370. + &ctrl_set_video_encode_profile_level,
  14371. + false
  14372. + },
  14373. + {
  14374. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  14375. + -1, /* Min is computed at runtime */
  14376. + V4L2_SCENE_MODE_TEXT,
  14377. + V4L2_SCENE_MODE_NONE, 1, NULL,
  14378. + MMAL_PARAMETER_PROFILE,
  14379. + &ctrl_set_scene_mode,
  14380. + false
  14381. + },
  14382. +};
  14383. +
  14384. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  14385. +{
  14386. + int c;
  14387. + int ret = 0;
  14388. +
  14389. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  14390. + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  14391. + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  14392. + &v4l2_ctrls[c]);
  14393. + if (!v4l2_ctrls[c].ignore_errors && ret) {
  14394. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14395. + "Failed when setting default values for ctrl %d\n",
  14396. + c);
  14397. + break;
  14398. + }
  14399. + }
  14400. + }
  14401. + return ret;
  14402. +}
  14403. +
  14404. +int set_framerate_params(struct bm2835_mmal_dev *dev)
  14405. +{
  14406. + struct mmal_parameter_fps_range fps_range;
  14407. + int ret;
  14408. +
  14409. + if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) &&
  14410. + (dev->exp_auto_priority)) {
  14411. + /* Variable FPS. Define min FPS as 1fps.
  14412. + * Max as max defined FPS.
  14413. + */
  14414. + fps_range.fps_low.num = 1;
  14415. + fps_range.fps_low.den = 1;
  14416. + fps_range.fps_high.num = dev->capture.timeperframe.denominator;
  14417. + fps_range.fps_high.den = dev->capture.timeperframe.numerator;
  14418. + } else {
  14419. + /* Fixed FPS - set min and max to be the same */
  14420. + fps_range.fps_low.num = fps_range.fps_high.num =
  14421. + dev->capture.timeperframe.denominator;
  14422. + fps_range.fps_low.den = fps_range.fps_high.den =
  14423. + dev->capture.timeperframe.numerator;
  14424. + }
  14425. +
  14426. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14427. + "Set fps range to %d/%d to %d/%d\n",
  14428. + fps_range.fps_low.num,
  14429. + fps_range.fps_low.den,
  14430. + fps_range.fps_high.num,
  14431. + fps_range.fps_high.den
  14432. + );
  14433. +
  14434. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  14435. + &dev->component[MMAL_COMPONENT_CAMERA]->
  14436. + output[MMAL_CAMERA_PORT_PREVIEW],
  14437. + MMAL_PARAMETER_FPS_RANGE,
  14438. + &fps_range, sizeof(fps_range));
  14439. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14440. + &dev->component[MMAL_COMPONENT_CAMERA]->
  14441. + output[MMAL_CAMERA_PORT_VIDEO],
  14442. + MMAL_PARAMETER_FPS_RANGE,
  14443. + &fps_range, sizeof(fps_range));
  14444. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14445. + &dev->component[MMAL_COMPONENT_CAMERA]->
  14446. + output[MMAL_CAMERA_PORT_CAPTURE],
  14447. + MMAL_PARAMETER_FPS_RANGE,
  14448. + &fps_range, sizeof(fps_range));
  14449. + if (ret)
  14450. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14451. + "Failed to set fps ret %d\n",
  14452. + ret);
  14453. +
  14454. + return ret;
  14455. +
  14456. +}
  14457. +
  14458. +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  14459. + struct v4l2_ctrl_handler *hdl)
  14460. +{
  14461. + int c;
  14462. + const struct bm2835_mmal_v4l2_ctrl *ctrl;
  14463. +
  14464. + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
  14465. +
  14466. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  14467. + ctrl = &v4l2_ctrls[c];
  14468. +
  14469. + switch (ctrl->type) {
  14470. + case MMAL_CONTROL_TYPE_STD:
  14471. + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
  14472. + &bm2835_mmal_ctrl_ops, ctrl->id,
  14473. + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
  14474. + break;
  14475. +
  14476. + case MMAL_CONTROL_TYPE_STD_MENU:
  14477. + {
  14478. + int mask = ctrl->min;
  14479. +
  14480. + if (ctrl->id == V4L2_CID_SCENE_MODE) {
  14481. + /* Special handling to work out the mask
  14482. + * value based on the scene_configs array
  14483. + * at runtime. Reduces the chance of
  14484. + * mismatches.
  14485. + */
  14486. + int i;
  14487. + mask = 1<<V4L2_SCENE_MODE_NONE;
  14488. + for (i = 0;
  14489. + i < ARRAY_SIZE(scene_configs);
  14490. + i++) {
  14491. + mask |= 1<<scene_configs[i].v4l2_scene;
  14492. + }
  14493. + mask = ~mask;
  14494. + }
  14495. +
  14496. + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  14497. + &bm2835_mmal_ctrl_ops, ctrl->id,
  14498. + ctrl->max, mask, ctrl->def);
  14499. + break;
  14500. + }
  14501. +
  14502. + case MMAL_CONTROL_TYPE_INT_MENU:
  14503. + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  14504. + &bm2835_mmal_ctrl_ops, ctrl->id,
  14505. + ctrl->max, ctrl->def, ctrl->imenu);
  14506. + break;
  14507. +
  14508. + case MMAL_CONTROL_TYPE_CLUSTER:
  14509. + /* skip this entry when constructing controls */
  14510. + continue;
  14511. + }
  14512. +
  14513. + if (hdl->error)
  14514. + break;
  14515. +
  14516. + dev->ctrls[c]->priv = (void *)ctrl;
  14517. + }
  14518. +
  14519. + if (hdl->error) {
  14520. + pr_err("error adding control %d/%d id 0x%x\n", c,
  14521. + V4L2_CTRL_COUNT, ctrl->id);
  14522. + return hdl->error;
  14523. + }
  14524. +
  14525. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  14526. + ctrl = &v4l2_ctrls[c];
  14527. +
  14528. + switch (ctrl->type) {
  14529. + case MMAL_CONTROL_TYPE_CLUSTER:
  14530. + v4l2_ctrl_auto_cluster(ctrl->min,
  14531. + &dev->ctrls[c+1],
  14532. + ctrl->max,
  14533. + ctrl->def);
  14534. + break;
  14535. +
  14536. + case MMAL_CONTROL_TYPE_STD:
  14537. + case MMAL_CONTROL_TYPE_STD_MENU:
  14538. + case MMAL_CONTROL_TYPE_INT_MENU:
  14539. + break;
  14540. + }
  14541. +
  14542. + }
  14543. +
  14544. + return 0;
  14545. +}
  14546. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/Kconfig linux-rpi/drivers/media/platform/bcm2835/Kconfig
  14547. --- linux-3.12.18/drivers/media/platform/bcm2835/Kconfig 1970-01-01 01:00:00.000000000 +0100
  14548. +++ linux-rpi/drivers/media/platform/bcm2835/Kconfig 2014-04-24 15:35:02.713549510 +0200
  14549. @@ -0,0 +1,25 @@
  14550. +# Broadcom VideoCore IV v4l2 camera support
  14551. +
  14552. +config VIDEO_BCM2835
  14553. + bool "Broadcom BCM2835 camera interface driver"
  14554. + depends on VIDEO_V4L2 && ARCH_BCM2708
  14555. + ---help---
  14556. + Say Y here to enable camera host interface devices for
  14557. + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
  14558. + to a service running on VideoCore.
  14559. +
  14560. +
  14561. +if VIDEO_BCM2835
  14562. +
  14563. +config VIDEO_BCM2835_MMAL
  14564. + tristate "Broadcom BM2835 MMAL camera interface driver"
  14565. + depends on BCM2708_VCHIQ
  14566. + select VIDEOBUF2_VMALLOC
  14567. + ---help---
  14568. + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
  14569. +
  14570. + To compile this driver as a module, choose M here: the
  14571. + module will be called bcm2835-v4l2.o
  14572. +
  14573. +
  14574. +endif # VIDEO_BM2835
  14575. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/Makefile linux-rpi/drivers/media/platform/bcm2835/Makefile
  14576. --- linux-3.12.18/drivers/media/platform/bcm2835/Makefile 1970-01-01 01:00:00.000000000 +0100
  14577. +++ linux-rpi/drivers/media/platform/bcm2835/Makefile 2014-04-24 15:35:02.713549510 +0200
  14578. @@ -0,0 +1,5 @@
  14579. +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
  14580. +
  14581. +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
  14582. +
  14583. +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  14584. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/mmal-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-common.h
  14585. --- linux-3.12.18/drivers/media/platform/bcm2835/mmal-common.h 1970-01-01 01:00:00.000000000 +0100
  14586. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-common.h 2014-04-24 15:35:02.713549510 +0200
  14587. @@ -0,0 +1,53 @@
  14588. +/*
  14589. + * Broadcom BM2835 V4L2 driver
  14590. + *
  14591. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14592. + *
  14593. + * This file is subject to the terms and conditions of the GNU General Public
  14594. + * License. See the file COPYING in the main directory of this archive
  14595. + * for more details.
  14596. + *
  14597. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14598. + * Dave Stevenson <dsteve@broadcom.com>
  14599. + * Simon Mellor <simellor@broadcom.com>
  14600. + * Luke Diamand <luked@broadcom.com>
  14601. + *
  14602. + * MMAL structures
  14603. + *
  14604. + */
  14605. +
  14606. +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
  14607. +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
  14608. +
  14609. +/** Special value signalling that time is not known */
  14610. +#define MMAL_TIME_UNKNOWN (1LL<<63)
  14611. +
  14612. +/* mapping between v4l and mmal video modes */
  14613. +struct mmal_fmt {
  14614. + char *name;
  14615. + u32 fourcc; /* v4l2 format id */
  14616. + int flags; /* v4l2 flags field */
  14617. + u32 mmal;
  14618. + int depth;
  14619. + u32 mmal_component; /* MMAL component index to be used to encode */
  14620. +};
  14621. +
  14622. +/* buffer for one video frame */
  14623. +struct mmal_buffer {
  14624. + /* v4l buffer data -- must be first */
  14625. + struct vb2_buffer vb;
  14626. +
  14627. + /* list of buffers available */
  14628. + struct list_head list;
  14629. +
  14630. + void *buffer; /* buffer pointer */
  14631. + unsigned long buffer_size; /* size of allocated buffer */
  14632. +};
  14633. +
  14634. +/* */
  14635. +struct mmal_colourfx {
  14636. + s32 enable;
  14637. + u32 u;
  14638. + u32 v;
  14639. +};
  14640. +
  14641. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/mmal-encodings.h linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h
  14642. --- linux-3.12.18/drivers/media/platform/bcm2835/mmal-encodings.h 1970-01-01 01:00:00.000000000 +0100
  14643. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h 2014-04-24 15:35:02.713549510 +0200
  14644. @@ -0,0 +1,94 @@
  14645. +/*
  14646. + * Broadcom BM2835 V4L2 driver
  14647. + *
  14648. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14649. + *
  14650. + * This file is subject to the terms and conditions of the GNU General Public
  14651. + * License. See the file COPYING in the main directory of this archive
  14652. + * for more details.
  14653. + *
  14654. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14655. + * Dave Stevenson <dsteve@broadcom.com>
  14656. + * Simon Mellor <simellor@broadcom.com>
  14657. + * Luke Diamand <luked@broadcom.com>
  14658. + */
  14659. +
  14660. +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  14661. +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  14662. +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
  14663. +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
  14664. +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
  14665. +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
  14666. +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
  14667. +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
  14668. +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
  14669. +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
  14670. +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
  14671. +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  14672. +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  14673. +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  14674. +#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
  14675. +
  14676. +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  14677. +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  14678. +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
  14679. +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
  14680. +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
  14681. +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
  14682. +
  14683. +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
  14684. +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
  14685. +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
  14686. +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
  14687. +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
  14688. +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
  14689. +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
  14690. +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
  14691. +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
  14692. +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
  14693. +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
  14694. +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
  14695. +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
  14696. +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
  14697. +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
  14698. +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
  14699. +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
  14700. +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
  14701. +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
  14702. +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
  14703. +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
  14704. +
  14705. +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
  14706. + * This format is *not* opaque - if requested you will receive full frames
  14707. + * of YUV_UV video.
  14708. + */
  14709. +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
  14710. +
  14711. +/** VideoCore opaque image format, image handles are returned to
  14712. + * the host but not the actual image data.
  14713. + */
  14714. +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
  14715. +
  14716. +/** An EGL image handle
  14717. + */
  14718. +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
  14719. +
  14720. +/* }@ */
  14721. +
  14722. +/** \name Pre-defined audio encodings */
  14723. +/* @{ */
  14724. +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
  14725. +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
  14726. +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
  14727. +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
  14728. +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
  14729. +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
  14730. +
  14731. +/* Pre-defined H264 encoding variants */
  14732. +
  14733. +/** ISO 14496-10 Annex B byte stream format */
  14734. +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
  14735. +/** ISO 14496-15 AVC stream format */
  14736. +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  14737. +/** Implicitly delineated NAL units without emulation prevention */
  14738. +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  14739. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/mmal-msg-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h
  14740. --- linux-3.12.18/drivers/media/platform/bcm2835/mmal-msg-common.h 1970-01-01 01:00:00.000000000 +0100
  14741. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h 2014-04-24 15:35:02.713549510 +0200
  14742. @@ -0,0 +1,50 @@
  14743. +/*
  14744. + * Broadcom BM2835 V4L2 driver
  14745. + *
  14746. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14747. + *
  14748. + * This file is subject to the terms and conditions of the GNU General Public
  14749. + * License. See the file COPYING in the main directory of this archive
  14750. + * for more details.
  14751. + *
  14752. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14753. + * Dave Stevenson <dsteve@broadcom.com>
  14754. + * Simon Mellor <simellor@broadcom.com>
  14755. + * Luke Diamand <luked@broadcom.com>
  14756. + */
  14757. +
  14758. +#ifndef MMAL_MSG_COMMON_H
  14759. +#define MMAL_MSG_COMMON_H
  14760. +
  14761. +enum mmal_msg_status {
  14762. + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
  14763. + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
  14764. + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
  14765. + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
  14766. + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
  14767. + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
  14768. + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
  14769. + MMAL_MSG_STATUS_EIO, /**< I/O error */
  14770. + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
  14771. + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
  14772. + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
  14773. + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
  14774. + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
  14775. + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
  14776. + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
  14777. + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
  14778. +};
  14779. +
  14780. +struct mmal_rect {
  14781. + s32 x; /**< x coordinate (from left) */
  14782. + s32 y; /**< y coordinate (from top) */
  14783. + s32 width; /**< width */
  14784. + s32 height; /**< height */
  14785. +};
  14786. +
  14787. +struct mmal_rational {
  14788. + s32 num; /**< Numerator */
  14789. + s32 den; /**< Denominator */
  14790. +};
  14791. +
  14792. +#endif /* MMAL_MSG_COMMON_H */
  14793. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/mmal-msg-format.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h
  14794. --- linux-3.12.18/drivers/media/platform/bcm2835/mmal-msg-format.h 1970-01-01 01:00:00.000000000 +0100
  14795. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h 2014-04-24 15:35:02.713549510 +0200
  14796. @@ -0,0 +1,81 @@
  14797. +/*
  14798. + * Broadcom BM2835 V4L2 driver
  14799. + *
  14800. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14801. + *
  14802. + * This file is subject to the terms and conditions of the GNU General Public
  14803. + * License. See the file COPYING in the main directory of this archive
  14804. + * for more details.
  14805. + *
  14806. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14807. + * Dave Stevenson <dsteve@broadcom.com>
  14808. + * Simon Mellor <simellor@broadcom.com>
  14809. + * Luke Diamand <luked@broadcom.com>
  14810. + */
  14811. +
  14812. +#ifndef MMAL_MSG_FORMAT_H
  14813. +#define MMAL_MSG_FORMAT_H
  14814. +
  14815. +#include "mmal-msg-common.h"
  14816. +
  14817. +/* MMAL_ES_FORMAT_T */
  14818. +
  14819. +
  14820. +struct mmal_audio_format {
  14821. + u32 channels; /**< Number of audio channels */
  14822. + u32 sample_rate; /**< Sample rate */
  14823. +
  14824. + u32 bits_per_sample; /**< Bits per sample */
  14825. + u32 block_align; /**< Size of a block of data */
  14826. +};
  14827. +
  14828. +struct mmal_video_format {
  14829. + u32 width; /**< Width of frame in pixels */
  14830. + u32 height; /**< Height of frame in rows of pixels */
  14831. + struct mmal_rect crop; /**< Visible region of the frame */
  14832. + struct mmal_rational frame_rate; /**< Frame rate */
  14833. + struct mmal_rational par; /**< Pixel aspect ratio */
  14834. +
  14835. + /* FourCC specifying the color space of the video stream. See the
  14836. + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
  14837. + */
  14838. + u32 color_space;
  14839. +};
  14840. +
  14841. +struct mmal_subpicture_format {
  14842. + u32 x_offset;
  14843. + u32 y_offset;
  14844. +};
  14845. +
  14846. +union mmal_es_specific_format {
  14847. + struct mmal_audio_format audio;
  14848. + struct mmal_video_format video;
  14849. + struct mmal_subpicture_format subpicture;
  14850. +};
  14851. +
  14852. +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
  14853. +struct mmal_es_format {
  14854. + u32 type; /* enum mmal_es_type */
  14855. +
  14856. + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
  14857. + u32 encoding_variant; /* FourCC specifying the specific
  14858. + * encoding variant of the elementary
  14859. + * stream.
  14860. + */
  14861. +
  14862. + union mmal_es_specific_format *es; /* TODO: pointers in
  14863. + * message serialisation?!?
  14864. + */
  14865. + /* Type specific
  14866. + * information for the
  14867. + * elementary stream
  14868. + */
  14869. +
  14870. + u32 bitrate; /**< Bitrate in bits per second */
  14871. + u32 flags; /**< Flags describing properties of the elementary stream. */
  14872. +
  14873. + u32 extradata_size; /**< Size of the codec specific data */
  14874. + u8 *extradata; /**< Codec specific data */
  14875. +};
  14876. +
  14877. +#endif /* MMAL_MSG_FORMAT_H */
  14878. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/mmal-msg.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h
  14879. --- linux-3.12.18/drivers/media/platform/bcm2835/mmal-msg.h 1970-01-01 01:00:00.000000000 +0100
  14880. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h 2014-04-24 15:35:02.713549510 +0200
  14881. @@ -0,0 +1,404 @@
  14882. +/*
  14883. + * Broadcom BM2835 V4L2 driver
  14884. + *
  14885. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14886. + *
  14887. + * This file is subject to the terms and conditions of the GNU General Public
  14888. + * License. See the file COPYING in the main directory of this archive
  14889. + * for more details.
  14890. + *
  14891. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14892. + * Dave Stevenson <dsteve@broadcom.com>
  14893. + * Simon Mellor <simellor@broadcom.com>
  14894. + * Luke Diamand <luked@broadcom.com>
  14895. + */
  14896. +
  14897. +/* all the data structures which serialise the MMAL protocol. note
  14898. + * these are directly mapped onto the recived message data.
  14899. + *
  14900. + * BEWARE: They seem to *assume* pointers are u32 and that there is no
  14901. + * structure padding!
  14902. + *
  14903. + * NOTE: this implementation uses kernel types to ensure sizes. Rather
  14904. + * than assigning values to enums to force their size the
  14905. + * implementation uses fixed size types and not the enums (though the
  14906. + * comments have the actual enum type
  14907. + */
  14908. +
  14909. +#define VC_MMAL_VER 15
  14910. +#define VC_MMAL_MIN_VER 10
  14911. +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
  14912. +
  14913. +/* max total message size is 512 bytes */
  14914. +#define MMAL_MSG_MAX_SIZE 512
  14915. +/* with six 32bit header elements max payload is therefore 488 bytes */
  14916. +#define MMAL_MSG_MAX_PAYLOAD 488
  14917. +
  14918. +#include "mmal-msg-common.h"
  14919. +#include "mmal-msg-format.h"
  14920. +#include "mmal-msg-port.h"
  14921. +
  14922. +enum mmal_msg_type {
  14923. + MMAL_MSG_TYPE_QUIT = 1,
  14924. + MMAL_MSG_TYPE_SERVICE_CLOSED,
  14925. + MMAL_MSG_TYPE_GET_VERSION,
  14926. + MMAL_MSG_TYPE_COMPONENT_CREATE,
  14927. + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  14928. + MMAL_MSG_TYPE_COMPONENT_ENABLE,
  14929. + MMAL_MSG_TYPE_COMPONENT_DISABLE,
  14930. + MMAL_MSG_TYPE_PORT_INFO_GET,
  14931. + MMAL_MSG_TYPE_PORT_INFO_SET,
  14932. + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  14933. + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  14934. + MMAL_MSG_TYPE_BUFFER_TO_HOST,
  14935. + MMAL_MSG_TYPE_GET_STATS,
  14936. + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  14937. + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  14938. + MMAL_MSG_TYPE_EVENT_TO_HOST,
  14939. + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  14940. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  14941. + MMAL_MSG_TYPE_CONSUME_MEM,
  14942. + MMAL_MSG_TYPE_LMK, /* 20 */
  14943. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  14944. + MMAL_MSG_TYPE_DRM_GET_LHS32,
  14945. + MMAL_MSG_TYPE_DRM_GET_TIME,
  14946. + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  14947. + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  14948. + MMAL_MSG_TYPE_HOST_LOG,
  14949. + MMAL_MSG_TYPE_MSG_LAST
  14950. +};
  14951. +
  14952. +/* port action request messages differ depending on the action type */
  14953. +enum mmal_msg_port_action_type {
  14954. + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
  14955. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  14956. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  14957. + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  14958. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  14959. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  14960. + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  14961. +};
  14962. +
  14963. +struct mmal_msg_header {
  14964. + u32 magic;
  14965. + u32 type; /** enum mmal_msg_type */
  14966. +
  14967. + /* Opaque handle to the control service */
  14968. + struct mmal_control_service *control_service;
  14969. +
  14970. + struct mmal_msg_context *context; /** a u32 per message context */
  14971. + u32 status; /** The status of the vchiq operation */
  14972. + u32 padding;
  14973. +};
  14974. +
  14975. +/* Send from VC to host to report version */
  14976. +struct mmal_msg_version {
  14977. + u32 flags;
  14978. + u32 major;
  14979. + u32 minor;
  14980. + u32 minimum;
  14981. +};
  14982. +
  14983. +/* request to VC to create component */
  14984. +struct mmal_msg_component_create {
  14985. + void *client_component; /* component context */
  14986. + char name[128];
  14987. + u32 pid; /* For debug */
  14988. +};
  14989. +
  14990. +/* reply from VC to component creation request */
  14991. +struct mmal_msg_component_create_reply {
  14992. + u32 status; /** enum mmal_msg_status - how does this differ to
  14993. + * the one in the header?
  14994. + */
  14995. + u32 component_handle; /* VideoCore handle for component */
  14996. + u32 input_num; /* Number of input ports */
  14997. + u32 output_num; /* Number of output ports */
  14998. + u32 clock_num; /* Number of clock ports */
  14999. +};
  15000. +
  15001. +/* request to VC to destroy a component */
  15002. +struct mmal_msg_component_destroy {
  15003. + u32 component_handle;
  15004. +};
  15005. +
  15006. +struct mmal_msg_component_destroy_reply {
  15007. + u32 status; /** The component destruction status */
  15008. +};
  15009. +
  15010. +
  15011. +/* request and reply to VC to enable a component */
  15012. +struct mmal_msg_component_enable {
  15013. + u32 component_handle;
  15014. +};
  15015. +
  15016. +struct mmal_msg_component_enable_reply {
  15017. + u32 status; /** The component enable status */
  15018. +};
  15019. +
  15020. +
  15021. +/* request and reply to VC to disable a component */
  15022. +struct mmal_msg_component_disable {
  15023. + u32 component_handle;
  15024. +};
  15025. +
  15026. +struct mmal_msg_component_disable_reply {
  15027. + u32 status; /** The component disable status */
  15028. +};
  15029. +
  15030. +/* request to VC to get port information */
  15031. +struct mmal_msg_port_info_get {
  15032. + u32 component_handle; /* component handle port is associated with */
  15033. + u32 port_type; /* enum mmal_msg_port_type */
  15034. + u32 index; /* port index to query */
  15035. +};
  15036. +
  15037. +/* reply from VC to get port info request */
  15038. +struct mmal_msg_port_info_get_reply {
  15039. + u32 status; /** enum mmal_msg_status */
  15040. + u32 component_handle; /* component handle port is associated with */
  15041. + u32 port_type; /* enum mmal_msg_port_type */
  15042. + u32 port_index; /* port indexed in query */
  15043. + s32 found; /* unused */
  15044. + u32 port_handle; /**< Handle to use for this port */
  15045. + struct mmal_port port;
  15046. + struct mmal_es_format format; /* elementry stream format */
  15047. + union mmal_es_specific_format es; /* es type specific data */
  15048. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  15049. +};
  15050. +
  15051. +/* request to VC to set port information */
  15052. +struct mmal_msg_port_info_set {
  15053. + u32 component_handle;
  15054. + u32 port_type; /* enum mmal_msg_port_type */
  15055. + u32 port_index; /* port indexed in query */
  15056. + struct mmal_port port;
  15057. + struct mmal_es_format format;
  15058. + union mmal_es_specific_format es;
  15059. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  15060. +};
  15061. +
  15062. +/* reply from VC to port info set request */
  15063. +struct mmal_msg_port_info_set_reply {
  15064. + u32 status;
  15065. + u32 component_handle; /* component handle port is associated with */
  15066. + u32 port_type; /* enum mmal_msg_port_type */
  15067. + u32 index; /* port indexed in query */
  15068. + s32 found; /* unused */
  15069. + u32 port_handle; /**< Handle to use for this port */
  15070. + struct mmal_port port;
  15071. + struct mmal_es_format format;
  15072. + union mmal_es_specific_format es;
  15073. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  15074. +};
  15075. +
  15076. +
  15077. +/* port action requests that take a mmal_port as a parameter */
  15078. +struct mmal_msg_port_action_port {
  15079. + u32 component_handle;
  15080. + u32 port_handle;
  15081. + u32 action; /* enum mmal_msg_port_action_type */
  15082. + struct mmal_port port;
  15083. +};
  15084. +
  15085. +/* port action requests that take handles as a parameter */
  15086. +struct mmal_msg_port_action_handle {
  15087. + u32 component_handle;
  15088. + u32 port_handle;
  15089. + u32 action; /* enum mmal_msg_port_action_type */
  15090. + u32 connect_component_handle;
  15091. + u32 connect_port_handle;
  15092. +};
  15093. +
  15094. +struct mmal_msg_port_action_reply {
  15095. + u32 status; /** The port action operation status */
  15096. +};
  15097. +
  15098. +
  15099. +
  15100. +
  15101. +/* MMAL buffer transfer */
  15102. +
  15103. +/** Size of space reserved in a buffer message for short messages. */
  15104. +#define MMAL_VC_SHORT_DATA 128
  15105. +
  15106. +/** Signals that the current payload is the end of the stream of data */
  15107. +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  15108. +/** Signals that the start of the current payload starts a frame */
  15109. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  15110. +/** Signals that the end of the current payload ends a frame */
  15111. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  15112. +/** Signals that the current payload contains only complete frames (>1) */
  15113. +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
  15114. + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  15115. +/** Signals that the current payload is a keyframe (i.e. self decodable) */
  15116. +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  15117. +/** Signals a discontinuity in the stream of data (e.g. after a seek).
  15118. + * Can be used for instance by a decoder to reset its state */
  15119. +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  15120. +/** Signals a buffer containing some kind of config data for the component
  15121. + * (e.g. codec config data) */
  15122. +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  15123. +/** Signals an encrypted payload */
  15124. +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  15125. +/** Signals a buffer containing side information */
  15126. +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  15127. +/** Signals a buffer which is the snapshot/postview image from a stills
  15128. + * capture
  15129. + */
  15130. +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  15131. +/** Signals a buffer which contains data known to be corrupted */
  15132. +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  15133. +/** Signals that a buffer failed to be transmitted */
  15134. +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  15135. +
  15136. +struct mmal_driver_buffer {
  15137. + u32 magic;
  15138. + u32 component_handle;
  15139. + u32 port_handle;
  15140. + void *client_context;
  15141. +};
  15142. +
  15143. +/* buffer header */
  15144. +struct mmal_buffer_header {
  15145. + struct mmal_buffer_header *next; /* next header */
  15146. + void *priv; /* framework private data */
  15147. + u32 cmd;
  15148. + void *data;
  15149. + u32 alloc_size;
  15150. + u32 length;
  15151. + u32 offset;
  15152. + u32 flags;
  15153. + s64 pts;
  15154. + s64 dts;
  15155. + void *type;
  15156. + void *user_data;
  15157. +};
  15158. +
  15159. +struct mmal_buffer_header_type_specific {
  15160. + union {
  15161. + struct {
  15162. + u32 planes;
  15163. + u32 offset[4];
  15164. + u32 pitch[4];
  15165. + u32 flags;
  15166. + } video;
  15167. + } u;
  15168. +};
  15169. +
  15170. +struct mmal_msg_buffer_from_host {
  15171. + /* The front 32 bytes of the buffer header are copied
  15172. + * back to us in the reply to allow for context. This
  15173. + * area is used to store two mmal_driver_buffer structures to
  15174. + * allow for multiple concurrent service users.
  15175. + */
  15176. + /* control data */
  15177. + struct mmal_driver_buffer drvbuf;
  15178. +
  15179. + /* referenced control data for passthrough buffer management */
  15180. + struct mmal_driver_buffer drvbuf_ref;
  15181. + struct mmal_buffer_header buffer_header; /* buffer header itself */
  15182. + struct mmal_buffer_header_type_specific buffer_header_type_specific;
  15183. + s32 is_zero_copy;
  15184. + s32 has_reference;
  15185. +
  15186. + /** allows short data to be xfered in control message */
  15187. + u32 payload_in_message;
  15188. + u8 short_data[MMAL_VC_SHORT_DATA];
  15189. +};
  15190. +
  15191. +
  15192. +/* port parameter setting */
  15193. +
  15194. +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  15195. +
  15196. +struct mmal_msg_port_parameter_set {
  15197. + u32 component_handle; /* component */
  15198. + u32 port_handle; /* port */
  15199. + u32 id; /* Parameter ID */
  15200. + u32 size; /* Parameter size */
  15201. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  15202. +};
  15203. +
  15204. +struct mmal_msg_port_parameter_set_reply {
  15205. + u32 status; /** enum mmal_msg_status todo: how does this
  15206. + * differ to the one in the header?
  15207. + */
  15208. +};
  15209. +
  15210. +/* port parameter getting */
  15211. +
  15212. +struct mmal_msg_port_parameter_get {
  15213. + u32 component_handle; /* component */
  15214. + u32 port_handle; /* port */
  15215. + u32 id; /* Parameter ID */
  15216. + u32 size; /* Parameter size */
  15217. +};
  15218. +
  15219. +struct mmal_msg_port_parameter_get_reply {
  15220. + u32 status; /* Status of mmal_port_parameter_get call */
  15221. + u32 id; /* Parameter ID */
  15222. + u32 size; /* Parameter size */
  15223. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  15224. +};
  15225. +
  15226. +/* event messages */
  15227. +#define MMAL_WORKER_EVENT_SPACE 256
  15228. +
  15229. +struct mmal_msg_event_to_host {
  15230. + void *client_component; /* component context */
  15231. +
  15232. + u32 port_type;
  15233. + u32 port_num;
  15234. +
  15235. + u32 cmd;
  15236. + u32 length;
  15237. + u8 data[MMAL_WORKER_EVENT_SPACE];
  15238. + struct mmal_buffer_header *delayed_buffer;
  15239. +};
  15240. +
  15241. +/* all mmal messages are serialised through this structure */
  15242. +struct mmal_msg {
  15243. + /* header */
  15244. + struct mmal_msg_header h;
  15245. + /* payload */
  15246. + union {
  15247. + struct mmal_msg_version version;
  15248. +
  15249. + struct mmal_msg_component_create component_create;
  15250. + struct mmal_msg_component_create_reply component_create_reply;
  15251. +
  15252. + struct mmal_msg_component_destroy component_destroy;
  15253. + struct mmal_msg_component_destroy_reply component_destroy_reply;
  15254. +
  15255. + struct mmal_msg_component_enable component_enable;
  15256. + struct mmal_msg_component_enable_reply component_enable_reply;
  15257. +
  15258. + struct mmal_msg_component_disable component_disable;
  15259. + struct mmal_msg_component_disable_reply component_disable_reply;
  15260. +
  15261. + struct mmal_msg_port_info_get port_info_get;
  15262. + struct mmal_msg_port_info_get_reply port_info_get_reply;
  15263. +
  15264. + struct mmal_msg_port_info_set port_info_set;
  15265. + struct mmal_msg_port_info_set_reply port_info_set_reply;
  15266. +
  15267. + struct mmal_msg_port_action_port port_action_port;
  15268. + struct mmal_msg_port_action_handle port_action_handle;
  15269. + struct mmal_msg_port_action_reply port_action_reply;
  15270. +
  15271. + struct mmal_msg_buffer_from_host buffer_from_host;
  15272. +
  15273. + struct mmal_msg_port_parameter_set port_parameter_set;
  15274. + struct mmal_msg_port_parameter_set_reply
  15275. + port_parameter_set_reply;
  15276. + struct mmal_msg_port_parameter_get
  15277. + port_parameter_get;
  15278. + struct mmal_msg_port_parameter_get_reply
  15279. + port_parameter_get_reply;
  15280. +
  15281. + struct mmal_msg_event_to_host event_to_host;
  15282. +
  15283. + u8 payload[MMAL_MSG_MAX_PAYLOAD];
  15284. + } u;
  15285. +};
  15286. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/mmal-msg-port.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h
  15287. --- linux-3.12.18/drivers/media/platform/bcm2835/mmal-msg-port.h 1970-01-01 01:00:00.000000000 +0100
  15288. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h 2014-04-24 15:35:02.713549510 +0200
  15289. @@ -0,0 +1,107 @@
  15290. +/*
  15291. + * Broadcom BM2835 V4L2 driver
  15292. + *
  15293. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15294. + *
  15295. + * This file is subject to the terms and conditions of the GNU General Public
  15296. + * License. See the file COPYING in the main directory of this archive
  15297. + * for more details.
  15298. + *
  15299. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15300. + * Dave Stevenson <dsteve@broadcom.com>
  15301. + * Simon Mellor <simellor@broadcom.com>
  15302. + * Luke Diamand <luked@broadcom.com>
  15303. + */
  15304. +
  15305. +/* MMAL_PORT_TYPE_T */
  15306. +enum mmal_port_type {
  15307. + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  15308. + MMAL_PORT_TYPE_CONTROL, /**< Control port */
  15309. + MMAL_PORT_TYPE_INPUT, /**< Input port */
  15310. + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  15311. + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  15312. +};
  15313. +
  15314. +/** The port is pass-through and doesn't need buffer headers allocated */
  15315. +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  15316. +/** The port wants to allocate the buffer payloads.
  15317. + * This signals a preference that payload allocation should be done
  15318. + * on this port for efficiency reasons. */
  15319. +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  15320. +/** The port supports format change events.
  15321. + * This applies to input ports and is used to let the client know
  15322. + * whether the port supports being reconfigured via a format
  15323. + * change event (i.e. without having to disable the port). */
  15324. +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  15325. +
  15326. +/* mmal port structure (MMAL_PORT_T)
  15327. + *
  15328. + * most elements are informational only, the pointer values for
  15329. + * interogation messages are generally provided as additional
  15330. + * strucures within the message. When used to set values only teh
  15331. + * buffer_num, buffer_size and userdata parameters are writable.
  15332. + */
  15333. +struct mmal_port {
  15334. + void *priv; /* Private member used by the framework */
  15335. + const char *name; /* Port name. Used for debugging purposes (RO) */
  15336. +
  15337. + u32 type; /* Type of the port (RO) enum mmal_port_type */
  15338. + u16 index; /* Index of the port in its type list (RO) */
  15339. + u16 index_all; /* Index of the port in the list of all ports (RO) */
  15340. +
  15341. + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
  15342. + struct mmal_es_format *format; /* Format of the elementary stream */
  15343. +
  15344. + u32 buffer_num_min; /* Minimum number of buffers the port
  15345. + * requires (RO). This is set by the
  15346. + * component.
  15347. + */
  15348. +
  15349. + u32 buffer_size_min; /* Minimum size of buffers the port
  15350. + * requires (RO). This is set by the
  15351. + * component.
  15352. + */
  15353. +
  15354. + u32 buffer_alignment_min; /* Minimum alignment requirement for
  15355. + * the buffers (RO). A value of
  15356. + * zero means no special alignment
  15357. + * requirements. This is set by the
  15358. + * component.
  15359. + */
  15360. +
  15361. + u32 buffer_num_recommended; /* Number of buffers the port
  15362. + * recommends for optimal
  15363. + * performance (RO). A value of
  15364. + * zero means no special
  15365. + * recommendation. This is set
  15366. + * by the component.
  15367. + */
  15368. +
  15369. + u32 buffer_size_recommended; /* Size of buffers the port
  15370. + * recommends for optimal
  15371. + * performance (RO). A value of
  15372. + * zero means no special
  15373. + * recommendation. This is set
  15374. + * by the component.
  15375. + */
  15376. +
  15377. + u32 buffer_num; /* Actual number of buffers the port will use.
  15378. + * This is set by the client.
  15379. + */
  15380. +
  15381. + u32 buffer_size; /* Actual maximum size of the buffers that
  15382. + * will be sent to the port. This is set by
  15383. + * the client.
  15384. + */
  15385. +
  15386. + void *component; /* Component this port belongs to (Read Only) */
  15387. +
  15388. + void *userdata; /* Field reserved for use by the client */
  15389. +
  15390. + u32 capabilities; /* Flags describing the capabilities of a
  15391. + * port (RO). Bitwise combination of \ref
  15392. + * portcapabilities "Port capabilities"
  15393. + * values.
  15394. + */
  15395. +
  15396. +};
  15397. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/mmal-parameters.h linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h
  15398. --- linux-3.12.18/drivers/media/platform/bcm2835/mmal-parameters.h 1970-01-01 01:00:00.000000000 +0100
  15399. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h 2014-04-24 15:35:02.713549510 +0200
  15400. @@ -0,0 +1,655 @@
  15401. +/*
  15402. + * Broadcom BM2835 V4L2 driver
  15403. + *
  15404. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15405. + *
  15406. + * This file is subject to the terms and conditions of the GNU General Public
  15407. + * License. See the file COPYING in the main directory of this archive
  15408. + * for more details.
  15409. + *
  15410. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15411. + * Dave Stevenson <dsteve@broadcom.com>
  15412. + * Simon Mellor <simellor@broadcom.com>
  15413. + * Luke Diamand <luked@broadcom.com>
  15414. + */
  15415. +
  15416. +/* common parameters */
  15417. +
  15418. +/** @name Parameter groups
  15419. + * Parameters are divided into groups, and then allocated sequentially within
  15420. + * a group using an enum.
  15421. + * @{
  15422. + */
  15423. +
  15424. +/** Common parameter ID group, used with many types of component. */
  15425. +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
  15426. +/** Camera-specific parameter ID group. */
  15427. +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
  15428. +/** Video-specific parameter ID group. */
  15429. +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
  15430. +/** Audio-specific parameter ID group. */
  15431. +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
  15432. +/** Clock-specific parameter ID group. */
  15433. +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
  15434. +/** Miracast-specific parameter ID group. */
  15435. +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
  15436. +
  15437. +/* Common parameters */
  15438. +enum mmal_parameter_common_type {
  15439. + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
  15440. + = MMAL_PARAMETER_GROUP_COMMON,
  15441. + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
  15442. + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
  15443. +
  15444. + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
  15445. + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
  15446. +
  15447. + /** MMAL_PARAMETER_BOOLEAN_T */
  15448. + MMAL_PARAMETER_ZERO_COPY,
  15449. +
  15450. + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
  15451. + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
  15452. +
  15453. + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
  15454. + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
  15455. + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
  15456. + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
  15457. + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  15458. + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  15459. + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  15460. + MMAL_PARAMETER_SYSTEM_TIME /**< MMAL_PARAMETER_UINT64_T */
  15461. +};
  15462. +
  15463. +/* camera parameters */
  15464. +
  15465. +enum mmal_parameter_camera_type {
  15466. + /* 0 */
  15467. + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
  15468. + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
  15469. + = MMAL_PARAMETER_GROUP_CAMERA,
  15470. + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
  15471. + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
  15472. + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15473. + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
  15474. + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
  15475. + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
  15476. + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
  15477. + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
  15478. + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
  15479. + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
  15480. + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
  15481. + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
  15482. + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  15483. + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
  15484. + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
  15485. +
  15486. + /* 0x10 */
  15487. + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
  15488. + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15489. + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
  15490. + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
  15491. + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
  15492. + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
  15493. + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
  15494. + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
  15495. + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15496. + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
  15497. + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
  15498. + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
  15499. + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
  15500. + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15501. + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
  15502. + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15503. +
  15504. + /* 0x20 */
  15505. + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
  15506. + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15507. + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15508. + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
  15509. + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
  15510. + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
  15511. + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
  15512. + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
  15513. + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
  15514. + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15515. + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
  15516. + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
  15517. + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  15518. + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  15519. + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  15520. + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  15521. +
  15522. + /* 0x30 */
  15523. + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
  15524. + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15525. +
  15526. + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
  15527. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  15528. +
  15529. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15530. + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
  15531. +
  15532. + /** @ref MMAL_PARAMETER_UINT32_T */
  15533. + MMAL_PARAMETER_CAMERA_MIN_ISO,
  15534. +
  15535. + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
  15536. + MMAL_PARAMETER_CAMERA_USE_CASE,
  15537. +
  15538. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15539. + MMAL_PARAMETER_CAPTURE_STATS_PASS,
  15540. +
  15541. + /** @ref MMAL_PARAMETER_UINT32_T */
  15542. + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
  15543. +
  15544. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15545. + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
  15546. +
  15547. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15548. + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
  15549. +
  15550. + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
  15551. + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
  15552. +
  15553. + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
  15554. + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
  15555. + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15556. + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
  15557. + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
  15558. + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  15559. +
  15560. + /* 0x40 */
  15561. + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15562. + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15563. + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15564. + MMAL_PARAMETER_SHUTTER_SPEED, /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  15565. + MMAL_PARAMETER_CUSTOM_AWB_GAINS, /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
  15566. +};
  15567. +
  15568. +struct mmal_parameter_rational {
  15569. + s32 num; /**< Numerator */
  15570. + s32 den; /**< Denominator */
  15571. +};
  15572. +
  15573. +enum mmal_parameter_camera_config_timestamp_mode {
  15574. + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
  15575. + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
  15576. + * for the frame timestamp
  15577. + */
  15578. + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
  15579. + * but subtract the
  15580. + * timestamp of the first
  15581. + * frame sent to give a
  15582. + * zero based timestamp.
  15583. + */
  15584. +};
  15585. +
  15586. +struct mmal_parameter_fps_range {
  15587. + /**< Low end of the permitted framerate range */
  15588. + struct mmal_parameter_rational fps_low;
  15589. + /**< High end of the permitted framerate range */
  15590. + struct mmal_parameter_rational fps_high;
  15591. +};
  15592. +
  15593. +
  15594. +/* camera configuration parameter */
  15595. +struct mmal_parameter_camera_config {
  15596. + /* Parameters for setting up the image pools */
  15597. + u32 max_stills_w; /* Max size of stills capture */
  15598. + u32 max_stills_h;
  15599. + u32 stills_yuv422; /* Allow YUV422 stills capture */
  15600. + u32 one_shot_stills; /* Continuous or one shot stills captures. */
  15601. +
  15602. + u32 max_preview_video_w; /* Max size of the preview or video
  15603. + * capture frames
  15604. + */
  15605. + u32 max_preview_video_h;
  15606. + u32 num_preview_video_frames;
  15607. +
  15608. + /** Sets the height of the circular buffer for stills capture. */
  15609. + u32 stills_capture_circular_buffer_height;
  15610. +
  15611. + /** Allows preview/encode to resume as fast as possible after the stills
  15612. + * input frame has been received, and then processes the still frame in
  15613. + * the background whilst preview/encode has resumed.
  15614. + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
  15615. + */
  15616. + u32 fast_preview_resume;
  15617. +
  15618. + /** Selects algorithm for timestamping frames if
  15619. + * there is no clock component connected.
  15620. + * enum mmal_parameter_camera_config_timestamp_mode
  15621. + */
  15622. + s32 use_stc_timestamp;
  15623. +};
  15624. +
  15625. +
  15626. +enum mmal_parameter_exposuremode {
  15627. + MMAL_PARAM_EXPOSUREMODE_OFF,
  15628. + MMAL_PARAM_EXPOSUREMODE_AUTO,
  15629. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  15630. + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
  15631. + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
  15632. + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
  15633. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  15634. + MMAL_PARAM_EXPOSUREMODE_SNOW,
  15635. + MMAL_PARAM_EXPOSUREMODE_BEACH,
  15636. + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
  15637. + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
  15638. + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  15639. + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  15640. +};
  15641. +
  15642. +enum mmal_parameter_exposuremeteringmode {
  15643. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
  15644. + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
  15645. + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
  15646. + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
  15647. +};
  15648. +
  15649. +enum mmal_parameter_awbmode {
  15650. + MMAL_PARAM_AWBMODE_OFF,
  15651. + MMAL_PARAM_AWBMODE_AUTO,
  15652. + MMAL_PARAM_AWBMODE_SUNLIGHT,
  15653. + MMAL_PARAM_AWBMODE_CLOUDY,
  15654. + MMAL_PARAM_AWBMODE_SHADE,
  15655. + MMAL_PARAM_AWBMODE_TUNGSTEN,
  15656. + MMAL_PARAM_AWBMODE_FLUORESCENT,
  15657. + MMAL_PARAM_AWBMODE_INCANDESCENT,
  15658. + MMAL_PARAM_AWBMODE_FLASH,
  15659. + MMAL_PARAM_AWBMODE_HORIZON,
  15660. +};
  15661. +
  15662. +enum mmal_parameter_imagefx {
  15663. + MMAL_PARAM_IMAGEFX_NONE,
  15664. + MMAL_PARAM_IMAGEFX_NEGATIVE,
  15665. + MMAL_PARAM_IMAGEFX_SOLARIZE,
  15666. + MMAL_PARAM_IMAGEFX_POSTERIZE,
  15667. + MMAL_PARAM_IMAGEFX_WHITEBOARD,
  15668. + MMAL_PARAM_IMAGEFX_BLACKBOARD,
  15669. + MMAL_PARAM_IMAGEFX_SKETCH,
  15670. + MMAL_PARAM_IMAGEFX_DENOISE,
  15671. + MMAL_PARAM_IMAGEFX_EMBOSS,
  15672. + MMAL_PARAM_IMAGEFX_OILPAINT,
  15673. + MMAL_PARAM_IMAGEFX_HATCH,
  15674. + MMAL_PARAM_IMAGEFX_GPEN,
  15675. + MMAL_PARAM_IMAGEFX_PASTEL,
  15676. + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  15677. + MMAL_PARAM_IMAGEFX_FILM,
  15678. + MMAL_PARAM_IMAGEFX_BLUR,
  15679. + MMAL_PARAM_IMAGEFX_SATURATION,
  15680. + MMAL_PARAM_IMAGEFX_COLOURSWAP,
  15681. + MMAL_PARAM_IMAGEFX_WASHEDOUT,
  15682. + MMAL_PARAM_IMAGEFX_POSTERISE,
  15683. + MMAL_PARAM_IMAGEFX_COLOURPOINT,
  15684. + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  15685. + MMAL_PARAM_IMAGEFX_CARTOON,
  15686. +};
  15687. +
  15688. +enum MMAL_PARAM_FLICKERAVOID_T {
  15689. + MMAL_PARAM_FLICKERAVOID_OFF,
  15690. + MMAL_PARAM_FLICKERAVOID_AUTO,
  15691. + MMAL_PARAM_FLICKERAVOID_50HZ,
  15692. + MMAL_PARAM_FLICKERAVOID_60HZ,
  15693. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  15694. +};
  15695. +
  15696. +struct mmal_parameter_awbgains {
  15697. + struct mmal_parameter_rational r_gain; /**< Red gain */
  15698. + struct mmal_parameter_rational b_gain; /**< Blue gain */
  15699. +};
  15700. +
  15701. +/** Manner of video rate control */
  15702. +enum mmal_parameter_rate_control_mode {
  15703. + MMAL_VIDEO_RATECONTROL_DEFAULT,
  15704. + MMAL_VIDEO_RATECONTROL_VARIABLE,
  15705. + MMAL_VIDEO_RATECONTROL_CONSTANT,
  15706. + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
  15707. + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  15708. +};
  15709. +
  15710. +enum mmal_video_profile {
  15711. + MMAL_VIDEO_PROFILE_H263_BASELINE,
  15712. + MMAL_VIDEO_PROFILE_H263_H320CODING,
  15713. + MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
  15714. + MMAL_VIDEO_PROFILE_H263_ISWV2,
  15715. + MMAL_VIDEO_PROFILE_H263_ISWV3,
  15716. + MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
  15717. + MMAL_VIDEO_PROFILE_H263_INTERNET,
  15718. + MMAL_VIDEO_PROFILE_H263_INTERLACE,
  15719. + MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
  15720. + MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
  15721. + MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
  15722. + MMAL_VIDEO_PROFILE_MP4V_CORE,
  15723. + MMAL_VIDEO_PROFILE_MP4V_MAIN,
  15724. + MMAL_VIDEO_PROFILE_MP4V_NBIT,
  15725. + MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
  15726. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
  15727. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
  15728. + MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
  15729. + MMAL_VIDEO_PROFILE_MP4V_HYBRID,
  15730. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
  15731. + MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
  15732. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
  15733. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
  15734. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
  15735. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
  15736. + MMAL_VIDEO_PROFILE_H264_BASELINE,
  15737. + MMAL_VIDEO_PROFILE_H264_MAIN,
  15738. + MMAL_VIDEO_PROFILE_H264_EXTENDED,
  15739. + MMAL_VIDEO_PROFILE_H264_HIGH,
  15740. + MMAL_VIDEO_PROFILE_H264_HIGH10,
  15741. + MMAL_VIDEO_PROFILE_H264_HIGH422,
  15742. + MMAL_VIDEO_PROFILE_H264_HIGH444,
  15743. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
  15744. + MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
  15745. +};
  15746. +
  15747. +enum mmal_video_level {
  15748. + MMAL_VIDEO_LEVEL_H263_10,
  15749. + MMAL_VIDEO_LEVEL_H263_20,
  15750. + MMAL_VIDEO_LEVEL_H263_30,
  15751. + MMAL_VIDEO_LEVEL_H263_40,
  15752. + MMAL_VIDEO_LEVEL_H263_45,
  15753. + MMAL_VIDEO_LEVEL_H263_50,
  15754. + MMAL_VIDEO_LEVEL_H263_60,
  15755. + MMAL_VIDEO_LEVEL_H263_70,
  15756. + MMAL_VIDEO_LEVEL_MP4V_0,
  15757. + MMAL_VIDEO_LEVEL_MP4V_0b,
  15758. + MMAL_VIDEO_LEVEL_MP4V_1,
  15759. + MMAL_VIDEO_LEVEL_MP4V_2,
  15760. + MMAL_VIDEO_LEVEL_MP4V_3,
  15761. + MMAL_VIDEO_LEVEL_MP4V_4,
  15762. + MMAL_VIDEO_LEVEL_MP4V_4a,
  15763. + MMAL_VIDEO_LEVEL_MP4V_5,
  15764. + MMAL_VIDEO_LEVEL_MP4V_6,
  15765. + MMAL_VIDEO_LEVEL_H264_1,
  15766. + MMAL_VIDEO_LEVEL_H264_1b,
  15767. + MMAL_VIDEO_LEVEL_H264_11,
  15768. + MMAL_VIDEO_LEVEL_H264_12,
  15769. + MMAL_VIDEO_LEVEL_H264_13,
  15770. + MMAL_VIDEO_LEVEL_H264_2,
  15771. + MMAL_VIDEO_LEVEL_H264_21,
  15772. + MMAL_VIDEO_LEVEL_H264_22,
  15773. + MMAL_VIDEO_LEVEL_H264_3,
  15774. + MMAL_VIDEO_LEVEL_H264_31,
  15775. + MMAL_VIDEO_LEVEL_H264_32,
  15776. + MMAL_VIDEO_LEVEL_H264_4,
  15777. + MMAL_VIDEO_LEVEL_H264_41,
  15778. + MMAL_VIDEO_LEVEL_H264_42,
  15779. + MMAL_VIDEO_LEVEL_H264_5,
  15780. + MMAL_VIDEO_LEVEL_H264_51,
  15781. + MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
  15782. +};
  15783. +
  15784. +struct mmal_parameter_video_profile {
  15785. + enum mmal_video_profile profile;
  15786. + enum mmal_video_level level;
  15787. +};
  15788. +
  15789. +/* video parameters */
  15790. +
  15791. +enum mmal_parameter_video_type {
  15792. + /** @ref MMAL_DISPLAYREGION_T */
  15793. + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
  15794. +
  15795. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  15796. + MMAL_PARAMETER_SUPPORTED_PROFILES,
  15797. +
  15798. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  15799. + MMAL_PARAMETER_PROFILE,
  15800. +
  15801. + /** @ref MMAL_PARAMETER_UINT32_T */
  15802. + MMAL_PARAMETER_INTRAPERIOD,
  15803. +
  15804. + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
  15805. + MMAL_PARAMETER_RATECONTROL,
  15806. +
  15807. + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
  15808. + MMAL_PARAMETER_NALUNITFORMAT,
  15809. +
  15810. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15811. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  15812. +
  15813. + /** @ref MMAL_PARAMETER_UINT32_T.
  15814. + * Setting the value to zero resets to the default (one slice per frame).
  15815. + */
  15816. + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
  15817. +
  15818. + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
  15819. + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
  15820. +
  15821. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
  15822. + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
  15823. +
  15824. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
  15825. + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
  15826. +
  15827. + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
  15828. + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
  15829. + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
  15830. + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
  15831. +
  15832. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15833. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  15834. +
  15835. + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
  15836. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  15837. +
  15838. + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
  15839. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  15840. +
  15841. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15842. + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
  15843. +
  15844. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15845. + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
  15846. +
  15847. + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
  15848. + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
  15849. +
  15850. + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
  15851. + /** @ref MMAL_PARAMETER_UINT32_T.
  15852. + * Changing this parameter from the default can reduce frame rate
  15853. + * because image buffers need to be re-pitched.
  15854. + */
  15855. + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
  15856. +
  15857. + /** @ref MMAL_PARAMETER_UINT32_T.
  15858. + * Changing this parameter from the default can reduce frame rate
  15859. + * because image buffers need to be re-pitched.
  15860. + */
  15861. + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
  15862. +
  15863. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15864. + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
  15865. +
  15866. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15867. + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
  15868. +
  15869. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  15870. + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
  15871. +
  15872. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  15873. + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
  15874. +
  15875. + /** @ref MMAL_PARAMETER_UINT32_T */
  15876. + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
  15877. +
  15878. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15879. + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
  15880. +
  15881. + /* H264 specific parameters */
  15882. +
  15883. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15884. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
  15885. +
  15886. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15887. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
  15888. +
  15889. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15890. + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
  15891. +
  15892. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15893. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
  15894. +
  15895. + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
  15896. + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
  15897. +
  15898. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15899. + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
  15900. +
  15901. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15902. + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
  15903. +
  15904. + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
  15905. + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
  15906. +
  15907. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15908. + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
  15909. +
  15910. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15911. + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
  15912. +
  15913. + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
  15914. + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  15915. +
  15916. + /** @ref MMAL_PARAMETER_BYTES_T */
  15917. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  15918. +
  15919. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15920. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  15921. +
  15922. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15923. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  15924. +
  15925. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15926. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  15927. +};
  15928. +
  15929. +/** Valid mirror modes */
  15930. +enum mmal_parameter_mirror {
  15931. + MMAL_PARAM_MIRROR_NONE,
  15932. + MMAL_PARAM_MIRROR_VERTICAL,
  15933. + MMAL_PARAM_MIRROR_HORIZONTAL,
  15934. + MMAL_PARAM_MIRROR_BOTH,
  15935. +};
  15936. +
  15937. +enum mmal_parameter_displaytransform {
  15938. + MMAL_DISPLAY_ROT0 = 0,
  15939. + MMAL_DISPLAY_MIRROR_ROT0 = 1,
  15940. + MMAL_DISPLAY_MIRROR_ROT180 = 2,
  15941. + MMAL_DISPLAY_ROT180 = 3,
  15942. + MMAL_DISPLAY_MIRROR_ROT90 = 4,
  15943. + MMAL_DISPLAY_ROT270 = 5,
  15944. + MMAL_DISPLAY_ROT90 = 6,
  15945. + MMAL_DISPLAY_MIRROR_ROT270 = 7,
  15946. +};
  15947. +
  15948. +enum mmal_parameter_displaymode {
  15949. + MMAL_DISPLAY_MODE_FILL = 0,
  15950. + MMAL_DISPLAY_MODE_LETTERBOX = 1,
  15951. +};
  15952. +
  15953. +enum mmal_parameter_displayset {
  15954. + MMAL_DISPLAY_SET_NONE = 0,
  15955. + MMAL_DISPLAY_SET_NUM = 1,
  15956. + MMAL_DISPLAY_SET_FULLSCREEN = 2,
  15957. + MMAL_DISPLAY_SET_TRANSFORM = 4,
  15958. + MMAL_DISPLAY_SET_DEST_RECT = 8,
  15959. + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
  15960. + MMAL_DISPLAY_SET_MODE = 0x20,
  15961. + MMAL_DISPLAY_SET_PIXEL = 0x40,
  15962. + MMAL_DISPLAY_SET_NOASPECT = 0x80,
  15963. + MMAL_DISPLAY_SET_LAYER = 0x100,
  15964. + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
  15965. + MMAL_DISPLAY_SET_ALPHA = 0x400,
  15966. +};
  15967. +
  15968. +struct mmal_parameter_displayregion {
  15969. + /** Bitfield that indicates which fields are set and should be
  15970. + * used. All other fields will maintain their current value.
  15971. + * \ref MMAL_DISPLAYSET_T defines the bits that can be
  15972. + * combined.
  15973. + */
  15974. + u32 set;
  15975. +
  15976. + /** Describes the display output device, with 0 typically
  15977. + * being a directly connected LCD display. The actual values
  15978. + * will depend on the hardware. Code using hard-wired numbers
  15979. + * (e.g. 2) is certain to fail.
  15980. + */
  15981. +
  15982. + u32 display_num;
  15983. + /** Indicates that we are using the full device screen area,
  15984. + * rather than a window of the display. If zero, then
  15985. + * dest_rect is used to specify a region of the display to
  15986. + * use.
  15987. + */
  15988. +
  15989. + s32 fullscreen;
  15990. + /** Indicates any rotation or flipping used to map frames onto
  15991. + * the natural display orientation.
  15992. + */
  15993. + u32 transform; /* enum mmal_parameter_displaytransform */
  15994. +
  15995. + /** Where to display the frame within the screen, if
  15996. + * fullscreen is zero.
  15997. + */
  15998. + struct vchiq_mmal_rect dest_rect;
  15999. +
  16000. + /** Indicates which area of the frame to display. If all
  16001. + * values are zero, the whole frame will be used.
  16002. + */
  16003. + struct vchiq_mmal_rect src_rect;
  16004. +
  16005. + /** If set to non-zero, indicates that any display scaling
  16006. + * should disregard the aspect ratio of the frame region being
  16007. + * displayed.
  16008. + */
  16009. + s32 noaspect;
  16010. +
  16011. + /** Indicates how the image should be scaled to fit the
  16012. + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
  16013. + * that the image should fill the screen by potentially
  16014. + * cropping the frames. Setting \code mode \endcode to \code
  16015. + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
  16016. + * source region should be displayed and black bars added if
  16017. + * necessary.
  16018. + */
  16019. + u32 mode; /* enum mmal_parameter_displaymode */
  16020. +
  16021. + /** If non-zero, defines the width of a source pixel relative
  16022. + * to \code pixel_y \endcode. If zero, then pixels default to
  16023. + * being square.
  16024. + */
  16025. + u32 pixel_x;
  16026. +
  16027. + /** If non-zero, defines the height of a source pixel relative
  16028. + * to \code pixel_x \endcode. If zero, then pixels default to
  16029. + * being square.
  16030. + */
  16031. + u32 pixel_y;
  16032. +
  16033. + /** Sets the relative depth of the images, with greater values
  16034. + * being in front of smaller values.
  16035. + */
  16036. + u32 layer;
  16037. +
  16038. + /** Set to non-zero to ensure copy protection is used on
  16039. + * output.
  16040. + */
  16041. + s32 copyprotect_required;
  16042. +
  16043. + /** Level of opacity of the layer, where zero is fully
  16044. + * transparent and 255 is fully opaque.
  16045. + */
  16046. + u32 alpha;
  16047. +};
  16048. +
  16049. +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
  16050. +
  16051. +struct mmal_parameter_imagefx_parameters {
  16052. + enum mmal_parameter_imagefx effect;
  16053. + u32 num_effect_params;
  16054. + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  16055. +};
  16056. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/mmal-vchiq.c linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c
  16057. --- linux-3.12.18/drivers/media/platform/bcm2835/mmal-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  16058. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c 2014-04-24 16:04:36.447091651 +0200
  16059. @@ -0,0 +1,1916 @@
  16060. +/*
  16061. + * Broadcom BM2835 V4L2 driver
  16062. + *
  16063. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  16064. + *
  16065. + * This file is subject to the terms and conditions of the GNU General Public
  16066. + * License. See the file COPYING in the main directory of this archive
  16067. + * for more details.
  16068. + *
  16069. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  16070. + * Dave Stevenson <dsteve@broadcom.com>
  16071. + * Simon Mellor <simellor@broadcom.com>
  16072. + * Luke Diamand <luked@broadcom.com>
  16073. + *
  16074. + * V4L2 driver MMAL vchiq interface code
  16075. + */
  16076. +
  16077. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  16078. +
  16079. +#include <linux/errno.h>
  16080. +#include <linux/kernel.h>
  16081. +#include <linux/mutex.h>
  16082. +#include <linux/mm.h>
  16083. +#include <linux/slab.h>
  16084. +#include <linux/completion.h>
  16085. +#include <linux/vmalloc.h>
  16086. +#include <asm/cacheflush.h>
  16087. +#include <media/videobuf2-vmalloc.h>
  16088. +
  16089. +#include "mmal-common.h"
  16090. +#include "mmal-vchiq.h"
  16091. +#include "mmal-msg.h"
  16092. +
  16093. +#define USE_VCHIQ_ARM
  16094. +#include "interface/vchi/vchi.h"
  16095. +
  16096. +/* maximum number of components supported */
  16097. +#define VCHIQ_MMAL_MAX_COMPONENTS 4
  16098. +
  16099. +/*#define FULL_MSG_DUMP 1*/
  16100. +
  16101. +#ifdef DEBUG
  16102. +static const char *const msg_type_names[] = {
  16103. + "UNKNOWN",
  16104. + "QUIT",
  16105. + "SERVICE_CLOSED",
  16106. + "GET_VERSION",
  16107. + "COMPONENT_CREATE",
  16108. + "COMPONENT_DESTROY",
  16109. + "COMPONENT_ENABLE",
  16110. + "COMPONENT_DISABLE",
  16111. + "PORT_INFO_GET",
  16112. + "PORT_INFO_SET",
  16113. + "PORT_ACTION",
  16114. + "BUFFER_FROM_HOST",
  16115. + "BUFFER_TO_HOST",
  16116. + "GET_STATS",
  16117. + "PORT_PARAMETER_SET",
  16118. + "PORT_PARAMETER_GET",
  16119. + "EVENT_TO_HOST",
  16120. + "GET_CORE_STATS_FOR_PORT",
  16121. + "OPAQUE_ALLOCATOR",
  16122. + "CONSUME_MEM",
  16123. + "LMK",
  16124. + "OPAQUE_ALLOCATOR_DESC",
  16125. + "DRM_GET_LHS32",
  16126. + "DRM_GET_TIME",
  16127. + "BUFFER_FROM_HOST_ZEROLEN",
  16128. + "PORT_FLUSH",
  16129. + "HOST_LOG",
  16130. +};
  16131. +#endif
  16132. +
  16133. +static const char *const port_action_type_names[] = {
  16134. + "UNKNOWN",
  16135. + "ENABLE",
  16136. + "DISABLE",
  16137. + "FLUSH",
  16138. + "CONNECT",
  16139. + "DISCONNECT",
  16140. + "SET_REQUIREMENTS",
  16141. +};
  16142. +
  16143. +#if defined(DEBUG)
  16144. +#if defined(FULL_MSG_DUMP)
  16145. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  16146. + do { \
  16147. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  16148. + msg_type_names[(MSG)->h.type], \
  16149. + (MSG)->h.type, (MSG_LEN)); \
  16150. + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
  16151. + 16, 4, (MSG), \
  16152. + sizeof(struct mmal_msg_header), 1); \
  16153. + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
  16154. + 16, 4, \
  16155. + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
  16156. + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
  16157. + } while (0)
  16158. +#else
  16159. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  16160. + { \
  16161. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  16162. + msg_type_names[(MSG)->h.type], \
  16163. + (MSG)->h.type, (MSG_LEN)); \
  16164. + }
  16165. +#endif
  16166. +#else
  16167. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
  16168. +#endif
  16169. +
  16170. +/* normal message context */
  16171. +struct mmal_msg_context {
  16172. + union {
  16173. + struct {
  16174. + /* work struct for defered callback - must come first */
  16175. + struct work_struct work;
  16176. + /* mmal instance */
  16177. + struct vchiq_mmal_instance *instance;
  16178. + /* mmal port */
  16179. + struct vchiq_mmal_port *port;
  16180. + /* actual buffer used to store bulk reply */
  16181. + struct mmal_buffer *buffer;
  16182. + /* amount of buffer used */
  16183. + unsigned long buffer_used;
  16184. + /* MMAL buffer flags */
  16185. + u32 mmal_flags;
  16186. + /* Presentation and Decode timestamps */
  16187. + s64 pts;
  16188. + s64 dts;
  16189. +
  16190. + int status; /* context status */
  16191. +
  16192. + } bulk; /* bulk data */
  16193. +
  16194. + struct {
  16195. + /* message handle to release */
  16196. + VCHI_HELD_MSG_T msg_handle;
  16197. + /* pointer to received message */
  16198. + struct mmal_msg *msg;
  16199. + /* received message length */
  16200. + u32 msg_len;
  16201. + /* completion upon reply */
  16202. + struct completion cmplt;
  16203. + } sync; /* synchronous response */
  16204. + } u;
  16205. +
  16206. +};
  16207. +
  16208. +struct vchiq_mmal_instance {
  16209. + VCHI_SERVICE_HANDLE_T handle;
  16210. +
  16211. + /* ensure serialised access to service */
  16212. + struct mutex vchiq_mutex;
  16213. +
  16214. + /* ensure serialised access to bulk operations */
  16215. + struct mutex bulk_mutex;
  16216. +
  16217. + /* vmalloc page to receive scratch bulk xfers into */
  16218. + void *bulk_scratch;
  16219. +
  16220. + /* component to use next */
  16221. + int component_idx;
  16222. + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
  16223. +};
  16224. +
  16225. +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
  16226. + *instance)
  16227. +{
  16228. + struct mmal_msg_context *msg_context;
  16229. +
  16230. + /* todo: should this be allocated from a pool to avoid kmalloc */
  16231. + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
  16232. + memset(msg_context, 0, sizeof(*msg_context));
  16233. +
  16234. + return msg_context;
  16235. +}
  16236. +
  16237. +static void release_msg_context(struct mmal_msg_context *msg_context)
  16238. +{
  16239. + kfree(msg_context);
  16240. +}
  16241. +
  16242. +/* deals with receipt of event to host message */
  16243. +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
  16244. + struct mmal_msg *msg, u32 msg_len)
  16245. +{
  16246. + pr_debug("unhandled event\n");
  16247. + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
  16248. + msg->u.event_to_host.client_component,
  16249. + msg->u.event_to_host.port_type,
  16250. + msg->u.event_to_host.port_num,
  16251. + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
  16252. +}
  16253. +
  16254. +/* workqueue scheduled callback
  16255. + *
  16256. + * we do this because it is important we do not call any other vchiq
  16257. + * sync calls from witin the message delivery thread
  16258. + */
  16259. +static void buffer_work_cb(struct work_struct *work)
  16260. +{
  16261. + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
  16262. +
  16263. + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
  16264. + msg_context->u.bulk.port,
  16265. + msg_context->u.bulk.status,
  16266. + msg_context->u.bulk.buffer,
  16267. + msg_context->u.bulk.buffer_used,
  16268. + msg_context->u.bulk.mmal_flags,
  16269. + msg_context->u.bulk.dts,
  16270. + msg_context->u.bulk.pts);
  16271. +
  16272. + /* release message context */
  16273. + release_msg_context(msg_context);
  16274. +}
  16275. +
  16276. +/* enqueue a bulk receive for a given message context */
  16277. +static int bulk_receive(struct vchiq_mmal_instance *instance,
  16278. + struct mmal_msg *msg,
  16279. + struct mmal_msg_context *msg_context)
  16280. +{
  16281. + unsigned long rd_len;
  16282. + unsigned long flags = 0;
  16283. + int ret;
  16284. +
  16285. + /* bulk mutex stops other bulk operations while we have a
  16286. + * receive in progress - released in callback
  16287. + */
  16288. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  16289. + if (ret != 0)
  16290. + return ret;
  16291. +
  16292. + rd_len = msg->u.buffer_from_host.buffer_header.length;
  16293. +
  16294. + /* take buffer from queue */
  16295. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  16296. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  16297. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16298. + pr_err("buffer list empty trying to submit bulk receive\n");
  16299. +
  16300. + /* todo: this is a serious error, we should never have
  16301. + * commited a buffer_to_host operation to the mmal
  16302. + * port without the buffer to back it up (underflow
  16303. + * handling) and there is no obvious way to deal with
  16304. + * this - how is the mmal servie going to react when
  16305. + * we fail to do the xfer and reschedule a buffer when
  16306. + * it arrives? perhaps a starved flag to indicate a
  16307. + * waiting bulk receive?
  16308. + */
  16309. +
  16310. + mutex_unlock(&instance->bulk_mutex);
  16311. +
  16312. + return -EINVAL;
  16313. + }
  16314. +
  16315. + msg_context->u.bulk.buffer =
  16316. + list_entry(msg_context->u.bulk.port->buffers.next,
  16317. + struct mmal_buffer, list);
  16318. + list_del(&msg_context->u.bulk.buffer->list);
  16319. +
  16320. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16321. +
  16322. + /* ensure we do not overrun the available buffer */
  16323. + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
  16324. + rd_len = msg_context->u.bulk.buffer->buffer_size;
  16325. + pr_warn("short read as not enough receive buffer space\n");
  16326. + /* todo: is this the correct response, what happens to
  16327. + * the rest of the message data?
  16328. + */
  16329. + }
  16330. +
  16331. + /* store length */
  16332. + msg_context->u.bulk.buffer_used = rd_len;
  16333. + msg_context->u.bulk.mmal_flags =
  16334. + msg->u.buffer_from_host.buffer_header.flags;
  16335. + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
  16336. + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
  16337. +
  16338. + // only need to flush L1 cache here, as VCHIQ takes care of the L2
  16339. + // cache.
  16340. + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
  16341. +
  16342. + /* queue the bulk submission */
  16343. + vchi_service_use(instance->handle);
  16344. + ret = vchi_bulk_queue_receive(instance->handle,
  16345. + msg_context->u.bulk.buffer->buffer,
  16346. + /* Actual receive needs to be a multiple
  16347. + * of 4 bytes
  16348. + */
  16349. + (rd_len + 3) & ~3,
  16350. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  16351. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  16352. + msg_context);
  16353. +
  16354. + vchi_service_release(instance->handle);
  16355. +
  16356. + if (ret != 0) {
  16357. + /* callback will not be clearing the mutex */
  16358. + mutex_unlock(&instance->bulk_mutex);
  16359. + }
  16360. +
  16361. + return ret;
  16362. +}
  16363. +
  16364. +/* enque a dummy bulk receive for a given message context */
  16365. +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
  16366. + struct mmal_msg_context *msg_context)
  16367. +{
  16368. + int ret;
  16369. +
  16370. + /* bulk mutex stops other bulk operations while we have a
  16371. + * receive in progress - released in callback
  16372. + */
  16373. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  16374. + if (ret != 0)
  16375. + return ret;
  16376. +
  16377. + /* zero length indicates this was a dummy transfer */
  16378. + msg_context->u.bulk.buffer_used = 0;
  16379. +
  16380. + /* queue the bulk submission */
  16381. + vchi_service_use(instance->handle);
  16382. +
  16383. + ret = vchi_bulk_queue_receive(instance->handle,
  16384. + instance->bulk_scratch,
  16385. + 8,
  16386. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  16387. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  16388. + msg_context);
  16389. +
  16390. + vchi_service_release(instance->handle);
  16391. +
  16392. + if (ret != 0) {
  16393. + /* callback will not be clearing the mutex */
  16394. + mutex_unlock(&instance->bulk_mutex);
  16395. + }
  16396. +
  16397. + return ret;
  16398. +}
  16399. +
  16400. +/* data in message, memcpy from packet into output buffer */
  16401. +static int inline_receive(struct vchiq_mmal_instance *instance,
  16402. + struct mmal_msg *msg,
  16403. + struct mmal_msg_context *msg_context)
  16404. +{
  16405. + unsigned long flags = 0;
  16406. +
  16407. + /* take buffer from queue */
  16408. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  16409. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  16410. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16411. + pr_err("buffer list empty trying to receive inline\n");
  16412. +
  16413. + /* todo: this is a serious error, we should never have
  16414. + * commited a buffer_to_host operation to the mmal
  16415. + * port without the buffer to back it up (with
  16416. + * underflow handling) and there is no obvious way to
  16417. + * deal with this. Less bad than the bulk case as we
  16418. + * can just drop this on the floor but...unhelpful
  16419. + */
  16420. + return -EINVAL;
  16421. + }
  16422. +
  16423. + msg_context->u.bulk.buffer =
  16424. + list_entry(msg_context->u.bulk.port->buffers.next,
  16425. + struct mmal_buffer, list);
  16426. + list_del(&msg_context->u.bulk.buffer->list);
  16427. +
  16428. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16429. +
  16430. + memcpy(msg_context->u.bulk.buffer->buffer,
  16431. + msg->u.buffer_from_host.short_data,
  16432. + msg->u.buffer_from_host.payload_in_message);
  16433. +
  16434. + msg_context->u.bulk.buffer_used =
  16435. + msg->u.buffer_from_host.payload_in_message;
  16436. +
  16437. + return 0;
  16438. +}
  16439. +
  16440. +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
  16441. +static int
  16442. +buffer_from_host(struct vchiq_mmal_instance *instance,
  16443. + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
  16444. +{
  16445. + struct mmal_msg_context *msg_context;
  16446. + struct mmal_msg m;
  16447. + int ret;
  16448. +
  16449. + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
  16450. +
  16451. + /* bulk mutex stops other bulk operations while we
  16452. + * have a receive in progress
  16453. + */
  16454. + if (mutex_lock_interruptible(&instance->bulk_mutex))
  16455. + return -EINTR;
  16456. +
  16457. + /* get context */
  16458. + msg_context = get_msg_context(instance);
  16459. + if (msg_context == NULL)
  16460. + return -ENOMEM;
  16461. +
  16462. + /* store bulk message context for when data arrives */
  16463. + msg_context->u.bulk.instance = instance;
  16464. + msg_context->u.bulk.port = port;
  16465. + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
  16466. + msg_context->u.bulk.buffer_used = 0;
  16467. +
  16468. + /* initialise work structure ready to schedule callback */
  16469. + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
  16470. +
  16471. + /* prep the buffer from host message */
  16472. + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
  16473. +
  16474. + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
  16475. + m.h.magic = MMAL_MAGIC;
  16476. + m.h.context = msg_context;
  16477. + m.h.status = 0;
  16478. +
  16479. + /* drvbuf is our private data passed back */
  16480. + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
  16481. + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
  16482. + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
  16483. + m.u.buffer_from_host.drvbuf.client_context = msg_context;
  16484. +
  16485. + /* buffer header */
  16486. + m.u.buffer_from_host.buffer_header.cmd = 0;
  16487. + m.u.buffer_from_host.buffer_header.data = buf->buffer;
  16488. + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
  16489. + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
  16490. + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
  16491. + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
  16492. + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
  16493. + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
  16494. +
  16495. + /* clear buffer type sepecific data */
  16496. + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
  16497. + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
  16498. +
  16499. + /* no payload in message */
  16500. + m.u.buffer_from_host.payload_in_message = 0;
  16501. +
  16502. + vchi_service_use(instance->handle);
  16503. +
  16504. + ret = vchi_msg_queue(instance->handle, &m,
  16505. + sizeof(struct mmal_msg_header) +
  16506. + sizeof(m.u.buffer_from_host),
  16507. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  16508. +
  16509. + if (ret != 0) {
  16510. + release_msg_context(msg_context);
  16511. + /* todo: is this correct error value? */
  16512. + }
  16513. +
  16514. + vchi_service_release(instance->handle);
  16515. +
  16516. + mutex_unlock(&instance->bulk_mutex);
  16517. +
  16518. + return ret;
  16519. +}
  16520. +
  16521. +/* submit a buffer to the mmal sevice
  16522. + *
  16523. + * the buffer_from_host uses size data from the ports next available
  16524. + * mmal_buffer and deals with there being no buffer available by
  16525. + * incrementing the underflow for later
  16526. + */
  16527. +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
  16528. + struct vchiq_mmal_port *port)
  16529. +{
  16530. + int ret;
  16531. + struct mmal_buffer *buf;
  16532. + unsigned long flags = 0;
  16533. +
  16534. + if (!port->enabled)
  16535. + return -EINVAL;
  16536. +
  16537. + /* peek buffer from queue */
  16538. + spin_lock_irqsave(&port->slock, flags);
  16539. + if (list_empty(&port->buffers)) {
  16540. + port->buffer_underflow++;
  16541. + spin_unlock_irqrestore(&port->slock, flags);
  16542. + return -ENOSPC;
  16543. + }
  16544. +
  16545. + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
  16546. +
  16547. + spin_unlock_irqrestore(&port->slock, flags);
  16548. +
  16549. + /* issue buffer to mmal service */
  16550. + ret = buffer_from_host(instance, port, buf);
  16551. + if (ret) {
  16552. + pr_err("adding buffer header failed\n");
  16553. + /* todo: how should this be dealt with */
  16554. + }
  16555. +
  16556. + return ret;
  16557. +}
  16558. +
  16559. +/* deals with receipt of buffer to host message */
  16560. +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
  16561. + struct mmal_msg *msg, u32 msg_len)
  16562. +{
  16563. + struct mmal_msg_context *msg_context;
  16564. +
  16565. + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
  16566. + instance, msg, msg_len);
  16567. +
  16568. + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
  16569. + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
  16570. + } else {
  16571. + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
  16572. + return;
  16573. + }
  16574. +
  16575. + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
  16576. + /* message reception had an error */
  16577. + pr_warn("error %d in reply\n", msg->h.status);
  16578. +
  16579. + msg_context->u.bulk.status = msg->h.status;
  16580. +
  16581. + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
  16582. + /* empty buffer */
  16583. + if (msg->u.buffer_from_host.buffer_header.flags &
  16584. + MMAL_BUFFER_HEADER_FLAG_EOS) {
  16585. + msg_context->u.bulk.status =
  16586. + dummy_bulk_receive(instance, msg_context);
  16587. + if (msg_context->u.bulk.status == 0)
  16588. + return; /* successful bulk submission, bulk
  16589. + * completion will trigger callback
  16590. + */
  16591. + } else {
  16592. + /* do callback with empty buffer - not EOS though */
  16593. + msg_context->u.bulk.status = 0;
  16594. + msg_context->u.bulk.buffer_used = 0;
  16595. + }
  16596. + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
  16597. + /* data is not in message, queue a bulk receive */
  16598. + msg_context->u.bulk.status =
  16599. + bulk_receive(instance, msg, msg_context);
  16600. + if (msg_context->u.bulk.status == 0)
  16601. + return; /* successful bulk submission, bulk
  16602. + * completion will trigger callback
  16603. + */
  16604. +
  16605. + /* failed to submit buffer, this will end badly */
  16606. + pr_err("error %d on bulk submission\n",
  16607. + msg_context->u.bulk.status);
  16608. +
  16609. + } else if (msg->u.buffer_from_host.payload_in_message <=
  16610. + MMAL_VC_SHORT_DATA) {
  16611. + /* data payload within message */
  16612. + msg_context->u.bulk.status = inline_receive(instance, msg,
  16613. + msg_context);
  16614. + } else {
  16615. + pr_err("message with invalid short payload\n");
  16616. +
  16617. + /* signal error */
  16618. + msg_context->u.bulk.status = -EINVAL;
  16619. + msg_context->u.bulk.buffer_used =
  16620. + msg->u.buffer_from_host.payload_in_message;
  16621. + }
  16622. +
  16623. + /* replace the buffer header */
  16624. + port_buffer_from_host(instance, msg_context->u.bulk.port);
  16625. +
  16626. + /* schedule the port callback */
  16627. + schedule_work(&msg_context->u.bulk.work);
  16628. +}
  16629. +
  16630. +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
  16631. + struct mmal_msg_context *msg_context)
  16632. +{
  16633. + /* bulk receive operation complete */
  16634. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  16635. +
  16636. + /* replace the buffer header */
  16637. + port_buffer_from_host(msg_context->u.bulk.instance,
  16638. + msg_context->u.bulk.port);
  16639. +
  16640. + msg_context->u.bulk.status = 0;
  16641. +
  16642. + /* schedule the port callback */
  16643. + schedule_work(&msg_context->u.bulk.work);
  16644. +}
  16645. +
  16646. +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
  16647. + struct mmal_msg_context *msg_context)
  16648. +{
  16649. + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
  16650. +
  16651. + /* bulk receive operation complete */
  16652. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  16653. +
  16654. + /* replace the buffer header */
  16655. + port_buffer_from_host(msg_context->u.bulk.instance,
  16656. + msg_context->u.bulk.port);
  16657. +
  16658. + msg_context->u.bulk.status = -EINTR;
  16659. +
  16660. + schedule_work(&msg_context->u.bulk.work);
  16661. +}
  16662. +
  16663. +/* incoming event service callback */
  16664. +static void service_callback(void *param,
  16665. + const VCHI_CALLBACK_REASON_T reason,
  16666. + void *bulk_ctx)
  16667. +{
  16668. + struct vchiq_mmal_instance *instance = param;
  16669. + int status;
  16670. + u32 msg_len;
  16671. + struct mmal_msg *msg;
  16672. + VCHI_HELD_MSG_T msg_handle;
  16673. +
  16674. + if (!instance) {
  16675. + pr_err("Message callback passed NULL instance\n");
  16676. + return;
  16677. + }
  16678. +
  16679. + switch (reason) {
  16680. + case VCHI_CALLBACK_MSG_AVAILABLE:
  16681. + status = vchi_msg_hold(instance->handle, (void **)&msg,
  16682. + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
  16683. + if (status) {
  16684. + pr_err("Unable to dequeue a message (%d)\n", status);
  16685. + break;
  16686. + }
  16687. +
  16688. + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
  16689. +
  16690. + /* handling is different for buffer messages */
  16691. + switch (msg->h.type) {
  16692. +
  16693. + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
  16694. + vchi_held_msg_release(&msg_handle);
  16695. + break;
  16696. +
  16697. + case MMAL_MSG_TYPE_EVENT_TO_HOST:
  16698. + event_to_host_cb(instance, msg, msg_len);
  16699. + vchi_held_msg_release(&msg_handle);
  16700. +
  16701. + break;
  16702. +
  16703. + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
  16704. + buffer_to_host_cb(instance, msg, msg_len);
  16705. + vchi_held_msg_release(&msg_handle);
  16706. + break;
  16707. +
  16708. + default:
  16709. + /* messages dependant on header context to complete */
  16710. +
  16711. + /* todo: the msg.context really ought to be sanity
  16712. + * checked before we just use it, afaict it comes back
  16713. + * and is used raw from the videocore. Perhaps it
  16714. + * should be verified the address lies in the kernel
  16715. + * address space.
  16716. + */
  16717. + if (msg->h.context == NULL) {
  16718. + pr_err("received message context was null!\n");
  16719. + vchi_held_msg_release(&msg_handle);
  16720. + break;
  16721. + }
  16722. +
  16723. + /* fill in context values */
  16724. + msg->h.context->u.sync.msg_handle = msg_handle;
  16725. + msg->h.context->u.sync.msg = msg;
  16726. + msg->h.context->u.sync.msg_len = msg_len;
  16727. +
  16728. + /* todo: should this check (completion_done()
  16729. + * == 1) for no one waiting? or do we need a
  16730. + * flag to tell us the completion has been
  16731. + * interrupted so we can free the message and
  16732. + * its context. This probably also solves the
  16733. + * message arriving after interruption todo
  16734. + * below
  16735. + */
  16736. +
  16737. + /* complete message so caller knows it happened */
  16738. + complete(&msg->h.context->u.sync.cmplt);
  16739. + break;
  16740. + }
  16741. +
  16742. + break;
  16743. +
  16744. + case VCHI_CALLBACK_BULK_RECEIVED:
  16745. + bulk_receive_cb(instance, bulk_ctx);
  16746. + break;
  16747. +
  16748. + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
  16749. + bulk_abort_cb(instance, bulk_ctx);
  16750. + break;
  16751. +
  16752. + case VCHI_CALLBACK_SERVICE_CLOSED:
  16753. + /* TODO: consider if this requires action if received when
  16754. + * driver is not explicitly closing the service
  16755. + */
  16756. + break;
  16757. +
  16758. + default:
  16759. + pr_err("Received unhandled message reason %d\n", reason);
  16760. + break;
  16761. + }
  16762. +}
  16763. +
  16764. +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
  16765. + struct mmal_msg *msg,
  16766. + unsigned int payload_len,
  16767. + struct mmal_msg **msg_out,
  16768. + VCHI_HELD_MSG_T *msg_handle_out)
  16769. +{
  16770. + struct mmal_msg_context msg_context;
  16771. + int ret;
  16772. +
  16773. + /* payload size must not cause message to exceed max size */
  16774. + if (payload_len >
  16775. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
  16776. + pr_err("payload length %d exceeds max:%d\n", payload_len,
  16777. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
  16778. + return -EINVAL;
  16779. + }
  16780. +
  16781. + init_completion(&msg_context.u.sync.cmplt);
  16782. +
  16783. + msg->h.magic = MMAL_MAGIC;
  16784. + msg->h.context = &msg_context;
  16785. + msg->h.status = 0;
  16786. +
  16787. + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
  16788. + ">>> sync message");
  16789. +
  16790. + vchi_service_use(instance->handle);
  16791. +
  16792. + ret = vchi_msg_queue(instance->handle,
  16793. + msg,
  16794. + sizeof(struct mmal_msg_header) + payload_len,
  16795. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  16796. +
  16797. + vchi_service_release(instance->handle);
  16798. +
  16799. + if (ret) {
  16800. + pr_err("error %d queuing message\n", ret);
  16801. + return ret;
  16802. + }
  16803. +
  16804. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, HZ);
  16805. + if (ret <= 0) {
  16806. + pr_err("error %d waiting for sync completion\n", ret);
  16807. + if (ret == 0)
  16808. + ret = -ETIME;
  16809. + /* todo: what happens if the message arrives after aborting */
  16810. + return ret;
  16811. + }
  16812. +
  16813. + *msg_out = msg_context.u.sync.msg;
  16814. + *msg_handle_out = msg_context.u.sync.msg_handle;
  16815. +
  16816. + return 0;
  16817. +}
  16818. +
  16819. +static void dump_port_info(struct vchiq_mmal_port *port)
  16820. +{
  16821. + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
  16822. +
  16823. + pr_debug("buffer minimum num:%d size:%d align:%d\n",
  16824. + port->minimum_buffer.num,
  16825. + port->minimum_buffer.size, port->minimum_buffer.alignment);
  16826. +
  16827. + pr_debug("buffer recommended num:%d size:%d align:%d\n",
  16828. + port->recommended_buffer.num,
  16829. + port->recommended_buffer.size,
  16830. + port->recommended_buffer.alignment);
  16831. +
  16832. + pr_debug("buffer current values num:%d size:%d align:%d\n",
  16833. + port->current_buffer.num,
  16834. + port->current_buffer.size, port->current_buffer.alignment);
  16835. +
  16836. + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
  16837. + port->format.type,
  16838. + port->format.encoding, port->format.encoding_variant);
  16839. +
  16840. + pr_debug(" bitrate:%d flags:0x%x\n",
  16841. + port->format.bitrate, port->format.flags);
  16842. +
  16843. + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
  16844. + pr_debug
  16845. + ("es video format: width:%d height:%d colourspace:0x%x\n",
  16846. + port->es.video.width, port->es.video.height,
  16847. + port->es.video.color_space);
  16848. +
  16849. + pr_debug(" : crop xywh %d,%d,%d,%d\n",
  16850. + port->es.video.crop.x,
  16851. + port->es.video.crop.y,
  16852. + port->es.video.crop.width, port->es.video.crop.height);
  16853. + pr_debug(" : framerate %d/%d aspect %d/%d\n",
  16854. + port->es.video.frame_rate.num,
  16855. + port->es.video.frame_rate.den,
  16856. + port->es.video.par.num, port->es.video.par.den);
  16857. + }
  16858. +}
  16859. +
  16860. +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
  16861. +{
  16862. +
  16863. + /* todo do readonly fields need setting at all? */
  16864. + p->type = port->type;
  16865. + p->index = port->index;
  16866. + p->index_all = 0;
  16867. + p->is_enabled = port->enabled;
  16868. + p->buffer_num_min = port->minimum_buffer.num;
  16869. + p->buffer_size_min = port->minimum_buffer.size;
  16870. + p->buffer_alignment_min = port->minimum_buffer.alignment;
  16871. + p->buffer_num_recommended = port->recommended_buffer.num;
  16872. + p->buffer_size_recommended = port->recommended_buffer.size;
  16873. +
  16874. + /* only three writable fields in a port */
  16875. + p->buffer_num = port->current_buffer.num;
  16876. + p->buffer_size = port->current_buffer.size;
  16877. + p->userdata = port;
  16878. +}
  16879. +
  16880. +static int port_info_set(struct vchiq_mmal_instance *instance,
  16881. + struct vchiq_mmal_port *port)
  16882. +{
  16883. + int ret;
  16884. + struct mmal_msg m;
  16885. + struct mmal_msg *rmsg;
  16886. + VCHI_HELD_MSG_T rmsg_handle;
  16887. +
  16888. + pr_debug("setting port info port %p\n", port);
  16889. + if (!port)
  16890. + return -1;
  16891. + dump_port_info(port);
  16892. +
  16893. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
  16894. +
  16895. + m.u.port_info_set.component_handle = port->component->handle;
  16896. + m.u.port_info_set.port_type = port->type;
  16897. + m.u.port_info_set.port_index = port->index;
  16898. +
  16899. + port_to_mmal_msg(port, &m.u.port_info_set.port);
  16900. +
  16901. + /* elementry stream format setup */
  16902. + m.u.port_info_set.format.type = port->format.type;
  16903. + m.u.port_info_set.format.encoding = port->format.encoding;
  16904. + m.u.port_info_set.format.encoding_variant =
  16905. + port->format.encoding_variant;
  16906. + m.u.port_info_set.format.bitrate = port->format.bitrate;
  16907. + m.u.port_info_set.format.flags = port->format.flags;
  16908. +
  16909. + memcpy(&m.u.port_info_set.es, &port->es,
  16910. + sizeof(union mmal_es_specific_format));
  16911. +
  16912. + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
  16913. + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
  16914. + port->format.extradata_size);
  16915. +
  16916. + ret = send_synchronous_mmal_msg(instance, &m,
  16917. + sizeof(m.u.port_info_set),
  16918. + &rmsg, &rmsg_handle);
  16919. + if (ret)
  16920. + return ret;
  16921. +
  16922. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
  16923. + /* got an unexpected message type in reply */
  16924. + ret = -EINVAL;
  16925. + goto release_msg;
  16926. + }
  16927. +
  16928. + /* return operation status */
  16929. + ret = -rmsg->u.port_info_get_reply.status;
  16930. +
  16931. + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
  16932. + port->component->handle, port->handle);
  16933. +
  16934. +release_msg:
  16935. + vchi_held_msg_release(&rmsg_handle);
  16936. +
  16937. + return ret;
  16938. +
  16939. +}
  16940. +
  16941. +/* use port info get message to retrive port information */
  16942. +static int port_info_get(struct vchiq_mmal_instance *instance,
  16943. + struct vchiq_mmal_port *port)
  16944. +{
  16945. + int ret;
  16946. + struct mmal_msg m;
  16947. + struct mmal_msg *rmsg;
  16948. + VCHI_HELD_MSG_T rmsg_handle;
  16949. +
  16950. + /* port info time */
  16951. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
  16952. + m.u.port_info_get.component_handle = port->component->handle;
  16953. + m.u.port_info_get.port_type = port->type;
  16954. + m.u.port_info_get.index = port->index;
  16955. +
  16956. + ret = send_synchronous_mmal_msg(instance, &m,
  16957. + sizeof(m.u.port_info_get),
  16958. + &rmsg, &rmsg_handle);
  16959. + if (ret)
  16960. + return ret;
  16961. +
  16962. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
  16963. + /* got an unexpected message type in reply */
  16964. + ret = -EINVAL;
  16965. + goto release_msg;
  16966. + }
  16967. +
  16968. + /* return operation status */
  16969. + ret = -rmsg->u.port_info_get_reply.status;
  16970. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  16971. + goto release_msg;
  16972. +
  16973. + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
  16974. + port->enabled = false;
  16975. + else
  16976. + port->enabled = true;
  16977. +
  16978. + /* copy the values out of the message */
  16979. + port->handle = rmsg->u.port_info_get_reply.port_handle;
  16980. +
  16981. + /* port type and index cached to use on port info set becuase
  16982. + * it does not use a port handle
  16983. + */
  16984. + port->type = rmsg->u.port_info_get_reply.port_type;
  16985. + port->index = rmsg->u.port_info_get_reply.port_index;
  16986. +
  16987. + port->minimum_buffer.num =
  16988. + rmsg->u.port_info_get_reply.port.buffer_num_min;
  16989. + port->minimum_buffer.size =
  16990. + rmsg->u.port_info_get_reply.port.buffer_size_min;
  16991. + port->minimum_buffer.alignment =
  16992. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  16993. +
  16994. + port->recommended_buffer.alignment =
  16995. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  16996. + port->recommended_buffer.num =
  16997. + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
  16998. +
  16999. + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
  17000. + port->current_buffer.size =
  17001. + rmsg->u.port_info_get_reply.port.buffer_size;
  17002. +
  17003. + /* stream format */
  17004. + port->format.type = rmsg->u.port_info_get_reply.format.type;
  17005. + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
  17006. + port->format.encoding_variant =
  17007. + rmsg->u.port_info_get_reply.format.encoding_variant;
  17008. + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
  17009. + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
  17010. +
  17011. + /* elementry stream format */
  17012. + memcpy(&port->es,
  17013. + &rmsg->u.port_info_get_reply.es,
  17014. + sizeof(union mmal_es_specific_format));
  17015. + port->format.es = &port->es;
  17016. +
  17017. + port->format.extradata_size =
  17018. + rmsg->u.port_info_get_reply.format.extradata_size;
  17019. + memcpy(port->format.extradata,
  17020. + rmsg->u.port_info_get_reply.extradata,
  17021. + port->format.extradata_size);
  17022. +
  17023. + pr_debug("received port info\n");
  17024. + dump_port_info(port);
  17025. +
  17026. +release_msg:
  17027. +
  17028. + pr_debug("%s:result:%d component:0x%x port:%d\n",
  17029. + __func__, ret, port->component->handle, port->handle);
  17030. +
  17031. + vchi_held_msg_release(&rmsg_handle);
  17032. +
  17033. + return ret;
  17034. +}
  17035. +
  17036. +/* create comonent on vc */
  17037. +static int create_component(struct vchiq_mmal_instance *instance,
  17038. + struct vchiq_mmal_component *component,
  17039. + const char *name)
  17040. +{
  17041. + int ret;
  17042. + struct mmal_msg m;
  17043. + struct mmal_msg *rmsg;
  17044. + VCHI_HELD_MSG_T rmsg_handle;
  17045. +
  17046. + /* build component create message */
  17047. + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
  17048. + m.u.component_create.client_component = component;
  17049. + strncpy(m.u.component_create.name, name,
  17050. + sizeof(m.u.component_create.name));
  17051. +
  17052. + ret = send_synchronous_mmal_msg(instance, &m,
  17053. + sizeof(m.u.component_create),
  17054. + &rmsg, &rmsg_handle);
  17055. + if (ret)
  17056. + return ret;
  17057. +
  17058. + if (rmsg->h.type != m.h.type) {
  17059. + /* got an unexpected message type in reply */
  17060. + ret = -EINVAL;
  17061. + goto release_msg;
  17062. + }
  17063. +
  17064. + ret = -rmsg->u.component_create_reply.status;
  17065. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  17066. + goto release_msg;
  17067. +
  17068. + /* a valid component response received */
  17069. + component->handle = rmsg->u.component_create_reply.component_handle;
  17070. + component->inputs = rmsg->u.component_create_reply.input_num;
  17071. + component->outputs = rmsg->u.component_create_reply.output_num;
  17072. + component->clocks = rmsg->u.component_create_reply.clock_num;
  17073. +
  17074. + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
  17075. + component->handle,
  17076. + component->inputs, component->outputs, component->clocks);
  17077. +
  17078. +release_msg:
  17079. + vchi_held_msg_release(&rmsg_handle);
  17080. +
  17081. + return ret;
  17082. +}
  17083. +
  17084. +/* destroys a component on vc */
  17085. +static int destroy_component(struct vchiq_mmal_instance *instance,
  17086. + struct vchiq_mmal_component *component)
  17087. +{
  17088. + int ret;
  17089. + struct mmal_msg m;
  17090. + struct mmal_msg *rmsg;
  17091. + VCHI_HELD_MSG_T rmsg_handle;
  17092. +
  17093. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
  17094. + m.u.component_destroy.component_handle = component->handle;
  17095. +
  17096. + ret = send_synchronous_mmal_msg(instance, &m,
  17097. + sizeof(m.u.component_destroy),
  17098. + &rmsg, &rmsg_handle);
  17099. + if (ret)
  17100. + return ret;
  17101. +
  17102. + if (rmsg->h.type != m.h.type) {
  17103. + /* got an unexpected message type in reply */
  17104. + ret = -EINVAL;
  17105. + goto release_msg;
  17106. + }
  17107. +
  17108. + ret = -rmsg->u.component_destroy_reply.status;
  17109. +
  17110. +release_msg:
  17111. +
  17112. + vchi_held_msg_release(&rmsg_handle);
  17113. +
  17114. + return ret;
  17115. +}
  17116. +
  17117. +/* enable a component on vc */
  17118. +static int enable_component(struct vchiq_mmal_instance *instance,
  17119. + struct vchiq_mmal_component *component)
  17120. +{
  17121. + int ret;
  17122. + struct mmal_msg m;
  17123. + struct mmal_msg *rmsg;
  17124. + VCHI_HELD_MSG_T rmsg_handle;
  17125. +
  17126. + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
  17127. + m.u.component_enable.component_handle = component->handle;
  17128. +
  17129. + ret = send_synchronous_mmal_msg(instance, &m,
  17130. + sizeof(m.u.component_enable),
  17131. + &rmsg, &rmsg_handle);
  17132. + if (ret)
  17133. + return ret;
  17134. +
  17135. + if (rmsg->h.type != m.h.type) {
  17136. + /* got an unexpected message type in reply */
  17137. + ret = -EINVAL;
  17138. + goto release_msg;
  17139. + }
  17140. +
  17141. + ret = -rmsg->u.component_enable_reply.status;
  17142. +
  17143. +release_msg:
  17144. + vchi_held_msg_release(&rmsg_handle);
  17145. +
  17146. + return ret;
  17147. +}
  17148. +
  17149. +/* disable a component on vc */
  17150. +static int disable_component(struct vchiq_mmal_instance *instance,
  17151. + struct vchiq_mmal_component *component)
  17152. +{
  17153. + int ret;
  17154. + struct mmal_msg m;
  17155. + struct mmal_msg *rmsg;
  17156. + VCHI_HELD_MSG_T rmsg_handle;
  17157. +
  17158. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
  17159. + m.u.component_disable.component_handle = component->handle;
  17160. +
  17161. + ret = send_synchronous_mmal_msg(instance, &m,
  17162. + sizeof(m.u.component_disable),
  17163. + &rmsg, &rmsg_handle);
  17164. + if (ret)
  17165. + return ret;
  17166. +
  17167. + if (rmsg->h.type != m.h.type) {
  17168. + /* got an unexpected message type in reply */
  17169. + ret = -EINVAL;
  17170. + goto release_msg;
  17171. + }
  17172. +
  17173. + ret = -rmsg->u.component_disable_reply.status;
  17174. +
  17175. +release_msg:
  17176. +
  17177. + vchi_held_msg_release(&rmsg_handle);
  17178. +
  17179. + return ret;
  17180. +}
  17181. +
  17182. +/* get version of mmal implementation */
  17183. +static int get_version(struct vchiq_mmal_instance *instance,
  17184. + u32 *major_out, u32 *minor_out)
  17185. +{
  17186. + int ret;
  17187. + struct mmal_msg m;
  17188. + struct mmal_msg *rmsg;
  17189. + VCHI_HELD_MSG_T rmsg_handle;
  17190. +
  17191. + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
  17192. +
  17193. + ret = send_synchronous_mmal_msg(instance, &m,
  17194. + sizeof(m.u.version),
  17195. + &rmsg, &rmsg_handle);
  17196. + if (ret)
  17197. + return ret;
  17198. +
  17199. + if (rmsg->h.type != m.h.type) {
  17200. + /* got an unexpected message type in reply */
  17201. + ret = -EINVAL;
  17202. + goto release_msg;
  17203. + }
  17204. +
  17205. + *major_out = rmsg->u.version.major;
  17206. + *minor_out = rmsg->u.version.minor;
  17207. +
  17208. +release_msg:
  17209. + vchi_held_msg_release(&rmsg_handle);
  17210. +
  17211. + return ret;
  17212. +}
  17213. +
  17214. +/* do a port action with a port as a parameter */
  17215. +static int port_action_port(struct vchiq_mmal_instance *instance,
  17216. + struct vchiq_mmal_port *port,
  17217. + enum mmal_msg_port_action_type action_type)
  17218. +{
  17219. + int ret;
  17220. + struct mmal_msg m;
  17221. + struct mmal_msg *rmsg;
  17222. + VCHI_HELD_MSG_T rmsg_handle;
  17223. +
  17224. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  17225. + m.u.port_action_port.component_handle = port->component->handle;
  17226. + m.u.port_action_port.port_handle = port->handle;
  17227. + m.u.port_action_port.action = action_type;
  17228. +
  17229. + port_to_mmal_msg(port, &m.u.port_action_port.port);
  17230. +
  17231. + ret = send_synchronous_mmal_msg(instance, &m,
  17232. + sizeof(m.u.port_action_port),
  17233. + &rmsg, &rmsg_handle);
  17234. + if (ret)
  17235. + return ret;
  17236. +
  17237. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  17238. + /* got an unexpected message type in reply */
  17239. + ret = -EINVAL;
  17240. + goto release_msg;
  17241. + }
  17242. +
  17243. + ret = -rmsg->u.port_action_reply.status;
  17244. +
  17245. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
  17246. + __func__,
  17247. + ret, port->component->handle, port->handle,
  17248. + port_action_type_names[action_type], action_type);
  17249. +
  17250. +release_msg:
  17251. + vchi_held_msg_release(&rmsg_handle);
  17252. +
  17253. + return ret;
  17254. +}
  17255. +
  17256. +/* do a port action with handles as parameters */
  17257. +static int port_action_handle(struct vchiq_mmal_instance *instance,
  17258. + struct vchiq_mmal_port *port,
  17259. + enum mmal_msg_port_action_type action_type,
  17260. + u32 connect_component_handle,
  17261. + u32 connect_port_handle)
  17262. +{
  17263. + int ret;
  17264. + struct mmal_msg m;
  17265. + struct mmal_msg *rmsg;
  17266. + VCHI_HELD_MSG_T rmsg_handle;
  17267. +
  17268. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  17269. +
  17270. + m.u.port_action_handle.component_handle = port->component->handle;
  17271. + m.u.port_action_handle.port_handle = port->handle;
  17272. + m.u.port_action_handle.action = action_type;
  17273. +
  17274. + m.u.port_action_handle.connect_component_handle =
  17275. + connect_component_handle;
  17276. + m.u.port_action_handle.connect_port_handle = connect_port_handle;
  17277. +
  17278. + ret = send_synchronous_mmal_msg(instance, &m,
  17279. + sizeof(m.u.port_action_handle),
  17280. + &rmsg, &rmsg_handle);
  17281. + if (ret)
  17282. + return ret;
  17283. +
  17284. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  17285. + /* got an unexpected message type in reply */
  17286. + ret = -EINVAL;
  17287. + goto release_msg;
  17288. + }
  17289. +
  17290. + ret = -rmsg->u.port_action_reply.status;
  17291. +
  17292. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
  17293. + " connect component:0x%x connect port:%d\n",
  17294. + __func__,
  17295. + ret, port->component->handle, port->handle,
  17296. + port_action_type_names[action_type],
  17297. + action_type, connect_component_handle, connect_port_handle);
  17298. +
  17299. +release_msg:
  17300. + vchi_held_msg_release(&rmsg_handle);
  17301. +
  17302. + return ret;
  17303. +}
  17304. +
  17305. +static int port_parameter_set(struct vchiq_mmal_instance *instance,
  17306. + struct vchiq_mmal_port *port,
  17307. + u32 parameter_id, void *value, u32 value_size)
  17308. +{
  17309. + int ret;
  17310. + struct mmal_msg m;
  17311. + struct mmal_msg *rmsg;
  17312. + VCHI_HELD_MSG_T rmsg_handle;
  17313. +
  17314. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
  17315. +
  17316. + m.u.port_parameter_set.component_handle = port->component->handle;
  17317. + m.u.port_parameter_set.port_handle = port->handle;
  17318. + m.u.port_parameter_set.id = parameter_id;
  17319. + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
  17320. + memcpy(&m.u.port_parameter_set.value, value, value_size);
  17321. +
  17322. + ret = send_synchronous_mmal_msg(instance, &m,
  17323. + (4 * sizeof(u32)) + value_size,
  17324. + &rmsg, &rmsg_handle);
  17325. + if (ret)
  17326. + return ret;
  17327. +
  17328. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
  17329. + /* got an unexpected message type in reply */
  17330. + ret = -EINVAL;
  17331. + goto release_msg;
  17332. + }
  17333. +
  17334. + ret = -rmsg->u.port_parameter_set_reply.status;
  17335. +
  17336. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
  17337. + __func__,
  17338. + ret, port->component->handle, port->handle, parameter_id);
  17339. +
  17340. +release_msg:
  17341. + vchi_held_msg_release(&rmsg_handle);
  17342. +
  17343. + return ret;
  17344. +}
  17345. +
  17346. +static int port_parameter_get(struct vchiq_mmal_instance *instance,
  17347. + struct vchiq_mmal_port *port,
  17348. + u32 parameter_id, void *value, u32 *value_size)
  17349. +{
  17350. + int ret;
  17351. + struct mmal_msg m;
  17352. + struct mmal_msg *rmsg;
  17353. + VCHI_HELD_MSG_T rmsg_handle;
  17354. +
  17355. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
  17356. +
  17357. + m.u.port_parameter_get.component_handle = port->component->handle;
  17358. + m.u.port_parameter_get.port_handle = port->handle;
  17359. + m.u.port_parameter_get.id = parameter_id;
  17360. + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
  17361. +
  17362. + ret = send_synchronous_mmal_msg(instance, &m,
  17363. + sizeof(struct
  17364. + mmal_msg_port_parameter_get),
  17365. + &rmsg, &rmsg_handle);
  17366. + if (ret)
  17367. + return ret;
  17368. +
  17369. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
  17370. + /* got an unexpected message type in reply */
  17371. + pr_err("Incorrect reply type %d\n", rmsg->h.type);
  17372. + ret = -EINVAL;
  17373. + goto release_msg;
  17374. + }
  17375. +
  17376. + ret = -rmsg->u.port_parameter_get_reply.status;
  17377. + if (ret) {
  17378. + /* Copy only as much as we have space for
  17379. + * but report true size of parameter
  17380. + */
  17381. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  17382. + *value_size);
  17383. + *value_size = rmsg->u.port_parameter_get_reply.size;
  17384. + } else
  17385. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  17386. + rmsg->u.port_parameter_get_reply.size);
  17387. +
  17388. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  17389. + ret, port->component->handle, port->handle, parameter_id);
  17390. +
  17391. +release_msg:
  17392. + vchi_held_msg_release(&rmsg_handle);
  17393. +
  17394. + return ret;
  17395. +}
  17396. +
  17397. +/* disables a port and drains buffers from it */
  17398. +static int port_disable(struct vchiq_mmal_instance *instance,
  17399. + struct vchiq_mmal_port *port)
  17400. +{
  17401. + int ret;
  17402. + struct list_head *q, *buf_head;
  17403. + unsigned long flags = 0;
  17404. +
  17405. + if (!port->enabled)
  17406. + return 0;
  17407. +
  17408. + port->enabled = false;
  17409. +
  17410. + ret = port_action_port(instance, port,
  17411. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
  17412. + if (ret == 0) {
  17413. +
  17414. + /* drain all queued buffers on port */
  17415. + spin_lock_irqsave(&port->slock, flags);
  17416. +
  17417. + list_for_each_safe(buf_head, q, &port->buffers) {
  17418. + struct mmal_buffer *mmalbuf;
  17419. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  17420. + list);
  17421. + list_del(buf_head);
  17422. + if (port->buffer_cb)
  17423. + port->buffer_cb(instance,
  17424. + port, 0, mmalbuf, 0, 0,
  17425. + MMAL_TIME_UNKNOWN,
  17426. + MMAL_TIME_UNKNOWN);
  17427. + }
  17428. +
  17429. + spin_unlock_irqrestore(&port->slock, flags);
  17430. +
  17431. + ret = port_info_get(instance, port);
  17432. + }
  17433. +
  17434. + return ret;
  17435. +}
  17436. +
  17437. +/* enable a port */
  17438. +static int port_enable(struct vchiq_mmal_instance *instance,
  17439. + struct vchiq_mmal_port *port)
  17440. +{
  17441. + unsigned int hdr_count;
  17442. + struct list_head *buf_head;
  17443. + int ret;
  17444. +
  17445. + if (port->enabled)
  17446. + return 0;
  17447. +
  17448. + /* ensure there are enough buffers queued to cover the buffer headers */
  17449. + if (port->buffer_cb != NULL) {
  17450. + hdr_count = 0;
  17451. + list_for_each(buf_head, &port->buffers) {
  17452. + hdr_count++;
  17453. + }
  17454. + if (hdr_count < port->current_buffer.num)
  17455. + return -ENOSPC;
  17456. + }
  17457. +
  17458. + ret = port_action_port(instance, port,
  17459. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
  17460. + if (ret)
  17461. + goto done;
  17462. +
  17463. + port->enabled = true;
  17464. +
  17465. + if (port->buffer_cb) {
  17466. + /* send buffer headers to videocore */
  17467. + hdr_count = 1;
  17468. + list_for_each(buf_head, &port->buffers) {
  17469. + struct mmal_buffer *mmalbuf;
  17470. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  17471. + list);
  17472. + ret = buffer_from_host(instance, port, mmalbuf);
  17473. + if (ret)
  17474. + goto done;
  17475. +
  17476. + hdr_count++;
  17477. + if (hdr_count > port->current_buffer.num)
  17478. + break;
  17479. + }
  17480. + }
  17481. +
  17482. + ret = port_info_get(instance, port);
  17483. +
  17484. +done:
  17485. + return ret;
  17486. +}
  17487. +
  17488. +/* ------------------------------------------------------------------
  17489. + * Exported API
  17490. + *------------------------------------------------------------------*/
  17491. +
  17492. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  17493. + struct vchiq_mmal_port *port)
  17494. +{
  17495. + int ret;
  17496. +
  17497. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17498. + return -EINTR;
  17499. +
  17500. + ret = port_info_set(instance, port);
  17501. + if (ret)
  17502. + goto release_unlock;
  17503. +
  17504. + /* read what has actually been set */
  17505. + ret = port_info_get(instance, port);
  17506. +
  17507. +release_unlock:
  17508. + mutex_unlock(&instance->vchiq_mutex);
  17509. +
  17510. + return ret;
  17511. +
  17512. +}
  17513. +
  17514. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  17515. + struct vchiq_mmal_port *port,
  17516. + u32 parameter, void *value, u32 value_size)
  17517. +{
  17518. + int ret;
  17519. +
  17520. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17521. + return -EINTR;
  17522. +
  17523. + ret = port_parameter_set(instance, port, parameter, value, value_size);
  17524. +
  17525. + mutex_unlock(&instance->vchiq_mutex);
  17526. +
  17527. + return ret;
  17528. +}
  17529. +
  17530. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  17531. + struct vchiq_mmal_port *port,
  17532. + u32 parameter, void *value, u32 *value_size)
  17533. +{
  17534. + int ret;
  17535. +
  17536. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17537. + return -EINTR;
  17538. +
  17539. + ret = port_parameter_get(instance, port, parameter, value, value_size);
  17540. +
  17541. + mutex_unlock(&instance->vchiq_mutex);
  17542. +
  17543. + return ret;
  17544. +}
  17545. +
  17546. +/* enable a port
  17547. + *
  17548. + * enables a port and queues buffers for satisfying callbacks if we
  17549. + * provide a callback handler
  17550. + */
  17551. +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
  17552. + struct vchiq_mmal_port *port,
  17553. + vchiq_mmal_buffer_cb buffer_cb)
  17554. +{
  17555. + int ret;
  17556. +
  17557. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17558. + return -EINTR;
  17559. +
  17560. + /* already enabled - noop */
  17561. + if (port->enabled) {
  17562. + ret = 0;
  17563. + goto unlock;
  17564. + }
  17565. +
  17566. + port->buffer_cb = buffer_cb;
  17567. +
  17568. + ret = port_enable(instance, port);
  17569. +
  17570. +unlock:
  17571. + mutex_unlock(&instance->vchiq_mutex);
  17572. +
  17573. + return ret;
  17574. +}
  17575. +
  17576. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  17577. + struct vchiq_mmal_port *port)
  17578. +{
  17579. + int ret;
  17580. +
  17581. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17582. + return -EINTR;
  17583. +
  17584. + if (!port->enabled) {
  17585. + mutex_unlock(&instance->vchiq_mutex);
  17586. + return 0;
  17587. + }
  17588. +
  17589. + ret = port_disable(instance, port);
  17590. +
  17591. + mutex_unlock(&instance->vchiq_mutex);
  17592. +
  17593. + return ret;
  17594. +}
  17595. +
  17596. +/* ports will be connected in a tunneled manner so data buffers
  17597. + * are not handled by client.
  17598. + */
  17599. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  17600. + struct vchiq_mmal_port *src,
  17601. + struct vchiq_mmal_port *dst)
  17602. +{
  17603. + int ret;
  17604. +
  17605. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17606. + return -EINTR;
  17607. +
  17608. + /* disconnect ports if connected */
  17609. + if (src->connected != NULL) {
  17610. + ret = port_disable(instance, src);
  17611. + if (ret) {
  17612. + pr_err("failed disabling src port(%d)\n", ret);
  17613. + goto release_unlock;
  17614. + }
  17615. +
  17616. + /* do not need to disable the destination port as they
  17617. + * are connected and it is done automatically
  17618. + */
  17619. +
  17620. + ret = port_action_handle(instance, src,
  17621. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
  17622. + src->connected->component->handle,
  17623. + src->connected->handle);
  17624. + if (ret < 0) {
  17625. + pr_err("failed disconnecting src port\n");
  17626. + goto release_unlock;
  17627. + }
  17628. + src->connected->enabled = false;
  17629. + src->connected = NULL;
  17630. + }
  17631. +
  17632. + if (dst == NULL) {
  17633. + /* do not make new connection */
  17634. + ret = 0;
  17635. + pr_debug("not making new connection\n");
  17636. + goto release_unlock;
  17637. + }
  17638. +
  17639. + /* copy src port format to dst */
  17640. + dst->format.encoding = src->format.encoding;
  17641. + dst->es.video.width = src->es.video.width;
  17642. + dst->es.video.height = src->es.video.height;
  17643. + dst->es.video.crop.x = src->es.video.crop.x;
  17644. + dst->es.video.crop.y = src->es.video.crop.y;
  17645. + dst->es.video.crop.width = src->es.video.crop.width;
  17646. + dst->es.video.crop.height = src->es.video.crop.height;
  17647. + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
  17648. + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
  17649. +
  17650. + /* set new format */
  17651. + ret = port_info_set(instance, dst);
  17652. + if (ret) {
  17653. + pr_debug("setting port info failed\n");
  17654. + goto release_unlock;
  17655. + }
  17656. +
  17657. + /* read what has actually been set */
  17658. + ret = port_info_get(instance, dst);
  17659. + if (ret) {
  17660. + pr_debug("read back port info failed\n");
  17661. + goto release_unlock;
  17662. + }
  17663. +
  17664. + /* connect two ports together */
  17665. + ret = port_action_handle(instance, src,
  17666. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
  17667. + dst->component->handle, dst->handle);
  17668. + if (ret < 0) {
  17669. + pr_debug("connecting port %d:%d to %d:%d failed\n",
  17670. + src->component->handle, src->handle,
  17671. + dst->component->handle, dst->handle);
  17672. + goto release_unlock;
  17673. + }
  17674. + src->connected = dst;
  17675. +
  17676. +release_unlock:
  17677. +
  17678. + mutex_unlock(&instance->vchiq_mutex);
  17679. +
  17680. + return ret;
  17681. +}
  17682. +
  17683. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  17684. + struct vchiq_mmal_port *port,
  17685. + struct mmal_buffer *buffer)
  17686. +{
  17687. + unsigned long flags = 0;
  17688. +
  17689. + spin_lock_irqsave(&port->slock, flags);
  17690. + list_add_tail(&buffer->list, &port->buffers);
  17691. + spin_unlock_irqrestore(&port->slock, flags);
  17692. +
  17693. + /* the port previously underflowed because it was missing a
  17694. + * mmal_buffer which has just been added, submit that buffer
  17695. + * to the mmal service.
  17696. + */
  17697. + if (port->buffer_underflow) {
  17698. + port_buffer_from_host(instance, port);
  17699. + port->buffer_underflow--;
  17700. + }
  17701. +
  17702. + return 0;
  17703. +}
  17704. +
  17705. +/* Initialise a mmal component and its ports
  17706. + *
  17707. + */
  17708. +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
  17709. + const char *name,
  17710. + struct vchiq_mmal_component **component_out)
  17711. +{
  17712. + int ret;
  17713. + int idx; /* port index */
  17714. + struct vchiq_mmal_component *component;
  17715. +
  17716. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17717. + return -EINTR;
  17718. +
  17719. + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
  17720. + ret = -EINVAL; /* todo is this correct error? */
  17721. + goto unlock;
  17722. + }
  17723. +
  17724. + component = &instance->component[instance->component_idx];
  17725. +
  17726. + ret = create_component(instance, component, name);
  17727. + if (ret < 0)
  17728. + goto unlock;
  17729. +
  17730. + /* ports info needs gathering */
  17731. + component->control.type = MMAL_PORT_TYPE_CONTROL;
  17732. + component->control.index = 0;
  17733. + component->control.component = component;
  17734. + spin_lock_init(&component->control.slock);
  17735. + INIT_LIST_HEAD(&component->control.buffers);
  17736. + ret = port_info_get(instance, &component->control);
  17737. + if (ret < 0)
  17738. + goto release_component;
  17739. +
  17740. + for (idx = 0; idx < component->inputs; idx++) {
  17741. + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
  17742. + component->input[idx].index = idx;
  17743. + component->input[idx].component = component;
  17744. + spin_lock_init(&component->input[idx].slock);
  17745. + INIT_LIST_HEAD(&component->input[idx].buffers);
  17746. + ret = port_info_get(instance, &component->input[idx]);
  17747. + if (ret < 0)
  17748. + goto release_component;
  17749. + }
  17750. +
  17751. + for (idx = 0; idx < component->outputs; idx++) {
  17752. + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
  17753. + component->output[idx].index = idx;
  17754. + component->output[idx].component = component;
  17755. + spin_lock_init(&component->output[idx].slock);
  17756. + INIT_LIST_HEAD(&component->output[idx].buffers);
  17757. + ret = port_info_get(instance, &component->output[idx]);
  17758. + if (ret < 0)
  17759. + goto release_component;
  17760. + }
  17761. +
  17762. + for (idx = 0; idx < component->clocks; idx++) {
  17763. + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
  17764. + component->clock[idx].index = idx;
  17765. + component->clock[idx].component = component;
  17766. + spin_lock_init(&component->clock[idx].slock);
  17767. + INIT_LIST_HEAD(&component->clock[idx].buffers);
  17768. + ret = port_info_get(instance, &component->clock[idx]);
  17769. + if (ret < 0)
  17770. + goto release_component;
  17771. + }
  17772. +
  17773. + instance->component_idx++;
  17774. +
  17775. + *component_out = component;
  17776. +
  17777. + mutex_unlock(&instance->vchiq_mutex);
  17778. +
  17779. + return 0;
  17780. +
  17781. +release_component:
  17782. + destroy_component(instance, component);
  17783. +unlock:
  17784. + mutex_unlock(&instance->vchiq_mutex);
  17785. +
  17786. + return ret;
  17787. +}
  17788. +
  17789. +/*
  17790. + * cause a mmal component to be destroyed
  17791. + */
  17792. +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
  17793. + struct vchiq_mmal_component *component)
  17794. +{
  17795. + int ret;
  17796. +
  17797. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17798. + return -EINTR;
  17799. +
  17800. + if (component->enabled)
  17801. + ret = disable_component(instance, component);
  17802. +
  17803. + ret = destroy_component(instance, component);
  17804. +
  17805. + mutex_unlock(&instance->vchiq_mutex);
  17806. +
  17807. + return ret;
  17808. +}
  17809. +
  17810. +/*
  17811. + * cause a mmal component to be enabled
  17812. + */
  17813. +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
  17814. + struct vchiq_mmal_component *component)
  17815. +{
  17816. + int ret;
  17817. +
  17818. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17819. + return -EINTR;
  17820. +
  17821. + if (component->enabled) {
  17822. + mutex_unlock(&instance->vchiq_mutex);
  17823. + return 0;
  17824. + }
  17825. +
  17826. + ret = enable_component(instance, component);
  17827. + if (ret == 0)
  17828. + component->enabled = true;
  17829. +
  17830. + mutex_unlock(&instance->vchiq_mutex);
  17831. +
  17832. + return ret;
  17833. +}
  17834. +
  17835. +/*
  17836. + * cause a mmal component to be enabled
  17837. + */
  17838. +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
  17839. + struct vchiq_mmal_component *component)
  17840. +{
  17841. + int ret;
  17842. +
  17843. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17844. + return -EINTR;
  17845. +
  17846. + if (!component->enabled) {
  17847. + mutex_unlock(&instance->vchiq_mutex);
  17848. + return 0;
  17849. + }
  17850. +
  17851. + ret = disable_component(instance, component);
  17852. + if (ret == 0)
  17853. + component->enabled = false;
  17854. +
  17855. + mutex_unlock(&instance->vchiq_mutex);
  17856. +
  17857. + return ret;
  17858. +}
  17859. +
  17860. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  17861. + u32 *major_out, u32 *minor_out)
  17862. +{
  17863. + int ret;
  17864. +
  17865. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17866. + return -EINTR;
  17867. +
  17868. + ret = get_version(instance, major_out, minor_out);
  17869. +
  17870. + mutex_unlock(&instance->vchiq_mutex);
  17871. +
  17872. + return ret;
  17873. +}
  17874. +
  17875. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
  17876. +{
  17877. + int status = 0;
  17878. +
  17879. + if (instance == NULL)
  17880. + return -EINVAL;
  17881. +
  17882. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17883. + return -EINTR;
  17884. +
  17885. + vchi_service_use(instance->handle);
  17886. +
  17887. + status = vchi_service_close(instance->handle);
  17888. + if (status != 0)
  17889. + pr_err("mmal-vchiq: VCHIQ close failed");
  17890. +
  17891. + mutex_unlock(&instance->vchiq_mutex);
  17892. +
  17893. + vfree(instance->bulk_scratch);
  17894. +
  17895. + kfree(instance);
  17896. +
  17897. + return status;
  17898. +}
  17899. +
  17900. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
  17901. +{
  17902. + int status;
  17903. + struct vchiq_mmal_instance *instance;
  17904. + static VCHI_CONNECTION_T *vchi_connection;
  17905. + static VCHI_INSTANCE_T vchi_instance;
  17906. + SERVICE_CREATION_T params = {
  17907. + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
  17908. + VC_MMAL_SERVER_NAME,
  17909. + vchi_connection,
  17910. + 0, /* rx fifo size (unused) */
  17911. + 0, /* tx fifo size (unused) */
  17912. + service_callback,
  17913. + NULL, /* service callback parameter */
  17914. + 1, /* unaligned bulk receives */
  17915. + 1, /* unaligned bulk transmits */
  17916. + 0 /* want crc check on bulk transfers */
  17917. + };
  17918. +
  17919. + /* compile time checks to ensure structure size as they are
  17920. + * directly (de)serialised from memory.
  17921. + */
  17922. +
  17923. + /* ensure the header structure has packed to the correct size */
  17924. + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
  17925. +
  17926. + /* ensure message structure does not exceed maximum length */
  17927. + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
  17928. +
  17929. + /* mmal port struct is correct size */
  17930. + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
  17931. +
  17932. + /* create a vchi instance */
  17933. + status = vchi_initialise(&vchi_instance);
  17934. + if (status) {
  17935. + pr_err("Failed to initialise VCHI instance (status=%d)\n",
  17936. + status);
  17937. + return -EIO;
  17938. + }
  17939. +
  17940. + status = vchi_connect(NULL, 0, vchi_instance);
  17941. + if (status) {
  17942. + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
  17943. + return -EIO;
  17944. + }
  17945. +
  17946. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  17947. + memset(instance, 0, sizeof(*instance));
  17948. +
  17949. + mutex_init(&instance->vchiq_mutex);
  17950. + mutex_init(&instance->bulk_mutex);
  17951. +
  17952. + instance->bulk_scratch = vmalloc(PAGE_SIZE);
  17953. +
  17954. + params.callback_param = instance;
  17955. +
  17956. + status = vchi_service_open(vchi_instance, &params, &instance->handle);
  17957. + if (status) {
  17958. + pr_err("Failed to open VCHI service connection (status=%d)\n",
  17959. + status);
  17960. + goto err_close_services;
  17961. + }
  17962. +
  17963. + vchi_service_release(instance->handle);
  17964. +
  17965. + *out_instance = instance;
  17966. +
  17967. + return 0;
  17968. +
  17969. +err_close_services:
  17970. +
  17971. + vchi_service_close(instance->handle);
  17972. + vfree(instance->bulk_scratch);
  17973. + kfree(instance);
  17974. + return -ENODEV;
  17975. +}
  17976. diff -Nur linux-3.12.18/drivers/media/platform/bcm2835/mmal-vchiq.h linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h
  17977. --- linux-3.12.18/drivers/media/platform/bcm2835/mmal-vchiq.h 1970-01-01 01:00:00.000000000 +0100
  17978. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h 2014-04-24 15:35:02.713549510 +0200
  17979. @@ -0,0 +1,178 @@
  17980. +/*
  17981. + * Broadcom BM2835 V4L2 driver
  17982. + *
  17983. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  17984. + *
  17985. + * This file is subject to the terms and conditions of the GNU General Public
  17986. + * License. See the file COPYING in the main directory of this archive
  17987. + * for more details.
  17988. + *
  17989. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  17990. + * Dave Stevenson <dsteve@broadcom.com>
  17991. + * Simon Mellor <simellor@broadcom.com>
  17992. + * Luke Diamand <luked@broadcom.com>
  17993. + *
  17994. + * MMAL interface to VCHIQ message passing
  17995. + */
  17996. +
  17997. +#ifndef MMAL_VCHIQ_H
  17998. +#define MMAL_VCHIQ_H
  17999. +
  18000. +#include "mmal-msg-format.h"
  18001. +
  18002. +#define MAX_PORT_COUNT 4
  18003. +
  18004. +/* Maximum size of the format extradata. */
  18005. +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
  18006. +
  18007. +struct vchiq_mmal_instance;
  18008. +
  18009. +enum vchiq_mmal_es_type {
  18010. + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
  18011. + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
  18012. + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
  18013. + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
  18014. + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
  18015. +};
  18016. +
  18017. +/* rectangle, used lots so it gets its own struct */
  18018. +struct vchiq_mmal_rect {
  18019. + s32 x;
  18020. + s32 y;
  18021. + s32 width;
  18022. + s32 height;
  18023. +};
  18024. +
  18025. +struct vchiq_mmal_port_buffer {
  18026. + unsigned int num; /* number of buffers */
  18027. + u32 size; /* size of buffers */
  18028. + u32 alignment; /* alignment of buffers */
  18029. +};
  18030. +
  18031. +struct vchiq_mmal_port;
  18032. +
  18033. +typedef void (*vchiq_mmal_buffer_cb)(
  18034. + struct vchiq_mmal_instance *instance,
  18035. + struct vchiq_mmal_port *port,
  18036. + int status, struct mmal_buffer *buffer,
  18037. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
  18038. +
  18039. +struct vchiq_mmal_port {
  18040. + bool enabled;
  18041. + u32 handle;
  18042. + u32 type; /* port type, cached to use on port info set */
  18043. + u32 index; /* port index, cached to use on port info set */
  18044. +
  18045. + /* component port belongs to, allows simple deref */
  18046. + struct vchiq_mmal_component *component;
  18047. +
  18048. + struct vchiq_mmal_port *connected; /* port conencted to */
  18049. +
  18050. + /* buffer info */
  18051. + struct vchiq_mmal_port_buffer minimum_buffer;
  18052. + struct vchiq_mmal_port_buffer recommended_buffer;
  18053. + struct vchiq_mmal_port_buffer current_buffer;
  18054. +
  18055. + /* stream format */
  18056. + struct mmal_es_format format;
  18057. + /* elementry stream format */
  18058. + union mmal_es_specific_format es;
  18059. +
  18060. + /* data buffers to fill */
  18061. + struct list_head buffers;
  18062. + /* lock to serialise adding and removing buffers from list */
  18063. + spinlock_t slock;
  18064. + /* count of how many buffer header refils have failed because
  18065. + * there was no buffer to satisfy them
  18066. + */
  18067. + int buffer_underflow;
  18068. + /* callback on buffer completion */
  18069. + vchiq_mmal_buffer_cb buffer_cb;
  18070. + /* callback context */
  18071. + void *cb_ctx;
  18072. +};
  18073. +
  18074. +struct vchiq_mmal_component {
  18075. + bool enabled;
  18076. + u32 handle; /* VideoCore handle for component */
  18077. + u32 inputs; /* Number of input ports */
  18078. + u32 outputs; /* Number of output ports */
  18079. + u32 clocks; /* Number of clock ports */
  18080. + struct vchiq_mmal_port control; /* control port */
  18081. + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
  18082. + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
  18083. + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
  18084. +};
  18085. +
  18086. +
  18087. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
  18088. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
  18089. +
  18090. +/* Initialise a mmal component and its ports
  18091. +*
  18092. +*/
  18093. +int vchiq_mmal_component_init(
  18094. + struct vchiq_mmal_instance *instance,
  18095. + const char *name,
  18096. + struct vchiq_mmal_component **component_out);
  18097. +
  18098. +int vchiq_mmal_component_finalise(
  18099. + struct vchiq_mmal_instance *instance,
  18100. + struct vchiq_mmal_component *component);
  18101. +
  18102. +int vchiq_mmal_component_enable(
  18103. + struct vchiq_mmal_instance *instance,
  18104. + struct vchiq_mmal_component *component);
  18105. +
  18106. +int vchiq_mmal_component_disable(
  18107. + struct vchiq_mmal_instance *instance,
  18108. + struct vchiq_mmal_component *component);
  18109. +
  18110. +
  18111. +
  18112. +/* enable a mmal port
  18113. + *
  18114. + * enables a port and if a buffer callback provided enque buffer
  18115. + * headers as apropriate for the port.
  18116. + */
  18117. +int vchiq_mmal_port_enable(
  18118. + struct vchiq_mmal_instance *instance,
  18119. + struct vchiq_mmal_port *port,
  18120. + vchiq_mmal_buffer_cb buffer_cb);
  18121. +
  18122. +/* disable a port
  18123. + *
  18124. + * disable a port will dequeue any pending buffers
  18125. + */
  18126. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  18127. + struct vchiq_mmal_port *port);
  18128. +
  18129. +
  18130. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  18131. + struct vchiq_mmal_port *port,
  18132. + u32 parameter,
  18133. + void *value,
  18134. + u32 value_size);
  18135. +
  18136. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  18137. + struct vchiq_mmal_port *port,
  18138. + u32 parameter,
  18139. + void *value,
  18140. + u32 *value_size);
  18141. +
  18142. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  18143. + struct vchiq_mmal_port *port);
  18144. +
  18145. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  18146. + struct vchiq_mmal_port *src,
  18147. + struct vchiq_mmal_port *dst);
  18148. +
  18149. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  18150. + u32 *major_out,
  18151. + u32 *minor_out);
  18152. +
  18153. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  18154. + struct vchiq_mmal_port *port,
  18155. + struct mmal_buffer *buf);
  18156. +
  18157. +#endif /* MMAL_VCHIQ_H */
  18158. diff -Nur linux-3.12.18/drivers/media/platform/Kconfig linux-rpi/drivers/media/platform/Kconfig
  18159. --- linux-3.12.18/drivers/media/platform/Kconfig 2014-04-18 11:14:28.000000000 +0200
  18160. +++ linux-rpi/drivers/media/platform/Kconfig 2014-04-24 16:04:36.447091651 +0200
  18161. @@ -124,6 +124,7 @@
  18162. source "drivers/media/platform/soc_camera/Kconfig"
  18163. source "drivers/media/platform/exynos4-is/Kconfig"
  18164. source "drivers/media/platform/s5p-tv/Kconfig"
  18165. +source "drivers/media/platform/bcm2835/Kconfig"
  18166. endif # V4L_PLATFORM_DRIVERS
  18167. diff -Nur linux-3.12.18/drivers/media/platform/Makefile linux-rpi/drivers/media/platform/Makefile
  18168. --- linux-3.12.18/drivers/media/platform/Makefile 2014-04-18 11:14:28.000000000 +0200
  18169. +++ linux-rpi/drivers/media/platform/Makefile 2014-04-24 16:04:36.447091651 +0200
  18170. @@ -52,4 +52,6 @@
  18171. obj-$(CONFIG_ARCH_OMAP) += omap/
  18172. +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
  18173. +
  18174. ccflags-y += -I$(srctree)/drivers/media/i2c
  18175. diff -Nur linux-3.12.18/drivers/media/usb/dvb-usb-v2/rtl28xxu.c linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
  18176. --- linux-3.12.18/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-04-18 11:14:28.000000000 +0200
  18177. +++ linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-04-24 16:04:36.559092734 +0200
  18178. @@ -1384,6 +1384,10 @@
  18179. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  18180. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  18181. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  18182. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xb803 /*USB_PID_AUGUST_DVBT205*/,
  18183. + &rtl2832u_props, "August DVB-T 205", NULL) },
  18184. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xa803 /*USB_PID_AUGUST_DVBT205*/,
  18185. + &rtl2832u_props, "August DVB-T 205", NULL) },
  18186. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
  18187. &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
  18188. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
  18189. diff -Nur linux-3.12.18/drivers/misc/Kconfig linux-rpi/drivers/misc/Kconfig
  18190. --- linux-3.12.18/drivers/misc/Kconfig 2014-04-18 11:14:28.000000000 +0200
  18191. +++ linux-rpi/drivers/misc/Kconfig 2014-04-24 16:04:36.711094204 +0200
  18192. @@ -537,4 +537,5 @@
  18193. source "drivers/misc/altera-stapl/Kconfig"
  18194. source "drivers/misc/mei/Kconfig"
  18195. source "drivers/misc/vmw_vmci/Kconfig"
  18196. +source "drivers/misc/vc04_services/Kconfig"
  18197. endmenu
  18198. diff -Nur linux-3.12.18/drivers/misc/Makefile linux-rpi/drivers/misc/Makefile
  18199. --- linux-3.12.18/drivers/misc/Makefile 2014-04-18 11:14:28.000000000 +0200
  18200. +++ linux-rpi/drivers/misc/Makefile 2014-04-24 15:35:02.873551293 +0200
  18201. @@ -53,3 +53,4 @@
  18202. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  18203. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  18204. obj-$(CONFIG_SRAM) += sram.o
  18205. +obj-$(CONFIG_BCM2708_VCHIQ) += vc04_services/
  18206. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchi/connections/connection.h linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h
  18207. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchi/connections/connection.h 1970-01-01 01:00:00.000000000 +0100
  18208. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h 2014-04-24 15:35:02.889551471 +0200
  18209. @@ -0,0 +1,328 @@
  18210. +/**
  18211. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18212. + *
  18213. + * Redistribution and use in source and binary forms, with or without
  18214. + * modification, are permitted provided that the following conditions
  18215. + * are met:
  18216. + * 1. Redistributions of source code must retain the above copyright
  18217. + * notice, this list of conditions, and the following disclaimer,
  18218. + * without modification.
  18219. + * 2. Redistributions in binary form must reproduce the above copyright
  18220. + * notice, this list of conditions and the following disclaimer in the
  18221. + * documentation and/or other materials provided with the distribution.
  18222. + * 3. The names of the above-listed copyright holders may not be used
  18223. + * to endorse or promote products derived from this software without
  18224. + * specific prior written permission.
  18225. + *
  18226. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18227. + * GNU General Public License ("GPL") version 2, as published by the Free
  18228. + * Software Foundation.
  18229. + *
  18230. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18231. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18232. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18233. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18234. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18235. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18236. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18237. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18238. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18239. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18240. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18241. + */
  18242. +
  18243. +#ifndef CONNECTION_H_
  18244. +#define CONNECTION_H_
  18245. +
  18246. +#include <linux/kernel.h>
  18247. +#include <linux/types.h>
  18248. +#include <linux/semaphore.h>
  18249. +
  18250. +#include "interface/vchi/vchi_cfg_internal.h"
  18251. +#include "interface/vchi/vchi_common.h"
  18252. +#include "interface/vchi/message_drivers/message.h"
  18253. +
  18254. +/******************************************************************************
  18255. + Global defs
  18256. + *****************************************************************************/
  18257. +
  18258. +// Opaque handle for a connection / service pair
  18259. +typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
  18260. +
  18261. +// opaque handle to the connection state information
  18262. +typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
  18263. +
  18264. +typedef struct vchi_connection_t VCHI_CONNECTION_T;
  18265. +
  18266. +
  18267. +/******************************************************************************
  18268. + API
  18269. + *****************************************************************************/
  18270. +
  18271. +// Routine to init a connection with a particular low level driver
  18272. +typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
  18273. + const VCHI_MESSAGE_DRIVER_T * driver );
  18274. +
  18275. +// Routine to control CRC enabling at a connection level
  18276. +typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
  18277. + VCHI_CRC_CONTROL_T control );
  18278. +
  18279. +// Routine to create a service
  18280. +typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
  18281. + int32_t service_id,
  18282. + uint32_t rx_fifo_size,
  18283. + uint32_t tx_fifo_size,
  18284. + int server,
  18285. + VCHI_CALLBACK_T callback,
  18286. + void *callback_param,
  18287. + int32_t want_crc,
  18288. + int32_t want_unaligned_bulk_rx,
  18289. + int32_t want_unaligned_bulk_tx,
  18290. + VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
  18291. +
  18292. +// Routine to close a service
  18293. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
  18294. +
  18295. +// Routine to queue a message
  18296. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18297. + const void *data,
  18298. + uint32_t data_size,
  18299. + VCHI_FLAGS_T flags,
  18300. + void *msg_handle );
  18301. +
  18302. +// scatter-gather (vector) message queueing
  18303. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18304. + VCHI_MSG_VECTOR_T *vector,
  18305. + uint32_t count,
  18306. + VCHI_FLAGS_T flags,
  18307. + void *msg_handle );
  18308. +
  18309. +// Routine to dequeue a message
  18310. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18311. + void *data,
  18312. + uint32_t max_data_size_to_read,
  18313. + uint32_t *actual_msg_size,
  18314. + VCHI_FLAGS_T flags );
  18315. +
  18316. +// Routine to peek at a message
  18317. +typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18318. + void **data,
  18319. + uint32_t *msg_size,
  18320. + VCHI_FLAGS_T flags );
  18321. +
  18322. +// Routine to hold a message
  18323. +typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18324. + void **data,
  18325. + uint32_t *msg_size,
  18326. + VCHI_FLAGS_T flags,
  18327. + void **message_handle );
  18328. +
  18329. +// Routine to initialise a received message iterator
  18330. +typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18331. + VCHI_MSG_ITER_T *iter,
  18332. + VCHI_FLAGS_T flags );
  18333. +
  18334. +// Routine to release a held message
  18335. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18336. + void *message_handle );
  18337. +
  18338. +// Routine to get info on a held message
  18339. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18340. + void *message_handle,
  18341. + void **data,
  18342. + int32_t *msg_size,
  18343. + uint32_t *tx_timestamp,
  18344. + uint32_t *rx_timestamp );
  18345. +
  18346. +// Routine to check whether the iterator has a next message
  18347. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18348. + const VCHI_MSG_ITER_T *iter );
  18349. +
  18350. +// Routine to advance the iterator
  18351. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18352. + VCHI_MSG_ITER_T *iter,
  18353. + void **data,
  18354. + uint32_t *msg_size );
  18355. +
  18356. +// Routine to remove the last message returned by the iterator
  18357. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18358. + VCHI_MSG_ITER_T *iter );
  18359. +
  18360. +// Routine to hold the last message returned by the iterator
  18361. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18362. + VCHI_MSG_ITER_T *iter,
  18363. + void **msg_handle );
  18364. +
  18365. +// Routine to transmit bulk data
  18366. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18367. + const void *data_src,
  18368. + uint32_t data_size,
  18369. + VCHI_FLAGS_T flags,
  18370. + void *bulk_handle );
  18371. +
  18372. +// Routine to receive data
  18373. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18374. + void *data_dst,
  18375. + uint32_t data_size,
  18376. + VCHI_FLAGS_T flags,
  18377. + void *bulk_handle );
  18378. +
  18379. +// Routine to report if a server is available
  18380. +typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
  18381. +
  18382. +// Routine to report the number of RX slots available
  18383. +typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
  18384. +
  18385. +// Routine to report the RX slot size
  18386. +typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
  18387. +
  18388. +// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  18389. +typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
  18390. + int32_t service,
  18391. + uint32_t length,
  18392. + MESSAGE_TX_CHANNEL_T channel,
  18393. + uint32_t channel_params,
  18394. + uint32_t data_length,
  18395. + uint32_t data_offset);
  18396. +
  18397. +// Callback to inform a service that a Xon or Xoff message has been received
  18398. +typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
  18399. +
  18400. +// Callback to inform a service that a server available reply message has been received
  18401. +typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
  18402. +
  18403. +// Callback to indicate that bulk auxiliary messages have arrived
  18404. +typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
  18405. +
  18406. +// Callback to indicate that bulk auxiliary messages have arrived
  18407. +typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
  18408. +
  18409. +// Callback with all the connection info you require
  18410. +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);
  18411. +
  18412. +// Callback to inform of a disconnect
  18413. +typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
  18414. +
  18415. +// Callback to inform of a power control request
  18416. +typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
  18417. +
  18418. +// allocate memory suitably aligned for this connection
  18419. +typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
  18420. +
  18421. +// free memory allocated by buffer_allocate
  18422. +typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
  18423. +
  18424. +
  18425. +/******************************************************************************
  18426. + System driver struct
  18427. + *****************************************************************************/
  18428. +
  18429. +struct opaque_vchi_connection_api_t
  18430. +{
  18431. + // Routine to init the connection
  18432. + VCHI_CONNECTION_INIT_T init;
  18433. +
  18434. + // Connection-level CRC control
  18435. + VCHI_CONNECTION_CRC_CONTROL_T crc_control;
  18436. +
  18437. + // Routine to connect to or create service
  18438. + VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
  18439. +
  18440. + // Routine to disconnect from a service
  18441. + VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
  18442. +
  18443. + // Routine to queue a message
  18444. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
  18445. +
  18446. + // scatter-gather (vector) message queue
  18447. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
  18448. +
  18449. + // Routine to dequeue a message
  18450. + VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
  18451. +
  18452. + // Routine to peek at a message
  18453. + VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
  18454. +
  18455. + // Routine to hold a message
  18456. + VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
  18457. +
  18458. + // Routine to initialise a received message iterator
  18459. + VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
  18460. +
  18461. + // Routine to release a message
  18462. + VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
  18463. +
  18464. + // Routine to get information on a held message
  18465. + VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
  18466. +
  18467. + // Routine to check for next message on iterator
  18468. + VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
  18469. +
  18470. + // Routine to get next message on iterator
  18471. + VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
  18472. +
  18473. + // Routine to remove the last message returned by iterator
  18474. + VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
  18475. +
  18476. + // Routine to hold the last message returned by iterator
  18477. + VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
  18478. +
  18479. + // Routine to transmit bulk data
  18480. + VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
  18481. +
  18482. + // Routine to receive data
  18483. + VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
  18484. +
  18485. + // Routine to report the available servers
  18486. + VCHI_CONNECTION_SERVER_PRESENT server_present;
  18487. +
  18488. + // Routine to report the number of RX slots available
  18489. + VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
  18490. +
  18491. + // Routine to report the RX slot size
  18492. + VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
  18493. +
  18494. + // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  18495. + VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
  18496. +
  18497. + // Callback to inform a service that a Xon or Xoff message has been received
  18498. + VCHI_CONNECTION_FLOW_CONTROL flow_control;
  18499. +
  18500. + // Callback to inform a service that a server available reply message has been received
  18501. + VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
  18502. +
  18503. + // Callback to indicate that bulk auxiliary messages have arrived
  18504. + VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
  18505. +
  18506. + // Callback to indicate that a bulk auxiliary message has been transmitted
  18507. + VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
  18508. +
  18509. + // Callback to provide information about the connection
  18510. + VCHI_CONNECTION_INFO connection_info;
  18511. +
  18512. + // Callback to notify that peer has requested disconnect
  18513. + VCHI_CONNECTION_DISCONNECT disconnect;
  18514. +
  18515. + // Callback to notify that peer has requested power change
  18516. + VCHI_CONNECTION_POWER_CONTROL power_control;
  18517. +
  18518. + // allocate memory suitably aligned for this connection
  18519. + VCHI_BUFFER_ALLOCATE buffer_allocate;
  18520. +
  18521. + // free memory allocated by buffer_allocate
  18522. + VCHI_BUFFER_FREE buffer_free;
  18523. +
  18524. +};
  18525. +
  18526. +struct vchi_connection_t {
  18527. + const VCHI_CONNECTION_API_T *api;
  18528. + VCHI_CONNECTION_STATE_T *state;
  18529. +#ifdef VCHI_COARSE_LOCKING
  18530. + struct semaphore sem;
  18531. +#endif
  18532. +};
  18533. +
  18534. +
  18535. +#endif /* CONNECTION_H_ */
  18536. +
  18537. +/****************************** End of file **********************************/
  18538. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h
  18539. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 1970-01-01 01:00:00.000000000 +0100
  18540. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 2014-04-24 15:35:02.889551471 +0200
  18541. @@ -0,0 +1,204 @@
  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_MESSAGE_H_
  18576. +#define _VCHI_MESSAGE_H_
  18577. +
  18578. +#include <linux/kernel.h>
  18579. +#include <linux/types.h>
  18580. +#include <linux/semaphore.h>
  18581. +
  18582. +#include "interface/vchi/vchi_cfg_internal.h"
  18583. +#include "interface/vchi/vchi_common.h"
  18584. +
  18585. +
  18586. +typedef enum message_event_type {
  18587. + MESSAGE_EVENT_NONE,
  18588. + MESSAGE_EVENT_NOP,
  18589. + MESSAGE_EVENT_MESSAGE,
  18590. + MESSAGE_EVENT_SLOT_COMPLETE,
  18591. + MESSAGE_EVENT_RX_BULK_PAUSED,
  18592. + MESSAGE_EVENT_RX_BULK_COMPLETE,
  18593. + MESSAGE_EVENT_TX_COMPLETE,
  18594. + MESSAGE_EVENT_MSG_DISCARDED
  18595. +} MESSAGE_EVENT_TYPE_T;
  18596. +
  18597. +typedef enum vchi_msg_flags
  18598. +{
  18599. + VCHI_MSG_FLAGS_NONE = 0x0,
  18600. + VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
  18601. +} VCHI_MSG_FLAGS_T;
  18602. +
  18603. +typedef enum message_tx_channel
  18604. +{
  18605. + MESSAGE_TX_CHANNEL_MESSAGE = 0,
  18606. + MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  18607. +} MESSAGE_TX_CHANNEL_T;
  18608. +
  18609. +// Macros used for cycling through bulk channels
  18610. +#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)
  18611. +#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  18612. +
  18613. +typedef enum message_rx_channel
  18614. +{
  18615. + MESSAGE_RX_CHANNEL_MESSAGE = 0,
  18616. + MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  18617. +} MESSAGE_RX_CHANNEL_T;
  18618. +
  18619. +// Message receive slot information
  18620. +typedef struct rx_msg_slot_info {
  18621. +
  18622. + struct rx_msg_slot_info *next;
  18623. + //struct slot_info *prev;
  18624. +#if !defined VCHI_COARSE_LOCKING
  18625. + struct semaphore sem;
  18626. +#endif
  18627. +
  18628. + uint8_t *addr; // base address of slot
  18629. + uint32_t len; // length of slot in bytes
  18630. +
  18631. + uint32_t write_ptr; // hardware causes this to advance
  18632. + uint32_t read_ptr; // this module does the reading
  18633. + int active; // is this slot in the hardware dma fifo?
  18634. + uint32_t msgs_parsed; // count how many messages are in this slot
  18635. + uint32_t msgs_released; // how many messages have been released
  18636. + void *state; // connection state information
  18637. + uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
  18638. +} RX_MSG_SLOTINFO_T;
  18639. +
  18640. +// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
  18641. +// In particular, it mustn't use addr and len - they're the client buffer, but the message
  18642. +// driver will be tasked with sending the aligned core section.
  18643. +typedef struct rx_bulk_slotinfo_t {
  18644. + struct rx_bulk_slotinfo_t *next;
  18645. +
  18646. + struct semaphore *blocking;
  18647. +
  18648. + // needed by DMA
  18649. + void *addr;
  18650. + uint32_t len;
  18651. +
  18652. + // needed for the callback
  18653. + void *service;
  18654. + void *handle;
  18655. + VCHI_FLAGS_T flags;
  18656. +} RX_BULK_SLOTINFO_T;
  18657. +
  18658. +
  18659. +/* ----------------------------------------------------------------------
  18660. + * each connection driver will have a pool of the following struct.
  18661. + *
  18662. + * the pool will be managed by vchi_qman_*
  18663. + * this means there will be multiple queues (single linked lists)
  18664. + * a given struct message_info will be on exactly one of these queues
  18665. + * at any one time
  18666. + * -------------------------------------------------------------------- */
  18667. +typedef struct rx_message_info {
  18668. +
  18669. + struct message_info *next;
  18670. + //struct message_info *prev;
  18671. +
  18672. + uint8_t *addr;
  18673. + uint32_t len;
  18674. + RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
  18675. + uint32_t tx_timestamp;
  18676. + uint32_t rx_timestamp;
  18677. +
  18678. +} RX_MESSAGE_INFO_T;
  18679. +
  18680. +typedef struct {
  18681. + MESSAGE_EVENT_TYPE_T type;
  18682. +
  18683. + struct {
  18684. + // for messages
  18685. + void *addr; // address of message
  18686. + uint16_t slot_delta; // whether this message indicated slot delta
  18687. + uint32_t len; // length of message
  18688. + RX_MSG_SLOTINFO_T *slot; // slot this message is in
  18689. + int32_t service; // service id this message is destined for
  18690. + uint32_t tx_timestamp; // timestamp from the header
  18691. + uint32_t rx_timestamp; // timestamp when we parsed it
  18692. + } message;
  18693. +
  18694. + // FIXME: cleanup slot reporting...
  18695. + RX_MSG_SLOTINFO_T *rx_msg;
  18696. + RX_BULK_SLOTINFO_T *rx_bulk;
  18697. + void *tx_handle;
  18698. + MESSAGE_TX_CHANNEL_T tx_channel;
  18699. +
  18700. +} MESSAGE_EVENT_T;
  18701. +
  18702. +
  18703. +// callbacks
  18704. +typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
  18705. +
  18706. +typedef struct {
  18707. + VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
  18708. +} VCHI_MESSAGE_DRIVER_OPEN_T;
  18709. +
  18710. +
  18711. +// handle to this instance of message driver (as returned by ->open)
  18712. +typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
  18713. +
  18714. +struct opaque_vchi_message_driver_t {
  18715. + VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
  18716. + int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
  18717. + int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
  18718. + int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
  18719. + int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
  18720. + int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
  18721. + 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)
  18722. + void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
  18723. + int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
  18724. + int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
  18725. + *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
  18726. +
  18727. + int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
  18728. + int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
  18729. + void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
  18730. + void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
  18731. + int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  18732. + int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  18733. +
  18734. + int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18735. + uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18736. + int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18737. + int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
  18738. + 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 );
  18739. + void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
  18740. +};
  18741. +
  18742. +
  18743. +#endif // _VCHI_MESSAGE_H_
  18744. +
  18745. +/****************************** End of file ***********************************/
  18746. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h
  18747. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 1970-01-01 01:00:00.000000000 +0100
  18748. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 2014-04-24 15:35:02.889551471 +0200
  18749. @@ -0,0 +1,224 @@
  18750. +/**
  18751. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18752. + *
  18753. + * Redistribution and use in source and binary forms, with or without
  18754. + * modification, are permitted provided that the following conditions
  18755. + * are met:
  18756. + * 1. Redistributions of source code must retain the above copyright
  18757. + * notice, this list of conditions, and the following disclaimer,
  18758. + * without modification.
  18759. + * 2. Redistributions in binary form must reproduce the above copyright
  18760. + * notice, this list of conditions and the following disclaimer in the
  18761. + * documentation and/or other materials provided with the distribution.
  18762. + * 3. The names of the above-listed copyright holders may not be used
  18763. + * to endorse or promote products derived from this software without
  18764. + * specific prior written permission.
  18765. + *
  18766. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18767. + * GNU General Public License ("GPL") version 2, as published by the Free
  18768. + * Software Foundation.
  18769. + *
  18770. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18771. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18772. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18773. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18774. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18775. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18776. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18777. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18778. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18779. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18780. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18781. + */
  18782. +
  18783. +#ifndef VCHI_CFG_H_
  18784. +#define VCHI_CFG_H_
  18785. +
  18786. +/****************************************************************************************
  18787. + * Defines in this first section are part of the VCHI API and may be examined by VCHI
  18788. + * services.
  18789. + ***************************************************************************************/
  18790. +
  18791. +/* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
  18792. +/* Really determined by the message driver, and should be available from a run-time call. */
  18793. +#ifndef VCHI_BULK_ALIGN
  18794. +# if __VCCOREVER__ >= 0x04000000
  18795. +# define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
  18796. +# else
  18797. +# define VCHI_BULK_ALIGN 16
  18798. +# endif
  18799. +#endif
  18800. +
  18801. +/* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
  18802. +/* May be less than or greater than VCHI_BULK_ALIGN */
  18803. +/* Really determined by the message driver, and should be available from a run-time call. */
  18804. +#ifndef VCHI_BULK_GRANULARITY
  18805. +# if __VCCOREVER__ >= 0x04000000
  18806. +# define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
  18807. +# else
  18808. +# define VCHI_BULK_GRANULARITY 16
  18809. +# endif
  18810. +#endif
  18811. +
  18812. +/* The largest possible message to be queued with vchi_msg_queue. */
  18813. +#ifndef VCHI_MAX_MSG_SIZE
  18814. +# if defined VCHI_LOCAL_HOST_PORT
  18815. +# define VCHI_MAX_MSG_SIZE 16384 // makes file transfers fast, but should they be using bulk?
  18816. +# else
  18817. +# define VCHI_MAX_MSG_SIZE 4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
  18818. +# endif
  18819. +#endif
  18820. +
  18821. +/******************************************************************************************
  18822. + * Defines below are system configuration options, and should not be used by VCHI services.
  18823. + *****************************************************************************************/
  18824. +
  18825. +/* How many connections can we support? A localhost implementation uses 2 connections,
  18826. + * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
  18827. + * driver. */
  18828. +#ifndef VCHI_MAX_NUM_CONNECTIONS
  18829. +# define VCHI_MAX_NUM_CONNECTIONS 3
  18830. +#endif
  18831. +
  18832. +/* How many services can we open per connection? Extending this doesn't cost processing time, just a small
  18833. + * amount of static memory. */
  18834. +#ifndef VCHI_MAX_SERVICES_PER_CONNECTION
  18835. +# define VCHI_MAX_SERVICES_PER_CONNECTION 36
  18836. +#endif
  18837. +
  18838. +/* Adjust if using a message driver that supports more logical TX channels */
  18839. +#ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
  18840. +# define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
  18841. +#endif
  18842. +
  18843. +/* Adjust if using a message driver that supports more logical RX channels */
  18844. +#ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
  18845. +# define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
  18846. +#endif
  18847. +
  18848. +/* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
  18849. + * receive queue space, less message headers. */
  18850. +#ifndef VCHI_NUM_READ_SLOTS
  18851. +# if defined(VCHI_LOCAL_HOST_PORT)
  18852. +# define VCHI_NUM_READ_SLOTS 4
  18853. +# else
  18854. +# define VCHI_NUM_READ_SLOTS 48
  18855. +# endif
  18856. +#endif
  18857. +
  18858. +/* Do we utilise overrun facility for receive message slots? Can aid peer transmit
  18859. + * performance. Only define on VideoCore end, talking to host.
  18860. + */
  18861. +//#define VCHI_MSG_RX_OVERRUN
  18862. +
  18863. +/* How many transmit slots do we use. Generally don't need many, as the hardware driver
  18864. + * underneath VCHI will usually have its own buffering. */
  18865. +#ifndef VCHI_NUM_WRITE_SLOTS
  18866. +# define VCHI_NUM_WRITE_SLOTS 4
  18867. +#endif
  18868. +
  18869. +/* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
  18870. + * then it's taking up too much buffer space, and the peer service will be told to stop
  18871. + * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
  18872. + * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
  18873. + * is too high. */
  18874. +#ifndef VCHI_XOFF_THRESHOLD
  18875. +# define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
  18876. +#endif
  18877. +
  18878. +/* After we've sent an XOFF, the peer will be told to resume transmission once the local
  18879. + * service has dequeued/released enough messages that it's now occupying
  18880. + * VCHI_XON_THRESHOLD slots or fewer. */
  18881. +#ifndef VCHI_XON_THRESHOLD
  18882. +# define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
  18883. +#endif
  18884. +
  18885. +/* A size below which a bulk transfer omits the handshake completely and always goes
  18886. + * via the message channel, if bulk auxiliary is being sent on that service. (The user
  18887. + * can guarantee this by enabling unaligned transmits).
  18888. + * Not API. */
  18889. +#ifndef VCHI_MIN_BULK_SIZE
  18890. +# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
  18891. +#endif
  18892. +
  18893. +/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
  18894. + * speed and latency; the smaller the chunk size the better change of messages and other
  18895. + * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
  18896. + * break transmissions into chunks.
  18897. + */
  18898. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
  18899. +# define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
  18900. +#endif
  18901. +
  18902. +/* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
  18903. + * with multiple-line frames. Only use if the receiver can cope. */
  18904. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
  18905. +# define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
  18906. +#endif
  18907. +
  18908. +/* How many TX messages can we have pending in our transmit slots. Once exhausted,
  18909. + * vchi_msg_queue will be blocked. */
  18910. +#ifndef VCHI_TX_MSG_QUEUE_SIZE
  18911. +# define VCHI_TX_MSG_QUEUE_SIZE 256
  18912. +#endif
  18913. +
  18914. +/* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
  18915. + * will be suspended until older messages are dequeued/released. */
  18916. +#ifndef VCHI_RX_MSG_QUEUE_SIZE
  18917. +# define VCHI_RX_MSG_QUEUE_SIZE 256
  18918. +#endif
  18919. +
  18920. +/* Really should be able to cope if we run out of received message descriptors, by
  18921. + * suspending parsing as the comment above says, but we don't. This sweeps the issue
  18922. + * under the carpet. */
  18923. +#if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  18924. +# undef VCHI_RX_MSG_QUEUE_SIZE
  18925. +# define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  18926. +#endif
  18927. +
  18928. +/* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
  18929. + * will be blocked. */
  18930. +#ifndef VCHI_TX_BULK_QUEUE_SIZE
  18931. +# define VCHI_TX_BULK_QUEUE_SIZE 64
  18932. +#endif
  18933. +
  18934. +/* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
  18935. + * will be blocked. */
  18936. +#ifndef VCHI_RX_BULK_QUEUE_SIZE
  18937. +# define VCHI_RX_BULK_QUEUE_SIZE 64
  18938. +#endif
  18939. +
  18940. +/* A limit on how many outstanding bulk requests we expect the peer to give us. If
  18941. + * the peer asks for more than this, VCHI will fail and assert. The number is determined
  18942. + * by the peer's hardware - it's the number of outstanding requests that can be queued
  18943. + * on all bulk channels. VC3's MPHI peripheral allows 16. */
  18944. +#ifndef VCHI_MAX_PEER_BULK_REQUESTS
  18945. +# define VCHI_MAX_PEER_BULK_REQUESTS 32
  18946. +#endif
  18947. +
  18948. +/* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
  18949. + * transmitter on and off.
  18950. + */
  18951. +/*#define VCHI_CCP2TX_MANUAL_POWER*/
  18952. +
  18953. +#ifndef VCHI_CCP2TX_MANUAL_POWER
  18954. +
  18955. +/* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
  18956. + * negative for no IDLE.
  18957. + */
  18958. +# ifndef VCHI_CCP2TX_IDLE_TIMEOUT
  18959. +# define VCHI_CCP2TX_IDLE_TIMEOUT 5
  18960. +# endif
  18961. +
  18962. +/* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
  18963. + * negative for no OFF.
  18964. + */
  18965. +# ifndef VCHI_CCP2TX_OFF_TIMEOUT
  18966. +# define VCHI_CCP2TX_OFF_TIMEOUT 1000
  18967. +# endif
  18968. +
  18969. +#endif /* VCHI_CCP2TX_MANUAL_POWER */
  18970. +
  18971. +#endif /* VCHI_CFG_H_ */
  18972. +
  18973. +/****************************** End of file **********************************/
  18974. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h
  18975. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 1970-01-01 01:00:00.000000000 +0100
  18976. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 2014-04-24 15:35:02.889551471 +0200
  18977. @@ -0,0 +1,71 @@
  18978. +/**
  18979. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18980. + *
  18981. + * Redistribution and use in source and binary forms, with or without
  18982. + * modification, are permitted provided that the following conditions
  18983. + * are met:
  18984. + * 1. Redistributions of source code must retain the above copyright
  18985. + * notice, this list of conditions, and the following disclaimer,
  18986. + * without modification.
  18987. + * 2. Redistributions in binary form must reproduce the above copyright
  18988. + * notice, this list of conditions and the following disclaimer in the
  18989. + * documentation and/or other materials provided with the distribution.
  18990. + * 3. The names of the above-listed copyright holders may not be used
  18991. + * to endorse or promote products derived from this software without
  18992. + * specific prior written permission.
  18993. + *
  18994. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18995. + * GNU General Public License ("GPL") version 2, as published by the Free
  18996. + * Software Foundation.
  18997. + *
  18998. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18999. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19000. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19001. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19002. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19003. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19004. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19005. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19006. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19007. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19008. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19009. + */
  19010. +
  19011. +#ifndef VCHI_CFG_INTERNAL_H_
  19012. +#define VCHI_CFG_INTERNAL_H_
  19013. +
  19014. +/****************************************************************************************
  19015. + * Control optimisation attempts.
  19016. + ***************************************************************************************/
  19017. +
  19018. +// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
  19019. +#define VCHI_COARSE_LOCKING
  19020. +
  19021. +// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
  19022. +// (only relevant if VCHI_COARSE_LOCKING)
  19023. +#define VCHI_ELIDE_BLOCK_EXIT_LOCK
  19024. +
  19025. +// Avoid lock on non-blocking peek
  19026. +// (only relevant if VCHI_COARSE_LOCKING)
  19027. +#define VCHI_AVOID_PEEK_LOCK
  19028. +
  19029. +// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
  19030. +#define VCHI_MULTIPLE_HANDLER_THREADS
  19031. +
  19032. +// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
  19033. +// our way through the pool of descriptors.
  19034. +#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
  19035. +
  19036. +// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
  19037. +#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
  19038. +
  19039. +// Don't use message descriptors for TX messages that don't need them
  19040. +#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
  19041. +
  19042. +// Nano-locks for multiqueue
  19043. +//#define VCHI_MQUEUE_NANOLOCKS
  19044. +
  19045. +// Lock-free(er) dequeuing
  19046. +//#define VCHI_RX_NANOLOCKS
  19047. +
  19048. +#endif /*VCHI_CFG_INTERNAL_H_*/
  19049. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchi/vchi_common.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h
  19050. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchi/vchi_common.h 1970-01-01 01:00:00.000000000 +0100
  19051. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h 2014-04-24 15:35:02.889551471 +0200
  19052. @@ -0,0 +1,163 @@
  19053. +/**
  19054. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19055. + *
  19056. + * Redistribution and use in source and binary forms, with or without
  19057. + * modification, are permitted provided that the following conditions
  19058. + * are met:
  19059. + * 1. Redistributions of source code must retain the above copyright
  19060. + * notice, this list of conditions, and the following disclaimer,
  19061. + * without modification.
  19062. + * 2. Redistributions in binary form must reproduce the above copyright
  19063. + * notice, this list of conditions and the following disclaimer in the
  19064. + * documentation and/or other materials provided with the distribution.
  19065. + * 3. The names of the above-listed copyright holders may not be used
  19066. + * to endorse or promote products derived from this software without
  19067. + * specific prior written permission.
  19068. + *
  19069. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19070. + * GNU General Public License ("GPL") version 2, as published by the Free
  19071. + * Software Foundation.
  19072. + *
  19073. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19074. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19075. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19076. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19077. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19078. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19079. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19080. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19081. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19082. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19083. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19084. + */
  19085. +
  19086. +#ifndef VCHI_COMMON_H_
  19087. +#define VCHI_COMMON_H_
  19088. +
  19089. +
  19090. +//flags used when sending messages (must be bitmapped)
  19091. +typedef enum
  19092. +{
  19093. + VCHI_FLAGS_NONE = 0x0,
  19094. + 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)
  19095. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
  19096. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go
  19097. + VCHI_FLAGS_ALLOW_PARTIAL = 0x8,
  19098. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10,
  19099. + VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20,
  19100. +
  19101. + VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only
  19102. + VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only
  19103. + VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only
  19104. + VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only
  19105. + VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only
  19106. + VCHI_FLAGS_INTERNAL = 0xFF0000
  19107. +} VCHI_FLAGS_T;
  19108. +
  19109. +// constants for vchi_crc_control()
  19110. +typedef enum {
  19111. + VCHI_CRC_NOTHING = -1,
  19112. + VCHI_CRC_PER_SERVICE = 0,
  19113. + VCHI_CRC_EVERYTHING = 1,
  19114. +} VCHI_CRC_CONTROL_T;
  19115. +
  19116. +//callback reasons when an event occurs on a service
  19117. +typedef enum
  19118. +{
  19119. + VCHI_CALLBACK_REASON_MIN,
  19120. +
  19121. + //This indicates that there is data available
  19122. + //handle is the msg id that was transmitted with the data
  19123. + // When a message is received and there was no FULL message available previously, send callback
  19124. + // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
  19125. + VCHI_CALLBACK_MSG_AVAILABLE,
  19126. + VCHI_CALLBACK_MSG_SENT,
  19127. + VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
  19128. +
  19129. + // This indicates that a transfer from the other side has completed
  19130. + VCHI_CALLBACK_BULK_RECEIVED,
  19131. + //This indicates that data queued up to be sent has now gone
  19132. + //handle is the msg id that was used when sending the data
  19133. + VCHI_CALLBACK_BULK_SENT,
  19134. + VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
  19135. + VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
  19136. +
  19137. + VCHI_CALLBACK_SERVICE_CLOSED,
  19138. +
  19139. + // this side has sent XOFF to peer due to lack of data consumption by service
  19140. + // (suggests the service may need to take some recovery action if it has
  19141. + // been deliberately holding off consuming data)
  19142. + VCHI_CALLBACK_SENT_XOFF,
  19143. + VCHI_CALLBACK_SENT_XON,
  19144. +
  19145. + // indicates that a bulk transfer has finished reading the source buffer
  19146. + VCHI_CALLBACK_BULK_DATA_READ,
  19147. +
  19148. + // power notification events (currently host side only)
  19149. + VCHI_CALLBACK_PEER_OFF,
  19150. + VCHI_CALLBACK_PEER_SUSPENDED,
  19151. + VCHI_CALLBACK_PEER_ON,
  19152. + VCHI_CALLBACK_PEER_RESUMED,
  19153. + VCHI_CALLBACK_FORCED_POWER_OFF,
  19154. +
  19155. +#ifdef USE_VCHIQ_ARM
  19156. + // some extra notifications provided by vchiq_arm
  19157. + VCHI_CALLBACK_SERVICE_OPENED,
  19158. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  19159. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  19160. +#endif
  19161. +
  19162. + VCHI_CALLBACK_REASON_MAX
  19163. +} VCHI_CALLBACK_REASON_T;
  19164. +
  19165. +//Calback used by all services / bulk transfers
  19166. +typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param
  19167. + VCHI_CALLBACK_REASON_T reason,
  19168. + void *handle ); //for transmitting msg's only
  19169. +
  19170. +
  19171. +
  19172. +/*
  19173. + * Define vector struct for scatter-gather (vector) operations
  19174. + * Vectors can be nested - if a vector element has negative length, then
  19175. + * the data pointer is treated as pointing to another vector array, with
  19176. + * '-vec_len' elements. Thus to append a header onto an existing vector,
  19177. + * you can do this:
  19178. + *
  19179. + * void foo(const VCHI_MSG_VECTOR_T *v, int n)
  19180. + * {
  19181. + * VCHI_MSG_VECTOR_T nv[2];
  19182. + * nv[0].vec_base = my_header;
  19183. + * nv[0].vec_len = sizeof my_header;
  19184. + * nv[1].vec_base = v;
  19185. + * nv[1].vec_len = -n;
  19186. + * ...
  19187. + *
  19188. + */
  19189. +typedef struct vchi_msg_vector {
  19190. + const void *vec_base;
  19191. + int32_t vec_len;
  19192. +} VCHI_MSG_VECTOR_T;
  19193. +
  19194. +// Opaque type for a connection API
  19195. +typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
  19196. +
  19197. +// Opaque type for a message driver
  19198. +typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
  19199. +
  19200. +
  19201. +// Iterator structure for reading ahead through received message queue. Allocated by client,
  19202. +// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
  19203. +// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
  19204. +// will not proceed to messages received since. Behaviour is undefined if an iterator
  19205. +// is used again after messages for that service are removed/dequeued by any
  19206. +// means other than vchi_msg_iter_... calls on the iterator itself.
  19207. +typedef struct {
  19208. + struct opaque_vchi_service_t *service;
  19209. + void *last;
  19210. + void *next;
  19211. + void *remove;
  19212. +} VCHI_MSG_ITER_T;
  19213. +
  19214. +
  19215. +#endif // VCHI_COMMON_H_
  19216. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchi/vchi.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h
  19217. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchi/vchi.h 1970-01-01 01:00:00.000000000 +0100
  19218. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h 2014-04-24 15:35:02.889551471 +0200
  19219. @@ -0,0 +1,373 @@
  19220. +/**
  19221. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19222. + *
  19223. + * Redistribution and use in source and binary forms, with or without
  19224. + * modification, are permitted provided that the following conditions
  19225. + * are met:
  19226. + * 1. Redistributions of source code must retain the above copyright
  19227. + * notice, this list of conditions, and the following disclaimer,
  19228. + * without modification.
  19229. + * 2. Redistributions in binary form must reproduce the above copyright
  19230. + * notice, this list of conditions and the following disclaimer in the
  19231. + * documentation and/or other materials provided with the distribution.
  19232. + * 3. The names of the above-listed copyright holders may not be used
  19233. + * to endorse or promote products derived from this software without
  19234. + * specific prior written permission.
  19235. + *
  19236. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19237. + * GNU General Public License ("GPL") version 2, as published by the Free
  19238. + * Software Foundation.
  19239. + *
  19240. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19241. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19242. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19243. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19244. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19245. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19246. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19247. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19248. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19249. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19250. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19251. + */
  19252. +
  19253. +#ifndef VCHI_H_
  19254. +#define VCHI_H_
  19255. +
  19256. +#include "interface/vchi/vchi_cfg.h"
  19257. +#include "interface/vchi/vchi_common.h"
  19258. +#include "interface/vchi/connections/connection.h"
  19259. +#include "vchi_mh.h"
  19260. +
  19261. +
  19262. +/******************************************************************************
  19263. + Global defs
  19264. + *****************************************************************************/
  19265. +
  19266. +#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  19267. +#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  19268. +#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  19269. +
  19270. +#ifdef USE_VCHIQ_ARM
  19271. +#define VCHI_BULK_ALIGNED(x) 1
  19272. +#else
  19273. +#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  19274. +#endif
  19275. +
  19276. +struct vchi_version {
  19277. + uint32_t version;
  19278. + uint32_t version_min;
  19279. +};
  19280. +#define VCHI_VERSION(v_) { v_, v_ }
  19281. +#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  19282. +
  19283. +typedef enum
  19284. +{
  19285. + VCHI_VEC_POINTER,
  19286. + VCHI_VEC_HANDLE,
  19287. + VCHI_VEC_LIST
  19288. +} VCHI_MSG_VECTOR_TYPE_T;
  19289. +
  19290. +typedef struct vchi_msg_vector_ex {
  19291. +
  19292. + VCHI_MSG_VECTOR_TYPE_T type;
  19293. + union
  19294. + {
  19295. + // a memory handle
  19296. + struct
  19297. + {
  19298. + VCHI_MEM_HANDLE_T handle;
  19299. + uint32_t offset;
  19300. + int32_t vec_len;
  19301. + } handle;
  19302. +
  19303. + // an ordinary data pointer
  19304. + struct
  19305. + {
  19306. + const void *vec_base;
  19307. + int32_t vec_len;
  19308. + } ptr;
  19309. +
  19310. + // a nested vector list
  19311. + struct
  19312. + {
  19313. + struct vchi_msg_vector_ex *vec;
  19314. + uint32_t vec_len;
  19315. + } list;
  19316. + } u;
  19317. +} VCHI_MSG_VECTOR_EX_T;
  19318. +
  19319. +
  19320. +// Construct an entry in a msg vector for a pointer (p) of length (l)
  19321. +#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
  19322. +
  19323. +// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
  19324. +#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
  19325. +
  19326. +// Macros to manipulate 'FOURCC' values
  19327. +#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))
  19328. +#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
  19329. +
  19330. +
  19331. +// Opaque service information
  19332. +struct opaque_vchi_service_t;
  19333. +
  19334. +// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  19335. +// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  19336. +typedef struct
  19337. +{
  19338. + struct opaque_vchi_service_t *service;
  19339. + void *message;
  19340. +} VCHI_HELD_MSG_T;
  19341. +
  19342. +
  19343. +
  19344. +// structure used to provide the information needed to open a server or a client
  19345. +typedef struct {
  19346. + struct vchi_version version;
  19347. + int32_t service_id;
  19348. + VCHI_CONNECTION_T *connection;
  19349. + uint32_t rx_fifo_size;
  19350. + uint32_t tx_fifo_size;
  19351. + VCHI_CALLBACK_T callback;
  19352. + void *callback_param;
  19353. + /* client intends to receive bulk transfers of
  19354. + odd lengths or into unaligned buffers */
  19355. + int32_t want_unaligned_bulk_rx;
  19356. + /* client intends to transmit bulk transfers of
  19357. + odd lengths or out of unaligned buffers */
  19358. + int32_t want_unaligned_bulk_tx;
  19359. + /* client wants to check CRCs on (bulk) xfers.
  19360. + Only needs to be set at 1 end - will do both directions. */
  19361. + int32_t want_crc;
  19362. +} SERVICE_CREATION_T;
  19363. +
  19364. +// Opaque handle for a VCHI instance
  19365. +typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  19366. +
  19367. +// Opaque handle for a server or client
  19368. +typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  19369. +
  19370. +// Service registration & startup
  19371. +typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
  19372. +
  19373. +typedef struct service_info_tag {
  19374. + const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
  19375. + VCHI_SERVICE_INIT init; /* Service initialisation function */
  19376. + void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
  19377. +} SERVICE_INFO_T;
  19378. +
  19379. +/******************************************************************************
  19380. + Global funcs - implementation is specific to which side you are on (local / remote)
  19381. + *****************************************************************************/
  19382. +
  19383. +#ifdef __cplusplus
  19384. +extern "C" {
  19385. +#endif
  19386. +
  19387. +extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
  19388. + const VCHI_MESSAGE_DRIVER_T * low_level);
  19389. +
  19390. +
  19391. +// Routine used to initialise the vchi on both local + remote connections
  19392. +extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );
  19393. +
  19394. +extern int32_t vchi_exit( void );
  19395. +
  19396. +extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,
  19397. + const uint32_t num_connections,
  19398. + VCHI_INSTANCE_T instance_handle );
  19399. +
  19400. +//When this is called, ensure that all services have no data pending.
  19401. +//Bulk transfers can remain 'queued'
  19402. +extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );
  19403. +
  19404. +// Global control over bulk CRC checking
  19405. +extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
  19406. + VCHI_CRC_CONTROL_T control );
  19407. +
  19408. +// helper functions
  19409. +extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  19410. +extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  19411. +extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  19412. +
  19413. +
  19414. +/******************************************************************************
  19415. + Global service API
  19416. + *****************************************************************************/
  19417. +// Routine to create a named service
  19418. +extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,
  19419. + SERVICE_CREATION_T *setup,
  19420. + VCHI_SERVICE_HANDLE_T *handle );
  19421. +
  19422. +// Routine to destory a service
  19423. +extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );
  19424. +
  19425. +// Routine to open a named service
  19426. +extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,
  19427. + SERVICE_CREATION_T *setup,
  19428. + VCHI_SERVICE_HANDLE_T *handle);
  19429. +
  19430. +extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,
  19431. + short *peer_version );
  19432. +
  19433. +// Routine to close a named service
  19434. +extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );
  19435. +
  19436. +// Routine to increment ref count on a named service
  19437. +extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );
  19438. +
  19439. +// Routine to decrement ref count on a named service
  19440. +extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );
  19441. +
  19442. +// Routine to send a message accross a service
  19443. +extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,
  19444. + const void *data,
  19445. + uint32_t data_size,
  19446. + VCHI_FLAGS_T flags,
  19447. + void *msg_handle );
  19448. +
  19449. +// scatter-gather (vector) and send message
  19450. +int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,
  19451. + VCHI_MSG_VECTOR_EX_T *vector,
  19452. + uint32_t count,
  19453. + VCHI_FLAGS_T flags,
  19454. + void *msg_handle );
  19455. +
  19456. +// legacy scatter-gather (vector) and send message, only handles pointers
  19457. +int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,
  19458. + VCHI_MSG_VECTOR_T *vector,
  19459. + uint32_t count,
  19460. + VCHI_FLAGS_T flags,
  19461. + void *msg_handle );
  19462. +
  19463. +// Routine to receive a msg from a service
  19464. +// Dequeue is equivalent to hold, copy into client buffer, release
  19465. +extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
  19466. + void *data,
  19467. + uint32_t max_data_size_to_read,
  19468. + uint32_t *actual_msg_size,
  19469. + VCHI_FLAGS_T flags );
  19470. +
  19471. +// Routine to look at a message in place.
  19472. +// The message is not dequeued, so a subsequent call to peek or dequeue
  19473. +// will return the same message.
  19474. +extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,
  19475. + void **data,
  19476. + uint32_t *msg_size,
  19477. + VCHI_FLAGS_T flags );
  19478. +
  19479. +// Routine to remove a message after it has been read in place with peek
  19480. +// The first message on the queue is dequeued.
  19481. +extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );
  19482. +
  19483. +// Routine to look at a message in place.
  19484. +// The message is dequeued, so the caller is left holding it; the descriptor is
  19485. +// filled in and must be released when the user has finished with the message.
  19486. +extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,
  19487. + void **data, // } may be NULL, as info can be
  19488. + uint32_t *msg_size, // } obtained from HELD_MSG_T
  19489. + VCHI_FLAGS_T flags,
  19490. + VCHI_HELD_MSG_T *message_descriptor );
  19491. +
  19492. +// Initialise an iterator to look through messages in place
  19493. +extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,
  19494. + VCHI_MSG_ITER_T *iter,
  19495. + VCHI_FLAGS_T flags );
  19496. +
  19497. +/******************************************************************************
  19498. + Global service support API - operations on held messages and message iterators
  19499. + *****************************************************************************/
  19500. +
  19501. +// Routine to get the address of a held message
  19502. +extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );
  19503. +
  19504. +// Routine to get the size of a held message
  19505. +extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );
  19506. +
  19507. +// Routine to get the transmit timestamp as written into the header by the peer
  19508. +extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );
  19509. +
  19510. +// Routine to get the reception timestamp, written as we parsed the header
  19511. +extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );
  19512. +
  19513. +// Routine to release a held message after it has been processed
  19514. +extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );
  19515. +
  19516. +// Indicates whether the iterator has a next message.
  19517. +extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );
  19518. +
  19519. +// Return the pointer and length for the next message and advance the iterator.
  19520. +extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,
  19521. + void **data,
  19522. + uint32_t *msg_size );
  19523. +
  19524. +// Remove the last message returned by vchi_msg_iter_next.
  19525. +// Can only be called once after each call to vchi_msg_iter_next.
  19526. +extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );
  19527. +
  19528. +// Hold the last message returned by vchi_msg_iter_next.
  19529. +// Can only be called once after each call to vchi_msg_iter_next.
  19530. +extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,
  19531. + VCHI_HELD_MSG_T *message );
  19532. +
  19533. +// Return information for the next message, and hold it, advancing the iterator.
  19534. +extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,
  19535. + void **data, // } may be NULL
  19536. + uint32_t *msg_size, // }
  19537. + VCHI_HELD_MSG_T *message );
  19538. +
  19539. +
  19540. +/******************************************************************************
  19541. + Global bulk API
  19542. + *****************************************************************************/
  19543. +
  19544. +// Routine to prepare interface for a transfer from the other side
  19545. +extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,
  19546. + void *data_dst,
  19547. + uint32_t data_size,
  19548. + VCHI_FLAGS_T flags,
  19549. + void *transfer_handle );
  19550. +
  19551. +
  19552. +// Prepare interface for a transfer from the other side into relocatable memory.
  19553. +int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,
  19554. + VCHI_MEM_HANDLE_T h_dst,
  19555. + uint32_t offset,
  19556. + uint32_t data_size,
  19557. + const VCHI_FLAGS_T flags,
  19558. + void * const bulk_handle );
  19559. +
  19560. +// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  19561. +extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,
  19562. + const void *data_src,
  19563. + uint32_t data_size,
  19564. + VCHI_FLAGS_T flags,
  19565. + void *transfer_handle );
  19566. +
  19567. +
  19568. +/******************************************************************************
  19569. + Configuration plumbing
  19570. + *****************************************************************************/
  19571. +
  19572. +// function prototypes for the different mid layers (the state info gives the different physical connections)
  19573. +extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
  19574. +//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
  19575. +//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
  19576. +
  19577. +// declare all message drivers here
  19578. +const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
  19579. +
  19580. +#ifdef __cplusplus
  19581. +}
  19582. +#endif
  19583. +
  19584. +extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,
  19585. + VCHI_MEM_HANDLE_T h_src,
  19586. + uint32_t offset,
  19587. + uint32_t data_size,
  19588. + VCHI_FLAGS_T flags,
  19589. + void *transfer_handle );
  19590. +#endif /* VCHI_H_ */
  19591. +
  19592. +/****************************** End of file **********************************/
  19593. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchi/vchi_mh.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h
  19594. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 1970-01-01 01:00:00.000000000 +0100
  19595. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 2014-04-24 15:35:02.893551516 +0200
  19596. @@ -0,0 +1,42 @@
  19597. +/**
  19598. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19599. + *
  19600. + * Redistribution and use in source and binary forms, with or without
  19601. + * modification, are permitted provided that the following conditions
  19602. + * are met:
  19603. + * 1. Redistributions of source code must retain the above copyright
  19604. + * notice, this list of conditions, and the following disclaimer,
  19605. + * without modification.
  19606. + * 2. Redistributions in binary form must reproduce the above copyright
  19607. + * notice, this list of conditions and the following disclaimer in the
  19608. + * documentation and/or other materials provided with the distribution.
  19609. + * 3. The names of the above-listed copyright holders may not be used
  19610. + * to endorse or promote products derived from this software without
  19611. + * specific prior written permission.
  19612. + *
  19613. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19614. + * GNU General Public License ("GPL") version 2, as published by the Free
  19615. + * Software Foundation.
  19616. + *
  19617. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19618. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19619. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19620. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19621. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19622. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19623. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19624. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19625. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19626. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19627. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19628. + */
  19629. +
  19630. +#ifndef VCHI_MH_H_
  19631. +#define VCHI_MH_H_
  19632. +
  19633. +#include <linux/types.h>
  19634. +
  19635. +typedef int32_t VCHI_MEM_HANDLE_T;
  19636. +#define VCHI_MEM_HANDLE_INVALID 0
  19637. +
  19638. +#endif
  19639. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
  19640. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 1970-01-01 01:00:00.000000000 +0100
  19641. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 2014-04-24 15:35:02.893551516 +0200
  19642. @@ -0,0 +1,561 @@
  19643. +/**
  19644. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19645. + *
  19646. + * Redistribution and use in source and binary forms, with or without
  19647. + * modification, are permitted provided that the following conditions
  19648. + * are met:
  19649. + * 1. Redistributions of source code must retain the above copyright
  19650. + * notice, this list of conditions, and the following disclaimer,
  19651. + * without modification.
  19652. + * 2. Redistributions in binary form must reproduce the above copyright
  19653. + * notice, this list of conditions and the following disclaimer in the
  19654. + * documentation and/or other materials provided with the distribution.
  19655. + * 3. The names of the above-listed copyright holders may not be used
  19656. + * to endorse or promote products derived from this software without
  19657. + * specific prior written permission.
  19658. + *
  19659. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19660. + * GNU General Public License ("GPL") version 2, as published by the Free
  19661. + * Software Foundation.
  19662. + *
  19663. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19664. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19665. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19666. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19667. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19668. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19669. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19670. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19671. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19672. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19673. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19674. + */
  19675. +
  19676. +#include <linux/kernel.h>
  19677. +#include <linux/types.h>
  19678. +#include <linux/errno.h>
  19679. +#include <linux/interrupt.h>
  19680. +#include <linux/irq.h>
  19681. +#include <linux/pagemap.h>
  19682. +#include <linux/dma-mapping.h>
  19683. +#include <linux/version.h>
  19684. +#include <linux/io.h>
  19685. +#include <linux/uaccess.h>
  19686. +#include <asm/pgtable.h>
  19687. +
  19688. +#include <mach/irqs.h>
  19689. +
  19690. +#include <mach/platform.h>
  19691. +#include <mach/vcio.h>
  19692. +
  19693. +#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
  19694. +
  19695. +#define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0
  19696. +#define VCHIQ_ARM_ADDRESS(x) ((void *)__virt_to_bus((unsigned)x))
  19697. +
  19698. +#include "vchiq_arm.h"
  19699. +#include "vchiq_2835.h"
  19700. +#include "vchiq_connected.h"
  19701. +
  19702. +#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
  19703. +
  19704. +typedef struct vchiq_2835_state_struct {
  19705. + int inited;
  19706. + VCHIQ_ARM_STATE_T arm_state;
  19707. +} VCHIQ_2835_ARM_STATE_T;
  19708. +
  19709. +static char *g_slot_mem;
  19710. +static int g_slot_mem_size;
  19711. +dma_addr_t g_slot_phys;
  19712. +static FRAGMENTS_T *g_fragments_base;
  19713. +static FRAGMENTS_T *g_free_fragments;
  19714. +struct semaphore g_free_fragments_sema;
  19715. +
  19716. +extern int vchiq_arm_log_level;
  19717. +
  19718. +static DEFINE_SEMAPHORE(g_free_fragments_mutex);
  19719. +
  19720. +static irqreturn_t
  19721. +vchiq_doorbell_irq(int irq, void *dev_id);
  19722. +
  19723. +static int
  19724. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  19725. + struct task_struct *task, PAGELIST_T ** ppagelist);
  19726. +
  19727. +static void
  19728. +free_pagelist(PAGELIST_T *pagelist, int actual);
  19729. +
  19730. +int __init
  19731. +vchiq_platform_init(VCHIQ_STATE_T *state)
  19732. +{
  19733. + VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
  19734. + int frag_mem_size;
  19735. + int err;
  19736. + int i;
  19737. +
  19738. + /* Allocate space for the channels in coherent memory */
  19739. + g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
  19740. + frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);
  19741. +
  19742. + g_slot_mem = dma_alloc_coherent(NULL, g_slot_mem_size + frag_mem_size,
  19743. + &g_slot_phys, GFP_ATOMIC);
  19744. +
  19745. + if (!g_slot_mem) {
  19746. + vchiq_log_error(vchiq_arm_log_level,
  19747. + "Unable to allocate channel memory");
  19748. + err = -ENOMEM;
  19749. + goto failed_alloc;
  19750. + }
  19751. +
  19752. + WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) != 0);
  19753. +
  19754. + vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
  19755. + if (!vchiq_slot_zero) {
  19756. + err = -EINVAL;
  19757. + goto failed_init_slots;
  19758. + }
  19759. +
  19760. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
  19761. + (int)g_slot_phys + g_slot_mem_size;
  19762. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
  19763. + MAX_FRAGMENTS;
  19764. +
  19765. + g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
  19766. + g_slot_mem_size += frag_mem_size;
  19767. +
  19768. + g_free_fragments = g_fragments_base;
  19769. + for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
  19770. + *(FRAGMENTS_T **)&g_fragments_base[i] =
  19771. + &g_fragments_base[i + 1];
  19772. + }
  19773. + *(FRAGMENTS_T **)&g_fragments_base[i] = NULL;
  19774. + sema_init(&g_free_fragments_sema, MAX_FRAGMENTS);
  19775. +
  19776. + if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
  19777. + VCHIQ_SUCCESS) {
  19778. + err = -EINVAL;
  19779. + goto failed_vchiq_init;
  19780. + }
  19781. +
  19782. + err = request_irq(VCHIQ_DOORBELL_IRQ, vchiq_doorbell_irq,
  19783. + IRQF_IRQPOLL, "VCHIQ doorbell",
  19784. + state);
  19785. + if (err < 0) {
  19786. + vchiq_log_error(vchiq_arm_log_level, "%s: failed to register "
  19787. + "irq=%d err=%d", __func__,
  19788. + VCHIQ_DOORBELL_IRQ, err);
  19789. + goto failed_request_irq;
  19790. + }
  19791. +
  19792. + /* Send the base address of the slots to VideoCore */
  19793. +
  19794. + dsb(); /* Ensure all writes have completed */
  19795. +
  19796. + bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);
  19797. +
  19798. + vchiq_log_info(vchiq_arm_log_level,
  19799. + "vchiq_init - done (slots %x, phys %x)",
  19800. + (unsigned int)vchiq_slot_zero, g_slot_phys);
  19801. +
  19802. + vchiq_call_connected_callbacks();
  19803. +
  19804. + return 0;
  19805. +
  19806. +failed_request_irq:
  19807. +failed_vchiq_init:
  19808. +failed_init_slots:
  19809. + dma_free_coherent(NULL, g_slot_mem_size, g_slot_mem, g_slot_phys);
  19810. +
  19811. +failed_alloc:
  19812. + return err;
  19813. +}
  19814. +
  19815. +void __exit
  19816. +vchiq_platform_exit(VCHIQ_STATE_T *state)
  19817. +{
  19818. + free_irq(VCHIQ_DOORBELL_IRQ, state);
  19819. + dma_free_coherent(NULL, g_slot_mem_size,
  19820. + g_slot_mem, g_slot_phys);
  19821. +}
  19822. +
  19823. +
  19824. +VCHIQ_STATUS_T
  19825. +vchiq_platform_init_state(VCHIQ_STATE_T *state)
  19826. +{
  19827. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  19828. + state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
  19829. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1;
  19830. + status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state);
  19831. + if(status != VCHIQ_SUCCESS)
  19832. + {
  19833. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0;
  19834. + }
  19835. + return status;
  19836. +}
  19837. +
  19838. +VCHIQ_ARM_STATE_T*
  19839. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
  19840. +{
  19841. + if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited)
  19842. + {
  19843. + BUG();
  19844. + }
  19845. + return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state;
  19846. +}
  19847. +
  19848. +void
  19849. +remote_event_signal(REMOTE_EVENT_T *event)
  19850. +{
  19851. + wmb();
  19852. +
  19853. + event->fired = 1;
  19854. +
  19855. + dsb(); /* data barrier operation */
  19856. +
  19857. + if (event->armed) {
  19858. + /* trigger vc interrupt */
  19859. +
  19860. + writel(0, __io_address(ARM_0_BELL2));
  19861. + }
  19862. +}
  19863. +
  19864. +int
  19865. +vchiq_copy_from_user(void *dst, const void *src, int size)
  19866. +{
  19867. + if ((uint32_t)src < TASK_SIZE) {
  19868. + return copy_from_user(dst, src, size);
  19869. + } else {
  19870. + memcpy(dst, src, size);
  19871. + return 0;
  19872. + }
  19873. +}
  19874. +
  19875. +VCHIQ_STATUS_T
  19876. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk, VCHI_MEM_HANDLE_T memhandle,
  19877. + void *offset, int size, int dir)
  19878. +{
  19879. + PAGELIST_T *pagelist;
  19880. + int ret;
  19881. +
  19882. + WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID);
  19883. +
  19884. + ret = create_pagelist((char __user *)offset, size,
  19885. + (dir == VCHIQ_BULK_RECEIVE)
  19886. + ? PAGELIST_READ
  19887. + : PAGELIST_WRITE,
  19888. + current,
  19889. + &pagelist);
  19890. + if (ret != 0)
  19891. + return VCHIQ_ERROR;
  19892. +
  19893. + bulk->handle = memhandle;
  19894. + bulk->data = VCHIQ_ARM_ADDRESS(pagelist);
  19895. +
  19896. + /* Store the pagelist address in remote_data, which isn't used by the
  19897. + slave. */
  19898. + bulk->remote_data = pagelist;
  19899. +
  19900. + return VCHIQ_SUCCESS;
  19901. +}
  19902. +
  19903. +void
  19904. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk)
  19905. +{
  19906. + if (bulk && bulk->remote_data && bulk->actual)
  19907. + free_pagelist((PAGELIST_T *)bulk->remote_data, bulk->actual);
  19908. +}
  19909. +
  19910. +void
  19911. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk)
  19912. +{
  19913. + /*
  19914. + * This should only be called on the master (VideoCore) side, but
  19915. + * provide an implementation to avoid the need for ifdefery.
  19916. + */
  19917. + BUG();
  19918. +}
  19919. +
  19920. +void
  19921. +vchiq_dump_platform_state(void *dump_context)
  19922. +{
  19923. + char buf[80];
  19924. + int len;
  19925. + len = snprintf(buf, sizeof(buf),
  19926. + " Platform: 2835 (VC master)");
  19927. + vchiq_dump(dump_context, buf, len + 1);
  19928. +}
  19929. +
  19930. +VCHIQ_STATUS_T
  19931. +vchiq_platform_suspend(VCHIQ_STATE_T *state)
  19932. +{
  19933. + return VCHIQ_ERROR;
  19934. +}
  19935. +
  19936. +VCHIQ_STATUS_T
  19937. +vchiq_platform_resume(VCHIQ_STATE_T *state)
  19938. +{
  19939. + return VCHIQ_SUCCESS;
  19940. +}
  19941. +
  19942. +void
  19943. +vchiq_platform_paused(VCHIQ_STATE_T *state)
  19944. +{
  19945. +}
  19946. +
  19947. +void
  19948. +vchiq_platform_resumed(VCHIQ_STATE_T *state)
  19949. +{
  19950. +}
  19951. +
  19952. +int
  19953. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state)
  19954. +{
  19955. + return 1; // autosuspend not supported - videocore always wanted
  19956. +}
  19957. +
  19958. +int
  19959. +vchiq_platform_use_suspend_timer(void)
  19960. +{
  19961. + return 0;
  19962. +}
  19963. +void
  19964. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
  19965. +{
  19966. + vchiq_log_info((vchiq_arm_log_level>=VCHIQ_LOG_INFO),"Suspend timer not in use");
  19967. +}
  19968. +void
  19969. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state)
  19970. +{
  19971. + (void)state;
  19972. +}
  19973. +/*
  19974. + * Local functions
  19975. + */
  19976. +
  19977. +static irqreturn_t
  19978. +vchiq_doorbell_irq(int irq, void *dev_id)
  19979. +{
  19980. + VCHIQ_STATE_T *state = dev_id;
  19981. + irqreturn_t ret = IRQ_NONE;
  19982. + unsigned int status;
  19983. +
  19984. + /* Read (and clear) the doorbell */
  19985. + status = readl(__io_address(ARM_0_BELL0));
  19986. +
  19987. + if (status & 0x4) { /* Was the doorbell rung? */
  19988. + remote_event_pollall(state);
  19989. + ret = IRQ_HANDLED;
  19990. + }
  19991. +
  19992. + return ret;
  19993. +}
  19994. +
  19995. +/* There is a potential problem with partial cache lines (pages?)
  19996. +** at the ends of the block when reading. If the CPU accessed anything in
  19997. +** the same line (page?) then it may have pulled old data into the cache,
  19998. +** obscuring the new data underneath. We can solve this by transferring the
  19999. +** partial cache lines separately, and allowing the ARM to copy into the
  20000. +** cached area.
  20001. +
  20002. +** N.B. This implementation plays slightly fast and loose with the Linux
  20003. +** driver programming rules, e.g. its use of __virt_to_bus instead of
  20004. +** dma_map_single, but it isn't a multi-platform driver and it benefits
  20005. +** from increased speed as a result.
  20006. +*/
  20007. +
  20008. +static int
  20009. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  20010. + struct task_struct *task, PAGELIST_T ** ppagelist)
  20011. +{
  20012. + PAGELIST_T *pagelist;
  20013. + struct page **pages;
  20014. + struct page *page;
  20015. + unsigned long *addrs;
  20016. + unsigned int num_pages, offset, i;
  20017. + char *addr, *base_addr, *next_addr;
  20018. + int run, addridx, actual_pages;
  20019. + unsigned long *need_release;
  20020. +
  20021. + offset = (unsigned int)buf & (PAGE_SIZE - 1);
  20022. + num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
  20023. +
  20024. + *ppagelist = NULL;
  20025. +
  20026. + /* Allocate enough storage to hold the page pointers and the page
  20027. + ** list
  20028. + */
  20029. + pagelist = kmalloc(sizeof(PAGELIST_T) +
  20030. + (num_pages * sizeof(unsigned long)) +
  20031. + sizeof(unsigned long) +
  20032. + (num_pages * sizeof(pages[0])),
  20033. + GFP_KERNEL);
  20034. +
  20035. + vchiq_log_trace(vchiq_arm_log_level,
  20036. + "create_pagelist - %x", (unsigned int)pagelist);
  20037. + if (!pagelist)
  20038. + return -ENOMEM;
  20039. +
  20040. + addrs = pagelist->addrs;
  20041. + need_release = (unsigned long *)(addrs + num_pages);
  20042. + pages = (struct page **)(addrs + num_pages + 1);
  20043. +
  20044. + if (is_vmalloc_addr(buf)) {
  20045. + for (actual_pages = 0; actual_pages < num_pages; actual_pages++) {
  20046. + pages[actual_pages] = vmalloc_to_page(buf + (actual_pages * PAGE_SIZE));
  20047. + }
  20048. + *need_release = 0; /* do not try and release vmalloc pages */
  20049. + } else {
  20050. + down_read(&task->mm->mmap_sem);
  20051. + actual_pages = get_user_pages(task, task->mm,
  20052. + (unsigned long)buf & ~(PAGE_SIZE - 1),
  20053. + num_pages,
  20054. + (type == PAGELIST_READ) /*Write */ ,
  20055. + 0 /*Force */ ,
  20056. + pages,
  20057. + NULL /*vmas */);
  20058. + up_read(&task->mm->mmap_sem);
  20059. +
  20060. + if (actual_pages != num_pages) {
  20061. + vchiq_log_info(vchiq_arm_log_level,
  20062. + "create_pagelist - only %d/%d pages locked",
  20063. + actual_pages,
  20064. + num_pages);
  20065. +
  20066. + /* This is probably due to the process being killed */
  20067. + while (actual_pages > 0)
  20068. + {
  20069. + actual_pages--;
  20070. + page_cache_release(pages[actual_pages]);
  20071. + }
  20072. + kfree(pagelist);
  20073. + if (actual_pages == 0)
  20074. + actual_pages = -ENOMEM;
  20075. + return actual_pages;
  20076. + }
  20077. + *need_release = 1; /* release user pages */
  20078. + }
  20079. +
  20080. + pagelist->length = count;
  20081. + pagelist->type = type;
  20082. + pagelist->offset = offset;
  20083. +
  20084. + /* Group the pages into runs of contiguous pages */
  20085. +
  20086. + base_addr = VCHIQ_ARM_ADDRESS(page_address(pages[0]));
  20087. + next_addr = base_addr + PAGE_SIZE;
  20088. + addridx = 0;
  20089. + run = 0;
  20090. +
  20091. + for (i = 1; i < num_pages; i++) {
  20092. + addr = VCHIQ_ARM_ADDRESS(page_address(pages[i]));
  20093. + if ((addr == next_addr) && (run < (PAGE_SIZE - 1))) {
  20094. + next_addr += PAGE_SIZE;
  20095. + run++;
  20096. + } else {
  20097. + addrs[addridx] = (unsigned long)base_addr + run;
  20098. + addridx++;
  20099. + base_addr = addr;
  20100. + next_addr = addr + PAGE_SIZE;
  20101. + run = 0;
  20102. + }
  20103. + }
  20104. +
  20105. + addrs[addridx] = (unsigned long)base_addr + run;
  20106. + addridx++;
  20107. +
  20108. + /* Partial cache lines (fragments) require special measures */
  20109. + if ((type == PAGELIST_READ) &&
  20110. + ((pagelist->offset & (CACHE_LINE_SIZE - 1)) ||
  20111. + ((pagelist->offset + pagelist->length) &
  20112. + (CACHE_LINE_SIZE - 1)))) {
  20113. + FRAGMENTS_T *fragments;
  20114. +
  20115. + if (down_interruptible(&g_free_fragments_sema) != 0) {
  20116. + kfree(pagelist);
  20117. + return -EINTR;
  20118. + }
  20119. +
  20120. + WARN_ON(g_free_fragments == NULL);
  20121. +
  20122. + down(&g_free_fragments_mutex);
  20123. + fragments = (FRAGMENTS_T *) g_free_fragments;
  20124. + WARN_ON(fragments == NULL);
  20125. + g_free_fragments = *(FRAGMENTS_T **) g_free_fragments;
  20126. + up(&g_free_fragments_mutex);
  20127. + pagelist->type =
  20128. + PAGELIST_READ_WITH_FRAGMENTS + (fragments -
  20129. + g_fragments_base);
  20130. + }
  20131. +
  20132. + for (page = virt_to_page(pagelist);
  20133. + page <= virt_to_page(addrs + num_pages - 1); page++) {
  20134. + flush_dcache_page(page);
  20135. + }
  20136. +
  20137. + *ppagelist = pagelist;
  20138. +
  20139. + return 0;
  20140. +}
  20141. +
  20142. +static void
  20143. +free_pagelist(PAGELIST_T *pagelist, int actual)
  20144. +{
  20145. + unsigned long *need_release;
  20146. + struct page **pages;
  20147. + unsigned int num_pages, i;
  20148. +
  20149. + vchiq_log_trace(vchiq_arm_log_level,
  20150. + "free_pagelist - %x, %d", (unsigned int)pagelist, actual);
  20151. +
  20152. + num_pages =
  20153. + (pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
  20154. + PAGE_SIZE;
  20155. +
  20156. + need_release = (unsigned long *)(pagelist->addrs + num_pages);
  20157. + pages = (struct page **)(pagelist->addrs + num_pages + 1);
  20158. +
  20159. + /* Deal with any partial cache lines (fragments) */
  20160. + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS) {
  20161. + FRAGMENTS_T *fragments = g_fragments_base +
  20162. + (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS);
  20163. + int head_bytes, tail_bytes;
  20164. + head_bytes = (CACHE_LINE_SIZE - pagelist->offset) &
  20165. + (CACHE_LINE_SIZE - 1);
  20166. + tail_bytes = (pagelist->offset + actual) &
  20167. + (CACHE_LINE_SIZE - 1);
  20168. +
  20169. + if ((actual >= 0) && (head_bytes != 0)) {
  20170. + if (head_bytes > actual)
  20171. + head_bytes = actual;
  20172. +
  20173. + memcpy((char *)page_address(pages[0]) +
  20174. + pagelist->offset,
  20175. + fragments->headbuf,
  20176. + head_bytes);
  20177. + }
  20178. + if ((actual >= 0) && (head_bytes < actual) &&
  20179. + (tail_bytes != 0)) {
  20180. + memcpy((char *)page_address(pages[num_pages - 1]) +
  20181. + ((pagelist->offset + actual) &
  20182. + (PAGE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)),
  20183. + fragments->tailbuf, tail_bytes);
  20184. + }
  20185. +
  20186. + down(&g_free_fragments_mutex);
  20187. + *(FRAGMENTS_T **) fragments = g_free_fragments;
  20188. + g_free_fragments = fragments;
  20189. + up(&g_free_fragments_mutex);
  20190. + up(&g_free_fragments_sema);
  20191. + }
  20192. +
  20193. + if (*need_release) {
  20194. + for (i = 0; i < num_pages; i++) {
  20195. + if (pagelist->type != PAGELIST_WRITE)
  20196. + set_page_dirty(pages[i]);
  20197. +
  20198. + page_cache_release(pages[i]);
  20199. + }
  20200. + }
  20201. +
  20202. + kfree(pagelist);
  20203. +}
  20204. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h
  20205. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 1970-01-01 01:00:00.000000000 +0100
  20206. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 2014-04-24 15:35:02.893551516 +0200
  20207. @@ -0,0 +1,42 @@
  20208. +/**
  20209. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20210. + *
  20211. + * Redistribution and use in source and binary forms, with or without
  20212. + * modification, are permitted provided that the following conditions
  20213. + * are met:
  20214. + * 1. Redistributions of source code must retain the above copyright
  20215. + * notice, this list of conditions, and the following disclaimer,
  20216. + * without modification.
  20217. + * 2. Redistributions in binary form must reproduce the above copyright
  20218. + * notice, this list of conditions and the following disclaimer in the
  20219. + * documentation and/or other materials provided with the distribution.
  20220. + * 3. The names of the above-listed copyright holders may not be used
  20221. + * to endorse or promote products derived from this software without
  20222. + * specific prior written permission.
  20223. + *
  20224. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20225. + * GNU General Public License ("GPL") version 2, as published by the Free
  20226. + * Software Foundation.
  20227. + *
  20228. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20229. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20230. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20231. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20232. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20233. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20234. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20235. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20236. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20237. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20238. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20239. + */
  20240. +
  20241. +#ifndef VCHIQ_2835_H
  20242. +#define VCHIQ_2835_H
  20243. +
  20244. +#include "vchiq_pagelist.h"
  20245. +
  20246. +#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
  20247. +#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
  20248. +
  20249. +#endif /* VCHIQ_2835_H */
  20250. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
  20251. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 1970-01-01 01:00:00.000000000 +0100
  20252. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 2014-04-24 15:35:02.893551516 +0200
  20253. @@ -0,0 +1,2813 @@
  20254. +/**
  20255. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20256. + *
  20257. + * Redistribution and use in source and binary forms, with or without
  20258. + * modification, are permitted provided that the following conditions
  20259. + * are met:
  20260. + * 1. Redistributions of source code must retain the above copyright
  20261. + * notice, this list of conditions, and the following disclaimer,
  20262. + * without modification.
  20263. + * 2. Redistributions in binary form must reproduce the above copyright
  20264. + * notice, this list of conditions and the following disclaimer in the
  20265. + * documentation and/or other materials provided with the distribution.
  20266. + * 3. The names of the above-listed copyright holders may not be used
  20267. + * to endorse or promote products derived from this software without
  20268. + * specific prior written permission.
  20269. + *
  20270. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20271. + * GNU General Public License ("GPL") version 2, as published by the Free
  20272. + * Software Foundation.
  20273. + *
  20274. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20275. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20276. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20277. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20278. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20279. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20280. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20281. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20282. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20283. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20284. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20285. + */
  20286. +
  20287. +#include <linux/kernel.h>
  20288. +#include <linux/module.h>
  20289. +#include <linux/types.h>
  20290. +#include <linux/errno.h>
  20291. +#include <linux/cdev.h>
  20292. +#include <linux/fs.h>
  20293. +#include <linux/device.h>
  20294. +#include <linux/mm.h>
  20295. +#include <linux/highmem.h>
  20296. +#include <linux/pagemap.h>
  20297. +#include <linux/bug.h>
  20298. +#include <linux/semaphore.h>
  20299. +#include <linux/list.h>
  20300. +#include <linux/proc_fs.h>
  20301. +
  20302. +#include "vchiq_core.h"
  20303. +#include "vchiq_ioctl.h"
  20304. +#include "vchiq_arm.h"
  20305. +
  20306. +#define DEVICE_NAME "vchiq"
  20307. +
  20308. +/* Override the default prefix, which would be vchiq_arm (from the filename) */
  20309. +#undef MODULE_PARAM_PREFIX
  20310. +#define MODULE_PARAM_PREFIX DEVICE_NAME "."
  20311. +
  20312. +#define VCHIQ_MINOR 0
  20313. +
  20314. +/* Some per-instance constants */
  20315. +#define MAX_COMPLETIONS 16
  20316. +#define MAX_SERVICES 64
  20317. +#define MAX_ELEMENTS 8
  20318. +#define MSG_QUEUE_SIZE 64
  20319. +
  20320. +#define KEEPALIVE_VER 1
  20321. +#define KEEPALIVE_VER_MIN KEEPALIVE_VER
  20322. +
  20323. +/* Run time control of log level, based on KERN_XXX level. */
  20324. +int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
  20325. +int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
  20326. +
  20327. +#define SUSPEND_TIMER_TIMEOUT_MS 100
  20328. +#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
  20329. +
  20330. +#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
  20331. +static const char *const suspend_state_names[] = {
  20332. + "VC_SUSPEND_FORCE_CANCELED",
  20333. + "VC_SUSPEND_REJECTED",
  20334. + "VC_SUSPEND_FAILED",
  20335. + "VC_SUSPEND_IDLE",
  20336. + "VC_SUSPEND_REQUESTED",
  20337. + "VC_SUSPEND_IN_PROGRESS",
  20338. + "VC_SUSPEND_SUSPENDED"
  20339. +};
  20340. +#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
  20341. +static const char *const resume_state_names[] = {
  20342. + "VC_RESUME_FAILED",
  20343. + "VC_RESUME_IDLE",
  20344. + "VC_RESUME_REQUESTED",
  20345. + "VC_RESUME_IN_PROGRESS",
  20346. + "VC_RESUME_RESUMED"
  20347. +};
  20348. +/* The number of times we allow force suspend to timeout before actually
  20349. +** _forcing_ suspend. This is to cater for SW which fails to release vchiq
  20350. +** correctly - we don't want to prevent ARM suspend indefinitely in this case.
  20351. +*/
  20352. +#define FORCE_SUSPEND_FAIL_MAX 8
  20353. +
  20354. +/* The time in ms allowed for videocore to go idle when force suspend has been
  20355. + * requested */
  20356. +#define FORCE_SUSPEND_TIMEOUT_MS 200
  20357. +
  20358. +
  20359. +static void suspend_timer_callback(unsigned long context);
  20360. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance);
  20361. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance);
  20362. +
  20363. +
  20364. +typedef struct user_service_struct {
  20365. + VCHIQ_SERVICE_T *service;
  20366. + void *userdata;
  20367. + VCHIQ_INSTANCE_T instance;
  20368. + int is_vchi;
  20369. + int dequeue_pending;
  20370. + int message_available_pos;
  20371. + int msg_insert;
  20372. + int msg_remove;
  20373. + struct semaphore insert_event;
  20374. + struct semaphore remove_event;
  20375. + VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
  20376. +} USER_SERVICE_T;
  20377. +
  20378. +struct bulk_waiter_node {
  20379. + struct bulk_waiter bulk_waiter;
  20380. + int pid;
  20381. + struct list_head list;
  20382. +};
  20383. +
  20384. +struct vchiq_instance_struct {
  20385. + VCHIQ_STATE_T *state;
  20386. + VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
  20387. + int completion_insert;
  20388. + int completion_remove;
  20389. + struct semaphore insert_event;
  20390. + struct semaphore remove_event;
  20391. + struct mutex completion_mutex;
  20392. +
  20393. + int connected;
  20394. + int closing;
  20395. + int pid;
  20396. + int mark;
  20397. +
  20398. + struct list_head bulk_waiter_list;
  20399. + struct mutex bulk_waiter_list_mutex;
  20400. +
  20401. + struct proc_dir_entry *proc_entry;
  20402. +};
  20403. +
  20404. +typedef struct dump_context_struct {
  20405. + char __user *buf;
  20406. + size_t actual;
  20407. + size_t space;
  20408. + loff_t offset;
  20409. +} DUMP_CONTEXT_T;
  20410. +
  20411. +static struct cdev vchiq_cdev;
  20412. +static dev_t vchiq_devid;
  20413. +static VCHIQ_STATE_T g_state;
  20414. +static struct class *vchiq_class;
  20415. +static struct device *vchiq_dev;
  20416. +static DEFINE_SPINLOCK(msg_queue_spinlock);
  20417. +
  20418. +static const char *const ioctl_names[] = {
  20419. + "CONNECT",
  20420. + "SHUTDOWN",
  20421. + "CREATE_SERVICE",
  20422. + "REMOVE_SERVICE",
  20423. + "QUEUE_MESSAGE",
  20424. + "QUEUE_BULK_TRANSMIT",
  20425. + "QUEUE_BULK_RECEIVE",
  20426. + "AWAIT_COMPLETION",
  20427. + "DEQUEUE_MESSAGE",
  20428. + "GET_CLIENT_ID",
  20429. + "GET_CONFIG",
  20430. + "CLOSE_SERVICE",
  20431. + "USE_SERVICE",
  20432. + "RELEASE_SERVICE",
  20433. + "SET_SERVICE_OPTION",
  20434. + "DUMP_PHYS_MEM"
  20435. +};
  20436. +
  20437. +vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
  20438. + (VCHIQ_IOC_MAX + 1));
  20439. +
  20440. +static void
  20441. +dump_phys_mem(void *virt_addr, uint32_t num_bytes);
  20442. +
  20443. +/****************************************************************************
  20444. +*
  20445. +* add_completion
  20446. +*
  20447. +***************************************************************************/
  20448. +
  20449. +static VCHIQ_STATUS_T
  20450. +add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
  20451. + VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
  20452. + void *bulk_userdata)
  20453. +{
  20454. + VCHIQ_COMPLETION_DATA_T *completion;
  20455. + DEBUG_INITIALISE(g_state.local)
  20456. +
  20457. + while (instance->completion_insert ==
  20458. + (instance->completion_remove + MAX_COMPLETIONS)) {
  20459. + /* Out of space - wait for the client */
  20460. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20461. + vchiq_log_trace(vchiq_arm_log_level,
  20462. + "add_completion - completion queue full");
  20463. + DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
  20464. + if (down_interruptible(&instance->remove_event) != 0) {
  20465. + vchiq_log_info(vchiq_arm_log_level,
  20466. + "service_callback interrupted");
  20467. + return VCHIQ_RETRY;
  20468. + } else if (instance->closing) {
  20469. + vchiq_log_info(vchiq_arm_log_level,
  20470. + "service_callback closing");
  20471. + return VCHIQ_ERROR;
  20472. + }
  20473. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20474. + }
  20475. +
  20476. + completion =
  20477. + &instance->completions[instance->completion_insert &
  20478. + (MAX_COMPLETIONS - 1)];
  20479. +
  20480. + completion->header = header;
  20481. + completion->reason = reason;
  20482. + /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
  20483. + completion->service_userdata = user_service->service;
  20484. + completion->bulk_userdata = bulk_userdata;
  20485. +
  20486. + if (reason == VCHIQ_SERVICE_CLOSED)
  20487. + /* Take an extra reference, to be held until
  20488. + this CLOSED notification is delivered. */
  20489. + lock_service(user_service->service);
  20490. +
  20491. + /* A write barrier is needed here to ensure that the entire completion
  20492. + record is written out before the insert point. */
  20493. + wmb();
  20494. +
  20495. + if (reason == VCHIQ_MESSAGE_AVAILABLE)
  20496. + user_service->message_available_pos =
  20497. + instance->completion_insert;
  20498. + instance->completion_insert++;
  20499. +
  20500. + up(&instance->insert_event);
  20501. +
  20502. + return VCHIQ_SUCCESS;
  20503. +}
  20504. +
  20505. +/****************************************************************************
  20506. +*
  20507. +* service_callback
  20508. +*
  20509. +***************************************************************************/
  20510. +
  20511. +static VCHIQ_STATUS_T
  20512. +service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
  20513. + VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
  20514. +{
  20515. + /* How do we ensure the callback goes to the right client?
  20516. + ** The service_user data points to a USER_SERVICE_T record containing
  20517. + ** the original callback and the user state structure, which contains a
  20518. + ** circular buffer for completion records.
  20519. + */
  20520. + USER_SERVICE_T *user_service;
  20521. + VCHIQ_SERVICE_T *service;
  20522. + VCHIQ_INSTANCE_T instance;
  20523. + DEBUG_INITIALISE(g_state.local)
  20524. +
  20525. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20526. +
  20527. + service = handle_to_service(handle);
  20528. + BUG_ON(!service);
  20529. + user_service = (USER_SERVICE_T *)service->base.userdata;
  20530. + instance = user_service->instance;
  20531. +
  20532. + if (!instance || instance->closing)
  20533. + return VCHIQ_SUCCESS;
  20534. +
  20535. + vchiq_log_trace(vchiq_arm_log_level,
  20536. + "service_callback - service %lx(%d), reason %d, header %lx, "
  20537. + "instance %lx, bulk_userdata %lx",
  20538. + (unsigned long)user_service,
  20539. + service->localport,
  20540. + reason, (unsigned long)header,
  20541. + (unsigned long)instance, (unsigned long)bulk_userdata);
  20542. +
  20543. + if (header && user_service->is_vchi) {
  20544. + spin_lock(&msg_queue_spinlock);
  20545. + while (user_service->msg_insert ==
  20546. + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
  20547. + spin_unlock(&msg_queue_spinlock);
  20548. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20549. + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
  20550. + vchiq_log_trace(vchiq_arm_log_level,
  20551. + "service_callback - msg queue full");
  20552. + /* If there is no MESSAGE_AVAILABLE in the completion
  20553. + ** queue, add one
  20554. + */
  20555. + if ((user_service->message_available_pos -
  20556. + instance->completion_remove) < 0) {
  20557. + VCHIQ_STATUS_T status;
  20558. + vchiq_log_info(vchiq_arm_log_level,
  20559. + "Inserting extra MESSAGE_AVAILABLE");
  20560. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20561. + status = add_completion(instance, reason,
  20562. + NULL, user_service, bulk_userdata);
  20563. + if (status != VCHIQ_SUCCESS) {
  20564. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20565. + return status;
  20566. + }
  20567. + }
  20568. +
  20569. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20570. + if (down_interruptible(&user_service->remove_event)
  20571. + != 0) {
  20572. + vchiq_log_info(vchiq_arm_log_level,
  20573. + "service_callback interrupted");
  20574. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20575. + return VCHIQ_RETRY;
  20576. + } else if (instance->closing) {
  20577. + vchiq_log_info(vchiq_arm_log_level,
  20578. + "service_callback closing");
  20579. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20580. + return VCHIQ_ERROR;
  20581. + }
  20582. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20583. + spin_lock(&msg_queue_spinlock);
  20584. + }
  20585. +
  20586. + user_service->msg_queue[user_service->msg_insert &
  20587. + (MSG_QUEUE_SIZE - 1)] = header;
  20588. + user_service->msg_insert++;
  20589. + spin_unlock(&msg_queue_spinlock);
  20590. +
  20591. + up(&user_service->insert_event);
  20592. +
  20593. + /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
  20594. + ** there is a MESSAGE_AVAILABLE in the completion queue then
  20595. + ** bypass the completion queue.
  20596. + */
  20597. + if (((user_service->message_available_pos -
  20598. + instance->completion_remove) >= 0) ||
  20599. + user_service->dequeue_pending) {
  20600. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20601. + user_service->dequeue_pending = 0;
  20602. + return VCHIQ_SUCCESS;
  20603. + }
  20604. +
  20605. + header = NULL;
  20606. + }
  20607. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20608. +
  20609. + return add_completion(instance, reason, header, user_service,
  20610. + bulk_userdata);
  20611. +}
  20612. +
  20613. +/****************************************************************************
  20614. +*
  20615. +* user_service_free
  20616. +*
  20617. +***************************************************************************/
  20618. +static void
  20619. +user_service_free(void *userdata)
  20620. +{
  20621. + kfree(userdata);
  20622. +}
  20623. +
  20624. +/****************************************************************************
  20625. +*
  20626. +* vchiq_ioctl
  20627. +*
  20628. +***************************************************************************/
  20629. +
  20630. +static long
  20631. +vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  20632. +{
  20633. + VCHIQ_INSTANCE_T instance = file->private_data;
  20634. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  20635. + VCHIQ_SERVICE_T *service = NULL;
  20636. + long ret = 0;
  20637. + int i, rc;
  20638. + DEBUG_INITIALISE(g_state.local)
  20639. +
  20640. + vchiq_log_trace(vchiq_arm_log_level,
  20641. + "vchiq_ioctl - instance %x, cmd %s, arg %lx",
  20642. + (unsigned int)instance,
  20643. + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
  20644. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
  20645. + ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
  20646. +
  20647. + switch (cmd) {
  20648. + case VCHIQ_IOC_SHUTDOWN:
  20649. + if (!instance->connected)
  20650. + break;
  20651. +
  20652. + /* Remove all services */
  20653. + i = 0;
  20654. + while ((service = next_service_by_instance(instance->state,
  20655. + instance, &i)) != NULL) {
  20656. + status = vchiq_remove_service(service->handle);
  20657. + unlock_service(service);
  20658. + if (status != VCHIQ_SUCCESS)
  20659. + break;
  20660. + }
  20661. + service = NULL;
  20662. +
  20663. + if (status == VCHIQ_SUCCESS) {
  20664. + /* Wake the completion thread and ask it to exit */
  20665. + instance->closing = 1;
  20666. + up(&instance->insert_event);
  20667. + }
  20668. +
  20669. + break;
  20670. +
  20671. + case VCHIQ_IOC_CONNECT:
  20672. + if (instance->connected) {
  20673. + ret = -EINVAL;
  20674. + break;
  20675. + }
  20676. + rc = mutex_lock_interruptible(&instance->state->mutex);
  20677. + if (rc != 0) {
  20678. + vchiq_log_error(vchiq_arm_log_level,
  20679. + "vchiq: connect: could not lock mutex for "
  20680. + "state %d: %d",
  20681. + instance->state->id, rc);
  20682. + ret = -EINTR;
  20683. + break;
  20684. + }
  20685. + status = vchiq_connect_internal(instance->state, instance);
  20686. + mutex_unlock(&instance->state->mutex);
  20687. +
  20688. + if (status == VCHIQ_SUCCESS)
  20689. + instance->connected = 1;
  20690. + else
  20691. + vchiq_log_error(vchiq_arm_log_level,
  20692. + "vchiq: could not connect: %d", status);
  20693. + break;
  20694. +
  20695. + case VCHIQ_IOC_CREATE_SERVICE: {
  20696. + VCHIQ_CREATE_SERVICE_T args;
  20697. + USER_SERVICE_T *user_service = NULL;
  20698. + void *userdata;
  20699. + int srvstate;
  20700. +
  20701. + if (copy_from_user
  20702. + (&args, (const void __user *)arg,
  20703. + sizeof(args)) != 0) {
  20704. + ret = -EFAULT;
  20705. + break;
  20706. + }
  20707. +
  20708. + user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
  20709. + if (!user_service) {
  20710. + ret = -ENOMEM;
  20711. + break;
  20712. + }
  20713. +
  20714. + if (args.is_open) {
  20715. + if (!instance->connected) {
  20716. + ret = -ENOTCONN;
  20717. + kfree(user_service);
  20718. + break;
  20719. + }
  20720. + srvstate = VCHIQ_SRVSTATE_OPENING;
  20721. + } else {
  20722. + srvstate =
  20723. + instance->connected ?
  20724. + VCHIQ_SRVSTATE_LISTENING :
  20725. + VCHIQ_SRVSTATE_HIDDEN;
  20726. + }
  20727. +
  20728. + userdata = args.params.userdata;
  20729. + args.params.callback = service_callback;
  20730. + args.params.userdata = user_service;
  20731. + service = vchiq_add_service_internal(
  20732. + instance->state,
  20733. + &args.params, srvstate,
  20734. + instance, user_service_free);
  20735. +
  20736. + if (service != NULL) {
  20737. + user_service->service = service;
  20738. + user_service->userdata = userdata;
  20739. + user_service->instance = instance;
  20740. + user_service->is_vchi = args.is_vchi;
  20741. + user_service->dequeue_pending = 0;
  20742. + user_service->message_available_pos =
  20743. + instance->completion_remove - 1;
  20744. + user_service->msg_insert = 0;
  20745. + user_service->msg_remove = 0;
  20746. + sema_init(&user_service->insert_event, 0);
  20747. + sema_init(&user_service->remove_event, 0);
  20748. +
  20749. + if (args.is_open) {
  20750. + status = vchiq_open_service_internal
  20751. + (service, instance->pid);
  20752. + if (status != VCHIQ_SUCCESS) {
  20753. + vchiq_remove_service(service->handle);
  20754. + service = NULL;
  20755. + ret = (status == VCHIQ_RETRY) ?
  20756. + -EINTR : -EIO;
  20757. + break;
  20758. + }
  20759. + }
  20760. +
  20761. + if (copy_to_user((void __user *)
  20762. + &(((VCHIQ_CREATE_SERVICE_T __user *)
  20763. + arg)->handle),
  20764. + (const void *)&service->handle,
  20765. + sizeof(service->handle)) != 0) {
  20766. + ret = -EFAULT;
  20767. + vchiq_remove_service(service->handle);
  20768. + }
  20769. +
  20770. + service = NULL;
  20771. + } else {
  20772. + ret = -EEXIST;
  20773. + kfree(user_service);
  20774. + }
  20775. + } break;
  20776. +
  20777. + case VCHIQ_IOC_CLOSE_SERVICE: {
  20778. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20779. +
  20780. + service = find_service_for_instance(instance, handle);
  20781. + if (service != NULL)
  20782. + status = vchiq_close_service(service->handle);
  20783. + else
  20784. + ret = -EINVAL;
  20785. + } break;
  20786. +
  20787. + case VCHIQ_IOC_REMOVE_SERVICE: {
  20788. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20789. +
  20790. + service = find_service_for_instance(instance, handle);
  20791. + if (service != NULL)
  20792. + status = vchiq_remove_service(service->handle);
  20793. + else
  20794. + ret = -EINVAL;
  20795. + } break;
  20796. +
  20797. + case VCHIQ_IOC_USE_SERVICE:
  20798. + case VCHIQ_IOC_RELEASE_SERVICE: {
  20799. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20800. +
  20801. + service = find_service_for_instance(instance, handle);
  20802. + if (service != NULL) {
  20803. + status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
  20804. + vchiq_use_service_internal(service) :
  20805. + vchiq_release_service_internal(service);
  20806. + if (status != VCHIQ_SUCCESS) {
  20807. + vchiq_log_error(vchiq_susp_log_level,
  20808. + "%s: cmd %s returned error %d for "
  20809. + "service %c%c%c%c:%03d",
  20810. + __func__,
  20811. + (cmd == VCHIQ_IOC_USE_SERVICE) ?
  20812. + "VCHIQ_IOC_USE_SERVICE" :
  20813. + "VCHIQ_IOC_RELEASE_SERVICE",
  20814. + status,
  20815. + VCHIQ_FOURCC_AS_4CHARS(
  20816. + service->base.fourcc),
  20817. + service->client_id);
  20818. + ret = -EINVAL;
  20819. + }
  20820. + } else
  20821. + ret = -EINVAL;
  20822. + } break;
  20823. +
  20824. + case VCHIQ_IOC_QUEUE_MESSAGE: {
  20825. + VCHIQ_QUEUE_MESSAGE_T args;
  20826. + if (copy_from_user
  20827. + (&args, (const void __user *)arg,
  20828. + sizeof(args)) != 0) {
  20829. + ret = -EFAULT;
  20830. + break;
  20831. + }
  20832. +
  20833. + service = find_service_for_instance(instance, args.handle);
  20834. +
  20835. + if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
  20836. + /* Copy elements into kernel space */
  20837. + VCHIQ_ELEMENT_T elements[MAX_ELEMENTS];
  20838. + if (copy_from_user(elements, args.elements,
  20839. + args.count * sizeof(VCHIQ_ELEMENT_T)) == 0)
  20840. + status = vchiq_queue_message
  20841. + (args.handle,
  20842. + elements, args.count);
  20843. + else
  20844. + ret = -EFAULT;
  20845. + } else {
  20846. + ret = -EINVAL;
  20847. + }
  20848. + } break;
  20849. +
  20850. + case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
  20851. + case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
  20852. + VCHIQ_QUEUE_BULK_TRANSFER_T args;
  20853. + struct bulk_waiter_node *waiter = NULL;
  20854. + VCHIQ_BULK_DIR_T dir =
  20855. + (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
  20856. + VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
  20857. +
  20858. + if (copy_from_user
  20859. + (&args, (const void __user *)arg,
  20860. + sizeof(args)) != 0) {
  20861. + ret = -EFAULT;
  20862. + break;
  20863. + }
  20864. +
  20865. + service = find_service_for_instance(instance, args.handle);
  20866. + if (!service) {
  20867. + ret = -EINVAL;
  20868. + break;
  20869. + }
  20870. +
  20871. + if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
  20872. + waiter = kzalloc(sizeof(struct bulk_waiter_node),
  20873. + GFP_KERNEL);
  20874. + if (!waiter) {
  20875. + ret = -ENOMEM;
  20876. + break;
  20877. + }
  20878. + args.userdata = &waiter->bulk_waiter;
  20879. + } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
  20880. + struct list_head *pos;
  20881. + mutex_lock(&instance->bulk_waiter_list_mutex);
  20882. + list_for_each(pos, &instance->bulk_waiter_list) {
  20883. + if (list_entry(pos, struct bulk_waiter_node,
  20884. + list)->pid == current->pid) {
  20885. + waiter = list_entry(pos,
  20886. + struct bulk_waiter_node,
  20887. + list);
  20888. + list_del(pos);
  20889. + break;
  20890. + }
  20891. +
  20892. + }
  20893. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  20894. + if (!waiter) {
  20895. + vchiq_log_error(vchiq_arm_log_level,
  20896. + "no bulk_waiter found for pid %d",
  20897. + current->pid);
  20898. + ret = -ESRCH;
  20899. + break;
  20900. + }
  20901. + vchiq_log_info(vchiq_arm_log_level,
  20902. + "found bulk_waiter %x for pid %d",
  20903. + (unsigned int)waiter, current->pid);
  20904. + args.userdata = &waiter->bulk_waiter;
  20905. + }
  20906. + status = vchiq_bulk_transfer
  20907. + (args.handle,
  20908. + VCHI_MEM_HANDLE_INVALID,
  20909. + args.data, args.size,
  20910. + args.userdata, args.mode,
  20911. + dir);
  20912. + if (!waiter)
  20913. + break;
  20914. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  20915. + !waiter->bulk_waiter.bulk) {
  20916. + if (waiter->bulk_waiter.bulk) {
  20917. + /* Cancel the signal when the transfer
  20918. + ** completes. */
  20919. + spin_lock(&bulk_waiter_spinlock);
  20920. + waiter->bulk_waiter.bulk->userdata = NULL;
  20921. + spin_unlock(&bulk_waiter_spinlock);
  20922. + }
  20923. + kfree(waiter);
  20924. + } else {
  20925. + const VCHIQ_BULK_MODE_T mode_waiting =
  20926. + VCHIQ_BULK_MODE_WAITING;
  20927. + waiter->pid = current->pid;
  20928. + mutex_lock(&instance->bulk_waiter_list_mutex);
  20929. + list_add(&waiter->list, &instance->bulk_waiter_list);
  20930. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  20931. + vchiq_log_info(vchiq_arm_log_level,
  20932. + "saved bulk_waiter %x for pid %d",
  20933. + (unsigned int)waiter, current->pid);
  20934. +
  20935. + if (copy_to_user((void __user *)
  20936. + &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
  20937. + arg)->mode),
  20938. + (const void *)&mode_waiting,
  20939. + sizeof(mode_waiting)) != 0)
  20940. + ret = -EFAULT;
  20941. + }
  20942. + } break;
  20943. +
  20944. + case VCHIQ_IOC_AWAIT_COMPLETION: {
  20945. + VCHIQ_AWAIT_COMPLETION_T args;
  20946. +
  20947. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20948. + if (!instance->connected) {
  20949. + ret = -ENOTCONN;
  20950. + break;
  20951. + }
  20952. +
  20953. + if (copy_from_user(&args, (const void __user *)arg,
  20954. + sizeof(args)) != 0) {
  20955. + ret = -EFAULT;
  20956. + break;
  20957. + }
  20958. +
  20959. + mutex_lock(&instance->completion_mutex);
  20960. +
  20961. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20962. + while ((instance->completion_remove ==
  20963. + instance->completion_insert)
  20964. + && !instance->closing) {
  20965. + int rc;
  20966. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20967. + mutex_unlock(&instance->completion_mutex);
  20968. + rc = down_interruptible(&instance->insert_event);
  20969. + mutex_lock(&instance->completion_mutex);
  20970. + if (rc != 0) {
  20971. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20972. + vchiq_log_info(vchiq_arm_log_level,
  20973. + "AWAIT_COMPLETION interrupted");
  20974. + ret = -EINTR;
  20975. + break;
  20976. + }
  20977. + }
  20978. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20979. +
  20980. + /* A read memory barrier is needed to stop prefetch of a stale
  20981. + ** completion record
  20982. + */
  20983. + rmb();
  20984. +
  20985. + if (ret == 0) {
  20986. + int msgbufcount = args.msgbufcount;
  20987. + for (ret = 0; ret < args.count; ret++) {
  20988. + VCHIQ_COMPLETION_DATA_T *completion;
  20989. + VCHIQ_SERVICE_T *service;
  20990. + USER_SERVICE_T *user_service;
  20991. + VCHIQ_HEADER_T *header;
  20992. + if (instance->completion_remove ==
  20993. + instance->completion_insert)
  20994. + break;
  20995. + completion = &instance->completions[
  20996. + instance->completion_remove &
  20997. + (MAX_COMPLETIONS - 1)];
  20998. +
  20999. + service = completion->service_userdata;
  21000. + user_service = service->base.userdata;
  21001. + completion->service_userdata =
  21002. + user_service->userdata;
  21003. +
  21004. + header = completion->header;
  21005. + if (header) {
  21006. + void __user *msgbuf;
  21007. + int msglen;
  21008. +
  21009. + msglen = header->size +
  21010. + sizeof(VCHIQ_HEADER_T);
  21011. + /* This must be a VCHIQ-style service */
  21012. + if (args.msgbufsize < msglen) {
  21013. + vchiq_log_error(
  21014. + vchiq_arm_log_level,
  21015. + "header %x: msgbufsize"
  21016. + " %x < msglen %x",
  21017. + (unsigned int)header,
  21018. + args.msgbufsize,
  21019. + msglen);
  21020. + WARN(1, "invalid message "
  21021. + "size\n");
  21022. + if (ret == 0)
  21023. + ret = -EMSGSIZE;
  21024. + break;
  21025. + }
  21026. + if (msgbufcount <= 0)
  21027. + /* Stall here for lack of a
  21028. + ** buffer for the message. */
  21029. + break;
  21030. + /* Get the pointer from user space */
  21031. + msgbufcount--;
  21032. + if (copy_from_user(&msgbuf,
  21033. + (const void __user *)
  21034. + &args.msgbufs[msgbufcount],
  21035. + sizeof(msgbuf)) != 0) {
  21036. + if (ret == 0)
  21037. + ret = -EFAULT;
  21038. + break;
  21039. + }
  21040. +
  21041. + /* Copy the message to user space */
  21042. + if (copy_to_user(msgbuf, header,
  21043. + msglen) != 0) {
  21044. + if (ret == 0)
  21045. + ret = -EFAULT;
  21046. + break;
  21047. + }
  21048. +
  21049. + /* Now it has been copied, the message
  21050. + ** can be released. */
  21051. + vchiq_release_message(service->handle,
  21052. + header);
  21053. +
  21054. + /* The completion must point to the
  21055. + ** msgbuf. */
  21056. + completion->header = msgbuf;
  21057. + }
  21058. +
  21059. + if (completion->reason ==
  21060. + VCHIQ_SERVICE_CLOSED)
  21061. + unlock_service(service);
  21062. +
  21063. + if (copy_to_user((void __user *)(
  21064. + (size_t)args.buf +
  21065. + ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
  21066. + completion,
  21067. + sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
  21068. + if (ret == 0)
  21069. + ret = -EFAULT;
  21070. + break;
  21071. + }
  21072. +
  21073. + instance->completion_remove++;
  21074. + }
  21075. +
  21076. + if (msgbufcount != args.msgbufcount) {
  21077. + if (copy_to_user((void __user *)
  21078. + &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
  21079. + msgbufcount,
  21080. + &msgbufcount,
  21081. + sizeof(msgbufcount)) != 0) {
  21082. + ret = -EFAULT;
  21083. + }
  21084. + }
  21085. + }
  21086. +
  21087. + if (ret != 0)
  21088. + up(&instance->remove_event);
  21089. + mutex_unlock(&instance->completion_mutex);
  21090. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  21091. + } break;
  21092. +
  21093. + case VCHIQ_IOC_DEQUEUE_MESSAGE: {
  21094. + VCHIQ_DEQUEUE_MESSAGE_T args;
  21095. + USER_SERVICE_T *user_service;
  21096. + VCHIQ_HEADER_T *header;
  21097. +
  21098. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21099. + if (copy_from_user
  21100. + (&args, (const void __user *)arg,
  21101. + sizeof(args)) != 0) {
  21102. + ret = -EFAULT;
  21103. + break;
  21104. + }
  21105. + service = find_service_for_instance(instance, args.handle);
  21106. + if (!service) {
  21107. + ret = -EINVAL;
  21108. + break;
  21109. + }
  21110. + user_service = (USER_SERVICE_T *)service->base.userdata;
  21111. + if (user_service->is_vchi == 0) {
  21112. + ret = -EINVAL;
  21113. + break;
  21114. + }
  21115. +
  21116. + spin_lock(&msg_queue_spinlock);
  21117. + if (user_service->msg_remove == user_service->msg_insert) {
  21118. + if (!args.blocking) {
  21119. + spin_unlock(&msg_queue_spinlock);
  21120. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21121. + ret = -EWOULDBLOCK;
  21122. + break;
  21123. + }
  21124. + user_service->dequeue_pending = 1;
  21125. + do {
  21126. + spin_unlock(&msg_queue_spinlock);
  21127. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21128. + if (down_interruptible(
  21129. + &user_service->insert_event) != 0) {
  21130. + vchiq_log_info(vchiq_arm_log_level,
  21131. + "DEQUEUE_MESSAGE interrupted");
  21132. + ret = -EINTR;
  21133. + break;
  21134. + }
  21135. + spin_lock(&msg_queue_spinlock);
  21136. + } while (user_service->msg_remove ==
  21137. + user_service->msg_insert);
  21138. +
  21139. + if (ret)
  21140. + break;
  21141. + }
  21142. +
  21143. + BUG_ON((int)(user_service->msg_insert -
  21144. + user_service->msg_remove) < 0);
  21145. +
  21146. + header = user_service->msg_queue[user_service->msg_remove &
  21147. + (MSG_QUEUE_SIZE - 1)];
  21148. + user_service->msg_remove++;
  21149. + spin_unlock(&msg_queue_spinlock);
  21150. +
  21151. + up(&user_service->remove_event);
  21152. + if (header == NULL)
  21153. + ret = -ENOTCONN;
  21154. + else if (header->size <= args.bufsize) {
  21155. + /* Copy to user space if msgbuf is not NULL */
  21156. + if ((args.buf == NULL) ||
  21157. + (copy_to_user((void __user *)args.buf,
  21158. + header->data,
  21159. + header->size) == 0)) {
  21160. + ret = header->size;
  21161. + vchiq_release_message(
  21162. + service->handle,
  21163. + header);
  21164. + } else
  21165. + ret = -EFAULT;
  21166. + } else {
  21167. + vchiq_log_error(vchiq_arm_log_level,
  21168. + "header %x: bufsize %x < size %x",
  21169. + (unsigned int)header, args.bufsize,
  21170. + header->size);
  21171. + WARN(1, "invalid size\n");
  21172. + ret = -EMSGSIZE;
  21173. + }
  21174. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21175. + } break;
  21176. +
  21177. + case VCHIQ_IOC_GET_CLIENT_ID: {
  21178. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  21179. +
  21180. + ret = vchiq_get_client_id(handle);
  21181. + } break;
  21182. +
  21183. + case VCHIQ_IOC_GET_CONFIG: {
  21184. + VCHIQ_GET_CONFIG_T args;
  21185. + VCHIQ_CONFIG_T config;
  21186. +
  21187. + if (copy_from_user(&args, (const void __user *)arg,
  21188. + sizeof(args)) != 0) {
  21189. + ret = -EFAULT;
  21190. + break;
  21191. + }
  21192. + if (args.config_size > sizeof(config)) {
  21193. + ret = -EINVAL;
  21194. + break;
  21195. + }
  21196. + status = vchiq_get_config(instance, args.config_size, &config);
  21197. + if (status == VCHIQ_SUCCESS) {
  21198. + if (copy_to_user((void __user *)args.pconfig,
  21199. + &config, args.config_size) != 0) {
  21200. + ret = -EFAULT;
  21201. + break;
  21202. + }
  21203. + }
  21204. + } break;
  21205. +
  21206. + case VCHIQ_IOC_SET_SERVICE_OPTION: {
  21207. + VCHIQ_SET_SERVICE_OPTION_T args;
  21208. +
  21209. + if (copy_from_user(
  21210. + &args, (const void __user *)arg,
  21211. + sizeof(args)) != 0) {
  21212. + ret = -EFAULT;
  21213. + break;
  21214. + }
  21215. +
  21216. + service = find_service_for_instance(instance, args.handle);
  21217. + if (!service) {
  21218. + ret = -EINVAL;
  21219. + break;
  21220. + }
  21221. +
  21222. + status = vchiq_set_service_option(
  21223. + args.handle, args.option, args.value);
  21224. + } break;
  21225. +
  21226. + case VCHIQ_IOC_DUMP_PHYS_MEM: {
  21227. + VCHIQ_DUMP_MEM_T args;
  21228. +
  21229. + if (copy_from_user
  21230. + (&args, (const void __user *)arg,
  21231. + sizeof(args)) != 0) {
  21232. + ret = -EFAULT;
  21233. + break;
  21234. + }
  21235. + dump_phys_mem(args.virt_addr, args.num_bytes);
  21236. + } break;
  21237. +
  21238. + default:
  21239. + ret = -ENOTTY;
  21240. + break;
  21241. + }
  21242. +
  21243. + if (service)
  21244. + unlock_service(service);
  21245. +
  21246. + if (ret == 0) {
  21247. + if (status == VCHIQ_ERROR)
  21248. + ret = -EIO;
  21249. + else if (status == VCHIQ_RETRY)
  21250. + ret = -EINTR;
  21251. + }
  21252. +
  21253. + if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
  21254. + (ret != -EWOULDBLOCK))
  21255. + vchiq_log_info(vchiq_arm_log_level,
  21256. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  21257. + (unsigned long)instance,
  21258. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  21259. + ioctl_names[_IOC_NR(cmd)] :
  21260. + "<invalid>",
  21261. + status, ret);
  21262. + else
  21263. + vchiq_log_trace(vchiq_arm_log_level,
  21264. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  21265. + (unsigned long)instance,
  21266. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  21267. + ioctl_names[_IOC_NR(cmd)] :
  21268. + "<invalid>",
  21269. + status, ret);
  21270. +
  21271. + return ret;
  21272. +}
  21273. +
  21274. +/****************************************************************************
  21275. +*
  21276. +* vchiq_open
  21277. +*
  21278. +***************************************************************************/
  21279. +
  21280. +static int
  21281. +vchiq_open(struct inode *inode, struct file *file)
  21282. +{
  21283. + int dev = iminor(inode) & 0x0f;
  21284. + vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
  21285. + switch (dev) {
  21286. + case VCHIQ_MINOR: {
  21287. + int ret;
  21288. + VCHIQ_STATE_T *state = vchiq_get_state();
  21289. + VCHIQ_INSTANCE_T instance;
  21290. +
  21291. + if (!state) {
  21292. + vchiq_log_error(vchiq_arm_log_level,
  21293. + "vchiq has no connection to VideoCore");
  21294. + return -ENOTCONN;
  21295. + }
  21296. +
  21297. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  21298. + if (!instance)
  21299. + return -ENOMEM;
  21300. +
  21301. + instance->state = state;
  21302. + instance->pid = current->tgid;
  21303. +
  21304. + ret = vchiq_proc_add_instance(instance);
  21305. + if (ret != 0) {
  21306. + kfree(instance);
  21307. + return ret;
  21308. + }
  21309. +
  21310. + sema_init(&instance->insert_event, 0);
  21311. + sema_init(&instance->remove_event, 0);
  21312. + mutex_init(&instance->completion_mutex);
  21313. + mutex_init(&instance->bulk_waiter_list_mutex);
  21314. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  21315. +
  21316. + file->private_data = instance;
  21317. + } break;
  21318. +
  21319. + default:
  21320. + vchiq_log_error(vchiq_arm_log_level,
  21321. + "Unknown minor device: %d", dev);
  21322. + return -ENXIO;
  21323. + }
  21324. +
  21325. + return 0;
  21326. +}
  21327. +
  21328. +/****************************************************************************
  21329. +*
  21330. +* vchiq_release
  21331. +*
  21332. +***************************************************************************/
  21333. +
  21334. +static int
  21335. +vchiq_release(struct inode *inode, struct file *file)
  21336. +{
  21337. + int dev = iminor(inode) & 0x0f;
  21338. + int ret = 0;
  21339. + switch (dev) {
  21340. + case VCHIQ_MINOR: {
  21341. + VCHIQ_INSTANCE_T instance = file->private_data;
  21342. + VCHIQ_STATE_T *state = vchiq_get_state();
  21343. + VCHIQ_SERVICE_T *service;
  21344. + int i;
  21345. +
  21346. + vchiq_log_info(vchiq_arm_log_level,
  21347. + "vchiq_release: instance=%lx",
  21348. + (unsigned long)instance);
  21349. +
  21350. + if (!state) {
  21351. + ret = -EPERM;
  21352. + goto out;
  21353. + }
  21354. +
  21355. + /* Ensure videocore is awake to allow termination. */
  21356. + vchiq_use_internal(instance->state, NULL,
  21357. + USE_TYPE_VCHIQ);
  21358. +
  21359. + mutex_lock(&instance->completion_mutex);
  21360. +
  21361. + /* Wake the completion thread and ask it to exit */
  21362. + instance->closing = 1;
  21363. + up(&instance->insert_event);
  21364. +
  21365. + mutex_unlock(&instance->completion_mutex);
  21366. +
  21367. + /* Wake the slot handler if the completion queue is full. */
  21368. + up(&instance->remove_event);
  21369. +
  21370. + /* Mark all services for termination... */
  21371. + i = 0;
  21372. + while ((service = next_service_by_instance(state, instance,
  21373. + &i)) != NULL) {
  21374. + USER_SERVICE_T *user_service = service->base.userdata;
  21375. +
  21376. + /* Wake the slot handler if the msg queue is full. */
  21377. + up(&user_service->remove_event);
  21378. +
  21379. + vchiq_terminate_service_internal(service);
  21380. + unlock_service(service);
  21381. + }
  21382. +
  21383. + /* ...and wait for them to die */
  21384. + i = 0;
  21385. + while ((service = next_service_by_instance(state, instance, &i))
  21386. + != NULL) {
  21387. + USER_SERVICE_T *user_service = service->base.userdata;
  21388. +
  21389. + down(&service->remove_event);
  21390. +
  21391. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  21392. +
  21393. + spin_lock(&msg_queue_spinlock);
  21394. +
  21395. + while (user_service->msg_remove !=
  21396. + user_service->msg_insert) {
  21397. + VCHIQ_HEADER_T *header = user_service->
  21398. + msg_queue[user_service->msg_remove &
  21399. + (MSG_QUEUE_SIZE - 1)];
  21400. + user_service->msg_remove++;
  21401. + spin_unlock(&msg_queue_spinlock);
  21402. +
  21403. + if (header)
  21404. + vchiq_release_message(
  21405. + service->handle,
  21406. + header);
  21407. + spin_lock(&msg_queue_spinlock);
  21408. + }
  21409. +
  21410. + spin_unlock(&msg_queue_spinlock);
  21411. +
  21412. + unlock_service(service);
  21413. + }
  21414. +
  21415. + /* Release any closed services */
  21416. + while (instance->completion_remove !=
  21417. + instance->completion_insert) {
  21418. + VCHIQ_COMPLETION_DATA_T *completion;
  21419. + VCHIQ_SERVICE_T *service;
  21420. + completion = &instance->completions[
  21421. + instance->completion_remove &
  21422. + (MAX_COMPLETIONS - 1)];
  21423. + service = completion->service_userdata;
  21424. + if (completion->reason == VCHIQ_SERVICE_CLOSED)
  21425. + unlock_service(service);
  21426. + instance->completion_remove++;
  21427. + }
  21428. +
  21429. + /* Release the PEER service count. */
  21430. + vchiq_release_internal(instance->state, NULL);
  21431. +
  21432. + {
  21433. + struct list_head *pos, *next;
  21434. + list_for_each_safe(pos, next,
  21435. + &instance->bulk_waiter_list) {
  21436. + struct bulk_waiter_node *waiter;
  21437. + waiter = list_entry(pos,
  21438. + struct bulk_waiter_node,
  21439. + list);
  21440. + list_del(pos);
  21441. + vchiq_log_info(vchiq_arm_log_level,
  21442. + "bulk_waiter - cleaned up %x "
  21443. + "for pid %d",
  21444. + (unsigned int)waiter, waiter->pid);
  21445. + kfree(waiter);
  21446. + }
  21447. + }
  21448. +
  21449. + vchiq_proc_remove_instance(instance);
  21450. +
  21451. + kfree(instance);
  21452. + file->private_data = NULL;
  21453. + } break;
  21454. +
  21455. + default:
  21456. + vchiq_log_error(vchiq_arm_log_level,
  21457. + "Unknown minor device: %d", dev);
  21458. + ret = -ENXIO;
  21459. + }
  21460. +
  21461. +out:
  21462. + return ret;
  21463. +}
  21464. +
  21465. +/****************************************************************************
  21466. +*
  21467. +* vchiq_dump
  21468. +*
  21469. +***************************************************************************/
  21470. +
  21471. +void
  21472. +vchiq_dump(void *dump_context, const char *str, int len)
  21473. +{
  21474. + DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
  21475. +
  21476. + if (context->actual < context->space) {
  21477. + int copy_bytes;
  21478. + if (context->offset > 0) {
  21479. + int skip_bytes = min(len, (int)context->offset);
  21480. + str += skip_bytes;
  21481. + len -= skip_bytes;
  21482. + context->offset -= skip_bytes;
  21483. + if (context->offset > 0)
  21484. + return;
  21485. + }
  21486. + copy_bytes = min(len, (int)(context->space - context->actual));
  21487. + if (copy_bytes == 0)
  21488. + return;
  21489. + if (copy_to_user(context->buf + context->actual, str,
  21490. + copy_bytes))
  21491. + context->actual = -EFAULT;
  21492. + context->actual += copy_bytes;
  21493. + len -= copy_bytes;
  21494. +
  21495. + /* If tne terminating NUL is included in the length, then it
  21496. + ** marks the end of a line and should be replaced with a
  21497. + ** carriage return. */
  21498. + if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
  21499. + char cr = '\n';
  21500. + if (copy_to_user(context->buf + context->actual - 1,
  21501. + &cr, 1))
  21502. + context->actual = -EFAULT;
  21503. + }
  21504. + }
  21505. +}
  21506. +
  21507. +/****************************************************************************
  21508. +*
  21509. +* vchiq_dump_platform_instance_state
  21510. +*
  21511. +***************************************************************************/
  21512. +
  21513. +void
  21514. +vchiq_dump_platform_instances(void *dump_context)
  21515. +{
  21516. + VCHIQ_STATE_T *state = vchiq_get_state();
  21517. + char buf[80];
  21518. + int len;
  21519. + int i;
  21520. +
  21521. + /* There is no list of instances, so instead scan all services,
  21522. + marking those that have been dumped. */
  21523. +
  21524. + for (i = 0; i < state->unused_service; i++) {
  21525. + VCHIQ_SERVICE_T *service = state->services[i];
  21526. + VCHIQ_INSTANCE_T instance;
  21527. +
  21528. + if (service && (service->base.callback == service_callback)) {
  21529. + instance = service->instance;
  21530. + if (instance)
  21531. + instance->mark = 0;
  21532. + }
  21533. + }
  21534. +
  21535. + for (i = 0; i < state->unused_service; i++) {
  21536. + VCHIQ_SERVICE_T *service = state->services[i];
  21537. + VCHIQ_INSTANCE_T instance;
  21538. +
  21539. + if (service && (service->base.callback == service_callback)) {
  21540. + instance = service->instance;
  21541. + if (instance && !instance->mark) {
  21542. + len = snprintf(buf, sizeof(buf),
  21543. + "Instance %x: pid %d,%s completions "
  21544. + "%d/%d",
  21545. + (unsigned int)instance, instance->pid,
  21546. + instance->connected ? " connected, " :
  21547. + "",
  21548. + instance->completion_insert -
  21549. + instance->completion_remove,
  21550. + MAX_COMPLETIONS);
  21551. +
  21552. + vchiq_dump(dump_context, buf, len + 1);
  21553. +
  21554. + instance->mark = 1;
  21555. + }
  21556. + }
  21557. + }
  21558. +}
  21559. +
  21560. +/****************************************************************************
  21561. +*
  21562. +* vchiq_dump_platform_service_state
  21563. +*
  21564. +***************************************************************************/
  21565. +
  21566. +void
  21567. +vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  21568. +{
  21569. + USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
  21570. + char buf[80];
  21571. + int len;
  21572. +
  21573. + len = snprintf(buf, sizeof(buf), " instance %x",
  21574. + (unsigned int)service->instance);
  21575. +
  21576. + if ((service->base.callback == service_callback) &&
  21577. + user_service->is_vchi) {
  21578. + len += snprintf(buf + len, sizeof(buf) - len,
  21579. + ", %d/%d messages",
  21580. + user_service->msg_insert - user_service->msg_remove,
  21581. + MSG_QUEUE_SIZE);
  21582. +
  21583. + if (user_service->dequeue_pending)
  21584. + len += snprintf(buf + len, sizeof(buf) - len,
  21585. + " (dequeue pending)");
  21586. + }
  21587. +
  21588. + vchiq_dump(dump_context, buf, len + 1);
  21589. +}
  21590. +
  21591. +/****************************************************************************
  21592. +*
  21593. +* dump_user_mem
  21594. +*
  21595. +***************************************************************************/
  21596. +
  21597. +static void
  21598. +dump_phys_mem(void *virt_addr, uint32_t num_bytes)
  21599. +{
  21600. + int rc;
  21601. + uint8_t *end_virt_addr = virt_addr + num_bytes;
  21602. + int num_pages;
  21603. + int offset;
  21604. + int end_offset;
  21605. + int page_idx;
  21606. + int prev_idx;
  21607. + struct page *page;
  21608. + struct page **pages;
  21609. + uint8_t *kmapped_virt_ptr;
  21610. +
  21611. + /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
  21612. +
  21613. + virt_addr = (void *)((unsigned long)virt_addr & ~0x0fuL);
  21614. + end_virt_addr = (void *)(((unsigned long)end_virt_addr + 15uL) &
  21615. + ~0x0fuL);
  21616. +
  21617. + offset = (int)(long)virt_addr & (PAGE_SIZE - 1);
  21618. + end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
  21619. +
  21620. + num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
  21621. +
  21622. + pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
  21623. + if (pages == NULL) {
  21624. + vchiq_log_error(vchiq_arm_log_level,
  21625. + "Unable to allocation memory for %d pages\n",
  21626. + num_pages);
  21627. + return;
  21628. + }
  21629. +
  21630. + down_read(&current->mm->mmap_sem);
  21631. + rc = get_user_pages(current, /* task */
  21632. + current->mm, /* mm */
  21633. + (unsigned long)virt_addr, /* start */
  21634. + num_pages, /* len */
  21635. + 0, /* write */
  21636. + 0, /* force */
  21637. + pages, /* pages (array of page pointers) */
  21638. + NULL); /* vmas */
  21639. + up_read(&current->mm->mmap_sem);
  21640. +
  21641. + prev_idx = -1;
  21642. + page = NULL;
  21643. +
  21644. + while (offset < end_offset) {
  21645. +
  21646. + int page_offset = offset % PAGE_SIZE;
  21647. + page_idx = offset / PAGE_SIZE;
  21648. +
  21649. + if (page_idx != prev_idx) {
  21650. +
  21651. + if (page != NULL)
  21652. + kunmap(page);
  21653. + page = pages[page_idx];
  21654. + kmapped_virt_ptr = kmap(page);
  21655. +
  21656. + prev_idx = page_idx;
  21657. + }
  21658. +
  21659. + if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
  21660. + vchiq_log_dump_mem("ph",
  21661. + (uint32_t)(unsigned long)&kmapped_virt_ptr[
  21662. + page_offset],
  21663. + &kmapped_virt_ptr[page_offset], 16);
  21664. +
  21665. + offset += 16;
  21666. + }
  21667. + if (page != NULL)
  21668. + kunmap(page);
  21669. +
  21670. + for (page_idx = 0; page_idx < num_pages; page_idx++)
  21671. + page_cache_release(pages[page_idx]);
  21672. +
  21673. + kfree(pages);
  21674. +}
  21675. +
  21676. +/****************************************************************************
  21677. +*
  21678. +* vchiq_read
  21679. +*
  21680. +***************************************************************************/
  21681. +
  21682. +static ssize_t
  21683. +vchiq_read(struct file *file, char __user *buf,
  21684. + size_t count, loff_t *ppos)
  21685. +{
  21686. + DUMP_CONTEXT_T context;
  21687. + context.buf = buf;
  21688. + context.actual = 0;
  21689. + context.space = count;
  21690. + context.offset = *ppos;
  21691. +
  21692. + vchiq_dump_state(&context, &g_state);
  21693. +
  21694. + *ppos += context.actual;
  21695. +
  21696. + return context.actual;
  21697. +}
  21698. +
  21699. +VCHIQ_STATE_T *
  21700. +vchiq_get_state(void)
  21701. +{
  21702. +
  21703. + if (g_state.remote == NULL)
  21704. + printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
  21705. + else if (g_state.remote->initialised != 1)
  21706. + printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
  21707. + __func__, g_state.remote->initialised);
  21708. +
  21709. + return ((g_state.remote != NULL) &&
  21710. + (g_state.remote->initialised == 1)) ? &g_state : NULL;
  21711. +}
  21712. +
  21713. +static const struct file_operations
  21714. +vchiq_fops = {
  21715. + .owner = THIS_MODULE,
  21716. + .unlocked_ioctl = vchiq_ioctl,
  21717. + .open = vchiq_open,
  21718. + .release = vchiq_release,
  21719. + .read = vchiq_read
  21720. +};
  21721. +
  21722. +/*
  21723. + * Autosuspend related functionality
  21724. + */
  21725. +
  21726. +int
  21727. +vchiq_videocore_wanted(VCHIQ_STATE_T *state)
  21728. +{
  21729. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21730. + if (!arm_state)
  21731. + /* autosuspend not supported - always return wanted */
  21732. + return 1;
  21733. + else if (arm_state->blocked_count)
  21734. + return 1;
  21735. + else if (!arm_state->videocore_use_count)
  21736. + /* usage count zero - check for override unless we're forcing */
  21737. + if (arm_state->resume_blocked)
  21738. + return 0;
  21739. + else
  21740. + return vchiq_platform_videocore_wanted(state);
  21741. + else
  21742. + /* non-zero usage count - videocore still required */
  21743. + return 1;
  21744. +}
  21745. +
  21746. +static VCHIQ_STATUS_T
  21747. +vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
  21748. + VCHIQ_HEADER_T *header,
  21749. + VCHIQ_SERVICE_HANDLE_T service_user,
  21750. + void *bulk_user)
  21751. +{
  21752. + vchiq_log_error(vchiq_susp_log_level,
  21753. + "%s callback reason %d", __func__, reason);
  21754. + return 0;
  21755. +}
  21756. +
  21757. +static int
  21758. +vchiq_keepalive_thread_func(void *v)
  21759. +{
  21760. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  21761. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21762. +
  21763. + VCHIQ_STATUS_T status;
  21764. + VCHIQ_INSTANCE_T instance;
  21765. + VCHIQ_SERVICE_HANDLE_T ka_handle;
  21766. +
  21767. + VCHIQ_SERVICE_PARAMS_T params = {
  21768. + .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
  21769. + .callback = vchiq_keepalive_vchiq_callback,
  21770. + .version = KEEPALIVE_VER,
  21771. + .version_min = KEEPALIVE_VER_MIN
  21772. + };
  21773. +
  21774. + status = vchiq_initialise(&instance);
  21775. + if (status != VCHIQ_SUCCESS) {
  21776. + vchiq_log_error(vchiq_susp_log_level,
  21777. + "%s vchiq_initialise failed %d", __func__, status);
  21778. + goto exit;
  21779. + }
  21780. +
  21781. + status = vchiq_connect(instance);
  21782. + if (status != VCHIQ_SUCCESS) {
  21783. + vchiq_log_error(vchiq_susp_log_level,
  21784. + "%s vchiq_connect failed %d", __func__, status);
  21785. + goto shutdown;
  21786. + }
  21787. +
  21788. + status = vchiq_add_service(instance, &params, &ka_handle);
  21789. + if (status != VCHIQ_SUCCESS) {
  21790. + vchiq_log_error(vchiq_susp_log_level,
  21791. + "%s vchiq_open_service failed %d", __func__, status);
  21792. + goto shutdown;
  21793. + }
  21794. +
  21795. + while (1) {
  21796. + long rc = 0, uc = 0;
  21797. + if (wait_for_completion_interruptible(&arm_state->ka_evt)
  21798. + != 0) {
  21799. + vchiq_log_error(vchiq_susp_log_level,
  21800. + "%s interrupted", __func__);
  21801. + flush_signals(current);
  21802. + continue;
  21803. + }
  21804. +
  21805. + /* read and clear counters. Do release_count then use_count to
  21806. + * prevent getting more releases than uses */
  21807. + rc = atomic_xchg(&arm_state->ka_release_count, 0);
  21808. + uc = atomic_xchg(&arm_state->ka_use_count, 0);
  21809. +
  21810. + /* Call use/release service the requisite number of times.
  21811. + * Process use before release so use counts don't go negative */
  21812. + while (uc--) {
  21813. + atomic_inc(&arm_state->ka_use_ack_count);
  21814. + status = vchiq_use_service(ka_handle);
  21815. + if (status != VCHIQ_SUCCESS) {
  21816. + vchiq_log_error(vchiq_susp_log_level,
  21817. + "%s vchiq_use_service error %d",
  21818. + __func__, status);
  21819. + }
  21820. + }
  21821. + while (rc--) {
  21822. + status = vchiq_release_service(ka_handle);
  21823. + if (status != VCHIQ_SUCCESS) {
  21824. + vchiq_log_error(vchiq_susp_log_level,
  21825. + "%s vchiq_release_service error %d",
  21826. + __func__, status);
  21827. + }
  21828. + }
  21829. + }
  21830. +
  21831. +shutdown:
  21832. + vchiq_shutdown(instance);
  21833. +exit:
  21834. + return 0;
  21835. +}
  21836. +
  21837. +
  21838. +
  21839. +VCHIQ_STATUS_T
  21840. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
  21841. +{
  21842. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  21843. +
  21844. + if (arm_state) {
  21845. + rwlock_init(&arm_state->susp_res_lock);
  21846. +
  21847. + init_completion(&arm_state->ka_evt);
  21848. + atomic_set(&arm_state->ka_use_count, 0);
  21849. + atomic_set(&arm_state->ka_use_ack_count, 0);
  21850. + atomic_set(&arm_state->ka_release_count, 0);
  21851. +
  21852. + init_completion(&arm_state->vc_suspend_complete);
  21853. +
  21854. + init_completion(&arm_state->vc_resume_complete);
  21855. + /* Initialise to 'done' state. We only want to block on resume
  21856. + * completion while videocore is suspended. */
  21857. + set_resume_state(arm_state, VC_RESUME_RESUMED);
  21858. +
  21859. + init_completion(&arm_state->resume_blocker);
  21860. + /* Initialise to 'done' state. We only want to block on this
  21861. + * completion while resume is blocked */
  21862. + complete_all(&arm_state->resume_blocker);
  21863. +
  21864. + init_completion(&arm_state->blocked_blocker);
  21865. + /* Initialise to 'done' state. We only want to block on this
  21866. + * completion while things are waiting on the resume blocker */
  21867. + complete_all(&arm_state->blocked_blocker);
  21868. +
  21869. + arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
  21870. + arm_state->suspend_timer_running = 0;
  21871. + init_timer(&arm_state->suspend_timer);
  21872. + arm_state->suspend_timer.data = (unsigned long)(state);
  21873. + arm_state->suspend_timer.function = suspend_timer_callback;
  21874. +
  21875. + arm_state->first_connect = 0;
  21876. +
  21877. + }
  21878. + return status;
  21879. +}
  21880. +
  21881. +/*
  21882. +** Functions to modify the state variables;
  21883. +** set_suspend_state
  21884. +** set_resume_state
  21885. +**
  21886. +** There are more state variables than we might like, so ensure they remain in
  21887. +** step. Suspend and resume state are maintained separately, since most of
  21888. +** these state machines can operate independently. However, there are a few
  21889. +** states where state transitions in one state machine cause a reset to the
  21890. +** other state machine. In addition, there are some completion events which
  21891. +** need to occur on state machine reset and end-state(s), so these are also
  21892. +** dealt with in these functions.
  21893. +**
  21894. +** In all states we set the state variable according to the input, but in some
  21895. +** cases we perform additional steps outlined below;
  21896. +**
  21897. +** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
  21898. +** The suspend completion is completed after any suspend
  21899. +** attempt. When we reset the state machine we also reset
  21900. +** the completion. This reset occurs when videocore is
  21901. +** resumed, and also if we initiate suspend after a suspend
  21902. +** failure.
  21903. +**
  21904. +** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
  21905. +** suspend - ie from this point on we must try to suspend
  21906. +** before resuming can occur. We therefore also reset the
  21907. +** resume state machine to VC_RESUME_IDLE in this state.
  21908. +**
  21909. +** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
  21910. +** complete_all on the suspend completion to notify
  21911. +** anything waiting for suspend to happen.
  21912. +**
  21913. +** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
  21914. +** initiate resume, so no need to alter resume state.
  21915. +** We call complete_all on the suspend completion to notify
  21916. +** of suspend rejection.
  21917. +**
  21918. +** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
  21919. +** suspend completion and reset the resume state machine.
  21920. +**
  21921. +** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
  21922. +** resume completion is in it's 'done' state whenever
  21923. +** videcore is running. Therfore, the VC_RESUME_IDLE state
  21924. +** implies that videocore is suspended.
  21925. +** Hence, any thread which needs to wait until videocore is
  21926. +** running can wait on this completion - it will only block
  21927. +** if videocore is suspended.
  21928. +**
  21929. +** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
  21930. +** Call complete_all on the resume completion to unblock
  21931. +** any threads waiting for resume. Also reset the suspend
  21932. +** state machine to it's idle state.
  21933. +**
  21934. +** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
  21935. +*/
  21936. +
  21937. +inline void
  21938. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  21939. + enum vc_suspend_status new_state)
  21940. +{
  21941. + /* set the state in all cases */
  21942. + arm_state->vc_suspend_state = new_state;
  21943. +
  21944. + /* state specific additional actions */
  21945. + switch (new_state) {
  21946. + case VC_SUSPEND_FORCE_CANCELED:
  21947. + complete_all(&arm_state->vc_suspend_complete);
  21948. + break;
  21949. + case VC_SUSPEND_REJECTED:
  21950. + complete_all(&arm_state->vc_suspend_complete);
  21951. + break;
  21952. + case VC_SUSPEND_FAILED:
  21953. + complete_all(&arm_state->vc_suspend_complete);
  21954. + arm_state->vc_resume_state = VC_RESUME_RESUMED;
  21955. + complete_all(&arm_state->vc_resume_complete);
  21956. + break;
  21957. + case VC_SUSPEND_IDLE:
  21958. + INIT_COMPLETION(arm_state->vc_suspend_complete);
  21959. + break;
  21960. + case VC_SUSPEND_REQUESTED:
  21961. + break;
  21962. + case VC_SUSPEND_IN_PROGRESS:
  21963. + set_resume_state(arm_state, VC_RESUME_IDLE);
  21964. + break;
  21965. + case VC_SUSPEND_SUSPENDED:
  21966. + complete_all(&arm_state->vc_suspend_complete);
  21967. + break;
  21968. + default:
  21969. + BUG();
  21970. + break;
  21971. + }
  21972. +}
  21973. +
  21974. +inline void
  21975. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  21976. + enum vc_resume_status new_state)
  21977. +{
  21978. + /* set the state in all cases */
  21979. + arm_state->vc_resume_state = new_state;
  21980. +
  21981. + /* state specific additional actions */
  21982. + switch (new_state) {
  21983. + case VC_RESUME_FAILED:
  21984. + break;
  21985. + case VC_RESUME_IDLE:
  21986. + INIT_COMPLETION(arm_state->vc_resume_complete);
  21987. + break;
  21988. + case VC_RESUME_REQUESTED:
  21989. + break;
  21990. + case VC_RESUME_IN_PROGRESS:
  21991. + break;
  21992. + case VC_RESUME_RESUMED:
  21993. + complete_all(&arm_state->vc_resume_complete);
  21994. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21995. + break;
  21996. + default:
  21997. + BUG();
  21998. + break;
  21999. + }
  22000. +}
  22001. +
  22002. +
  22003. +/* should be called with the write lock held */
  22004. +inline void
  22005. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  22006. +{
  22007. + del_timer(&arm_state->suspend_timer);
  22008. + arm_state->suspend_timer.expires = jiffies +
  22009. + msecs_to_jiffies(arm_state->
  22010. + suspend_timer_timeout);
  22011. + add_timer(&arm_state->suspend_timer);
  22012. + arm_state->suspend_timer_running = 1;
  22013. +}
  22014. +
  22015. +/* should be called with the write lock held */
  22016. +static inline void
  22017. +stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  22018. +{
  22019. + if (arm_state->suspend_timer_running) {
  22020. + del_timer(&arm_state->suspend_timer);
  22021. + arm_state->suspend_timer_running = 0;
  22022. + }
  22023. +}
  22024. +
  22025. +static inline int
  22026. +need_resume(VCHIQ_STATE_T *state)
  22027. +{
  22028. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22029. + return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
  22030. + (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
  22031. + vchiq_videocore_wanted(state);
  22032. +}
  22033. +
  22034. +static int
  22035. +block_resume(VCHIQ_ARM_STATE_T *arm_state)
  22036. +{
  22037. + int status = VCHIQ_SUCCESS;
  22038. + const unsigned long timeout_val =
  22039. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
  22040. + int resume_count = 0;
  22041. +
  22042. + /* Allow any threads which were blocked by the last force suspend to
  22043. + * complete if they haven't already. Only give this one shot; if
  22044. + * blocked_count is incremented after blocked_blocker is completed
  22045. + * (which only happens when blocked_count hits 0) then those threads
  22046. + * will have to wait until next time around */
  22047. + if (arm_state->blocked_count) {
  22048. + INIT_COMPLETION(arm_state->blocked_blocker);
  22049. + write_unlock_bh(&arm_state->susp_res_lock);
  22050. + vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
  22051. + "blocked clients", __func__);
  22052. + if (wait_for_completion_interruptible_timeout(
  22053. + &arm_state->blocked_blocker, timeout_val)
  22054. + <= 0) {
  22055. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  22056. + "previously blocked clients failed" , __func__);
  22057. + status = VCHIQ_ERROR;
  22058. + write_lock_bh(&arm_state->susp_res_lock);
  22059. + goto out;
  22060. + }
  22061. + vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
  22062. + "clients resumed", __func__);
  22063. + write_lock_bh(&arm_state->susp_res_lock);
  22064. + }
  22065. +
  22066. + /* We need to wait for resume to complete if it's in process */
  22067. + while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
  22068. + arm_state->vc_resume_state > VC_RESUME_IDLE) {
  22069. + if (resume_count > 1) {
  22070. + status = VCHIQ_ERROR;
  22071. + vchiq_log_error(vchiq_susp_log_level, "%s waited too "
  22072. + "many times for resume" , __func__);
  22073. + goto out;
  22074. + }
  22075. + write_unlock_bh(&arm_state->susp_res_lock);
  22076. + vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
  22077. + __func__);
  22078. + if (wait_for_completion_interruptible_timeout(
  22079. + &arm_state->vc_resume_complete, timeout_val)
  22080. + <= 0) {
  22081. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  22082. + "resume failed (%s)", __func__,
  22083. + resume_state_names[arm_state->vc_resume_state +
  22084. + VC_RESUME_NUM_OFFSET]);
  22085. + status = VCHIQ_ERROR;
  22086. + write_lock_bh(&arm_state->susp_res_lock);
  22087. + goto out;
  22088. + }
  22089. + vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
  22090. + write_lock_bh(&arm_state->susp_res_lock);
  22091. + resume_count++;
  22092. + }
  22093. + INIT_COMPLETION(arm_state->resume_blocker);
  22094. + arm_state->resume_blocked = 1;
  22095. +
  22096. +out:
  22097. + return status;
  22098. +}
  22099. +
  22100. +static inline void
  22101. +unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
  22102. +{
  22103. + complete_all(&arm_state->resume_blocker);
  22104. + arm_state->resume_blocked = 0;
  22105. +}
  22106. +
  22107. +/* Initiate suspend via slot handler. Should be called with the write lock
  22108. + * held */
  22109. +VCHIQ_STATUS_T
  22110. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
  22111. +{
  22112. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  22113. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22114. +
  22115. + if (!arm_state)
  22116. + goto out;
  22117. +
  22118. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22119. + status = VCHIQ_SUCCESS;
  22120. +
  22121. +
  22122. + switch (arm_state->vc_suspend_state) {
  22123. + case VC_SUSPEND_REQUESTED:
  22124. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
  22125. + "requested", __func__);
  22126. + break;
  22127. + case VC_SUSPEND_IN_PROGRESS:
  22128. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
  22129. + "progress", __func__);
  22130. + break;
  22131. +
  22132. + default:
  22133. + /* We don't expect to be in other states, so log but continue
  22134. + * anyway */
  22135. + vchiq_log_error(vchiq_susp_log_level,
  22136. + "%s unexpected suspend state %s", __func__,
  22137. + suspend_state_names[arm_state->vc_suspend_state +
  22138. + VC_SUSPEND_NUM_OFFSET]);
  22139. + /* fall through */
  22140. + case VC_SUSPEND_REJECTED:
  22141. + case VC_SUSPEND_FAILED:
  22142. + /* Ensure any idle state actions have been run */
  22143. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  22144. + /* fall through */
  22145. + case VC_SUSPEND_IDLE:
  22146. + vchiq_log_info(vchiq_susp_log_level,
  22147. + "%s: suspending", __func__);
  22148. + set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
  22149. + /* kick the slot handler thread to initiate suspend */
  22150. + request_poll(state, NULL, 0);
  22151. + break;
  22152. + }
  22153. +
  22154. +out:
  22155. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  22156. + return status;
  22157. +}
  22158. +
  22159. +void
  22160. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
  22161. +{
  22162. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22163. + int susp = 0;
  22164. +
  22165. + if (!arm_state)
  22166. + goto out;
  22167. +
  22168. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22169. +
  22170. + write_lock_bh(&arm_state->susp_res_lock);
  22171. + if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
  22172. + arm_state->vc_resume_state == VC_RESUME_RESUMED) {
  22173. + set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
  22174. + susp = 1;
  22175. + }
  22176. + write_unlock_bh(&arm_state->susp_res_lock);
  22177. +
  22178. + if (susp)
  22179. + vchiq_platform_suspend(state);
  22180. +
  22181. +out:
  22182. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22183. + return;
  22184. +}
  22185. +
  22186. +
  22187. +static void
  22188. +output_timeout_error(VCHIQ_STATE_T *state)
  22189. +{
  22190. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22191. + char service_err[50] = "";
  22192. + int vc_use_count = arm_state->videocore_use_count;
  22193. + int active_services = state->unused_service;
  22194. + int i;
  22195. +
  22196. + if (!arm_state->videocore_use_count) {
  22197. + snprintf(service_err, 50, " Videocore usecount is 0");
  22198. + goto output_msg;
  22199. + }
  22200. + for (i = 0; i < active_services; i++) {
  22201. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  22202. + if (service_ptr && service_ptr->service_use_count &&
  22203. + (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
  22204. + snprintf(service_err, 50, " %c%c%c%c(%d) service has "
  22205. + "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
  22206. + service_ptr->base.fourcc),
  22207. + service_ptr->client_id,
  22208. + service_ptr->service_use_count,
  22209. + service_ptr->service_use_count ==
  22210. + vc_use_count ? "" : " (+ more)");
  22211. + break;
  22212. + }
  22213. + }
  22214. +
  22215. +output_msg:
  22216. + vchiq_log_error(vchiq_susp_log_level,
  22217. + "timed out waiting for vc suspend (%d).%s",
  22218. + arm_state->autosuspend_override, service_err);
  22219. +
  22220. +}
  22221. +
  22222. +/* Try to get videocore into suspended state, regardless of autosuspend state.
  22223. +** We don't actually force suspend, since videocore may get into a bad state
  22224. +** if we force suspend at a bad time. Instead, we wait for autosuspend to
  22225. +** determine a good point to suspend. If this doesn't happen within 100ms we
  22226. +** report failure.
  22227. +**
  22228. +** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
  22229. +** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
  22230. +*/
  22231. +VCHIQ_STATUS_T
  22232. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
  22233. +{
  22234. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22235. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  22236. + long rc = 0;
  22237. + int repeat = -1;
  22238. +
  22239. + if (!arm_state)
  22240. + goto out;
  22241. +
  22242. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22243. +
  22244. + write_lock_bh(&arm_state->susp_res_lock);
  22245. +
  22246. + status = block_resume(arm_state);
  22247. + if (status != VCHIQ_SUCCESS)
  22248. + goto unlock;
  22249. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  22250. + /* Already suspended - just block resume and exit */
  22251. + vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
  22252. + __func__);
  22253. + status = VCHIQ_SUCCESS;
  22254. + goto unlock;
  22255. + } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
  22256. + /* initiate suspend immediately in the case that we're waiting
  22257. + * for the timeout */
  22258. + stop_suspend_timer(arm_state);
  22259. + if (!vchiq_videocore_wanted(state)) {
  22260. + vchiq_log_info(vchiq_susp_log_level, "%s videocore "
  22261. + "idle, initiating suspend", __func__);
  22262. + status = vchiq_arm_vcsuspend(state);
  22263. + } else if (arm_state->autosuspend_override <
  22264. + FORCE_SUSPEND_FAIL_MAX) {
  22265. + vchiq_log_info(vchiq_susp_log_level, "%s letting "
  22266. + "videocore go idle", __func__);
  22267. + status = VCHIQ_SUCCESS;
  22268. + } else {
  22269. + vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
  22270. + "many times - attempting suspend", __func__);
  22271. + status = vchiq_arm_vcsuspend(state);
  22272. + }
  22273. + } else {
  22274. + vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
  22275. + "in progress - wait for completion", __func__);
  22276. + status = VCHIQ_SUCCESS;
  22277. + }
  22278. +
  22279. + /* Wait for suspend to happen due to system idle (not forced..) */
  22280. + if (status != VCHIQ_SUCCESS)
  22281. + goto unblock_resume;
  22282. +
  22283. + do {
  22284. + write_unlock_bh(&arm_state->susp_res_lock);
  22285. +
  22286. + rc = wait_for_completion_interruptible_timeout(
  22287. + &arm_state->vc_suspend_complete,
  22288. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
  22289. +
  22290. + write_lock_bh(&arm_state->susp_res_lock);
  22291. + if (rc < 0) {
  22292. + vchiq_log_warning(vchiq_susp_log_level, "%s "
  22293. + "interrupted waiting for suspend", __func__);
  22294. + status = VCHIQ_ERROR;
  22295. + goto unblock_resume;
  22296. + } else if (rc == 0) {
  22297. + if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
  22298. + /* Repeat timeout once if in progress */
  22299. + if (repeat < 0) {
  22300. + repeat = 1;
  22301. + continue;
  22302. + }
  22303. + }
  22304. + arm_state->autosuspend_override++;
  22305. + output_timeout_error(state);
  22306. +
  22307. + status = VCHIQ_RETRY;
  22308. + goto unblock_resume;
  22309. + }
  22310. + } while (0 < (repeat--));
  22311. +
  22312. + /* Check and report state in case we need to abort ARM suspend */
  22313. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
  22314. + status = VCHIQ_RETRY;
  22315. + vchiq_log_error(vchiq_susp_log_level,
  22316. + "%s videocore suspend failed (state %s)", __func__,
  22317. + suspend_state_names[arm_state->vc_suspend_state +
  22318. + VC_SUSPEND_NUM_OFFSET]);
  22319. + /* Reset the state only if it's still in an error state.
  22320. + * Something could have already initiated another suspend. */
  22321. + if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
  22322. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  22323. +
  22324. + goto unblock_resume;
  22325. + }
  22326. +
  22327. + /* successfully suspended - unlock and exit */
  22328. + goto unlock;
  22329. +
  22330. +unblock_resume:
  22331. + /* all error states need to unblock resume before exit */
  22332. + unblock_resume(arm_state);
  22333. +
  22334. +unlock:
  22335. + write_unlock_bh(&arm_state->susp_res_lock);
  22336. +
  22337. +out:
  22338. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  22339. + return status;
  22340. +}
  22341. +
  22342. +void
  22343. +vchiq_check_suspend(VCHIQ_STATE_T *state)
  22344. +{
  22345. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22346. +
  22347. + if (!arm_state)
  22348. + goto out;
  22349. +
  22350. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22351. +
  22352. + write_lock_bh(&arm_state->susp_res_lock);
  22353. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
  22354. + arm_state->first_connect &&
  22355. + !vchiq_videocore_wanted(state)) {
  22356. + vchiq_arm_vcsuspend(state);
  22357. + }
  22358. + write_unlock_bh(&arm_state->susp_res_lock);
  22359. +
  22360. +out:
  22361. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22362. + return;
  22363. +}
  22364. +
  22365. +
  22366. +int
  22367. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
  22368. +{
  22369. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22370. + int resume = 0;
  22371. + int ret = -1;
  22372. +
  22373. + if (!arm_state)
  22374. + goto out;
  22375. +
  22376. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22377. +
  22378. + write_lock_bh(&arm_state->susp_res_lock);
  22379. + unblock_resume(arm_state);
  22380. + resume = vchiq_check_resume(state);
  22381. + write_unlock_bh(&arm_state->susp_res_lock);
  22382. +
  22383. + if (resume) {
  22384. + if (wait_for_completion_interruptible(
  22385. + &arm_state->vc_resume_complete) < 0) {
  22386. + vchiq_log_error(vchiq_susp_log_level,
  22387. + "%s interrupted", __func__);
  22388. + /* failed, cannot accurately derive suspend
  22389. + * state, so exit early. */
  22390. + goto out;
  22391. + }
  22392. + }
  22393. +
  22394. + read_lock_bh(&arm_state->susp_res_lock);
  22395. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  22396. + vchiq_log_info(vchiq_susp_log_level,
  22397. + "%s: Videocore remains suspended", __func__);
  22398. + } else {
  22399. + vchiq_log_info(vchiq_susp_log_level,
  22400. + "%s: Videocore resumed", __func__);
  22401. + ret = 0;
  22402. + }
  22403. + read_unlock_bh(&arm_state->susp_res_lock);
  22404. +out:
  22405. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  22406. + return ret;
  22407. +}
  22408. +
  22409. +/* This function should be called with the write lock held */
  22410. +int
  22411. +vchiq_check_resume(VCHIQ_STATE_T *state)
  22412. +{
  22413. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22414. + int resume = 0;
  22415. +
  22416. + if (!arm_state)
  22417. + goto out;
  22418. +
  22419. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22420. +
  22421. + if (need_resume(state)) {
  22422. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  22423. + request_poll(state, NULL, 0);
  22424. + resume = 1;
  22425. + }
  22426. +
  22427. +out:
  22428. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22429. + return resume;
  22430. +}
  22431. +
  22432. +void
  22433. +vchiq_platform_check_resume(VCHIQ_STATE_T *state)
  22434. +{
  22435. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22436. + int res = 0;
  22437. +
  22438. + if (!arm_state)
  22439. + goto out;
  22440. +
  22441. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22442. +
  22443. + write_lock_bh(&arm_state->susp_res_lock);
  22444. + if (arm_state->wake_address == 0) {
  22445. + vchiq_log_info(vchiq_susp_log_level,
  22446. + "%s: already awake", __func__);
  22447. + goto unlock;
  22448. + }
  22449. + if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
  22450. + vchiq_log_info(vchiq_susp_log_level,
  22451. + "%s: already resuming", __func__);
  22452. + goto unlock;
  22453. + }
  22454. +
  22455. + if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
  22456. + set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
  22457. + res = 1;
  22458. + } else
  22459. + vchiq_log_trace(vchiq_susp_log_level,
  22460. + "%s: not resuming (resume state %s)", __func__,
  22461. + resume_state_names[arm_state->vc_resume_state +
  22462. + VC_RESUME_NUM_OFFSET]);
  22463. +
  22464. +unlock:
  22465. + write_unlock_bh(&arm_state->susp_res_lock);
  22466. +
  22467. + if (res)
  22468. + vchiq_platform_resume(state);
  22469. +
  22470. +out:
  22471. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22472. + return;
  22473. +
  22474. +}
  22475. +
  22476. +
  22477. +
  22478. +VCHIQ_STATUS_T
  22479. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  22480. + enum USE_TYPE_E use_type)
  22481. +{
  22482. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22483. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  22484. + char entity[16];
  22485. + int *entity_uc;
  22486. + int local_uc, local_entity_uc;
  22487. +
  22488. + if (!arm_state)
  22489. + goto out;
  22490. +
  22491. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22492. +
  22493. + if (use_type == USE_TYPE_VCHIQ) {
  22494. + sprintf(entity, "VCHIQ: ");
  22495. + entity_uc = &arm_state->peer_use_count;
  22496. + } else if (service) {
  22497. + sprintf(entity, "%c%c%c%c:%03d",
  22498. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  22499. + service->client_id);
  22500. + entity_uc = &service->service_use_count;
  22501. + } else {
  22502. + vchiq_log_error(vchiq_susp_log_level, "%s null service "
  22503. + "ptr", __func__);
  22504. + ret = VCHIQ_ERROR;
  22505. + goto out;
  22506. + }
  22507. +
  22508. + write_lock_bh(&arm_state->susp_res_lock);
  22509. + while (arm_state->resume_blocked) {
  22510. + /* If we call 'use' while force suspend is waiting for suspend,
  22511. + * then we're about to block the thread which the force is
  22512. + * waiting to complete, so we're bound to just time out. In this
  22513. + * case, set the suspend state such that the wait will be
  22514. + * canceled, so we can complete as quickly as possible. */
  22515. + if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
  22516. + VC_SUSPEND_IDLE) {
  22517. + set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
  22518. + break;
  22519. + }
  22520. + /* If suspend is already in progress then we need to block */
  22521. + if (!try_wait_for_completion(&arm_state->resume_blocker)) {
  22522. + /* Indicate that there are threads waiting on the resume
  22523. + * blocker. These need to be allowed to complete before
  22524. + * a _second_ call to force suspend can complete,
  22525. + * otherwise low priority threads might never actually
  22526. + * continue */
  22527. + arm_state->blocked_count++;
  22528. + write_unlock_bh(&arm_state->susp_res_lock);
  22529. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  22530. + "blocked - waiting...", __func__, entity);
  22531. + if (wait_for_completion_killable(
  22532. + &arm_state->resume_blocker) != 0) {
  22533. + vchiq_log_error(vchiq_susp_log_level, "%s %s "
  22534. + "wait for resume blocker interrupted",
  22535. + __func__, entity);
  22536. + ret = VCHIQ_ERROR;
  22537. + write_lock_bh(&arm_state->susp_res_lock);
  22538. + arm_state->blocked_count--;
  22539. + write_unlock_bh(&arm_state->susp_res_lock);
  22540. + goto out;
  22541. + }
  22542. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  22543. + "unblocked", __func__, entity);
  22544. + write_lock_bh(&arm_state->susp_res_lock);
  22545. + if (--arm_state->blocked_count == 0)
  22546. + complete_all(&arm_state->blocked_blocker);
  22547. + }
  22548. + }
  22549. +
  22550. + stop_suspend_timer(arm_state);
  22551. +
  22552. + local_uc = ++arm_state->videocore_use_count;
  22553. + local_entity_uc = ++(*entity_uc);
  22554. +
  22555. + /* If there's a pending request which hasn't yet been serviced then
  22556. + * just clear it. If we're past VC_SUSPEND_REQUESTED state then
  22557. + * vc_resume_complete will block until we either resume or fail to
  22558. + * suspend */
  22559. + if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
  22560. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  22561. +
  22562. + if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
  22563. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  22564. + vchiq_log_info(vchiq_susp_log_level,
  22565. + "%s %s count %d, state count %d",
  22566. + __func__, entity, local_entity_uc, local_uc);
  22567. + request_poll(state, NULL, 0);
  22568. + } else
  22569. + vchiq_log_trace(vchiq_susp_log_level,
  22570. + "%s %s count %d, state count %d",
  22571. + __func__, entity, *entity_uc, local_uc);
  22572. +
  22573. +
  22574. + write_unlock_bh(&arm_state->susp_res_lock);
  22575. +
  22576. + /* Completion is in a done state when we're not suspended, so this won't
  22577. + * block for the non-suspended case. */
  22578. + if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
  22579. + vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
  22580. + __func__, entity);
  22581. + if (wait_for_completion_killable(
  22582. + &arm_state->vc_resume_complete) != 0) {
  22583. + vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
  22584. + "resume interrupted", __func__, entity);
  22585. + ret = VCHIQ_ERROR;
  22586. + goto out;
  22587. + }
  22588. + vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
  22589. + entity);
  22590. + }
  22591. +
  22592. + if (ret == VCHIQ_SUCCESS) {
  22593. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  22594. + long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
  22595. + while (ack_cnt && (status == VCHIQ_SUCCESS)) {
  22596. + /* Send the use notify to videocore */
  22597. + status = vchiq_send_remote_use_active(state);
  22598. + if (status == VCHIQ_SUCCESS)
  22599. + ack_cnt--;
  22600. + else
  22601. + atomic_add(ack_cnt,
  22602. + &arm_state->ka_use_ack_count);
  22603. + }
  22604. + }
  22605. +
  22606. +out:
  22607. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  22608. + return ret;
  22609. +}
  22610. +
  22611. +VCHIQ_STATUS_T
  22612. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
  22613. +{
  22614. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22615. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  22616. + char entity[16];
  22617. + int *entity_uc;
  22618. + int local_uc, local_entity_uc;
  22619. +
  22620. + if (!arm_state)
  22621. + goto out;
  22622. +
  22623. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22624. +
  22625. + if (service) {
  22626. + sprintf(entity, "%c%c%c%c:%03d",
  22627. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  22628. + service->client_id);
  22629. + entity_uc = &service->service_use_count;
  22630. + } else {
  22631. + sprintf(entity, "PEER: ");
  22632. + entity_uc = &arm_state->peer_use_count;
  22633. + }
  22634. +
  22635. + write_lock_bh(&arm_state->susp_res_lock);
  22636. + if (!arm_state->videocore_use_count || !(*entity_uc)) {
  22637. + /* Don't use BUG_ON - don't allow user thread to crash kernel */
  22638. + WARN_ON(!arm_state->videocore_use_count);
  22639. + WARN_ON(!(*entity_uc));
  22640. + ret = VCHIQ_ERROR;
  22641. + goto unlock;
  22642. + }
  22643. + local_uc = --arm_state->videocore_use_count;
  22644. + local_entity_uc = --(*entity_uc);
  22645. +
  22646. + if (!vchiq_videocore_wanted(state)) {
  22647. + if (vchiq_platform_use_suspend_timer() &&
  22648. + !arm_state->resume_blocked) {
  22649. + /* Only use the timer if we're not trying to force
  22650. + * suspend (=> resume_blocked) */
  22651. + start_suspend_timer(arm_state);
  22652. + } else {
  22653. + vchiq_log_info(vchiq_susp_log_level,
  22654. + "%s %s count %d, state count %d - suspending",
  22655. + __func__, entity, *entity_uc,
  22656. + arm_state->videocore_use_count);
  22657. + vchiq_arm_vcsuspend(state);
  22658. + }
  22659. + } else
  22660. + vchiq_log_trace(vchiq_susp_log_level,
  22661. + "%s %s count %d, state count %d",
  22662. + __func__, entity, *entity_uc,
  22663. + arm_state->videocore_use_count);
  22664. +
  22665. +unlock:
  22666. + write_unlock_bh(&arm_state->susp_res_lock);
  22667. +
  22668. +out:
  22669. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  22670. + return ret;
  22671. +}
  22672. +
  22673. +void
  22674. +vchiq_on_remote_use(VCHIQ_STATE_T *state)
  22675. +{
  22676. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22677. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22678. + atomic_inc(&arm_state->ka_use_count);
  22679. + complete(&arm_state->ka_evt);
  22680. +}
  22681. +
  22682. +void
  22683. +vchiq_on_remote_release(VCHIQ_STATE_T *state)
  22684. +{
  22685. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22686. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22687. + atomic_inc(&arm_state->ka_release_count);
  22688. + complete(&arm_state->ka_evt);
  22689. +}
  22690. +
  22691. +VCHIQ_STATUS_T
  22692. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
  22693. +{
  22694. + return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
  22695. +}
  22696. +
  22697. +VCHIQ_STATUS_T
  22698. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
  22699. +{
  22700. + return vchiq_release_internal(service->state, service);
  22701. +}
  22702. +
  22703. +static void suspend_timer_callback(unsigned long context)
  22704. +{
  22705. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *)context;
  22706. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22707. + if (!arm_state)
  22708. + goto out;
  22709. + vchiq_log_info(vchiq_susp_log_level,
  22710. + "%s - suspend timer expired - check suspend", __func__);
  22711. + vchiq_check_suspend(state);
  22712. +out:
  22713. + return;
  22714. +}
  22715. +
  22716. +VCHIQ_STATUS_T
  22717. +vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
  22718. +{
  22719. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22720. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22721. + if (service) {
  22722. + ret = vchiq_use_internal(service->state, service,
  22723. + USE_TYPE_SERVICE_NO_RESUME);
  22724. + unlock_service(service);
  22725. + }
  22726. + return ret;
  22727. +}
  22728. +
  22729. +VCHIQ_STATUS_T
  22730. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
  22731. +{
  22732. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22733. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22734. + if (service) {
  22735. + ret = vchiq_use_internal(service->state, service,
  22736. + USE_TYPE_SERVICE);
  22737. + unlock_service(service);
  22738. + }
  22739. + return ret;
  22740. +}
  22741. +
  22742. +VCHIQ_STATUS_T
  22743. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
  22744. +{
  22745. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22746. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22747. + if (service) {
  22748. + ret = vchiq_release_internal(service->state, service);
  22749. + unlock_service(service);
  22750. + }
  22751. + return ret;
  22752. +}
  22753. +
  22754. +void
  22755. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
  22756. +{
  22757. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22758. + int i, j = 0;
  22759. + /* Only dump 64 services */
  22760. + static const int local_max_services = 64;
  22761. + /* If there's more than 64 services, only dump ones with
  22762. + * non-zero counts */
  22763. + int only_nonzero = 0;
  22764. + static const char *nz = "<-- preventing suspend";
  22765. +
  22766. + enum vc_suspend_status vc_suspend_state;
  22767. + enum vc_resume_status vc_resume_state;
  22768. + int peer_count;
  22769. + int vc_use_count;
  22770. + int active_services;
  22771. + struct service_data_struct {
  22772. + int fourcc;
  22773. + int clientid;
  22774. + int use_count;
  22775. + } service_data[local_max_services];
  22776. +
  22777. + if (!arm_state)
  22778. + return;
  22779. +
  22780. + read_lock_bh(&arm_state->susp_res_lock);
  22781. + vc_suspend_state = arm_state->vc_suspend_state;
  22782. + vc_resume_state = arm_state->vc_resume_state;
  22783. + peer_count = arm_state->peer_use_count;
  22784. + vc_use_count = arm_state->videocore_use_count;
  22785. + active_services = state->unused_service;
  22786. + if (active_services > local_max_services)
  22787. + only_nonzero = 1;
  22788. +
  22789. + for (i = 0; (i < active_services) && (j < local_max_services); i++) {
  22790. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  22791. + if (!service_ptr)
  22792. + continue;
  22793. +
  22794. + if (only_nonzero && !service_ptr->service_use_count)
  22795. + continue;
  22796. +
  22797. + if (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE) {
  22798. + service_data[j].fourcc = service_ptr->base.fourcc;
  22799. + service_data[j].clientid = service_ptr->client_id;
  22800. + service_data[j++].use_count = service_ptr->
  22801. + service_use_count;
  22802. + }
  22803. + }
  22804. +
  22805. + read_unlock_bh(&arm_state->susp_res_lock);
  22806. +
  22807. + vchiq_log_warning(vchiq_susp_log_level,
  22808. + "-- Videcore suspend state: %s --",
  22809. + suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
  22810. + vchiq_log_warning(vchiq_susp_log_level,
  22811. + "-- Videcore resume state: %s --",
  22812. + resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
  22813. +
  22814. + if (only_nonzero)
  22815. + vchiq_log_warning(vchiq_susp_log_level, "Too many active "
  22816. + "services (%d). Only dumping up to first %d services "
  22817. + "with non-zero use-count", active_services,
  22818. + local_max_services);
  22819. +
  22820. + for (i = 0; i < j; i++) {
  22821. + vchiq_log_warning(vchiq_susp_log_level,
  22822. + "----- %c%c%c%c:%d service count %d %s",
  22823. + VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
  22824. + service_data[i].clientid,
  22825. + service_data[i].use_count,
  22826. + service_data[i].use_count ? nz : "");
  22827. + }
  22828. + vchiq_log_warning(vchiq_susp_log_level,
  22829. + "----- VCHIQ use count count %d", peer_count);
  22830. + vchiq_log_warning(vchiq_susp_log_level,
  22831. + "--- Overall vchiq instance use count %d", vc_use_count);
  22832. +
  22833. + vchiq_dump_platform_use_state(state);
  22834. +}
  22835. +
  22836. +VCHIQ_STATUS_T
  22837. +vchiq_check_service(VCHIQ_SERVICE_T *service)
  22838. +{
  22839. + VCHIQ_ARM_STATE_T *arm_state;
  22840. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22841. +
  22842. + if (!service || !service->state)
  22843. + goto out;
  22844. +
  22845. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22846. +
  22847. + arm_state = vchiq_platform_get_arm_state(service->state);
  22848. +
  22849. + read_lock_bh(&arm_state->susp_res_lock);
  22850. + if (service->service_use_count)
  22851. + ret = VCHIQ_SUCCESS;
  22852. + read_unlock_bh(&arm_state->susp_res_lock);
  22853. +
  22854. + if (ret == VCHIQ_ERROR) {
  22855. + vchiq_log_error(vchiq_susp_log_level,
  22856. + "%s ERROR - %c%c%c%c:%d service count %d, "
  22857. + "state count %d, videocore suspend state %s", __func__,
  22858. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  22859. + service->client_id, service->service_use_count,
  22860. + arm_state->videocore_use_count,
  22861. + suspend_state_names[arm_state->vc_suspend_state +
  22862. + VC_SUSPEND_NUM_OFFSET]);
  22863. + vchiq_dump_service_use_state(service->state);
  22864. + }
  22865. +out:
  22866. + return ret;
  22867. +}
  22868. +
  22869. +/* stub functions */
  22870. +void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
  22871. +{
  22872. + (void)state;
  22873. +}
  22874. +
  22875. +void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  22876. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
  22877. +{
  22878. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22879. + vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
  22880. + get_conn_state_name(oldstate), get_conn_state_name(newstate));
  22881. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
  22882. + write_lock_bh(&arm_state->susp_res_lock);
  22883. + if (!arm_state->first_connect) {
  22884. + char threadname[10];
  22885. + arm_state->first_connect = 1;
  22886. + write_unlock_bh(&arm_state->susp_res_lock);
  22887. + snprintf(threadname, sizeof(threadname), "VCHIQka-%d",
  22888. + state->id);
  22889. + arm_state->ka_thread = kthread_create(
  22890. + &vchiq_keepalive_thread_func,
  22891. + (void *)state,
  22892. + threadname);
  22893. + if (arm_state->ka_thread == NULL) {
  22894. + vchiq_log_error(vchiq_susp_log_level,
  22895. + "vchiq: FATAL: couldn't create thread %s",
  22896. + threadname);
  22897. + } else {
  22898. + wake_up_process(arm_state->ka_thread);
  22899. + }
  22900. + } else
  22901. + write_unlock_bh(&arm_state->susp_res_lock);
  22902. + }
  22903. +}
  22904. +
  22905. +
  22906. +/****************************************************************************
  22907. +*
  22908. +* vchiq_init - called when the module is loaded.
  22909. +*
  22910. +***************************************************************************/
  22911. +
  22912. +static int __init
  22913. +vchiq_init(void)
  22914. +{
  22915. + int err;
  22916. + void *ptr_err;
  22917. +
  22918. + /* create proc entries */
  22919. + err = vchiq_proc_init();
  22920. + if (err != 0)
  22921. + goto failed_proc_init;
  22922. +
  22923. + err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
  22924. + if (err != 0) {
  22925. + vchiq_log_error(vchiq_arm_log_level,
  22926. + "Unable to allocate device number");
  22927. + goto failed_alloc_chrdev;
  22928. + }
  22929. + cdev_init(&vchiq_cdev, &vchiq_fops);
  22930. + vchiq_cdev.owner = THIS_MODULE;
  22931. + err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
  22932. + if (err != 0) {
  22933. + vchiq_log_error(vchiq_arm_log_level,
  22934. + "Unable to register device");
  22935. + goto failed_cdev_add;
  22936. + }
  22937. +
  22938. + /* create sysfs entries */
  22939. + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
  22940. + ptr_err = vchiq_class;
  22941. + if (IS_ERR(ptr_err))
  22942. + goto failed_class_create;
  22943. +
  22944. + vchiq_dev = device_create(vchiq_class, NULL,
  22945. + vchiq_devid, NULL, "vchiq");
  22946. + ptr_err = vchiq_dev;
  22947. + if (IS_ERR(ptr_err))
  22948. + goto failed_device_create;
  22949. +
  22950. + err = vchiq_platform_init(&g_state);
  22951. + if (err != 0)
  22952. + goto failed_platform_init;
  22953. +
  22954. + vchiq_log_info(vchiq_arm_log_level,
  22955. + "vchiq: initialised - version %d (min %d), device %d.%d",
  22956. + VCHIQ_VERSION, VCHIQ_VERSION_MIN,
  22957. + MAJOR(vchiq_devid), MINOR(vchiq_devid));
  22958. +
  22959. + return 0;
  22960. +
  22961. +failed_platform_init:
  22962. + device_destroy(vchiq_class, vchiq_devid);
  22963. +failed_device_create:
  22964. + class_destroy(vchiq_class);
  22965. +failed_class_create:
  22966. + cdev_del(&vchiq_cdev);
  22967. + err = PTR_ERR(ptr_err);
  22968. +failed_cdev_add:
  22969. + unregister_chrdev_region(vchiq_devid, 1);
  22970. +failed_alloc_chrdev:
  22971. + vchiq_proc_deinit();
  22972. +failed_proc_init:
  22973. + vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
  22974. + return err;
  22975. +}
  22976. +
  22977. +static int vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
  22978. +{
  22979. + VCHIQ_SERVICE_T *service;
  22980. + int use_count = 0, i;
  22981. + i = 0;
  22982. + while ((service = next_service_by_instance(instance->state,
  22983. + instance, &i)) != NULL) {
  22984. + use_count += service->service_use_count;
  22985. + unlock_service(service);
  22986. + }
  22987. + return use_count;
  22988. +}
  22989. +
  22990. +/* read the per-process use-count */
  22991. +static int proc_read_use_count(char *page, char **start,
  22992. + off_t off, int count,
  22993. + int *eof, void *data)
  22994. +{
  22995. + VCHIQ_INSTANCE_T instance = data;
  22996. + int len, use_count;
  22997. +
  22998. + use_count = vchiq_instance_get_use_count(instance);
  22999. + len = snprintf(page+off, count, "%d\n", use_count);
  23000. +
  23001. + return len;
  23002. +}
  23003. +
  23004. +/* add an instance (process) to the proc entries */
  23005. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance)
  23006. +{
  23007. +#if 1
  23008. + return 0;
  23009. +#else
  23010. + char pidstr[32];
  23011. + struct proc_dir_entry *top, *use_count;
  23012. + struct proc_dir_entry *clients = vchiq_clients_top();
  23013. + int pid = instance->pid;
  23014. +
  23015. + snprintf(pidstr, sizeof(pidstr), "%d", pid);
  23016. + top = proc_mkdir(pidstr, clients);
  23017. + if (!top)
  23018. + goto fail_top;
  23019. +
  23020. + use_count = create_proc_read_entry("use_count",
  23021. + 0444, top,
  23022. + proc_read_use_count,
  23023. + instance);
  23024. + if (!use_count)
  23025. + goto fail_use_count;
  23026. +
  23027. + instance->proc_entry = top;
  23028. +
  23029. + return 0;
  23030. +
  23031. +fail_use_count:
  23032. + remove_proc_entry(top->name, clients);
  23033. +fail_top:
  23034. + return -ENOMEM;
  23035. +#endif
  23036. +}
  23037. +
  23038. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance)
  23039. +{
  23040. +#if 0
  23041. + struct proc_dir_entry *clients = vchiq_clients_top();
  23042. + remove_proc_entry("use_count", instance->proc_entry);
  23043. + remove_proc_entry(instance->proc_entry->name, clients);
  23044. +#endif
  23045. +}
  23046. +
  23047. +/****************************************************************************
  23048. +*
  23049. +* vchiq_exit - called when the module is unloaded.
  23050. +*
  23051. +***************************************************************************/
  23052. +
  23053. +static void __exit
  23054. +vchiq_exit(void)
  23055. +{
  23056. + vchiq_platform_exit(&g_state);
  23057. + device_destroy(vchiq_class, vchiq_devid);
  23058. + class_destroy(vchiq_class);
  23059. + cdev_del(&vchiq_cdev);
  23060. + unregister_chrdev_region(vchiq_devid, 1);
  23061. +}
  23062. +
  23063. +module_init(vchiq_init);
  23064. +module_exit(vchiq_exit);
  23065. +MODULE_LICENSE("GPL");
  23066. +MODULE_AUTHOR("Broadcom Corporation");
  23067. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h
  23068. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 1970-01-01 01:00:00.000000000 +0100
  23069. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 2014-04-24 15:35:02.893551516 +0200
  23070. @@ -0,0 +1,212 @@
  23071. +/**
  23072. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23073. + *
  23074. + * Redistribution and use in source and binary forms, with or without
  23075. + * modification, are permitted provided that the following conditions
  23076. + * are met:
  23077. + * 1. Redistributions of source code must retain the above copyright
  23078. + * notice, this list of conditions, and the following disclaimer,
  23079. + * without modification.
  23080. + * 2. Redistributions in binary form must reproduce the above copyright
  23081. + * notice, this list of conditions and the following disclaimer in the
  23082. + * documentation and/or other materials provided with the distribution.
  23083. + * 3. The names of the above-listed copyright holders may not be used
  23084. + * to endorse or promote products derived from this software without
  23085. + * specific prior written permission.
  23086. + *
  23087. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23088. + * GNU General Public License ("GPL") version 2, as published by the Free
  23089. + * Software Foundation.
  23090. + *
  23091. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23092. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23093. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23094. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23095. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23096. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23097. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23098. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23099. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23100. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23101. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23102. + */
  23103. +
  23104. +#ifndef VCHIQ_ARM_H
  23105. +#define VCHIQ_ARM_H
  23106. +
  23107. +#include <linux/mutex.h>
  23108. +#include <linux/semaphore.h>
  23109. +#include <linux/atomic.h>
  23110. +#include "vchiq_core.h"
  23111. +
  23112. +
  23113. +enum vc_suspend_status {
  23114. + VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
  23115. + VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
  23116. + VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
  23117. + VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
  23118. + VC_SUSPEND_REQUESTED, /* User has requested suspend */
  23119. + VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
  23120. + VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
  23121. +};
  23122. +
  23123. +enum vc_resume_status {
  23124. + VC_RESUME_FAILED = -1, /* Videocore resume failed */
  23125. + VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
  23126. + VC_RESUME_REQUESTED, /* User has requested resume */
  23127. + VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
  23128. + VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
  23129. +};
  23130. +
  23131. +
  23132. +enum USE_TYPE_E {
  23133. + USE_TYPE_SERVICE,
  23134. + USE_TYPE_SERVICE_NO_RESUME,
  23135. + USE_TYPE_VCHIQ
  23136. +};
  23137. +
  23138. +
  23139. +
  23140. +typedef struct vchiq_arm_state_struct {
  23141. + /* Keepalive-related data */
  23142. + struct task_struct *ka_thread;
  23143. + struct completion ka_evt;
  23144. + atomic_t ka_use_count;
  23145. + atomic_t ka_use_ack_count;
  23146. + atomic_t ka_release_count;
  23147. +
  23148. + struct completion vc_suspend_complete;
  23149. + struct completion vc_resume_complete;
  23150. +
  23151. + rwlock_t susp_res_lock;
  23152. + enum vc_suspend_status vc_suspend_state;
  23153. + enum vc_resume_status vc_resume_state;
  23154. +
  23155. + unsigned int wake_address;
  23156. +
  23157. + struct timer_list suspend_timer;
  23158. + int suspend_timer_timeout;
  23159. + int suspend_timer_running;
  23160. +
  23161. + /* Global use count for videocore.
  23162. + ** This is equal to the sum of the use counts for all services. When
  23163. + ** this hits zero the videocore suspend procedure will be initiated.
  23164. + */
  23165. + int videocore_use_count;
  23166. +
  23167. + /* Use count to track requests from videocore peer.
  23168. + ** This use count is not associated with a service, so needs to be
  23169. + ** tracked separately with the state.
  23170. + */
  23171. + int peer_use_count;
  23172. +
  23173. + /* Flag to indicate whether resume is blocked. This happens when the
  23174. + ** ARM is suspending
  23175. + */
  23176. + struct completion resume_blocker;
  23177. + int resume_blocked;
  23178. + struct completion blocked_blocker;
  23179. + int blocked_count;
  23180. +
  23181. + int autosuspend_override;
  23182. +
  23183. + /* Flag to indicate that the first vchiq connect has made it through.
  23184. + ** This means that both sides should be fully ready, and we should
  23185. + ** be able to suspend after this point.
  23186. + */
  23187. + int first_connect;
  23188. +
  23189. + unsigned long long suspend_start_time;
  23190. + unsigned long long sleep_start_time;
  23191. + unsigned long long resume_start_time;
  23192. + unsigned long long last_wake_time;
  23193. +
  23194. +} VCHIQ_ARM_STATE_T;
  23195. +
  23196. +extern int vchiq_arm_log_level;
  23197. +extern int vchiq_susp_log_level;
  23198. +
  23199. +extern int __init
  23200. +vchiq_platform_init(VCHIQ_STATE_T *state);
  23201. +
  23202. +extern void __exit
  23203. +vchiq_platform_exit(VCHIQ_STATE_T *state);
  23204. +
  23205. +extern VCHIQ_STATE_T *
  23206. +vchiq_get_state(void);
  23207. +
  23208. +extern VCHIQ_STATUS_T
  23209. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
  23210. +
  23211. +extern VCHIQ_STATUS_T
  23212. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
  23213. +
  23214. +extern int
  23215. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
  23216. +
  23217. +extern VCHIQ_STATUS_T
  23218. +vchiq_arm_vcresume(VCHIQ_STATE_T *state);
  23219. +
  23220. +extern VCHIQ_STATUS_T
  23221. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
  23222. +
  23223. +extern int
  23224. +vchiq_check_resume(VCHIQ_STATE_T *state);
  23225. +
  23226. +extern void
  23227. +vchiq_check_suspend(VCHIQ_STATE_T *state);
  23228. +
  23229. +extern VCHIQ_STATUS_T
  23230. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
  23231. +
  23232. +extern VCHIQ_STATUS_T
  23233. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle);
  23234. +
  23235. +extern VCHIQ_STATUS_T
  23236. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  23237. +
  23238. +extern VCHIQ_STATUS_T
  23239. +vchiq_platform_suspend(VCHIQ_STATE_T *state);
  23240. +
  23241. +extern int
  23242. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
  23243. +
  23244. +extern int
  23245. +vchiq_platform_use_suspend_timer(void);
  23246. +
  23247. +extern void
  23248. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
  23249. +
  23250. +extern void
  23251. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
  23252. +
  23253. +extern VCHIQ_ARM_STATE_T*
  23254. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
  23255. +
  23256. +extern int
  23257. +vchiq_videocore_wanted(VCHIQ_STATE_T *state);
  23258. +
  23259. +extern VCHIQ_STATUS_T
  23260. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  23261. + enum USE_TYPE_E use_type);
  23262. +extern VCHIQ_STATUS_T
  23263. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
  23264. +
  23265. +void
  23266. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  23267. + enum vc_suspend_status new_state);
  23268. +
  23269. +void
  23270. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  23271. + enum vc_resume_status new_state);
  23272. +
  23273. +void
  23274. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
  23275. +
  23276. +extern int vchiq_proc_init(void);
  23277. +extern void vchiq_proc_deinit(void);
  23278. +extern struct proc_dir_entry *vchiq_proc_top(void);
  23279. +extern struct proc_dir_entry *vchiq_clients_top(void);
  23280. +
  23281. +
  23282. +#endif /* VCHIQ_ARM_H */
  23283. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h
  23284. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 1970-01-01 01:00:00.000000000 +0100
  23285. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 2014-04-24 15:35:02.893551516 +0200
  23286. @@ -0,0 +1,37 @@
  23287. +/**
  23288. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23289. + *
  23290. + * Redistribution and use in source and binary forms, with or without
  23291. + * modification, are permitted provided that the following conditions
  23292. + * are met:
  23293. + * 1. Redistributions of source code must retain the above copyright
  23294. + * notice, this list of conditions, and the following disclaimer,
  23295. + * without modification.
  23296. + * 2. Redistributions in binary form must reproduce the above copyright
  23297. + * notice, this list of conditions and the following disclaimer in the
  23298. + * documentation and/or other materials provided with the distribution.
  23299. + * 3. The names of the above-listed copyright holders may not be used
  23300. + * to endorse or promote products derived from this software without
  23301. + * specific prior written permission.
  23302. + *
  23303. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23304. + * GNU General Public License ("GPL") version 2, as published by the Free
  23305. + * Software Foundation.
  23306. + *
  23307. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23308. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23309. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23310. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23311. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23312. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23313. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23314. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23315. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23316. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23317. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23318. + */
  23319. +
  23320. +const char *vchiq_get_build_hostname(void);
  23321. +const char *vchiq_get_build_version(void);
  23322. +const char *vchiq_get_build_time(void);
  23323. +const char *vchiq_get_build_date(void);
  23324. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h
  23325. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 1970-01-01 01:00:00.000000000 +0100
  23326. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 2014-04-24 15:35:02.893551516 +0200
  23327. @@ -0,0 +1,60 @@
  23328. +/**
  23329. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23330. + *
  23331. + * Redistribution and use in source and binary forms, with or without
  23332. + * modification, are permitted provided that the following conditions
  23333. + * are met:
  23334. + * 1. Redistributions of source code must retain the above copyright
  23335. + * notice, this list of conditions, and the following disclaimer,
  23336. + * without modification.
  23337. + * 2. Redistributions in binary form must reproduce the above copyright
  23338. + * notice, this list of conditions and the following disclaimer in the
  23339. + * documentation and/or other materials provided with the distribution.
  23340. + * 3. The names of the above-listed copyright holders may not be used
  23341. + * to endorse or promote products derived from this software without
  23342. + * specific prior written permission.
  23343. + *
  23344. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23345. + * GNU General Public License ("GPL") version 2, as published by the Free
  23346. + * Software Foundation.
  23347. + *
  23348. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23349. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23350. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23351. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23352. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23353. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23354. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23355. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23356. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23357. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23358. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23359. + */
  23360. +
  23361. +#ifndef VCHIQ_CFG_H
  23362. +#define VCHIQ_CFG_H
  23363. +
  23364. +#define VCHIQ_MAGIC VCHIQ_MAKE_FOURCC('V', 'C', 'H', 'I')
  23365. +/* The version of VCHIQ - change with any non-trivial change */
  23366. +#define VCHIQ_VERSION 6
  23367. +/* The minimum compatible version - update to match VCHIQ_VERSION with any
  23368. +** incompatible change */
  23369. +#define VCHIQ_VERSION_MIN 3
  23370. +
  23371. +#define VCHIQ_MAX_STATES 1
  23372. +#define VCHIQ_MAX_SERVICES 4096
  23373. +#define VCHIQ_MAX_SLOTS 128
  23374. +#define VCHIQ_MAX_SLOTS_PER_SIDE 64
  23375. +
  23376. +#define VCHIQ_NUM_CURRENT_BULKS 32
  23377. +#define VCHIQ_NUM_SERVICE_BULKS 4
  23378. +
  23379. +#ifndef VCHIQ_ENABLE_DEBUG
  23380. +#define VCHIQ_ENABLE_DEBUG 1
  23381. +#endif
  23382. +
  23383. +#ifndef VCHIQ_ENABLE_STATS
  23384. +#define VCHIQ_ENABLE_STATS 1
  23385. +#endif
  23386. +
  23387. +#endif /* VCHIQ_CFG_H */
  23388. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
  23389. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 1970-01-01 01:00:00.000000000 +0100
  23390. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 2014-04-24 15:35:02.893551516 +0200
  23391. @@ -0,0 +1,119 @@
  23392. +/**
  23393. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23394. + *
  23395. + * Redistribution and use in source and binary forms, with or without
  23396. + * modification, are permitted provided that the following conditions
  23397. + * are met:
  23398. + * 1. Redistributions of source code must retain the above copyright
  23399. + * notice, this list of conditions, and the following disclaimer,
  23400. + * without modification.
  23401. + * 2. Redistributions in binary form must reproduce the above copyright
  23402. + * notice, this list of conditions and the following disclaimer in the
  23403. + * documentation and/or other materials provided with the distribution.
  23404. + * 3. The names of the above-listed copyright holders may not be used
  23405. + * to endorse or promote products derived from this software without
  23406. + * specific prior written permission.
  23407. + *
  23408. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23409. + * GNU General Public License ("GPL") version 2, as published by the Free
  23410. + * Software Foundation.
  23411. + *
  23412. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23413. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23414. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23415. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23416. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23417. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23418. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23419. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23420. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23421. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23422. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23423. + */
  23424. +
  23425. +#include "vchiq_connected.h"
  23426. +#include "vchiq_core.h"
  23427. +#include <linux/module.h>
  23428. +#include <linux/mutex.h>
  23429. +
  23430. +#define MAX_CALLBACKS 10
  23431. +
  23432. +static int g_connected;
  23433. +static int g_num_deferred_callbacks;
  23434. +static VCHIQ_CONNECTED_CALLBACK_T g_deferred_callback[MAX_CALLBACKS];
  23435. +static int g_once_init;
  23436. +static struct mutex g_connected_mutex;
  23437. +
  23438. +/****************************************************************************
  23439. +*
  23440. +* Function to initialize our lock.
  23441. +*
  23442. +***************************************************************************/
  23443. +
  23444. +static void connected_init(void)
  23445. +{
  23446. + if (!g_once_init) {
  23447. + mutex_init(&g_connected_mutex);
  23448. + g_once_init = 1;
  23449. + }
  23450. +}
  23451. +
  23452. +/****************************************************************************
  23453. +*
  23454. +* This function is used to defer initialization until the vchiq stack is
  23455. +* initialized. If the stack is already initialized, then the callback will
  23456. +* be made immediately, otherwise it will be deferred until
  23457. +* vchiq_call_connected_callbacks is called.
  23458. +*
  23459. +***************************************************************************/
  23460. +
  23461. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
  23462. +{
  23463. + connected_init();
  23464. +
  23465. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  23466. + return;
  23467. +
  23468. + if (g_connected)
  23469. + /* We're already connected. Call the callback immediately. */
  23470. +
  23471. + callback();
  23472. + else {
  23473. + if (g_num_deferred_callbacks >= MAX_CALLBACKS)
  23474. + vchiq_log_error(vchiq_core_log_level,
  23475. + "There already %d callback registered - "
  23476. + "please increase MAX_CALLBACKS",
  23477. + g_num_deferred_callbacks);
  23478. + else {
  23479. + g_deferred_callback[g_num_deferred_callbacks] =
  23480. + callback;
  23481. + g_num_deferred_callbacks++;
  23482. + }
  23483. + }
  23484. + mutex_unlock(&g_connected_mutex);
  23485. +}
  23486. +
  23487. +/****************************************************************************
  23488. +*
  23489. +* This function is called by the vchiq stack once it has been connected to
  23490. +* the videocore and clients can start to use the stack.
  23491. +*
  23492. +***************************************************************************/
  23493. +
  23494. +void vchiq_call_connected_callbacks(void)
  23495. +{
  23496. + int i;
  23497. +
  23498. + connected_init();
  23499. +
  23500. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  23501. + return;
  23502. +
  23503. + for (i = 0; i < g_num_deferred_callbacks; i++)
  23504. + g_deferred_callback[i]();
  23505. +
  23506. + g_num_deferred_callbacks = 0;
  23507. + g_connected = 1;
  23508. + mutex_unlock(&g_connected_mutex);
  23509. +}
  23510. +EXPORT_SYMBOL(vchiq_add_connected_callback);
  23511. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h
  23512. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 1970-01-01 01:00:00.000000000 +0100
  23513. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 2014-04-24 16:04:36.831095364 +0200
  23514. @@ -0,0 +1,50 @@
  23515. +/**
  23516. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23517. + *
  23518. + * Redistribution and use in source and binary forms, with or without
  23519. + * modification, are permitted provided that the following conditions
  23520. + * are met:
  23521. + * 1. Redistributions of source code must retain the above copyright
  23522. + * notice, this list of conditions, and the following disclaimer,
  23523. + * without modification.
  23524. + * 2. Redistributions in binary form must reproduce the above copyright
  23525. + * notice, this list of conditions and the following disclaimer in the
  23526. + * documentation and/or other materials provided with the distribution.
  23527. + * 3. The names of the above-listed copyright holders may not be used
  23528. + * to endorse or promote products derived from this software without
  23529. + * specific prior written permission.
  23530. + *
  23531. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23532. + * GNU General Public License ("GPL") version 2, as published by the Free
  23533. + * Software Foundation.
  23534. + *
  23535. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23536. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23537. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23538. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23539. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23540. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23541. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23542. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23543. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23544. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23545. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23546. + */
  23547. +
  23548. +#ifndef VCHIQ_CONNECTED_H
  23549. +#define VCHIQ_CONNECTED_H
  23550. +
  23551. +/* ---- Include Files ----------------------------------------------------- */
  23552. +
  23553. +/* ---- Constants and Types ---------------------------------------------- */
  23554. +
  23555. +typedef void (*VCHIQ_CONNECTED_CALLBACK_T)(void);
  23556. +
  23557. +/* ---- Variable Externs ------------------------------------------------- */
  23558. +
  23559. +/* ---- Function Prototypes ---------------------------------------------- */
  23560. +
  23561. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback);
  23562. +void vchiq_call_connected_callbacks(void);
  23563. +
  23564. +#endif /* VCHIQ_CONNECTED_H */
  23565. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
  23566. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 1970-01-01 01:00:00.000000000 +0100
  23567. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 2014-04-24 15:35:02.893551516 +0200
  23568. @@ -0,0 +1,3824 @@
  23569. +/**
  23570. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23571. + *
  23572. + * Redistribution and use in source and binary forms, with or without
  23573. + * modification, are permitted provided that the following conditions
  23574. + * are met:
  23575. + * 1. Redistributions of source code must retain the above copyright
  23576. + * notice, this list of conditions, and the following disclaimer,
  23577. + * without modification.
  23578. + * 2. Redistributions in binary form must reproduce the above copyright
  23579. + * notice, this list of conditions and the following disclaimer in the
  23580. + * documentation and/or other materials provided with the distribution.
  23581. + * 3. The names of the above-listed copyright holders may not be used
  23582. + * to endorse or promote products derived from this software without
  23583. + * specific prior written permission.
  23584. + *
  23585. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23586. + * GNU General Public License ("GPL") version 2, as published by the Free
  23587. + * Software Foundation.
  23588. + *
  23589. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23590. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23591. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23592. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23593. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23594. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23595. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23596. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23597. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23598. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23599. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23600. + */
  23601. +
  23602. +#include "vchiq_core.h"
  23603. +
  23604. +#define VCHIQ_SLOT_HANDLER_STACK 8192
  23605. +
  23606. +#define HANDLE_STATE_SHIFT 12
  23607. +
  23608. +#define SLOT_INFO_FROM_INDEX(state, index) (state->slot_info + (index))
  23609. +#define SLOT_DATA_FROM_INDEX(state, index) (state->slot_data + (index))
  23610. +#define SLOT_INDEX_FROM_DATA(state, data) \
  23611. + (((unsigned int)((char *)data - (char *)state->slot_data)) / \
  23612. + VCHIQ_SLOT_SIZE)
  23613. +#define SLOT_INDEX_FROM_INFO(state, info) \
  23614. + ((unsigned int)(info - state->slot_info))
  23615. +#define SLOT_QUEUE_INDEX_FROM_POS(pos) \
  23616. + ((int)((unsigned int)(pos) / VCHIQ_SLOT_SIZE))
  23617. +
  23618. +
  23619. +#define BULK_INDEX(x) (x & (VCHIQ_NUM_SERVICE_BULKS - 1))
  23620. +
  23621. +
  23622. +struct vchiq_open_payload {
  23623. + int fourcc;
  23624. + int client_id;
  23625. + short version;
  23626. + short version_min;
  23627. +};
  23628. +
  23629. +struct vchiq_openack_payload {
  23630. + short version;
  23631. +};
  23632. +
  23633. +/* we require this for consistency between endpoints */
  23634. +vchiq_static_assert(sizeof(VCHIQ_HEADER_T) == 8);
  23635. +vchiq_static_assert(IS_POW2(sizeof(VCHIQ_HEADER_T)));
  23636. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
  23637. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
  23638. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
  23639. +vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
  23640. +
  23641. +/* Run time control of log level, based on KERN_XXX level. */
  23642. +int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
  23643. +int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
  23644. +int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;
  23645. +
  23646. +static atomic_t pause_bulks_count = ATOMIC_INIT(0);
  23647. +
  23648. +static DEFINE_SPINLOCK(service_spinlock);
  23649. +DEFINE_SPINLOCK(bulk_waiter_spinlock);
  23650. +DEFINE_SPINLOCK(quota_spinlock);
  23651. +
  23652. +VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  23653. +static unsigned int handle_seq;
  23654. +
  23655. +static const char *const srvstate_names[] = {
  23656. + "FREE",
  23657. + "HIDDEN",
  23658. + "LISTENING",
  23659. + "OPENING",
  23660. + "OPEN",
  23661. + "OPENSYNC",
  23662. + "CLOSESENT",
  23663. + "CLOSERECVD",
  23664. + "CLOSEWAIT",
  23665. + "CLOSED"
  23666. +};
  23667. +
  23668. +static const char *const reason_names[] = {
  23669. + "SERVICE_OPENED",
  23670. + "SERVICE_CLOSED",
  23671. + "MESSAGE_AVAILABLE",
  23672. + "BULK_TRANSMIT_DONE",
  23673. + "BULK_RECEIVE_DONE",
  23674. + "BULK_TRANSMIT_ABORTED",
  23675. + "BULK_RECEIVE_ABORTED"
  23676. +};
  23677. +
  23678. +static const char *const conn_state_names[] = {
  23679. + "DISCONNECTED",
  23680. + "CONNECTING",
  23681. + "CONNECTED",
  23682. + "PAUSING",
  23683. + "PAUSE_SENT",
  23684. + "PAUSED",
  23685. + "RESUMING",
  23686. + "PAUSE_TIMEOUT",
  23687. + "RESUME_TIMEOUT"
  23688. +};
  23689. +
  23690. +
  23691. +static void
  23692. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header);
  23693. +
  23694. +static const char *msg_type_str(unsigned int msg_type)
  23695. +{
  23696. + switch (msg_type) {
  23697. + case VCHIQ_MSG_PADDING: return "PADDING";
  23698. + case VCHIQ_MSG_CONNECT: return "CONNECT";
  23699. + case VCHIQ_MSG_OPEN: return "OPEN";
  23700. + case VCHIQ_MSG_OPENACK: return "OPENACK";
  23701. + case VCHIQ_MSG_CLOSE: return "CLOSE";
  23702. + case VCHIQ_MSG_DATA: return "DATA";
  23703. + case VCHIQ_MSG_BULK_RX: return "BULK_RX";
  23704. + case VCHIQ_MSG_BULK_TX: return "BULK_TX";
  23705. + case VCHIQ_MSG_BULK_RX_DONE: return "BULK_RX_DONE";
  23706. + case VCHIQ_MSG_BULK_TX_DONE: return "BULK_TX_DONE";
  23707. + case VCHIQ_MSG_PAUSE: return "PAUSE";
  23708. + case VCHIQ_MSG_RESUME: return "RESUME";
  23709. + case VCHIQ_MSG_REMOTE_USE: return "REMOTE_USE";
  23710. + case VCHIQ_MSG_REMOTE_RELEASE: return "REMOTE_RELEASE";
  23711. + case VCHIQ_MSG_REMOTE_USE_ACTIVE: return "REMOTE_USE_ACTIVE";
  23712. + }
  23713. + return "???";
  23714. +}
  23715. +
  23716. +static inline void
  23717. +vchiq_set_service_state(VCHIQ_SERVICE_T *service, int newstate)
  23718. +{
  23719. + vchiq_log_info(vchiq_core_log_level, "%d: srv:%d %s->%s",
  23720. + service->state->id, service->localport,
  23721. + srvstate_names[service->srvstate],
  23722. + srvstate_names[newstate]);
  23723. + service->srvstate = newstate;
  23724. +}
  23725. +
  23726. +VCHIQ_SERVICE_T *
  23727. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
  23728. +{
  23729. + VCHIQ_SERVICE_T *service;
  23730. +
  23731. + spin_lock(&service_spinlock);
  23732. + service = handle_to_service(handle);
  23733. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23734. + (service->handle == handle)) {
  23735. + BUG_ON(service->ref_count == 0);
  23736. + service->ref_count++;
  23737. + } else
  23738. + service = NULL;
  23739. + spin_unlock(&service_spinlock);
  23740. +
  23741. + if (!service)
  23742. + vchiq_log_info(vchiq_core_log_level,
  23743. + "Invalid service handle 0x%x", handle);
  23744. +
  23745. + return service;
  23746. +}
  23747. +
  23748. +VCHIQ_SERVICE_T *
  23749. +find_service_by_port(VCHIQ_STATE_T *state, int localport)
  23750. +{
  23751. + VCHIQ_SERVICE_T *service = NULL;
  23752. + if ((unsigned int)localport <= VCHIQ_PORT_MAX) {
  23753. + spin_lock(&service_spinlock);
  23754. + service = state->services[localport];
  23755. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) {
  23756. + BUG_ON(service->ref_count == 0);
  23757. + service->ref_count++;
  23758. + } else
  23759. + service = NULL;
  23760. + spin_unlock(&service_spinlock);
  23761. + }
  23762. +
  23763. + if (!service)
  23764. + vchiq_log_info(vchiq_core_log_level,
  23765. + "Invalid port %d", localport);
  23766. +
  23767. + return service;
  23768. +}
  23769. +
  23770. +VCHIQ_SERVICE_T *
  23771. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  23772. + VCHIQ_SERVICE_HANDLE_T handle) {
  23773. + VCHIQ_SERVICE_T *service;
  23774. +
  23775. + spin_lock(&service_spinlock);
  23776. + service = handle_to_service(handle);
  23777. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23778. + (service->handle == handle) &&
  23779. + (service->instance == instance)) {
  23780. + BUG_ON(service->ref_count == 0);
  23781. + service->ref_count++;
  23782. + } else
  23783. + service = NULL;
  23784. + spin_unlock(&service_spinlock);
  23785. +
  23786. + if (!service)
  23787. + vchiq_log_info(vchiq_core_log_level,
  23788. + "Invalid service handle 0x%x", handle);
  23789. +
  23790. + return service;
  23791. +}
  23792. +
  23793. +VCHIQ_SERVICE_T *
  23794. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  23795. + int *pidx)
  23796. +{
  23797. + VCHIQ_SERVICE_T *service = NULL;
  23798. + int idx = *pidx;
  23799. +
  23800. + spin_lock(&service_spinlock);
  23801. + while (idx < state->unused_service) {
  23802. + VCHIQ_SERVICE_T *srv = state->services[idx++];
  23803. + if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23804. + (srv->instance == instance)) {
  23805. + service = srv;
  23806. + BUG_ON(service->ref_count == 0);
  23807. + service->ref_count++;
  23808. + break;
  23809. + }
  23810. + }
  23811. + spin_unlock(&service_spinlock);
  23812. +
  23813. + *pidx = idx;
  23814. +
  23815. + return service;
  23816. +}
  23817. +
  23818. +void
  23819. +lock_service(VCHIQ_SERVICE_T *service)
  23820. +{
  23821. + spin_lock(&service_spinlock);
  23822. + BUG_ON(!service || (service->ref_count == 0));
  23823. + if (service)
  23824. + service->ref_count++;
  23825. + spin_unlock(&service_spinlock);
  23826. +}
  23827. +
  23828. +void
  23829. +unlock_service(VCHIQ_SERVICE_T *service)
  23830. +{
  23831. + VCHIQ_STATE_T *state = service->state;
  23832. + spin_lock(&service_spinlock);
  23833. + BUG_ON(!service || (service->ref_count == 0));
  23834. + if (service && service->ref_count) {
  23835. + service->ref_count--;
  23836. + if (!service->ref_count) {
  23837. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  23838. + state->services[service->localport] = NULL;
  23839. + } else
  23840. + service = NULL;
  23841. + }
  23842. + spin_unlock(&service_spinlock);
  23843. +
  23844. + if (service && service->userdata_term)
  23845. + service->userdata_term(service->base.userdata);
  23846. +
  23847. + kfree(service);
  23848. +}
  23849. +
  23850. +int
  23851. +vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T handle)
  23852. +{
  23853. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  23854. + int id;
  23855. +
  23856. + id = service ? service->client_id : 0;
  23857. + if (service)
  23858. + unlock_service(service);
  23859. +
  23860. + return id;
  23861. +}
  23862. +
  23863. +void *
  23864. +vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T handle)
  23865. +{
  23866. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  23867. +
  23868. + return service ? service->base.userdata : NULL;
  23869. +}
  23870. +
  23871. +int
  23872. +vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T handle)
  23873. +{
  23874. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  23875. +
  23876. + return service ? service->base.fourcc : 0;
  23877. +}
  23878. +
  23879. +static void
  23880. +mark_service_closing_internal(VCHIQ_SERVICE_T *service, int sh_thread)
  23881. +{
  23882. + VCHIQ_STATE_T *state = service->state;
  23883. + VCHIQ_SERVICE_QUOTA_T *service_quota;
  23884. +
  23885. + service->closing = 1;
  23886. +
  23887. + /* Synchronise with other threads. */
  23888. + mutex_lock(&state->recycle_mutex);
  23889. + mutex_unlock(&state->recycle_mutex);
  23890. + if (!sh_thread || (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT)) {
  23891. + /* If we're pausing then the slot_mutex is held until resume
  23892. + * by the slot handler. Therefore don't try to acquire this
  23893. + * mutex if we're the slot handler and in the pause sent state.
  23894. + * We don't need to in this case anyway. */
  23895. + mutex_lock(&state->slot_mutex);
  23896. + mutex_unlock(&state->slot_mutex);
  23897. + }
  23898. +
  23899. + /* Unblock any sending thread. */
  23900. + service_quota = &state->service_quotas[service->localport];
  23901. + up(&service_quota->quota_event);
  23902. +}
  23903. +
  23904. +static void
  23905. +mark_service_closing(VCHIQ_SERVICE_T *service)
  23906. +{
  23907. + mark_service_closing_internal(service, 0);
  23908. +}
  23909. +
  23910. +static inline VCHIQ_STATUS_T
  23911. +make_service_callback(VCHIQ_SERVICE_T *service, VCHIQ_REASON_T reason,
  23912. + VCHIQ_HEADER_T *header, void *bulk_userdata)
  23913. +{
  23914. + VCHIQ_STATUS_T status;
  23915. + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, %x)",
  23916. + service->state->id, service->localport, reason_names[reason],
  23917. + (unsigned int)header, (unsigned int)bulk_userdata);
  23918. + status = service->base.callback(reason, header, service->handle,
  23919. + bulk_userdata);
  23920. + if (status == VCHIQ_ERROR) {
  23921. + vchiq_log_warning(vchiq_core_log_level,
  23922. + "%d: ignoring ERROR from callback to service %x",
  23923. + service->state->id, service->handle);
  23924. + status = VCHIQ_SUCCESS;
  23925. + }
  23926. + return status;
  23927. +}
  23928. +
  23929. +inline void
  23930. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate)
  23931. +{
  23932. + VCHIQ_CONNSTATE_T oldstate = state->conn_state;
  23933. + vchiq_log_info(vchiq_core_log_level, "%d: %s->%s", state->id,
  23934. + conn_state_names[oldstate],
  23935. + conn_state_names[newstate]);
  23936. + state->conn_state = newstate;
  23937. + vchiq_platform_conn_state_changed(state, oldstate, newstate);
  23938. +}
  23939. +
  23940. +static inline void
  23941. +remote_event_create(REMOTE_EVENT_T *event)
  23942. +{
  23943. + event->armed = 0;
  23944. + /* Don't clear the 'fired' flag because it may already have been set
  23945. + ** by the other side. */
  23946. + sema_init(event->event, 0);
  23947. +}
  23948. +
  23949. +static inline void
  23950. +remote_event_destroy(REMOTE_EVENT_T *event)
  23951. +{
  23952. + (void)event;
  23953. +}
  23954. +
  23955. +static inline int
  23956. +remote_event_wait(REMOTE_EVENT_T *event)
  23957. +{
  23958. + if (!event->fired) {
  23959. + event->armed = 1;
  23960. + dsb();
  23961. + if (!event->fired) {
  23962. + if (down_interruptible(event->event) != 0) {
  23963. + event->armed = 0;
  23964. + return 0;
  23965. + }
  23966. + }
  23967. + event->armed = 0;
  23968. + wmb();
  23969. + }
  23970. +
  23971. + event->fired = 0;
  23972. + return 1;
  23973. +}
  23974. +
  23975. +static inline void
  23976. +remote_event_signal_local(REMOTE_EVENT_T *event)
  23977. +{
  23978. + event->armed = 0;
  23979. + up(event->event);
  23980. +}
  23981. +
  23982. +static inline void
  23983. +remote_event_poll(REMOTE_EVENT_T *event)
  23984. +{
  23985. + if (event->fired && event->armed)
  23986. + remote_event_signal_local(event);
  23987. +}
  23988. +
  23989. +void
  23990. +remote_event_pollall(VCHIQ_STATE_T *state)
  23991. +{
  23992. + remote_event_poll(&state->local->sync_trigger);
  23993. + remote_event_poll(&state->local->sync_release);
  23994. + remote_event_poll(&state->local->trigger);
  23995. + remote_event_poll(&state->local->recycle);
  23996. +}
  23997. +
  23998. +/* Round up message sizes so that any space at the end of a slot is always big
  23999. +** enough for a header. This relies on header size being a power of two, which
  24000. +** has been verified earlier by a static assertion. */
  24001. +
  24002. +static inline unsigned int
  24003. +calc_stride(unsigned int size)
  24004. +{
  24005. + /* Allow room for the header */
  24006. + size += sizeof(VCHIQ_HEADER_T);
  24007. +
  24008. + /* Round up */
  24009. + return (size + sizeof(VCHIQ_HEADER_T) - 1) & ~(sizeof(VCHIQ_HEADER_T)
  24010. + - 1);
  24011. +}
  24012. +
  24013. +/* Called by the slot handler thread */
  24014. +static VCHIQ_SERVICE_T *
  24015. +get_listening_service(VCHIQ_STATE_T *state, int fourcc)
  24016. +{
  24017. + int i;
  24018. +
  24019. + WARN_ON(fourcc == VCHIQ_FOURCC_INVALID);
  24020. +
  24021. + for (i = 0; i < state->unused_service; i++) {
  24022. + VCHIQ_SERVICE_T *service = state->services[i];
  24023. + if (service &&
  24024. + (service->public_fourcc == fourcc) &&
  24025. + ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  24026. + ((service->srvstate == VCHIQ_SRVSTATE_OPEN) &&
  24027. + (service->remoteport == VCHIQ_PORT_FREE)))) {
  24028. + lock_service(service);
  24029. + return service;
  24030. + }
  24031. + }
  24032. +
  24033. + return NULL;
  24034. +}
  24035. +
  24036. +/* Called by the slot handler thread */
  24037. +static VCHIQ_SERVICE_T *
  24038. +get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
  24039. +{
  24040. + int i;
  24041. + for (i = 0; i < state->unused_service; i++) {
  24042. + VCHIQ_SERVICE_T *service = state->services[i];
  24043. + if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN)
  24044. + && (service->remoteport == port)) {
  24045. + lock_service(service);
  24046. + return service;
  24047. + }
  24048. + }
  24049. + return NULL;
  24050. +}
  24051. +
  24052. +inline void
  24053. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
  24054. +{
  24055. + uint32_t value;
  24056. +
  24057. + if (service) {
  24058. + do {
  24059. + value = atomic_read(&service->poll_flags);
  24060. + } while (atomic_cmpxchg(&service->poll_flags, value,
  24061. + value | (1 << poll_type)) != value);
  24062. +
  24063. + do {
  24064. + value = atomic_read(&state->poll_services[
  24065. + service->localport>>5]);
  24066. + } while (atomic_cmpxchg(
  24067. + &state->poll_services[service->localport>>5],
  24068. + value, value | (1 << (service->localport & 0x1f)))
  24069. + != value);
  24070. + }
  24071. +
  24072. + state->poll_needed = 1;
  24073. + wmb();
  24074. +
  24075. + /* ... and ensure the slot handler runs. */
  24076. + remote_event_signal_local(&state->local->trigger);
  24077. +}
  24078. +
  24079. +/* Called from queue_message, by the slot handler and application threads,
  24080. +** with slot_mutex held */
  24081. +static VCHIQ_HEADER_T *
  24082. +reserve_space(VCHIQ_STATE_T *state, int space, int is_blocking)
  24083. +{
  24084. + VCHIQ_SHARED_STATE_T *local = state->local;
  24085. + int tx_pos = state->local_tx_pos;
  24086. + int slot_space = VCHIQ_SLOT_SIZE - (tx_pos & VCHIQ_SLOT_MASK);
  24087. +
  24088. + if (space > slot_space) {
  24089. + VCHIQ_HEADER_T *header;
  24090. + /* Fill the remaining space with padding */
  24091. + WARN_ON(state->tx_data == NULL);
  24092. + header = (VCHIQ_HEADER_T *)
  24093. + (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  24094. + header->msgid = VCHIQ_MSGID_PADDING;
  24095. + header->size = slot_space - sizeof(VCHIQ_HEADER_T);
  24096. +
  24097. + tx_pos += slot_space;
  24098. + }
  24099. +
  24100. + /* If necessary, get the next slot. */
  24101. + if ((tx_pos & VCHIQ_SLOT_MASK) == 0) {
  24102. + int slot_index;
  24103. +
  24104. + /* If there is no free slot... */
  24105. +
  24106. + if (down_trylock(&state->slot_available_event) != 0) {
  24107. + /* ...wait for one. */
  24108. +
  24109. + VCHIQ_STATS_INC(state, slot_stalls);
  24110. +
  24111. + /* But first, flush through the last slot. */
  24112. + state->local_tx_pos = tx_pos;
  24113. + local->tx_pos = tx_pos;
  24114. + remote_event_signal(&state->remote->trigger);
  24115. +
  24116. + if (!is_blocking ||
  24117. + (down_interruptible(
  24118. + &state->slot_available_event) != 0))
  24119. + return NULL; /* No space available */
  24120. + }
  24121. +
  24122. + BUG_ON(tx_pos ==
  24123. + (state->slot_queue_available * VCHIQ_SLOT_SIZE));
  24124. +
  24125. + slot_index = local->slot_queue[
  24126. + SLOT_QUEUE_INDEX_FROM_POS(tx_pos) &
  24127. + VCHIQ_SLOT_QUEUE_MASK];
  24128. + state->tx_data =
  24129. + (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  24130. + }
  24131. +
  24132. + state->local_tx_pos = tx_pos + space;
  24133. +
  24134. + return (VCHIQ_HEADER_T *)(state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  24135. +}
  24136. +
  24137. +/* Called by the recycle thread. */
  24138. +static void
  24139. +process_free_queue(VCHIQ_STATE_T *state)
  24140. +{
  24141. + VCHIQ_SHARED_STATE_T *local = state->local;
  24142. + BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  24143. + int slot_queue_available;
  24144. +
  24145. + /* Use a read memory barrier to ensure that any state that may have
  24146. + ** been modified by another thread is not masked by stale prefetched
  24147. + ** values. */
  24148. + rmb();
  24149. +
  24150. + /* Find slots which have been freed by the other side, and return them
  24151. + ** to the available queue. */
  24152. + slot_queue_available = state->slot_queue_available;
  24153. +
  24154. + while (slot_queue_available != local->slot_queue_recycle) {
  24155. + unsigned int pos;
  24156. + int slot_index = local->slot_queue[slot_queue_available++ &
  24157. + VCHIQ_SLOT_QUEUE_MASK];
  24158. + char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  24159. + int data_found = 0;
  24160. +
  24161. + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%x %x %x",
  24162. + state->id, slot_index, (unsigned int)data,
  24163. + local->slot_queue_recycle, slot_queue_available);
  24164. +
  24165. + /* Initialise the bitmask for services which have used this
  24166. + ** slot */
  24167. + BITSET_ZERO(service_found);
  24168. +
  24169. + pos = 0;
  24170. +
  24171. + while (pos < VCHIQ_SLOT_SIZE) {
  24172. + VCHIQ_HEADER_T *header =
  24173. + (VCHIQ_HEADER_T *)(data + pos);
  24174. + int msgid = header->msgid;
  24175. + if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) {
  24176. + int port = VCHIQ_MSG_SRCPORT(msgid);
  24177. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  24178. + &state->service_quotas[port];
  24179. + int count;
  24180. + spin_lock(&quota_spinlock);
  24181. + count = service_quota->message_use_count;
  24182. + if (count > 0)
  24183. + service_quota->message_use_count =
  24184. + count - 1;
  24185. + spin_unlock(&quota_spinlock);
  24186. +
  24187. + if (count == service_quota->message_quota)
  24188. + /* Signal the service that it
  24189. + ** has dropped below its quota
  24190. + */
  24191. + up(&service_quota->quota_event);
  24192. + else if (count == 0) {
  24193. + vchiq_log_error(vchiq_core_log_level,
  24194. + "service %d "
  24195. + "message_use_count=%d "
  24196. + "(header %x, msgid %x, "
  24197. + "header->msgid %x, "
  24198. + "header->size %x)",
  24199. + port,
  24200. + service_quota->
  24201. + message_use_count,
  24202. + (unsigned int)header, msgid,
  24203. + header->msgid,
  24204. + header->size);
  24205. + WARN(1, "invalid message use count\n");
  24206. + }
  24207. + if (!BITSET_IS_SET(service_found, port)) {
  24208. + /* Set the found bit for this service */
  24209. + BITSET_SET(service_found, port);
  24210. +
  24211. + spin_lock(&quota_spinlock);
  24212. + count = service_quota->slot_use_count;
  24213. + if (count > 0)
  24214. + service_quota->slot_use_count =
  24215. + count - 1;
  24216. + spin_unlock(&quota_spinlock);
  24217. +
  24218. + if (count > 0) {
  24219. + /* Signal the service in case
  24220. + ** it has dropped below its
  24221. + ** quota */
  24222. + up(&service_quota->quota_event);
  24223. + vchiq_log_trace(
  24224. + vchiq_core_log_level,
  24225. + "%d: pfq:%d %x@%x - "
  24226. + "slot_use->%d",
  24227. + state->id, port,
  24228. + header->size,
  24229. + (unsigned int)header,
  24230. + count - 1);
  24231. + } else {
  24232. + vchiq_log_error(
  24233. + vchiq_core_log_level,
  24234. + "service %d "
  24235. + "slot_use_count"
  24236. + "=%d (header %x"
  24237. + ", msgid %x, "
  24238. + "header->msgid"
  24239. + " %x, header->"
  24240. + "size %x)",
  24241. + port, count,
  24242. + (unsigned int)header,
  24243. + msgid,
  24244. + header->msgid,
  24245. + header->size);
  24246. + WARN(1, "bad slot use count\n");
  24247. + }
  24248. + }
  24249. +
  24250. + data_found = 1;
  24251. + }
  24252. +
  24253. + pos += calc_stride(header->size);
  24254. + if (pos > VCHIQ_SLOT_SIZE) {
  24255. + vchiq_log_error(vchiq_core_log_level,
  24256. + "pfq - pos %x: header %x, msgid %x, "
  24257. + "header->msgid %x, header->size %x",
  24258. + pos, (unsigned int)header, msgid,
  24259. + header->msgid, header->size);
  24260. + WARN(1, "invalid slot position\n");
  24261. + }
  24262. + }
  24263. +
  24264. + if (data_found) {
  24265. + int count;
  24266. + spin_lock(&quota_spinlock);
  24267. + count = state->data_use_count;
  24268. + if (count > 0)
  24269. + state->data_use_count =
  24270. + count - 1;
  24271. + spin_unlock(&quota_spinlock);
  24272. + if (count == state->data_quota)
  24273. + up(&state->data_quota_event);
  24274. + }
  24275. +
  24276. + state->slot_queue_available = slot_queue_available;
  24277. + up(&state->slot_available_event);
  24278. + }
  24279. +}
  24280. +
  24281. +/* Called by the slot handler and application threads */
  24282. +static VCHIQ_STATUS_T
  24283. +queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  24284. + int msgid, const VCHIQ_ELEMENT_T *elements,
  24285. + int count, int size, int is_blocking)
  24286. +{
  24287. + VCHIQ_SHARED_STATE_T *local;
  24288. + VCHIQ_SERVICE_QUOTA_T *service_quota = NULL;
  24289. + VCHIQ_HEADER_T *header;
  24290. + int type = VCHIQ_MSG_TYPE(msgid);
  24291. +
  24292. + unsigned int stride;
  24293. +
  24294. + local = state->local;
  24295. +
  24296. + stride = calc_stride(size);
  24297. +
  24298. + WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
  24299. +
  24300. + if ((type != VCHIQ_MSG_RESUME) &&
  24301. + (mutex_lock_interruptible(&state->slot_mutex) != 0))
  24302. + return VCHIQ_RETRY;
  24303. +
  24304. + if (type == VCHIQ_MSG_DATA) {
  24305. + int tx_end_index;
  24306. +
  24307. + BUG_ON(!service);
  24308. +
  24309. + if (service->closing) {
  24310. + /* The service has been closed */
  24311. + mutex_unlock(&state->slot_mutex);
  24312. + return VCHIQ_ERROR;
  24313. + }
  24314. +
  24315. + service_quota = &state->service_quotas[service->localport];
  24316. +
  24317. + spin_lock(&quota_spinlock);
  24318. +
  24319. + /* Ensure this service doesn't use more than its quota of
  24320. + ** messages or slots */
  24321. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  24322. + state->local_tx_pos + stride - 1);
  24323. +
  24324. + /* Ensure data messages don't use more than their quota of
  24325. + ** slots */
  24326. + while ((tx_end_index != state->previous_data_index) &&
  24327. + (state->data_use_count == state->data_quota)) {
  24328. + VCHIQ_STATS_INC(state, data_stalls);
  24329. + spin_unlock(&quota_spinlock);
  24330. + mutex_unlock(&state->slot_mutex);
  24331. +
  24332. + if (down_interruptible(&state->data_quota_event)
  24333. + != 0)
  24334. + return VCHIQ_RETRY;
  24335. +
  24336. + mutex_lock(&state->slot_mutex);
  24337. + spin_lock(&quota_spinlock);
  24338. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  24339. + state->local_tx_pos + stride - 1);
  24340. + if ((tx_end_index == state->previous_data_index) ||
  24341. + (state->data_use_count < state->data_quota)) {
  24342. + /* Pass the signal on to other waiters */
  24343. + up(&state->data_quota_event);
  24344. + break;
  24345. + }
  24346. + }
  24347. +
  24348. + while ((service_quota->message_use_count ==
  24349. + service_quota->message_quota) ||
  24350. + ((tx_end_index != service_quota->previous_tx_index) &&
  24351. + (service_quota->slot_use_count ==
  24352. + service_quota->slot_quota))) {
  24353. + spin_unlock(&quota_spinlock);
  24354. + vchiq_log_trace(vchiq_core_log_level,
  24355. + "%d: qm:%d %s,%x - quota stall "
  24356. + "(msg %d, slot %d)",
  24357. + state->id, service->localport,
  24358. + msg_type_str(type), size,
  24359. + service_quota->message_use_count,
  24360. + service_quota->slot_use_count);
  24361. + VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
  24362. + mutex_unlock(&state->slot_mutex);
  24363. + if (down_interruptible(&service_quota->quota_event)
  24364. + != 0)
  24365. + return VCHIQ_RETRY;
  24366. + if (service->closing)
  24367. + return VCHIQ_ERROR;
  24368. + if (mutex_lock_interruptible(&state->slot_mutex) != 0)
  24369. + return VCHIQ_RETRY;
  24370. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
  24371. + /* The service has been closed */
  24372. + mutex_unlock(&state->slot_mutex);
  24373. + return VCHIQ_ERROR;
  24374. + }
  24375. + spin_lock(&quota_spinlock);
  24376. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  24377. + state->local_tx_pos + stride - 1);
  24378. + }
  24379. +
  24380. + spin_unlock(&quota_spinlock);
  24381. + }
  24382. +
  24383. + header = reserve_space(state, stride, is_blocking);
  24384. +
  24385. + if (!header) {
  24386. + if (service)
  24387. + VCHIQ_SERVICE_STATS_INC(service, slot_stalls);
  24388. + mutex_unlock(&state->slot_mutex);
  24389. + return VCHIQ_RETRY;
  24390. + }
  24391. +
  24392. + if (type == VCHIQ_MSG_DATA) {
  24393. + int i, pos;
  24394. + int tx_end_index;
  24395. + int slot_use_count;
  24396. +
  24397. + vchiq_log_info(vchiq_core_log_level,
  24398. + "%d: qm %s@%x,%x (%d->%d)",
  24399. + state->id,
  24400. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24401. + (unsigned int)header, size,
  24402. + VCHIQ_MSG_SRCPORT(msgid),
  24403. + VCHIQ_MSG_DSTPORT(msgid));
  24404. +
  24405. + BUG_ON(!service);
  24406. +
  24407. + for (i = 0, pos = 0; i < (unsigned int)count;
  24408. + pos += elements[i++].size)
  24409. + if (elements[i].size) {
  24410. + if (vchiq_copy_from_user
  24411. + (header->data + pos, elements[i].data,
  24412. + (size_t) elements[i].size) !=
  24413. + VCHIQ_SUCCESS) {
  24414. + mutex_unlock(&state->slot_mutex);
  24415. + VCHIQ_SERVICE_STATS_INC(service,
  24416. + error_count);
  24417. + return VCHIQ_ERROR;
  24418. + }
  24419. + if (i == 0) {
  24420. + if (vchiq_core_msg_log_level >=
  24421. + VCHIQ_LOG_INFO)
  24422. + vchiq_log_dump_mem("Sent", 0,
  24423. + header->data + pos,
  24424. + min(64u,
  24425. + elements[0].size));
  24426. + }
  24427. + }
  24428. +
  24429. + spin_lock(&quota_spinlock);
  24430. + service_quota->message_use_count++;
  24431. +
  24432. + tx_end_index =
  24433. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos - 1);
  24434. +
  24435. + /* If this transmission can't fit in the last slot used by any
  24436. + ** service, the data_use_count must be increased. */
  24437. + if (tx_end_index != state->previous_data_index) {
  24438. + state->previous_data_index = tx_end_index;
  24439. + state->data_use_count++;
  24440. + }
  24441. +
  24442. + /* If this isn't the same slot last used by this service,
  24443. + ** the service's slot_use_count must be increased. */
  24444. + if (tx_end_index != service_quota->previous_tx_index) {
  24445. + service_quota->previous_tx_index = tx_end_index;
  24446. + slot_use_count = ++service_quota->slot_use_count;
  24447. + } else {
  24448. + slot_use_count = 0;
  24449. + }
  24450. +
  24451. + spin_unlock(&quota_spinlock);
  24452. +
  24453. + if (slot_use_count)
  24454. + vchiq_log_trace(vchiq_core_log_level,
  24455. + "%d: qm:%d %s,%x - slot_use->%d (hdr %p)",
  24456. + state->id, service->localport,
  24457. + msg_type_str(VCHIQ_MSG_TYPE(msgid)), size,
  24458. + slot_use_count, header);
  24459. +
  24460. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  24461. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  24462. + } else {
  24463. + vchiq_log_info(vchiq_core_log_level,
  24464. + "%d: qm %s@%x,%x (%d->%d)", state->id,
  24465. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24466. + (unsigned int)header, size,
  24467. + VCHIQ_MSG_SRCPORT(msgid),
  24468. + VCHIQ_MSG_DSTPORT(msgid));
  24469. + if (size != 0) {
  24470. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  24471. + memcpy(header->data, elements[0].data,
  24472. + elements[0].size);
  24473. + }
  24474. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  24475. + }
  24476. +
  24477. + header->msgid = msgid;
  24478. + header->size = size;
  24479. +
  24480. + {
  24481. + int svc_fourcc;
  24482. +
  24483. + svc_fourcc = service
  24484. + ? service->base.fourcc
  24485. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  24486. +
  24487. + vchiq_log_info(vchiq_core_msg_log_level,
  24488. + "Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  24489. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24490. + VCHIQ_MSG_TYPE(msgid),
  24491. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  24492. + VCHIQ_MSG_SRCPORT(msgid),
  24493. + VCHIQ_MSG_DSTPORT(msgid),
  24494. + size);
  24495. + }
  24496. +
  24497. + /* Make sure the new header is visible to the peer. */
  24498. + wmb();
  24499. +
  24500. + /* Make the new tx_pos visible to the peer. */
  24501. + local->tx_pos = state->local_tx_pos;
  24502. + wmb();
  24503. +
  24504. + if (service && (type == VCHIQ_MSG_CLOSE))
  24505. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSESENT);
  24506. +
  24507. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  24508. + mutex_unlock(&state->slot_mutex);
  24509. +
  24510. + remote_event_signal(&state->remote->trigger);
  24511. +
  24512. + return VCHIQ_SUCCESS;
  24513. +}
  24514. +
  24515. +/* Called by the slot handler and application threads */
  24516. +static VCHIQ_STATUS_T
  24517. +queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  24518. + int msgid, const VCHIQ_ELEMENT_T *elements,
  24519. + int count, int size, int is_blocking)
  24520. +{
  24521. + VCHIQ_SHARED_STATE_T *local;
  24522. + VCHIQ_HEADER_T *header;
  24523. +
  24524. + local = state->local;
  24525. +
  24526. + if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
  24527. + (mutex_lock_interruptible(&state->sync_mutex) != 0))
  24528. + return VCHIQ_RETRY;
  24529. +
  24530. + remote_event_wait(&local->sync_release);
  24531. +
  24532. + rmb();
  24533. +
  24534. + header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  24535. + local->slot_sync);
  24536. +
  24537. + {
  24538. + int oldmsgid = header->msgid;
  24539. + if (oldmsgid != VCHIQ_MSGID_PADDING)
  24540. + vchiq_log_error(vchiq_core_log_level,
  24541. + "%d: qms - msgid %x, not PADDING",
  24542. + state->id, oldmsgid);
  24543. + }
  24544. +
  24545. + if (service) {
  24546. + int i, pos;
  24547. +
  24548. + vchiq_log_info(vchiq_sync_log_level,
  24549. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  24550. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24551. + (unsigned int)header, size,
  24552. + VCHIQ_MSG_SRCPORT(msgid),
  24553. + VCHIQ_MSG_DSTPORT(msgid));
  24554. +
  24555. + for (i = 0, pos = 0; i < (unsigned int)count;
  24556. + pos += elements[i++].size)
  24557. + if (elements[i].size) {
  24558. + if (vchiq_copy_from_user
  24559. + (header->data + pos, elements[i].data,
  24560. + (size_t) elements[i].size) !=
  24561. + VCHIQ_SUCCESS) {
  24562. + mutex_unlock(&state->sync_mutex);
  24563. + VCHIQ_SERVICE_STATS_INC(service,
  24564. + error_count);
  24565. + return VCHIQ_ERROR;
  24566. + }
  24567. + if (i == 0) {
  24568. + if (vchiq_sync_log_level >=
  24569. + VCHIQ_LOG_TRACE)
  24570. + vchiq_log_dump_mem("Sent Sync",
  24571. + 0, header->data + pos,
  24572. + min(64u,
  24573. + elements[0].size));
  24574. + }
  24575. + }
  24576. +
  24577. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  24578. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  24579. + } else {
  24580. + vchiq_log_info(vchiq_sync_log_level,
  24581. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  24582. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24583. + (unsigned int)header, size,
  24584. + VCHIQ_MSG_SRCPORT(msgid),
  24585. + VCHIQ_MSG_DSTPORT(msgid));
  24586. + if (size != 0) {
  24587. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  24588. + memcpy(header->data, elements[0].data,
  24589. + elements[0].size);
  24590. + }
  24591. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  24592. + }
  24593. +
  24594. + header->size = size;
  24595. + header->msgid = msgid;
  24596. +
  24597. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  24598. + int svc_fourcc;
  24599. +
  24600. + svc_fourcc = service
  24601. + ? service->base.fourcc
  24602. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  24603. +
  24604. + vchiq_log_trace(vchiq_sync_log_level,
  24605. + "Sent Sync Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  24606. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24607. + VCHIQ_MSG_TYPE(msgid),
  24608. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  24609. + VCHIQ_MSG_SRCPORT(msgid),
  24610. + VCHIQ_MSG_DSTPORT(msgid),
  24611. + size);
  24612. + }
  24613. +
  24614. + /* Make sure the new header is visible to the peer. */
  24615. + wmb();
  24616. +
  24617. + remote_event_signal(&state->remote->sync_trigger);
  24618. +
  24619. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  24620. + mutex_unlock(&state->sync_mutex);
  24621. +
  24622. + return VCHIQ_SUCCESS;
  24623. +}
  24624. +
  24625. +static inline void
  24626. +claim_slot(VCHIQ_SLOT_INFO_T *slot)
  24627. +{
  24628. + slot->use_count++;
  24629. +}
  24630. +
  24631. +static void
  24632. +release_slot(VCHIQ_STATE_T *state, VCHIQ_SLOT_INFO_T *slot_info,
  24633. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_T *service)
  24634. +{
  24635. + int release_count;
  24636. +
  24637. + mutex_lock(&state->recycle_mutex);
  24638. +
  24639. + if (header) {
  24640. + int msgid = header->msgid;
  24641. + if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) ||
  24642. + (service && service->closing)) {
  24643. + mutex_unlock(&state->recycle_mutex);
  24644. + return;
  24645. + }
  24646. +
  24647. + /* Rewrite the message header to prevent a double
  24648. + ** release */
  24649. + header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED;
  24650. + }
  24651. +
  24652. + release_count = slot_info->release_count;
  24653. + slot_info->release_count = ++release_count;
  24654. +
  24655. + if (release_count == slot_info->use_count) {
  24656. + int slot_queue_recycle;
  24657. + /* Add to the freed queue */
  24658. +
  24659. + /* A read barrier is necessary here to prevent speculative
  24660. + ** fetches of remote->slot_queue_recycle from overtaking the
  24661. + ** mutex. */
  24662. + rmb();
  24663. +
  24664. + slot_queue_recycle = state->remote->slot_queue_recycle;
  24665. + state->remote->slot_queue[slot_queue_recycle &
  24666. + VCHIQ_SLOT_QUEUE_MASK] =
  24667. + SLOT_INDEX_FROM_INFO(state, slot_info);
  24668. + state->remote->slot_queue_recycle = slot_queue_recycle + 1;
  24669. + vchiq_log_info(vchiq_core_log_level,
  24670. + "%d: release_slot %d - recycle->%x",
  24671. + state->id, SLOT_INDEX_FROM_INFO(state, slot_info),
  24672. + state->remote->slot_queue_recycle);
  24673. +
  24674. + /* A write barrier is necessary, but remote_event_signal
  24675. + ** contains one. */
  24676. + remote_event_signal(&state->remote->recycle);
  24677. + }
  24678. +
  24679. + mutex_unlock(&state->recycle_mutex);
  24680. +}
  24681. +
  24682. +/* Called by the slot handler - don't hold the bulk mutex */
  24683. +static VCHIQ_STATUS_T
  24684. +notify_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue,
  24685. + int retry_poll)
  24686. +{
  24687. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  24688. +
  24689. + vchiq_log_trace(vchiq_core_log_level,
  24690. + "%d: nb:%d %cx - p=%x rn=%x r=%x",
  24691. + service->state->id, service->localport,
  24692. + (queue == &service->bulk_tx) ? 't' : 'r',
  24693. + queue->process, queue->remote_notify, queue->remove);
  24694. +
  24695. + if (service->state->is_master) {
  24696. + while (queue->remote_notify != queue->process) {
  24697. + VCHIQ_BULK_T *bulk =
  24698. + &queue->bulks[BULK_INDEX(queue->remote_notify)];
  24699. + int msgtype = (bulk->dir == VCHIQ_BULK_TRANSMIT) ?
  24700. + VCHIQ_MSG_BULK_RX_DONE : VCHIQ_MSG_BULK_TX_DONE;
  24701. + int msgid = VCHIQ_MAKE_MSG(msgtype, service->localport,
  24702. + service->remoteport);
  24703. + VCHIQ_ELEMENT_T element = { &bulk->actual, 4 };
  24704. + /* Only reply to non-dummy bulk requests */
  24705. + if (bulk->remote_data) {
  24706. + status = queue_message(service->state, NULL,
  24707. + msgid, &element, 1, 4, 0);
  24708. + if (status != VCHIQ_SUCCESS)
  24709. + break;
  24710. + }
  24711. + queue->remote_notify++;
  24712. + }
  24713. + } else {
  24714. + queue->remote_notify = queue->process;
  24715. + }
  24716. +
  24717. + if (status == VCHIQ_SUCCESS) {
  24718. + while (queue->remove != queue->remote_notify) {
  24719. + VCHIQ_BULK_T *bulk =
  24720. + &queue->bulks[BULK_INDEX(queue->remove)];
  24721. +
  24722. + /* Only generate callbacks for non-dummy bulk
  24723. + ** requests, and non-terminated services */
  24724. + if (bulk->data && service->instance) {
  24725. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
  24726. + if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
  24727. + VCHIQ_SERVICE_STATS_INC(service,
  24728. + bulk_tx_count);
  24729. + VCHIQ_SERVICE_STATS_ADD(service,
  24730. + bulk_tx_bytes,
  24731. + bulk->actual);
  24732. + } else {
  24733. + VCHIQ_SERVICE_STATS_INC(service,
  24734. + bulk_rx_count);
  24735. + VCHIQ_SERVICE_STATS_ADD(service,
  24736. + bulk_rx_bytes,
  24737. + bulk->actual);
  24738. + }
  24739. + } else {
  24740. + VCHIQ_SERVICE_STATS_INC(service,
  24741. + bulk_aborted_count);
  24742. + }
  24743. + if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
  24744. + struct bulk_waiter *waiter;
  24745. + spin_lock(&bulk_waiter_spinlock);
  24746. + waiter = bulk->userdata;
  24747. + if (waiter) {
  24748. + waiter->actual = bulk->actual;
  24749. + up(&waiter->event);
  24750. + }
  24751. + spin_unlock(&bulk_waiter_spinlock);
  24752. + } else if (bulk->mode ==
  24753. + VCHIQ_BULK_MODE_CALLBACK) {
  24754. + VCHIQ_REASON_T reason = (bulk->dir ==
  24755. + VCHIQ_BULK_TRANSMIT) ?
  24756. + ((bulk->actual ==
  24757. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  24758. + VCHIQ_BULK_TRANSMIT_ABORTED :
  24759. + VCHIQ_BULK_TRANSMIT_DONE) :
  24760. + ((bulk->actual ==
  24761. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  24762. + VCHIQ_BULK_RECEIVE_ABORTED :
  24763. + VCHIQ_BULK_RECEIVE_DONE);
  24764. + status = make_service_callback(service,
  24765. + reason, NULL, bulk->userdata);
  24766. + if (status == VCHIQ_RETRY)
  24767. + break;
  24768. + }
  24769. + }
  24770. +
  24771. + queue->remove++;
  24772. + up(&service->bulk_remove_event);
  24773. + }
  24774. + if (!retry_poll)
  24775. + status = VCHIQ_SUCCESS;
  24776. + }
  24777. +
  24778. + if (status == VCHIQ_RETRY)
  24779. + request_poll(service->state, service,
  24780. + (queue == &service->bulk_tx) ?
  24781. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  24782. +
  24783. + return status;
  24784. +}
  24785. +
  24786. +/* Called by the slot handler thread */
  24787. +static void
  24788. +poll_services(VCHIQ_STATE_T *state)
  24789. +{
  24790. + int group, i;
  24791. +
  24792. + for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
  24793. + uint32_t flags;
  24794. + flags = atomic_xchg(&state->poll_services[group], 0);
  24795. + for (i = 0; flags; i++) {
  24796. + if (flags & (1 << i)) {
  24797. + VCHIQ_SERVICE_T *service =
  24798. + find_service_by_port(state,
  24799. + (group<<5) + i);
  24800. + uint32_t service_flags;
  24801. + flags &= ~(1 << i);
  24802. + if (!service)
  24803. + continue;
  24804. + service_flags =
  24805. + atomic_xchg(&service->poll_flags, 0);
  24806. + if (service_flags &
  24807. + (1 << VCHIQ_POLL_REMOVE)) {
  24808. + vchiq_log_info(vchiq_core_log_level,
  24809. + "%d: ps - remove %d<->%d",
  24810. + state->id, service->localport,
  24811. + service->remoteport);
  24812. +
  24813. + /* Make it look like a client, because
  24814. + it must be removed and not left in
  24815. + the LISTENING state. */
  24816. + service->public_fourcc =
  24817. + VCHIQ_FOURCC_INVALID;
  24818. +
  24819. + if (vchiq_close_service_internal(
  24820. + service, 0/*!close_recvd*/) !=
  24821. + VCHIQ_SUCCESS)
  24822. + request_poll(state, service,
  24823. + VCHIQ_POLL_REMOVE);
  24824. + } else if (service_flags &
  24825. + (1 << VCHIQ_POLL_TERMINATE)) {
  24826. + vchiq_log_info(vchiq_core_log_level,
  24827. + "%d: ps - terminate %d<->%d",
  24828. + state->id, service->localport,
  24829. + service->remoteport);
  24830. + if (vchiq_close_service_internal(
  24831. + service, 0/*!close_recvd*/) !=
  24832. + VCHIQ_SUCCESS)
  24833. + request_poll(state, service,
  24834. + VCHIQ_POLL_TERMINATE);
  24835. + }
  24836. + if (service_flags & (1 << VCHIQ_POLL_TXNOTIFY))
  24837. + notify_bulks(service,
  24838. + &service->bulk_tx,
  24839. + 1/*retry_poll*/);
  24840. + if (service_flags & (1 << VCHIQ_POLL_RXNOTIFY))
  24841. + notify_bulks(service,
  24842. + &service->bulk_rx,
  24843. + 1/*retry_poll*/);
  24844. + unlock_service(service);
  24845. + }
  24846. + }
  24847. + }
  24848. +}
  24849. +
  24850. +/* Called by the slot handler or application threads, holding the bulk mutex. */
  24851. +static int
  24852. +resolve_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  24853. +{
  24854. + VCHIQ_STATE_T *state = service->state;
  24855. + int resolved = 0;
  24856. + int rc;
  24857. +
  24858. + while ((queue->process != queue->local_insert) &&
  24859. + (queue->process != queue->remote_insert)) {
  24860. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  24861. +
  24862. + vchiq_log_trace(vchiq_core_log_level,
  24863. + "%d: rb:%d %cx - li=%x ri=%x p=%x",
  24864. + state->id, service->localport,
  24865. + (queue == &service->bulk_tx) ? 't' : 'r',
  24866. + queue->local_insert, queue->remote_insert,
  24867. + queue->process);
  24868. +
  24869. + WARN_ON(!((int)(queue->local_insert - queue->process) > 0));
  24870. + WARN_ON(!((int)(queue->remote_insert - queue->process) > 0));
  24871. +
  24872. + rc = mutex_lock_interruptible(&state->bulk_transfer_mutex);
  24873. + if (rc != 0)
  24874. + break;
  24875. +
  24876. + vchiq_transfer_bulk(bulk);
  24877. + mutex_unlock(&state->bulk_transfer_mutex);
  24878. +
  24879. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  24880. + const char *header = (queue == &service->bulk_tx) ?
  24881. + "Send Bulk to" : "Recv Bulk from";
  24882. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED)
  24883. + vchiq_log_info(vchiq_core_msg_log_level,
  24884. + "%s %c%c%c%c d:%d len:%d %x<->%x",
  24885. + header,
  24886. + VCHIQ_FOURCC_AS_4CHARS(
  24887. + service->base.fourcc),
  24888. + service->remoteport,
  24889. + bulk->size,
  24890. + (unsigned int)bulk->data,
  24891. + (unsigned int)bulk->remote_data);
  24892. + else
  24893. + vchiq_log_info(vchiq_core_msg_log_level,
  24894. + "%s %c%c%c%c d:%d ABORTED - tx len:%d,"
  24895. + " rx len:%d %x<->%x",
  24896. + header,
  24897. + VCHIQ_FOURCC_AS_4CHARS(
  24898. + service->base.fourcc),
  24899. + service->remoteport,
  24900. + bulk->size,
  24901. + bulk->remote_size,
  24902. + (unsigned int)bulk->data,
  24903. + (unsigned int)bulk->remote_data);
  24904. + }
  24905. +
  24906. + vchiq_complete_bulk(bulk);
  24907. + queue->process++;
  24908. + resolved++;
  24909. + }
  24910. + return resolved;
  24911. +}
  24912. +
  24913. +/* Called with the bulk_mutex held */
  24914. +static void
  24915. +abort_outstanding_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  24916. +{
  24917. + int is_tx = (queue == &service->bulk_tx);
  24918. + vchiq_log_trace(vchiq_core_log_level,
  24919. + "%d: aob:%d %cx - li=%x ri=%x p=%x",
  24920. + service->state->id, service->localport, is_tx ? 't' : 'r',
  24921. + queue->local_insert, queue->remote_insert, queue->process);
  24922. +
  24923. + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0));
  24924. + WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0));
  24925. +
  24926. + while ((queue->process != queue->local_insert) ||
  24927. + (queue->process != queue->remote_insert)) {
  24928. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  24929. +
  24930. + if (queue->process == queue->remote_insert) {
  24931. + /* fabricate a matching dummy bulk */
  24932. + bulk->remote_data = NULL;
  24933. + bulk->remote_size = 0;
  24934. + queue->remote_insert++;
  24935. + }
  24936. +
  24937. + if (queue->process != queue->local_insert) {
  24938. + vchiq_complete_bulk(bulk);
  24939. +
  24940. + vchiq_log_info(vchiq_core_msg_log_level,
  24941. + "%s %c%c%c%c d:%d ABORTED - tx len:%d, "
  24942. + "rx len:%d",
  24943. + is_tx ? "Send Bulk to" : "Recv Bulk from",
  24944. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  24945. + service->remoteport,
  24946. + bulk->size,
  24947. + bulk->remote_size);
  24948. + } else {
  24949. + /* fabricate a matching dummy bulk */
  24950. + bulk->data = NULL;
  24951. + bulk->size = 0;
  24952. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  24953. + bulk->dir = is_tx ? VCHIQ_BULK_TRANSMIT :
  24954. + VCHIQ_BULK_RECEIVE;
  24955. + queue->local_insert++;
  24956. + }
  24957. +
  24958. + queue->process++;
  24959. + }
  24960. +}
  24961. +
  24962. +/* Called from the slot handler thread */
  24963. +static void
  24964. +pause_bulks(VCHIQ_STATE_T *state)
  24965. +{
  24966. + if (unlikely(atomic_inc_return(&pause_bulks_count) != 1)) {
  24967. + WARN_ON_ONCE(1);
  24968. + atomic_set(&pause_bulks_count, 1);
  24969. + return;
  24970. + }
  24971. +
  24972. + /* Block bulk transfers from all services */
  24973. + mutex_lock(&state->bulk_transfer_mutex);
  24974. +}
  24975. +
  24976. +/* Called from the slot handler thread */
  24977. +static void
  24978. +resume_bulks(VCHIQ_STATE_T *state)
  24979. +{
  24980. + int i;
  24981. + if (unlikely(atomic_dec_return(&pause_bulks_count) != 0)) {
  24982. + WARN_ON_ONCE(1);
  24983. + atomic_set(&pause_bulks_count, 0);
  24984. + return;
  24985. + }
  24986. +
  24987. + /* Allow bulk transfers from all services */
  24988. + mutex_unlock(&state->bulk_transfer_mutex);
  24989. +
  24990. + if (state->deferred_bulks == 0)
  24991. + return;
  24992. +
  24993. + /* Deal with any bulks which had to be deferred due to being in
  24994. + * paused state. Don't try to match up to number of deferred bulks
  24995. + * in case we've had something come and close the service in the
  24996. + * interim - just process all bulk queues for all services */
  24997. + vchiq_log_info(vchiq_core_log_level, "%s: processing %d deferred bulks",
  24998. + __func__, state->deferred_bulks);
  24999. +
  25000. + for (i = 0; i < state->unused_service; i++) {
  25001. + VCHIQ_SERVICE_T *service = state->services[i];
  25002. + int resolved_rx = 0;
  25003. + int resolved_tx = 0;
  25004. + if (!service || (service->srvstate != VCHIQ_SRVSTATE_OPEN))
  25005. + continue;
  25006. +
  25007. + mutex_lock(&service->bulk_mutex);
  25008. + resolved_rx = resolve_bulks(service, &service->bulk_rx);
  25009. + resolved_tx = resolve_bulks(service, &service->bulk_tx);
  25010. + mutex_unlock(&service->bulk_mutex);
  25011. + if (resolved_rx)
  25012. + notify_bulks(service, &service->bulk_rx, 1);
  25013. + if (resolved_tx)
  25014. + notify_bulks(service, &service->bulk_tx, 1);
  25015. + }
  25016. + state->deferred_bulks = 0;
  25017. +}
  25018. +
  25019. +static int
  25020. +parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  25021. +{
  25022. + VCHIQ_SERVICE_T *service = NULL;
  25023. + int msgid, size;
  25024. + int type;
  25025. + unsigned int localport, remoteport;
  25026. +
  25027. + msgid = header->msgid;
  25028. + size = header->size;
  25029. + type = VCHIQ_MSG_TYPE(msgid);
  25030. + localport = VCHIQ_MSG_DSTPORT(msgid);
  25031. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  25032. + if (size >= sizeof(struct vchiq_open_payload)) {
  25033. + const struct vchiq_open_payload *payload =
  25034. + (struct vchiq_open_payload *)header->data;
  25035. + unsigned int fourcc;
  25036. +
  25037. + fourcc = payload->fourcc;
  25038. + vchiq_log_info(vchiq_core_log_level,
  25039. + "%d: prs OPEN@%x (%d->'%c%c%c%c')",
  25040. + state->id, (unsigned int)header,
  25041. + localport,
  25042. + VCHIQ_FOURCC_AS_4CHARS(fourcc));
  25043. +
  25044. + service = get_listening_service(state, fourcc);
  25045. +
  25046. + if (service) {
  25047. + /* A matching service exists */
  25048. + short version = payload->version;
  25049. + short version_min = payload->version_min;
  25050. + if ((service->version < version_min) ||
  25051. + (version < service->version_min)) {
  25052. + /* Version mismatch */
  25053. + vchiq_loud_error_header();
  25054. + vchiq_loud_error("%d: service %d (%c%c%c%c) "
  25055. + "version mismatch - local (%d, min %d)"
  25056. + " vs. remote (%d, min %d)",
  25057. + state->id, service->localport,
  25058. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  25059. + service->version, service->version_min,
  25060. + version, version_min);
  25061. + vchiq_loud_error_footer();
  25062. + unlock_service(service);
  25063. + service = NULL;
  25064. + goto fail_open;
  25065. + }
  25066. + service->peer_version = version;
  25067. +
  25068. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  25069. + struct vchiq_openack_payload ack_payload = {
  25070. + service->version
  25071. + };
  25072. + VCHIQ_ELEMENT_T body = {
  25073. + &ack_payload,
  25074. + sizeof(ack_payload)
  25075. + };
  25076. +
  25077. + /* Acknowledge the OPEN */
  25078. + if (service->sync) {
  25079. + if (queue_message_sync(state, NULL,
  25080. + VCHIQ_MAKE_MSG(
  25081. + VCHIQ_MSG_OPENACK,
  25082. + service->localport,
  25083. + remoteport),
  25084. + &body, 1, sizeof(ack_payload),
  25085. + 0) == VCHIQ_RETRY)
  25086. + goto bail_not_ready;
  25087. + } else {
  25088. + if (queue_message(state, NULL,
  25089. + VCHIQ_MAKE_MSG(
  25090. + VCHIQ_MSG_OPENACK,
  25091. + service->localport,
  25092. + remoteport),
  25093. + &body, 1, sizeof(ack_payload),
  25094. + 0) == VCHIQ_RETRY)
  25095. + goto bail_not_ready;
  25096. + }
  25097. +
  25098. + /* The service is now open */
  25099. + vchiq_set_service_state(service,
  25100. + service->sync ? VCHIQ_SRVSTATE_OPENSYNC
  25101. + : VCHIQ_SRVSTATE_OPEN);
  25102. + }
  25103. +
  25104. + service->remoteport = remoteport;
  25105. + service->client_id = ((int *)header->data)[1];
  25106. + if (make_service_callback(service, VCHIQ_SERVICE_OPENED,
  25107. + NULL, NULL) == VCHIQ_RETRY) {
  25108. + /* Bail out if not ready */
  25109. + service->remoteport = VCHIQ_PORT_FREE;
  25110. + goto bail_not_ready;
  25111. + }
  25112. +
  25113. + /* Success - the message has been dealt with */
  25114. + unlock_service(service);
  25115. + return 1;
  25116. + }
  25117. + }
  25118. +
  25119. +fail_open:
  25120. + /* No available service, or an invalid request - send a CLOSE */
  25121. + if (queue_message(state, NULL,
  25122. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
  25123. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  25124. + goto bail_not_ready;
  25125. +
  25126. + return 1;
  25127. +
  25128. +bail_not_ready:
  25129. + if (service)
  25130. + unlock_service(service);
  25131. +
  25132. + return 0;
  25133. +}
  25134. +
  25135. +/* Called by the slot handler thread */
  25136. +static void
  25137. +parse_rx_slots(VCHIQ_STATE_T *state)
  25138. +{
  25139. + VCHIQ_SHARED_STATE_T *remote = state->remote;
  25140. + VCHIQ_SERVICE_T *service = NULL;
  25141. + int tx_pos;
  25142. + DEBUG_INITIALISE(state->local)
  25143. +
  25144. + tx_pos = remote->tx_pos;
  25145. +
  25146. + while (state->rx_pos != tx_pos) {
  25147. + VCHIQ_HEADER_T *header;
  25148. + int msgid, size;
  25149. + int type;
  25150. + unsigned int localport, remoteport;
  25151. +
  25152. + DEBUG_TRACE(PARSE_LINE);
  25153. + if (!state->rx_data) {
  25154. + int rx_index;
  25155. + WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0));
  25156. + rx_index = remote->slot_queue[
  25157. + SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) &
  25158. + VCHIQ_SLOT_QUEUE_MASK];
  25159. + state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state,
  25160. + rx_index);
  25161. + state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index);
  25162. +
  25163. + /* Initialise use_count to one, and increment
  25164. + ** release_count at the end of the slot to avoid
  25165. + ** releasing the slot prematurely. */
  25166. + state->rx_info->use_count = 1;
  25167. + state->rx_info->release_count = 0;
  25168. + }
  25169. +
  25170. + header = (VCHIQ_HEADER_T *)(state->rx_data +
  25171. + (state->rx_pos & VCHIQ_SLOT_MASK));
  25172. + DEBUG_VALUE(PARSE_HEADER, (int)header);
  25173. + msgid = header->msgid;
  25174. + DEBUG_VALUE(PARSE_MSGID, msgid);
  25175. + size = header->size;
  25176. + type = VCHIQ_MSG_TYPE(msgid);
  25177. + localport = VCHIQ_MSG_DSTPORT(msgid);
  25178. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  25179. +
  25180. + if (type != VCHIQ_MSG_DATA)
  25181. + VCHIQ_STATS_INC(state, ctrl_rx_count);
  25182. +
  25183. + switch (type) {
  25184. + case VCHIQ_MSG_OPENACK:
  25185. + case VCHIQ_MSG_CLOSE:
  25186. + case VCHIQ_MSG_DATA:
  25187. + case VCHIQ_MSG_BULK_RX:
  25188. + case VCHIQ_MSG_BULK_TX:
  25189. + case VCHIQ_MSG_BULK_RX_DONE:
  25190. + case VCHIQ_MSG_BULK_TX_DONE:
  25191. + service = find_service_by_port(state, localport);
  25192. + if ((!service || service->remoteport != remoteport) &&
  25193. + (localport == 0) &&
  25194. + (type == VCHIQ_MSG_CLOSE)) {
  25195. + /* This could be a CLOSE from a client which
  25196. + hadn't yet received the OPENACK - look for
  25197. + the connected service */
  25198. + if (service)
  25199. + unlock_service(service);
  25200. + service = get_connected_service(state,
  25201. + remoteport);
  25202. + if (service)
  25203. + vchiq_log_warning(vchiq_core_log_level,
  25204. + "%d: prs %s@%x (%d->%d) - "
  25205. + "found connected service %d",
  25206. + state->id, msg_type_str(type),
  25207. + (unsigned int)header,
  25208. + remoteport, localport,
  25209. + service->localport);
  25210. + }
  25211. +
  25212. + if (!service) {
  25213. + vchiq_log_error(vchiq_core_log_level,
  25214. + "%d: prs %s@%x (%d->%d) - "
  25215. + "invalid/closed service %d",
  25216. + state->id, msg_type_str(type),
  25217. + (unsigned int)header,
  25218. + remoteport, localport, localport);
  25219. + goto skip_message;
  25220. + }
  25221. + break;
  25222. + default:
  25223. + break;
  25224. + }
  25225. +
  25226. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  25227. + int svc_fourcc;
  25228. +
  25229. + svc_fourcc = service
  25230. + ? service->base.fourcc
  25231. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25232. + vchiq_log_info(vchiq_core_msg_log_level,
  25233. + "Rcvd Msg %s(%u) from %c%c%c%c s:%d d:%d "
  25234. + "len:%d",
  25235. + msg_type_str(type), type,
  25236. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25237. + remoteport, localport, size);
  25238. + if (size > 0)
  25239. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  25240. + min(64, size));
  25241. + }
  25242. +
  25243. + if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
  25244. + > VCHIQ_SLOT_SIZE) {
  25245. + vchiq_log_error(vchiq_core_log_level,
  25246. + "header %x (msgid %x) - size %x too big for "
  25247. + "slot",
  25248. + (unsigned int)header, (unsigned int)msgid,
  25249. + (unsigned int)size);
  25250. + WARN(1, "oversized for slot\n");
  25251. + }
  25252. +
  25253. + switch (type) {
  25254. + case VCHIQ_MSG_OPEN:
  25255. + WARN_ON(!(VCHIQ_MSG_DSTPORT(msgid) == 0));
  25256. + if (!parse_open(state, header))
  25257. + goto bail_not_ready;
  25258. + break;
  25259. + case VCHIQ_MSG_OPENACK:
  25260. + if (size >= sizeof(struct vchiq_openack_payload)) {
  25261. + const struct vchiq_openack_payload *payload =
  25262. + (struct vchiq_openack_payload *)
  25263. + header->data;
  25264. + service->peer_version = payload->version;
  25265. + }
  25266. + vchiq_log_info(vchiq_core_log_level,
  25267. + "%d: prs OPENACK@%x,%x (%d->%d) v:%d",
  25268. + state->id, (unsigned int)header, size,
  25269. + remoteport, localport, service->peer_version);
  25270. + if (service->srvstate ==
  25271. + VCHIQ_SRVSTATE_OPENING) {
  25272. + service->remoteport = remoteport;
  25273. + vchiq_set_service_state(service,
  25274. + VCHIQ_SRVSTATE_OPEN);
  25275. + up(&service->remove_event);
  25276. + } else
  25277. + vchiq_log_error(vchiq_core_log_level,
  25278. + "OPENACK received in state %s",
  25279. + srvstate_names[service->srvstate]);
  25280. + break;
  25281. + case VCHIQ_MSG_CLOSE:
  25282. + WARN_ON(size != 0); /* There should be no data */
  25283. +
  25284. + vchiq_log_info(vchiq_core_log_level,
  25285. + "%d: prs CLOSE@%x (%d->%d)",
  25286. + state->id, (unsigned int)header,
  25287. + remoteport, localport);
  25288. +
  25289. + mark_service_closing_internal(service, 1);
  25290. +
  25291. + if (vchiq_close_service_internal(service,
  25292. + 1/*close_recvd*/) == VCHIQ_RETRY)
  25293. + goto bail_not_ready;
  25294. +
  25295. + vchiq_log_info(vchiq_core_log_level,
  25296. + "Close Service %c%c%c%c s:%u d:%d",
  25297. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  25298. + service->localport,
  25299. + service->remoteport);
  25300. + break;
  25301. + case VCHIQ_MSG_DATA:
  25302. + vchiq_log_trace(vchiq_core_log_level,
  25303. + "%d: prs DATA@%x,%x (%d->%d)",
  25304. + state->id, (unsigned int)header, size,
  25305. + remoteport, localport);
  25306. +
  25307. + if ((service->remoteport == remoteport)
  25308. + && (service->srvstate ==
  25309. + VCHIQ_SRVSTATE_OPEN)) {
  25310. + header->msgid = msgid | VCHIQ_MSGID_CLAIMED;
  25311. + claim_slot(state->rx_info);
  25312. + DEBUG_TRACE(PARSE_LINE);
  25313. + if (make_service_callback(service,
  25314. + VCHIQ_MESSAGE_AVAILABLE, header,
  25315. + NULL) == VCHIQ_RETRY) {
  25316. + DEBUG_TRACE(PARSE_LINE);
  25317. + goto bail_not_ready;
  25318. + }
  25319. + VCHIQ_SERVICE_STATS_INC(service, ctrl_rx_count);
  25320. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_rx_bytes,
  25321. + size);
  25322. + } else {
  25323. + VCHIQ_STATS_INC(state, error_count);
  25324. + }
  25325. + break;
  25326. + case VCHIQ_MSG_CONNECT:
  25327. + vchiq_log_info(vchiq_core_log_level,
  25328. + "%d: prs CONNECT@%x",
  25329. + state->id, (unsigned int)header);
  25330. + up(&state->connect);
  25331. + break;
  25332. + case VCHIQ_MSG_BULK_RX:
  25333. + case VCHIQ_MSG_BULK_TX: {
  25334. + VCHIQ_BULK_QUEUE_T *queue;
  25335. + WARN_ON(!state->is_master);
  25336. + queue = (type == VCHIQ_MSG_BULK_RX) ?
  25337. + &service->bulk_tx : &service->bulk_rx;
  25338. + if ((service->remoteport == remoteport)
  25339. + && (service->srvstate ==
  25340. + VCHIQ_SRVSTATE_OPEN)) {
  25341. + VCHIQ_BULK_T *bulk;
  25342. + int resolved = 0;
  25343. +
  25344. + DEBUG_TRACE(PARSE_LINE);
  25345. + if (mutex_lock_interruptible(
  25346. + &service->bulk_mutex) != 0) {
  25347. + DEBUG_TRACE(PARSE_LINE);
  25348. + goto bail_not_ready;
  25349. + }
  25350. +
  25351. + WARN_ON(!(queue->remote_insert < queue->remove +
  25352. + VCHIQ_NUM_SERVICE_BULKS));
  25353. + bulk = &queue->bulks[
  25354. + BULK_INDEX(queue->remote_insert)];
  25355. + bulk->remote_data =
  25356. + (void *)((int *)header->data)[0];
  25357. + bulk->remote_size = ((int *)header->data)[1];
  25358. + wmb();
  25359. +
  25360. + vchiq_log_info(vchiq_core_log_level,
  25361. + "%d: prs %s@%x (%d->%d) %x@%x",
  25362. + state->id, msg_type_str(type),
  25363. + (unsigned int)header,
  25364. + remoteport, localport,
  25365. + bulk->remote_size,
  25366. + (unsigned int)bulk->remote_data);
  25367. +
  25368. + queue->remote_insert++;
  25369. +
  25370. + if (atomic_read(&pause_bulks_count)) {
  25371. + state->deferred_bulks++;
  25372. + vchiq_log_info(vchiq_core_log_level,
  25373. + "%s: deferring bulk (%d)",
  25374. + __func__,
  25375. + state->deferred_bulks);
  25376. + if (state->conn_state !=
  25377. + VCHIQ_CONNSTATE_PAUSE_SENT)
  25378. + vchiq_log_error(
  25379. + vchiq_core_log_level,
  25380. + "%s: bulks paused in "
  25381. + "unexpected state %s",
  25382. + __func__,
  25383. + conn_state_names[
  25384. + state->conn_state]);
  25385. + } else if (state->conn_state ==
  25386. + VCHIQ_CONNSTATE_CONNECTED) {
  25387. + DEBUG_TRACE(PARSE_LINE);
  25388. + resolved = resolve_bulks(service,
  25389. + queue);
  25390. + }
  25391. +
  25392. + mutex_unlock(&service->bulk_mutex);
  25393. + if (resolved)
  25394. + notify_bulks(service, queue,
  25395. + 1/*retry_poll*/);
  25396. + }
  25397. + } break;
  25398. + case VCHIQ_MSG_BULK_RX_DONE:
  25399. + case VCHIQ_MSG_BULK_TX_DONE:
  25400. + WARN_ON(state->is_master);
  25401. + if ((service->remoteport == remoteport)
  25402. + && (service->srvstate !=
  25403. + VCHIQ_SRVSTATE_FREE)) {
  25404. + VCHIQ_BULK_QUEUE_T *queue;
  25405. + VCHIQ_BULK_T *bulk;
  25406. +
  25407. + queue = (type == VCHIQ_MSG_BULK_RX_DONE) ?
  25408. + &service->bulk_rx : &service->bulk_tx;
  25409. +
  25410. + DEBUG_TRACE(PARSE_LINE);
  25411. + if (mutex_lock_interruptible(
  25412. + &service->bulk_mutex) != 0) {
  25413. + DEBUG_TRACE(PARSE_LINE);
  25414. + goto bail_not_ready;
  25415. + }
  25416. + if ((int)(queue->remote_insert -
  25417. + queue->local_insert) >= 0) {
  25418. + vchiq_log_error(vchiq_core_log_level,
  25419. + "%d: prs %s@%x (%d->%d) "
  25420. + "unexpected (ri=%d,li=%d)",
  25421. + state->id, msg_type_str(type),
  25422. + (unsigned int)header,
  25423. + remoteport, localport,
  25424. + queue->remote_insert,
  25425. + queue->local_insert);
  25426. + mutex_unlock(&service->bulk_mutex);
  25427. + break;
  25428. + }
  25429. +
  25430. + BUG_ON(queue->process == queue->local_insert);
  25431. + BUG_ON(queue->process != queue->remote_insert);
  25432. +
  25433. + bulk = &queue->bulks[
  25434. + BULK_INDEX(queue->remote_insert)];
  25435. + bulk->actual = *(int *)header->data;
  25436. + queue->remote_insert++;
  25437. +
  25438. + vchiq_log_info(vchiq_core_log_level,
  25439. + "%d: prs %s@%x (%d->%d) %x@%x",
  25440. + state->id, msg_type_str(type),
  25441. + (unsigned int)header,
  25442. + remoteport, localport,
  25443. + bulk->actual, (unsigned int)bulk->data);
  25444. +
  25445. + vchiq_log_trace(vchiq_core_log_level,
  25446. + "%d: prs:%d %cx li=%x ri=%x p=%x",
  25447. + state->id, localport,
  25448. + (type == VCHIQ_MSG_BULK_RX_DONE) ?
  25449. + 'r' : 't',
  25450. + queue->local_insert,
  25451. + queue->remote_insert, queue->process);
  25452. +
  25453. + DEBUG_TRACE(PARSE_LINE);
  25454. + WARN_ON(queue->process == queue->local_insert);
  25455. + vchiq_complete_bulk(bulk);
  25456. + queue->process++;
  25457. + mutex_unlock(&service->bulk_mutex);
  25458. + DEBUG_TRACE(PARSE_LINE);
  25459. + notify_bulks(service, queue, 1/*retry_poll*/);
  25460. + DEBUG_TRACE(PARSE_LINE);
  25461. + }
  25462. + break;
  25463. + case VCHIQ_MSG_PADDING:
  25464. + vchiq_log_trace(vchiq_core_log_level,
  25465. + "%d: prs PADDING@%x,%x",
  25466. + state->id, (unsigned int)header, size);
  25467. + break;
  25468. + case VCHIQ_MSG_PAUSE:
  25469. + /* If initiated, signal the application thread */
  25470. + vchiq_log_trace(vchiq_core_log_level,
  25471. + "%d: prs PAUSE@%x,%x",
  25472. + state->id, (unsigned int)header, size);
  25473. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  25474. + vchiq_log_error(vchiq_core_log_level,
  25475. + "%d: PAUSE received in state PAUSED",
  25476. + state->id);
  25477. + break;
  25478. + }
  25479. + if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
  25480. + /* Send a PAUSE in response */
  25481. + if (queue_message(state, NULL,
  25482. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  25483. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  25484. + goto bail_not_ready;
  25485. + if (state->is_master)
  25486. + pause_bulks(state);
  25487. + }
  25488. + /* At this point slot_mutex is held */
  25489. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED);
  25490. + vchiq_platform_paused(state);
  25491. + break;
  25492. + case VCHIQ_MSG_RESUME:
  25493. + vchiq_log_trace(vchiq_core_log_level,
  25494. + "%d: prs RESUME@%x,%x",
  25495. + state->id, (unsigned int)header, size);
  25496. + /* Release the slot mutex */
  25497. + mutex_unlock(&state->slot_mutex);
  25498. + if (state->is_master)
  25499. + resume_bulks(state);
  25500. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  25501. + vchiq_platform_resumed(state);
  25502. + break;
  25503. +
  25504. + case VCHIQ_MSG_REMOTE_USE:
  25505. + vchiq_on_remote_use(state);
  25506. + break;
  25507. + case VCHIQ_MSG_REMOTE_RELEASE:
  25508. + vchiq_on_remote_release(state);
  25509. + break;
  25510. + case VCHIQ_MSG_REMOTE_USE_ACTIVE:
  25511. + vchiq_on_remote_use_active(state);
  25512. + break;
  25513. +
  25514. + default:
  25515. + vchiq_log_error(vchiq_core_log_level,
  25516. + "%d: prs invalid msgid %x@%x,%x",
  25517. + state->id, msgid, (unsigned int)header, size);
  25518. + WARN(1, "invalid message\n");
  25519. + break;
  25520. + }
  25521. +
  25522. +skip_message:
  25523. + if (service) {
  25524. + unlock_service(service);
  25525. + service = NULL;
  25526. + }
  25527. +
  25528. + state->rx_pos += calc_stride(size);
  25529. +
  25530. + DEBUG_TRACE(PARSE_LINE);
  25531. + /* Perform some housekeeping when the end of the slot is
  25532. + ** reached. */
  25533. + if ((state->rx_pos & VCHIQ_SLOT_MASK) == 0) {
  25534. + /* Remove the extra reference count. */
  25535. + release_slot(state, state->rx_info, NULL, NULL);
  25536. + state->rx_data = NULL;
  25537. + }
  25538. + }
  25539. +
  25540. +bail_not_ready:
  25541. + if (service)
  25542. + unlock_service(service);
  25543. +}
  25544. +
  25545. +/* Called by the slot handler thread */
  25546. +static int
  25547. +slot_handler_func(void *v)
  25548. +{
  25549. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  25550. + VCHIQ_SHARED_STATE_T *local = state->local;
  25551. + DEBUG_INITIALISE(local)
  25552. +
  25553. + while (1) {
  25554. + DEBUG_COUNT(SLOT_HANDLER_COUNT);
  25555. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  25556. + remote_event_wait(&local->trigger);
  25557. +
  25558. + rmb();
  25559. +
  25560. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  25561. + if (state->poll_needed) {
  25562. + /* Check if we need to suspend - may change our
  25563. + * conn_state */
  25564. + vchiq_platform_check_suspend(state);
  25565. +
  25566. + state->poll_needed = 0;
  25567. +
  25568. + /* Handle service polling and other rare conditions here
  25569. + ** out of the mainline code */
  25570. + switch (state->conn_state) {
  25571. + case VCHIQ_CONNSTATE_CONNECTED:
  25572. + /* Poll the services as requested */
  25573. + poll_services(state);
  25574. + break;
  25575. +
  25576. + case VCHIQ_CONNSTATE_PAUSING:
  25577. + if (state->is_master)
  25578. + pause_bulks(state);
  25579. + if (queue_message(state, NULL,
  25580. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  25581. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  25582. + vchiq_set_conn_state(state,
  25583. + VCHIQ_CONNSTATE_PAUSE_SENT);
  25584. + } else {
  25585. + if (state->is_master)
  25586. + resume_bulks(state);
  25587. + /* Retry later */
  25588. + state->poll_needed = 1;
  25589. + }
  25590. + break;
  25591. +
  25592. + case VCHIQ_CONNSTATE_PAUSED:
  25593. + vchiq_platform_resume(state);
  25594. + break;
  25595. +
  25596. + case VCHIQ_CONNSTATE_RESUMING:
  25597. + if (queue_message(state, NULL,
  25598. + VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
  25599. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  25600. + if (state->is_master)
  25601. + resume_bulks(state);
  25602. + vchiq_set_conn_state(state,
  25603. + VCHIQ_CONNSTATE_CONNECTED);
  25604. + vchiq_platform_resumed(state);
  25605. + } else {
  25606. + /* This should really be impossible,
  25607. + ** since the PAUSE should have flushed
  25608. + ** through outstanding messages. */
  25609. + vchiq_log_error(vchiq_core_log_level,
  25610. + "Failed to send RESUME "
  25611. + "message");
  25612. + BUG();
  25613. + }
  25614. + break;
  25615. +
  25616. + case VCHIQ_CONNSTATE_PAUSE_TIMEOUT:
  25617. + case VCHIQ_CONNSTATE_RESUME_TIMEOUT:
  25618. + vchiq_platform_handle_timeout(state);
  25619. + break;
  25620. + default:
  25621. + break;
  25622. + }
  25623. +
  25624. +
  25625. + }
  25626. +
  25627. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  25628. + parse_rx_slots(state);
  25629. + }
  25630. + return 0;
  25631. +}
  25632. +
  25633. +
  25634. +/* Called by the recycle thread */
  25635. +static int
  25636. +recycle_func(void *v)
  25637. +{
  25638. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  25639. + VCHIQ_SHARED_STATE_T *local = state->local;
  25640. +
  25641. + while (1) {
  25642. + remote_event_wait(&local->recycle);
  25643. +
  25644. + process_free_queue(state);
  25645. + }
  25646. + return 0;
  25647. +}
  25648. +
  25649. +
  25650. +/* Called by the sync thread */
  25651. +static int
  25652. +sync_func(void *v)
  25653. +{
  25654. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  25655. + VCHIQ_SHARED_STATE_T *local = state->local;
  25656. + VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  25657. + state->remote->slot_sync);
  25658. +
  25659. + while (1) {
  25660. + VCHIQ_SERVICE_T *service;
  25661. + int msgid, size;
  25662. + int type;
  25663. + unsigned int localport, remoteport;
  25664. +
  25665. + remote_event_wait(&local->sync_trigger);
  25666. +
  25667. + rmb();
  25668. +
  25669. + msgid = header->msgid;
  25670. + size = header->size;
  25671. + type = VCHIQ_MSG_TYPE(msgid);
  25672. + localport = VCHIQ_MSG_DSTPORT(msgid);
  25673. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  25674. +
  25675. + service = find_service_by_port(state, localport);
  25676. +
  25677. + if (!service) {
  25678. + vchiq_log_error(vchiq_sync_log_level,
  25679. + "%d: sf %s@%x (%d->%d) - "
  25680. + "invalid/closed service %d",
  25681. + state->id, msg_type_str(type),
  25682. + (unsigned int)header,
  25683. + remoteport, localport, localport);
  25684. + release_message_sync(state, header);
  25685. + continue;
  25686. + }
  25687. +
  25688. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  25689. + int svc_fourcc;
  25690. +
  25691. + svc_fourcc = service
  25692. + ? service->base.fourcc
  25693. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25694. + vchiq_log_trace(vchiq_sync_log_level,
  25695. + "Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d",
  25696. + msg_type_str(type),
  25697. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25698. + remoteport, localport, size);
  25699. + if (size > 0)
  25700. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  25701. + min(64, size));
  25702. + }
  25703. +
  25704. + switch (type) {
  25705. + case VCHIQ_MSG_OPENACK:
  25706. + if (size >= sizeof(struct vchiq_openack_payload)) {
  25707. + const struct vchiq_openack_payload *payload =
  25708. + (struct vchiq_openack_payload *)
  25709. + header->data;
  25710. + service->peer_version = payload->version;
  25711. + }
  25712. + vchiq_log_info(vchiq_sync_log_level,
  25713. + "%d: sf OPENACK@%x,%x (%d->%d) v:%d",
  25714. + state->id, (unsigned int)header, size,
  25715. + remoteport, localport, service->peer_version);
  25716. + if (service->srvstate == VCHIQ_SRVSTATE_OPENING) {
  25717. + service->remoteport = remoteport;
  25718. + vchiq_set_service_state(service,
  25719. + VCHIQ_SRVSTATE_OPENSYNC);
  25720. + up(&service->remove_event);
  25721. + }
  25722. + release_message_sync(state, header);
  25723. + break;
  25724. +
  25725. + case VCHIQ_MSG_DATA:
  25726. + vchiq_log_trace(vchiq_sync_log_level,
  25727. + "%d: sf DATA@%x,%x (%d->%d)",
  25728. + state->id, (unsigned int)header, size,
  25729. + remoteport, localport);
  25730. +
  25731. + if ((service->remoteport == remoteport) &&
  25732. + (service->srvstate ==
  25733. + VCHIQ_SRVSTATE_OPENSYNC)) {
  25734. + if (make_service_callback(service,
  25735. + VCHIQ_MESSAGE_AVAILABLE, header,
  25736. + NULL) == VCHIQ_RETRY)
  25737. + vchiq_log_error(vchiq_sync_log_level,
  25738. + "synchronous callback to "
  25739. + "service %d returns "
  25740. + "VCHIQ_RETRY",
  25741. + localport);
  25742. + }
  25743. + break;
  25744. +
  25745. + default:
  25746. + vchiq_log_error(vchiq_sync_log_level,
  25747. + "%d: sf unexpected msgid %x@%x,%x",
  25748. + state->id, msgid, (unsigned int)header, size);
  25749. + release_message_sync(state, header);
  25750. + break;
  25751. + }
  25752. +
  25753. + unlock_service(service);
  25754. + }
  25755. +
  25756. + return 0;
  25757. +}
  25758. +
  25759. +
  25760. +static void
  25761. +init_bulk_queue(VCHIQ_BULK_QUEUE_T *queue)
  25762. +{
  25763. + queue->local_insert = 0;
  25764. + queue->remote_insert = 0;
  25765. + queue->process = 0;
  25766. + queue->remote_notify = 0;
  25767. + queue->remove = 0;
  25768. +}
  25769. +
  25770. +
  25771. +inline const char *
  25772. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
  25773. +{
  25774. + return conn_state_names[conn_state];
  25775. +}
  25776. +
  25777. +
  25778. +VCHIQ_SLOT_ZERO_T *
  25779. +vchiq_init_slots(void *mem_base, int mem_size)
  25780. +{
  25781. + int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
  25782. + VCHIQ_SLOT_ZERO_T *slot_zero =
  25783. + (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
  25784. + int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
  25785. + int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
  25786. +
  25787. + /* Ensure there is enough memory to run an absolutely minimum system */
  25788. + num_slots -= first_data_slot;
  25789. +
  25790. + if (num_slots < 4) {
  25791. + vchiq_log_error(vchiq_core_log_level,
  25792. + "vchiq_init_slots - insufficient memory %x bytes",
  25793. + mem_size);
  25794. + return NULL;
  25795. + }
  25796. +
  25797. + memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T));
  25798. +
  25799. + slot_zero->magic = VCHIQ_MAGIC;
  25800. + slot_zero->version = VCHIQ_VERSION;
  25801. + slot_zero->version_min = VCHIQ_VERSION_MIN;
  25802. + slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T);
  25803. + slot_zero->slot_size = VCHIQ_SLOT_SIZE;
  25804. + slot_zero->max_slots = VCHIQ_MAX_SLOTS;
  25805. + slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE;
  25806. +
  25807. + slot_zero->master.slot_sync = first_data_slot;
  25808. + slot_zero->master.slot_first = first_data_slot + 1;
  25809. + slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1;
  25810. + slot_zero->slave.slot_sync = first_data_slot + (num_slots/2);
  25811. + slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1;
  25812. + slot_zero->slave.slot_last = first_data_slot + num_slots - 1;
  25813. +
  25814. + return slot_zero;
  25815. +}
  25816. +
  25817. +VCHIQ_STATUS_T
  25818. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  25819. + int is_master)
  25820. +{
  25821. + VCHIQ_SHARED_STATE_T *local;
  25822. + VCHIQ_SHARED_STATE_T *remote;
  25823. + VCHIQ_STATUS_T status;
  25824. + char threadname[10];
  25825. + static int id;
  25826. + int i;
  25827. +
  25828. + vchiq_log_warning(vchiq_core_log_level,
  25829. + "%s: slot_zero = 0x%08lx, is_master = %d",
  25830. + __func__, (unsigned long)slot_zero, is_master);
  25831. +
  25832. + /* Check the input configuration */
  25833. +
  25834. + if (slot_zero->magic != VCHIQ_MAGIC) {
  25835. + vchiq_loud_error_header();
  25836. + vchiq_loud_error("Invalid VCHIQ magic value found.");
  25837. + vchiq_loud_error("slot_zero=%x: magic=%x (expected %x)",
  25838. + (unsigned int)slot_zero, slot_zero->magic, VCHIQ_MAGIC);
  25839. + vchiq_loud_error_footer();
  25840. + return VCHIQ_ERROR;
  25841. + }
  25842. +
  25843. + if (slot_zero->version < VCHIQ_VERSION_MIN) {
  25844. + vchiq_loud_error_header();
  25845. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  25846. + vchiq_loud_error("slot_zero=%x: VideoCore version=%d "
  25847. + "(minimum %d)",
  25848. + (unsigned int)slot_zero, slot_zero->version,
  25849. + VCHIQ_VERSION_MIN);
  25850. + vchiq_loud_error("Restart with a newer VideoCore image.");
  25851. + vchiq_loud_error_footer();
  25852. + return VCHIQ_ERROR;
  25853. + }
  25854. +
  25855. + if (VCHIQ_VERSION < slot_zero->version_min) {
  25856. + vchiq_loud_error_header();
  25857. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  25858. + vchiq_loud_error("slot_zero=%x: version=%d (VideoCore "
  25859. + "minimum %d)",
  25860. + (unsigned int)slot_zero, VCHIQ_VERSION,
  25861. + slot_zero->version_min);
  25862. + vchiq_loud_error("Restart with a newer kernel.");
  25863. + vchiq_loud_error_footer();
  25864. + return VCHIQ_ERROR;
  25865. + }
  25866. +
  25867. + if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) ||
  25868. + (slot_zero->slot_size != VCHIQ_SLOT_SIZE) ||
  25869. + (slot_zero->max_slots != VCHIQ_MAX_SLOTS) ||
  25870. + (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) {
  25871. + vchiq_loud_error_header();
  25872. + if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T))
  25873. + vchiq_loud_error("slot_zero=%x: slot_zero_size=%x "
  25874. + "(expected %x)",
  25875. + (unsigned int)slot_zero,
  25876. + slot_zero->slot_zero_size,
  25877. + sizeof(VCHIQ_SLOT_ZERO_T));
  25878. + if (slot_zero->slot_size != VCHIQ_SLOT_SIZE)
  25879. + vchiq_loud_error("slot_zero=%x: slot_size=%d "
  25880. + "(expected %d",
  25881. + (unsigned int)slot_zero, slot_zero->slot_size,
  25882. + VCHIQ_SLOT_SIZE);
  25883. + if (slot_zero->max_slots != VCHIQ_MAX_SLOTS)
  25884. + vchiq_loud_error("slot_zero=%x: max_slots=%d "
  25885. + "(expected %d)",
  25886. + (unsigned int)slot_zero, slot_zero->max_slots,
  25887. + VCHIQ_MAX_SLOTS);
  25888. + if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)
  25889. + vchiq_loud_error("slot_zero=%x: max_slots_per_side=%d "
  25890. + "(expected %d)",
  25891. + (unsigned int)slot_zero,
  25892. + slot_zero->max_slots_per_side,
  25893. + VCHIQ_MAX_SLOTS_PER_SIDE);
  25894. + vchiq_loud_error_footer();
  25895. + return VCHIQ_ERROR;
  25896. + }
  25897. +
  25898. + if (is_master) {
  25899. + local = &slot_zero->master;
  25900. + remote = &slot_zero->slave;
  25901. + } else {
  25902. + local = &slot_zero->slave;
  25903. + remote = &slot_zero->master;
  25904. + }
  25905. +
  25906. + if (local->initialised) {
  25907. + vchiq_loud_error_header();
  25908. + if (remote->initialised)
  25909. + vchiq_loud_error("local state has already been "
  25910. + "initialised");
  25911. + else
  25912. + vchiq_loud_error("master/slave mismatch - two %ss",
  25913. + is_master ? "master" : "slave");
  25914. + vchiq_loud_error_footer();
  25915. + return VCHIQ_ERROR;
  25916. + }
  25917. +
  25918. + memset(state, 0, sizeof(VCHIQ_STATE_T));
  25919. +
  25920. + state->id = id++;
  25921. + state->is_master = is_master;
  25922. +
  25923. + /*
  25924. + initialize shared state pointers
  25925. + */
  25926. +
  25927. + state->local = local;
  25928. + state->remote = remote;
  25929. + state->slot_data = (VCHIQ_SLOT_T *)slot_zero;
  25930. +
  25931. + /*
  25932. + initialize events and mutexes
  25933. + */
  25934. +
  25935. + sema_init(&state->connect, 0);
  25936. + mutex_init(&state->mutex);
  25937. + sema_init(&state->trigger_event, 0);
  25938. + sema_init(&state->recycle_event, 0);
  25939. + sema_init(&state->sync_trigger_event, 0);
  25940. + sema_init(&state->sync_release_event, 0);
  25941. +
  25942. + mutex_init(&state->slot_mutex);
  25943. + mutex_init(&state->recycle_mutex);
  25944. + mutex_init(&state->sync_mutex);
  25945. + mutex_init(&state->bulk_transfer_mutex);
  25946. +
  25947. + sema_init(&state->slot_available_event, 0);
  25948. + sema_init(&state->slot_remove_event, 0);
  25949. + sema_init(&state->data_quota_event, 0);
  25950. +
  25951. + state->slot_queue_available = 0;
  25952. +
  25953. + for (i = 0; i < VCHIQ_MAX_SERVICES; i++) {
  25954. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  25955. + &state->service_quotas[i];
  25956. + sema_init(&service_quota->quota_event, 0);
  25957. + }
  25958. +
  25959. + for (i = local->slot_first; i <= local->slot_last; i++) {
  25960. + local->slot_queue[state->slot_queue_available++] = i;
  25961. + up(&state->slot_available_event);
  25962. + }
  25963. +
  25964. + state->default_slot_quota = state->slot_queue_available/2;
  25965. + state->default_message_quota =
  25966. + min((unsigned short)(state->default_slot_quota * 256),
  25967. + (unsigned short)~0);
  25968. +
  25969. + state->previous_data_index = -1;
  25970. + state->data_use_count = 0;
  25971. + state->data_quota = state->slot_queue_available - 1;
  25972. +
  25973. + local->trigger.event = &state->trigger_event;
  25974. + remote_event_create(&local->trigger);
  25975. + local->tx_pos = 0;
  25976. +
  25977. + local->recycle.event = &state->recycle_event;
  25978. + remote_event_create(&local->recycle);
  25979. + local->slot_queue_recycle = state->slot_queue_available;
  25980. +
  25981. + local->sync_trigger.event = &state->sync_trigger_event;
  25982. + remote_event_create(&local->sync_trigger);
  25983. +
  25984. + local->sync_release.event = &state->sync_release_event;
  25985. + remote_event_create(&local->sync_release);
  25986. +
  25987. + /* At start-of-day, the slot is empty and available */
  25988. + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid
  25989. + = VCHIQ_MSGID_PADDING;
  25990. + remote_event_signal_local(&local->sync_release);
  25991. +
  25992. + local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
  25993. +
  25994. + status = vchiq_platform_init_state(state);
  25995. +
  25996. + /*
  25997. + bring up slot handler thread
  25998. + */
  25999. + snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id);
  26000. + state->slot_handler_thread = kthread_create(&slot_handler_func,
  26001. + (void *)state,
  26002. + threadname);
  26003. +
  26004. + if (state->slot_handler_thread == NULL) {
  26005. + vchiq_loud_error_header();
  26006. + vchiq_loud_error("couldn't create thread %s", threadname);
  26007. + vchiq_loud_error_footer();
  26008. + return VCHIQ_ERROR;
  26009. + }
  26010. + set_user_nice(state->slot_handler_thread, -19);
  26011. + wake_up_process(state->slot_handler_thread);
  26012. +
  26013. + snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id);
  26014. + state->recycle_thread = kthread_create(&recycle_func,
  26015. + (void *)state,
  26016. + threadname);
  26017. + if (state->recycle_thread == NULL) {
  26018. + vchiq_loud_error_header();
  26019. + vchiq_loud_error("couldn't create thread %s", threadname);
  26020. + vchiq_loud_error_footer();
  26021. + return VCHIQ_ERROR;
  26022. + }
  26023. + set_user_nice(state->recycle_thread, -19);
  26024. + wake_up_process(state->recycle_thread);
  26025. +
  26026. + snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id);
  26027. + state->sync_thread = kthread_create(&sync_func,
  26028. + (void *)state,
  26029. + threadname);
  26030. + if (state->sync_thread == NULL) {
  26031. + vchiq_loud_error_header();
  26032. + vchiq_loud_error("couldn't create thread %s", threadname);
  26033. + vchiq_loud_error_footer();
  26034. + return VCHIQ_ERROR;
  26035. + }
  26036. + set_user_nice(state->sync_thread, -20);
  26037. + wake_up_process(state->sync_thread);
  26038. +
  26039. + BUG_ON(state->id >= VCHIQ_MAX_STATES);
  26040. + vchiq_states[state->id] = state;
  26041. +
  26042. + /* Indicate readiness to the other side */
  26043. + local->initialised = 1;
  26044. +
  26045. + return status;
  26046. +}
  26047. +
  26048. +/* Called from application thread when a client or server service is created. */
  26049. +VCHIQ_SERVICE_T *
  26050. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  26051. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  26052. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
  26053. +{
  26054. + VCHIQ_SERVICE_T *service;
  26055. +
  26056. + service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
  26057. + if (service) {
  26058. + service->base.fourcc = params->fourcc;
  26059. + service->base.callback = params->callback;
  26060. + service->base.userdata = params->userdata;
  26061. + service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
  26062. + service->ref_count = 1;
  26063. + service->srvstate = VCHIQ_SRVSTATE_FREE;
  26064. + service->userdata_term = userdata_term;
  26065. + service->localport = VCHIQ_PORT_FREE;
  26066. + service->remoteport = VCHIQ_PORT_FREE;
  26067. +
  26068. + service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
  26069. + VCHIQ_FOURCC_INVALID : params->fourcc;
  26070. + service->client_id = 0;
  26071. + service->auto_close = 1;
  26072. + service->sync = 0;
  26073. + service->closing = 0;
  26074. + atomic_set(&service->poll_flags, 0);
  26075. + service->version = params->version;
  26076. + service->version_min = params->version_min;
  26077. + service->state = state;
  26078. + service->instance = instance;
  26079. + service->service_use_count = 0;
  26080. + init_bulk_queue(&service->bulk_tx);
  26081. + init_bulk_queue(&service->bulk_rx);
  26082. + sema_init(&service->remove_event, 0);
  26083. + sema_init(&service->bulk_remove_event, 0);
  26084. + mutex_init(&service->bulk_mutex);
  26085. + memset(&service->stats, 0, sizeof(service->stats));
  26086. + } else {
  26087. + vchiq_log_error(vchiq_core_log_level,
  26088. + "Out of memory");
  26089. + }
  26090. +
  26091. + if (service) {
  26092. + VCHIQ_SERVICE_T **pservice = NULL;
  26093. + int i;
  26094. +
  26095. + /* Although it is perfectly possible to use service_spinlock
  26096. + ** to protect the creation of services, it is overkill as it
  26097. + ** disables interrupts while the array is searched.
  26098. + ** The only danger is of another thread trying to create a
  26099. + ** service - service deletion is safe.
  26100. + ** Therefore it is preferable to use state->mutex which,
  26101. + ** although slower to claim, doesn't block interrupts while
  26102. + ** it is held.
  26103. + */
  26104. +
  26105. + mutex_lock(&state->mutex);
  26106. +
  26107. + /* Prepare to use a previously unused service */
  26108. + if (state->unused_service < VCHIQ_MAX_SERVICES)
  26109. + pservice = &state->services[state->unused_service];
  26110. +
  26111. + if (srvstate == VCHIQ_SRVSTATE_OPENING) {
  26112. + for (i = 0; i < state->unused_service; i++) {
  26113. + VCHIQ_SERVICE_T *srv = state->services[i];
  26114. + if (!srv) {
  26115. + pservice = &state->services[i];
  26116. + break;
  26117. + }
  26118. + }
  26119. + } else {
  26120. + for (i = (state->unused_service - 1); i >= 0; i--) {
  26121. + VCHIQ_SERVICE_T *srv = state->services[i];
  26122. + if (!srv)
  26123. + pservice = &state->services[i];
  26124. + else if ((srv->public_fourcc == params->fourcc)
  26125. + && ((srv->instance != instance) ||
  26126. + (srv->base.callback !=
  26127. + params->callback))) {
  26128. + /* There is another server using this
  26129. + ** fourcc which doesn't match. */
  26130. + pservice = NULL;
  26131. + break;
  26132. + }
  26133. + }
  26134. + }
  26135. +
  26136. + if (pservice) {
  26137. + service->localport = (pservice - state->services);
  26138. + if (!handle_seq)
  26139. + handle_seq = VCHIQ_MAX_STATES *
  26140. + VCHIQ_MAX_SERVICES;
  26141. + service->handle = handle_seq |
  26142. + (state->id * VCHIQ_MAX_SERVICES) |
  26143. + service->localport;
  26144. + handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
  26145. + *pservice = service;
  26146. + if (pservice == &state->services[state->unused_service])
  26147. + state->unused_service++;
  26148. + }
  26149. +
  26150. + mutex_unlock(&state->mutex);
  26151. +
  26152. + if (!pservice) {
  26153. + kfree(service);
  26154. + service = NULL;
  26155. + }
  26156. + }
  26157. +
  26158. + if (service) {
  26159. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26160. + &state->service_quotas[service->localport];
  26161. + service_quota->slot_quota = state->default_slot_quota;
  26162. + service_quota->message_quota = state->default_message_quota;
  26163. + if (service_quota->slot_use_count == 0)
  26164. + service_quota->previous_tx_index =
  26165. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
  26166. + - 1;
  26167. +
  26168. + /* Bring this service online */
  26169. + vchiq_set_service_state(service, srvstate);
  26170. +
  26171. + vchiq_log_info(vchiq_core_msg_log_level,
  26172. + "%s Service %c%c%c%c SrcPort:%d",
  26173. + (srvstate == VCHIQ_SRVSTATE_OPENING)
  26174. + ? "Open" : "Add",
  26175. + VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
  26176. + service->localport);
  26177. + }
  26178. +
  26179. + /* Don't unlock the service - leave it with a ref_count of 1. */
  26180. +
  26181. + return service;
  26182. +}
  26183. +
  26184. +VCHIQ_STATUS_T
  26185. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id)
  26186. +{
  26187. + struct vchiq_open_payload payload = {
  26188. + service->base.fourcc,
  26189. + client_id,
  26190. + service->version,
  26191. + service->version_min
  26192. + };
  26193. + VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) };
  26194. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26195. +
  26196. + service->client_id = client_id;
  26197. + vchiq_use_service_internal(service);
  26198. + status = queue_message(service->state, NULL,
  26199. + VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN, service->localport, 0),
  26200. + &body, 1, sizeof(payload), 1);
  26201. + if (status == VCHIQ_SUCCESS) {
  26202. + if (down_interruptible(&service->remove_event) != 0) {
  26203. + status = VCHIQ_RETRY;
  26204. + vchiq_release_service_internal(service);
  26205. + } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
  26206. + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
  26207. + if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
  26208. + vchiq_log_error(vchiq_core_log_level,
  26209. + "%d: osi - srvstate = %s (ref %d)",
  26210. + service->state->id,
  26211. + srvstate_names[service->srvstate],
  26212. + service->ref_count);
  26213. + status = VCHIQ_ERROR;
  26214. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26215. + vchiq_release_service_internal(service);
  26216. + }
  26217. + }
  26218. + return status;
  26219. +}
  26220. +
  26221. +static void
  26222. +release_service_messages(VCHIQ_SERVICE_T *service)
  26223. +{
  26224. + VCHIQ_STATE_T *state = service->state;
  26225. + int slot_last = state->remote->slot_last;
  26226. + int i;
  26227. +
  26228. + /* Release any claimed messages */
  26229. + for (i = state->remote->slot_first; i <= slot_last; i++) {
  26230. + VCHIQ_SLOT_INFO_T *slot_info =
  26231. + SLOT_INFO_FROM_INDEX(state, i);
  26232. + if (slot_info->release_count != slot_info->use_count) {
  26233. + char *data =
  26234. + (char *)SLOT_DATA_FROM_INDEX(state, i);
  26235. + unsigned int pos, end;
  26236. +
  26237. + end = VCHIQ_SLOT_SIZE;
  26238. + if (data == state->rx_data)
  26239. + /* This buffer is still being read from - stop
  26240. + ** at the current read position */
  26241. + end = state->rx_pos & VCHIQ_SLOT_MASK;
  26242. +
  26243. + pos = 0;
  26244. +
  26245. + while (pos < end) {
  26246. + VCHIQ_HEADER_T *header =
  26247. + (VCHIQ_HEADER_T *)(data + pos);
  26248. + int msgid = header->msgid;
  26249. + int port = VCHIQ_MSG_DSTPORT(msgid);
  26250. + if ((port == service->localport) &&
  26251. + (msgid & VCHIQ_MSGID_CLAIMED)) {
  26252. + vchiq_log_info(vchiq_core_log_level,
  26253. + " fsi - hdr %x",
  26254. + (unsigned int)header);
  26255. + release_slot(state, slot_info, header,
  26256. + NULL);
  26257. + }
  26258. + pos += calc_stride(header->size);
  26259. + if (pos > VCHIQ_SLOT_SIZE) {
  26260. + vchiq_log_error(vchiq_core_log_level,
  26261. + "fsi - pos %x: header %x, "
  26262. + "msgid %x, header->msgid %x, "
  26263. + "header->size %x",
  26264. + pos, (unsigned int)header,
  26265. + msgid, header->msgid,
  26266. + header->size);
  26267. + WARN(1, "invalid slot position\n");
  26268. + }
  26269. + }
  26270. + }
  26271. + }
  26272. +}
  26273. +
  26274. +static int
  26275. +do_abort_bulks(VCHIQ_SERVICE_T *service)
  26276. +{
  26277. + VCHIQ_STATUS_T status;
  26278. +
  26279. + /* Abort any outstanding bulk transfers */
  26280. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0)
  26281. + return 0;
  26282. + abort_outstanding_bulks(service, &service->bulk_tx);
  26283. + abort_outstanding_bulks(service, &service->bulk_rx);
  26284. + mutex_unlock(&service->bulk_mutex);
  26285. +
  26286. + status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
  26287. + if (status == VCHIQ_SUCCESS)
  26288. + status = notify_bulks(service, &service->bulk_rx,
  26289. + 0/*!retry_poll*/);
  26290. + return (status == VCHIQ_SUCCESS);
  26291. +}
  26292. +
  26293. +static VCHIQ_STATUS_T
  26294. +close_service_complete(VCHIQ_SERVICE_T *service, int failstate)
  26295. +{
  26296. + VCHIQ_STATUS_T status;
  26297. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  26298. + int newstate;
  26299. +
  26300. + switch (service->srvstate) {
  26301. + case VCHIQ_SRVSTATE_OPEN:
  26302. + case VCHIQ_SRVSTATE_CLOSESENT:
  26303. + case VCHIQ_SRVSTATE_CLOSERECVD:
  26304. + if (is_server) {
  26305. + if (service->auto_close) {
  26306. + service->client_id = 0;
  26307. + service->remoteport = VCHIQ_PORT_FREE;
  26308. + newstate = VCHIQ_SRVSTATE_LISTENING;
  26309. + } else
  26310. + newstate = VCHIQ_SRVSTATE_CLOSEWAIT;
  26311. + } else
  26312. + newstate = VCHIQ_SRVSTATE_CLOSED;
  26313. + vchiq_set_service_state(service, newstate);
  26314. + break;
  26315. + case VCHIQ_SRVSTATE_LISTENING:
  26316. + break;
  26317. + default:
  26318. + vchiq_log_error(vchiq_core_log_level,
  26319. + "close_service_complete(%x) called in state %s",
  26320. + service->handle, srvstate_names[service->srvstate]);
  26321. + WARN(1, "close_service_complete in unexpected state\n");
  26322. + return VCHIQ_ERROR;
  26323. + }
  26324. +
  26325. + status = make_service_callback(service,
  26326. + VCHIQ_SERVICE_CLOSED, NULL, NULL);
  26327. +
  26328. + if (status != VCHIQ_RETRY) {
  26329. + int uc = service->service_use_count;
  26330. + int i;
  26331. + /* Complete the close process */
  26332. + for (i = 0; i < uc; i++)
  26333. + /* cater for cases where close is forced and the
  26334. + ** client may not close all it's handles */
  26335. + vchiq_release_service_internal(service);
  26336. +
  26337. + service->client_id = 0;
  26338. + service->remoteport = VCHIQ_PORT_FREE;
  26339. +
  26340. + if (service->srvstate == VCHIQ_SRVSTATE_CLOSED)
  26341. + vchiq_free_service_internal(service);
  26342. + else if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) {
  26343. + if (is_server)
  26344. + service->closing = 0;
  26345. +
  26346. + up(&service->remove_event);
  26347. + }
  26348. + } else
  26349. + vchiq_set_service_state(service, failstate);
  26350. +
  26351. + return status;
  26352. +}
  26353. +
  26354. +/* Called by the slot handler */
  26355. +VCHIQ_STATUS_T
  26356. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
  26357. +{
  26358. + VCHIQ_STATE_T *state = service->state;
  26359. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26360. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  26361. +
  26362. + vchiq_log_info(vchiq_core_log_level, "%d: csi:%d,%d (%s)",
  26363. + service->state->id, service->localport, close_recvd,
  26364. + srvstate_names[service->srvstate]);
  26365. +
  26366. + switch (service->srvstate) {
  26367. + case VCHIQ_SRVSTATE_CLOSED:
  26368. + case VCHIQ_SRVSTATE_HIDDEN:
  26369. + case VCHIQ_SRVSTATE_LISTENING:
  26370. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  26371. + if (close_recvd)
  26372. + vchiq_log_error(vchiq_core_log_level,
  26373. + "vchiq_close_service_internal(1) called "
  26374. + "in state %s",
  26375. + srvstate_names[service->srvstate]);
  26376. + else if (is_server) {
  26377. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  26378. + status = VCHIQ_ERROR;
  26379. + } else {
  26380. + service->client_id = 0;
  26381. + service->remoteport = VCHIQ_PORT_FREE;
  26382. + if (service->srvstate ==
  26383. + VCHIQ_SRVSTATE_CLOSEWAIT)
  26384. + vchiq_set_service_state(service,
  26385. + VCHIQ_SRVSTATE_LISTENING);
  26386. + }
  26387. + up(&service->remove_event);
  26388. + } else
  26389. + vchiq_free_service_internal(service);
  26390. + break;
  26391. + case VCHIQ_SRVSTATE_OPENING:
  26392. + if (close_recvd) {
  26393. + /* The open was rejected - tell the user */
  26394. + vchiq_set_service_state(service,
  26395. + VCHIQ_SRVSTATE_CLOSEWAIT);
  26396. + up(&service->remove_event);
  26397. + } else {
  26398. + /* Shutdown mid-open - let the other side know */
  26399. + status = queue_message(state, service,
  26400. + VCHIQ_MAKE_MSG
  26401. + (VCHIQ_MSG_CLOSE,
  26402. + service->localport,
  26403. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  26404. + NULL, 0, 0, 0);
  26405. + }
  26406. + break;
  26407. +
  26408. + case VCHIQ_SRVSTATE_OPENSYNC:
  26409. + mutex_lock(&state->sync_mutex);
  26410. + /* Drop through */
  26411. +
  26412. + case VCHIQ_SRVSTATE_OPEN:
  26413. + if (state->is_master || close_recvd) {
  26414. + if (!do_abort_bulks(service))
  26415. + status = VCHIQ_RETRY;
  26416. + }
  26417. +
  26418. + release_service_messages(service);
  26419. +
  26420. + if (status == VCHIQ_SUCCESS)
  26421. + status = queue_message(state, service,
  26422. + VCHIQ_MAKE_MSG
  26423. + (VCHIQ_MSG_CLOSE,
  26424. + service->localport,
  26425. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  26426. + NULL, 0, 0, 0);
  26427. +
  26428. + if (status == VCHIQ_SUCCESS) {
  26429. + if (!close_recvd)
  26430. + break;
  26431. + } else if (service->srvstate == VCHIQ_SRVSTATE_OPENSYNC) {
  26432. + mutex_unlock(&state->sync_mutex);
  26433. + break;
  26434. + } else
  26435. + break;
  26436. +
  26437. + status = close_service_complete(service,
  26438. + VCHIQ_SRVSTATE_CLOSERECVD);
  26439. + break;
  26440. +
  26441. + case VCHIQ_SRVSTATE_CLOSESENT:
  26442. + if (!close_recvd)
  26443. + /* This happens when a process is killed mid-close */
  26444. + break;
  26445. +
  26446. + if (!state->is_master) {
  26447. + if (!do_abort_bulks(service)) {
  26448. + status = VCHIQ_RETRY;
  26449. + break;
  26450. + }
  26451. + }
  26452. +
  26453. + if (status == VCHIQ_SUCCESS)
  26454. + status = close_service_complete(service,
  26455. + VCHIQ_SRVSTATE_CLOSERECVD);
  26456. + break;
  26457. +
  26458. + case VCHIQ_SRVSTATE_CLOSERECVD:
  26459. + if (!close_recvd && is_server)
  26460. + /* Force into LISTENING mode */
  26461. + vchiq_set_service_state(service,
  26462. + VCHIQ_SRVSTATE_LISTENING);
  26463. + status = close_service_complete(service,
  26464. + VCHIQ_SRVSTATE_CLOSERECVD);
  26465. + break;
  26466. +
  26467. + default:
  26468. + vchiq_log_error(vchiq_core_log_level,
  26469. + "vchiq_close_service_internal(%d) called in state %s",
  26470. + close_recvd, srvstate_names[service->srvstate]);
  26471. + break;
  26472. + }
  26473. +
  26474. + return status;
  26475. +}
  26476. +
  26477. +/* Called from the application process upon process death */
  26478. +void
  26479. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service)
  26480. +{
  26481. + VCHIQ_STATE_T *state = service->state;
  26482. +
  26483. + vchiq_log_info(vchiq_core_log_level, "%d: tsi - (%d<->%d)",
  26484. + state->id, service->localport, service->remoteport);
  26485. +
  26486. + mark_service_closing(service);
  26487. +
  26488. + /* Mark the service for removal by the slot handler */
  26489. + request_poll(state, service, VCHIQ_POLL_REMOVE);
  26490. +}
  26491. +
  26492. +/* Called from the slot handler */
  26493. +void
  26494. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service)
  26495. +{
  26496. + VCHIQ_STATE_T *state = service->state;
  26497. +
  26498. + vchiq_log_info(vchiq_core_log_level, "%d: fsi - (%d)",
  26499. + state->id, service->localport);
  26500. +
  26501. + switch (service->srvstate) {
  26502. + case VCHIQ_SRVSTATE_OPENING:
  26503. + case VCHIQ_SRVSTATE_CLOSED:
  26504. + case VCHIQ_SRVSTATE_HIDDEN:
  26505. + case VCHIQ_SRVSTATE_LISTENING:
  26506. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  26507. + break;
  26508. + default:
  26509. + vchiq_log_error(vchiq_core_log_level,
  26510. + "%d: fsi - (%d) in state %s",
  26511. + state->id, service->localport,
  26512. + srvstate_names[service->srvstate]);
  26513. + return;
  26514. + }
  26515. +
  26516. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_FREE);
  26517. +
  26518. + up(&service->remove_event);
  26519. +
  26520. + /* Release the initial lock */
  26521. + unlock_service(service);
  26522. +}
  26523. +
  26524. +VCHIQ_STATUS_T
  26525. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  26526. +{
  26527. + VCHIQ_SERVICE_T *service;
  26528. + int i;
  26529. +
  26530. + /* Find all services registered to this client and enable them. */
  26531. + i = 0;
  26532. + while ((service = next_service_by_instance(state, instance,
  26533. + &i)) != NULL) {
  26534. + if (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)
  26535. + vchiq_set_service_state(service,
  26536. + VCHIQ_SRVSTATE_LISTENING);
  26537. + unlock_service(service);
  26538. + }
  26539. +
  26540. + if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
  26541. + if (queue_message(state, NULL,
  26542. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0,
  26543. + 0, 1) == VCHIQ_RETRY)
  26544. + return VCHIQ_RETRY;
  26545. +
  26546. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTING);
  26547. + }
  26548. +
  26549. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
  26550. + if (down_interruptible(&state->connect) != 0)
  26551. + return VCHIQ_RETRY;
  26552. +
  26553. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  26554. + up(&state->connect);
  26555. + }
  26556. +
  26557. + return VCHIQ_SUCCESS;
  26558. +}
  26559. +
  26560. +VCHIQ_STATUS_T
  26561. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  26562. +{
  26563. + VCHIQ_SERVICE_T *service;
  26564. + int i;
  26565. +
  26566. + /* Find all services registered to this client and enable them. */
  26567. + i = 0;
  26568. + while ((service = next_service_by_instance(state, instance,
  26569. + &i)) != NULL) {
  26570. + (void)vchiq_remove_service(service->handle);
  26571. + unlock_service(service);
  26572. + }
  26573. +
  26574. + return VCHIQ_SUCCESS;
  26575. +}
  26576. +
  26577. +VCHIQ_STATUS_T
  26578. +vchiq_pause_internal(VCHIQ_STATE_T *state)
  26579. +{
  26580. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26581. +
  26582. + switch (state->conn_state) {
  26583. + case VCHIQ_CONNSTATE_CONNECTED:
  26584. + /* Request a pause */
  26585. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
  26586. + request_poll(state, NULL, 0);
  26587. + break;
  26588. + default:
  26589. + vchiq_log_error(vchiq_core_log_level,
  26590. + "vchiq_pause_internal in state %s\n",
  26591. + conn_state_names[state->conn_state]);
  26592. + status = VCHIQ_ERROR;
  26593. + VCHIQ_STATS_INC(state, error_count);
  26594. + break;
  26595. + }
  26596. +
  26597. + return status;
  26598. +}
  26599. +
  26600. +VCHIQ_STATUS_T
  26601. +vchiq_resume_internal(VCHIQ_STATE_T *state)
  26602. +{
  26603. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26604. +
  26605. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  26606. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
  26607. + request_poll(state, NULL, 0);
  26608. + } else {
  26609. + status = VCHIQ_ERROR;
  26610. + VCHIQ_STATS_INC(state, error_count);
  26611. + }
  26612. +
  26613. + return status;
  26614. +}
  26615. +
  26616. +VCHIQ_STATUS_T
  26617. +vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
  26618. +{
  26619. + /* Unregister the service */
  26620. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26621. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26622. +
  26623. + if (!service)
  26624. + return VCHIQ_ERROR;
  26625. +
  26626. + vchiq_log_info(vchiq_core_log_level,
  26627. + "%d: close_service:%d",
  26628. + service->state->id, service->localport);
  26629. +
  26630. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26631. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  26632. + (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)) {
  26633. + unlock_service(service);
  26634. + return VCHIQ_ERROR;
  26635. + }
  26636. +
  26637. + mark_service_closing(service);
  26638. +
  26639. + if (current == service->state->slot_handler_thread) {
  26640. + status = vchiq_close_service_internal(service,
  26641. + 0/*!close_recvd*/);
  26642. + BUG_ON(status == VCHIQ_RETRY);
  26643. + } else {
  26644. + /* Mark the service for termination by the slot handler */
  26645. + request_poll(service->state, service, VCHIQ_POLL_TERMINATE);
  26646. + }
  26647. +
  26648. + while (1) {
  26649. + if (down_interruptible(&service->remove_event) != 0) {
  26650. + status = VCHIQ_RETRY;
  26651. + break;
  26652. + }
  26653. +
  26654. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26655. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  26656. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  26657. + break;
  26658. +
  26659. + vchiq_log_warning(vchiq_core_log_level,
  26660. + "%d: close_service:%d - waiting in state %s",
  26661. + service->state->id, service->localport,
  26662. + srvstate_names[service->srvstate]);
  26663. + }
  26664. +
  26665. + if ((status == VCHIQ_SUCCESS) &&
  26666. + (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  26667. + (service->srvstate != VCHIQ_SRVSTATE_LISTENING))
  26668. + status = VCHIQ_ERROR;
  26669. +
  26670. + unlock_service(service);
  26671. +
  26672. + return status;
  26673. +}
  26674. +
  26675. +VCHIQ_STATUS_T
  26676. +vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
  26677. +{
  26678. + /* Unregister the service */
  26679. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26680. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26681. +
  26682. + if (!service)
  26683. + return VCHIQ_ERROR;
  26684. +
  26685. + vchiq_log_info(vchiq_core_log_level,
  26686. + "%d: remove_service:%d",
  26687. + service->state->id, service->localport);
  26688. +
  26689. + if (service->srvstate == VCHIQ_SRVSTATE_FREE) {
  26690. + unlock_service(service);
  26691. + return VCHIQ_ERROR;
  26692. + }
  26693. +
  26694. + mark_service_closing(service);
  26695. +
  26696. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  26697. + (current == service->state->slot_handler_thread)) {
  26698. + /* Make it look like a client, because it must be removed and
  26699. + not left in the LISTENING state. */
  26700. + service->public_fourcc = VCHIQ_FOURCC_INVALID;
  26701. +
  26702. + status = vchiq_close_service_internal(service,
  26703. + 0/*!close_recvd*/);
  26704. + BUG_ON(status == VCHIQ_RETRY);
  26705. + } else {
  26706. + /* Mark the service for removal by the slot handler */
  26707. + request_poll(service->state, service, VCHIQ_POLL_REMOVE);
  26708. + }
  26709. + while (1) {
  26710. + if (down_interruptible(&service->remove_event) != 0) {
  26711. + status = VCHIQ_RETRY;
  26712. + break;
  26713. + }
  26714. +
  26715. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26716. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  26717. + break;
  26718. +
  26719. + vchiq_log_warning(vchiq_core_log_level,
  26720. + "%d: remove_service:%d - waiting in state %s",
  26721. + service->state->id, service->localport,
  26722. + srvstate_names[service->srvstate]);
  26723. + }
  26724. +
  26725. + if ((status == VCHIQ_SUCCESS) &&
  26726. + (service->srvstate != VCHIQ_SRVSTATE_FREE))
  26727. + status = VCHIQ_ERROR;
  26728. +
  26729. + unlock_service(service);
  26730. +
  26731. + return status;
  26732. +}
  26733. +
  26734. +
  26735. +/* This function may be called by kernel threads or user threads.
  26736. + * User threads may receive VCHIQ_RETRY to indicate that a signal has been
  26737. + * received and the call should be retried after being returned to user
  26738. + * context.
  26739. + * When called in blocking mode, the userdata field points to a bulk_waiter
  26740. + * structure.
  26741. + */
  26742. +VCHIQ_STATUS_T
  26743. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  26744. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  26745. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir)
  26746. +{
  26747. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26748. + VCHIQ_BULK_QUEUE_T *queue;
  26749. + VCHIQ_BULK_T *bulk;
  26750. + VCHIQ_STATE_T *state;
  26751. + struct bulk_waiter *bulk_waiter = NULL;
  26752. + const char dir_char = (dir == VCHIQ_BULK_TRANSMIT) ? 't' : 'r';
  26753. + const int dir_msgtype = (dir == VCHIQ_BULK_TRANSMIT) ?
  26754. + VCHIQ_MSG_BULK_TX : VCHIQ_MSG_BULK_RX;
  26755. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26756. +
  26757. + if (!service ||
  26758. + (service->srvstate != VCHIQ_SRVSTATE_OPEN) ||
  26759. + ((memhandle == VCHI_MEM_HANDLE_INVALID) && (offset == NULL)) ||
  26760. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  26761. + goto error_exit;
  26762. +
  26763. + switch (mode) {
  26764. + case VCHIQ_BULK_MODE_NOCALLBACK:
  26765. + case VCHIQ_BULK_MODE_CALLBACK:
  26766. + break;
  26767. + case VCHIQ_BULK_MODE_BLOCKING:
  26768. + bulk_waiter = (struct bulk_waiter *)userdata;
  26769. + sema_init(&bulk_waiter->event, 0);
  26770. + bulk_waiter->actual = 0;
  26771. + bulk_waiter->bulk = NULL;
  26772. + break;
  26773. + case VCHIQ_BULK_MODE_WAITING:
  26774. + bulk_waiter = (struct bulk_waiter *)userdata;
  26775. + bulk = bulk_waiter->bulk;
  26776. + goto waiting;
  26777. + default:
  26778. + goto error_exit;
  26779. + }
  26780. +
  26781. + state = service->state;
  26782. +
  26783. + queue = (dir == VCHIQ_BULK_TRANSMIT) ?
  26784. + &service->bulk_tx : &service->bulk_rx;
  26785. +
  26786. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0) {
  26787. + status = VCHIQ_RETRY;
  26788. + goto error_exit;
  26789. + }
  26790. +
  26791. + if (queue->local_insert == queue->remove + VCHIQ_NUM_SERVICE_BULKS) {
  26792. + VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
  26793. + do {
  26794. + mutex_unlock(&service->bulk_mutex);
  26795. + if (down_interruptible(&service->bulk_remove_event)
  26796. + != 0) {
  26797. + status = VCHIQ_RETRY;
  26798. + goto error_exit;
  26799. + }
  26800. + if (mutex_lock_interruptible(&service->bulk_mutex)
  26801. + != 0) {
  26802. + status = VCHIQ_RETRY;
  26803. + goto error_exit;
  26804. + }
  26805. + } while (queue->local_insert == queue->remove +
  26806. + VCHIQ_NUM_SERVICE_BULKS);
  26807. + }
  26808. +
  26809. + bulk = &queue->bulks[BULK_INDEX(queue->local_insert)];
  26810. +
  26811. + bulk->mode = mode;
  26812. + bulk->dir = dir;
  26813. + bulk->userdata = userdata;
  26814. + bulk->size = size;
  26815. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  26816. +
  26817. + if (vchiq_prepare_bulk_data(bulk, memhandle, offset, size, dir) !=
  26818. + VCHIQ_SUCCESS)
  26819. + goto unlock_error_exit;
  26820. +
  26821. + wmb();
  26822. +
  26823. + vchiq_log_info(vchiq_core_log_level,
  26824. + "%d: bt (%d->%d) %cx %x@%x %x",
  26825. + state->id,
  26826. + service->localport, service->remoteport, dir_char,
  26827. + size, (unsigned int)bulk->data, (unsigned int)userdata);
  26828. +
  26829. + if (state->is_master) {
  26830. + queue->local_insert++;
  26831. + if (resolve_bulks(service, queue))
  26832. + request_poll(state, service,
  26833. + (dir == VCHIQ_BULK_TRANSMIT) ?
  26834. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  26835. + } else {
  26836. + int payload[2] = { (int)bulk->data, bulk->size };
  26837. + VCHIQ_ELEMENT_T element = { payload, sizeof(payload) };
  26838. +
  26839. + status = queue_message(state, NULL,
  26840. + VCHIQ_MAKE_MSG(dir_msgtype,
  26841. + service->localport, service->remoteport),
  26842. + &element, 1, sizeof(payload), 1);
  26843. + if (status != VCHIQ_SUCCESS) {
  26844. + vchiq_complete_bulk(bulk);
  26845. + goto unlock_error_exit;
  26846. + }
  26847. + queue->local_insert++;
  26848. + }
  26849. +
  26850. + mutex_unlock(&service->bulk_mutex);
  26851. +
  26852. + vchiq_log_trace(vchiq_core_log_level,
  26853. + "%d: bt:%d %cx li=%x ri=%x p=%x",
  26854. + state->id,
  26855. + service->localport, dir_char,
  26856. + queue->local_insert, queue->remote_insert, queue->process);
  26857. +
  26858. +waiting:
  26859. + unlock_service(service);
  26860. +
  26861. + status = VCHIQ_SUCCESS;
  26862. +
  26863. + if (bulk_waiter) {
  26864. + bulk_waiter->bulk = bulk;
  26865. + if (down_interruptible(&bulk_waiter->event) != 0)
  26866. + status = VCHIQ_RETRY;
  26867. + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
  26868. + status = VCHIQ_ERROR;
  26869. + }
  26870. +
  26871. + return status;
  26872. +
  26873. +unlock_error_exit:
  26874. + mutex_unlock(&service->bulk_mutex);
  26875. +
  26876. +error_exit:
  26877. + if (service)
  26878. + unlock_service(service);
  26879. + return status;
  26880. +}
  26881. +
  26882. +VCHIQ_STATUS_T
  26883. +vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
  26884. + const VCHIQ_ELEMENT_T *elements, unsigned int count)
  26885. +{
  26886. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26887. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26888. +
  26889. + unsigned int size = 0;
  26890. + unsigned int i;
  26891. +
  26892. + if (!service ||
  26893. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  26894. + goto error_exit;
  26895. +
  26896. + for (i = 0; i < (unsigned int)count; i++) {
  26897. + if (elements[i].size) {
  26898. + if (elements[i].data == NULL) {
  26899. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26900. + goto error_exit;
  26901. + }
  26902. + size += elements[i].size;
  26903. + }
  26904. + }
  26905. +
  26906. + if (size > VCHIQ_MAX_MSG_SIZE) {
  26907. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26908. + goto error_exit;
  26909. + }
  26910. +
  26911. + switch (service->srvstate) {
  26912. + case VCHIQ_SRVSTATE_OPEN:
  26913. + status = queue_message(service->state, service,
  26914. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  26915. + service->localport,
  26916. + service->remoteport),
  26917. + elements, count, size, 1);
  26918. + break;
  26919. + case VCHIQ_SRVSTATE_OPENSYNC:
  26920. + status = queue_message_sync(service->state, service,
  26921. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  26922. + service->localport,
  26923. + service->remoteport),
  26924. + elements, count, size, 1);
  26925. + break;
  26926. + default:
  26927. + status = VCHIQ_ERROR;
  26928. + break;
  26929. + }
  26930. +
  26931. +error_exit:
  26932. + if (service)
  26933. + unlock_service(service);
  26934. +
  26935. + return status;
  26936. +}
  26937. +
  26938. +void
  26939. +vchiq_release_message(VCHIQ_SERVICE_HANDLE_T handle, VCHIQ_HEADER_T *header)
  26940. +{
  26941. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26942. + VCHIQ_SHARED_STATE_T *remote;
  26943. + VCHIQ_STATE_T *state;
  26944. + int slot_index;
  26945. +
  26946. + if (!service)
  26947. + return;
  26948. +
  26949. + state = service->state;
  26950. + remote = state->remote;
  26951. +
  26952. + slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header);
  26953. +
  26954. + if ((slot_index >= remote->slot_first) &&
  26955. + (slot_index <= remote->slot_last)) {
  26956. + int msgid = header->msgid;
  26957. + if (msgid & VCHIQ_MSGID_CLAIMED) {
  26958. + VCHIQ_SLOT_INFO_T *slot_info =
  26959. + SLOT_INFO_FROM_INDEX(state, slot_index);
  26960. +
  26961. + release_slot(state, slot_info, header, service);
  26962. + }
  26963. + } else if (slot_index == remote->slot_sync)
  26964. + release_message_sync(state, header);
  26965. +
  26966. + unlock_service(service);
  26967. +}
  26968. +
  26969. +static void
  26970. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  26971. +{
  26972. + header->msgid = VCHIQ_MSGID_PADDING;
  26973. + wmb();
  26974. + remote_event_signal(&state->remote->sync_release);
  26975. +}
  26976. +
  26977. +VCHIQ_STATUS_T
  26978. +vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
  26979. +{
  26980. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26981. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26982. +
  26983. + if (!service ||
  26984. + (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
  26985. + !peer_version)
  26986. + goto exit;
  26987. + *peer_version = service->peer_version;
  26988. + status = VCHIQ_SUCCESS;
  26989. +
  26990. +exit:
  26991. + if (service)
  26992. + unlock_service(service);
  26993. + return status;
  26994. +}
  26995. +
  26996. +VCHIQ_STATUS_T
  26997. +vchiq_get_config(VCHIQ_INSTANCE_T instance,
  26998. + int config_size, VCHIQ_CONFIG_T *pconfig)
  26999. +{
  27000. + VCHIQ_CONFIG_T config;
  27001. +
  27002. + (void)instance;
  27003. +
  27004. + config.max_msg_size = VCHIQ_MAX_MSG_SIZE;
  27005. + config.bulk_threshold = VCHIQ_MAX_MSG_SIZE;
  27006. + config.max_outstanding_bulks = VCHIQ_NUM_SERVICE_BULKS;
  27007. + config.max_services = VCHIQ_MAX_SERVICES;
  27008. + config.version = VCHIQ_VERSION;
  27009. + config.version_min = VCHIQ_VERSION_MIN;
  27010. +
  27011. + if (config_size > sizeof(VCHIQ_CONFIG_T))
  27012. + return VCHIQ_ERROR;
  27013. +
  27014. + memcpy(pconfig, &config,
  27015. + min(config_size, (int)(sizeof(VCHIQ_CONFIG_T))));
  27016. +
  27017. + return VCHIQ_SUCCESS;
  27018. +}
  27019. +
  27020. +VCHIQ_STATUS_T
  27021. +vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
  27022. + VCHIQ_SERVICE_OPTION_T option, int value)
  27023. +{
  27024. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  27025. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  27026. +
  27027. + if (service) {
  27028. + switch (option) {
  27029. + case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
  27030. + service->auto_close = value;
  27031. + status = VCHIQ_SUCCESS;
  27032. + break;
  27033. +
  27034. + case VCHIQ_SERVICE_OPTION_SLOT_QUOTA: {
  27035. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  27036. + &service->state->service_quotas[
  27037. + service->localport];
  27038. + if (value == 0)
  27039. + value = service->state->default_slot_quota;
  27040. + if ((value >= service_quota->slot_use_count) &&
  27041. + (value < (unsigned short)~0)) {
  27042. + service_quota->slot_quota = value;
  27043. + if ((value >= service_quota->slot_use_count) &&
  27044. + (service_quota->message_quota >=
  27045. + service_quota->message_use_count)) {
  27046. + /* Signal the service that it may have
  27047. + ** dropped below its quota */
  27048. + up(&service_quota->quota_event);
  27049. + }
  27050. + status = VCHIQ_SUCCESS;
  27051. + }
  27052. + } break;
  27053. +
  27054. + case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA: {
  27055. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  27056. + &service->state->service_quotas[
  27057. + service->localport];
  27058. + if (value == 0)
  27059. + value = service->state->default_message_quota;
  27060. + if ((value >= service_quota->message_use_count) &&
  27061. + (value < (unsigned short)~0)) {
  27062. + service_quota->message_quota = value;
  27063. + if ((value >=
  27064. + service_quota->message_use_count) &&
  27065. + (service_quota->slot_quota >=
  27066. + service_quota->slot_use_count))
  27067. + /* Signal the service that it may have
  27068. + ** dropped below its quota */
  27069. + up(&service_quota->quota_event);
  27070. + status = VCHIQ_SUCCESS;
  27071. + }
  27072. + } break;
  27073. +
  27074. + case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
  27075. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  27076. + (service->srvstate ==
  27077. + VCHIQ_SRVSTATE_LISTENING)) {
  27078. + service->sync = value;
  27079. + status = VCHIQ_SUCCESS;
  27080. + }
  27081. + break;
  27082. +
  27083. + default:
  27084. + break;
  27085. + }
  27086. + unlock_service(service);
  27087. + }
  27088. +
  27089. + return status;
  27090. +}
  27091. +
  27092. +void
  27093. +vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
  27094. + VCHIQ_SHARED_STATE_T *shared, const char *label)
  27095. +{
  27096. + static const char *const debug_names[] = {
  27097. + "<entries>",
  27098. + "SLOT_HANDLER_COUNT",
  27099. + "SLOT_HANDLER_LINE",
  27100. + "PARSE_LINE",
  27101. + "PARSE_HEADER",
  27102. + "PARSE_MSGID",
  27103. + "AWAIT_COMPLETION_LINE",
  27104. + "DEQUEUE_MESSAGE_LINE",
  27105. + "SERVICE_CALLBACK_LINE",
  27106. + "MSG_QUEUE_FULL_COUNT",
  27107. + "COMPLETION_QUEUE_FULL_COUNT"
  27108. + };
  27109. + int i;
  27110. +
  27111. + char buf[80];
  27112. + int len;
  27113. + len = snprintf(buf, sizeof(buf),
  27114. + " %s: slots %d-%d tx_pos=%x recycle=%x",
  27115. + label, shared->slot_first, shared->slot_last,
  27116. + shared->tx_pos, shared->slot_queue_recycle);
  27117. + vchiq_dump(dump_context, buf, len + 1);
  27118. +
  27119. + len = snprintf(buf, sizeof(buf),
  27120. + " Slots claimed:");
  27121. + vchiq_dump(dump_context, buf, len + 1);
  27122. +
  27123. + for (i = shared->slot_first; i <= shared->slot_last; i++) {
  27124. + VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i);
  27125. + if (slot_info.use_count != slot_info.release_count) {
  27126. + len = snprintf(buf, sizeof(buf),
  27127. + " %d: %d/%d", i, slot_info.use_count,
  27128. + slot_info.release_count);
  27129. + vchiq_dump(dump_context, buf, len + 1);
  27130. + }
  27131. + }
  27132. +
  27133. + for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
  27134. + len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
  27135. + debug_names[i], shared->debug[i], shared->debug[i]);
  27136. + vchiq_dump(dump_context, buf, len + 1);
  27137. + }
  27138. +}
  27139. +
  27140. +void
  27141. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state)
  27142. +{
  27143. + char buf[80];
  27144. + int len;
  27145. + int i;
  27146. +
  27147. + len = snprintf(buf, sizeof(buf), "State %d: %s", state->id,
  27148. + conn_state_names[state->conn_state]);
  27149. + vchiq_dump(dump_context, buf, len + 1);
  27150. +
  27151. + len = snprintf(buf, sizeof(buf),
  27152. + " tx_pos=%x(@%x), rx_pos=%x(@%x)",
  27153. + state->local->tx_pos,
  27154. + (uint32_t)state->tx_data +
  27155. + (state->local_tx_pos & VCHIQ_SLOT_MASK),
  27156. + state->rx_pos,
  27157. + (uint32_t)state->rx_data +
  27158. + (state->rx_pos & VCHIQ_SLOT_MASK));
  27159. + vchiq_dump(dump_context, buf, len + 1);
  27160. +
  27161. + len = snprintf(buf, sizeof(buf),
  27162. + " Version: %d (min %d)",
  27163. + VCHIQ_VERSION, VCHIQ_VERSION_MIN);
  27164. + vchiq_dump(dump_context, buf, len + 1);
  27165. +
  27166. + if (VCHIQ_ENABLE_STATS) {
  27167. + len = snprintf(buf, sizeof(buf),
  27168. + " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
  27169. + "error_count=%d",
  27170. + state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
  27171. + state->stats.error_count);
  27172. + vchiq_dump(dump_context, buf, len + 1);
  27173. + }
  27174. +
  27175. + len = snprintf(buf, sizeof(buf),
  27176. + " Slots: %d available (%d data), %d recyclable, %d stalls "
  27177. + "(%d data)",
  27178. + ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
  27179. + state->local_tx_pos) / VCHIQ_SLOT_SIZE,
  27180. + state->data_quota - state->data_use_count,
  27181. + state->local->slot_queue_recycle - state->slot_queue_available,
  27182. + state->stats.slot_stalls, state->stats.data_stalls);
  27183. + vchiq_dump(dump_context, buf, len + 1);
  27184. +
  27185. + vchiq_dump_platform_state(dump_context);
  27186. +
  27187. + vchiq_dump_shared_state(dump_context, state, state->local, "Local");
  27188. + vchiq_dump_shared_state(dump_context, state, state->remote, "Remote");
  27189. +
  27190. + vchiq_dump_platform_instances(dump_context);
  27191. +
  27192. + for (i = 0; i < state->unused_service; i++) {
  27193. + VCHIQ_SERVICE_T *service = find_service_by_port(state, i);
  27194. +
  27195. + if (service) {
  27196. + vchiq_dump_service_state(dump_context, service);
  27197. + unlock_service(service);
  27198. + }
  27199. + }
  27200. +}
  27201. +
  27202. +void
  27203. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  27204. +{
  27205. + char buf[80];
  27206. + int len;
  27207. +
  27208. + len = snprintf(buf, sizeof(buf), "Service %d: %s (ref %u)",
  27209. + service->localport, srvstate_names[service->srvstate],
  27210. + service->ref_count - 1); /*Don't include the lock just taken*/
  27211. +
  27212. + if (service->srvstate != VCHIQ_SRVSTATE_FREE) {
  27213. + char remoteport[30];
  27214. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  27215. + &service->state->service_quotas[service->localport];
  27216. + int fourcc = service->base.fourcc;
  27217. + int tx_pending, rx_pending;
  27218. + if (service->remoteport != VCHIQ_PORT_FREE) {
  27219. + int len2 = snprintf(remoteport, sizeof(remoteport),
  27220. + "%d", service->remoteport);
  27221. + if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
  27222. + snprintf(remoteport + len2,
  27223. + sizeof(remoteport) - len2,
  27224. + " (client %x)", service->client_id);
  27225. + } else
  27226. + strcpy(remoteport, "n/a");
  27227. +
  27228. + len += snprintf(buf + len, sizeof(buf) - len,
  27229. + " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
  27230. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  27231. + remoteport,
  27232. + service_quota->message_use_count,
  27233. + service_quota->message_quota,
  27234. + service_quota->slot_use_count,
  27235. + service_quota->slot_quota);
  27236. +
  27237. + vchiq_dump(dump_context, buf, len + 1);
  27238. +
  27239. + tx_pending = service->bulk_tx.local_insert -
  27240. + service->bulk_tx.remote_insert;
  27241. +
  27242. + rx_pending = service->bulk_rx.local_insert -
  27243. + service->bulk_rx.remote_insert;
  27244. +
  27245. + len = snprintf(buf, sizeof(buf),
  27246. + " Bulk: tx_pending=%d (size %d),"
  27247. + " rx_pending=%d (size %d)",
  27248. + tx_pending,
  27249. + tx_pending ? service->bulk_tx.bulks[
  27250. + BULK_INDEX(service->bulk_tx.remove)].size : 0,
  27251. + rx_pending,
  27252. + rx_pending ? service->bulk_rx.bulks[
  27253. + BULK_INDEX(service->bulk_rx.remove)].size : 0);
  27254. +
  27255. + if (VCHIQ_ENABLE_STATS) {
  27256. + vchiq_dump(dump_context, buf, len + 1);
  27257. +
  27258. + len = snprintf(buf, sizeof(buf),
  27259. + " Ctrl: tx_count=%d, tx_bytes=%llu, "
  27260. + "rx_count=%d, rx_bytes=%llu",
  27261. + service->stats.ctrl_tx_count,
  27262. + service->stats.ctrl_tx_bytes,
  27263. + service->stats.ctrl_rx_count,
  27264. + service->stats.ctrl_rx_bytes);
  27265. + vchiq_dump(dump_context, buf, len + 1);
  27266. +
  27267. + len = snprintf(buf, sizeof(buf),
  27268. + " Bulk: tx_count=%d, tx_bytes=%llu, "
  27269. + "rx_count=%d, rx_bytes=%llu",
  27270. + service->stats.bulk_tx_count,
  27271. + service->stats.bulk_tx_bytes,
  27272. + service->stats.bulk_rx_count,
  27273. + service->stats.bulk_rx_bytes);
  27274. + vchiq_dump(dump_context, buf, len + 1);
  27275. +
  27276. + len = snprintf(buf, sizeof(buf),
  27277. + " %d quota stalls, %d slot stalls, "
  27278. + "%d bulk stalls, %d aborted, %d errors",
  27279. + service->stats.quota_stalls,
  27280. + service->stats.slot_stalls,
  27281. + service->stats.bulk_stalls,
  27282. + service->stats.bulk_aborted_count,
  27283. + service->stats.error_count);
  27284. + }
  27285. + }
  27286. +
  27287. + vchiq_dump(dump_context, buf, len + 1);
  27288. +
  27289. + if (service->srvstate != VCHIQ_SRVSTATE_FREE)
  27290. + vchiq_dump_platform_service_state(dump_context, service);
  27291. +}
  27292. +
  27293. +
  27294. +void
  27295. +vchiq_loud_error_header(void)
  27296. +{
  27297. + vchiq_log_error(vchiq_core_log_level,
  27298. + "============================================================"
  27299. + "================");
  27300. + vchiq_log_error(vchiq_core_log_level,
  27301. + "============================================================"
  27302. + "================");
  27303. + vchiq_log_error(vchiq_core_log_level, "=====");
  27304. +}
  27305. +
  27306. +void
  27307. +vchiq_loud_error_footer(void)
  27308. +{
  27309. + vchiq_log_error(vchiq_core_log_level, "=====");
  27310. + vchiq_log_error(vchiq_core_log_level,
  27311. + "============================================================"
  27312. + "================");
  27313. + vchiq_log_error(vchiq_core_log_level,
  27314. + "============================================================"
  27315. + "================");
  27316. +}
  27317. +
  27318. +
  27319. +VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
  27320. +{
  27321. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  27322. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  27323. + status = queue_message(state, NULL,
  27324. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
  27325. + NULL, 0, 0, 0);
  27326. + return status;
  27327. +}
  27328. +
  27329. +VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
  27330. +{
  27331. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  27332. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  27333. + status = queue_message(state, NULL,
  27334. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
  27335. + NULL, 0, 0, 0);
  27336. + return status;
  27337. +}
  27338. +
  27339. +VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
  27340. +{
  27341. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  27342. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  27343. + status = queue_message(state, NULL,
  27344. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
  27345. + NULL, 0, 0, 0);
  27346. + return status;
  27347. +}
  27348. +
  27349. +void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  27350. + size_t numBytes)
  27351. +{
  27352. + const uint8_t *mem = (const uint8_t *)voidMem;
  27353. + size_t offset;
  27354. + char lineBuf[100];
  27355. + char *s;
  27356. +
  27357. + while (numBytes > 0) {
  27358. + s = lineBuf;
  27359. +
  27360. + for (offset = 0; offset < 16; offset++) {
  27361. + if (offset < numBytes)
  27362. + s += snprintf(s, 4, "%02x ", mem[offset]);
  27363. + else
  27364. + s += snprintf(s, 4, " ");
  27365. + }
  27366. +
  27367. + for (offset = 0; offset < 16; offset++) {
  27368. + if (offset < numBytes) {
  27369. + uint8_t ch = mem[offset];
  27370. +
  27371. + if ((ch < ' ') || (ch > '~'))
  27372. + ch = '.';
  27373. + *s++ = (char)ch;
  27374. + }
  27375. + }
  27376. + *s++ = '\0';
  27377. +
  27378. + if ((label != NULL) && (*label != '\0'))
  27379. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  27380. + "%s: %08x: %s", label, addr, lineBuf);
  27381. + else
  27382. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  27383. + "%08x: %s", addr, lineBuf);
  27384. +
  27385. + addr += 16;
  27386. + mem += 16;
  27387. + if (numBytes > 16)
  27388. + numBytes -= 16;
  27389. + else
  27390. + numBytes = 0;
  27391. + }
  27392. +}
  27393. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h
  27394. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 1970-01-01 01:00:00.000000000 +0100
  27395. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 2014-04-24 15:35:02.893551516 +0200
  27396. @@ -0,0 +1,706 @@
  27397. +/**
  27398. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27399. + *
  27400. + * Redistribution and use in source and binary forms, with or without
  27401. + * modification, are permitted provided that the following conditions
  27402. + * are met:
  27403. + * 1. Redistributions of source code must retain the above copyright
  27404. + * notice, this list of conditions, and the following disclaimer,
  27405. + * without modification.
  27406. + * 2. Redistributions in binary form must reproduce the above copyright
  27407. + * notice, this list of conditions and the following disclaimer in the
  27408. + * documentation and/or other materials provided with the distribution.
  27409. + * 3. The names of the above-listed copyright holders may not be used
  27410. + * to endorse or promote products derived from this software without
  27411. + * specific prior written permission.
  27412. + *
  27413. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27414. + * GNU General Public License ("GPL") version 2, as published by the Free
  27415. + * Software Foundation.
  27416. + *
  27417. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27418. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27419. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27420. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27421. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27422. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27423. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27424. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27425. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27426. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27427. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27428. + */
  27429. +
  27430. +#ifndef VCHIQ_CORE_H
  27431. +#define VCHIQ_CORE_H
  27432. +
  27433. +#include <linux/mutex.h>
  27434. +#include <linux/semaphore.h>
  27435. +#include <linux/kthread.h>
  27436. +
  27437. +#include "vchiq_cfg.h"
  27438. +
  27439. +#include "vchiq.h"
  27440. +
  27441. +/* Run time control of log level, based on KERN_XXX level. */
  27442. +#define VCHIQ_LOG_DEFAULT 4
  27443. +#define VCHIQ_LOG_ERROR 3
  27444. +#define VCHIQ_LOG_WARNING 4
  27445. +#define VCHIQ_LOG_INFO 6
  27446. +#define VCHIQ_LOG_TRACE 7
  27447. +
  27448. +#define VCHIQ_LOG_PREFIX KERN_INFO "vchiq: "
  27449. +
  27450. +#ifndef vchiq_log_error
  27451. +#define vchiq_log_error(cat, fmt, ...) \
  27452. + do { if (cat >= VCHIQ_LOG_ERROR) \
  27453. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  27454. +#endif
  27455. +#ifndef vchiq_log_warning
  27456. +#define vchiq_log_warning(cat, fmt, ...) \
  27457. + do { if (cat >= VCHIQ_LOG_WARNING) \
  27458. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  27459. +#endif
  27460. +#ifndef vchiq_log_info
  27461. +#define vchiq_log_info(cat, fmt, ...) \
  27462. + do { if (cat >= VCHIQ_LOG_INFO) \
  27463. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  27464. +#endif
  27465. +#ifndef vchiq_log_trace
  27466. +#define vchiq_log_trace(cat, fmt, ...) \
  27467. + do { if (cat >= VCHIQ_LOG_TRACE) \
  27468. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  27469. +#endif
  27470. +
  27471. +#define vchiq_loud_error(...) \
  27472. + vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
  27473. +
  27474. +#ifndef vchiq_static_assert
  27475. +#define vchiq_static_assert(cond) __attribute__((unused)) \
  27476. + extern int vchiq_static_assert[(cond) ? 1 : -1]
  27477. +#endif
  27478. +
  27479. +#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
  27480. +
  27481. +/* Ensure that the slot size and maximum number of slots are powers of 2 */
  27482. +vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
  27483. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
  27484. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
  27485. +
  27486. +#define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
  27487. +#define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
  27488. +#define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
  27489. + VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
  27490. +
  27491. +#define VCHIQ_MSG_PADDING 0 /* - */
  27492. +#define VCHIQ_MSG_CONNECT 1 /* - */
  27493. +#define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
  27494. +#define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
  27495. +#define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
  27496. +#define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
  27497. +#define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
  27498. +#define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
  27499. +#define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
  27500. +#define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
  27501. +#define VCHIQ_MSG_PAUSE 10 /* - */
  27502. +#define VCHIQ_MSG_RESUME 11 /* - */
  27503. +#define VCHIQ_MSG_REMOTE_USE 12 /* - */
  27504. +#define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
  27505. +#define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
  27506. +
  27507. +#define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
  27508. +#define VCHIQ_PORT_FREE 0x1000
  27509. +#define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
  27510. +#define VCHIQ_MAKE_MSG(type, srcport, dstport) \
  27511. + ((type<<24) | (srcport<<12) | (dstport<<0))
  27512. +#define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
  27513. +#define VCHIQ_MSG_SRCPORT(msgid) \
  27514. + (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
  27515. +#define VCHIQ_MSG_DSTPORT(msgid) \
  27516. + ((unsigned short)msgid & 0xfff)
  27517. +
  27518. +#define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
  27519. + ((fourcc) >> 24) & 0xff, \
  27520. + ((fourcc) >> 16) & 0xff, \
  27521. + ((fourcc) >> 8) & 0xff, \
  27522. + (fourcc) & 0xff
  27523. +
  27524. +/* Ensure the fields are wide enough */
  27525. +vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
  27526. + == 0);
  27527. +vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
  27528. +vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
  27529. + (unsigned int)VCHIQ_PORT_FREE);
  27530. +
  27531. +#define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
  27532. +#define VCHIQ_MSGID_CLAIMED 0x40000000
  27533. +
  27534. +#define VCHIQ_FOURCC_INVALID 0x00000000
  27535. +#define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
  27536. +
  27537. +#define VCHIQ_BULK_ACTUAL_ABORTED -1
  27538. +
  27539. +typedef uint32_t BITSET_T;
  27540. +
  27541. +vchiq_static_assert((sizeof(BITSET_T) * 8) == 32);
  27542. +
  27543. +#define BITSET_SIZE(b) ((b + 31) >> 5)
  27544. +#define BITSET_WORD(b) (b >> 5)
  27545. +#define BITSET_BIT(b) (1 << (b & 31))
  27546. +#define BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
  27547. +#define BITSET_IS_SET(bs, b) (bs[BITSET_WORD(b)] & BITSET_BIT(b))
  27548. +#define BITSET_SET(bs, b) (bs[BITSET_WORD(b)] |= BITSET_BIT(b))
  27549. +#define BITSET_CLR(bs, b) (bs[BITSET_WORD(b)] &= ~BITSET_BIT(b))
  27550. +
  27551. +#if VCHIQ_ENABLE_STATS
  27552. +#define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
  27553. +#define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
  27554. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
  27555. + (service->stats. stat += addend)
  27556. +#else
  27557. +#define VCHIQ_STATS_INC(state, stat) ((void)0)
  27558. +#define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
  27559. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
  27560. +#endif
  27561. +
  27562. +enum {
  27563. + DEBUG_ENTRIES,
  27564. +#if VCHIQ_ENABLE_DEBUG
  27565. + DEBUG_SLOT_HANDLER_COUNT,
  27566. + DEBUG_SLOT_HANDLER_LINE,
  27567. + DEBUG_PARSE_LINE,
  27568. + DEBUG_PARSE_HEADER,
  27569. + DEBUG_PARSE_MSGID,
  27570. + DEBUG_AWAIT_COMPLETION_LINE,
  27571. + DEBUG_DEQUEUE_MESSAGE_LINE,
  27572. + DEBUG_SERVICE_CALLBACK_LINE,
  27573. + DEBUG_MSG_QUEUE_FULL_COUNT,
  27574. + DEBUG_COMPLETION_QUEUE_FULL_COUNT,
  27575. +#endif
  27576. + DEBUG_MAX
  27577. +};
  27578. +
  27579. +#if VCHIQ_ENABLE_DEBUG
  27580. +
  27581. +#define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
  27582. +#define DEBUG_TRACE(d) \
  27583. + do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
  27584. +#define DEBUG_VALUE(d, v) \
  27585. + do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
  27586. +#define DEBUG_COUNT(d) \
  27587. + do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
  27588. +
  27589. +#else /* VCHIQ_ENABLE_DEBUG */
  27590. +
  27591. +#define DEBUG_INITIALISE(local)
  27592. +#define DEBUG_TRACE(d)
  27593. +#define DEBUG_VALUE(d, v)
  27594. +#define DEBUG_COUNT(d)
  27595. +
  27596. +#endif /* VCHIQ_ENABLE_DEBUG */
  27597. +
  27598. +typedef enum {
  27599. + VCHIQ_CONNSTATE_DISCONNECTED,
  27600. + VCHIQ_CONNSTATE_CONNECTING,
  27601. + VCHIQ_CONNSTATE_CONNECTED,
  27602. + VCHIQ_CONNSTATE_PAUSING,
  27603. + VCHIQ_CONNSTATE_PAUSE_SENT,
  27604. + VCHIQ_CONNSTATE_PAUSED,
  27605. + VCHIQ_CONNSTATE_RESUMING,
  27606. + VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
  27607. + VCHIQ_CONNSTATE_RESUME_TIMEOUT
  27608. +} VCHIQ_CONNSTATE_T;
  27609. +
  27610. +enum {
  27611. + VCHIQ_SRVSTATE_FREE,
  27612. + VCHIQ_SRVSTATE_HIDDEN,
  27613. + VCHIQ_SRVSTATE_LISTENING,
  27614. + VCHIQ_SRVSTATE_OPENING,
  27615. + VCHIQ_SRVSTATE_OPEN,
  27616. + VCHIQ_SRVSTATE_OPENSYNC,
  27617. + VCHIQ_SRVSTATE_CLOSESENT,
  27618. + VCHIQ_SRVSTATE_CLOSERECVD,
  27619. + VCHIQ_SRVSTATE_CLOSEWAIT,
  27620. + VCHIQ_SRVSTATE_CLOSED
  27621. +};
  27622. +
  27623. +enum {
  27624. + VCHIQ_POLL_TERMINATE,
  27625. + VCHIQ_POLL_REMOVE,
  27626. + VCHIQ_POLL_TXNOTIFY,
  27627. + VCHIQ_POLL_RXNOTIFY,
  27628. + VCHIQ_POLL_COUNT
  27629. +};
  27630. +
  27631. +typedef enum {
  27632. + VCHIQ_BULK_TRANSMIT,
  27633. + VCHIQ_BULK_RECEIVE
  27634. +} VCHIQ_BULK_DIR_T;
  27635. +
  27636. +typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
  27637. +
  27638. +typedef struct vchiq_bulk_struct {
  27639. + short mode;
  27640. + short dir;
  27641. + void *userdata;
  27642. + VCHI_MEM_HANDLE_T handle;
  27643. + void *data;
  27644. + int size;
  27645. + void *remote_data;
  27646. + int remote_size;
  27647. + int actual;
  27648. +} VCHIQ_BULK_T;
  27649. +
  27650. +typedef struct vchiq_bulk_queue_struct {
  27651. + int local_insert; /* Where to insert the next local bulk */
  27652. + int remote_insert; /* Where to insert the next remote bulk (master) */
  27653. + int process; /* Bulk to transfer next */
  27654. + int remote_notify; /* Bulk to notify the remote client of next (mstr) */
  27655. + int remove; /* Bulk to notify the local client of, and remove,
  27656. + ** next */
  27657. + VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
  27658. +} VCHIQ_BULK_QUEUE_T;
  27659. +
  27660. +typedef struct remote_event_struct {
  27661. + int armed;
  27662. + int fired;
  27663. + struct semaphore *event;
  27664. +} REMOTE_EVENT_T;
  27665. +
  27666. +typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
  27667. +
  27668. +typedef struct vchiq_state_struct VCHIQ_STATE_T;
  27669. +
  27670. +typedef struct vchiq_slot_struct {
  27671. + char data[VCHIQ_SLOT_SIZE];
  27672. +} VCHIQ_SLOT_T;
  27673. +
  27674. +typedef struct vchiq_slot_info_struct {
  27675. + /* Use two counters rather than one to avoid the need for a mutex. */
  27676. + short use_count;
  27677. + short release_count;
  27678. +} VCHIQ_SLOT_INFO_T;
  27679. +
  27680. +typedef struct vchiq_service_struct {
  27681. + VCHIQ_SERVICE_BASE_T base;
  27682. + VCHIQ_SERVICE_HANDLE_T handle;
  27683. + unsigned int ref_count;
  27684. + int srvstate;
  27685. + VCHIQ_USERDATA_TERM_T userdata_term;
  27686. + unsigned int localport;
  27687. + unsigned int remoteport;
  27688. + int public_fourcc;
  27689. + int client_id;
  27690. + char auto_close;
  27691. + char sync;
  27692. + char closing;
  27693. + atomic_t poll_flags;
  27694. + short version;
  27695. + short version_min;
  27696. + short peer_version;
  27697. +
  27698. + VCHIQ_STATE_T *state;
  27699. + VCHIQ_INSTANCE_T instance;
  27700. +
  27701. + int service_use_count;
  27702. +
  27703. + VCHIQ_BULK_QUEUE_T bulk_tx;
  27704. + VCHIQ_BULK_QUEUE_T bulk_rx;
  27705. +
  27706. + struct semaphore remove_event;
  27707. + struct semaphore bulk_remove_event;
  27708. + struct mutex bulk_mutex;
  27709. +
  27710. + struct service_stats_struct {
  27711. + int quota_stalls;
  27712. + int slot_stalls;
  27713. + int bulk_stalls;
  27714. + int error_count;
  27715. + int ctrl_tx_count;
  27716. + int ctrl_rx_count;
  27717. + int bulk_tx_count;
  27718. + int bulk_rx_count;
  27719. + int bulk_aborted_count;
  27720. + uint64_t ctrl_tx_bytes;
  27721. + uint64_t ctrl_rx_bytes;
  27722. + uint64_t bulk_tx_bytes;
  27723. + uint64_t bulk_rx_bytes;
  27724. + } stats;
  27725. +} VCHIQ_SERVICE_T;
  27726. +
  27727. +/* The quota information is outside VCHIQ_SERVICE_T so that it can be
  27728. + statically allocated, since for accounting reasons a service's slot
  27729. + usage is carried over between users of the same port number.
  27730. + */
  27731. +typedef struct vchiq_service_quota_struct {
  27732. + unsigned short slot_quota;
  27733. + unsigned short slot_use_count;
  27734. + unsigned short message_quota;
  27735. + unsigned short message_use_count;
  27736. + struct semaphore quota_event;
  27737. + int previous_tx_index;
  27738. +} VCHIQ_SERVICE_QUOTA_T;
  27739. +
  27740. +typedef struct vchiq_shared_state_struct {
  27741. +
  27742. + /* A non-zero value here indicates that the content is valid. */
  27743. + int initialised;
  27744. +
  27745. + /* The first and last (inclusive) slots allocated to the owner. */
  27746. + int slot_first;
  27747. + int slot_last;
  27748. +
  27749. + /* The slot allocated to synchronous messages from the owner. */
  27750. + int slot_sync;
  27751. +
  27752. + /* Signalling this event indicates that owner's slot handler thread
  27753. + ** should run. */
  27754. + REMOTE_EVENT_T trigger;
  27755. +
  27756. + /* Indicates the byte position within the stream where the next message
  27757. + ** will be written. The least significant bits are an index into the
  27758. + ** slot. The next bits are the index of the slot in slot_queue. */
  27759. + int tx_pos;
  27760. +
  27761. + /* This event should be signalled when a slot is recycled. */
  27762. + REMOTE_EVENT_T recycle;
  27763. +
  27764. + /* The slot_queue index where the next recycled slot will be written. */
  27765. + int slot_queue_recycle;
  27766. +
  27767. + /* This event should be signalled when a synchronous message is sent. */
  27768. + REMOTE_EVENT_T sync_trigger;
  27769. +
  27770. + /* This event should be signalled when a synchronous message has been
  27771. + ** released. */
  27772. + REMOTE_EVENT_T sync_release;
  27773. +
  27774. + /* A circular buffer of slot indexes. */
  27775. + int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
  27776. +
  27777. + /* Debugging state */
  27778. + int debug[DEBUG_MAX];
  27779. +} VCHIQ_SHARED_STATE_T;
  27780. +
  27781. +typedef struct vchiq_slot_zero_struct {
  27782. + int magic;
  27783. + short version;
  27784. + short version_min;
  27785. + int slot_zero_size;
  27786. + int slot_size;
  27787. + int max_slots;
  27788. + int max_slots_per_side;
  27789. + int platform_data[2];
  27790. + VCHIQ_SHARED_STATE_T master;
  27791. + VCHIQ_SHARED_STATE_T slave;
  27792. + VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
  27793. +} VCHIQ_SLOT_ZERO_T;
  27794. +
  27795. +struct vchiq_state_struct {
  27796. + int id;
  27797. + int initialised;
  27798. + VCHIQ_CONNSTATE_T conn_state;
  27799. + int is_master;
  27800. +
  27801. + VCHIQ_SHARED_STATE_T *local;
  27802. + VCHIQ_SHARED_STATE_T *remote;
  27803. + VCHIQ_SLOT_T *slot_data;
  27804. +
  27805. + unsigned short default_slot_quota;
  27806. + unsigned short default_message_quota;
  27807. +
  27808. + /* Event indicating connect message received */
  27809. + struct semaphore connect;
  27810. +
  27811. + /* Mutex protecting services */
  27812. + struct mutex mutex;
  27813. + VCHIQ_INSTANCE_T *instance;
  27814. +
  27815. + /* Processes incoming messages */
  27816. + struct task_struct *slot_handler_thread;
  27817. +
  27818. + /* Processes recycled slots */
  27819. + struct task_struct *recycle_thread;
  27820. +
  27821. + /* Processes synchronous messages */
  27822. + struct task_struct *sync_thread;
  27823. +
  27824. + /* Local implementation of the trigger remote event */
  27825. + struct semaphore trigger_event;
  27826. +
  27827. + /* Local implementation of the recycle remote event */
  27828. + struct semaphore recycle_event;
  27829. +
  27830. + /* Local implementation of the sync trigger remote event */
  27831. + struct semaphore sync_trigger_event;
  27832. +
  27833. + /* Local implementation of the sync release remote event */
  27834. + struct semaphore sync_release_event;
  27835. +
  27836. + char *tx_data;
  27837. + char *rx_data;
  27838. + VCHIQ_SLOT_INFO_T *rx_info;
  27839. +
  27840. + struct mutex slot_mutex;
  27841. +
  27842. + struct mutex recycle_mutex;
  27843. +
  27844. + struct mutex sync_mutex;
  27845. +
  27846. + struct mutex bulk_transfer_mutex;
  27847. +
  27848. + /* Indicates the byte position within the stream from where the next
  27849. + ** message will be read. The least significant bits are an index into
  27850. + ** the slot.The next bits are the index of the slot in
  27851. + ** remote->slot_queue. */
  27852. + int rx_pos;
  27853. +
  27854. + /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
  27855. + from remote->tx_pos. */
  27856. + int local_tx_pos;
  27857. +
  27858. + /* The slot_queue index of the slot to become available next. */
  27859. + int slot_queue_available;
  27860. +
  27861. + /* A flag to indicate if any poll has been requested */
  27862. + int poll_needed;
  27863. +
  27864. + /* Ths index of the previous slot used for data messages. */
  27865. + int previous_data_index;
  27866. +
  27867. + /* The number of slots occupied by data messages. */
  27868. + unsigned short data_use_count;
  27869. +
  27870. + /* The maximum number of slots to be occupied by data messages. */
  27871. + unsigned short data_quota;
  27872. +
  27873. + /* An array of bit sets indicating which services must be polled. */
  27874. + atomic_t poll_services[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  27875. +
  27876. + /* The number of the first unused service */
  27877. + int unused_service;
  27878. +
  27879. + /* Signalled when a free slot becomes available. */
  27880. + struct semaphore slot_available_event;
  27881. +
  27882. + struct semaphore slot_remove_event;
  27883. +
  27884. + /* Signalled when a free data slot becomes available. */
  27885. + struct semaphore data_quota_event;
  27886. +
  27887. + /* Incremented when there are bulk transfers which cannot be processed
  27888. + * whilst paused and must be processed on resume */
  27889. + int deferred_bulks;
  27890. +
  27891. + struct state_stats_struct {
  27892. + int slot_stalls;
  27893. + int data_stalls;
  27894. + int ctrl_tx_count;
  27895. + int ctrl_rx_count;
  27896. + int error_count;
  27897. + } stats;
  27898. +
  27899. + VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
  27900. + VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
  27901. + VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
  27902. +
  27903. + VCHIQ_PLATFORM_STATE_T platform_state;
  27904. +};
  27905. +
  27906. +struct bulk_waiter {
  27907. + VCHIQ_BULK_T *bulk;
  27908. + struct semaphore event;
  27909. + int actual;
  27910. +};
  27911. +
  27912. +extern spinlock_t bulk_waiter_spinlock;
  27913. +
  27914. +extern int vchiq_core_log_level;
  27915. +extern int vchiq_core_msg_log_level;
  27916. +extern int vchiq_sync_log_level;
  27917. +
  27918. +extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  27919. +
  27920. +extern const char *
  27921. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
  27922. +
  27923. +extern VCHIQ_SLOT_ZERO_T *
  27924. +vchiq_init_slots(void *mem_base, int mem_size);
  27925. +
  27926. +extern VCHIQ_STATUS_T
  27927. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  27928. + int is_master);
  27929. +
  27930. +extern VCHIQ_STATUS_T
  27931. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  27932. +
  27933. +extern VCHIQ_SERVICE_T *
  27934. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  27935. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  27936. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
  27937. +
  27938. +extern VCHIQ_STATUS_T
  27939. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
  27940. +
  27941. +extern VCHIQ_STATUS_T
  27942. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
  27943. +
  27944. +extern void
  27945. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
  27946. +
  27947. +extern void
  27948. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
  27949. +
  27950. +extern VCHIQ_STATUS_T
  27951. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  27952. +
  27953. +extern VCHIQ_STATUS_T
  27954. +vchiq_pause_internal(VCHIQ_STATE_T *state);
  27955. +
  27956. +extern VCHIQ_STATUS_T
  27957. +vchiq_resume_internal(VCHIQ_STATE_T *state);
  27958. +
  27959. +extern void
  27960. +remote_event_pollall(VCHIQ_STATE_T *state);
  27961. +
  27962. +extern VCHIQ_STATUS_T
  27963. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  27964. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  27965. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
  27966. +
  27967. +extern void
  27968. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
  27969. +
  27970. +extern void
  27971. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
  27972. +
  27973. +extern void
  27974. +vchiq_loud_error_header(void);
  27975. +
  27976. +extern void
  27977. +vchiq_loud_error_footer(void);
  27978. +
  27979. +extern void
  27980. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
  27981. +
  27982. +static inline VCHIQ_SERVICE_T *
  27983. +handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
  27984. +{
  27985. + VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
  27986. + (VCHIQ_MAX_STATES - 1)];
  27987. + if (!state)
  27988. + return NULL;
  27989. +
  27990. + return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
  27991. +}
  27992. +
  27993. +extern VCHIQ_SERVICE_T *
  27994. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
  27995. +
  27996. +extern VCHIQ_SERVICE_T *
  27997. +find_service_by_port(VCHIQ_STATE_T *state, int localport);
  27998. +
  27999. +extern VCHIQ_SERVICE_T *
  28000. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  28001. + VCHIQ_SERVICE_HANDLE_T handle);
  28002. +
  28003. +extern VCHIQ_SERVICE_T *
  28004. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  28005. + int *pidx);
  28006. +
  28007. +extern void
  28008. +lock_service(VCHIQ_SERVICE_T *service);
  28009. +
  28010. +extern void
  28011. +unlock_service(VCHIQ_SERVICE_T *service);
  28012. +
  28013. +/* The following functions are called from vchiq_core, and external
  28014. +** implementations must be provided. */
  28015. +
  28016. +extern VCHIQ_STATUS_T
  28017. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
  28018. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
  28019. +
  28020. +extern void
  28021. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
  28022. +
  28023. +extern void
  28024. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
  28025. +
  28026. +extern VCHIQ_STATUS_T
  28027. +vchiq_copy_from_user(void *dst, const void *src, int size);
  28028. +
  28029. +extern void
  28030. +remote_event_signal(REMOTE_EVENT_T *event);
  28031. +
  28032. +void
  28033. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
  28034. +
  28035. +extern void
  28036. +vchiq_platform_paused(VCHIQ_STATE_T *state);
  28037. +
  28038. +extern VCHIQ_STATUS_T
  28039. +vchiq_platform_resume(VCHIQ_STATE_T *state);
  28040. +
  28041. +extern void
  28042. +vchiq_platform_resumed(VCHIQ_STATE_T *state);
  28043. +
  28044. +extern void
  28045. +vchiq_dump(void *dump_context, const char *str, int len);
  28046. +
  28047. +extern void
  28048. +vchiq_dump_platform_state(void *dump_context);
  28049. +
  28050. +extern void
  28051. +vchiq_dump_platform_instances(void *dump_context);
  28052. +
  28053. +extern void
  28054. +vchiq_dump_platform_service_state(void *dump_context,
  28055. + VCHIQ_SERVICE_T *service);
  28056. +
  28057. +extern VCHIQ_STATUS_T
  28058. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
  28059. +
  28060. +extern VCHIQ_STATUS_T
  28061. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
  28062. +
  28063. +extern void
  28064. +vchiq_on_remote_use(VCHIQ_STATE_T *state);
  28065. +
  28066. +extern void
  28067. +vchiq_on_remote_release(VCHIQ_STATE_T *state);
  28068. +
  28069. +extern VCHIQ_STATUS_T
  28070. +vchiq_platform_init_state(VCHIQ_STATE_T *state);
  28071. +
  28072. +extern VCHIQ_STATUS_T
  28073. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  28074. +
  28075. +extern void
  28076. +vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
  28077. +
  28078. +extern VCHIQ_STATUS_T
  28079. +vchiq_send_remote_use(VCHIQ_STATE_T *state);
  28080. +
  28081. +extern VCHIQ_STATUS_T
  28082. +vchiq_send_remote_release(VCHIQ_STATE_T *state);
  28083. +
  28084. +extern VCHIQ_STATUS_T
  28085. +vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
  28086. +
  28087. +extern void
  28088. +vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  28089. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
  28090. +
  28091. +extern void
  28092. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
  28093. +
  28094. +extern void
  28095. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
  28096. +
  28097. +
  28098. +extern void
  28099. +vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  28100. + size_t numBytes);
  28101. +
  28102. +#endif
  28103. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion
  28104. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 1970-01-01 01:00:00.000000000 +0100
  28105. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 2014-04-24 16:04:36.831095364 +0200
  28106. @@ -0,0 +1,87 @@
  28107. +#!/usr/bin/perl -w
  28108. +
  28109. +use strict;
  28110. +
  28111. +#
  28112. +# Generate a version from available information
  28113. +#
  28114. +
  28115. +my $prefix = shift @ARGV;
  28116. +my $root = shift @ARGV;
  28117. +
  28118. +
  28119. +if ( not defined $root ) {
  28120. + die "usage: $0 prefix root-dir\n";
  28121. +}
  28122. +
  28123. +if ( ! -d $root ) {
  28124. + die "root directory $root not found\n";
  28125. +}
  28126. +
  28127. +my $version = "unknown";
  28128. +my $tainted = "";
  28129. +
  28130. +if ( -d "$root/.git" ) {
  28131. + # attempt to work out git version. only do so
  28132. + # on a linux build host, as cygwin builds are
  28133. + # already slow enough
  28134. +
  28135. + if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
  28136. + if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
  28137. + $version = "no git version";
  28138. + }
  28139. + else {
  28140. + $version = <F>;
  28141. + $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  28142. + $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  28143. + }
  28144. +
  28145. + if (open(G, "git --git-dir $root/.git status --porcelain|")) {
  28146. + $tainted = <G>;
  28147. + $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  28148. + $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  28149. + if (length $tainted) {
  28150. + $version = join ' ', $version, "(tainted)";
  28151. + }
  28152. + else {
  28153. + $version = join ' ', $version, "(clean)";
  28154. + }
  28155. + }
  28156. + }
  28157. +}
  28158. +
  28159. +my $hostname = `hostname`;
  28160. +$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  28161. +$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  28162. +
  28163. +
  28164. +print STDERR "Version $version\n";
  28165. +print <<EOF;
  28166. +#include "${prefix}_build_info.h"
  28167. +#include <linux/broadcom/vc_debug_sym.h>
  28168. +
  28169. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
  28170. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
  28171. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
  28172. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
  28173. +
  28174. +const char *vchiq_get_build_hostname( void )
  28175. +{
  28176. + return vchiq_build_hostname;
  28177. +}
  28178. +
  28179. +const char *vchiq_get_build_version( void )
  28180. +{
  28181. + return vchiq_build_version;
  28182. +}
  28183. +
  28184. +const char *vchiq_get_build_date( void )
  28185. +{
  28186. + return vchiq_build_date;
  28187. +}
  28188. +
  28189. +const char *vchiq_get_build_time( void )
  28190. +{
  28191. + return vchiq_build_time;
  28192. +}
  28193. +EOF
  28194. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h
  28195. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 1970-01-01 01:00:00.000000000 +0100
  28196. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 2014-04-24 16:04:36.831095364 +0200
  28197. @@ -0,0 +1,40 @@
  28198. +/**
  28199. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28200. + *
  28201. + * Redistribution and use in source and binary forms, with or without
  28202. + * modification, are permitted provided that the following conditions
  28203. + * are met:
  28204. + * 1. Redistributions of source code must retain the above copyright
  28205. + * notice, this list of conditions, and the following disclaimer,
  28206. + * without modification.
  28207. + * 2. Redistributions in binary form must reproduce the above copyright
  28208. + * notice, this list of conditions and the following disclaimer in the
  28209. + * documentation and/or other materials provided with the distribution.
  28210. + * 3. The names of the above-listed copyright holders may not be used
  28211. + * to endorse or promote products derived from this software without
  28212. + * specific prior written permission.
  28213. + *
  28214. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28215. + * GNU General Public License ("GPL") version 2, as published by the Free
  28216. + * Software Foundation.
  28217. + *
  28218. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28219. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28220. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28221. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28222. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28223. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28224. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28225. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28226. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28227. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28228. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28229. + */
  28230. +
  28231. +#ifndef VCHIQ_VCHIQ_H
  28232. +#define VCHIQ_VCHIQ_H
  28233. +
  28234. +#include "vchiq_if.h"
  28235. +#include "vchiq_util.h"
  28236. +
  28237. +#endif
  28238. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h
  28239. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 1970-01-01 01:00:00.000000000 +0100
  28240. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 2014-04-24 15:35:02.893551516 +0200
  28241. @@ -0,0 +1,188 @@
  28242. +/**
  28243. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28244. + *
  28245. + * Redistribution and use in source and binary forms, with or without
  28246. + * modification, are permitted provided that the following conditions
  28247. + * are met:
  28248. + * 1. Redistributions of source code must retain the above copyright
  28249. + * notice, this list of conditions, and the following disclaimer,
  28250. + * without modification.
  28251. + * 2. Redistributions in binary form must reproduce the above copyright
  28252. + * notice, this list of conditions and the following disclaimer in the
  28253. + * documentation and/or other materials provided with the distribution.
  28254. + * 3. The names of the above-listed copyright holders may not be used
  28255. + * to endorse or promote products derived from this software without
  28256. + * specific prior written permission.
  28257. + *
  28258. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28259. + * GNU General Public License ("GPL") version 2, as published by the Free
  28260. + * Software Foundation.
  28261. + *
  28262. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28263. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28264. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28265. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28266. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28267. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28268. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28269. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28270. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28271. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28272. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28273. + */
  28274. +
  28275. +#ifndef VCHIQ_IF_H
  28276. +#define VCHIQ_IF_H
  28277. +
  28278. +#include "interface/vchi/vchi_mh.h"
  28279. +
  28280. +#define VCHIQ_SERVICE_HANDLE_INVALID 0
  28281. +
  28282. +#define VCHIQ_SLOT_SIZE 4096
  28283. +#define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
  28284. +#define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
  28285. +
  28286. +#define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
  28287. + (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
  28288. +#define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
  28289. +#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service)
  28290. +
  28291. +typedef enum {
  28292. + VCHIQ_SERVICE_OPENED, /* service, -, - */
  28293. + VCHIQ_SERVICE_CLOSED, /* service, -, - */
  28294. + VCHIQ_MESSAGE_AVAILABLE, /* service, header, - */
  28295. + VCHIQ_BULK_TRANSMIT_DONE, /* service, -, bulk_userdata */
  28296. + VCHIQ_BULK_RECEIVE_DONE, /* service, -, bulk_userdata */
  28297. + VCHIQ_BULK_TRANSMIT_ABORTED, /* service, -, bulk_userdata */
  28298. + VCHIQ_BULK_RECEIVE_ABORTED /* service, -, bulk_userdata */
  28299. +} VCHIQ_REASON_T;
  28300. +
  28301. +typedef enum {
  28302. + VCHIQ_ERROR = -1,
  28303. + VCHIQ_SUCCESS = 0,
  28304. + VCHIQ_RETRY = 1
  28305. +} VCHIQ_STATUS_T;
  28306. +
  28307. +typedef enum {
  28308. + VCHIQ_BULK_MODE_CALLBACK,
  28309. + VCHIQ_BULK_MODE_BLOCKING,
  28310. + VCHIQ_BULK_MODE_NOCALLBACK,
  28311. + VCHIQ_BULK_MODE_WAITING /* Reserved for internal use */
  28312. +} VCHIQ_BULK_MODE_T;
  28313. +
  28314. +typedef enum {
  28315. + VCHIQ_SERVICE_OPTION_AUTOCLOSE,
  28316. + VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
  28317. + VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
  28318. + VCHIQ_SERVICE_OPTION_SYNCHRONOUS
  28319. +} VCHIQ_SERVICE_OPTION_T;
  28320. +
  28321. +typedef struct vchiq_header_struct {
  28322. + /* The message identifier - opaque to applications. */
  28323. + int msgid;
  28324. +
  28325. + /* Size of message data. */
  28326. + unsigned int size;
  28327. +
  28328. + char data[0]; /* message */
  28329. +} VCHIQ_HEADER_T;
  28330. +
  28331. +typedef struct {
  28332. + const void *data;
  28333. + unsigned int size;
  28334. +} VCHIQ_ELEMENT_T;
  28335. +
  28336. +typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
  28337. +
  28338. +typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
  28339. + VCHIQ_SERVICE_HANDLE_T, void *);
  28340. +
  28341. +typedef struct vchiq_service_base_struct {
  28342. + int fourcc;
  28343. + VCHIQ_CALLBACK_T callback;
  28344. + void *userdata;
  28345. +} VCHIQ_SERVICE_BASE_T;
  28346. +
  28347. +typedef struct vchiq_service_params_struct {
  28348. + int fourcc;
  28349. + VCHIQ_CALLBACK_T callback;
  28350. + void *userdata;
  28351. + short version; /* Increment for non-trivial changes */
  28352. + short version_min; /* Update for incompatible changes */
  28353. +} VCHIQ_SERVICE_PARAMS_T;
  28354. +
  28355. +typedef struct vchiq_config_struct {
  28356. + unsigned int max_msg_size;
  28357. + unsigned int bulk_threshold; /* The message size above which it
  28358. + is better to use a bulk transfer
  28359. + (<= max_msg_size) */
  28360. + unsigned int max_outstanding_bulks;
  28361. + unsigned int max_services;
  28362. + short version; /* The version of VCHIQ */
  28363. + short version_min; /* The minimum compatible version of VCHIQ */
  28364. +} VCHIQ_CONFIG_T;
  28365. +
  28366. +typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
  28367. +typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
  28368. +
  28369. +extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
  28370. +extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
  28371. +extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
  28372. +extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
  28373. + const VCHIQ_SERVICE_PARAMS_T *params,
  28374. + VCHIQ_SERVICE_HANDLE_T *pservice);
  28375. +extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
  28376. + const VCHIQ_SERVICE_PARAMS_T *params,
  28377. + VCHIQ_SERVICE_HANDLE_T *pservice);
  28378. +extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
  28379. +extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
  28380. +extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
  28381. +extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
  28382. + VCHIQ_SERVICE_HANDLE_T service);
  28383. +extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
  28384. +
  28385. +extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
  28386. + const VCHIQ_ELEMENT_T *elements, unsigned int count);
  28387. +extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
  28388. + VCHIQ_HEADER_T *header);
  28389. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  28390. + const void *data, unsigned int size, void *userdata);
  28391. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  28392. + void *data, unsigned int size, void *userdata);
  28393. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
  28394. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  28395. + const void *offset, unsigned int size, void *userdata);
  28396. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
  28397. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  28398. + void *offset, unsigned int size, void *userdata);
  28399. +extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  28400. + const void *data, unsigned int size, void *userdata,
  28401. + VCHIQ_BULK_MODE_T mode);
  28402. +extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  28403. + void *data, unsigned int size, void *userdata,
  28404. + VCHIQ_BULK_MODE_T mode);
  28405. +extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
  28406. + VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
  28407. + void *userdata, VCHIQ_BULK_MODE_T mode);
  28408. +extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
  28409. + VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
  28410. + void *userdata, VCHIQ_BULK_MODE_T mode);
  28411. +extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
  28412. +extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
  28413. +extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
  28414. +extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
  28415. + int config_size, VCHIQ_CONFIG_T *pconfig);
  28416. +extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
  28417. + VCHIQ_SERVICE_OPTION_T option, int value);
  28418. +
  28419. +extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
  28420. + VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
  28421. +extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
  28422. +
  28423. +extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
  28424. + void *ptr, size_t num_bytes);
  28425. +
  28426. +extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
  28427. + short *peer_version);
  28428. +
  28429. +#endif /* VCHIQ_IF_H */
  28430. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
  28431. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  28432. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 2014-04-24 15:35:02.893551516 +0200
  28433. @@ -0,0 +1,129 @@
  28434. +/**
  28435. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28436. + *
  28437. + * Redistribution and use in source and binary forms, with or without
  28438. + * modification, are permitted provided that the following conditions
  28439. + * are met:
  28440. + * 1. Redistributions of source code must retain the above copyright
  28441. + * notice, this list of conditions, and the following disclaimer,
  28442. + * without modification.
  28443. + * 2. Redistributions in binary form must reproduce the above copyright
  28444. + * notice, this list of conditions and the following disclaimer in the
  28445. + * documentation and/or other materials provided with the distribution.
  28446. + * 3. The names of the above-listed copyright holders may not be used
  28447. + * to endorse or promote products derived from this software without
  28448. + * specific prior written permission.
  28449. + *
  28450. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28451. + * GNU General Public License ("GPL") version 2, as published by the Free
  28452. + * Software Foundation.
  28453. + *
  28454. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28455. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28456. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28457. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28458. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28459. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28460. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28461. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28462. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28463. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28464. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28465. + */
  28466. +
  28467. +#ifndef VCHIQ_IOCTLS_H
  28468. +#define VCHIQ_IOCTLS_H
  28469. +
  28470. +#include <linux/ioctl.h>
  28471. +#include "vchiq_if.h"
  28472. +
  28473. +#define VCHIQ_IOC_MAGIC 0xc4
  28474. +#define VCHIQ_INVALID_HANDLE (~0)
  28475. +
  28476. +typedef struct {
  28477. + VCHIQ_SERVICE_PARAMS_T params;
  28478. + int is_open;
  28479. + int is_vchi;
  28480. + unsigned int handle; /* OUT */
  28481. +} VCHIQ_CREATE_SERVICE_T;
  28482. +
  28483. +typedef struct {
  28484. + unsigned int handle;
  28485. + unsigned int count;
  28486. + const VCHIQ_ELEMENT_T *elements;
  28487. +} VCHIQ_QUEUE_MESSAGE_T;
  28488. +
  28489. +typedef struct {
  28490. + unsigned int handle;
  28491. + void *data;
  28492. + unsigned int size;
  28493. + void *userdata;
  28494. + VCHIQ_BULK_MODE_T mode;
  28495. +} VCHIQ_QUEUE_BULK_TRANSFER_T;
  28496. +
  28497. +typedef struct {
  28498. + VCHIQ_REASON_T reason;
  28499. + VCHIQ_HEADER_T *header;
  28500. + void *service_userdata;
  28501. + void *bulk_userdata;
  28502. +} VCHIQ_COMPLETION_DATA_T;
  28503. +
  28504. +typedef struct {
  28505. + unsigned int count;
  28506. + VCHIQ_COMPLETION_DATA_T *buf;
  28507. + unsigned int msgbufsize;
  28508. + unsigned int msgbufcount; /* IN/OUT */
  28509. + void **msgbufs;
  28510. +} VCHIQ_AWAIT_COMPLETION_T;
  28511. +
  28512. +typedef struct {
  28513. + unsigned int handle;
  28514. + int blocking;
  28515. + unsigned int bufsize;
  28516. + void *buf;
  28517. +} VCHIQ_DEQUEUE_MESSAGE_T;
  28518. +
  28519. +typedef struct {
  28520. + unsigned int config_size;
  28521. + VCHIQ_CONFIG_T *pconfig;
  28522. +} VCHIQ_GET_CONFIG_T;
  28523. +
  28524. +typedef struct {
  28525. + unsigned int handle;
  28526. + VCHIQ_SERVICE_OPTION_T option;
  28527. + int value;
  28528. +} VCHIQ_SET_SERVICE_OPTION_T;
  28529. +
  28530. +typedef struct {
  28531. + void *virt_addr;
  28532. + size_t num_bytes;
  28533. +} VCHIQ_DUMP_MEM_T;
  28534. +
  28535. +#define VCHIQ_IOC_CONNECT _IO(VCHIQ_IOC_MAGIC, 0)
  28536. +#define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC, 1)
  28537. +#define VCHIQ_IOC_CREATE_SERVICE \
  28538. + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
  28539. +#define VCHIQ_IOC_REMOVE_SERVICE _IO(VCHIQ_IOC_MAGIC, 3)
  28540. +#define VCHIQ_IOC_QUEUE_MESSAGE \
  28541. + _IOW(VCHIQ_IOC_MAGIC, 4, VCHIQ_QUEUE_MESSAGE_T)
  28542. +#define VCHIQ_IOC_QUEUE_BULK_TRANSMIT \
  28543. + _IOWR(VCHIQ_IOC_MAGIC, 5, VCHIQ_QUEUE_BULK_TRANSFER_T)
  28544. +#define VCHIQ_IOC_QUEUE_BULK_RECEIVE \
  28545. + _IOWR(VCHIQ_IOC_MAGIC, 6, VCHIQ_QUEUE_BULK_TRANSFER_T)
  28546. +#define VCHIQ_IOC_AWAIT_COMPLETION \
  28547. + _IOWR(VCHIQ_IOC_MAGIC, 7, VCHIQ_AWAIT_COMPLETION_T)
  28548. +#define VCHIQ_IOC_DEQUEUE_MESSAGE \
  28549. + _IOWR(VCHIQ_IOC_MAGIC, 8, VCHIQ_DEQUEUE_MESSAGE_T)
  28550. +#define VCHIQ_IOC_GET_CLIENT_ID _IO(VCHIQ_IOC_MAGIC, 9)
  28551. +#define VCHIQ_IOC_GET_CONFIG \
  28552. + _IOWR(VCHIQ_IOC_MAGIC, 10, VCHIQ_GET_CONFIG_T)
  28553. +#define VCHIQ_IOC_CLOSE_SERVICE _IO(VCHIQ_IOC_MAGIC, 11)
  28554. +#define VCHIQ_IOC_USE_SERVICE _IO(VCHIQ_IOC_MAGIC, 12)
  28555. +#define VCHIQ_IOC_RELEASE_SERVICE _IO(VCHIQ_IOC_MAGIC, 13)
  28556. +#define VCHIQ_IOC_SET_SERVICE_OPTION \
  28557. + _IOW(VCHIQ_IOC_MAGIC, 14, VCHIQ_SET_SERVICE_OPTION_T)
  28558. +#define VCHIQ_IOC_DUMP_PHYS_MEM \
  28559. + _IOW(VCHIQ_IOC_MAGIC, 15, VCHIQ_DUMP_MEM_T)
  28560. +#define VCHIQ_IOC_MAX 15
  28561. +
  28562. +#endif
  28563. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
  28564. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 1970-01-01 01:00:00.000000000 +0100
  28565. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 2014-04-24 15:35:02.893551516 +0200
  28566. @@ -0,0 +1,456 @@
  28567. +/**
  28568. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28569. + *
  28570. + * Redistribution and use in source and binary forms, with or without
  28571. + * modification, are permitted provided that the following conditions
  28572. + * are met:
  28573. + * 1. Redistributions of source code must retain the above copyright
  28574. + * notice, this list of conditions, and the following disclaimer,
  28575. + * without modification.
  28576. + * 2. Redistributions in binary form must reproduce the above copyright
  28577. + * notice, this list of conditions and the following disclaimer in the
  28578. + * documentation and/or other materials provided with the distribution.
  28579. + * 3. The names of the above-listed copyright holders may not be used
  28580. + * to endorse or promote products derived from this software without
  28581. + * specific prior written permission.
  28582. + *
  28583. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28584. + * GNU General Public License ("GPL") version 2, as published by the Free
  28585. + * Software Foundation.
  28586. + *
  28587. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28588. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28589. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28590. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28591. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28592. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28593. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28594. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28595. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28596. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28597. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28598. + */
  28599. +
  28600. +/* ---- Include Files ---------------------------------------------------- */
  28601. +
  28602. +#include <linux/kernel.h>
  28603. +#include <linux/module.h>
  28604. +#include <linux/mutex.h>
  28605. +
  28606. +#include "vchiq_core.h"
  28607. +#include "vchiq_arm.h"
  28608. +
  28609. +/* ---- Public Variables ------------------------------------------------- */
  28610. +
  28611. +/* ---- Private Constants and Types -------------------------------------- */
  28612. +
  28613. +struct bulk_waiter_node {
  28614. + struct bulk_waiter bulk_waiter;
  28615. + int pid;
  28616. + struct list_head list;
  28617. +};
  28618. +
  28619. +struct vchiq_instance_struct {
  28620. + VCHIQ_STATE_T *state;
  28621. +
  28622. + int connected;
  28623. +
  28624. + struct list_head bulk_waiter_list;
  28625. + struct mutex bulk_waiter_list_mutex;
  28626. +};
  28627. +
  28628. +static VCHIQ_STATUS_T
  28629. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28630. + unsigned int size, VCHIQ_BULK_DIR_T dir);
  28631. +
  28632. +/****************************************************************************
  28633. +*
  28634. +* vchiq_initialise
  28635. +*
  28636. +***************************************************************************/
  28637. +#define VCHIQ_INIT_RETRIES 10
  28638. +VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instanceOut)
  28639. +{
  28640. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  28641. + VCHIQ_STATE_T *state;
  28642. + VCHIQ_INSTANCE_T instance = NULL;
  28643. + int i;
  28644. +
  28645. + vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
  28646. +
  28647. + /* VideoCore may not be ready due to boot up timing.
  28648. + It may never be ready if kernel and firmware are mismatched, so don't block forever. */
  28649. + for (i=0; i<VCHIQ_INIT_RETRIES; i++) {
  28650. + state = vchiq_get_state();
  28651. + if (state)
  28652. + break;
  28653. + udelay(500);
  28654. + }
  28655. + if (i==VCHIQ_INIT_RETRIES) {
  28656. + vchiq_log_error(vchiq_core_log_level,
  28657. + "%s: videocore not initialized\n", __func__);
  28658. + goto failed;
  28659. + } else if (i>0) {
  28660. + vchiq_log_warning(vchiq_core_log_level,
  28661. + "%s: videocore initialized after %d retries\n", __func__, i);
  28662. + }
  28663. +
  28664. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  28665. + if (!instance) {
  28666. + vchiq_log_error(vchiq_core_log_level,
  28667. + "%s: error allocating vchiq instance\n", __func__);
  28668. + goto failed;
  28669. + }
  28670. +
  28671. + instance->connected = 0;
  28672. + instance->state = state;
  28673. + mutex_init(&instance->bulk_waiter_list_mutex);
  28674. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  28675. +
  28676. + *instanceOut = instance;
  28677. +
  28678. + status = VCHIQ_SUCCESS;
  28679. +
  28680. +failed:
  28681. + vchiq_log_trace(vchiq_core_log_level,
  28682. + "%s(%p): returning %d", __func__, instance, status);
  28683. +
  28684. + return status;
  28685. +}
  28686. +EXPORT_SYMBOL(vchiq_initialise);
  28687. +
  28688. +/****************************************************************************
  28689. +*
  28690. +* vchiq_shutdown
  28691. +*
  28692. +***************************************************************************/
  28693. +
  28694. +VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
  28695. +{
  28696. + VCHIQ_STATUS_T status;
  28697. + VCHIQ_STATE_T *state = instance->state;
  28698. +
  28699. + vchiq_log_trace(vchiq_core_log_level,
  28700. + "%s(%p) called", __func__, instance);
  28701. +
  28702. + if (mutex_lock_interruptible(&state->mutex) != 0)
  28703. + return VCHIQ_RETRY;
  28704. +
  28705. + /* Remove all services */
  28706. + status = vchiq_shutdown_internal(state, instance);
  28707. +
  28708. + mutex_unlock(&state->mutex);
  28709. +
  28710. + vchiq_log_trace(vchiq_core_log_level,
  28711. + "%s(%p): returning %d", __func__, instance, status);
  28712. +
  28713. + if (status == VCHIQ_SUCCESS) {
  28714. + struct list_head *pos, *next;
  28715. + list_for_each_safe(pos, next,
  28716. + &instance->bulk_waiter_list) {
  28717. + struct bulk_waiter_node *waiter;
  28718. + waiter = list_entry(pos,
  28719. + struct bulk_waiter_node,
  28720. + list);
  28721. + list_del(pos);
  28722. + vchiq_log_info(vchiq_arm_log_level,
  28723. + "bulk_waiter - cleaned up %x "
  28724. + "for pid %d",
  28725. + (unsigned int)waiter, waiter->pid);
  28726. + kfree(waiter);
  28727. + }
  28728. + kfree(instance);
  28729. + }
  28730. +
  28731. + return status;
  28732. +}
  28733. +EXPORT_SYMBOL(vchiq_shutdown);
  28734. +
  28735. +/****************************************************************************
  28736. +*
  28737. +* vchiq_is_connected
  28738. +*
  28739. +***************************************************************************/
  28740. +
  28741. +int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
  28742. +{
  28743. + return instance->connected;
  28744. +}
  28745. +
  28746. +/****************************************************************************
  28747. +*
  28748. +* vchiq_connect
  28749. +*
  28750. +***************************************************************************/
  28751. +
  28752. +VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
  28753. +{
  28754. + VCHIQ_STATUS_T status;
  28755. + VCHIQ_STATE_T *state = instance->state;
  28756. +
  28757. + vchiq_log_trace(vchiq_core_log_level,
  28758. + "%s(%p) called", __func__, instance);
  28759. +
  28760. + if (mutex_lock_interruptible(&state->mutex) != 0) {
  28761. + vchiq_log_trace(vchiq_core_log_level,
  28762. + "%s: call to mutex_lock failed", __func__);
  28763. + status = VCHIQ_RETRY;
  28764. + goto failed;
  28765. + }
  28766. + status = vchiq_connect_internal(state, instance);
  28767. +
  28768. + if (status == VCHIQ_SUCCESS)
  28769. + instance->connected = 1;
  28770. +
  28771. + mutex_unlock(&state->mutex);
  28772. +
  28773. +failed:
  28774. + vchiq_log_trace(vchiq_core_log_level,
  28775. + "%s(%p): returning %d", __func__, instance, status);
  28776. +
  28777. + return status;
  28778. +}
  28779. +EXPORT_SYMBOL(vchiq_connect);
  28780. +
  28781. +/****************************************************************************
  28782. +*
  28783. +* vchiq_add_service
  28784. +*
  28785. +***************************************************************************/
  28786. +
  28787. +VCHIQ_STATUS_T vchiq_add_service(
  28788. + VCHIQ_INSTANCE_T instance,
  28789. + const VCHIQ_SERVICE_PARAMS_T *params,
  28790. + VCHIQ_SERVICE_HANDLE_T *phandle)
  28791. +{
  28792. + VCHIQ_STATUS_T status;
  28793. + VCHIQ_STATE_T *state = instance->state;
  28794. + VCHIQ_SERVICE_T *service = NULL;
  28795. + int srvstate;
  28796. +
  28797. + vchiq_log_trace(vchiq_core_log_level,
  28798. + "%s(%p) called", __func__, instance);
  28799. +
  28800. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  28801. +
  28802. + srvstate = vchiq_is_connected(instance)
  28803. + ? VCHIQ_SRVSTATE_LISTENING
  28804. + : VCHIQ_SRVSTATE_HIDDEN;
  28805. +
  28806. + service = vchiq_add_service_internal(
  28807. + state,
  28808. + params,
  28809. + srvstate,
  28810. + instance,
  28811. + NULL);
  28812. +
  28813. + if (service) {
  28814. + *phandle = service->handle;
  28815. + status = VCHIQ_SUCCESS;
  28816. + } else
  28817. + status = VCHIQ_ERROR;
  28818. +
  28819. + vchiq_log_trace(vchiq_core_log_level,
  28820. + "%s(%p): returning %d", __func__, instance, status);
  28821. +
  28822. + return status;
  28823. +}
  28824. +EXPORT_SYMBOL(vchiq_add_service);
  28825. +
  28826. +/****************************************************************************
  28827. +*
  28828. +* vchiq_open_service
  28829. +*
  28830. +***************************************************************************/
  28831. +
  28832. +VCHIQ_STATUS_T vchiq_open_service(
  28833. + VCHIQ_INSTANCE_T instance,
  28834. + const VCHIQ_SERVICE_PARAMS_T *params,
  28835. + VCHIQ_SERVICE_HANDLE_T *phandle)
  28836. +{
  28837. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  28838. + VCHIQ_STATE_T *state = instance->state;
  28839. + VCHIQ_SERVICE_T *service = NULL;
  28840. +
  28841. + vchiq_log_trace(vchiq_core_log_level,
  28842. + "%s(%p) called", __func__, instance);
  28843. +
  28844. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  28845. +
  28846. + if (!vchiq_is_connected(instance))
  28847. + goto failed;
  28848. +
  28849. + service = vchiq_add_service_internal(state,
  28850. + params,
  28851. + VCHIQ_SRVSTATE_OPENING,
  28852. + instance,
  28853. + NULL);
  28854. +
  28855. + if (service) {
  28856. + status = vchiq_open_service_internal(service, current->pid);
  28857. + if (status == VCHIQ_SUCCESS)
  28858. + *phandle = service->handle;
  28859. + else
  28860. + vchiq_remove_service(service->handle);
  28861. + }
  28862. +
  28863. +failed:
  28864. + vchiq_log_trace(vchiq_core_log_level,
  28865. + "%s(%p): returning %d", __func__, instance, status);
  28866. +
  28867. + return status;
  28868. +}
  28869. +EXPORT_SYMBOL(vchiq_open_service);
  28870. +
  28871. +VCHIQ_STATUS_T
  28872. +vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle,
  28873. + const void *data, unsigned int size, void *userdata)
  28874. +{
  28875. + return vchiq_bulk_transfer(handle,
  28876. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  28877. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_TRANSMIT);
  28878. +}
  28879. +EXPORT_SYMBOL(vchiq_queue_bulk_transmit);
  28880. +
  28881. +VCHIQ_STATUS_T
  28882. +vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28883. + unsigned int size, void *userdata)
  28884. +{
  28885. + return vchiq_bulk_transfer(handle,
  28886. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  28887. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_RECEIVE);
  28888. +}
  28889. +EXPORT_SYMBOL(vchiq_queue_bulk_receive);
  28890. +
  28891. +VCHIQ_STATUS_T
  28892. +vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle, const void *data,
  28893. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  28894. +{
  28895. + VCHIQ_STATUS_T status;
  28896. +
  28897. + switch (mode) {
  28898. + case VCHIQ_BULK_MODE_NOCALLBACK:
  28899. + case VCHIQ_BULK_MODE_CALLBACK:
  28900. + status = vchiq_bulk_transfer(handle,
  28901. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  28902. + mode, VCHIQ_BULK_TRANSMIT);
  28903. + break;
  28904. + case VCHIQ_BULK_MODE_BLOCKING:
  28905. + status = vchiq_blocking_bulk_transfer(handle,
  28906. + (void *)data, size, VCHIQ_BULK_TRANSMIT);
  28907. + break;
  28908. + default:
  28909. + return VCHIQ_ERROR;
  28910. + }
  28911. +
  28912. + return status;
  28913. +}
  28914. +EXPORT_SYMBOL(vchiq_bulk_transmit);
  28915. +
  28916. +VCHIQ_STATUS_T
  28917. +vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28918. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  28919. +{
  28920. + VCHIQ_STATUS_T status;
  28921. +
  28922. + switch (mode) {
  28923. + case VCHIQ_BULK_MODE_NOCALLBACK:
  28924. + case VCHIQ_BULK_MODE_CALLBACK:
  28925. + status = vchiq_bulk_transfer(handle,
  28926. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  28927. + mode, VCHIQ_BULK_RECEIVE);
  28928. + break;
  28929. + case VCHIQ_BULK_MODE_BLOCKING:
  28930. + status = vchiq_blocking_bulk_transfer(handle,
  28931. + (void *)data, size, VCHIQ_BULK_RECEIVE);
  28932. + break;
  28933. + default:
  28934. + return VCHIQ_ERROR;
  28935. + }
  28936. +
  28937. + return status;
  28938. +}
  28939. +EXPORT_SYMBOL(vchiq_bulk_receive);
  28940. +
  28941. +static VCHIQ_STATUS_T
  28942. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28943. + unsigned int size, VCHIQ_BULK_DIR_T dir)
  28944. +{
  28945. + VCHIQ_INSTANCE_T instance;
  28946. + VCHIQ_SERVICE_T *service;
  28947. + VCHIQ_STATUS_T status;
  28948. + struct bulk_waiter_node *waiter = NULL;
  28949. + struct list_head *pos;
  28950. +
  28951. + service = find_service_by_handle(handle);
  28952. + if (!service)
  28953. + return VCHIQ_ERROR;
  28954. +
  28955. + instance = service->instance;
  28956. +
  28957. + unlock_service(service);
  28958. +
  28959. + mutex_lock(&instance->bulk_waiter_list_mutex);
  28960. + list_for_each(pos, &instance->bulk_waiter_list) {
  28961. + if (list_entry(pos, struct bulk_waiter_node,
  28962. + list)->pid == current->pid) {
  28963. + waiter = list_entry(pos,
  28964. + struct bulk_waiter_node,
  28965. + list);
  28966. + list_del(pos);
  28967. + break;
  28968. + }
  28969. + }
  28970. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  28971. +
  28972. + if (waiter) {
  28973. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  28974. + if (bulk) {
  28975. + /* This thread has an outstanding bulk transfer. */
  28976. + if ((bulk->data != data) ||
  28977. + (bulk->size != size)) {
  28978. + /* This is not a retry of the previous one.
  28979. + ** Cancel the signal when the transfer
  28980. + ** completes. */
  28981. + spin_lock(&bulk_waiter_spinlock);
  28982. + bulk->userdata = NULL;
  28983. + spin_unlock(&bulk_waiter_spinlock);
  28984. + }
  28985. + }
  28986. + }
  28987. +
  28988. + if (!waiter) {
  28989. + waiter = kzalloc(sizeof(struct bulk_waiter_node), GFP_KERNEL);
  28990. + if (!waiter) {
  28991. + vchiq_log_error(vchiq_core_log_level,
  28992. + "%s - out of memory", __func__);
  28993. + return VCHIQ_ERROR;
  28994. + }
  28995. + }
  28996. +
  28997. + status = vchiq_bulk_transfer(handle, VCHI_MEM_HANDLE_INVALID,
  28998. + data, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING,
  28999. + dir);
  29000. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  29001. + !waiter->bulk_waiter.bulk) {
  29002. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  29003. + if (bulk) {
  29004. + /* Cancel the signal when the transfer
  29005. + ** completes. */
  29006. + spin_lock(&bulk_waiter_spinlock);
  29007. + bulk->userdata = NULL;
  29008. + spin_unlock(&bulk_waiter_spinlock);
  29009. + }
  29010. + kfree(waiter);
  29011. + } else {
  29012. + waiter->pid = current->pid;
  29013. + mutex_lock(&instance->bulk_waiter_list_mutex);
  29014. + list_add(&waiter->list, &instance->bulk_waiter_list);
  29015. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  29016. + vchiq_log_info(vchiq_arm_log_level,
  29017. + "saved bulk_waiter %x for pid %d",
  29018. + (unsigned int)waiter, current->pid);
  29019. + }
  29020. +
  29021. + return status;
  29022. +}
  29023. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h
  29024. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 1970-01-01 01:00:00.000000000 +0100
  29025. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 2014-04-24 15:35:02.893551516 +0200
  29026. @@ -0,0 +1,71 @@
  29027. +/**
  29028. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29029. + *
  29030. + * Redistribution and use in source and binary forms, with or without
  29031. + * modification, are permitted provided that the following conditions
  29032. + * are met:
  29033. + * 1. Redistributions of source code must retain the above copyright
  29034. + * notice, this list of conditions, and the following disclaimer,
  29035. + * without modification.
  29036. + * 2. Redistributions in binary form must reproduce the above copyright
  29037. + * notice, this list of conditions and the following disclaimer in the
  29038. + * documentation and/or other materials provided with the distribution.
  29039. + * 3. The names of the above-listed copyright holders may not be used
  29040. + * to endorse or promote products derived from this software without
  29041. + * specific prior written permission.
  29042. + *
  29043. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29044. + * GNU General Public License ("GPL") version 2, as published by the Free
  29045. + * Software Foundation.
  29046. + *
  29047. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29048. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29049. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29050. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29051. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29052. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29053. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29054. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29055. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29056. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29057. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29058. + */
  29059. +
  29060. +#ifndef VCHIQ_MEMDRV_H
  29061. +#define VCHIQ_MEMDRV_H
  29062. +
  29063. +/* ---- Include Files ----------------------------------------------------- */
  29064. +
  29065. +#include <linux/kernel.h>
  29066. +#include "vchiq_if.h"
  29067. +
  29068. +/* ---- Constants and Types ---------------------------------------------- */
  29069. +
  29070. +typedef struct {
  29071. + void *armSharedMemVirt;
  29072. + dma_addr_t armSharedMemPhys;
  29073. + size_t armSharedMemSize;
  29074. +
  29075. + void *vcSharedMemVirt;
  29076. + dma_addr_t vcSharedMemPhys;
  29077. + size_t vcSharedMemSize;
  29078. +} VCHIQ_SHARED_MEM_INFO_T;
  29079. +
  29080. +/* ---- Variable Externs ------------------------------------------------- */
  29081. +
  29082. +/* ---- Function Prototypes ---------------------------------------------- */
  29083. +
  29084. +void vchiq_get_shared_mem_info(VCHIQ_SHARED_MEM_INFO_T *info);
  29085. +
  29086. +VCHIQ_STATUS_T vchiq_memdrv_initialise(void);
  29087. +
  29088. +VCHIQ_STATUS_T vchiq_userdrv_create_instance(
  29089. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  29090. +
  29091. +VCHIQ_STATUS_T vchiq_userdrv_suspend(
  29092. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  29093. +
  29094. +VCHIQ_STATUS_T vchiq_userdrv_resume(
  29095. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  29096. +
  29097. +#endif
  29098. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h
  29099. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 1970-01-01 01:00:00.000000000 +0100
  29100. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 2014-04-24 15:35:02.893551516 +0200
  29101. @@ -0,0 +1,58 @@
  29102. +/**
  29103. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29104. + *
  29105. + * Redistribution and use in source and binary forms, with or without
  29106. + * modification, are permitted provided that the following conditions
  29107. + * are met:
  29108. + * 1. Redistributions of source code must retain the above copyright
  29109. + * notice, this list of conditions, and the following disclaimer,
  29110. + * without modification.
  29111. + * 2. Redistributions in binary form must reproduce the above copyright
  29112. + * notice, this list of conditions and the following disclaimer in the
  29113. + * documentation and/or other materials provided with the distribution.
  29114. + * 3. The names of the above-listed copyright holders may not be used
  29115. + * to endorse or promote products derived from this software without
  29116. + * specific prior written permission.
  29117. + *
  29118. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29119. + * GNU General Public License ("GPL") version 2, as published by the Free
  29120. + * Software Foundation.
  29121. + *
  29122. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29123. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29124. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29125. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29126. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29127. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29128. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29129. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29130. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29131. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29132. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29133. + */
  29134. +
  29135. +#ifndef VCHIQ_PAGELIST_H
  29136. +#define VCHIQ_PAGELIST_H
  29137. +
  29138. +#ifndef PAGE_SIZE
  29139. +#define PAGE_SIZE 4096
  29140. +#endif
  29141. +#define CACHE_LINE_SIZE 32
  29142. +#define PAGELIST_WRITE 0
  29143. +#define PAGELIST_READ 1
  29144. +#define PAGELIST_READ_WITH_FRAGMENTS 2
  29145. +
  29146. +typedef struct pagelist_struct {
  29147. + unsigned long length;
  29148. + unsigned short type;
  29149. + unsigned short offset;
  29150. + unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of following
  29151. + pages at consecutive addresses. */
  29152. +} PAGELIST_T;
  29153. +
  29154. +typedef struct fragments_struct {
  29155. + char headbuf[CACHE_LINE_SIZE];
  29156. + char tailbuf[CACHE_LINE_SIZE];
  29157. +} FRAGMENTS_T;
  29158. +
  29159. +#endif /* VCHIQ_PAGELIST_H */
  29160. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c
  29161. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 1970-01-01 01:00:00.000000000 +0100
  29162. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 2014-04-24 16:04:36.831095364 +0200
  29163. @@ -0,0 +1,253 @@
  29164. +/**
  29165. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29166. + *
  29167. + * Redistribution and use in source and binary forms, with or without
  29168. + * modification, are permitted provided that the following conditions
  29169. + * are met:
  29170. + * 1. Redistributions of source code must retain the above copyright
  29171. + * notice, this list of conditions, and the following disclaimer,
  29172. + * without modification.
  29173. + * 2. Redistributions in binary form must reproduce the above copyright
  29174. + * notice, this list of conditions and the following disclaimer in the
  29175. + * documentation and/or other materials provided with the distribution.
  29176. + * 3. The names of the above-listed copyright holders may not be used
  29177. + * to endorse or promote products derived from this software without
  29178. + * specific prior written permission.
  29179. + *
  29180. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29181. + * GNU General Public License ("GPL") version 2, as published by the Free
  29182. + * Software Foundation.
  29183. + *
  29184. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29185. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29186. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29187. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29188. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29189. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29190. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29191. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29192. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29193. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29194. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29195. + */
  29196. +
  29197. +
  29198. +#include <linux/proc_fs.h>
  29199. +#include "vchiq_core.h"
  29200. +#include "vchiq_arm.h"
  29201. +
  29202. +#if 1
  29203. +
  29204. +int vchiq_proc_init(void)
  29205. +{
  29206. + return 0;
  29207. +}
  29208. +
  29209. +void vchiq_proc_deinit(void)
  29210. +{
  29211. +}
  29212. +
  29213. +#else
  29214. +
  29215. +struct vchiq_proc_info {
  29216. + /* Global 'vc' proc entry used by all instances */
  29217. + struct proc_dir_entry *vc_cfg_dir;
  29218. +
  29219. + /* one entry per client process */
  29220. + struct proc_dir_entry *clients;
  29221. +
  29222. + /* log categories */
  29223. + struct proc_dir_entry *log_categories;
  29224. +};
  29225. +
  29226. +static struct vchiq_proc_info proc_info;
  29227. +
  29228. +struct proc_dir_entry *vchiq_proc_top(void)
  29229. +{
  29230. + BUG_ON(proc_info.vc_cfg_dir == NULL);
  29231. + return proc_info.vc_cfg_dir;
  29232. +}
  29233. +
  29234. +/****************************************************************************
  29235. +*
  29236. +* log category entries
  29237. +*
  29238. +***************************************************************************/
  29239. +#define PROC_WRITE_BUF_SIZE 256
  29240. +
  29241. +#define VCHIQ_LOG_ERROR_STR "error"
  29242. +#define VCHIQ_LOG_WARNING_STR "warning"
  29243. +#define VCHIQ_LOG_INFO_STR "info"
  29244. +#define VCHIQ_LOG_TRACE_STR "trace"
  29245. +
  29246. +static int log_cfg_read(char *buffer,
  29247. + char **start,
  29248. + off_t off,
  29249. + int count,
  29250. + int *eof,
  29251. + void *data)
  29252. +{
  29253. + int len = 0;
  29254. + char *log_value = NULL;
  29255. +
  29256. + switch (*((int *)data)) {
  29257. + case VCHIQ_LOG_ERROR:
  29258. + log_value = VCHIQ_LOG_ERROR_STR;
  29259. + break;
  29260. + case VCHIQ_LOG_WARNING:
  29261. + log_value = VCHIQ_LOG_WARNING_STR;
  29262. + break;
  29263. + case VCHIQ_LOG_INFO:
  29264. + log_value = VCHIQ_LOG_INFO_STR;
  29265. + break;
  29266. + case VCHIQ_LOG_TRACE:
  29267. + log_value = VCHIQ_LOG_TRACE_STR;
  29268. + break;
  29269. + default:
  29270. + break;
  29271. + }
  29272. +
  29273. + len += sprintf(buffer + len,
  29274. + "%s\n",
  29275. + log_value ? log_value : "(null)");
  29276. +
  29277. + return len;
  29278. +}
  29279. +
  29280. +
  29281. +static int log_cfg_write(struct file *file,
  29282. + const char __user *buffer,
  29283. + unsigned long count,
  29284. + void *data)
  29285. +{
  29286. + int *log_module = data;
  29287. + char kbuf[PROC_WRITE_BUF_SIZE + 1];
  29288. +
  29289. + (void)file;
  29290. +
  29291. + memset(kbuf, 0, PROC_WRITE_BUF_SIZE + 1);
  29292. + if (count >= PROC_WRITE_BUF_SIZE)
  29293. + count = PROC_WRITE_BUF_SIZE;
  29294. +
  29295. + if (copy_from_user(kbuf,
  29296. + buffer,
  29297. + count) != 0)
  29298. + return -EFAULT;
  29299. + kbuf[count - 1] = 0;
  29300. +
  29301. + if (strncmp("error", kbuf, strlen("error")) == 0)
  29302. + *log_module = VCHIQ_LOG_ERROR;
  29303. + else if (strncmp("warning", kbuf, strlen("warning")) == 0)
  29304. + *log_module = VCHIQ_LOG_WARNING;
  29305. + else if (strncmp("info", kbuf, strlen("info")) == 0)
  29306. + *log_module = VCHIQ_LOG_INFO;
  29307. + else if (strncmp("trace", kbuf, strlen("trace")) == 0)
  29308. + *log_module = VCHIQ_LOG_TRACE;
  29309. + else
  29310. + *log_module = VCHIQ_LOG_DEFAULT;
  29311. +
  29312. + return count;
  29313. +}
  29314. +
  29315. +/* Log category proc entries */
  29316. +struct vchiq_proc_log_entry {
  29317. + const char *name;
  29318. + int *plevel;
  29319. + struct proc_dir_entry *dir;
  29320. +};
  29321. +
  29322. +static struct vchiq_proc_log_entry vchiq_proc_log_entries[] = {
  29323. + { "core", &vchiq_core_log_level },
  29324. + { "msg", &vchiq_core_msg_log_level },
  29325. + { "sync", &vchiq_sync_log_level },
  29326. + { "susp", &vchiq_susp_log_level },
  29327. + { "arm", &vchiq_arm_log_level },
  29328. +};
  29329. +static int n_log_entries =
  29330. + sizeof(vchiq_proc_log_entries)/sizeof(vchiq_proc_log_entries[0]);
  29331. +
  29332. +/* create an entry under /proc/vc/log for each log category */
  29333. +static int vchiq_proc_create_log_entries(struct proc_dir_entry *top)
  29334. +{
  29335. + struct proc_dir_entry *dir;
  29336. + size_t i;
  29337. + int ret = 0;
  29338. + dir = proc_mkdir("log", proc_info.vc_cfg_dir);
  29339. + if (!dir)
  29340. + return -ENOMEM;
  29341. + proc_info.log_categories = dir;
  29342. +
  29343. + for (i = 0; i < n_log_entries; i++) {
  29344. + dir = create_proc_entry(vchiq_proc_log_entries[i].name,
  29345. + 0644,
  29346. + proc_info.log_categories);
  29347. + if (!dir) {
  29348. + ret = -ENOMEM;
  29349. + break;
  29350. + }
  29351. +
  29352. + dir->read_proc = &log_cfg_read;
  29353. + dir->write_proc = &log_cfg_write;
  29354. + dir->data = (void *)vchiq_proc_log_entries[i].plevel;
  29355. +
  29356. + vchiq_proc_log_entries[i].dir = dir;
  29357. + }
  29358. + return ret;
  29359. +}
  29360. +
  29361. +
  29362. +int vchiq_proc_init(void)
  29363. +{
  29364. + BUG_ON(proc_info.vc_cfg_dir != NULL);
  29365. +
  29366. + proc_info.vc_cfg_dir = proc_mkdir("vc", NULL);
  29367. + if (proc_info.vc_cfg_dir == NULL)
  29368. + goto fail;
  29369. +
  29370. + proc_info.clients = proc_mkdir("clients",
  29371. + proc_info.vc_cfg_dir);
  29372. + if (!proc_info.clients)
  29373. + goto fail;
  29374. +
  29375. + if (vchiq_proc_create_log_entries(proc_info.vc_cfg_dir) != 0)
  29376. + goto fail;
  29377. +
  29378. + return 0;
  29379. +
  29380. +fail:
  29381. + vchiq_proc_deinit();
  29382. + vchiq_log_error(vchiq_arm_log_level,
  29383. + "%s: failed to create proc directory",
  29384. + __func__);
  29385. +
  29386. + return -ENOMEM;
  29387. +}
  29388. +
  29389. +/* remove all the proc entries */
  29390. +void vchiq_proc_deinit(void)
  29391. +{
  29392. + /* log category entries */
  29393. + if (proc_info.log_categories) {
  29394. + size_t i;
  29395. + for (i = 0; i < n_log_entries; i++)
  29396. + if (vchiq_proc_log_entries[i].dir)
  29397. + remove_proc_entry(
  29398. + vchiq_proc_log_entries[i].name,
  29399. + proc_info.log_categories);
  29400. +
  29401. + remove_proc_entry(proc_info.log_categories->name,
  29402. + proc_info.vc_cfg_dir);
  29403. + }
  29404. + if (proc_info.clients)
  29405. + remove_proc_entry(proc_info.clients->name,
  29406. + proc_info.vc_cfg_dir);
  29407. + if (proc_info.vc_cfg_dir)
  29408. + remove_proc_entry(proc_info.vc_cfg_dir->name, NULL);
  29409. +}
  29410. +
  29411. +struct proc_dir_entry *vchiq_clients_top(void)
  29412. +{
  29413. + return proc_info.clients;
  29414. +}
  29415. +
  29416. +#endif
  29417. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c
  29418. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 1970-01-01 01:00:00.000000000 +0100
  29419. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 2014-04-24 15:35:02.893551516 +0200
  29420. @@ -0,0 +1,828 @@
  29421. +/**
  29422. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29423. + *
  29424. + * Redistribution and use in source and binary forms, with or without
  29425. + * modification, are permitted provided that the following conditions
  29426. + * are met:
  29427. + * 1. Redistributions of source code must retain the above copyright
  29428. + * notice, this list of conditions, and the following disclaimer,
  29429. + * without modification.
  29430. + * 2. Redistributions in binary form must reproduce the above copyright
  29431. + * notice, this list of conditions and the following disclaimer in the
  29432. + * documentation and/or other materials provided with the distribution.
  29433. + * 3. The names of the above-listed copyright holders may not be used
  29434. + * to endorse or promote products derived from this software without
  29435. + * specific prior written permission.
  29436. + *
  29437. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29438. + * GNU General Public License ("GPL") version 2, as published by the Free
  29439. + * Software Foundation.
  29440. + *
  29441. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29442. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29443. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29444. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29445. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29446. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29447. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29448. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29449. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29450. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29451. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29452. + */
  29453. +#include <linux/module.h>
  29454. +#include <linux/types.h>
  29455. +
  29456. +#include "interface/vchi/vchi.h"
  29457. +#include "vchiq.h"
  29458. +#include "vchiq_core.h"
  29459. +
  29460. +#include "vchiq_util.h"
  29461. +
  29462. +#include <stddef.h>
  29463. +
  29464. +#define vchiq_status_to_vchi(status) ((int32_t)status)
  29465. +
  29466. +typedef struct {
  29467. + VCHIQ_SERVICE_HANDLE_T handle;
  29468. +
  29469. + VCHIU_QUEUE_T queue;
  29470. +
  29471. + VCHI_CALLBACK_T callback;
  29472. + void *callback_param;
  29473. +} SHIM_SERVICE_T;
  29474. +
  29475. +/* ----------------------------------------------------------------------
  29476. + * return pointer to the mphi message driver function table
  29477. + * -------------------------------------------------------------------- */
  29478. +const VCHI_MESSAGE_DRIVER_T *
  29479. +vchi_mphi_message_driver_func_table(void)
  29480. +{
  29481. + return NULL;
  29482. +}
  29483. +
  29484. +/* ----------------------------------------------------------------------
  29485. + * return a pointer to the 'single' connection driver fops
  29486. + * -------------------------------------------------------------------- */
  29487. +const VCHI_CONNECTION_API_T *
  29488. +single_get_func_table(void)
  29489. +{
  29490. + return NULL;
  29491. +}
  29492. +
  29493. +VCHI_CONNECTION_T *vchi_create_connection(
  29494. + const VCHI_CONNECTION_API_T *function_table,
  29495. + const VCHI_MESSAGE_DRIVER_T *low_level)
  29496. +{
  29497. + (void)function_table;
  29498. + (void)low_level;
  29499. + return NULL;
  29500. +}
  29501. +
  29502. +/***********************************************************
  29503. + * Name: vchi_msg_peek
  29504. + *
  29505. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  29506. + * void **data,
  29507. + * uint32_t *msg_size,
  29508. +
  29509. +
  29510. + * VCHI_FLAGS_T flags
  29511. + *
  29512. + * Description: Routine to return a pointer to the current message (to allow in
  29513. + * place processing). The message can be removed using
  29514. + * vchi_msg_remove when you're finished
  29515. + *
  29516. + * Returns: int32_t - success == 0
  29517. + *
  29518. + ***********************************************************/
  29519. +int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  29520. + void **data,
  29521. + uint32_t *msg_size,
  29522. + VCHI_FLAGS_T flags)
  29523. +{
  29524. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29525. + VCHIQ_HEADER_T *header;
  29526. +
  29527. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29528. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29529. +
  29530. + if (flags == VCHI_FLAGS_NONE)
  29531. + if (vchiu_queue_is_empty(&service->queue))
  29532. + return -1;
  29533. +
  29534. + header = vchiu_queue_peek(&service->queue);
  29535. +
  29536. + *data = header->data;
  29537. + *msg_size = header->size;
  29538. +
  29539. + return 0;
  29540. +}
  29541. +EXPORT_SYMBOL(vchi_msg_peek);
  29542. +
  29543. +/***********************************************************
  29544. + * Name: vchi_msg_remove
  29545. + *
  29546. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  29547. + *
  29548. + * Description: Routine to remove a message (after it has been read with
  29549. + * vchi_msg_peek)
  29550. + *
  29551. + * Returns: int32_t - success == 0
  29552. + *
  29553. + ***********************************************************/
  29554. +int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle)
  29555. +{
  29556. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29557. + VCHIQ_HEADER_T *header;
  29558. +
  29559. + header = vchiu_queue_pop(&service->queue);
  29560. +
  29561. + vchiq_release_message(service->handle, header);
  29562. +
  29563. + return 0;
  29564. +}
  29565. +EXPORT_SYMBOL(vchi_msg_remove);
  29566. +
  29567. +/***********************************************************
  29568. + * Name: vchi_msg_queue
  29569. + *
  29570. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29571. + * const void *data,
  29572. + * uint32_t data_size,
  29573. + * VCHI_FLAGS_T flags,
  29574. + * void *msg_handle,
  29575. + *
  29576. + * Description: Thin wrapper to queue a message onto a connection
  29577. + *
  29578. + * Returns: int32_t - success == 0
  29579. + *
  29580. + ***********************************************************/
  29581. +int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
  29582. + const void *data,
  29583. + uint32_t data_size,
  29584. + VCHI_FLAGS_T flags,
  29585. + void *msg_handle)
  29586. +{
  29587. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29588. + VCHIQ_ELEMENT_T element = {data, data_size};
  29589. + VCHIQ_STATUS_T status;
  29590. +
  29591. + (void)msg_handle;
  29592. +
  29593. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  29594. +
  29595. + status = vchiq_queue_message(service->handle, &element, 1);
  29596. +
  29597. + /* vchiq_queue_message() may return VCHIQ_RETRY, so we need to
  29598. + ** implement a retry mechanism since this function is supposed
  29599. + ** to block until queued
  29600. + */
  29601. + while (status == VCHIQ_RETRY) {
  29602. + msleep(1);
  29603. + status = vchiq_queue_message(service->handle, &element, 1);
  29604. + }
  29605. +
  29606. + return vchiq_status_to_vchi(status);
  29607. +}
  29608. +EXPORT_SYMBOL(vchi_msg_queue);
  29609. +
  29610. +/***********************************************************
  29611. + * Name: vchi_bulk_queue_receive
  29612. + *
  29613. + * Arguments: VCHI_BULK_HANDLE_T handle,
  29614. + * void *data_dst,
  29615. + * const uint32_t data_size,
  29616. + * VCHI_FLAGS_T flags
  29617. + * void *bulk_handle
  29618. + *
  29619. + * Description: Routine to setup a rcv buffer
  29620. + *
  29621. + * Returns: int32_t - success == 0
  29622. + *
  29623. + ***********************************************************/
  29624. +int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  29625. + void *data_dst,
  29626. + uint32_t data_size,
  29627. + VCHI_FLAGS_T flags,
  29628. + void *bulk_handle)
  29629. +{
  29630. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29631. + VCHIQ_BULK_MODE_T mode;
  29632. + VCHIQ_STATUS_T status;
  29633. +
  29634. + switch ((int)flags) {
  29635. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  29636. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29637. + WARN_ON(!service->callback);
  29638. + mode = VCHIQ_BULK_MODE_CALLBACK;
  29639. + break;
  29640. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  29641. + mode = VCHIQ_BULK_MODE_BLOCKING;
  29642. + break;
  29643. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29644. + case VCHI_FLAGS_NONE:
  29645. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  29646. + break;
  29647. + default:
  29648. + WARN(1, "unsupported message\n");
  29649. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  29650. + }
  29651. +
  29652. + status = vchiq_bulk_receive(service->handle, data_dst, data_size,
  29653. + bulk_handle, mode);
  29654. +
  29655. + /* vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
  29656. + ** implement a retry mechanism since this function is supposed
  29657. + ** to block until queued
  29658. + */
  29659. + while (status == VCHIQ_RETRY) {
  29660. + msleep(1);
  29661. + status = vchiq_bulk_receive(service->handle, data_dst,
  29662. + data_size, bulk_handle, mode);
  29663. + }
  29664. +
  29665. + return vchiq_status_to_vchi(status);
  29666. +}
  29667. +EXPORT_SYMBOL(vchi_bulk_queue_receive);
  29668. +
  29669. +/***********************************************************
  29670. + * Name: vchi_bulk_queue_transmit
  29671. + *
  29672. + * Arguments: VCHI_BULK_HANDLE_T handle,
  29673. + * const void *data_src,
  29674. + * uint32_t data_size,
  29675. + * VCHI_FLAGS_T flags,
  29676. + * void *bulk_handle
  29677. + *
  29678. + * Description: Routine to transmit some data
  29679. + *
  29680. + * Returns: int32_t - success == 0
  29681. + *
  29682. + ***********************************************************/
  29683. +int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  29684. + const void *data_src,
  29685. + uint32_t data_size,
  29686. + VCHI_FLAGS_T flags,
  29687. + void *bulk_handle)
  29688. +{
  29689. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29690. + VCHIQ_BULK_MODE_T mode;
  29691. + VCHIQ_STATUS_T status;
  29692. +
  29693. + switch ((int)flags) {
  29694. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  29695. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29696. + WARN_ON(!service->callback);
  29697. + mode = VCHIQ_BULK_MODE_CALLBACK;
  29698. + break;
  29699. + case VCHI_FLAGS_BLOCK_UNTIL_DATA_READ:
  29700. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  29701. + mode = VCHIQ_BULK_MODE_BLOCKING;
  29702. + break;
  29703. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29704. + case VCHI_FLAGS_NONE:
  29705. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  29706. + break;
  29707. + default:
  29708. + WARN(1, "unsupported message\n");
  29709. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  29710. + }
  29711. +
  29712. + status = vchiq_bulk_transmit(service->handle, data_src, data_size,
  29713. + bulk_handle, mode);
  29714. +
  29715. + /* vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
  29716. + ** implement a retry mechanism since this function is supposed
  29717. + ** to block until queued
  29718. + */
  29719. + while (status == VCHIQ_RETRY) {
  29720. + msleep(1);
  29721. + status = vchiq_bulk_transmit(service->handle, data_src,
  29722. + data_size, bulk_handle, mode);
  29723. + }
  29724. +
  29725. + return vchiq_status_to_vchi(status);
  29726. +}
  29727. +EXPORT_SYMBOL(vchi_bulk_queue_transmit);
  29728. +
  29729. +/***********************************************************
  29730. + * Name: vchi_msg_dequeue
  29731. + *
  29732. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29733. + * void *data,
  29734. + * uint32_t max_data_size_to_read,
  29735. + * uint32_t *actual_msg_size
  29736. + * VCHI_FLAGS_T flags
  29737. + *
  29738. + * Description: Routine to dequeue a message into the supplied buffer
  29739. + *
  29740. + * Returns: int32_t - success == 0
  29741. + *
  29742. + ***********************************************************/
  29743. +int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  29744. + void *data,
  29745. + uint32_t max_data_size_to_read,
  29746. + uint32_t *actual_msg_size,
  29747. + VCHI_FLAGS_T flags)
  29748. +{
  29749. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29750. + VCHIQ_HEADER_T *header;
  29751. +
  29752. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29753. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29754. +
  29755. + if (flags == VCHI_FLAGS_NONE)
  29756. + if (vchiu_queue_is_empty(&service->queue))
  29757. + return -1;
  29758. +
  29759. + header = vchiu_queue_pop(&service->queue);
  29760. +
  29761. + memcpy(data, header->data, header->size < max_data_size_to_read ?
  29762. + header->size : max_data_size_to_read);
  29763. +
  29764. + *actual_msg_size = header->size;
  29765. +
  29766. + vchiq_release_message(service->handle, header);
  29767. +
  29768. + return 0;
  29769. +}
  29770. +EXPORT_SYMBOL(vchi_msg_dequeue);
  29771. +
  29772. +/***********************************************************
  29773. + * Name: vchi_msg_queuev
  29774. + *
  29775. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29776. + * VCHI_MSG_VECTOR_T *vector,
  29777. + * uint32_t count,
  29778. + * VCHI_FLAGS_T flags,
  29779. + * void *msg_handle
  29780. + *
  29781. + * Description: Thin wrapper to queue a message onto a connection
  29782. + *
  29783. + * Returns: int32_t - success == 0
  29784. + *
  29785. + ***********************************************************/
  29786. +
  29787. +vchiq_static_assert(sizeof(VCHI_MSG_VECTOR_T) == sizeof(VCHIQ_ELEMENT_T));
  29788. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_base) ==
  29789. + offsetof(VCHIQ_ELEMENT_T, data));
  29790. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_len) ==
  29791. + offsetof(VCHIQ_ELEMENT_T, size));
  29792. +
  29793. +int32_t vchi_msg_queuev(VCHI_SERVICE_HANDLE_T handle,
  29794. + VCHI_MSG_VECTOR_T *vector,
  29795. + uint32_t count,
  29796. + VCHI_FLAGS_T flags,
  29797. + void *msg_handle)
  29798. +{
  29799. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29800. +
  29801. + (void)msg_handle;
  29802. +
  29803. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  29804. +
  29805. + return vchiq_status_to_vchi(vchiq_queue_message(service->handle,
  29806. + (const VCHIQ_ELEMENT_T *)vector, count));
  29807. +}
  29808. +EXPORT_SYMBOL(vchi_msg_queuev);
  29809. +
  29810. +/***********************************************************
  29811. + * Name: vchi_held_msg_release
  29812. + *
  29813. + * Arguments: VCHI_HELD_MSG_T *message
  29814. + *
  29815. + * Description: Routine to release a held message (after it has been read with
  29816. + * vchi_msg_hold)
  29817. + *
  29818. + * Returns: int32_t - success == 0
  29819. + *
  29820. + ***********************************************************/
  29821. +int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message)
  29822. +{
  29823. + vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service,
  29824. + (VCHIQ_HEADER_T *)message->message);
  29825. +
  29826. + return 0;
  29827. +}
  29828. +EXPORT_SYMBOL(vchi_held_msg_release);
  29829. +
  29830. +/***********************************************************
  29831. + * Name: vchi_msg_hold
  29832. + *
  29833. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29834. + * void **data,
  29835. + * uint32_t *msg_size,
  29836. + * VCHI_FLAGS_T flags,
  29837. + * VCHI_HELD_MSG_T *message_handle
  29838. + *
  29839. + * Description: Routine to return a pointer to the current message (to allow
  29840. + * in place processing). The message is dequeued - don't forget
  29841. + * to release the message using vchi_held_msg_release when you're
  29842. + * finished.
  29843. + *
  29844. + * Returns: int32_t - success == 0
  29845. + *
  29846. + ***********************************************************/
  29847. +int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  29848. + void **data,
  29849. + uint32_t *msg_size,
  29850. + VCHI_FLAGS_T flags,
  29851. + VCHI_HELD_MSG_T *message_handle)
  29852. +{
  29853. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29854. + VCHIQ_HEADER_T *header;
  29855. +
  29856. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29857. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29858. +
  29859. + if (flags == VCHI_FLAGS_NONE)
  29860. + if (vchiu_queue_is_empty(&service->queue))
  29861. + return -1;
  29862. +
  29863. + header = vchiu_queue_pop(&service->queue);
  29864. +
  29865. + *data = header->data;
  29866. + *msg_size = header->size;
  29867. +
  29868. + message_handle->service =
  29869. + (struct opaque_vchi_service_t *)service->handle;
  29870. + message_handle->message = header;
  29871. +
  29872. + return 0;
  29873. +}
  29874. +EXPORT_SYMBOL(vchi_msg_hold);
  29875. +
  29876. +/***********************************************************
  29877. + * Name: vchi_initialise
  29878. + *
  29879. + * Arguments: VCHI_INSTANCE_T *instance_handle
  29880. + * VCHI_CONNECTION_T **connections
  29881. + * const uint32_t num_connections
  29882. + *
  29883. + * Description: Initialises the hardware but does not transmit anything
  29884. + * When run as a Host App this will be called twice hence the need
  29885. + * to malloc the state information
  29886. + *
  29887. + * Returns: 0 if successful, failure otherwise
  29888. + *
  29889. + ***********************************************************/
  29890. +
  29891. +int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle)
  29892. +{
  29893. + VCHIQ_INSTANCE_T instance;
  29894. + VCHIQ_STATUS_T status;
  29895. +
  29896. + status = vchiq_initialise(&instance);
  29897. +
  29898. + *instance_handle = (VCHI_INSTANCE_T)instance;
  29899. +
  29900. + return vchiq_status_to_vchi(status);
  29901. +}
  29902. +EXPORT_SYMBOL(vchi_initialise);
  29903. +
  29904. +/***********************************************************
  29905. + * Name: vchi_connect
  29906. + *
  29907. + * Arguments: VCHI_CONNECTION_T **connections
  29908. + * const uint32_t num_connections
  29909. + * VCHI_INSTANCE_T instance_handle)
  29910. + *
  29911. + * Description: Starts the command service on each connection,
  29912. + * causing INIT messages to be pinged back and forth
  29913. + *
  29914. + * Returns: 0 if successful, failure otherwise
  29915. + *
  29916. + ***********************************************************/
  29917. +int32_t vchi_connect(VCHI_CONNECTION_T **connections,
  29918. + const uint32_t num_connections,
  29919. + VCHI_INSTANCE_T instance_handle)
  29920. +{
  29921. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29922. +
  29923. + (void)connections;
  29924. + (void)num_connections;
  29925. +
  29926. + return vchiq_connect(instance);
  29927. +}
  29928. +EXPORT_SYMBOL(vchi_connect);
  29929. +
  29930. +
  29931. +/***********************************************************
  29932. + * Name: vchi_disconnect
  29933. + *
  29934. + * Arguments: VCHI_INSTANCE_T instance_handle
  29935. + *
  29936. + * Description: Stops the command service on each connection,
  29937. + * causing DE-INIT messages to be pinged back and forth
  29938. + *
  29939. + * Returns: 0 if successful, failure otherwise
  29940. + *
  29941. + ***********************************************************/
  29942. +int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle)
  29943. +{
  29944. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29945. + return vchiq_status_to_vchi(vchiq_shutdown(instance));
  29946. +}
  29947. +EXPORT_SYMBOL(vchi_disconnect);
  29948. +
  29949. +
  29950. +/***********************************************************
  29951. + * Name: vchi_service_open
  29952. + * Name: vchi_service_create
  29953. + *
  29954. + * Arguments: VCHI_INSTANCE_T *instance_handle
  29955. + * SERVICE_CREATION_T *setup,
  29956. + * VCHI_SERVICE_HANDLE_T *handle
  29957. + *
  29958. + * Description: Routine to open a service
  29959. + *
  29960. + * Returns: int32_t - success == 0
  29961. + *
  29962. + ***********************************************************/
  29963. +
  29964. +static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
  29965. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_HANDLE_T handle, void *bulk_user)
  29966. +{
  29967. + SHIM_SERVICE_T *service =
  29968. + (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
  29969. +
  29970. + if (!service->callback)
  29971. + goto release;
  29972. +
  29973. + switch (reason) {
  29974. + case VCHIQ_MESSAGE_AVAILABLE:
  29975. + vchiu_queue_push(&service->queue, header);
  29976. +
  29977. + service->callback(service->callback_param,
  29978. + VCHI_CALLBACK_MSG_AVAILABLE, NULL);
  29979. +
  29980. + goto done;
  29981. + break;
  29982. +
  29983. + case VCHIQ_BULK_TRANSMIT_DONE:
  29984. + service->callback(service->callback_param,
  29985. + VCHI_CALLBACK_BULK_SENT, bulk_user);
  29986. + break;
  29987. +
  29988. + case VCHIQ_BULK_RECEIVE_DONE:
  29989. + service->callback(service->callback_param,
  29990. + VCHI_CALLBACK_BULK_RECEIVED, bulk_user);
  29991. + break;
  29992. +
  29993. + case VCHIQ_SERVICE_CLOSED:
  29994. + service->callback(service->callback_param,
  29995. + VCHI_CALLBACK_SERVICE_CLOSED, NULL);
  29996. + break;
  29997. +
  29998. + case VCHIQ_SERVICE_OPENED:
  29999. + /* No equivalent VCHI reason */
  30000. + break;
  30001. +
  30002. + case VCHIQ_BULK_TRANSMIT_ABORTED:
  30003. + service->callback(service->callback_param,
  30004. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  30005. + bulk_user);
  30006. + break;
  30007. +
  30008. + case VCHIQ_BULK_RECEIVE_ABORTED:
  30009. + service->callback(service->callback_param,
  30010. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  30011. + bulk_user);
  30012. + break;
  30013. +
  30014. + default:
  30015. + WARN(1, "not supported\n");
  30016. + break;
  30017. + }
  30018. +
  30019. +release:
  30020. + vchiq_release_message(service->handle, header);
  30021. +done:
  30022. + return VCHIQ_SUCCESS;
  30023. +}
  30024. +
  30025. +static SHIM_SERVICE_T *service_alloc(VCHIQ_INSTANCE_T instance,
  30026. + SERVICE_CREATION_T *setup)
  30027. +{
  30028. + SHIM_SERVICE_T *service = kzalloc(sizeof(SHIM_SERVICE_T), GFP_KERNEL);
  30029. +
  30030. + (void)instance;
  30031. +
  30032. + if (service) {
  30033. + if (vchiu_queue_init(&service->queue, 64)) {
  30034. + service->callback = setup->callback;
  30035. + service->callback_param = setup->callback_param;
  30036. + } else {
  30037. + kfree(service);
  30038. + service = NULL;
  30039. + }
  30040. + }
  30041. +
  30042. + return service;
  30043. +}
  30044. +
  30045. +static void service_free(SHIM_SERVICE_T *service)
  30046. +{
  30047. + if (service) {
  30048. + vchiu_queue_delete(&service->queue);
  30049. + kfree(service);
  30050. + }
  30051. +}
  30052. +
  30053. +int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  30054. + SERVICE_CREATION_T *setup,
  30055. + VCHI_SERVICE_HANDLE_T *handle)
  30056. +{
  30057. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  30058. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  30059. + if (service) {
  30060. + VCHIQ_SERVICE_PARAMS_T params;
  30061. + VCHIQ_STATUS_T status;
  30062. +
  30063. + memset(&params, 0, sizeof(params));
  30064. + params.fourcc = setup->service_id;
  30065. + params.callback = shim_callback;
  30066. + params.userdata = service;
  30067. + params.version = setup->version.version;
  30068. + params.version_min = setup->version.version_min;
  30069. +
  30070. + status = vchiq_open_service(instance, &params,
  30071. + &service->handle);
  30072. + if (status != VCHIQ_SUCCESS) {
  30073. + service_free(service);
  30074. + service = NULL;
  30075. + }
  30076. + }
  30077. +
  30078. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  30079. +
  30080. + return (service != NULL) ? 0 : -1;
  30081. +}
  30082. +EXPORT_SYMBOL(vchi_service_open);
  30083. +
  30084. +int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
  30085. + SERVICE_CREATION_T *setup,
  30086. + VCHI_SERVICE_HANDLE_T *handle)
  30087. +{
  30088. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  30089. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  30090. + if (service) {
  30091. + VCHIQ_SERVICE_PARAMS_T params;
  30092. + VCHIQ_STATUS_T status;
  30093. +
  30094. + memset(&params, 0, sizeof(params));
  30095. + params.fourcc = setup->service_id;
  30096. + params.callback = shim_callback;
  30097. + params.userdata = service;
  30098. + params.version = setup->version.version;
  30099. + params.version_min = setup->version.version_min;
  30100. + status = vchiq_add_service(instance, &params, &service->handle);
  30101. +
  30102. + if (status != VCHIQ_SUCCESS) {
  30103. + service_free(service);
  30104. + service = NULL;
  30105. + }
  30106. + }
  30107. +
  30108. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  30109. +
  30110. + return (service != NULL) ? 0 : -1;
  30111. +}
  30112. +EXPORT_SYMBOL(vchi_service_create);
  30113. +
  30114. +int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
  30115. +{
  30116. + int32_t ret = -1;
  30117. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30118. + if (service) {
  30119. + VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
  30120. + if (status == VCHIQ_SUCCESS) {
  30121. + service_free(service);
  30122. + service = NULL;
  30123. + }
  30124. +
  30125. + ret = vchiq_status_to_vchi(status);
  30126. + }
  30127. + return ret;
  30128. +}
  30129. +EXPORT_SYMBOL(vchi_service_close);
  30130. +
  30131. +int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle)
  30132. +{
  30133. + int32_t ret = -1;
  30134. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30135. + if (service) {
  30136. + VCHIQ_STATUS_T status = vchiq_remove_service(service->handle);
  30137. + if (status == VCHIQ_SUCCESS) {
  30138. + service_free(service);
  30139. + service = NULL;
  30140. + }
  30141. +
  30142. + ret = vchiq_status_to_vchi(status);
  30143. + }
  30144. + return ret;
  30145. +}
  30146. +EXPORT_SYMBOL(vchi_service_destroy);
  30147. +
  30148. +int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version )
  30149. +{
  30150. + int32_t ret = -1;
  30151. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30152. + if(service)
  30153. + {
  30154. + VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version);
  30155. + ret = vchiq_status_to_vchi( status );
  30156. + }
  30157. + return ret;
  30158. +}
  30159. +EXPORT_SYMBOL(vchi_get_peer_version);
  30160. +
  30161. +/* ----------------------------------------------------------------------
  30162. + * read a uint32_t from buffer.
  30163. + * network format is defined to be little endian
  30164. + * -------------------------------------------------------------------- */
  30165. +uint32_t
  30166. +vchi_readbuf_uint32(const void *_ptr)
  30167. +{
  30168. + const unsigned char *ptr = _ptr;
  30169. + return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
  30170. +}
  30171. +
  30172. +/* ----------------------------------------------------------------------
  30173. + * write a uint32_t to buffer.
  30174. + * network format is defined to be little endian
  30175. + * -------------------------------------------------------------------- */
  30176. +void
  30177. +vchi_writebuf_uint32(void *_ptr, uint32_t value)
  30178. +{
  30179. + unsigned char *ptr = _ptr;
  30180. + ptr[0] = (unsigned char)((value >> 0) & 0xFF);
  30181. + ptr[1] = (unsigned char)((value >> 8) & 0xFF);
  30182. + ptr[2] = (unsigned char)((value >> 16) & 0xFF);
  30183. + ptr[3] = (unsigned char)((value >> 24) & 0xFF);
  30184. +}
  30185. +
  30186. +/* ----------------------------------------------------------------------
  30187. + * read a uint16_t from buffer.
  30188. + * network format is defined to be little endian
  30189. + * -------------------------------------------------------------------- */
  30190. +uint16_t
  30191. +vchi_readbuf_uint16(const void *_ptr)
  30192. +{
  30193. + const unsigned char *ptr = _ptr;
  30194. + return ptr[0] | (ptr[1] << 8);
  30195. +}
  30196. +
  30197. +/* ----------------------------------------------------------------------
  30198. + * write a uint16_t into the buffer.
  30199. + * network format is defined to be little endian
  30200. + * -------------------------------------------------------------------- */
  30201. +void
  30202. +vchi_writebuf_uint16(void *_ptr, uint16_t value)
  30203. +{
  30204. + unsigned char *ptr = _ptr;
  30205. + ptr[0] = (value >> 0) & 0xFF;
  30206. + ptr[1] = (value >> 8) & 0xFF;
  30207. +}
  30208. +
  30209. +/***********************************************************
  30210. + * Name: vchi_service_use
  30211. + *
  30212. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  30213. + *
  30214. + * Description: Routine to increment refcount on a service
  30215. + *
  30216. + * Returns: void
  30217. + *
  30218. + ***********************************************************/
  30219. +int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle)
  30220. +{
  30221. + int32_t ret = -1;
  30222. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30223. + if (service)
  30224. + ret = vchiq_status_to_vchi(vchiq_use_service(service->handle));
  30225. + return ret;
  30226. +}
  30227. +EXPORT_SYMBOL(vchi_service_use);
  30228. +
  30229. +/***********************************************************
  30230. + * Name: vchi_service_release
  30231. + *
  30232. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  30233. + *
  30234. + * Description: Routine to decrement refcount on a service
  30235. + *
  30236. + * Returns: void
  30237. + *
  30238. + ***********************************************************/
  30239. +int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle)
  30240. +{
  30241. + int32_t ret = -1;
  30242. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30243. + if (service)
  30244. + ret = vchiq_status_to_vchi(
  30245. + vchiq_release_service(service->handle));
  30246. + return ret;
  30247. +}
  30248. +EXPORT_SYMBOL(vchi_service_release);
  30249. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
  30250. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 1970-01-01 01:00:00.000000000 +0100
  30251. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 2014-04-24 15:35:02.893551516 +0200
  30252. @@ -0,0 +1,151 @@
  30253. +/**
  30254. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30255. + *
  30256. + * Redistribution and use in source and binary forms, with or without
  30257. + * modification, are permitted provided that the following conditions
  30258. + * are met:
  30259. + * 1. Redistributions of source code must retain the above copyright
  30260. + * notice, this list of conditions, and the following disclaimer,
  30261. + * without modification.
  30262. + * 2. Redistributions in binary form must reproduce the above copyright
  30263. + * notice, this list of conditions and the following disclaimer in the
  30264. + * documentation and/or other materials provided with the distribution.
  30265. + * 3. The names of the above-listed copyright holders may not be used
  30266. + * to endorse or promote products derived from this software without
  30267. + * specific prior written permission.
  30268. + *
  30269. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30270. + * GNU General Public License ("GPL") version 2, as published by the Free
  30271. + * Software Foundation.
  30272. + *
  30273. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30274. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30275. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30276. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30277. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30278. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30279. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30280. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30281. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30282. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30283. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30284. + */
  30285. +
  30286. +#include "vchiq_util.h"
  30287. +
  30288. +static inline int is_pow2(int i)
  30289. +{
  30290. + return i && !(i & (i - 1));
  30291. +}
  30292. +
  30293. +int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
  30294. +{
  30295. + WARN_ON(!is_pow2(size));
  30296. +
  30297. + queue->size = size;
  30298. + queue->read = 0;
  30299. + queue->write = 0;
  30300. +
  30301. + sema_init(&queue->pop, 0);
  30302. + sema_init(&queue->push, 0);
  30303. +
  30304. + queue->storage = kzalloc(size * sizeof(VCHIQ_HEADER_T *), GFP_KERNEL);
  30305. + if (queue->storage == NULL) {
  30306. + vchiu_queue_delete(queue);
  30307. + return 0;
  30308. + }
  30309. + return 1;
  30310. +}
  30311. +
  30312. +void vchiu_queue_delete(VCHIU_QUEUE_T *queue)
  30313. +{
  30314. + if (queue->storage != NULL)
  30315. + kfree(queue->storage);
  30316. +}
  30317. +
  30318. +int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue)
  30319. +{
  30320. + return queue->read == queue->write;
  30321. +}
  30322. +
  30323. +int vchiu_queue_is_full(VCHIU_QUEUE_T *queue)
  30324. +{
  30325. + return queue->write == queue->read + queue->size;
  30326. +}
  30327. +
  30328. +void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
  30329. +{
  30330. + while (queue->write == queue->read + queue->size) {
  30331. + if (down_interruptible(&queue->pop) != 0) {
  30332. + flush_signals(current);
  30333. + }
  30334. + }
  30335. +
  30336. + /*
  30337. + * Write to queue->storage must be visible after read from
  30338. + * queue->read
  30339. + */
  30340. + smp_mb();
  30341. +
  30342. + queue->storage[queue->write & (queue->size - 1)] = header;
  30343. +
  30344. + /*
  30345. + * Write to queue->storage must be visible before write to
  30346. + * queue->write
  30347. + */
  30348. + smp_wmb();
  30349. +
  30350. + queue->write++;
  30351. +
  30352. + up(&queue->push);
  30353. +}
  30354. +
  30355. +VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
  30356. +{
  30357. + while (queue->write == queue->read) {
  30358. + if (down_interruptible(&queue->push) != 0) {
  30359. + flush_signals(current);
  30360. + }
  30361. + }
  30362. +
  30363. + up(&queue->push); // We haven't removed anything from the queue.
  30364. +
  30365. + /*
  30366. + * Read from queue->storage must be visible after read from
  30367. + * queue->write
  30368. + */
  30369. + smp_rmb();
  30370. +
  30371. + return queue->storage[queue->read & (queue->size - 1)];
  30372. +}
  30373. +
  30374. +VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
  30375. +{
  30376. + VCHIQ_HEADER_T *header;
  30377. +
  30378. + while (queue->write == queue->read) {
  30379. + if (down_interruptible(&queue->push) != 0) {
  30380. + flush_signals(current);
  30381. + }
  30382. + }
  30383. +
  30384. + /*
  30385. + * Read from queue->storage must be visible after read from
  30386. + * queue->write
  30387. + */
  30388. + smp_rmb();
  30389. +
  30390. + header = queue->storage[queue->read & (queue->size - 1)];
  30391. +
  30392. + /*
  30393. + * Read from queue->storage must be visible before write to
  30394. + * queue->read
  30395. + */
  30396. + smp_mb();
  30397. +
  30398. + queue->read++;
  30399. +
  30400. + up(&queue->pop);
  30401. +
  30402. + return header;
  30403. +}
  30404. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h
  30405. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 1970-01-01 01:00:00.000000000 +0100
  30406. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 2014-04-24 16:04:36.831095364 +0200
  30407. @@ -0,0 +1,81 @@
  30408. +/**
  30409. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30410. + *
  30411. + * Redistribution and use in source and binary forms, with or without
  30412. + * modification, are permitted provided that the following conditions
  30413. + * are met:
  30414. + * 1. Redistributions of source code must retain the above copyright
  30415. + * notice, this list of conditions, and the following disclaimer,
  30416. + * without modification.
  30417. + * 2. Redistributions in binary form must reproduce the above copyright
  30418. + * notice, this list of conditions and the following disclaimer in the
  30419. + * documentation and/or other materials provided with the distribution.
  30420. + * 3. The names of the above-listed copyright holders may not be used
  30421. + * to endorse or promote products derived from this software without
  30422. + * specific prior written permission.
  30423. + *
  30424. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30425. + * GNU General Public License ("GPL") version 2, as published by the Free
  30426. + * Software Foundation.
  30427. + *
  30428. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30429. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30430. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30431. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30432. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30433. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30434. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30435. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30436. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30437. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30438. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30439. + */
  30440. +
  30441. +#ifndef VCHIQ_UTIL_H
  30442. +#define VCHIQ_UTIL_H
  30443. +
  30444. +#include <linux/types.h>
  30445. +#include <linux/semaphore.h>
  30446. +#include <linux/mutex.h>
  30447. +#include <linux/bitops.h>
  30448. +#include <linux/kthread.h>
  30449. +#include <linux/wait.h>
  30450. +#include <linux/vmalloc.h>
  30451. +#include <linux/jiffies.h>
  30452. +#include <linux/delay.h>
  30453. +#include <linux/string.h>
  30454. +#include <linux/types.h>
  30455. +#include <linux/interrupt.h>
  30456. +#include <linux/random.h>
  30457. +#include <linux/sched.h>
  30458. +#include <linux/ctype.h>
  30459. +#include <linux/uaccess.h>
  30460. +#include <linux/time.h> /* for time_t */
  30461. +#include <linux/slab.h>
  30462. +#include <linux/vmalloc.h>
  30463. +
  30464. +#include "vchiq_if.h"
  30465. +
  30466. +typedef struct {
  30467. + int size;
  30468. + int read;
  30469. + int write;
  30470. +
  30471. + struct semaphore pop;
  30472. + struct semaphore push;
  30473. +
  30474. + VCHIQ_HEADER_T **storage;
  30475. +} VCHIU_QUEUE_T;
  30476. +
  30477. +extern int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size);
  30478. +extern void vchiu_queue_delete(VCHIU_QUEUE_T *queue);
  30479. +
  30480. +extern int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue);
  30481. +extern int vchiu_queue_is_full(VCHIU_QUEUE_T *queue);
  30482. +
  30483. +extern void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header);
  30484. +
  30485. +extern VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue);
  30486. +extern VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue);
  30487. +
  30488. +#endif
  30489. diff -Nur linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c
  30490. --- linux-3.12.18/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 1970-01-01 01:00:00.000000000 +0100
  30491. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 2014-04-24 15:35:02.893551516 +0200
  30492. @@ -0,0 +1,59 @@
  30493. +/**
  30494. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30495. + *
  30496. + * Redistribution and use in source and binary forms, with or without
  30497. + * modification, are permitted provided that the following conditions
  30498. + * are met:
  30499. + * 1. Redistributions of source code must retain the above copyright
  30500. + * notice, this list of conditions, and the following disclaimer,
  30501. + * without modification.
  30502. + * 2. Redistributions in binary form must reproduce the above copyright
  30503. + * notice, this list of conditions and the following disclaimer in the
  30504. + * documentation and/or other materials provided with the distribution.
  30505. + * 3. The names of the above-listed copyright holders may not be used
  30506. + * to endorse or promote products derived from this software without
  30507. + * specific prior written permission.
  30508. + *
  30509. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30510. + * GNU General Public License ("GPL") version 2, as published by the Free
  30511. + * Software Foundation.
  30512. + *
  30513. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30514. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30515. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30516. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30517. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30518. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30519. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30520. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30521. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30522. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30523. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30524. + */
  30525. +#include "vchiq_build_info.h"
  30526. +#include <linux/broadcom/vc_debug_sym.h>
  30527. +
  30528. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_hostname, "dc4-arm-01" );
  30529. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_version, "9245b4c35b99b3870e1f7dc598c5692b3c66a6f0 (tainted)" );
  30530. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_time, __TIME__ );
  30531. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_date, __DATE__ );
  30532. +
  30533. +const char *vchiq_get_build_hostname( void )
  30534. +{
  30535. + return vchiq_build_hostname;
  30536. +}
  30537. +
  30538. +const char *vchiq_get_build_version( void )
  30539. +{
  30540. + return vchiq_build_version;
  30541. +}
  30542. +
  30543. +const char *vchiq_get_build_date( void )
  30544. +{
  30545. + return vchiq_build_date;
  30546. +}
  30547. +
  30548. +const char *vchiq_get_build_time( void )
  30549. +{
  30550. + return vchiq_build_time;
  30551. +}
  30552. diff -Nur linux-3.12.18/drivers/misc/vc04_services/Kconfig linux-rpi/drivers/misc/vc04_services/Kconfig
  30553. --- linux-3.12.18/drivers/misc/vc04_services/Kconfig 1970-01-01 01:00:00.000000000 +0100
  30554. +++ linux-rpi/drivers/misc/vc04_services/Kconfig 2014-04-24 16:04:36.831095364 +0200
  30555. @@ -0,0 +1,9 @@
  30556. +config BCM2708_VCHIQ
  30557. + tristate "Videocore VCHIQ"
  30558. + depends on MACH_BCM2708
  30559. + default y
  30560. + help
  30561. + Kernel to VideoCore communication interface for the
  30562. + BCM2708 family of products.
  30563. + Defaults to Y when the Broadcom Videocore services
  30564. + are included in the build, N otherwise.
  30565. diff -Nur linux-3.12.18/drivers/misc/vc04_services/Makefile linux-rpi/drivers/misc/vc04_services/Makefile
  30566. --- linux-3.12.18/drivers/misc/vc04_services/Makefile 1970-01-01 01:00:00.000000000 +0100
  30567. +++ linux-rpi/drivers/misc/vc04_services/Makefile 2014-04-24 16:04:36.831095364 +0200
  30568. @@ -0,0 +1,17 @@
  30569. +ifeq ($(CONFIG_MACH_BCM2708),y)
  30570. +
  30571. +obj-$(CONFIG_BCM2708_VCHIQ) += vchiq.o
  30572. +
  30573. +vchiq-objs := \
  30574. + interface/vchiq_arm/vchiq_core.o \
  30575. + interface/vchiq_arm/vchiq_arm.o \
  30576. + interface/vchiq_arm/vchiq_kern_lib.o \
  30577. + interface/vchiq_arm/vchiq_2835_arm.o \
  30578. + interface/vchiq_arm/vchiq_proc.o \
  30579. + interface/vchiq_arm/vchiq_shim.o \
  30580. + interface/vchiq_arm/vchiq_util.o \
  30581. + interface/vchiq_arm/vchiq_connected.o \
  30582. +
  30583. +ccflags-y += -DVCOS_VERIFY_BKPTS=1 -Idrivers/misc/vc04_services -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000
  30584. +
  30585. +endif
  30586. diff -Nur linux-3.12.18/drivers/mmc/card/block.c linux-rpi/drivers/mmc/card/block.c
  30587. --- linux-3.12.18/drivers/mmc/card/block.c 2014-04-18 11:14:28.000000000 +0200
  30588. +++ linux-rpi/drivers/mmc/card/block.c 2014-04-24 16:04:36.835095403 +0200
  30589. @@ -1361,7 +1361,7 @@
  30590. brq->data.blocks = 1;
  30591. }
  30592. - if (brq->data.blocks > 1 || do_rel_wr) {
  30593. + if (brq->data.blocks > 1 || do_rel_wr || card->host->caps2 & MMC_CAP2_FORCE_MULTIBLOCK) {
  30594. /* SPI multiblock writes terminate using a special
  30595. * token, not a STOP_TRANSMISSION request.
  30596. */
  30597. diff -Nur linux-3.12.18/drivers/mmc/core/sd.c linux-rpi/drivers/mmc/core/sd.c
  30598. --- linux-3.12.18/drivers/mmc/core/sd.c 2014-04-18 11:14:28.000000000 +0200
  30599. +++ linux-rpi/drivers/mmc/core/sd.c 2014-04-24 16:04:36.839095442 +0200
  30600. @@ -14,6 +14,8 @@
  30601. #include <linux/sizes.h>
  30602. #include <linux/slab.h>
  30603. #include <linux/stat.h>
  30604. +#include <linux/jiffies.h>
  30605. +#include <linux/nmi.h>
  30606. #include <linux/mmc/host.h>
  30607. #include <linux/mmc/card.h>
  30608. @@ -66,6 +68,15 @@
  30609. __res & __mask; \
  30610. })
  30611. +// timeout for tries
  30612. +static const unsigned long retry_timeout_ms= 10*1000;
  30613. +
  30614. +// try at least 10 times, even if timeout is reached
  30615. +static const int retry_min_tries= 10;
  30616. +
  30617. +// delay between tries
  30618. +static const unsigned long retry_delay_ms= 10;
  30619. +
  30620. /*
  30621. * Given the decoded CSD structure, decode the raw CID to our CID structure.
  30622. */
  30623. @@ -218,12 +229,63 @@
  30624. }
  30625. /*
  30626. - * Fetch and process SD Status register.
  30627. + * Fetch and process SD Configuration Register.
  30628. + */
  30629. +static int mmc_read_scr(struct mmc_card *card)
  30630. +{
  30631. + unsigned long timeout_at;
  30632. + int err, tries;
  30633. +
  30634. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  30635. + tries= 0;
  30636. +
  30637. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  30638. + {
  30639. + unsigned long delay_at;
  30640. + tries++;
  30641. +
  30642. + err = mmc_app_send_scr(card, card->raw_scr);
  30643. + if( !err )
  30644. + break; // success!!!
  30645. +
  30646. + touch_nmi_watchdog(); // we are still alive!
  30647. +
  30648. + // delay
  30649. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  30650. + while( time_before( jiffies, delay_at ) )
  30651. + {
  30652. + mdelay( 1 );
  30653. + touch_nmi_watchdog(); // we are still alive!
  30654. + }
  30655. + }
  30656. +
  30657. + if( err)
  30658. + {
  30659. + 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 );
  30660. + return err;
  30661. + }
  30662. +
  30663. + if( tries > 1 )
  30664. + {
  30665. + pr_info("%s: could read SD Configuration register (SCR) at the %dth attempt\n", mmc_hostname(card->host), tries );
  30666. + }
  30667. +
  30668. + err = mmc_decode_scr(card);
  30669. + if (err)
  30670. + return err;
  30671. +
  30672. + return err;
  30673. +}
  30674. +
  30675. +/*
  30676. + * Fetch and process SD Status Register.
  30677. */
  30678. static int mmc_read_ssr(struct mmc_card *card)
  30679. {
  30680. + unsigned long timeout_at;
  30681. unsigned int au, es, et, eo;
  30682. int err, i;
  30683. + int tries;
  30684. u32 *ssr;
  30685. if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
  30686. @@ -236,14 +298,40 @@
  30687. if (!ssr)
  30688. return -ENOMEM;
  30689. - err = mmc_app_sd_status(card, ssr);
  30690. - if (err) {
  30691. - pr_warning("%s: problem reading SD Status "
  30692. - "register.\n", mmc_hostname(card->host));
  30693. - err = 0;
  30694. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  30695. + tries= 0;
  30696. +
  30697. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  30698. + {
  30699. + unsigned long delay_at;
  30700. + tries++;
  30701. +
  30702. + err= mmc_app_sd_status(card, ssr);
  30703. + if( !err )
  30704. + break; // sucess!!!
  30705. +
  30706. + touch_nmi_watchdog(); // we are still alive!
  30707. +
  30708. + // delay
  30709. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  30710. + while( time_before( jiffies, delay_at ) )
  30711. + {
  30712. + mdelay( 1 );
  30713. + touch_nmi_watchdog(); // we are still alive!
  30714. + }
  30715. + }
  30716. +
  30717. + if( err)
  30718. + {
  30719. + 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 );
  30720. goto out;
  30721. }
  30722. + if( tries > 1 )
  30723. + {
  30724. + pr_info("%s: read SD Status register (SSR) after %d attempts\n", mmc_hostname(card->host), tries );
  30725. + }
  30726. +
  30727. for (i = 0; i < 16; i++)
  30728. ssr[i] = be32_to_cpu(ssr[i]);
  30729. @@ -823,14 +911,10 @@
  30730. if (!reinit) {
  30731. /*
  30732. - * Fetch SCR from card.
  30733. + * Fetch and decode SD Configuration register.
  30734. */
  30735. - err = mmc_app_send_scr(card, card->raw_scr);
  30736. - if (err)
  30737. - return err;
  30738. -
  30739. - err = mmc_decode_scr(card);
  30740. - if (err)
  30741. + err = mmc_read_scr(card);
  30742. + if( err )
  30743. return err;
  30744. /*
  30745. diff -Nur linux-3.12.18/drivers/mmc/host/Kconfig linux-rpi/drivers/mmc/host/Kconfig
  30746. --- linux-3.12.18/drivers/mmc/host/Kconfig 2014-04-18 11:14:28.000000000 +0200
  30747. +++ linux-rpi/drivers/mmc/host/Kconfig 2014-04-24 16:04:36.839095442 +0200
  30748. @@ -260,6 +260,27 @@
  30749. If you have a controller with this interface, say Y or M here.
  30750. +config MMC_SDHCI_BCM2708
  30751. + tristate "SDHCI support on BCM2708"
  30752. + depends on MMC_SDHCI && MACH_BCM2708
  30753. + select MMC_SDHCI_IO_ACCESSORS
  30754. + help
  30755. + This selects the Secure Digital Host Controller Interface (SDHCI)
  30756. + often referrered to as the eMMC block.
  30757. +
  30758. + If you have a controller with this interface, say Y or M here.
  30759. +
  30760. + If unsure, say N.
  30761. +
  30762. +config MMC_SDHCI_BCM2708_DMA
  30763. + bool "DMA support on BCM2708 Arasan controller"
  30764. + depends on MMC_SDHCI_BCM2708
  30765. + help
  30766. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  30767. + based chips.
  30768. +
  30769. + If unsure, say N.
  30770. +
  30771. config MMC_SDHCI_BCM2835
  30772. tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
  30773. depends on ARCH_BCM2835
  30774. diff -Nur linux-3.12.18/drivers/mmc/host/Makefile linux-rpi/drivers/mmc/host/Makefile
  30775. --- linux-3.12.18/drivers/mmc/host/Makefile 2014-04-18 11:14:28.000000000 +0200
  30776. +++ linux-rpi/drivers/mmc/host/Makefile 2014-04-24 16:04:36.839095442 +0200
  30777. @@ -15,6 +15,7 @@
  30778. obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
  30779. obj-$(CONFIG_MMC_SDHCI_SIRF) += sdhci-sirf.o
  30780. obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
  30781. +obj-$(CONFIG_MMC_SDHCI_BCM2708) += sdhci-bcm2708.o
  30782. obj-$(CONFIG_MMC_WBSD) += wbsd.o
  30783. obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
  30784. obj-$(CONFIG_MMC_OMAP) += omap.o
  30785. diff -Nur linux-3.12.18/drivers/mmc/host/sdhci-bcm2708.c linux-rpi/drivers/mmc/host/sdhci-bcm2708.c
  30786. --- linux-3.12.18/drivers/mmc/host/sdhci-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  30787. +++ linux-rpi/drivers/mmc/host/sdhci-bcm2708.c 2014-04-24 16:04:36.847095519 +0200
  30788. @@ -0,0 +1,1410 @@
  30789. +/*
  30790. + * sdhci-bcm2708.c Support for SDHCI device on BCM2708
  30791. + * Copyright (c) 2010 Broadcom
  30792. + *
  30793. + * This program is free software; you can redistribute it and/or modify
  30794. + * it under the terms of the GNU General Public License version 2 as
  30795. + * published by the Free Software Foundation.
  30796. + *
  30797. + * This program is distributed in the hope that it will be useful,
  30798. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30799. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30800. + * GNU General Public License for more details.
  30801. + *
  30802. + * You should have received a copy of the GNU General Public License
  30803. + * along with this program; if not, write to the Free Software
  30804. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30805. + */
  30806. +
  30807. +/* Supports:
  30808. + * SDHCI platform device - Arasan SD controller in BCM2708
  30809. + *
  30810. + * Inspired by sdhci-pci.c, by Pierre Ossman
  30811. + */
  30812. +
  30813. +#include <linux/delay.h>
  30814. +#include <linux/highmem.h>
  30815. +#include <linux/platform_device.h>
  30816. +#include <linux/module.h>
  30817. +#include <linux/mmc/mmc.h>
  30818. +#include <linux/mmc/host.h>
  30819. +#include <linux/mmc/sd.h>
  30820. +
  30821. +#include <linux/io.h>
  30822. +#include <linux/dma-mapping.h>
  30823. +#include <mach/dma.h>
  30824. +
  30825. +#include "sdhci.h"
  30826. +
  30827. +/*****************************************************************************\
  30828. + * *
  30829. + * Configuration *
  30830. + * *
  30831. +\*****************************************************************************/
  30832. +
  30833. +#define DRIVER_NAME "bcm2708_sdhci"
  30834. +
  30835. +/* for the time being insist on DMA mode - PIO seems not to work */
  30836. +#ifndef CONFIG_MMC_SDHCI_BCM2708_DMA
  30837. +#warning Non-DMA (PIO) version of this driver currently unavailable
  30838. +#endif
  30839. +#undef CONFIG_MMC_SDHCI_BCM2708_DMA
  30840. +#define CONFIG_MMC_SDHCI_BCM2708_DMA y
  30841. +
  30842. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30843. +/* #define CHECK_DMA_USE */
  30844. +#endif
  30845. +//#define LOG_REGISTERS
  30846. +
  30847. +#define USE_SCHED_TIME
  30848. +#define USE_SPACED_WRITES_2CLK 1 /* space consecutive register writes */
  30849. +#define USE_SOFTWARE_TIMEOUTS 1 /* not hardware timeouts */
  30850. +#define SOFTWARE_ERASE_TIMEOUT_SEC 30
  30851. +
  30852. +#define SDHCI_BCM_DMA_CHAN 4 /* this default is normally overriden */
  30853. +#define SDHCI_BCM_DMA_WAITS 0 /* delays slowing DMA transfers: 0-31 */
  30854. +/* We are worried that SD card DMA use may be blocking the AXI bus for others */
  30855. +
  30856. +/*! TODO: obtain these from the physical address */
  30857. +#define DMA_SDHCI_BASE 0x7e300000 /* EMMC register block on Videocore */
  30858. +#define DMA_SDHCI_BUFFER (DMA_SDHCI_BASE + SDHCI_BUFFER)
  30859. +
  30860. +#define BCM2708_SDHCI_SLEEP_TIMEOUT 1000 /* msecs */
  30861. +
  30862. +/* Mhz clock that the EMMC core is running at. Should match the platform clockman settings */
  30863. +#define BCM2708_EMMC_CLOCK_FREQ 50000000
  30864. +
  30865. +#define REG_EXRDFIFO_EN 0x80
  30866. +#define REG_EXRDFIFO_CFG 0x84
  30867. +
  30868. +int cycle_delay=2;
  30869. +
  30870. +/*****************************************************************************\
  30871. + * *
  30872. + * Debug *
  30873. + * *
  30874. +\*****************************************************************************/
  30875. +
  30876. +
  30877. +
  30878. +#define DBG(f, x...) \
  30879. + pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
  30880. +// printk(KERN_INFO DRIVER_NAME " [%s()]: " f, __func__,## x)//GRAYG
  30881. +
  30882. +
  30883. +/*****************************************************************************\
  30884. + * *
  30885. + * High Precision Time *
  30886. + * *
  30887. +\*****************************************************************************/
  30888. +
  30889. +#ifdef USE_SCHED_TIME
  30890. +
  30891. +#include <mach/frc.h>
  30892. +
  30893. +typedef unsigned long hptime_t;
  30894. +
  30895. +#define FMT_HPT "lu"
  30896. +
  30897. +static inline hptime_t hptime(void)
  30898. +{
  30899. + return frc_clock_ticks32();
  30900. +}
  30901. +
  30902. +#define HPTIME_CLK_NS 1000ul
  30903. +
  30904. +#else
  30905. +
  30906. +typedef unsigned long hptime_t;
  30907. +
  30908. +#define FMT_HPT "lu"
  30909. +
  30910. +static inline hptime_t hptime(void)
  30911. +{
  30912. + return jiffies;
  30913. +}
  30914. +
  30915. +#define HPTIME_CLK_NS (1000000000ul/HZ)
  30916. +
  30917. +#endif
  30918. +
  30919. +static inline unsigned long int since_ns(hptime_t t)
  30920. +{
  30921. + return (unsigned long)((hptime() - t) * HPTIME_CLK_NS);
  30922. +}
  30923. +
  30924. +static bool allow_highspeed = 1;
  30925. +static int emmc_clock_freq = BCM2708_EMMC_CLOCK_FREQ;
  30926. +static bool sync_after_dma = 1;
  30927. +static bool missing_status = 1;
  30928. +static bool spurious_crc_acmd51 = 0;
  30929. +bool enable_llm = 1;
  30930. +bool extra_messages = 0;
  30931. +
  30932. +#if 0
  30933. +static void hptime_test(void)
  30934. +{
  30935. + hptime_t now;
  30936. + hptime_t later;
  30937. +
  30938. + now = hptime();
  30939. + msleep(10);
  30940. + later = hptime();
  30941. +
  30942. + printk(KERN_INFO DRIVER_NAME": 10ms = %"FMT_HPT" clks "
  30943. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  30944. + later-now, now, later,
  30945. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  30946. +
  30947. + now = hptime();
  30948. + msleep(1000);
  30949. + later = hptime();
  30950. +
  30951. + printk(KERN_INFO DRIVER_NAME": 1s = %"FMT_HPT" clks "
  30952. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  30953. + later-now, now, later,
  30954. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  30955. +}
  30956. +#endif
  30957. +
  30958. +/*****************************************************************************\
  30959. + * *
  30960. + * SDHCI core callbacks *
  30961. + * *
  30962. +\*****************************************************************************/
  30963. +
  30964. +
  30965. +#ifdef CHECK_DMA_USE
  30966. +/*#define CHECK_DMA_REG_USE*/
  30967. +#endif
  30968. +
  30969. +#ifdef CHECK_DMA_REG_USE
  30970. +/* we don't expect anything to be using these registers during a
  30971. + DMA (except the IRQ status) - so check */
  30972. +static void check_dma_reg_use(struct sdhci_host *host, int reg);
  30973. +#else
  30974. +#define check_dma_reg_use(host, reg)
  30975. +#endif
  30976. +
  30977. +
  30978. +static inline u32 sdhci_bcm2708_raw_readl(struct sdhci_host *host, int reg)
  30979. +{
  30980. + return readl(host->ioaddr + reg);
  30981. +}
  30982. +
  30983. +u32 sdhci_bcm2708_readl(struct sdhci_host *host, int reg)
  30984. +{
  30985. + u32 l = sdhci_bcm2708_raw_readl(host, reg);
  30986. +
  30987. +#ifdef LOG_REGISTERS
  30988. + printk(KERN_ERR "%s: readl from 0x%02x, value 0x%08x\n",
  30989. + mmc_hostname(host->mmc), reg, l);
  30990. +#endif
  30991. + check_dma_reg_use(host, reg);
  30992. +
  30993. + return l;
  30994. +}
  30995. +
  30996. +u16 sdhci_bcm2708_readw(struct sdhci_host *host, int reg)
  30997. +{
  30998. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  30999. + u32 w = l >> (reg << 3 & 0x18) & 0xffff;
  31000. +
  31001. +#ifdef LOG_REGISTERS
  31002. + printk(KERN_ERR "%s: readw from 0x%02x, value 0x%04x\n",
  31003. + mmc_hostname(host->mmc), reg, w);
  31004. +#endif
  31005. + check_dma_reg_use(host, reg);
  31006. +
  31007. + return (u16)w;
  31008. +}
  31009. +
  31010. +u8 sdhci_bcm2708_readb(struct sdhci_host *host, int reg)
  31011. +{
  31012. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  31013. + u32 b = l >> (reg << 3 & 0x18) & 0xff;
  31014. +
  31015. +#ifdef LOG_REGISTERS
  31016. + printk(KERN_ERR "%s: readb from 0x%02x, value 0x%02x\n",
  31017. + mmc_hostname(host->mmc), reg, b);
  31018. +#endif
  31019. + check_dma_reg_use(host, reg);
  31020. +
  31021. + return (u8)b;
  31022. +}
  31023. +
  31024. +
  31025. +static void sdhci_bcm2708_raw_writel(struct sdhci_host *host, u32 val, int reg)
  31026. +{
  31027. + u32 ier;
  31028. +
  31029. +#if USE_SPACED_WRITES_2CLK
  31030. + static bool timeout_disabled = false;
  31031. + unsigned int ns_2clk = 0;
  31032. +
  31033. + /* The Arasan has a bugette whereby it may lose the content of
  31034. + * successive writes to registers that are within two SD-card clock
  31035. + * cycles of each other (a clock domain crossing problem).
  31036. + * It seems, however, that the data register does not have this problem.
  31037. + * (Which is just as well - otherwise we'd have to nobble the DMA engine
  31038. + * too)
  31039. + */
  31040. + if (reg != SDHCI_BUFFER && host->clock != 0) {
  31041. + /* host->clock is the clock freq in Hz */
  31042. + static hptime_t last_write_hpt;
  31043. + hptime_t now = hptime();
  31044. + ns_2clk = cycle_delay*1000000/(host->clock/1000);
  31045. +
  31046. + if (now == last_write_hpt || now == last_write_hpt+1) {
  31047. + /* we can't guarantee any significant time has
  31048. + * passed - we'll have to wait anyway ! */
  31049. + ndelay(ns_2clk);
  31050. + } else
  31051. + {
  31052. + /* we must have waited at least this many ns: */
  31053. + unsigned int ns_wait = HPTIME_CLK_NS *
  31054. + (now - last_write_hpt - 1);
  31055. + if (ns_wait < ns_2clk)
  31056. + ndelay(ns_2clk - ns_wait);
  31057. + }
  31058. + last_write_hpt = now;
  31059. + }
  31060. +#if USE_SOFTWARE_TIMEOUTS
  31061. + /* The Arasan is clocked for timeouts using the SD clock which is too
  31062. + * fast for ERASE commands and causes issues. So we disable timeouts
  31063. + * for ERASE */
  31064. + if (host->cmd != NULL && host->cmd->opcode == MMC_ERASE &&
  31065. + reg == (SDHCI_COMMAND & ~3)) {
  31066. + mod_timer(&host->timer,
  31067. + jiffies + SOFTWARE_ERASE_TIMEOUT_SEC * HZ);
  31068. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  31069. + ier &= ~SDHCI_INT_DATA_TIMEOUT;
  31070. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  31071. + timeout_disabled = true;
  31072. + ndelay(ns_2clk);
  31073. + } else if (timeout_disabled) {
  31074. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  31075. + ier |= SDHCI_INT_DATA_TIMEOUT;
  31076. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  31077. + timeout_disabled = false;
  31078. + ndelay(ns_2clk);
  31079. + }
  31080. +#endif
  31081. + writel(val, host->ioaddr + reg);
  31082. +#else
  31083. + void __iomem * regaddr = host->ioaddr + reg;
  31084. +
  31085. + writel(val, regaddr);
  31086. +
  31087. + if (reg != SDHCI_BUFFER && reg != SDHCI_INT_STATUS && host->clock != 0)
  31088. + {
  31089. + int timeout = 100000;
  31090. + while (val != readl(regaddr) && --timeout > 0)
  31091. + continue;
  31092. +
  31093. + if (timeout <= 0)
  31094. + printk(KERN_ERR "%s: writing 0x%X to reg 0x%X "
  31095. + "always gives 0x%X\n",
  31096. + mmc_hostname(host->mmc),
  31097. + val, reg, readl(regaddr));
  31098. + BUG_ON(timeout <= 0);
  31099. + }
  31100. +#endif
  31101. +}
  31102. +
  31103. +
  31104. +void sdhci_bcm2708_writel(struct sdhci_host *host, u32 val, int reg)
  31105. +{
  31106. +#ifdef LOG_REGISTERS
  31107. + printk(KERN_ERR "%s: writel to 0x%02x, value 0x%08x\n",
  31108. + mmc_hostname(host->mmc), reg, val);
  31109. +#endif
  31110. + check_dma_reg_use(host, reg);
  31111. +
  31112. + sdhci_bcm2708_raw_writel(host, val, reg);
  31113. +}
  31114. +
  31115. +void sdhci_bcm2708_writew(struct sdhci_host *host, u16 val, int reg)
  31116. +{
  31117. + static u32 shadow = 0;
  31118. +
  31119. + u32 p = reg == SDHCI_COMMAND ? shadow :
  31120. + sdhci_bcm2708_raw_readl(host, reg & ~3);
  31121. + u32 s = reg << 3 & 0x18;
  31122. + u32 l = val << s;
  31123. + u32 m = 0xffff << s;
  31124. +
  31125. +#ifdef LOG_REGISTERS
  31126. + printk(KERN_ERR "%s: writew to 0x%02x, value 0x%04x\n",
  31127. + mmc_hostname(host->mmc), reg, val);
  31128. +#endif
  31129. +
  31130. + if (reg == SDHCI_TRANSFER_MODE)
  31131. + shadow = (p & ~m) | l;
  31132. + else {
  31133. + check_dma_reg_use(host, reg);
  31134. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  31135. + }
  31136. +}
  31137. +
  31138. +void sdhci_bcm2708_writeb(struct sdhci_host *host, u8 val, int reg)
  31139. +{
  31140. + u32 p = sdhci_bcm2708_raw_readl(host, reg & ~3);
  31141. + u32 s = reg << 3 & 0x18;
  31142. + u32 l = val << s;
  31143. + u32 m = 0xff << s;
  31144. +
  31145. +#ifdef LOG_REGISTERS
  31146. + printk(KERN_ERR "%s: writeb to 0x%02x, value 0x%02x\n",
  31147. + mmc_hostname(host->mmc), reg, val);
  31148. +#endif
  31149. +
  31150. + check_dma_reg_use(host, reg);
  31151. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  31152. +}
  31153. +
  31154. +static unsigned int sdhci_bcm2708_get_max_clock(struct sdhci_host *host)
  31155. +{
  31156. + return emmc_clock_freq;
  31157. +}
  31158. +
  31159. +/*****************************************************************************\
  31160. + * *
  31161. + * DMA Operation *
  31162. + * *
  31163. +\*****************************************************************************/
  31164. +
  31165. +struct sdhci_bcm2708_priv {
  31166. + int dma_chan;
  31167. + int dma_irq;
  31168. + void __iomem *dma_chan_base;
  31169. + struct bcm2708_dma_cb *cb_base; /* DMA control blocks */
  31170. + dma_addr_t cb_handle;
  31171. + /* tracking scatter gather progress */
  31172. + unsigned sg_ix; /* scatter gather list index */
  31173. + unsigned sg_done; /* bytes in current sg_ix done */
  31174. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31175. + unsigned char dma_wanted; /* DMA transfer requested */
  31176. + unsigned char dma_waits; /* wait states in DMAs */
  31177. +#ifdef CHECK_DMA_USE
  31178. + unsigned char dmas_pending; /* no of unfinished DMAs */
  31179. + hptime_t when_started;
  31180. + hptime_t when_reset;
  31181. + hptime_t when_stopped;
  31182. +#endif
  31183. +#endif
  31184. + /* signalling the end of a transfer */
  31185. + void (*complete)(struct sdhci_host *);
  31186. +};
  31187. +
  31188. +#define SDHCI_HOST_PRIV(host) \
  31189. + (struct sdhci_bcm2708_priv *)((struct sdhci_host *)(host)+1)
  31190. +
  31191. +
  31192. +
  31193. +#ifdef CHECK_DMA_REG_USE
  31194. +static void check_dma_reg_use(struct sdhci_host *host, int reg)
  31195. +{
  31196. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31197. + if (host_priv->dma_wanted && reg != SDHCI_INT_STATUS) {
  31198. + printk(KERN_INFO"%s: accessing register 0x%x during DMA\n",
  31199. + mmc_hostname(host->mmc), reg);
  31200. + }
  31201. +}
  31202. +#endif
  31203. +
  31204. +
  31205. +
  31206. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31207. +
  31208. +static void sdhci_clear_set_irqgen(struct sdhci_host *host, u32 clear, u32 set)
  31209. +{
  31210. + u32 ier;
  31211. +
  31212. + ier = sdhci_bcm2708_raw_readl(host, SDHCI_SIGNAL_ENABLE);
  31213. + ier &= ~clear;
  31214. + ier |= set;
  31215. + /* change which requests generate IRQs - makes no difference to
  31216. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  31217. + sdhci_bcm2708_raw_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  31218. +}
  31219. +
  31220. +static void sdhci_signal_irqs(struct sdhci_host *host, u32 irqs)
  31221. +{
  31222. + sdhci_clear_set_irqgen(host, 0, irqs);
  31223. +}
  31224. +
  31225. +static void sdhci_unsignal_irqs(struct sdhci_host *host, u32 irqs)
  31226. +{
  31227. + sdhci_clear_set_irqgen(host, irqs, 0);
  31228. +}
  31229. +
  31230. +
  31231. +
  31232. +static void schci_bcm2708_cb_read(struct sdhci_bcm2708_priv *host,
  31233. + int ix,
  31234. + dma_addr_t dma_addr, unsigned len,
  31235. + int /*bool*/ is_last)
  31236. +{
  31237. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  31238. + unsigned char dmawaits = host->dma_waits;
  31239. +
  31240. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  31241. + BCM2708_DMA_WAITS(dmawaits) |
  31242. + BCM2708_DMA_S_DREQ |
  31243. + BCM2708_DMA_D_WIDTH |
  31244. + BCM2708_DMA_D_INC;
  31245. + cb->src = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  31246. + cb->dst = dma_addr;
  31247. + cb->length = len;
  31248. + cb->stride = 0;
  31249. +
  31250. + if (is_last) {
  31251. + cb->info |= BCM2708_DMA_INT_EN |
  31252. + BCM2708_DMA_WAIT_RESP;
  31253. + cb->next = 0;
  31254. + } else
  31255. + cb->next = host->cb_handle +
  31256. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  31257. +
  31258. + cb->pad[0] = 0;
  31259. + cb->pad[1] = 0;
  31260. +}
  31261. +
  31262. +static void schci_bcm2708_cb_write(struct sdhci_bcm2708_priv *host,
  31263. + int ix,
  31264. + dma_addr_t dma_addr, unsigned len,
  31265. + int /*bool*/ is_last)
  31266. +{
  31267. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  31268. + unsigned char dmawaits = host->dma_waits;
  31269. +
  31270. + /* We can make arbitrarily large writes as long as we specify DREQ to
  31271. + pace the delivery of bytes to the Arasan hardware */
  31272. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  31273. + BCM2708_DMA_WAITS(dmawaits) |
  31274. + BCM2708_DMA_D_DREQ |
  31275. + BCM2708_DMA_S_WIDTH |
  31276. + BCM2708_DMA_S_INC;
  31277. + cb->src = dma_addr;
  31278. + cb->dst = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  31279. + cb->length = len;
  31280. + cb->stride = 0;
  31281. +
  31282. + if (is_last) {
  31283. + cb->info |= BCM2708_DMA_INT_EN |
  31284. + BCM2708_DMA_WAIT_RESP;
  31285. + cb->next = 0;
  31286. + } else
  31287. + cb->next = host->cb_handle +
  31288. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  31289. +
  31290. + cb->pad[0] = 0;
  31291. + cb->pad[1] = 0;
  31292. +}
  31293. +
  31294. +
  31295. +static void schci_bcm2708_dma_go(struct sdhci_host *host)
  31296. +{
  31297. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31298. + void __iomem *dma_chan_base = host_priv->dma_chan_base;
  31299. +
  31300. + BUG_ON(host_priv->dma_wanted);
  31301. +#ifdef CHECK_DMA_USE
  31302. + if (host_priv->dma_wanted)
  31303. + printk(KERN_ERR "%s: DMA already in progress - "
  31304. + "now %"FMT_HPT", last started %lu "
  31305. + "reset %lu stopped %lu\n",
  31306. + mmc_hostname(host->mmc),
  31307. + hptime(), since_ns(host_priv->when_started),
  31308. + since_ns(host_priv->when_reset),
  31309. + since_ns(host_priv->when_stopped));
  31310. + else if (host_priv->dmas_pending > 0)
  31311. + printk(KERN_INFO "%s: note - new DMA when %d reset DMAs "
  31312. + "already in progress - "
  31313. + "now %"FMT_HPT", started %lu reset %lu stopped %lu\n",
  31314. + mmc_hostname(host->mmc),
  31315. + host_priv->dmas_pending,
  31316. + hptime(), since_ns(host_priv->when_started),
  31317. + since_ns(host_priv->when_reset),
  31318. + since_ns(host_priv->when_stopped));
  31319. + host_priv->dmas_pending += 1;
  31320. + host_priv->when_started = hptime();
  31321. +#endif
  31322. + host_priv->dma_wanted = 1;
  31323. + DBG("PDMA go - base %p handle %08X\n", dma_chan_base,
  31324. + host_priv->cb_handle);
  31325. + bcm_dma_start(dma_chan_base, host_priv->cb_handle);
  31326. +}
  31327. +
  31328. +
  31329. +static void
  31330. +sdhci_platdma_read(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  31331. +{
  31332. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31333. +
  31334. + DBG("PDMA to read %d bytes\n", len);
  31335. + host_priv->sg_done += len;
  31336. + schci_bcm2708_cb_read(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  31337. + schci_bcm2708_dma_go(host);
  31338. +}
  31339. +
  31340. +
  31341. +static void
  31342. +sdhci_platdma_write(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  31343. +{
  31344. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31345. +
  31346. + DBG("PDMA to write %d bytes\n", len);
  31347. + //BUG_ON(0 != (len & 0x1ff));
  31348. +
  31349. + host_priv->sg_done += len;
  31350. + schci_bcm2708_cb_write(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  31351. + schci_bcm2708_dma_go(host);
  31352. +}
  31353. +
  31354. +/*! space is avaiable to receive into or data is available to write
  31355. + Platform DMA exported function
  31356. +*/
  31357. +void
  31358. +sdhci_bcm2708_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  31359. + void(*completion_callback)(struct sdhci_host *host))
  31360. +{
  31361. + struct mmc_data *data = host->data;
  31362. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31363. + int sg_ix;
  31364. + size_t bytes;
  31365. + dma_addr_t addr;
  31366. +
  31367. + BUG_ON(NULL == data);
  31368. + BUG_ON(0 == data->blksz);
  31369. +
  31370. + host_priv->complete = completion_callback;
  31371. +
  31372. + sg_ix = host_priv->sg_ix;
  31373. + BUG_ON(sg_ix >= data->sg_len);
  31374. +
  31375. + /* we can DMA blocks larger than blksz - it may hang the DMA
  31376. + channel but we are its only user */
  31377. + bytes = sg_dma_len(&data->sg[sg_ix]) - host_priv->sg_done;
  31378. + addr = sg_dma_address(&data->sg[sg_ix]) + host_priv->sg_done;
  31379. +
  31380. + if (bytes > 0) {
  31381. + /* We're going to poll for read/write available state until
  31382. + we finish this DMA
  31383. + */
  31384. +
  31385. + if (data->flags & MMC_DATA_READ) {
  31386. + if (*ref_intmask & SDHCI_INT_DATA_AVAIL) {
  31387. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31388. + SDHCI_INT_SPACE_AVAIL);
  31389. + sdhci_platdma_read(host, addr, bytes);
  31390. + }
  31391. + } else {
  31392. + if (*ref_intmask & SDHCI_INT_SPACE_AVAIL) {
  31393. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31394. + SDHCI_INT_SPACE_AVAIL);
  31395. + sdhci_platdma_write(host, addr, bytes);
  31396. + }
  31397. + }
  31398. + }
  31399. + /* else:
  31400. + we have run out of bytes that need transferring (e.g. we may be in
  31401. + the middle of the last DMA transfer), or
  31402. + it is also possible that we've been called when another IRQ is
  31403. + signalled, even though we've turned off signalling of our own IRQ */
  31404. +
  31405. + *ref_intmask &= ~SDHCI_INT_DATA_END;
  31406. + /* don't let the main sdhci driver act on this .. we'll deal with it
  31407. + when we respond to the DMA - if one is currently in progress */
  31408. +}
  31409. +
  31410. +/* is it possible to DMA the given mmc_data structure?
  31411. + Platform DMA exported function
  31412. +*/
  31413. +int /*bool*/
  31414. +sdhci_bcm2708_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  31415. +{
  31416. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31417. + int ok = bcm_sg_suitable_for_dma(data->sg, data->sg_len);
  31418. +
  31419. + if (!ok)
  31420. + DBG("Reverting to PIO - bad cache alignment\n");
  31421. +
  31422. + else {
  31423. + host_priv->sg_ix = 0; /* first SG index */
  31424. + host_priv->sg_done = 0; /* no bytes done */
  31425. + }
  31426. +
  31427. + return ok;
  31428. +}
  31429. +
  31430. +#include <mach/arm_control.h> //GRAYG
  31431. +/*! the current SD transacton has been abandonned
  31432. + We need to tidy up if we were in the middle of a DMA
  31433. + Platform DMA exported function
  31434. +*/
  31435. +void
  31436. +sdhci_bcm2708_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  31437. +{
  31438. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31439. +// unsigned long flags;
  31440. +
  31441. + BUG_ON(NULL == host);
  31442. +
  31443. +// spin_lock_irqsave(&host->lock, flags);
  31444. +
  31445. + if (host_priv->dma_wanted) {
  31446. + if (NULL == data) {
  31447. + printk(KERN_ERR "%s: ongoing DMA reset - no data!\n",
  31448. + mmc_hostname(host->mmc));
  31449. + BUG_ON(NULL == data);
  31450. + } else {
  31451. + struct scatterlist *sg;
  31452. + int sg_len;
  31453. + int sg_todo;
  31454. + int rc;
  31455. + unsigned long cs;
  31456. +
  31457. + sg = data->sg;
  31458. + sg_len = data->sg_len;
  31459. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  31460. +
  31461. + cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  31462. +
  31463. + if (!(BCM2708_DMA_ACTIVE & cs))
  31464. + {
  31465. + if (extra_messages)
  31466. + printk(KERN_INFO "%s: missed completion of "
  31467. + "cmd %d DMA (%d/%d [%d]/[%d]) - "
  31468. + "ignoring it\n",
  31469. + mmc_hostname(host->mmc),
  31470. + host->last_cmdop,
  31471. + host_priv->sg_done, sg_todo,
  31472. + host_priv->sg_ix+1, sg_len);
  31473. + }
  31474. + else
  31475. + printk(KERN_INFO "%s: resetting ongoing cmd %d"
  31476. + "DMA before %d/%d [%d]/[%d] complete\n",
  31477. + mmc_hostname(host->mmc),
  31478. + host->last_cmdop,
  31479. + host_priv->sg_done, sg_todo,
  31480. + host_priv->sg_ix+1, sg_len);
  31481. +#ifdef CHECK_DMA_USE
  31482. + printk(KERN_INFO "%s: now %"FMT_HPT" started %lu "
  31483. + "last reset %lu last stopped %lu\n",
  31484. + mmc_hostname(host->mmc),
  31485. + hptime(), since_ns(host_priv->when_started),
  31486. + since_ns(host_priv->when_reset),
  31487. + since_ns(host_priv->when_stopped));
  31488. + { unsigned long info, debug;
  31489. + void __iomem *base;
  31490. + unsigned long pend0, pend1, pend2;
  31491. +
  31492. + base = host_priv->dma_chan_base;
  31493. + cs = readl(base + BCM2708_DMA_CS);
  31494. + info = readl(base + BCM2708_DMA_INFO);
  31495. + debug = readl(base + BCM2708_DMA_DEBUG);
  31496. + printk(KERN_INFO "%s: DMA%d CS=%08lX TI=%08lX "
  31497. + "DEBUG=%08lX\n",
  31498. + mmc_hostname(host->mmc),
  31499. + host_priv->dma_chan,
  31500. + cs, info, debug);
  31501. + pend0 = readl(__io_address(ARM_IRQ_PEND0));
  31502. + pend1 = readl(__io_address(ARM_IRQ_PEND1));
  31503. + pend2 = readl(__io_address(ARM_IRQ_PEND2));
  31504. +
  31505. + printk(KERN_INFO "%s: PEND0=%08lX "
  31506. + "PEND1=%08lX PEND2=%08lX\n",
  31507. + mmc_hostname(host->mmc),
  31508. + pend0, pend1, pend2);
  31509. +
  31510. + //gintsts = readl(__io_address(GINTSTS));
  31511. + //gintmsk = readl(__io_address(GINTMSK));
  31512. + //printk(KERN_INFO "%s: USB GINTSTS=%08lX"
  31513. + // "GINTMSK=%08lX\n",
  31514. + // mmc_hostname(host->mmc), gintsts, gintmsk);
  31515. + }
  31516. +#endif
  31517. + rc = bcm_dma_abort(host_priv->dma_chan_base);
  31518. + BUG_ON(rc != 0);
  31519. + }
  31520. + host_priv->dma_wanted = 0;
  31521. +#ifdef CHECK_DMA_USE
  31522. + host_priv->when_reset = hptime();
  31523. +#endif
  31524. + }
  31525. +
  31526. +// spin_unlock_irqrestore(&host->lock, flags);
  31527. +}
  31528. +
  31529. +
  31530. +static void sdhci_bcm2708_dma_complete_irq(struct sdhci_host *host,
  31531. + u32 dma_cs)
  31532. +{
  31533. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31534. + struct mmc_data *data;
  31535. + struct scatterlist *sg;
  31536. + int sg_len;
  31537. + int sg_ix;
  31538. + int sg_todo;
  31539. +// unsigned long flags;
  31540. +
  31541. + BUG_ON(NULL == host);
  31542. +
  31543. +// spin_lock_irqsave(&host->lock, flags);
  31544. + data = host->data;
  31545. +
  31546. +#ifdef CHECK_DMA_USE
  31547. + if (host_priv->dmas_pending <= 0)
  31548. + DBG("on completion no DMA in progress - "
  31549. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  31550. + hptime(), since_ns(host_priv->when_started),
  31551. + since_ns(host_priv->when_reset),
  31552. + since_ns(host_priv->when_stopped));
  31553. + else if (host_priv->dmas_pending > 1)
  31554. + DBG("still %d DMA in progress after completion - "
  31555. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  31556. + host_priv->dmas_pending - 1,
  31557. + hptime(), since_ns(host_priv->when_started),
  31558. + since_ns(host_priv->when_reset),
  31559. + since_ns(host_priv->when_stopped));
  31560. + BUG_ON(host_priv->dmas_pending <= 0);
  31561. + host_priv->dmas_pending -= 1;
  31562. + host_priv->when_stopped = hptime();
  31563. +#endif
  31564. + host_priv->dma_wanted = 0;
  31565. +
  31566. + if (NULL == data) {
  31567. + DBG("PDMA unused completion - status 0x%X\n", dma_cs);
  31568. +// spin_unlock_irqrestore(&host->lock, flags);
  31569. + return;
  31570. + }
  31571. + sg = data->sg;
  31572. + sg_len = data->sg_len;
  31573. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  31574. +
  31575. + DBG("PDMA complete %d/%d [%d]/[%d]..\n",
  31576. + host_priv->sg_done, sg_todo,
  31577. + host_priv->sg_ix+1, sg_len);
  31578. +
  31579. + BUG_ON(host_priv->sg_done > sg_todo);
  31580. +
  31581. + if (host_priv->sg_done >= sg_todo) {
  31582. + host_priv->sg_ix++;
  31583. + host_priv->sg_done = 0;
  31584. + }
  31585. +
  31586. + sg_ix = host_priv->sg_ix;
  31587. + if (sg_ix < sg_len) {
  31588. + u32 irq_mask;
  31589. + /* Set off next DMA if we've got the capacity */
  31590. +
  31591. + if (data->flags & MMC_DATA_READ)
  31592. + irq_mask = SDHCI_INT_DATA_AVAIL;
  31593. + else
  31594. + irq_mask = SDHCI_INT_SPACE_AVAIL;
  31595. +
  31596. + /* We have to use the interrupt status register on the BCM2708
  31597. + rather than the SDHCI_PRESENT_STATE register because latency
  31598. + in the glue logic means that the information retrieved from
  31599. + the latter is not always up-to-date w.r.t the DMA engine -
  31600. + it may not indicate that a read or a write is ready yet */
  31601. + if (sdhci_bcm2708_raw_readl(host, SDHCI_INT_STATUS) &
  31602. + irq_mask) {
  31603. + size_t bytes = sg_dma_len(&sg[sg_ix]) -
  31604. + host_priv->sg_done;
  31605. + dma_addr_t addr = sg_dma_address(&data->sg[sg_ix]) +
  31606. + host_priv->sg_done;
  31607. +
  31608. + /* acknowledge interrupt */
  31609. + sdhci_bcm2708_raw_writel(host, irq_mask,
  31610. + SDHCI_INT_STATUS);
  31611. +
  31612. + BUG_ON(0 == bytes);
  31613. +
  31614. + if (data->flags & MMC_DATA_READ)
  31615. + sdhci_platdma_read(host, addr, bytes);
  31616. + else
  31617. + sdhci_platdma_write(host, addr, bytes);
  31618. + } else {
  31619. + DBG("PDMA - wait avail\n");
  31620. + /* may generate an IRQ if already present */
  31621. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31622. + SDHCI_INT_SPACE_AVAIL);
  31623. + }
  31624. + } else {
  31625. + if (sync_after_dma) {
  31626. + /* On the Arasan controller the stop command (which will be
  31627. + scheduled after this completes) does not seem to work
  31628. + properly if we allow it to be issued when we are
  31629. + transferring data to/from the SD card.
  31630. + We get CRC and DEND errors unless we wait for
  31631. + the SD controller to finish reading/writing to the card. */
  31632. + u32 state_mask;
  31633. + int timeout=3*1000*1000;
  31634. +
  31635. + DBG("PDMA over - sync card\n");
  31636. + if (data->flags & MMC_DATA_READ)
  31637. + state_mask = SDHCI_DOING_READ;
  31638. + else
  31639. + state_mask = SDHCI_DOING_WRITE;
  31640. +
  31641. + while (0 != (sdhci_bcm2708_raw_readl(host, SDHCI_PRESENT_STATE)
  31642. + & state_mask) && --timeout > 0)
  31643. + {
  31644. + udelay(1);
  31645. + continue;
  31646. + }
  31647. + if (timeout <= 0)
  31648. + printk(KERN_ERR"%s: final %s to SD card still "
  31649. + "running\n",
  31650. + mmc_hostname(host->mmc),
  31651. + data->flags & MMC_DATA_READ? "read": "write");
  31652. + }
  31653. + if (host_priv->complete) {
  31654. + (*host_priv->complete)(host);
  31655. + DBG("PDMA %s complete\n",
  31656. + data->flags & MMC_DATA_READ?"read":"write");
  31657. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31658. + SDHCI_INT_SPACE_AVAIL);
  31659. + }
  31660. + }
  31661. +// spin_unlock_irqrestore(&host->lock, flags);
  31662. +}
  31663. +
  31664. +static irqreturn_t sdhci_bcm2708_dma_irq(int irq, void *dev_id)
  31665. +{
  31666. + irqreturn_t result = IRQ_NONE;
  31667. + struct sdhci_host *host = dev_id;
  31668. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31669. + u32 dma_cs; /* control and status register */
  31670. +
  31671. + BUG_ON(NULL == dev_id);
  31672. + BUG_ON(NULL == host_priv->dma_chan_base);
  31673. +
  31674. + sdhci_spin_lock(host);
  31675. +
  31676. + dma_cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  31677. +
  31678. + if (dma_cs & BCM2708_DMA_ERR) {
  31679. + unsigned long debug;
  31680. + debug = readl(host_priv->dma_chan_base +
  31681. + BCM2708_DMA_DEBUG);
  31682. + printk(KERN_ERR "%s: DMA error - CS %lX DEBUG %lX\n",
  31683. + mmc_hostname(host->mmc), (unsigned long)dma_cs,
  31684. + (unsigned long)debug);
  31685. + /* reset error */
  31686. + writel(debug, host_priv->dma_chan_base +
  31687. + BCM2708_DMA_DEBUG);
  31688. + }
  31689. + if (dma_cs & BCM2708_DMA_INT) {
  31690. + /* acknowledge interrupt */
  31691. + writel(BCM2708_DMA_INT,
  31692. + host_priv->dma_chan_base + BCM2708_DMA_CS);
  31693. +
  31694. + dsb(); /* ARM data synchronization (push) operation */
  31695. +
  31696. + if (!host_priv->dma_wanted) {
  31697. + /* ignore this interrupt - it was reset */
  31698. + if (extra_messages)
  31699. + printk(KERN_INFO "%s: DMA IRQ %X ignored - "
  31700. + "results were reset\n",
  31701. + mmc_hostname(host->mmc), dma_cs);
  31702. +#ifdef CHECK_DMA_USE
  31703. + printk(KERN_INFO "%s: now %"FMT_HPT
  31704. + " started %lu reset %lu stopped %lu\n",
  31705. + mmc_hostname(host->mmc), hptime(),
  31706. + since_ns(host_priv->when_started),
  31707. + since_ns(host_priv->when_reset),
  31708. + since_ns(host_priv->when_stopped));
  31709. + host_priv->dmas_pending--;
  31710. +#endif
  31711. + } else
  31712. + sdhci_bcm2708_dma_complete_irq(host, dma_cs);
  31713. +
  31714. + result = IRQ_HANDLED;
  31715. + }
  31716. + sdhci_spin_unlock(host);
  31717. +
  31718. + return result;
  31719. +}
  31720. +#endif /* CONFIG_MMC_SDHCI_BCM2708_DMA */
  31721. +
  31722. +
  31723. +/***************************************************************************** \
  31724. + * *
  31725. + * Device Attributes *
  31726. + * *
  31727. +\*****************************************************************************/
  31728. +
  31729. +
  31730. +/**
  31731. + * Show the DMA-using status
  31732. + */
  31733. +static ssize_t attr_dma_show(struct device *_dev,
  31734. + struct device_attribute *attr, char *buf)
  31735. +{
  31736. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31737. +
  31738. + if (host) {
  31739. + int use_dma = (host->flags & SDHCI_USE_PLATDMA? 1:0);
  31740. + return sprintf(buf, "%d\n", use_dma);
  31741. + } else
  31742. + return -EINVAL;
  31743. +}
  31744. +
  31745. +/**
  31746. + * Set the DMA-using status
  31747. + */
  31748. +static ssize_t attr_dma_store(struct device *_dev,
  31749. + struct device_attribute *attr,
  31750. + const char *buf, size_t count)
  31751. +{
  31752. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31753. +
  31754. + if (host) {
  31755. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31756. + int on = simple_strtol(buf, NULL, 0);
  31757. + if (on) {
  31758. + host->flags |= SDHCI_USE_PLATDMA;
  31759. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  31760. + printk(KERN_INFO "%s: DMA enabled\n",
  31761. + mmc_hostname(host->mmc));
  31762. + } else {
  31763. + host->flags &= ~(SDHCI_USE_PLATDMA | SDHCI_REQ_USE_DMA);
  31764. + sdhci_bcm2708_writel(host, 0, REG_EXRDFIFO_EN);
  31765. + printk(KERN_INFO "%s: DMA disabled\n",
  31766. + mmc_hostname(host->mmc));
  31767. + }
  31768. +#endif
  31769. + return count;
  31770. + } else
  31771. + return -EINVAL;
  31772. +}
  31773. +
  31774. +static DEVICE_ATTR(use_dma, S_IRUGO | S_IWUGO, attr_dma_show, attr_dma_store);
  31775. +
  31776. +
  31777. +/**
  31778. + * Show the DMA wait states used
  31779. + */
  31780. +static ssize_t attr_dmawait_show(struct device *_dev,
  31781. + struct device_attribute *attr, char *buf)
  31782. +{
  31783. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31784. +
  31785. + if (host) {
  31786. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31787. + int dmawait = host_priv->dma_waits;
  31788. + return sprintf(buf, "%d\n", dmawait);
  31789. + } else
  31790. + return -EINVAL;
  31791. +}
  31792. +
  31793. +/**
  31794. + * Set the DMA wait state used
  31795. + */
  31796. +static ssize_t attr_dmawait_store(struct device *_dev,
  31797. + struct device_attribute *attr,
  31798. + const char *buf, size_t count)
  31799. +{
  31800. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31801. +
  31802. + if (host) {
  31803. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31804. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31805. + int dma_waits = simple_strtol(buf, NULL, 0);
  31806. + if (dma_waits >= 0 && dma_waits < 32)
  31807. + host_priv->dma_waits = dma_waits;
  31808. + else
  31809. + printk(KERN_ERR "%s: illegal dma_waits value - %d",
  31810. + mmc_hostname(host->mmc), dma_waits);
  31811. +#endif
  31812. + return count;
  31813. + } else
  31814. + return -EINVAL;
  31815. +}
  31816. +
  31817. +static DEVICE_ATTR(dma_wait, S_IRUGO | S_IWUGO,
  31818. + attr_dmawait_show, attr_dmawait_store);
  31819. +
  31820. +
  31821. +/**
  31822. + * Show the DMA-using status
  31823. + */
  31824. +static ssize_t attr_status_show(struct device *_dev,
  31825. + struct device_attribute *attr, char *buf)
  31826. +{
  31827. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31828. +
  31829. + if (host) {
  31830. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31831. + return sprintf(buf,
  31832. + "present: yes\n"
  31833. + "power: %s\n"
  31834. + "clock: %u Hz\n"
  31835. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31836. + "dma: %s (%d waits)\n",
  31837. +#else
  31838. + "dma: unconfigured\n",
  31839. +#endif
  31840. + "always on",
  31841. + host->clock
  31842. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31843. + , (host->flags & SDHCI_USE_PLATDMA)? "on": "off"
  31844. + , host_priv->dma_waits
  31845. +#endif
  31846. + );
  31847. + } else
  31848. + return -EINVAL;
  31849. +}
  31850. +
  31851. +static DEVICE_ATTR(status, S_IRUGO, attr_status_show, NULL);
  31852. +
  31853. +/***************************************************************************** \
  31854. + * *
  31855. + * Power Management *
  31856. + * *
  31857. +\*****************************************************************************/
  31858. +
  31859. +
  31860. +#ifdef CONFIG_PM
  31861. +static int sdhci_bcm2708_suspend(struct platform_device *dev, pm_message_t state)
  31862. +{
  31863. + struct sdhci_host *host = (struct sdhci_host *)
  31864. + platform_get_drvdata(dev);
  31865. + int ret = 0;
  31866. +
  31867. + if (host->mmc) {
  31868. + //ret = mmc_suspend_host(host->mmc);
  31869. + }
  31870. +
  31871. + return ret;
  31872. +}
  31873. +
  31874. +static int sdhci_bcm2708_resume(struct platform_device *dev)
  31875. +{
  31876. + struct sdhci_host *host = (struct sdhci_host *)
  31877. + platform_get_drvdata(dev);
  31878. + int ret = 0;
  31879. +
  31880. + if (host->mmc) {
  31881. + //ret = mmc_resume_host(host->mmc);
  31882. + }
  31883. +
  31884. + return ret;
  31885. +}
  31886. +#endif
  31887. +
  31888. +
  31889. +/*****************************************************************************\
  31890. + * *
  31891. + * Device quirk functions. Implemented as local ops because the flags *
  31892. + * field is out of space with newer kernels. This implementation can be *
  31893. + * back ported to older kernels as well. *
  31894. +\****************************************************************************/
  31895. +static unsigned int sdhci_bcm2708_quirk_extra_ints(struct sdhci_host *host)
  31896. +{
  31897. + return 1;
  31898. +}
  31899. +
  31900. +static unsigned int sdhci_bcm2708_quirk_spurious_crc_acmd51(struct sdhci_host *host)
  31901. +{
  31902. + return 1;
  31903. +}
  31904. +
  31905. +static unsigned int sdhci_bcm2708_missing_status(struct sdhci_host *host)
  31906. +{
  31907. + return 1;
  31908. +}
  31909. +
  31910. +/***************************************************************************** \
  31911. + * *
  31912. + * Device ops *
  31913. + * *
  31914. +\*****************************************************************************/
  31915. +
  31916. +static struct sdhci_ops sdhci_bcm2708_ops = {
  31917. +#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  31918. + .read_l = sdhci_bcm2708_readl,
  31919. + .read_w = sdhci_bcm2708_readw,
  31920. + .read_b = sdhci_bcm2708_readb,
  31921. + .write_l = sdhci_bcm2708_writel,
  31922. + .write_w = sdhci_bcm2708_writew,
  31923. + .write_b = sdhci_bcm2708_writeb,
  31924. +#else
  31925. +#error The BCM2708 SDHCI driver needs CONFIG_MMC_SDHCI_IO_ACCESSORS to be set
  31926. +#endif
  31927. + .get_max_clock = sdhci_bcm2708_get_max_clock,
  31928. +
  31929. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31930. + // Platform DMA operations
  31931. + .pdma_able = sdhci_bcm2708_platdma_dmaable,
  31932. + .pdma_avail = sdhci_bcm2708_platdma_avail,
  31933. + .pdma_reset = sdhci_bcm2708_platdma_reset,
  31934. +#endif
  31935. + .extra_ints = sdhci_bcm2708_quirk_extra_ints,
  31936. +};
  31937. +
  31938. +/*****************************************************************************\
  31939. + * *
  31940. + * Device probing/removal *
  31941. + * *
  31942. +\*****************************************************************************/
  31943. +
  31944. +static int sdhci_bcm2708_probe(struct platform_device *pdev)
  31945. +{
  31946. + struct sdhci_host *host;
  31947. + struct resource *iomem;
  31948. + struct sdhci_bcm2708_priv *host_priv;
  31949. + int ret;
  31950. +
  31951. + BUG_ON(pdev == NULL);
  31952. +
  31953. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  31954. + if (!iomem) {
  31955. + ret = -ENOMEM;
  31956. + goto err;
  31957. + }
  31958. +
  31959. + if (resource_size(iomem) != 0x100)
  31960. + dev_err(&pdev->dev, "Invalid iomem size. You may "
  31961. + "experience problems.\n");
  31962. +
  31963. + if (pdev->dev.parent)
  31964. + host = sdhci_alloc_host(pdev->dev.parent,
  31965. + sizeof(struct sdhci_bcm2708_priv));
  31966. + else
  31967. + host = sdhci_alloc_host(&pdev->dev,
  31968. + sizeof(struct sdhci_bcm2708_priv));
  31969. +
  31970. + if (IS_ERR(host)) {
  31971. + ret = PTR_ERR(host);
  31972. + goto err;
  31973. + }
  31974. + if (missing_status) {
  31975. + sdhci_bcm2708_ops.missing_status = sdhci_bcm2708_missing_status;
  31976. + }
  31977. +
  31978. + if( spurious_crc_acmd51 ) {
  31979. + sdhci_bcm2708_ops.spurious_crc_acmd51 = sdhci_bcm2708_quirk_spurious_crc_acmd51;
  31980. + }
  31981. +
  31982. +
  31983. + printk("sdhci: %s low-latency mode\n",enable_llm?"Enable":"Disable");
  31984. +
  31985. + host->hw_name = "BCM2708_Arasan";
  31986. + host->ops = &sdhci_bcm2708_ops;
  31987. + host->irq = platform_get_irq(pdev, 0);
  31988. + host->second_irq = 0;
  31989. +
  31990. + host->quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  31991. + SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  31992. + SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  31993. + SDHCI_QUIRK_MISSING_CAPS |
  31994. + SDHCI_QUIRK_NO_HISPD_BIT |
  31995. + (sync_after_dma ? 0:SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12);
  31996. +
  31997. +
  31998. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31999. + host->flags = SDHCI_USE_PLATDMA;
  32000. +#endif
  32001. +
  32002. + if (!request_mem_region(iomem->start, resource_size(iomem),
  32003. + mmc_hostname(host->mmc))) {
  32004. + dev_err(&pdev->dev, "cannot request region\n");
  32005. + ret = -EBUSY;
  32006. + goto err_request;
  32007. + }
  32008. +
  32009. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  32010. + if (!host->ioaddr) {
  32011. + dev_err(&pdev->dev, "failed to remap registers\n");
  32012. + ret = -ENOMEM;
  32013. + goto err_remap;
  32014. + }
  32015. +
  32016. + host_priv = SDHCI_HOST_PRIV(host);
  32017. +
  32018. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32019. + host_priv->dma_wanted = 0;
  32020. +#ifdef CHECK_DMA_USE
  32021. + host_priv->dmas_pending = 0;
  32022. + host_priv->when_started = 0;
  32023. + host_priv->when_reset = 0;
  32024. + host_priv->when_stopped = 0;
  32025. +#endif
  32026. + host_priv->sg_ix = 0;
  32027. + host_priv->sg_done = 0;
  32028. + host_priv->complete = NULL;
  32029. + host_priv->dma_waits = SDHCI_BCM_DMA_WAITS;
  32030. +
  32031. + host_priv->cb_base = dma_alloc_writecombine(&pdev->dev, SZ_4K,
  32032. + &host_priv->cb_handle,
  32033. + GFP_KERNEL);
  32034. + if (!host_priv->cb_base) {
  32035. + dev_err(&pdev->dev, "cannot allocate DMA CBs\n");
  32036. + ret = -ENOMEM;
  32037. + goto err_alloc_cb;
  32038. + }
  32039. +
  32040. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  32041. + &host_priv->dma_chan_base,
  32042. + &host_priv->dma_irq);
  32043. + if (ret < 0) {
  32044. + dev_err(&pdev->dev, "couldn't allocate a DMA channel\n");
  32045. + goto err_add_dma;
  32046. + }
  32047. + host_priv->dma_chan = ret;
  32048. +
  32049. + ret = request_irq(host_priv->dma_irq, sdhci_bcm2708_dma_irq,
  32050. + 0 /*IRQF_SHARED*/, DRIVER_NAME " (dma)", host);
  32051. + if (ret) {
  32052. + dev_err(&pdev->dev, "cannot set DMA IRQ\n");
  32053. + goto err_add_dma_irq;
  32054. + }
  32055. + host->second_irq = host_priv->dma_irq;
  32056. + DBG("DMA CBs %p handle %08X DMA%d %p DMA IRQ %d\n",
  32057. + host_priv->cb_base, (unsigned)host_priv->cb_handle,
  32058. + host_priv->dma_chan, host_priv->dma_chan_base,
  32059. + host_priv->dma_irq);
  32060. +
  32061. + // we support 3.3V
  32062. + host->caps |= SDHCI_CAN_VDD_330;
  32063. + if (allow_highspeed)
  32064. + host->mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
  32065. +
  32066. + /* single block writes cause data loss with some SD cards! */
  32067. + host->mmc->caps2 |= MMC_CAP2_FORCE_MULTIBLOCK;
  32068. +#endif
  32069. +
  32070. + ret = sdhci_add_host(host);
  32071. + if (ret)
  32072. + goto err_add_host;
  32073. +
  32074. + platform_set_drvdata(pdev, host);
  32075. + ret = device_create_file(&pdev->dev, &dev_attr_use_dma);
  32076. + ret = device_create_file(&pdev->dev, &dev_attr_dma_wait);
  32077. + ret = device_create_file(&pdev->dev, &dev_attr_status);
  32078. +
  32079. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32080. + /* enable extension fifo for paced DMA transfers */
  32081. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  32082. + sdhci_bcm2708_writel(host, 4, REG_EXRDFIFO_CFG);
  32083. +#endif
  32084. +
  32085. + printk(KERN_INFO "%s: BCM2708 SDHC host at 0x%08llx DMA %d IRQ %d\n",
  32086. + mmc_hostname(host->mmc), (unsigned long long)iomem->start,
  32087. + host_priv->dma_chan, host_priv->dma_irq);
  32088. +
  32089. + return 0;
  32090. +
  32091. +err_add_host:
  32092. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32093. + free_irq(host_priv->dma_irq, host);
  32094. +err_add_dma_irq:
  32095. + bcm_dma_chan_free(host_priv->dma_chan);
  32096. +err_add_dma:
  32097. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  32098. + host_priv->cb_handle);
  32099. +err_alloc_cb:
  32100. +#endif
  32101. + iounmap(host->ioaddr);
  32102. +err_remap:
  32103. + release_mem_region(iomem->start, resource_size(iomem));
  32104. +err_request:
  32105. + sdhci_free_host(host);
  32106. +err:
  32107. + dev_err(&pdev->dev, "probe failed, err %d\n", ret);
  32108. + return ret;
  32109. +}
  32110. +
  32111. +static int sdhci_bcm2708_remove(struct platform_device *pdev)
  32112. +{
  32113. + struct sdhci_host *host = platform_get_drvdata(pdev);
  32114. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  32115. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32116. + int dead;
  32117. + u32 scratch;
  32118. +
  32119. + dead = 0;
  32120. + scratch = sdhci_bcm2708_readl(host, SDHCI_INT_STATUS);
  32121. + if (scratch == (u32)-1)
  32122. + dead = 1;
  32123. +
  32124. + device_remove_file(&pdev->dev, &dev_attr_status);
  32125. + device_remove_file(&pdev->dev, &dev_attr_dma_wait);
  32126. + device_remove_file(&pdev->dev, &dev_attr_use_dma);
  32127. +
  32128. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32129. + free_irq(host_priv->dma_irq, host);
  32130. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  32131. + host_priv->cb_handle);
  32132. +#endif
  32133. + sdhci_remove_host(host, dead);
  32134. + iounmap(host->ioaddr);
  32135. + release_mem_region(iomem->start, resource_size(iomem));
  32136. + sdhci_free_host(host);
  32137. + platform_set_drvdata(pdev, NULL);
  32138. +
  32139. + return 0;
  32140. +}
  32141. +
  32142. +static struct platform_driver sdhci_bcm2708_driver = {
  32143. + .driver = {
  32144. + .name = DRIVER_NAME,
  32145. + .owner = THIS_MODULE,
  32146. + },
  32147. + .probe = sdhci_bcm2708_probe,
  32148. + .remove = sdhci_bcm2708_remove,
  32149. +
  32150. +#ifdef CONFIG_PM
  32151. + .suspend = sdhci_bcm2708_suspend,
  32152. + .resume = sdhci_bcm2708_resume,
  32153. +#endif
  32154. +
  32155. +};
  32156. +
  32157. +/*****************************************************************************\
  32158. + * *
  32159. + * Driver init/exit *
  32160. + * *
  32161. +\*****************************************************************************/
  32162. +
  32163. +static int __init sdhci_drv_init(void)
  32164. +{
  32165. + return platform_driver_register(&sdhci_bcm2708_driver);
  32166. +}
  32167. +
  32168. +static void __exit sdhci_drv_exit(void)
  32169. +{
  32170. + platform_driver_unregister(&sdhci_bcm2708_driver);
  32171. +}
  32172. +
  32173. +module_init(sdhci_drv_init);
  32174. +module_exit(sdhci_drv_exit);
  32175. +
  32176. +module_param(allow_highspeed, bool, 0444);
  32177. +module_param(emmc_clock_freq, int, 0444);
  32178. +module_param(sync_after_dma, bool, 0444);
  32179. +module_param(missing_status, bool, 0444);
  32180. +module_param(spurious_crc_acmd51, bool, 0444);
  32181. +module_param(enable_llm, bool, 0444);
  32182. +module_param(cycle_delay, int, 0444);
  32183. +module_param(extra_messages, bool, 0444);
  32184. +
  32185. +MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
  32186. +MODULE_AUTHOR("Broadcom <info@broadcom.com>");
  32187. +MODULE_LICENSE("GPL v2");
  32188. +MODULE_ALIAS("platform:"DRIVER_NAME);
  32189. +
  32190. +MODULE_PARM_DESC(allow_highspeed, "Allow high speed transfers modes");
  32191. +MODULE_PARM_DESC(emmc_clock_freq, "Specify the speed of emmc clock");
  32192. +MODULE_PARM_DESC(sync_after_dma, "Block in driver until dma complete");
  32193. +MODULE_PARM_DESC(missing_status, "Use the missing status quirk");
  32194. +MODULE_PARM_DESC(spurious_crc_acmd51, "Use the spurious crc quirk for reading SCR (ACMD51)");
  32195. +MODULE_PARM_DESC(enable_llm, "Enable low-latency mode");
  32196. +MODULE_PARM_DESC(extra_messages, "Enable more sdcard warning messages");
  32197. +
  32198. +
  32199. diff -Nur linux-3.12.18/drivers/mmc/host/sdhci.c linux-rpi/drivers/mmc/host/sdhci.c
  32200. --- linux-3.12.18/drivers/mmc/host/sdhci.c 2014-04-18 11:14:28.000000000 +0200
  32201. +++ linux-rpi/drivers/mmc/host/sdhci.c 2014-04-24 16:04:36.851095558 +0200
  32202. @@ -28,6 +28,7 @@
  32203. #include <linux/mmc/mmc.h>
  32204. #include <linux/mmc/host.h>
  32205. #include <linux/mmc/card.h>
  32206. +#include <linux/mmc/sd.h>
  32207. #include <linux/mmc/slot-gpio.h>
  32208. #include "sdhci.h"
  32209. @@ -131,6 +132,99 @@
  32210. * Low level functions *
  32211. * *
  32212. \*****************************************************************************/
  32213. +extern bool enable_llm;
  32214. +static int sdhci_locked=0;
  32215. +void sdhci_spin_lock(struct sdhci_host *host)
  32216. +{
  32217. + spin_lock(&host->lock);
  32218. +#ifdef CONFIG_PREEMPT
  32219. + if(enable_llm)
  32220. + {
  32221. + disable_irq_nosync(host->irq);
  32222. + if(host->second_irq)
  32223. + disable_irq_nosync(host->second_irq);
  32224. + local_irq_enable();
  32225. + }
  32226. +#endif
  32227. +}
  32228. +
  32229. +void sdhci_spin_unlock(struct sdhci_host *host)
  32230. +{
  32231. +#ifdef CONFIG_PREEMPT
  32232. + if(enable_llm)
  32233. + {
  32234. + local_irq_disable();
  32235. + if(host->second_irq)
  32236. + enable_irq(host->second_irq);
  32237. + enable_irq(host->irq);
  32238. + }
  32239. +#endif
  32240. + spin_unlock(&host->lock);
  32241. +}
  32242. +
  32243. +void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags)
  32244. +{
  32245. +#ifdef CONFIG_PREEMPT
  32246. + if(enable_llm)
  32247. + {
  32248. + while(sdhci_locked)
  32249. + {
  32250. + preempt_schedule();
  32251. + }
  32252. + spin_lock_irqsave(&host->lock,*flags);
  32253. + disable_irq(host->irq);
  32254. + if(host->second_irq)
  32255. + disable_irq(host->second_irq);
  32256. + local_irq_enable();
  32257. + }
  32258. + else
  32259. +#endif
  32260. + spin_lock_irqsave(&host->lock,*flags);
  32261. +}
  32262. +
  32263. +void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags)
  32264. +{
  32265. +#ifdef CONFIG_PREEMPT
  32266. + if(enable_llm)
  32267. + {
  32268. + local_irq_disable();
  32269. + if(host->second_irq)
  32270. + enable_irq(host->second_irq);
  32271. + enable_irq(host->irq);
  32272. + }
  32273. +#endif
  32274. + spin_unlock_irqrestore(&host->lock,flags);
  32275. +}
  32276. +
  32277. +static void sdhci_spin_enable_schedule(struct sdhci_host *host)
  32278. +{
  32279. +#ifdef CONFIG_PREEMPT
  32280. + if(enable_llm)
  32281. + {
  32282. + sdhci_locked = 1;
  32283. + preempt_enable();
  32284. + }
  32285. +#endif
  32286. +}
  32287. +
  32288. +static void sdhci_spin_disable_schedule(struct sdhci_host *host)
  32289. +{
  32290. +#ifdef CONFIG_PREEMPT
  32291. + if(enable_llm)
  32292. + {
  32293. + preempt_disable();
  32294. + sdhci_locked = 0;
  32295. + }
  32296. +#endif
  32297. +}
  32298. +
  32299. +
  32300. +#undef spin_lock_irqsave
  32301. +#define spin_lock_irqsave(host_lock, flags) sdhci_spin_lock_irqsave(container_of(host_lock, struct sdhci_host, lock), &flags)
  32302. +#define spin_unlock_irqrestore(host_lock, flags) sdhci_spin_unlock_irqrestore(container_of(host_lock, struct sdhci_host, lock), flags)
  32303. +
  32304. +#define spin_lock(host_lock) sdhci_spin_lock(container_of(host_lock, struct sdhci_host, lock))
  32305. +#define spin_unlock(host_lock) sdhci_spin_unlock(container_of(host_lock, struct sdhci_host, lock))
  32306. static void sdhci_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set)
  32307. {
  32308. @@ -300,7 +394,7 @@
  32309. struct sdhci_host *host = container_of(led, struct sdhci_host, led);
  32310. unsigned long flags;
  32311. - spin_lock_irqsave(&host->lock, flags);
  32312. + sdhci_spin_lock_irqsave(host, &flags);
  32313. if (host->runtime_suspended)
  32314. goto out;
  32315. @@ -310,7 +404,7 @@
  32316. else
  32317. sdhci_activate_led(host);
  32318. out:
  32319. - spin_unlock_irqrestore(&host->lock, flags);
  32320. + sdhci_spin_unlock_irqrestore(host, flags);
  32321. }
  32322. #endif
  32323. @@ -327,7 +421,7 @@
  32324. u32 uninitialized_var(scratch);
  32325. u8 *buf;
  32326. - DBG("PIO reading\n");
  32327. + DBG("PIO reading %db\n", host->data->blksz);
  32328. blksize = host->data->blksz;
  32329. chunk = 0;
  32330. @@ -372,7 +466,7 @@
  32331. u32 scratch;
  32332. u8 *buf;
  32333. - DBG("PIO writing\n");
  32334. + DBG("PIO writing %db\n", host->data->blksz);
  32335. blksize = host->data->blksz;
  32336. chunk = 0;
  32337. @@ -411,19 +505,28 @@
  32338. local_irq_restore(flags);
  32339. }
  32340. -static void sdhci_transfer_pio(struct sdhci_host *host)
  32341. +static void sdhci_transfer_pio(struct sdhci_host *host, u32 intstate)
  32342. {
  32343. u32 mask;
  32344. + u32 state = 0;
  32345. + u32 intmask;
  32346. + int available;
  32347. BUG_ON(!host->data);
  32348. if (host->blocks == 0)
  32349. return;
  32350. - if (host->data->flags & MMC_DATA_READ)
  32351. + if (host->data->flags & MMC_DATA_READ) {
  32352. mask = SDHCI_DATA_AVAILABLE;
  32353. - else
  32354. + intmask = SDHCI_INT_DATA_AVAIL;
  32355. + } else {
  32356. mask = SDHCI_SPACE_AVAILABLE;
  32357. + intmask = SDHCI_INT_SPACE_AVAIL;
  32358. + }
  32359. +
  32360. + /* initially we can see whether we can procede using intstate */
  32361. + available = (intstate & intmask);
  32362. /*
  32363. * Some controllers (JMicron JMB38x) mess up the buffer bits
  32364. @@ -434,7 +537,7 @@
  32365. (host->data->blocks == 1))
  32366. mask = ~0;
  32367. - while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  32368. + while (available) {
  32369. if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY)
  32370. udelay(100);
  32371. @@ -446,9 +549,12 @@
  32372. host->blocks--;
  32373. if (host->blocks == 0)
  32374. break;
  32375. + state = sdhci_readl(host, SDHCI_PRESENT_STATE);
  32376. + available = state & mask;
  32377. + break;
  32378. }
  32379. - DBG("PIO transfer complete.\n");
  32380. + DBG("PIO transfer complete - %d blocks left.\n", host->blocks);
  32381. }
  32382. static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
  32383. @@ -721,7 +827,9 @@
  32384. u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  32385. u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  32386. - if (host->flags & SDHCI_REQ_USE_DMA)
  32387. + /* platform DMA will begin on receipt of PIO irqs */
  32388. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  32389. + !(host->flags & SDHCI_USE_PLATDMA))
  32390. sdhci_clear_set_irqs(host, pio_irqs, dma_irqs);
  32391. else
  32392. sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
  32393. @@ -753,44 +861,25 @@
  32394. host->data_early = 0;
  32395. host->data->bytes_xfered = 0;
  32396. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
  32397. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA | SDHCI_USE_PLATDMA))
  32398. host->flags |= SDHCI_REQ_USE_DMA;
  32399. /*
  32400. * FIXME: This doesn't account for merging when mapping the
  32401. * scatterlist.
  32402. */
  32403. - if (host->flags & SDHCI_REQ_USE_DMA) {
  32404. - int broken, i;
  32405. - struct scatterlist *sg;
  32406. -
  32407. - broken = 0;
  32408. - if (host->flags & SDHCI_USE_ADMA) {
  32409. - if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
  32410. - broken = 1;
  32411. - } else {
  32412. - if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
  32413. - broken = 1;
  32414. - }
  32415. -
  32416. - if (unlikely(broken)) {
  32417. - for_each_sg(data->sg, sg, data->sg_len, i) {
  32418. - if (sg->length & 0x3) {
  32419. - DBG("Reverting to PIO because of "
  32420. - "transfer size (%d)\n",
  32421. - sg->length);
  32422. - host->flags &= ~SDHCI_REQ_USE_DMA;
  32423. - break;
  32424. - }
  32425. - }
  32426. - }
  32427. - }
  32428. /*
  32429. * The assumption here being that alignment is the same after
  32430. * translation to device address space.
  32431. */
  32432. - if (host->flags & SDHCI_REQ_USE_DMA) {
  32433. + if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) ==
  32434. + (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) {
  32435. +
  32436. + if (! sdhci_platdma_dmaable(host, data))
  32437. + host->flags &= ~SDHCI_REQ_USE_DMA;
  32438. +
  32439. + } else if (host->flags & SDHCI_REQ_USE_DMA) {
  32440. int broken, i;
  32441. struct scatterlist *sg;
  32442. @@ -849,7 +938,8 @@
  32443. */
  32444. WARN_ON(1);
  32445. host->flags &= ~SDHCI_REQ_USE_DMA;
  32446. - } else {
  32447. + } else
  32448. + if (!(host->flags & SDHCI_USE_PLATDMA)) {
  32449. WARN_ON(sg_cnt != 1);
  32450. sdhci_writel(host, sg_dma_address(data->sg),
  32451. SDHCI_DMA_ADDRESS);
  32452. @@ -865,11 +955,13 @@
  32453. if (host->version >= SDHCI_SPEC_200) {
  32454. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  32455. ctrl &= ~SDHCI_CTRL_DMA_MASK;
  32456. + if (! (host->flags & SDHCI_USE_PLATDMA)) {
  32457. if ((host->flags & SDHCI_REQ_USE_DMA) &&
  32458. (host->flags & SDHCI_USE_ADMA))
  32459. ctrl |= SDHCI_CTRL_ADMA32;
  32460. else
  32461. ctrl |= SDHCI_CTRL_SDMA;
  32462. + }
  32463. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  32464. }
  32465. @@ -921,7 +1013,8 @@
  32466. if (data->flags & MMC_DATA_READ)
  32467. mode |= SDHCI_TRNS_READ;
  32468. - if (host->flags & SDHCI_REQ_USE_DMA)
  32469. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  32470. + !(host->flags & SDHCI_USE_PLATDMA))
  32471. mode |= SDHCI_TRNS_DMA;
  32472. sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
  32473. @@ -937,13 +1030,16 @@
  32474. host->data = NULL;
  32475. if (host->flags & SDHCI_REQ_USE_DMA) {
  32476. - if (host->flags & SDHCI_USE_ADMA)
  32477. - sdhci_adma_table_post(host, data);
  32478. - else {
  32479. + /* we may have to abandon an ongoing platform DMA */
  32480. + if (host->flags & SDHCI_USE_PLATDMA)
  32481. + sdhci_platdma_reset(host, data);
  32482. +
  32483. + if (host->flags & (SDHCI_USE_PLATDMA | SDHCI_USE_SDMA)) {
  32484. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  32485. data->sg_len, (data->flags & MMC_DATA_READ) ?
  32486. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  32487. - }
  32488. + } else if (host->flags & SDHCI_USE_ADMA)
  32489. + sdhci_adma_table_post(host, data);
  32490. }
  32491. /*
  32492. @@ -996,6 +1092,12 @@
  32493. if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  32494. mask |= SDHCI_DATA_INHIBIT;
  32495. + if(host->ops->missing_status && (cmd->opcode == MMC_SEND_STATUS)) {
  32496. + timeout = 5000; // Really obscenely large delay to send the status, due to bug in controller
  32497. + // which might cause the STATUS command to get stuck when a data operation is in flow
  32498. + mask |= SDHCI_DATA_INHIBIT;
  32499. + }
  32500. +
  32501. /* We shouldn't wait for data inihibit for stop commands, even
  32502. though they might use busy signaling */
  32503. if (host->mrq->data && (cmd == host->mrq->data->stop))
  32504. @@ -1011,12 +1113,20 @@
  32505. return;
  32506. }
  32507. timeout--;
  32508. + sdhci_spin_enable_schedule(host);
  32509. mdelay(1);
  32510. + sdhci_spin_disable_schedule(host);
  32511. }
  32512. + DBG("send cmd %d - wait 0x%X irq 0x%x\n", cmd->opcode, mask,
  32513. + sdhci_readl(host, SDHCI_INT_STATUS));
  32514. mod_timer(&host->timer, jiffies + 10 * HZ);
  32515. host->cmd = cmd;
  32516. + if (host->last_cmdop == MMC_APP_CMD)
  32517. + host->last_cmdop = -cmd->opcode;
  32518. + else
  32519. + host->last_cmdop = cmd->opcode;
  32520. sdhci_prepare_data(host, cmd);
  32521. @@ -1232,7 +1342,9 @@
  32522. return;
  32523. }
  32524. timeout--;
  32525. + sdhci_spin_enable_schedule(host);
  32526. mdelay(1);
  32527. + sdhci_spin_disable_schedule(host);
  32528. }
  32529. clk |= SDHCI_CLOCK_CARD_EN;
  32530. @@ -1333,7 +1445,7 @@
  32531. sdhci_runtime_pm_get(host);
  32532. - spin_lock_irqsave(&host->lock, flags);
  32533. + sdhci_spin_lock_irqsave(host, &flags);
  32534. WARN_ON(host->mrq != NULL);
  32535. @@ -1391,9 +1503,9 @@
  32536. mmc->card->type == MMC_TYPE_MMC ?
  32537. MMC_SEND_TUNING_BLOCK_HS200 :
  32538. MMC_SEND_TUNING_BLOCK;
  32539. - spin_unlock_irqrestore(&host->lock, flags);
  32540. + sdhci_spin_unlock_irqrestore(host, flags);
  32541. sdhci_execute_tuning(mmc, tuning_opcode);
  32542. - spin_lock_irqsave(&host->lock, flags);
  32543. + sdhci_spin_lock_irqsave(host, &flags);
  32544. /* Restore original mmc_request structure */
  32545. host->mrq = mrq;
  32546. @@ -1407,7 +1519,7 @@
  32547. }
  32548. mmiowb();
  32549. - spin_unlock_irqrestore(&host->lock, flags);
  32550. + sdhci_spin_unlock_irqrestore(host, flags);
  32551. }
  32552. static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
  32553. @@ -1416,10 +1528,10 @@
  32554. int vdd_bit = -1;
  32555. u8 ctrl;
  32556. - spin_lock_irqsave(&host->lock, flags);
  32557. + sdhci_spin_lock_irqsave(host, &flags);
  32558. if (host->flags & SDHCI_DEVICE_DEAD) {
  32559. - spin_unlock_irqrestore(&host->lock, flags);
  32560. + sdhci_spin_unlock_irqrestore(host, flags);
  32561. if (host->vmmc && ios->power_mode == MMC_POWER_OFF)
  32562. mmc_regulator_set_ocr(host->mmc, host->vmmc, 0);
  32563. return;
  32564. @@ -1446,9 +1558,9 @@
  32565. vdd_bit = sdhci_set_power(host, ios->vdd);
  32566. if (host->vmmc && vdd_bit != -1) {
  32567. - spin_unlock_irqrestore(&host->lock, flags);
  32568. + sdhci_spin_unlock_irqrestore(host, flags);
  32569. mmc_regulator_set_ocr(host->mmc, host->vmmc, vdd_bit);
  32570. - spin_lock_irqsave(&host->lock, flags);
  32571. + sdhci_spin_lock_irqsave(host, &flags);
  32572. }
  32573. if (host->ops->platform_send_init_74_clocks)
  32574. @@ -1585,7 +1697,7 @@
  32575. sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
  32576. mmiowb();
  32577. - spin_unlock_irqrestore(&host->lock, flags);
  32578. + sdhci_spin_unlock_irqrestore(host, flags);
  32579. }
  32580. static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  32581. @@ -1633,7 +1745,7 @@
  32582. unsigned long flags;
  32583. int is_readonly;
  32584. - spin_lock_irqsave(&host->lock, flags);
  32585. + sdhci_spin_lock_irqsave(host, &flags);
  32586. if (host->flags & SDHCI_DEVICE_DEAD)
  32587. is_readonly = 0;
  32588. @@ -1643,7 +1755,7 @@
  32589. is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE)
  32590. & SDHCI_WRITE_PROTECT);
  32591. - spin_unlock_irqrestore(&host->lock, flags);
  32592. + sdhci_spin_unlock_irqrestore(host, flags);
  32593. /* This quirk needs to be replaced by a callback-function later */
  32594. return host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT ?
  32595. @@ -1716,9 +1828,9 @@
  32596. struct sdhci_host *host = mmc_priv(mmc);
  32597. unsigned long flags;
  32598. - spin_lock_irqsave(&host->lock, flags);
  32599. + sdhci_spin_lock_irqsave(host, &flags);
  32600. sdhci_enable_sdio_irq_nolock(host, enable);
  32601. - spin_unlock_irqrestore(&host->lock, flags);
  32602. + sdhci_spin_unlock_irqrestore(host, flags);
  32603. }
  32604. static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
  32605. @@ -2066,7 +2178,7 @@
  32606. if (host->ops->card_event)
  32607. host->ops->card_event(host);
  32608. - spin_lock_irqsave(&host->lock, flags);
  32609. + sdhci_spin_lock_irqsave(host, &flags);
  32610. /* Check host->mrq first in case we are runtime suspended */
  32611. if (host->mrq && !sdhci_do_get_cd(host)) {
  32612. @@ -2082,7 +2194,7 @@
  32613. tasklet_schedule(&host->finish_tasklet);
  32614. }
  32615. - spin_unlock_irqrestore(&host->lock, flags);
  32616. + sdhci_spin_unlock_irqrestore(host, flags);
  32617. }
  32618. static const struct mmc_host_ops sdhci_ops = {
  32619. @@ -2121,14 +2233,14 @@
  32620. host = (struct sdhci_host*)param;
  32621. - spin_lock_irqsave(&host->lock, flags);
  32622. + sdhci_spin_lock_irqsave(host, &flags);
  32623. /*
  32624. * If this tasklet gets rescheduled while running, it will
  32625. * be run again afterwards but without any active request.
  32626. */
  32627. if (!host->mrq) {
  32628. - spin_unlock_irqrestore(&host->lock, flags);
  32629. + sdhci_spin_unlock_irqrestore(host, flags);
  32630. return;
  32631. }
  32632. @@ -2166,7 +2278,7 @@
  32633. #endif
  32634. mmiowb();
  32635. - spin_unlock_irqrestore(&host->lock, flags);
  32636. + sdhci_spin_unlock_irqrestore(host, flags);
  32637. mmc_request_done(host->mmc, mrq);
  32638. sdhci_runtime_pm_put(host);
  32639. @@ -2179,11 +2291,11 @@
  32640. host = (struct sdhci_host*)data;
  32641. - spin_lock_irqsave(&host->lock, flags);
  32642. + sdhci_spin_lock_irqsave(host, &flags);
  32643. if (host->mrq) {
  32644. pr_err("%s: Timeout waiting for hardware "
  32645. - "interrupt.\n", mmc_hostname(host->mmc));
  32646. + "interrupt - cmd%d.\n", mmc_hostname(host->mmc), host->last_cmdop);
  32647. sdhci_dumpregs(host);
  32648. if (host->data) {
  32649. @@ -2200,7 +2312,7 @@
  32650. }
  32651. mmiowb();
  32652. - spin_unlock_irqrestore(&host->lock, flags);
  32653. + sdhci_spin_unlock_irqrestore(host, flags);
  32654. }
  32655. static void sdhci_tuning_timer(unsigned long data)
  32656. @@ -2210,11 +2322,11 @@
  32657. host = (struct sdhci_host *)data;
  32658. - spin_lock_irqsave(&host->lock, flags);
  32659. + sdhci_spin_lock_irqsave(host, &flags);
  32660. host->flags |= SDHCI_NEEDS_RETUNING;
  32661. - spin_unlock_irqrestore(&host->lock, flags);
  32662. + sdhci_spin_unlock_irqrestore(host, flags);
  32663. }
  32664. /*****************************************************************************\
  32665. @@ -2228,10 +2340,13 @@
  32666. BUG_ON(intmask == 0);
  32667. if (!host->cmd) {
  32668. + if (!(host->ops->extra_ints)) {
  32669. pr_err("%s: Got command interrupt 0x%08x even "
  32670. "though no command operation was in progress.\n",
  32671. mmc_hostname(host->mmc), (unsigned)intmask);
  32672. sdhci_dumpregs(host);
  32673. + } else
  32674. + DBG("cmd irq 0x%08x cmd complete\n", (unsigned)intmask);
  32675. return;
  32676. }
  32677. @@ -2301,6 +2416,19 @@
  32678. static void sdhci_show_adma_error(struct sdhci_host *host) { }
  32679. #endif
  32680. +static void sdhci_data_end(struct sdhci_host *host)
  32681. +{
  32682. + if (host->cmd) {
  32683. + /*
  32684. + * Data managed to finish before the
  32685. + * command completed. Make sure we do
  32686. + * things in the proper order.
  32687. + */
  32688. + host->data_early = 1;
  32689. + } else
  32690. + sdhci_finish_data(host);
  32691. +}
  32692. +
  32693. static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
  32694. {
  32695. u32 command;
  32696. @@ -2330,23 +2458,39 @@
  32697. }
  32698. }
  32699. + if (!(host->ops->extra_ints)) {
  32700. pr_err("%s: Got data interrupt 0x%08x even "
  32701. "though no data operation was in progress.\n",
  32702. mmc_hostname(host->mmc), (unsigned)intmask);
  32703. sdhci_dumpregs(host);
  32704. + } else
  32705. + DBG("data irq 0x%08x but no data\n", (unsigned)intmask);
  32706. return;
  32707. }
  32708. if (intmask & SDHCI_INT_DATA_TIMEOUT)
  32709. host->data->error = -ETIMEDOUT;
  32710. - else if (intmask & SDHCI_INT_DATA_END_BIT)
  32711. + else if (intmask & SDHCI_INT_DATA_END_BIT) {
  32712. + DBG("end error in cmd %d\n", host->last_cmdop);
  32713. + if (host->ops->spurious_crc_acmd51 &&
  32714. + host->last_cmdop == -SD_APP_SEND_SCR) {
  32715. + DBG("ignoring spurious data_end_bit error\n");
  32716. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  32717. + } else
  32718. host->data->error = -EILSEQ;
  32719. - else if ((intmask & SDHCI_INT_DATA_CRC) &&
  32720. + } else if ((intmask & SDHCI_INT_DATA_CRC) &&
  32721. SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
  32722. - != MMC_BUS_TEST_R)
  32723. + != MMC_BUS_TEST_R) {
  32724. + DBG("crc error in cmd %d\n", host->last_cmdop);
  32725. + if (host->ops->spurious_crc_acmd51 &&
  32726. + host->last_cmdop == -SD_APP_SEND_SCR) {
  32727. + DBG("ignoring spurious data_crc_bit error\n");
  32728. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  32729. + } else {
  32730. host->data->error = -EILSEQ;
  32731. - else if (intmask & SDHCI_INT_ADMA_ERROR) {
  32732. + }
  32733. + } else if (intmask & SDHCI_INT_ADMA_ERROR) {
  32734. pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
  32735. sdhci_show_adma_error(host);
  32736. host->data->error = -EIO;
  32737. @@ -2354,11 +2498,18 @@
  32738. host->ops->adma_workaround(host, intmask);
  32739. }
  32740. - if (host->data->error)
  32741. + if (host->data->error) {
  32742. + DBG("finish request early on error %d\n", host->data->error);
  32743. sdhci_finish_data(host);
  32744. - else {
  32745. - if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  32746. - sdhci_transfer_pio(host);
  32747. + } else {
  32748. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) {
  32749. + if (host->flags & SDHCI_REQ_USE_DMA) {
  32750. + /* possible only in PLATDMA mode */
  32751. + sdhci_platdma_avail(host, &intmask,
  32752. + &sdhci_data_end);
  32753. + } else
  32754. + sdhci_transfer_pio(host, intmask);
  32755. + }
  32756. /*
  32757. * We currently don't do anything fancy with DMA
  32758. @@ -2387,18 +2538,8 @@
  32759. sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS);
  32760. }
  32761. - if (intmask & SDHCI_INT_DATA_END) {
  32762. - if (host->cmd) {
  32763. - /*
  32764. - * Data managed to finish before the
  32765. - * command completed. Make sure we do
  32766. - * things in the proper order.
  32767. - */
  32768. - host->data_early = 1;
  32769. - } else {
  32770. - sdhci_finish_data(host);
  32771. - }
  32772. - }
  32773. + if (intmask & SDHCI_INT_DATA_END)
  32774. + sdhci_data_end(host);
  32775. }
  32776. }
  32777. @@ -2409,10 +2550,10 @@
  32778. u32 intmask, unexpected = 0;
  32779. int cardint = 0, max_loops = 16;
  32780. - spin_lock(&host->lock);
  32781. + sdhci_spin_lock(host);
  32782. if (host->runtime_suspended) {
  32783. - spin_unlock(&host->lock);
  32784. + sdhci_spin_unlock(host);
  32785. pr_warning("%s: got irq while runtime suspended\n",
  32786. mmc_hostname(host->mmc));
  32787. return IRQ_HANDLED;
  32788. @@ -2454,6 +2595,22 @@
  32789. tasklet_schedule(&host->card_tasklet);
  32790. }
  32791. + if (intmask & SDHCI_INT_ERROR_MASK & ~SDHCI_INT_ERROR)
  32792. + DBG("controller reports error 0x%x -"
  32793. + "%s%s%s%s%s%s%s%s%s%s",
  32794. + intmask,
  32795. + intmask & SDHCI_INT_TIMEOUT? " timeout": "",
  32796. + intmask & SDHCI_INT_CRC ? " crc": "",
  32797. + intmask & SDHCI_INT_END_BIT? " endbit": "",
  32798. + intmask & SDHCI_INT_INDEX? " index": "",
  32799. + intmask & SDHCI_INT_DATA_TIMEOUT? " data_timeout": "",
  32800. + intmask & SDHCI_INT_DATA_CRC? " data_crc": "",
  32801. + intmask & SDHCI_INT_DATA_END_BIT? " data_endbit": "",
  32802. + intmask & SDHCI_INT_BUS_POWER? " buspower": "",
  32803. + intmask & SDHCI_INT_ACMD12ERR? " acmd12": "",
  32804. + intmask & SDHCI_INT_ADMA_ERROR? " adma": ""
  32805. + );
  32806. +
  32807. if (intmask & SDHCI_INT_CMD_MASK) {
  32808. sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
  32809. SDHCI_INT_STATUS);
  32810. @@ -2468,7 +2625,13 @@
  32811. intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
  32812. - intmask &= ~SDHCI_INT_ERROR;
  32813. + if (intmask & SDHCI_INT_ERROR_MASK) {
  32814. + /* collect any uncovered errors */
  32815. + sdhci_writel(host, intmask & SDHCI_INT_ERROR_MASK,
  32816. + SDHCI_INT_STATUS);
  32817. + }
  32818. +
  32819. + intmask &= ~SDHCI_INT_ERROR_MASK;
  32820. if (intmask & SDHCI_INT_BUS_POWER) {
  32821. pr_err("%s: Card is consuming too much power!\n",
  32822. @@ -2494,7 +2657,7 @@
  32823. if (intmask && --max_loops)
  32824. goto again;
  32825. out:
  32826. - spin_unlock(&host->lock);
  32827. + sdhci_spin_unlock(host);
  32828. if (unexpected) {
  32829. pr_err("%s: Unexpected interrupt 0x%08x.\n",
  32830. @@ -2588,13 +2751,14 @@
  32831. {
  32832. int ret;
  32833. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  32834. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32835. + SDHCI_USE_PLATDMA)) {
  32836. if (host->ops->enable_dma)
  32837. host->ops->enable_dma(host);
  32838. }
  32839. if (!device_may_wakeup(mmc_dev(host->mmc))) {
  32840. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  32841. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  32842. mmc_hostname(host->mmc), host);
  32843. if (ret)
  32844. return ret;
  32845. @@ -2671,15 +2835,15 @@
  32846. host->flags &= ~SDHCI_NEEDS_RETUNING;
  32847. }
  32848. - spin_lock_irqsave(&host->lock, flags);
  32849. + sdhci_spin_lock_irqsave(host, &flags);
  32850. sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
  32851. - spin_unlock_irqrestore(&host->lock, flags);
  32852. + sdhci_spin_unlock_irqrestore(host, flags);
  32853. synchronize_irq(host->irq);
  32854. - spin_lock_irqsave(&host->lock, flags);
  32855. + sdhci_spin_lock_irqsave(host, &flags);
  32856. host->runtime_suspended = true;
  32857. - spin_unlock_irqrestore(&host->lock, flags);
  32858. + sdhci_spin_unlock_irqrestore(host, flags);
  32859. return ret;
  32860. }
  32861. @@ -2705,16 +2869,16 @@
  32862. sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios);
  32863. if ((host_flags & SDHCI_PV_ENABLED) &&
  32864. !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) {
  32865. - spin_lock_irqsave(&host->lock, flags);
  32866. + sdhci_spin_lock_irqsave(host, &flags);
  32867. sdhci_enable_preset_value(host, true);
  32868. - spin_unlock_irqrestore(&host->lock, flags);
  32869. + sdhci_spin_unlock_irqrestore(host, flags);
  32870. }
  32871. /* Set the re-tuning expiration flag */
  32872. if (host->flags & SDHCI_USING_RETUNING_TIMER)
  32873. host->flags |= SDHCI_NEEDS_RETUNING;
  32874. - spin_lock_irqsave(&host->lock, flags);
  32875. + sdhci_spin_lock_irqsave(host, &flags);
  32876. host->runtime_suspended = false;
  32877. @@ -2725,7 +2889,7 @@
  32878. /* Enable Card Detection */
  32879. sdhci_enable_card_detection(host);
  32880. - spin_unlock_irqrestore(&host->lock, flags);
  32881. + sdhci_spin_unlock_irqrestore(host, flags);
  32882. return ret;
  32883. }
  32884. @@ -2820,14 +2984,16 @@
  32885. host->flags &= ~SDHCI_USE_ADMA;
  32886. }
  32887. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  32888. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32889. + SDHCI_USE_PLATDMA)) {
  32890. if (host->ops->enable_dma) {
  32891. if (host->ops->enable_dma(host)) {
  32892. pr_warning("%s: No suitable DMA "
  32893. "available. Falling back to PIO.\n",
  32894. mmc_hostname(mmc));
  32895. host->flags &=
  32896. - ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA);
  32897. + ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32898. + SDHCI_USE_PLATDMA);
  32899. }
  32900. }
  32901. }
  32902. @@ -3218,8 +3384,8 @@
  32903. sdhci_init(host, 0);
  32904. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  32905. - mmc_hostname(mmc), host);
  32906. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  32907. + mmc_hostname(mmc), host);
  32908. if (ret) {
  32909. pr_err("%s: Failed to request IRQ %d: %d\n",
  32910. mmc_hostname(mmc), host->irq, ret);
  32911. @@ -3252,6 +3418,7 @@
  32912. pr_info("%s: SDHCI controller on %s [%s] using %s\n",
  32913. mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
  32914. + (host->flags & SDHCI_USE_PLATDMA) ? "platform's DMA" :
  32915. (host->flags & SDHCI_USE_ADMA) ? "ADMA" :
  32916. (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
  32917. @@ -3279,7 +3446,7 @@
  32918. unsigned long flags;
  32919. if (dead) {
  32920. - spin_lock_irqsave(&host->lock, flags);
  32921. + sdhci_spin_lock_irqsave(host, &flags);
  32922. host->flags |= SDHCI_DEVICE_DEAD;
  32923. @@ -3291,7 +3458,7 @@
  32924. tasklet_schedule(&host->finish_tasklet);
  32925. }
  32926. - spin_unlock_irqrestore(&host->lock, flags);
  32927. + sdhci_spin_unlock_irqrestore(host, flags);
  32928. }
  32929. sdhci_disable_card_detection(host);
  32930. diff -Nur linux-3.12.18/drivers/mmc/host/sdhci.h linux-rpi/drivers/mmc/host/sdhci.h
  32931. --- linux-3.12.18/drivers/mmc/host/sdhci.h 2014-04-18 11:14:28.000000000 +0200
  32932. +++ linux-rpi/drivers/mmc/host/sdhci.h 2014-04-24 16:04:36.851095558 +0200
  32933. @@ -289,6 +289,18 @@
  32934. void (*platform_reset_enter)(struct sdhci_host *host, u8 mask);
  32935. void (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
  32936. int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
  32937. +
  32938. + int (*pdma_able)(struct sdhci_host *host,
  32939. + struct mmc_data *data);
  32940. + void (*pdma_avail)(struct sdhci_host *host,
  32941. + unsigned int *ref_intmask,
  32942. + void(*complete)(struct sdhci_host *));
  32943. + void (*pdma_reset)(struct sdhci_host *host,
  32944. + struct mmc_data *data);
  32945. + unsigned int (*extra_ints)(struct sdhci_host *host);
  32946. + unsigned int (*spurious_crc_acmd51)(struct sdhci_host *host);
  32947. + unsigned int (*missing_status)(struct sdhci_host *host);
  32948. +
  32949. void (*hw_reset)(struct sdhci_host *host);
  32950. void (*platform_suspend)(struct sdhci_host *host);
  32951. void (*platform_resume)(struct sdhci_host *host);
  32952. @@ -400,9 +412,38 @@
  32953. extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
  32954. #endif
  32955. +static inline int /*bool*/
  32956. +sdhci_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  32957. +{
  32958. + if (host->ops->pdma_able)
  32959. + return host->ops->pdma_able(host, data);
  32960. + else
  32961. + return 1;
  32962. +}
  32963. +static inline void
  32964. +sdhci_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  32965. + void(*completion_callback)(struct sdhci_host *))
  32966. +{
  32967. + if (host->ops->pdma_avail)
  32968. + host->ops->pdma_avail(host, ref_intmask, completion_callback);
  32969. +}
  32970. +
  32971. +static inline void
  32972. +sdhci_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  32973. +{
  32974. + if (host->ops->pdma_reset)
  32975. + host->ops->pdma_reset(host, data);
  32976. +}
  32977. +
  32978. #ifdef CONFIG_PM_RUNTIME
  32979. extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
  32980. extern int sdhci_runtime_resume_host(struct sdhci_host *host);
  32981. #endif
  32982. +extern void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags);
  32983. +extern void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags);
  32984. +extern void sdhci_spin_lock(struct sdhci_host *host);
  32985. +extern void sdhci_spin_unlock(struct sdhci_host *host);
  32986. +
  32987. +
  32988. #endif /* __SDHCI_HW_H */
  32989. diff -Nur linux-3.12.18/drivers/net/bonding/bond_alb.c linux-rpi/drivers/net/bonding/bond_alb.c
  32990. --- linux-3.12.18/drivers/net/bonding/bond_alb.c 2014-04-18 11:14:28.000000000 +0200
  32991. +++ linux-rpi/drivers/net/bonding/bond_alb.c 2014-04-24 16:04:36.879095829 +0200
  32992. @@ -694,7 +694,7 @@
  32993. client_info->ntt = 0;
  32994. }
  32995. - if (vlan_get_tag(skb, &client_info->vlan_id))
  32996. + if (!vlan_get_tag(skb, &client_info->vlan_id))
  32997. client_info->vlan_id = 0;
  32998. if (!client_info->assigned) {
  32999. diff -Nur linux-3.12.18/drivers/net/ethernet/broadcom/bnx2.c linux-rpi/drivers/net/ethernet/broadcom/bnx2.c
  33000. --- linux-3.12.18/drivers/net/ethernet/broadcom/bnx2.c 2014-04-18 11:14:28.000000000 +0200
  33001. +++ linux-rpi/drivers/net/ethernet/broadcom/bnx2.c 2014-04-24 16:04:36.911096138 +0200
  33002. @@ -2490,7 +2490,6 @@
  33003. bp->fw_wr_seq++;
  33004. msg_data |= bp->fw_wr_seq;
  33005. - bp->fw_last_msg = msg_data;
  33006. bnx2_shmem_wr(bp, BNX2_DRV_MB, msg_data);
  33007. @@ -3983,23 +3982,8 @@
  33008. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  33009. }
  33010. - if (!(bp->flags & BNX2_FLAG_NO_WOL)) {
  33011. - u32 val;
  33012. -
  33013. - wol_msg |= BNX2_DRV_MSG_DATA_WAIT3;
  33014. - if (bp->fw_last_msg || BNX2_CHIP(bp) != BNX2_CHIP_5709) {
  33015. - bnx2_fw_sync(bp, wol_msg, 1, 0);
  33016. - return;
  33017. - }
  33018. - /* Tell firmware not to power down the PHY yet, otherwise
  33019. - * the chip will take a long time to respond to MMIO reads.
  33020. - */
  33021. - val = bnx2_shmem_rd(bp, BNX2_PORT_FEATURE);
  33022. - bnx2_shmem_wr(bp, BNX2_PORT_FEATURE,
  33023. - val | BNX2_PORT_FEATURE_ASF_ENABLED);
  33024. - bnx2_fw_sync(bp, wol_msg, 1, 0);
  33025. - bnx2_shmem_wr(bp, BNX2_PORT_FEATURE, val);
  33026. - }
  33027. + if (!(bp->flags & BNX2_FLAG_NO_WOL))
  33028. + bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg, 1, 0);
  33029. }
  33030. @@ -4031,22 +4015,9 @@
  33031. if (bp->wol)
  33032. pci_set_power_state(bp->pdev, PCI_D3hot);
  33033. - break;
  33034. -
  33035. - }
  33036. - if (!bp->fw_last_msg && BNX2_CHIP(bp) == BNX2_CHIP_5709) {
  33037. - u32 val;
  33038. -
  33039. - /* Tell firmware not to power down the PHY yet,
  33040. - * otherwise the other port may not respond to
  33041. - * MMIO reads.
  33042. - */
  33043. - val = bnx2_shmem_rd(bp, BNX2_BC_STATE_CONDITION);
  33044. - val &= ~BNX2_CONDITION_PM_STATE_MASK;
  33045. - val |= BNX2_CONDITION_PM_STATE_UNPREP;
  33046. - bnx2_shmem_wr(bp, BNX2_BC_STATE_CONDITION, val);
  33047. + } else {
  33048. + pci_set_power_state(bp->pdev, PCI_D3hot);
  33049. }
  33050. - pci_set_power_state(bp->pdev, PCI_D3hot);
  33051. /* No more memory access after this point until
  33052. * device is brought back to D0.
  33053. diff -Nur linux-3.12.18/drivers/net/ethernet/broadcom/bnx2.h linux-rpi/drivers/net/ethernet/broadcom/bnx2.h
  33054. --- linux-3.12.18/drivers/net/ethernet/broadcom/bnx2.h 2014-04-18 11:14:28.000000000 +0200
  33055. +++ linux-rpi/drivers/net/ethernet/broadcom/bnx2.h 2014-04-24 16:04:36.915096177 +0200
  33056. @@ -6890,7 +6890,6 @@
  33057. u16 fw_wr_seq;
  33058. u16 fw_drv_pulse_wr_seq;
  33059. - u32 fw_last_msg;
  33060. int rx_max_ring;
  33061. int rx_ring_size;
  33062. @@ -7397,10 +7396,6 @@
  33063. #define BNX2_CONDITION_MFW_RUN_NCSI 0x00006000
  33064. #define BNX2_CONDITION_MFW_RUN_NONE 0x0000e000
  33065. #define BNX2_CONDITION_MFW_RUN_MASK 0x0000e000
  33066. -#define BNX2_CONDITION_PM_STATE_MASK 0x00030000
  33067. -#define BNX2_CONDITION_PM_STATE_FULL 0x00030000
  33068. -#define BNX2_CONDITION_PM_STATE_PREP 0x00020000
  33069. -#define BNX2_CONDITION_PM_STATE_UNPREP 0x00010000
  33070. #define BNX2_BC_STATE_DEBUG_CMD 0x1dc
  33071. #define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE 0x42440000
  33072. diff -Nur linux-3.12.18/drivers/net/ethernet/broadcom/tg3.c linux-rpi/drivers/net/ethernet/broadcom/tg3.c
  33073. --- linux-3.12.18/drivers/net/ethernet/broadcom/tg3.c 2014-04-18 11:14:28.000000000 +0200
  33074. +++ linux-rpi/drivers/net/ethernet/broadcom/tg3.c 2014-04-24 16:04:36.935096370 +0200
  33075. @@ -17480,6 +17480,8 @@
  33076. tg3_init_bufmgr_config(tp);
  33077. + features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
  33078. +
  33079. /* 5700 B0 chips do not support checksumming correctly due
  33080. * to hardware bugs.
  33081. */
  33082. @@ -17511,8 +17513,7 @@
  33083. features |= NETIF_F_TSO_ECN;
  33084. }
  33085. - dev->features |= features | NETIF_F_HW_VLAN_CTAG_TX |
  33086. - NETIF_F_HW_VLAN_CTAG_RX;
  33087. + dev->features |= features;
  33088. dev->vlan_features |= features;
  33089. /*
  33090. diff -Nur linux-3.12.18/drivers/net/ethernet/freescale/fec_main.c linux-rpi/drivers/net/ethernet/freescale/fec_main.c
  33091. --- linux-3.12.18/drivers/net/ethernet/freescale/fec_main.c 2014-04-18 11:14:28.000000000 +0200
  33092. +++ linux-rpi/drivers/net/ethernet/freescale/fec_main.c 2014-04-24 16:04:37.143098381 +0200
  33093. @@ -525,6 +525,13 @@
  33094. /* Clear any outstanding interrupt. */
  33095. writel(0xffc00000, fep->hwp + FEC_IEVENT);
  33096. + /* Setup multicast filter. */
  33097. + set_multicast_list(ndev);
  33098. +#ifndef CONFIG_M5272
  33099. + writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
  33100. + writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
  33101. +#endif
  33102. +
  33103. /* Set maximum receive buffer size. */
  33104. writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
  33105. @@ -645,13 +652,6 @@
  33106. writel(rcntl, fep->hwp + FEC_R_CNTRL);
  33107. - /* Setup multicast filter. */
  33108. - set_multicast_list(ndev);
  33109. -#ifndef CONFIG_M5272
  33110. - writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
  33111. - writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
  33112. -#endif
  33113. -
  33114. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
  33115. /* enable ENET endian swap */
  33116. ecntl |= (1 << 8);
  33117. diff -Nur linux-3.12.18/drivers/net/ethernet/micrel/ks8851.c linux-rpi/drivers/net/ethernet/micrel/ks8851.c
  33118. --- linux-3.12.18/drivers/net/ethernet/micrel/ks8851.c 2014-04-18 11:14:28.000000000 +0200
  33119. +++ linux-rpi/drivers/net/ethernet/micrel/ks8851.c 2014-04-24 15:35:03.105553878 +0200
  33120. @@ -23,7 +23,6 @@
  33121. #include <linux/crc32.h>
  33122. #include <linux/mii.h>
  33123. #include <linux/eeprom_93cx6.h>
  33124. -#include <linux/regulator/consumer.h>
  33125. #include <linux/spi/spi.h>
  33126. @@ -84,7 +83,6 @@
  33127. * @rc_rxqcr: Cached copy of KS_RXQCR.
  33128. * @eeprom_size: Companion eeprom size in Bytes, 0 if no eeprom
  33129. * @eeprom: 93CX6 EEPROM state for accessing on-board EEPROM.
  33130. - * @vdd_reg: Optional regulator supplying the chip
  33131. *
  33132. * The @lock ensures that the chip is protected when certain operations are
  33133. * in progress. When the read or write packet transfer is in progress, most
  33134. @@ -132,7 +130,6 @@
  33135. struct spi_transfer spi_xfer2[2];
  33136. struct eeprom_93cx6 eeprom;
  33137. - struct regulator *vdd_reg;
  33138. };
  33139. static int msg_enable;
  33140. @@ -1417,21 +1414,6 @@
  33141. ks->spidev = spi;
  33142. ks->tx_space = 6144;
  33143. - ks->vdd_reg = regulator_get_optional(&spi->dev, "vdd");
  33144. - if (IS_ERR(ks->vdd_reg)) {
  33145. - ret = PTR_ERR(ks->vdd_reg);
  33146. - if (ret == -EPROBE_DEFER)
  33147. - goto err_reg;
  33148. - } else {
  33149. - ret = regulator_enable(ks->vdd_reg);
  33150. - if (ret) {
  33151. - dev_err(&spi->dev, "regulator enable fail: %d\n",
  33152. - ret);
  33153. - goto err_reg_en;
  33154. - }
  33155. - }
  33156. -
  33157. -
  33158. mutex_init(&ks->lock);
  33159. spin_lock_init(&ks->statelock);
  33160. @@ -1526,14 +1508,8 @@
  33161. err_netdev:
  33162. free_irq(ndev->irq, ks);
  33163. -err_irq:
  33164. err_id:
  33165. - if (!IS_ERR(ks->vdd_reg))
  33166. - regulator_disable(ks->vdd_reg);
  33167. -err_reg_en:
  33168. - if (!IS_ERR(ks->vdd_reg))
  33169. - regulator_put(ks->vdd_reg);
  33170. -err_reg:
  33171. +err_irq:
  33172. free_netdev(ndev);
  33173. return ret;
  33174. }
  33175. @@ -1547,10 +1523,6 @@
  33176. unregister_netdev(priv->netdev);
  33177. free_irq(spi->irq, priv);
  33178. - if (!IS_ERR(priv->vdd_reg)) {
  33179. - regulator_disable(priv->vdd_reg);
  33180. - regulator_put(priv->vdd_reg);
  33181. - }
  33182. free_netdev(priv->netdev);
  33183. return 0;
  33184. diff -Nur linux-3.12.18/drivers/net/usb/smsc95xx.c linux-rpi/drivers/net/usb/smsc95xx.c
  33185. --- linux-3.12.18/drivers/net/usb/smsc95xx.c 2014-04-18 11:14:28.000000000 +0200
  33186. +++ linux-rpi/drivers/net/usb/smsc95xx.c 2014-04-24 15:35:03.209555036 +0200
  33187. @@ -61,6 +61,7 @@
  33188. #define SUSPEND_SUSPEND3 (0x08)
  33189. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  33190. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  33191. +#define MAC_ADDR_LEN (6)
  33192. struct smsc95xx_priv {
  33193. u32 mac_cr;
  33194. @@ -76,6 +77,10 @@
  33195. module_param(turbo_mode, bool, 0644);
  33196. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  33197. +static char *macaddr = ":";
  33198. +module_param(macaddr, charp, 0);
  33199. +MODULE_PARM_DESC(macaddr, "MAC address");
  33200. +
  33201. static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
  33202. u32 *data, int in_pm)
  33203. {
  33204. @@ -765,8 +770,59 @@
  33205. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  33206. }
  33207. +/* Check the macaddr module parameter for a MAC address */
  33208. +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
  33209. +{
  33210. + int i, j, got_num, num;
  33211. + u8 mtbl[MAC_ADDR_LEN];
  33212. +
  33213. + if (macaddr[0] == ':')
  33214. + return 0;
  33215. +
  33216. + i = 0;
  33217. + j = 0;
  33218. + num = 0;
  33219. + got_num = 0;
  33220. + while (j < MAC_ADDR_LEN) {
  33221. + if (macaddr[i] && macaddr[i] != ':') {
  33222. + got_num++;
  33223. + if ('0' <= macaddr[i] && macaddr[i] <= '9')
  33224. + num = num * 16 + macaddr[i] - '0';
  33225. + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
  33226. + num = num * 16 + 10 + macaddr[i] - 'A';
  33227. + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
  33228. + num = num * 16 + 10 + macaddr[i] - 'a';
  33229. + else
  33230. + break;
  33231. + i++;
  33232. + } else if (got_num == 2) {
  33233. + mtbl[j++] = (u8) num;
  33234. + num = 0;
  33235. + got_num = 0;
  33236. + i++;
  33237. + } else {
  33238. + break;
  33239. + }
  33240. + }
  33241. +
  33242. + if (j == MAC_ADDR_LEN) {
  33243. + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
  33244. + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
  33245. + mtbl[3], mtbl[4], mtbl[5]);
  33246. + for (i = 0; i < MAC_ADDR_LEN; i++)
  33247. + dev_mac[i] = mtbl[i];
  33248. + return 1;
  33249. + } else {
  33250. + return 0;
  33251. + }
  33252. +}
  33253. +
  33254. static void smsc95xx_init_mac_address(struct usbnet *dev)
  33255. {
  33256. + /* Check module parameters */
  33257. + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
  33258. + return;
  33259. +
  33260. /* try reading mac address from EEPROM */
  33261. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  33262. dev->net->dev_addr) == 0) {
  33263. diff -Nur linux-3.12.18/drivers/net/usb/usbnet.c linux-rpi/drivers/net/usb/usbnet.c
  33264. --- linux-3.12.18/drivers/net/usb/usbnet.c 2014-04-18 11:14:28.000000000 +0200
  33265. +++ linux-rpi/drivers/net/usb/usbnet.c 2014-04-24 16:04:37.631103100 +0200
  33266. @@ -753,12 +753,14 @@
  33267. // precondition: never called in_interrupt
  33268. static void usbnet_terminate_urbs(struct usbnet *dev)
  33269. {
  33270. + DECLARE_WAIT_QUEUE_HEAD_ONSTACK(unlink_wakeup);
  33271. DECLARE_WAITQUEUE(wait, current);
  33272. int temp;
  33273. /* ensure there are no more active urbs */
  33274. - add_wait_queue(&dev->wait, &wait);
  33275. + add_wait_queue(&unlink_wakeup, &wait);
  33276. set_current_state(TASK_UNINTERRUPTIBLE);
  33277. + dev->wait = &unlink_wakeup;
  33278. temp = unlink_urbs(dev, &dev->txq) +
  33279. unlink_urbs(dev, &dev->rxq);
  33280. @@ -772,14 +774,15 @@
  33281. "waited for %d urb completions\n", temp);
  33282. }
  33283. set_current_state(TASK_RUNNING);
  33284. - remove_wait_queue(&dev->wait, &wait);
  33285. + dev->wait = NULL;
  33286. + remove_wait_queue(&unlink_wakeup, &wait);
  33287. }
  33288. int usbnet_stop (struct net_device *net)
  33289. {
  33290. struct usbnet *dev = netdev_priv(net);
  33291. struct driver_info *info = dev->driver_info;
  33292. - int retval, pm;
  33293. + int retval;
  33294. clear_bit(EVENT_DEV_OPEN, &dev->flags);
  33295. netif_stop_queue (net);
  33296. @@ -789,8 +792,6 @@
  33297. net->stats.rx_packets, net->stats.tx_packets,
  33298. net->stats.rx_errors, net->stats.tx_errors);
  33299. - /* to not race resume */
  33300. - pm = usb_autopm_get_interface(dev->intf);
  33301. /* allow minidriver to stop correctly (wireless devices to turn off
  33302. * radio etc) */
  33303. if (info->stop) {
  33304. @@ -817,9 +818,6 @@
  33305. dev->flags = 0;
  33306. del_timer_sync (&dev->delay);
  33307. tasklet_kill (&dev->bh);
  33308. - if (!pm)
  33309. - usb_autopm_put_interface(dev->intf);
  33310. -
  33311. if (info->manage_power &&
  33312. !test_and_clear_bit(EVENT_NO_RUNTIME_PM, &dev->flags))
  33313. info->manage_power(dev, 0);
  33314. @@ -1440,12 +1438,11 @@
  33315. /* restart RX again after disabling due to high error rate */
  33316. clear_bit(EVENT_RX_KILL, &dev->flags);
  33317. - /* waiting for all pending urbs to complete?
  33318. - * only then can we forgo submitting anew
  33319. - */
  33320. - if (waitqueue_active(&dev->wait)) {
  33321. - if (dev->txq.qlen + dev->rxq.qlen + dev->done.qlen == 0)
  33322. - wake_up_all(&dev->wait);
  33323. + // waiting for all pending urbs to complete?
  33324. + if (dev->wait) {
  33325. + if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
  33326. + wake_up (dev->wait);
  33327. + }
  33328. // or are we maybe short a few urbs?
  33329. } else if (netif_running (dev->net) &&
  33330. @@ -1584,7 +1581,6 @@
  33331. dev->driver_name = name;
  33332. dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
  33333. | NETIF_MSG_PROBE | NETIF_MSG_LINK);
  33334. - init_waitqueue_head(&dev->wait);
  33335. skb_queue_head_init (&dev->rxq);
  33336. skb_queue_head_init (&dev->txq);
  33337. skb_queue_head_init (&dev->done);
  33338. @@ -1796,10 +1792,9 @@
  33339. spin_unlock_irq(&dev->txq.lock);
  33340. if (test_bit(EVENT_DEV_OPEN, &dev->flags)) {
  33341. - /* handle remote wakeup ASAP
  33342. - * we cannot race against stop
  33343. - */
  33344. - if (netif_device_present(dev->net) &&
  33345. + /* handle remote wakeup ASAP */
  33346. + if (!dev->wait &&
  33347. + netif_device_present(dev->net) &&
  33348. !timer_pending(&dev->delay) &&
  33349. !test_bit(EVENT_RX_HALT, &dev->flags))
  33350. rx_alloc_submit(dev, GFP_NOIO);
  33351. diff -Nur linux-3.12.18/drivers/net/vxlan.c linux-rpi/drivers/net/vxlan.c
  33352. --- linux-3.12.18/drivers/net/vxlan.c 2014-04-18 11:14:28.000000000 +0200
  33353. +++ linux-rpi/drivers/net/vxlan.c 2014-04-24 16:04:37.631103100 +0200
  33354. @@ -781,9 +781,6 @@
  33355. if (err)
  33356. return err;
  33357. - if (vxlan->default_dst.remote_ip.sa.sa_family != ip.sa.sa_family)
  33358. - return -EAFNOSUPPORT;
  33359. -
  33360. spin_lock_bh(&vxlan->hash_lock);
  33361. err = vxlan_fdb_create(vxlan, addr, &ip, ndm->ndm_state, flags,
  33362. port, vni, ifindex, ndm->ndm_flags);
  33363. @@ -1215,9 +1212,6 @@
  33364. neigh_release(n);
  33365. - if (reply == NULL)
  33366. - goto out;
  33367. -
  33368. skb_reset_mac_header(reply);
  33369. __skb_pull(reply, skb_network_offset(reply));
  33370. reply->ip_summed = CHECKSUM_UNNECESSARY;
  33371. @@ -1239,103 +1233,15 @@
  33372. }
  33373. #if IS_ENABLED(CONFIG_IPV6)
  33374. -
  33375. -static struct sk_buff *vxlan_na_create(struct sk_buff *request,
  33376. - struct neighbour *n, bool isrouter)
  33377. -{
  33378. - struct net_device *dev = request->dev;
  33379. - struct sk_buff *reply;
  33380. - struct nd_msg *ns, *na;
  33381. - struct ipv6hdr *pip6;
  33382. - u8 *daddr;
  33383. - int na_olen = 8; /* opt hdr + ETH_ALEN for target */
  33384. - int ns_olen;
  33385. - int i, len;
  33386. -
  33387. - if (dev == NULL)
  33388. - return NULL;
  33389. -
  33390. - len = LL_RESERVED_SPACE(dev) + sizeof(struct ipv6hdr) +
  33391. - sizeof(*na) + na_olen + dev->needed_tailroom;
  33392. - reply = alloc_skb(len, GFP_ATOMIC);
  33393. - if (reply == NULL)
  33394. - return NULL;
  33395. -
  33396. - reply->protocol = htons(ETH_P_IPV6);
  33397. - reply->dev = dev;
  33398. - skb_reserve(reply, LL_RESERVED_SPACE(request->dev));
  33399. - skb_push(reply, sizeof(struct ethhdr));
  33400. - skb_set_mac_header(reply, 0);
  33401. -
  33402. - ns = (struct nd_msg *)skb_transport_header(request);
  33403. -
  33404. - daddr = eth_hdr(request)->h_source;
  33405. - ns_olen = request->len - skb_transport_offset(request) - sizeof(*ns);
  33406. - for (i = 0; i < ns_olen-1; i += (ns->opt[i+1]<<3)) {
  33407. - if (ns->opt[i] == ND_OPT_SOURCE_LL_ADDR) {
  33408. - daddr = ns->opt + i + sizeof(struct nd_opt_hdr);
  33409. - break;
  33410. - }
  33411. - }
  33412. -
  33413. - /* Ethernet header */
  33414. - memcpy(eth_hdr(reply)->h_dest, daddr, ETH_ALEN);
  33415. - memcpy(eth_hdr(reply)->h_source, n->ha, ETH_ALEN);
  33416. - eth_hdr(reply)->h_proto = htons(ETH_P_IPV6);
  33417. - reply->protocol = htons(ETH_P_IPV6);
  33418. -
  33419. - skb_pull(reply, sizeof(struct ethhdr));
  33420. - skb_set_network_header(reply, 0);
  33421. - skb_put(reply, sizeof(struct ipv6hdr));
  33422. -
  33423. - /* IPv6 header */
  33424. -
  33425. - pip6 = ipv6_hdr(reply);
  33426. - memset(pip6, 0, sizeof(struct ipv6hdr));
  33427. - pip6->version = 6;
  33428. - pip6->priority = ipv6_hdr(request)->priority;
  33429. - pip6->nexthdr = IPPROTO_ICMPV6;
  33430. - pip6->hop_limit = 255;
  33431. - pip6->daddr = ipv6_hdr(request)->saddr;
  33432. - pip6->saddr = *(struct in6_addr *)n->primary_key;
  33433. -
  33434. - skb_pull(reply, sizeof(struct ipv6hdr));
  33435. - skb_set_transport_header(reply, 0);
  33436. -
  33437. - na = (struct nd_msg *)skb_put(reply, sizeof(*na) + na_olen);
  33438. -
  33439. - /* Neighbor Advertisement */
  33440. - memset(na, 0, sizeof(*na)+na_olen);
  33441. - na->icmph.icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT;
  33442. - na->icmph.icmp6_router = isrouter;
  33443. - na->icmph.icmp6_override = 1;
  33444. - na->icmph.icmp6_solicited = 1;
  33445. - na->target = ns->target;
  33446. - memcpy(&na->opt[2], n->ha, ETH_ALEN);
  33447. - na->opt[0] = ND_OPT_TARGET_LL_ADDR;
  33448. - na->opt[1] = na_olen >> 3;
  33449. -
  33450. - na->icmph.icmp6_cksum = csum_ipv6_magic(&pip6->saddr,
  33451. - &pip6->daddr, sizeof(*na)+na_olen, IPPROTO_ICMPV6,
  33452. - csum_partial(na, sizeof(*na)+na_olen, 0));
  33453. -
  33454. - pip6->payload_len = htons(sizeof(*na)+na_olen);
  33455. -
  33456. - skb_push(reply, sizeof(struct ipv6hdr));
  33457. -
  33458. - reply->ip_summed = CHECKSUM_UNNECESSARY;
  33459. -
  33460. - return reply;
  33461. -}
  33462. -
  33463. static int neigh_reduce(struct net_device *dev, struct sk_buff *skb)
  33464. {
  33465. struct vxlan_dev *vxlan = netdev_priv(dev);
  33466. - struct nd_msg *msg;
  33467. + struct neighbour *n;
  33468. + union vxlan_addr ipa;
  33469. const struct ipv6hdr *iphdr;
  33470. const struct in6_addr *saddr, *daddr;
  33471. - struct neighbour *n;
  33472. - struct inet6_dev *in6_dev;
  33473. + struct nd_msg *msg;
  33474. + struct inet6_dev *in6_dev = NULL;
  33475. in6_dev = __in6_dev_get(dev);
  33476. if (!in6_dev)
  33477. @@ -1348,20 +1254,19 @@
  33478. saddr = &iphdr->saddr;
  33479. daddr = &iphdr->daddr;
  33480. + if (ipv6_addr_loopback(daddr) ||
  33481. + ipv6_addr_is_multicast(daddr))
  33482. + goto out;
  33483. +
  33484. msg = (struct nd_msg *)skb_transport_header(skb);
  33485. if (msg->icmph.icmp6_code != 0 ||
  33486. msg->icmph.icmp6_type != NDISC_NEIGHBOUR_SOLICITATION)
  33487. goto out;
  33488. - if (ipv6_addr_loopback(daddr) ||
  33489. - ipv6_addr_is_multicast(&msg->target))
  33490. - goto out;
  33491. -
  33492. - n = neigh_lookup(ipv6_stub->nd_tbl, &msg->target, dev);
  33493. + n = neigh_lookup(ipv6_stub->nd_tbl, daddr, dev);
  33494. if (n) {
  33495. struct vxlan_fdb *f;
  33496. - struct sk_buff *reply;
  33497. if (!(n->nud_state & NUD_CONNECTED)) {
  33498. neigh_release(n);
  33499. @@ -1375,23 +1280,13 @@
  33500. goto out;
  33501. }
  33502. - reply = vxlan_na_create(skb, n,
  33503. - !!(f ? f->flags & NTF_ROUTER : 0));
  33504. -
  33505. + ipv6_stub->ndisc_send_na(dev, n, saddr, &msg->target,
  33506. + !!in6_dev->cnf.forwarding,
  33507. + true, false, false);
  33508. neigh_release(n);
  33509. -
  33510. - if (reply == NULL)
  33511. - goto out;
  33512. -
  33513. - if (netif_rx_ni(reply) == NET_RX_DROP)
  33514. - dev->stats.rx_dropped++;
  33515. -
  33516. } else if (vxlan->flags & VXLAN_F_L3MISS) {
  33517. - union vxlan_addr ipa = {
  33518. - .sin6.sin6_addr = msg->target,
  33519. - .sa.sa_family = AF_INET6,
  33520. - };
  33521. -
  33522. + ipa.sin6.sin6_addr = *daddr;
  33523. + ipa.sa.sa_family = AF_INET6;
  33524. vxlan_ip_miss(dev, &ipa);
  33525. }
  33526. @@ -2488,10 +2383,9 @@
  33527. vni = nla_get_u32(data[IFLA_VXLAN_ID]);
  33528. dst->remote_vni = vni;
  33529. - /* Unless IPv6 is explicitly requested, assume IPv4 */
  33530. - dst->remote_ip.sa.sa_family = AF_INET;
  33531. if (data[IFLA_VXLAN_GROUP]) {
  33532. dst->remote_ip.sin.sin_addr.s_addr = nla_get_be32(data[IFLA_VXLAN_GROUP]);
  33533. + dst->remote_ip.sa.sa_family = AF_INET;
  33534. } else if (data[IFLA_VXLAN_GROUP6]) {
  33535. if (!IS_ENABLED(CONFIG_IPV6))
  33536. return -EPFNOSUPPORT;
  33537. diff -Nur linux-3.12.18/drivers/net/xen-netback/common.h linux-rpi/drivers/net/xen-netback/common.h
  33538. --- linux-3.12.18/drivers/net/xen-netback/common.h 2014-04-18 11:14:28.000000000 +0200
  33539. +++ linux-rpi/drivers/net/xen-netback/common.h 2014-04-24 16:04:37.763104376 +0200
  33540. @@ -102,11 +102,6 @@
  33541. domid_t domid;
  33542. unsigned int handle;
  33543. - /* Is this interface disabled? True when backend discovers
  33544. - * frontend is rogue.
  33545. - */
  33546. - bool disabled;
  33547. -
  33548. /* Use NAPI for guest TX */
  33549. struct napi_struct napi;
  33550. /* When feature-split-event-channels = 0, tx_irq = rx_irq. */
  33551. diff -Nur linux-3.12.18/drivers/net/xen-netback/interface.c linux-rpi/drivers/net/xen-netback/interface.c
  33552. --- linux-3.12.18/drivers/net/xen-netback/interface.c 2014-04-18 11:14:28.000000000 +0200
  33553. +++ linux-rpi/drivers/net/xen-netback/interface.c 2014-04-24 16:04:37.763104376 +0200
  33554. @@ -66,15 +66,6 @@
  33555. struct xenvif *vif = container_of(napi, struct xenvif, napi);
  33556. int work_done;
  33557. - /* This vif is rogue, we pretend we've there is nothing to do
  33558. - * for this vif to deschedule it from NAPI. But this interface
  33559. - * will be turned off in thread context later.
  33560. - */
  33561. - if (unlikely(vif->disabled)) {
  33562. - napi_complete(napi);
  33563. - return 0;
  33564. - }
  33565. -
  33566. work_done = xenvif_tx_action(vif, budget);
  33567. if (work_done < budget) {
  33568. @@ -318,8 +309,6 @@
  33569. vif->csum = 1;
  33570. vif->dev = dev;
  33571. - vif->disabled = false;
  33572. -
  33573. vif->credit_bytes = vif->remaining_credit = ~0UL;
  33574. vif->credit_usec = 0UL;
  33575. init_timer(&vif->credit_timeout);
  33576. diff -Nur linux-3.12.18/drivers/net/xen-netback/netback.c linux-rpi/drivers/net/xen-netback/netback.c
  33577. --- linux-3.12.18/drivers/net/xen-netback/netback.c 2014-04-18 11:14:28.000000000 +0200
  33578. +++ linux-rpi/drivers/net/xen-netback/netback.c 2014-04-24 16:04:37.763104376 +0200
  33579. @@ -206,8 +206,8 @@
  33580. * into multiple copies tend to give large frags their
  33581. * own buffers as before.
  33582. */
  33583. - BUG_ON(size > MAX_BUFFER_OFFSET);
  33584. - if ((offset + size > MAX_BUFFER_OFFSET) && offset && !head)
  33585. + if ((offset + size > MAX_BUFFER_OFFSET) &&
  33586. + (size <= MAX_BUFFER_OFFSET) && offset && !head)
  33587. return true;
  33588. return false;
  33589. @@ -731,8 +731,7 @@
  33590. static void xenvif_fatal_tx_err(struct xenvif *vif)
  33591. {
  33592. netdev_err(vif->dev, "fatal error; disabling device\n");
  33593. - vif->disabled = true;
  33594. - xenvif_kick_thread(vif);
  33595. + xenvif_carrier_off(vif);
  33596. }
  33597. static int xenvif_count_requests(struct xenvif *vif,
  33598. @@ -1243,7 +1242,7 @@
  33599. vif->tx.sring->req_prod, vif->tx.req_cons,
  33600. XEN_NETIF_TX_RING_SIZE);
  33601. xenvif_fatal_tx_err(vif);
  33602. - break;
  33603. + continue;
  33604. }
  33605. RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx, work_to_do);
  33606. @@ -1643,18 +1642,7 @@
  33607. while (!kthread_should_stop()) {
  33608. wait_event_interruptible(vif->wq,
  33609. rx_work_todo(vif) ||
  33610. - vif->disabled ||
  33611. kthread_should_stop());
  33612. -
  33613. - /* This frontend is found to be rogue, disable it in
  33614. - * kthread context. Currently this is only set when
  33615. - * netback finds out frontend sends malformed packet,
  33616. - * but we cannot disable the interface in softirq
  33617. - * context so we defer it here.
  33618. - */
  33619. - if (unlikely(vif->disabled && netif_carrier_ok(vif->dev)))
  33620. - xenvif_carrier_off(vif);
  33621. -
  33622. if (kthread_should_stop())
  33623. break;
  33624. diff -Nur linux-3.12.18/drivers/pci/host/pci-mvebu.c linux-rpi/drivers/pci/host/pci-mvebu.c
  33625. --- linux-3.12.18/drivers/pci/host/pci-mvebu.c 2014-04-18 11:14:28.000000000 +0200
  33626. +++ linux-rpi/drivers/pci/host/pci-mvebu.c 2014-04-24 16:04:37.847105188 +0200
  33627. @@ -866,23 +866,11 @@
  33628. continue;
  33629. }
  33630. - port->clk = of_clk_get_by_name(child, NULL);
  33631. - if (IS_ERR(port->clk)) {
  33632. - dev_err(&pdev->dev, "PCIe%d.%d: cannot get clock\n",
  33633. - port->port, port->lane);
  33634. - continue;
  33635. - }
  33636. -
  33637. - ret = clk_prepare_enable(port->clk);
  33638. - if (ret)
  33639. - continue;
  33640. -
  33641. port->base = mvebu_pcie_map_registers(pdev, child, port);
  33642. if (IS_ERR(port->base)) {
  33643. dev_err(&pdev->dev, "PCIe%d.%d: cannot map registers\n",
  33644. port->port, port->lane);
  33645. port->base = NULL;
  33646. - clk_disable_unprepare(port->clk);
  33647. continue;
  33648. }
  33649. @@ -898,9 +886,22 @@
  33650. port->port, port->lane);
  33651. }
  33652. + port->clk = of_clk_get_by_name(child, NULL);
  33653. + if (IS_ERR(port->clk)) {
  33654. + dev_err(&pdev->dev, "PCIe%d.%d: cannot get clock\n",
  33655. + port->port, port->lane);
  33656. + iounmap(port->base);
  33657. + port->haslink = 0;
  33658. + continue;
  33659. + }
  33660. +
  33661. port->dn = child;
  33662. +
  33663. + clk_prepare_enable(port->clk);
  33664. spin_lock_init(&port->conf_lock);
  33665. +
  33666. mvebu_sw_pci_bridge_init(port);
  33667. +
  33668. i++;
  33669. }
  33670. diff -Nur linux-3.12.18/drivers/spi/Kconfig linux-rpi/drivers/spi/Kconfig
  33671. --- linux-3.12.18/drivers/spi/Kconfig 2014-04-18 11:14:28.000000000 +0200
  33672. +++ linux-rpi/drivers/spi/Kconfig 2014-04-24 16:04:38.875115127 +0200
  33673. @@ -85,6 +85,14 @@
  33674. is for the regular SPI controller. Slave mode operation is not also
  33675. not supported.
  33676. +config SPI_BCM2708
  33677. + tristate "BCM2708 SPI controller driver (SPI0)"
  33678. + depends on MACH_BCM2708
  33679. + help
  33680. + This selects a driver for the Broadcom BCM2708 SPI master (SPI0). This
  33681. + driver is not compatible with the "Universal SPI Master" or the SPI slave
  33682. + device.
  33683. +
  33684. config SPI_BFIN5XX
  33685. tristate "SPI controller driver for ADI Blackfin5xx"
  33686. depends on BLACKFIN && !BF60x
  33687. diff -Nur linux-3.12.18/drivers/spi/Makefile linux-rpi/drivers/spi/Makefile
  33688. --- linux-3.12.18/drivers/spi/Makefile 2014-04-18 11:14:28.000000000 +0200
  33689. +++ linux-rpi/drivers/spi/Makefile 2014-04-24 16:04:38.875115127 +0200
  33690. @@ -18,6 +18,7 @@
  33691. obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o
  33692. obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
  33693. obj-$(CONFIG_SPI_BFIN_V3) += spi-bfin-v3.o
  33694. +obj-$(CONFIG_SPI_BCM2708) += spi-bcm2708.o
  33695. obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
  33696. obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
  33697. obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
  33698. diff -Nur linux-3.12.18/drivers/spi/spi-bcm2708.c linux-rpi/drivers/spi/spi-bcm2708.c
  33699. --- linux-3.12.18/drivers/spi/spi-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  33700. +++ linux-rpi/drivers/spi/spi-bcm2708.c 2014-04-24 15:35:03.781561409 +0200
  33701. @@ -0,0 +1,626 @@
  33702. +/*
  33703. + * Driver for Broadcom BCM2708 SPI Controllers
  33704. + *
  33705. + * Copyright (C) 2012 Chris Boot
  33706. + *
  33707. + * This driver is inspired by:
  33708. + * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
  33709. + * spi-atmel.c, Copyright (C) 2006 Atmel Corporation
  33710. + *
  33711. + * This program is free software; you can redistribute it and/or modify
  33712. + * it under the terms of the GNU General Public License as published by
  33713. + * the Free Software Foundation; either version 2 of the License, or
  33714. + * (at your option) any later version.
  33715. + *
  33716. + * This program is distributed in the hope that it will be useful,
  33717. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33718. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33719. + * GNU General Public License for more details.
  33720. + *
  33721. + * You should have received a copy of the GNU General Public License
  33722. + * along with this program; if not, write to the Free Software
  33723. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  33724. + */
  33725. +
  33726. +#include <linux/kernel.h>
  33727. +#include <linux/module.h>
  33728. +#include <linux/spinlock.h>
  33729. +#include <linux/clk.h>
  33730. +#include <linux/err.h>
  33731. +#include <linux/platform_device.h>
  33732. +#include <linux/io.h>
  33733. +#include <linux/spi/spi.h>
  33734. +#include <linux/interrupt.h>
  33735. +#include <linux/delay.h>
  33736. +#include <linux/log2.h>
  33737. +#include <linux/sched.h>
  33738. +#include <linux/wait.h>
  33739. +
  33740. +/* SPI register offsets */
  33741. +#define SPI_CS 0x00
  33742. +#define SPI_FIFO 0x04
  33743. +#define SPI_CLK 0x08
  33744. +#define SPI_DLEN 0x0c
  33745. +#define SPI_LTOH 0x10
  33746. +#define SPI_DC 0x14
  33747. +
  33748. +/* Bitfields in CS */
  33749. +#define SPI_CS_LEN_LONG 0x02000000
  33750. +#define SPI_CS_DMA_LEN 0x01000000
  33751. +#define SPI_CS_CSPOL2 0x00800000
  33752. +#define SPI_CS_CSPOL1 0x00400000
  33753. +#define SPI_CS_CSPOL0 0x00200000
  33754. +#define SPI_CS_RXF 0x00100000
  33755. +#define SPI_CS_RXR 0x00080000
  33756. +#define SPI_CS_TXD 0x00040000
  33757. +#define SPI_CS_RXD 0x00020000
  33758. +#define SPI_CS_DONE 0x00010000
  33759. +#define SPI_CS_LEN 0x00002000
  33760. +#define SPI_CS_REN 0x00001000
  33761. +#define SPI_CS_ADCS 0x00000800
  33762. +#define SPI_CS_INTR 0x00000400
  33763. +#define SPI_CS_INTD 0x00000200
  33764. +#define SPI_CS_DMAEN 0x00000100
  33765. +#define SPI_CS_TA 0x00000080
  33766. +#define SPI_CS_CSPOL 0x00000040
  33767. +#define SPI_CS_CLEAR_RX 0x00000020
  33768. +#define SPI_CS_CLEAR_TX 0x00000010
  33769. +#define SPI_CS_CPOL 0x00000008
  33770. +#define SPI_CS_CPHA 0x00000004
  33771. +#define SPI_CS_CS_10 0x00000002
  33772. +#define SPI_CS_CS_01 0x00000001
  33773. +
  33774. +#define SPI_TIMEOUT_MS 150
  33775. +
  33776. +#define DRV_NAME "bcm2708_spi"
  33777. +
  33778. +struct bcm2708_spi {
  33779. + spinlock_t lock;
  33780. + void __iomem *base;
  33781. + int irq;
  33782. + struct clk *clk;
  33783. + bool stopping;
  33784. +
  33785. + struct list_head queue;
  33786. + struct workqueue_struct *workq;
  33787. + struct work_struct work;
  33788. + struct completion done;
  33789. +
  33790. + const u8 *tx_buf;
  33791. + u8 *rx_buf;
  33792. + int len;
  33793. +};
  33794. +
  33795. +struct bcm2708_spi_state {
  33796. + u32 cs;
  33797. + u16 cdiv;
  33798. +};
  33799. +
  33800. +/*
  33801. + * This function sets the ALT mode on the SPI pins so that we can use them with
  33802. + * the SPI hardware.
  33803. + *
  33804. + * FIXME: This is a hack. Use pinmux / pinctrl.
  33805. + */
  33806. +static void bcm2708_init_pinmode(void)
  33807. +{
  33808. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  33809. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  33810. +
  33811. + int pin;
  33812. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  33813. +
  33814. + /* SPI is on GPIO 7..11 */
  33815. + for (pin = 7; pin <= 11; pin++) {
  33816. + INP_GPIO(pin); /* set mode to GPIO input first */
  33817. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  33818. + }
  33819. +
  33820. + iounmap(gpio);
  33821. +
  33822. +#undef INP_GPIO
  33823. +#undef SET_GPIO_ALT
  33824. +}
  33825. +
  33826. +static inline u32 bcm2708_rd(struct bcm2708_spi *bs, unsigned reg)
  33827. +{
  33828. + return readl(bs->base + reg);
  33829. +}
  33830. +
  33831. +static inline void bcm2708_wr(struct bcm2708_spi *bs, unsigned reg, u32 val)
  33832. +{
  33833. + writel(val, bs->base + reg);
  33834. +}
  33835. +
  33836. +static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
  33837. +{
  33838. + u8 byte;
  33839. +
  33840. + while (len--) {
  33841. + byte = bcm2708_rd(bs, SPI_FIFO);
  33842. + if (bs->rx_buf)
  33843. + *bs->rx_buf++ = byte;
  33844. + }
  33845. +}
  33846. +
  33847. +static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
  33848. +{
  33849. + u8 byte;
  33850. + u16 val;
  33851. +
  33852. + if (len > bs->len)
  33853. + len = bs->len;
  33854. +
  33855. + if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
  33856. + /* LoSSI mode */
  33857. + if (unlikely(len % 2)) {
  33858. + printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
  33859. + bs->len = 0;
  33860. + return;
  33861. + }
  33862. + while (len) {
  33863. + if (bs->tx_buf) {
  33864. + val = *(const u16 *)bs->tx_buf;
  33865. + bs->tx_buf += 2;
  33866. + } else
  33867. + val = 0;
  33868. + bcm2708_wr(bs, SPI_FIFO, val);
  33869. + bs->len -= 2;
  33870. + len -= 2;
  33871. + }
  33872. + return;
  33873. + }
  33874. +
  33875. + while (len--) {
  33876. + byte = bs->tx_buf ? *bs->tx_buf++ : 0;
  33877. + bcm2708_wr(bs, SPI_FIFO, byte);
  33878. + bs->len--;
  33879. + }
  33880. +}
  33881. +
  33882. +static irqreturn_t bcm2708_spi_interrupt(int irq, void *dev_id)
  33883. +{
  33884. + struct spi_master *master = dev_id;
  33885. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  33886. + u32 cs;
  33887. +
  33888. + spin_lock(&bs->lock);
  33889. +
  33890. + cs = bcm2708_rd(bs, SPI_CS);
  33891. +
  33892. + if (cs & SPI_CS_DONE) {
  33893. + if (bs->len) { /* first interrupt in a transfer */
  33894. + /* fill the TX fifo with up to 16 bytes */
  33895. + bcm2708_wr_fifo(bs, 16);
  33896. + } else { /* transfer complete */
  33897. + /* disable interrupts */
  33898. + cs &= ~(SPI_CS_INTR | SPI_CS_INTD);
  33899. + bcm2708_wr(bs, SPI_CS, cs);
  33900. +
  33901. + /* drain RX FIFO */
  33902. + while (cs & SPI_CS_RXD) {
  33903. + bcm2708_rd_fifo(bs, 1);
  33904. + cs = bcm2708_rd(bs, SPI_CS);
  33905. + }
  33906. +
  33907. + /* wake up our bh */
  33908. + complete(&bs->done);
  33909. + }
  33910. + } else if (cs & SPI_CS_RXR) {
  33911. + /* read 12 bytes of data */
  33912. + bcm2708_rd_fifo(bs, 12);
  33913. +
  33914. + /* write up to 12 bytes */
  33915. + bcm2708_wr_fifo(bs, 12);
  33916. + }
  33917. +
  33918. + spin_unlock(&bs->lock);
  33919. +
  33920. + return IRQ_HANDLED;
  33921. +}
  33922. +
  33923. +static int bcm2708_setup_state(struct spi_master *master,
  33924. + struct device *dev, struct bcm2708_spi_state *state,
  33925. + u32 hz, u8 csel, u8 mode, u8 bpw)
  33926. +{
  33927. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  33928. + int cdiv;
  33929. + unsigned long bus_hz;
  33930. + u32 cs = 0;
  33931. +
  33932. + bus_hz = clk_get_rate(bs->clk);
  33933. +
  33934. + if (hz >= bus_hz) {
  33935. + cdiv = 2; /* bus_hz / 2 is as fast as we can go */
  33936. + } else if (hz) {
  33937. + cdiv = DIV_ROUND_UP(bus_hz, hz);
  33938. +
  33939. + /* CDIV must be a power of 2, so round up */
  33940. + cdiv = roundup_pow_of_two(cdiv);
  33941. +
  33942. + if (cdiv > 65536) {
  33943. + dev_dbg(dev,
  33944. + "setup: %d Hz too slow, cdiv %u; min %ld Hz\n",
  33945. + hz, cdiv, bus_hz / 65536);
  33946. + return -EINVAL;
  33947. + } else if (cdiv == 65536) {
  33948. + cdiv = 0;
  33949. + } else if (cdiv == 1) {
  33950. + cdiv = 2; /* 1 gets rounded down to 0; == 65536 */
  33951. + }
  33952. + } else {
  33953. + cdiv = 0;
  33954. + }
  33955. +
  33956. + switch (bpw) {
  33957. + case 8:
  33958. + break;
  33959. + case 9:
  33960. + /* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
  33961. + cs |= SPI_CS_LEN;
  33962. + break;
  33963. + default:
  33964. + dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
  33965. + bpw);
  33966. + return -EINVAL;
  33967. + }
  33968. +
  33969. + if (mode & SPI_CPOL)
  33970. + cs |= SPI_CS_CPOL;
  33971. + if (mode & SPI_CPHA)
  33972. + cs |= SPI_CS_CPHA;
  33973. +
  33974. + if (!(mode & SPI_NO_CS)) {
  33975. + if (mode & SPI_CS_HIGH) {
  33976. + cs |= SPI_CS_CSPOL;
  33977. + cs |= SPI_CS_CSPOL0 << csel;
  33978. + }
  33979. +
  33980. + cs |= csel;
  33981. + } else {
  33982. + cs |= SPI_CS_CS_10 | SPI_CS_CS_01;
  33983. + }
  33984. +
  33985. + if (state) {
  33986. + state->cs = cs;
  33987. + state->cdiv = cdiv;
  33988. + dev_dbg(dev, "setup: want %d Hz; "
  33989. + "bus_hz=%lu / cdiv=%u == %lu Hz; "
  33990. + "mode %u: cs 0x%08X\n",
  33991. + hz, bus_hz, cdiv, bus_hz/cdiv, mode, cs);
  33992. + }
  33993. +
  33994. + return 0;
  33995. +}
  33996. +
  33997. +static int bcm2708_process_transfer(struct bcm2708_spi *bs,
  33998. + struct spi_message *msg, struct spi_transfer *xfer)
  33999. +{
  34000. + struct spi_device *spi = msg->spi;
  34001. + struct bcm2708_spi_state state, *stp;
  34002. + int ret;
  34003. + u32 cs;
  34004. +
  34005. + if (bs->stopping)
  34006. + return -ESHUTDOWN;
  34007. +
  34008. + if (xfer->bits_per_word || xfer->speed_hz) {
  34009. + ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
  34010. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  34011. + spi->chip_select, spi->mode,
  34012. + xfer->bits_per_word ? xfer->bits_per_word :
  34013. + spi->bits_per_word);
  34014. + if (ret)
  34015. + return ret;
  34016. +
  34017. + stp = &state;
  34018. + } else {
  34019. + stp = spi->controller_state;
  34020. + }
  34021. +
  34022. + INIT_COMPLETION(bs->done);
  34023. + bs->tx_buf = xfer->tx_buf;
  34024. + bs->rx_buf = xfer->rx_buf;
  34025. + bs->len = xfer->len;
  34026. +
  34027. + cs = stp->cs | SPI_CS_INTR | SPI_CS_INTD | SPI_CS_TA;
  34028. +
  34029. + bcm2708_wr(bs, SPI_CLK, stp->cdiv);
  34030. + bcm2708_wr(bs, SPI_CS, cs);
  34031. +
  34032. + ret = wait_for_completion_timeout(&bs->done,
  34033. + msecs_to_jiffies(SPI_TIMEOUT_MS));
  34034. + if (ret == 0) {
  34035. + dev_err(&spi->dev, "transfer timed out\n");
  34036. + return -ETIMEDOUT;
  34037. + }
  34038. +
  34039. + if (xfer->delay_usecs)
  34040. + udelay(xfer->delay_usecs);
  34041. +
  34042. + if (list_is_last(&xfer->transfer_list, &msg->transfers) ||
  34043. + xfer->cs_change) {
  34044. + /* clear TA and interrupt flags */
  34045. + bcm2708_wr(bs, SPI_CS, stp->cs);
  34046. + }
  34047. +
  34048. + msg->actual_length += (xfer->len - bs->len);
  34049. +
  34050. + return 0;
  34051. +}
  34052. +
  34053. +static void bcm2708_work(struct work_struct *work)
  34054. +{
  34055. + struct bcm2708_spi *bs = container_of(work, struct bcm2708_spi, work);
  34056. + unsigned long flags;
  34057. + struct spi_message *msg;
  34058. + struct spi_transfer *xfer;
  34059. + int status = 0;
  34060. +
  34061. + spin_lock_irqsave(&bs->lock, flags);
  34062. + while (!list_empty(&bs->queue)) {
  34063. + msg = list_first_entry(&bs->queue, struct spi_message, queue);
  34064. + list_del_init(&msg->queue);
  34065. + spin_unlock_irqrestore(&bs->lock, flags);
  34066. +
  34067. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  34068. + status = bcm2708_process_transfer(bs, msg, xfer);
  34069. + if (status)
  34070. + break;
  34071. + }
  34072. +
  34073. + msg->status = status;
  34074. + msg->complete(msg->context);
  34075. +
  34076. + spin_lock_irqsave(&bs->lock, flags);
  34077. + }
  34078. + spin_unlock_irqrestore(&bs->lock, flags);
  34079. +}
  34080. +
  34081. +static int bcm2708_spi_setup(struct spi_device *spi)
  34082. +{
  34083. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  34084. + struct bcm2708_spi_state *state;
  34085. + int ret;
  34086. +
  34087. + if (bs->stopping)
  34088. + return -ESHUTDOWN;
  34089. +
  34090. + if (!(spi->mode & SPI_NO_CS) &&
  34091. + (spi->chip_select > spi->master->num_chipselect)) {
  34092. + dev_dbg(&spi->dev,
  34093. + "setup: invalid chipselect %u (%u defined)\n",
  34094. + spi->chip_select, spi->master->num_chipselect);
  34095. + return -EINVAL;
  34096. + }
  34097. +
  34098. + state = spi->controller_state;
  34099. + if (!state) {
  34100. + state = kzalloc(sizeof(*state), GFP_KERNEL);
  34101. + if (!state)
  34102. + return -ENOMEM;
  34103. +
  34104. + spi->controller_state = state;
  34105. + }
  34106. +
  34107. + ret = bcm2708_setup_state(spi->master, &spi->dev, state,
  34108. + spi->max_speed_hz, spi->chip_select, spi->mode,
  34109. + spi->bits_per_word);
  34110. + if (ret < 0) {
  34111. + kfree(state);
  34112. + spi->controller_state = NULL;
  34113. + return ret;
  34114. + }
  34115. +
  34116. + dev_dbg(&spi->dev,
  34117. + "setup: cd %d: %d Hz, bpw %u, mode 0x%x -> CS=%08x CDIV=%04x\n",
  34118. + spi->chip_select, spi->max_speed_hz, spi->bits_per_word,
  34119. + spi->mode, state->cs, state->cdiv);
  34120. +
  34121. + return 0;
  34122. +}
  34123. +
  34124. +static int bcm2708_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  34125. +{
  34126. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  34127. + struct spi_transfer *xfer;
  34128. + int ret;
  34129. + unsigned long flags;
  34130. +
  34131. + if (unlikely(list_empty(&msg->transfers)))
  34132. + return -EINVAL;
  34133. +
  34134. + if (bs->stopping)
  34135. + return -ESHUTDOWN;
  34136. +
  34137. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  34138. + if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  34139. + dev_dbg(&spi->dev, "missing rx or tx buf\n");
  34140. + return -EINVAL;
  34141. + }
  34142. +
  34143. + if (!xfer->bits_per_word || xfer->speed_hz)
  34144. + continue;
  34145. +
  34146. + ret = bcm2708_setup_state(spi->master, &spi->dev, NULL,
  34147. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  34148. + spi->chip_select, spi->mode,
  34149. + xfer->bits_per_word ? xfer->bits_per_word :
  34150. + spi->bits_per_word);
  34151. + if (ret)
  34152. + return ret;
  34153. + }
  34154. +
  34155. + msg->status = -EINPROGRESS;
  34156. + msg->actual_length = 0;
  34157. +
  34158. + spin_lock_irqsave(&bs->lock, flags);
  34159. + list_add_tail(&msg->queue, &bs->queue);
  34160. + queue_work(bs->workq, &bs->work);
  34161. + spin_unlock_irqrestore(&bs->lock, flags);
  34162. +
  34163. + return 0;
  34164. +}
  34165. +
  34166. +static void bcm2708_spi_cleanup(struct spi_device *spi)
  34167. +{
  34168. + if (spi->controller_state) {
  34169. + kfree(spi->controller_state);
  34170. + spi->controller_state = NULL;
  34171. + }
  34172. +}
  34173. +
  34174. +static int bcm2708_spi_probe(struct platform_device *pdev)
  34175. +{
  34176. + struct resource *regs;
  34177. + int irq, err = -ENOMEM;
  34178. + struct clk *clk;
  34179. + struct spi_master *master;
  34180. + struct bcm2708_spi *bs;
  34181. +
  34182. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  34183. + if (!regs) {
  34184. + dev_err(&pdev->dev, "could not get IO memory\n");
  34185. + return -ENXIO;
  34186. + }
  34187. +
  34188. + irq = platform_get_irq(pdev, 0);
  34189. + if (irq < 0) {
  34190. + dev_err(&pdev->dev, "could not get IRQ\n");
  34191. + return irq;
  34192. + }
  34193. +
  34194. + clk = clk_get(&pdev->dev, NULL);
  34195. + if (IS_ERR(clk)) {
  34196. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  34197. + return PTR_ERR(clk);
  34198. + }
  34199. +
  34200. + bcm2708_init_pinmode();
  34201. +
  34202. + master = spi_alloc_master(&pdev->dev, sizeof(*bs));
  34203. + if (!master) {
  34204. + dev_err(&pdev->dev, "spi_alloc_master() failed\n");
  34205. + goto out_clk_put;
  34206. + }
  34207. +
  34208. + /* the spi->mode bits understood by this driver: */
  34209. + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
  34210. +
  34211. + master->bus_num = pdev->id;
  34212. + master->num_chipselect = 3;
  34213. + master->setup = bcm2708_spi_setup;
  34214. + master->transfer = bcm2708_spi_transfer;
  34215. + master->cleanup = bcm2708_spi_cleanup;
  34216. + platform_set_drvdata(pdev, master);
  34217. +
  34218. + bs = spi_master_get_devdata(master);
  34219. +
  34220. + spin_lock_init(&bs->lock);
  34221. + INIT_LIST_HEAD(&bs->queue);
  34222. + init_completion(&bs->done);
  34223. + INIT_WORK(&bs->work, bcm2708_work);
  34224. +
  34225. + bs->base = ioremap(regs->start, resource_size(regs));
  34226. + if (!bs->base) {
  34227. + dev_err(&pdev->dev, "could not remap memory\n");
  34228. + goto out_master_put;
  34229. + }
  34230. +
  34231. + bs->workq = create_singlethread_workqueue(dev_name(&pdev->dev));
  34232. + if (!bs->workq) {
  34233. + dev_err(&pdev->dev, "could not create workqueue\n");
  34234. + goto out_iounmap;
  34235. + }
  34236. +
  34237. + bs->irq = irq;
  34238. + bs->clk = clk;
  34239. + bs->stopping = false;
  34240. +
  34241. + err = request_irq(irq, bcm2708_spi_interrupt, 0, dev_name(&pdev->dev),
  34242. + master);
  34243. + if (err) {
  34244. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  34245. + goto out_workqueue;
  34246. + }
  34247. +
  34248. + /* initialise the hardware */
  34249. + clk_enable(clk);
  34250. + bcm2708_wr(bs, SPI_CS, SPI_CS_REN | SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  34251. +
  34252. + err = spi_register_master(master);
  34253. + if (err) {
  34254. + dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
  34255. + goto out_free_irq;
  34256. + }
  34257. +
  34258. + dev_info(&pdev->dev, "SPI Controller at 0x%08lx (irq %d)\n",
  34259. + (unsigned long)regs->start, irq);
  34260. +
  34261. + return 0;
  34262. +
  34263. +out_free_irq:
  34264. + free_irq(bs->irq, master);
  34265. +out_workqueue:
  34266. + destroy_workqueue(bs->workq);
  34267. +out_iounmap:
  34268. + iounmap(bs->base);
  34269. +out_master_put:
  34270. + spi_master_put(master);
  34271. +out_clk_put:
  34272. + clk_put(clk);
  34273. + return err;
  34274. +}
  34275. +
  34276. +static int bcm2708_spi_remove(struct platform_device *pdev)
  34277. +{
  34278. + struct spi_master *master = platform_get_drvdata(pdev);
  34279. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  34280. +
  34281. + /* reset the hardware and block queue progress */
  34282. + spin_lock_irq(&bs->lock);
  34283. + bs->stopping = true;
  34284. + bcm2708_wr(bs, SPI_CS, SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  34285. + spin_unlock_irq(&bs->lock);
  34286. +
  34287. + flush_work_sync(&bs->work);
  34288. +
  34289. + clk_disable(bs->clk);
  34290. + clk_put(bs->clk);
  34291. + free_irq(bs->irq, master);
  34292. + iounmap(bs->base);
  34293. +
  34294. + spi_unregister_master(master);
  34295. +
  34296. + return 0;
  34297. +}
  34298. +
  34299. +static struct platform_driver bcm2708_spi_driver = {
  34300. + .driver = {
  34301. + .name = DRV_NAME,
  34302. + .owner = THIS_MODULE,
  34303. + },
  34304. + .probe = bcm2708_spi_probe,
  34305. + .remove = bcm2708_spi_remove,
  34306. +};
  34307. +
  34308. +
  34309. +static int __init bcm2708_spi_init(void)
  34310. +{
  34311. + return platform_driver_probe(&bcm2708_spi_driver, bcm2708_spi_probe);
  34312. +}
  34313. +module_init(bcm2708_spi_init);
  34314. +
  34315. +static void __exit bcm2708_spi_exit(void)
  34316. +{
  34317. + platform_driver_unregister(&bcm2708_spi_driver);
  34318. +}
  34319. +module_exit(bcm2708_spi_exit);
  34320. +
  34321. +
  34322. +//module_platform_driver(bcm2708_spi_driver);
  34323. +
  34324. +MODULE_DESCRIPTION("SPI controller driver for Broadcom BCM2708");
  34325. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  34326. +MODULE_LICENSE("GPL v2");
  34327. +MODULE_ALIAS("platform:" DRV_NAME);
  34328. diff -Nur linux-3.12.18/drivers/staging/media/lirc/Kconfig linux-rpi/drivers/staging/media/lirc/Kconfig
  34329. --- linux-3.12.18/drivers/staging/media/lirc/Kconfig 2014-04-18 11:14:28.000000000 +0200
  34330. +++ linux-rpi/drivers/staging/media/lirc/Kconfig 2014-04-24 15:35:03.925563013 +0200
  34331. @@ -38,6 +38,12 @@
  34332. help
  34333. Driver for Homebrew Parallel Port Receivers
  34334. +config LIRC_RPI
  34335. + tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
  34336. + depends on LIRC
  34337. + help
  34338. + Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
  34339. +
  34340. config LIRC_SASEM
  34341. tristate "Sasem USB IR Remote"
  34342. depends on LIRC && USB
  34343. diff -Nur linux-3.12.18/drivers/staging/media/lirc/lirc_rpi.c linux-rpi/drivers/staging/media/lirc/lirc_rpi.c
  34344. --- linux-3.12.18/drivers/staging/media/lirc/lirc_rpi.c 1970-01-01 01:00:00.000000000 +0100
  34345. +++ linux-rpi/drivers/staging/media/lirc/lirc_rpi.c 2014-04-24 15:35:03.925563013 +0200
  34346. @@ -0,0 +1,693 @@
  34347. +/*
  34348. + * lirc_rpi.c
  34349. + *
  34350. + * lirc_rpi - Device driver that records pulse- and pause-lengths
  34351. + * (space-lengths) (just like the lirc_serial driver does)
  34352. + * between GPIO interrupt events on the Raspberry Pi.
  34353. + * Lots of code has been taken from the lirc_serial module,
  34354. + * so I would like say thanks to the authors.
  34355. + *
  34356. + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
  34357. + * Michael Bishop <cleverca22@gmail.com>
  34358. + * This program is free software; you can redistribute it and/or modify
  34359. + * it under the terms of the GNU General Public License as published by
  34360. + * the Free Software Foundation; either version 2 of the License, or
  34361. + * (at your option) any later version.
  34362. + *
  34363. + * This program is distributed in the hope that it will be useful,
  34364. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34365. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34366. + * GNU General Public License for more details.
  34367. + *
  34368. + * You should have received a copy of the GNU General Public License
  34369. + * along with this program; if not, write to the Free Software
  34370. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  34371. + */
  34372. +
  34373. +#include <linux/module.h>
  34374. +#include <linux/errno.h>
  34375. +#include <linux/interrupt.h>
  34376. +#include <linux/sched.h>
  34377. +#include <linux/kernel.h>
  34378. +#include <linux/time.h>
  34379. +#include <linux/string.h>
  34380. +#include <linux/delay.h>
  34381. +#include <linux/platform_device.h>
  34382. +#include <linux/irq.h>
  34383. +#include <linux/spinlock.h>
  34384. +#include <media/lirc.h>
  34385. +#include <media/lirc_dev.h>
  34386. +#include <linux/gpio.h>
  34387. +
  34388. +#define LIRC_DRIVER_NAME "lirc_rpi"
  34389. +#define RBUF_LEN 256
  34390. +#define LIRC_TRANSMITTER_LATENCY 256
  34391. +
  34392. +#ifndef MAX_UDELAY_MS
  34393. +#define MAX_UDELAY_US 5000
  34394. +#else
  34395. +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
  34396. +#endif
  34397. +
  34398. +#define dprintk(fmt, args...) \
  34399. + do { \
  34400. + if (debug) \
  34401. + printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
  34402. + fmt, ## args); \
  34403. + } while (0)
  34404. +
  34405. +/* module parameters */
  34406. +
  34407. +/* set the default GPIO input pin */
  34408. +static int gpio_in_pin = 18;
  34409. +/* set the default GPIO output pin */
  34410. +static int gpio_out_pin = 17;
  34411. +/* enable debugging messages */
  34412. +static bool debug;
  34413. +/* -1 = auto, 0 = active high, 1 = active low */
  34414. +static int sense = -1;
  34415. +/* use softcarrier by default */
  34416. +static bool softcarrier = 1;
  34417. +/* 0 = do not invert output, 1 = invert output */
  34418. +static bool invert = 0;
  34419. +
  34420. +struct gpio_chip *gpiochip;
  34421. +struct irq_chip *irqchip;
  34422. +struct irq_data *irqdata;
  34423. +
  34424. +/* forward declarations */
  34425. +static long send_pulse(unsigned long length);
  34426. +static void send_space(long length);
  34427. +static void lirc_rpi_exit(void);
  34428. +
  34429. +int valid_gpio_pins[] = { 0, 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21,
  34430. + 22, 23, 24, 25 ,27, 28, 29, 30, 31 };
  34431. +
  34432. +static struct platform_device *lirc_rpi_dev;
  34433. +static struct timeval lasttv = { 0, 0 };
  34434. +static struct lirc_buffer rbuf;
  34435. +static spinlock_t lock;
  34436. +
  34437. +/* initialized/set in init_timing_params() */
  34438. +static unsigned int freq = 38000;
  34439. +static unsigned int duty_cycle = 50;
  34440. +static unsigned long period;
  34441. +static unsigned long pulse_width;
  34442. +static unsigned long space_width;
  34443. +
  34444. +static void safe_udelay(unsigned long usecs)
  34445. +{
  34446. + while (usecs > MAX_UDELAY_US) {
  34447. + udelay(MAX_UDELAY_US);
  34448. + usecs -= MAX_UDELAY_US;
  34449. + }
  34450. + udelay(usecs);
  34451. +}
  34452. +
  34453. +static int init_timing_params(unsigned int new_duty_cycle,
  34454. + unsigned int new_freq)
  34455. +{
  34456. + /*
  34457. + * period, pulse/space width are kept with 8 binary places -
  34458. + * IE multiplied by 256.
  34459. + */
  34460. + if (256 * 1000000L / new_freq * new_duty_cycle / 100 <=
  34461. + LIRC_TRANSMITTER_LATENCY)
  34462. + return -EINVAL;
  34463. + if (256 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
  34464. + LIRC_TRANSMITTER_LATENCY)
  34465. + return -EINVAL;
  34466. + duty_cycle = new_duty_cycle;
  34467. + freq = new_freq;
  34468. + period = 256 * 1000000L / freq;
  34469. + pulse_width = period * duty_cycle / 100;
  34470. + space_width = period - pulse_width;
  34471. + dprintk("in init_timing_params, freq=%d pulse=%ld, "
  34472. + "space=%ld\n", freq, pulse_width, space_width);
  34473. + return 0;
  34474. +}
  34475. +
  34476. +static long send_pulse_softcarrier(unsigned long length)
  34477. +{
  34478. + int flag;
  34479. + unsigned long actual, target, d;
  34480. +
  34481. + length <<= 8;
  34482. +
  34483. + actual = 0; target = 0; flag = 0;
  34484. + while (actual < length) {
  34485. + if (flag) {
  34486. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34487. + target += space_width;
  34488. + } else {
  34489. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  34490. + target += pulse_width;
  34491. + }
  34492. + d = (target - actual -
  34493. + LIRC_TRANSMITTER_LATENCY + 128) >> 8;
  34494. + /*
  34495. + * Note - we've checked in ioctl that the pulse/space
  34496. + * widths are big enough so that d is > 0
  34497. + */
  34498. + udelay(d);
  34499. + actual += (d << 8) + LIRC_TRANSMITTER_LATENCY;
  34500. + flag = !flag;
  34501. + }
  34502. + return (actual-length) >> 8;
  34503. +}
  34504. +
  34505. +static long send_pulse(unsigned long length)
  34506. +{
  34507. + if (length <= 0)
  34508. + return 0;
  34509. +
  34510. + if (softcarrier) {
  34511. + return send_pulse_softcarrier(length);
  34512. + } else {
  34513. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  34514. + safe_udelay(length);
  34515. + return 0;
  34516. + }
  34517. +}
  34518. +
  34519. +static void send_space(long length)
  34520. +{
  34521. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34522. + if (length <= 0)
  34523. + return;
  34524. + safe_udelay(length);
  34525. +}
  34526. +
  34527. +static void rbwrite(int l)
  34528. +{
  34529. + if (lirc_buffer_full(&rbuf)) {
  34530. + /* no new signals will be accepted */
  34531. + dprintk("Buffer overrun\n");
  34532. + return;
  34533. + }
  34534. + lirc_buffer_write(&rbuf, (void *)&l);
  34535. +}
  34536. +
  34537. +static void frbwrite(int l)
  34538. +{
  34539. + /* simple noise filter */
  34540. + static int pulse, space;
  34541. + static unsigned int ptr;
  34542. +
  34543. + if (ptr > 0 && (l & PULSE_BIT)) {
  34544. + pulse += l & PULSE_MASK;
  34545. + if (pulse > 250) {
  34546. + rbwrite(space);
  34547. + rbwrite(pulse | PULSE_BIT);
  34548. + ptr = 0;
  34549. + pulse = 0;
  34550. + }
  34551. + return;
  34552. + }
  34553. + if (!(l & PULSE_BIT)) {
  34554. + if (ptr == 0) {
  34555. + if (l > 20000) {
  34556. + space = l;
  34557. + ptr++;
  34558. + return;
  34559. + }
  34560. + } else {
  34561. + if (l > 20000) {
  34562. + space += pulse;
  34563. + if (space > PULSE_MASK)
  34564. + space = PULSE_MASK;
  34565. + space += l;
  34566. + if (space > PULSE_MASK)
  34567. + space = PULSE_MASK;
  34568. + pulse = 0;
  34569. + return;
  34570. + }
  34571. + rbwrite(space);
  34572. + rbwrite(pulse | PULSE_BIT);
  34573. + ptr = 0;
  34574. + pulse = 0;
  34575. + }
  34576. + }
  34577. + rbwrite(l);
  34578. +}
  34579. +
  34580. +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
  34581. +{
  34582. + struct timeval tv;
  34583. + long deltv;
  34584. + int data;
  34585. + int signal;
  34586. +
  34587. + /* use the GPIO signal level */
  34588. + signal = gpiochip->get(gpiochip, gpio_in_pin);
  34589. +
  34590. + /* unmask the irq */
  34591. + irqchip->irq_unmask(irqdata);
  34592. +
  34593. + if (sense != -1) {
  34594. + /* get current time */
  34595. + do_gettimeofday(&tv);
  34596. +
  34597. + /* calc time since last interrupt in microseconds */
  34598. + deltv = tv.tv_sec-lasttv.tv_sec;
  34599. + if (tv.tv_sec < lasttv.tv_sec ||
  34600. + (tv.tv_sec == lasttv.tv_sec &&
  34601. + tv.tv_usec < lasttv.tv_usec)) {
  34602. + printk(KERN_WARNING LIRC_DRIVER_NAME
  34603. + ": AIEEEE: your clock just jumped backwards\n");
  34604. + printk(KERN_WARNING LIRC_DRIVER_NAME
  34605. + ": %d %d %lx %lx %lx %lx\n", signal, sense,
  34606. + tv.tv_sec, lasttv.tv_sec,
  34607. + tv.tv_usec, lasttv.tv_usec);
  34608. + data = PULSE_MASK;
  34609. + } else if (deltv > 15) {
  34610. + data = PULSE_MASK; /* really long time */
  34611. + if (!(signal^sense)) {
  34612. + /* sanity check */
  34613. + printk(KERN_WARNING LIRC_DRIVER_NAME
  34614. + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
  34615. + signal, sense, tv.tv_sec, lasttv.tv_sec,
  34616. + tv.tv_usec, lasttv.tv_usec);
  34617. + /*
  34618. + * detecting pulse while this
  34619. + * MUST be a space!
  34620. + */
  34621. + sense = sense ? 0 : 1;
  34622. + }
  34623. + } else {
  34624. + data = (int) (deltv*1000000 +
  34625. + (tv.tv_usec - lasttv.tv_usec));
  34626. + }
  34627. + frbwrite(signal^sense ? data : (data|PULSE_BIT));
  34628. + lasttv = tv;
  34629. + wake_up_interruptible(&rbuf.wait_poll);
  34630. + }
  34631. +
  34632. + return IRQ_HANDLED;
  34633. +}
  34634. +
  34635. +static int is_right_chip(struct gpio_chip *chip, void *data)
  34636. +{
  34637. + dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
  34638. +
  34639. + if (strcmp(data, chip->label) == 0)
  34640. + return 1;
  34641. + return 0;
  34642. +}
  34643. +
  34644. +static int init_port(void)
  34645. +{
  34646. + int i, nlow, nhigh, ret, irq;
  34647. +
  34648. + gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
  34649. +
  34650. + if (!gpiochip)
  34651. + return -ENODEV;
  34652. +
  34653. + if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
  34654. + printk(KERN_ALERT LIRC_DRIVER_NAME
  34655. + ": cant claim gpio pin %d\n", gpio_out_pin);
  34656. + ret = -ENODEV;
  34657. + goto exit_init_port;
  34658. + }
  34659. +
  34660. + if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
  34661. + printk(KERN_ALERT LIRC_DRIVER_NAME
  34662. + ": cant claim gpio pin %d\n", gpio_in_pin);
  34663. + ret = -ENODEV;
  34664. + goto exit_gpio_free_out_pin;
  34665. + }
  34666. +
  34667. + gpiochip->direction_input(gpiochip, gpio_in_pin);
  34668. + gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
  34669. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34670. +
  34671. + irq = gpiochip->to_irq(gpiochip, gpio_in_pin);
  34672. + dprintk("to_irq %d\n", irq);
  34673. + irqdata = irq_get_irq_data(irq);
  34674. +
  34675. + if (irqdata && irqdata->chip) {
  34676. + irqchip = irqdata->chip;
  34677. + } else {
  34678. + ret = -ENODEV;
  34679. + goto exit_gpio_free_in_pin;
  34680. + }
  34681. +
  34682. + /* if pin is high, then this must be an active low receiver. */
  34683. + if (sense == -1) {
  34684. + /* wait 1/2 sec for the power supply */
  34685. + msleep(500);
  34686. +
  34687. + /*
  34688. + * probe 9 times every 0.04s, collect "votes" for
  34689. + * active high/low
  34690. + */
  34691. + nlow = 0;
  34692. + nhigh = 0;
  34693. + for (i = 0; i < 9; i++) {
  34694. + if (gpiochip->get(gpiochip, gpio_in_pin))
  34695. + nlow++;
  34696. + else
  34697. + nhigh++;
  34698. + msleep(40);
  34699. + }
  34700. + sense = (nlow >= nhigh ? 1 : 0);
  34701. + printk(KERN_INFO LIRC_DRIVER_NAME
  34702. + ": auto-detected active %s receiver on GPIO pin %d\n",
  34703. + sense ? "low" : "high", gpio_in_pin);
  34704. + } else {
  34705. + printk(KERN_INFO LIRC_DRIVER_NAME
  34706. + ": manually using active %s receiver on GPIO pin %d\n",
  34707. + sense ? "low" : "high", gpio_in_pin);
  34708. + }
  34709. +
  34710. + return 0;
  34711. +
  34712. + exit_gpio_free_in_pin:
  34713. + gpio_free(gpio_in_pin);
  34714. +
  34715. + exit_gpio_free_out_pin:
  34716. + gpio_free(gpio_out_pin);
  34717. +
  34718. + exit_init_port:
  34719. + return ret;
  34720. +}
  34721. +
  34722. +// called when the character device is opened
  34723. +static int set_use_inc(void *data)
  34724. +{
  34725. + int result;
  34726. + unsigned long flags;
  34727. +
  34728. + /* initialize timestamp */
  34729. + do_gettimeofday(&lasttv);
  34730. +
  34731. + result = request_irq(gpiochip->to_irq(gpiochip, gpio_in_pin),
  34732. + (irq_handler_t) irq_handler, 0,
  34733. + LIRC_DRIVER_NAME, (void*) 0);
  34734. +
  34735. + switch (result) {
  34736. + case -EBUSY:
  34737. + printk(KERN_ERR LIRC_DRIVER_NAME
  34738. + ": IRQ %d is busy\n",
  34739. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  34740. + return -EBUSY;
  34741. + case -EINVAL:
  34742. + printk(KERN_ERR LIRC_DRIVER_NAME
  34743. + ": Bad irq number or handler\n");
  34744. + return -EINVAL;
  34745. + default:
  34746. + dprintk("Interrupt %d obtained\n",
  34747. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  34748. + break;
  34749. + };
  34750. +
  34751. + /* initialize pulse/space widths */
  34752. + init_timing_params(duty_cycle, freq);
  34753. +
  34754. + spin_lock_irqsave(&lock, flags);
  34755. +
  34756. + /* GPIO Pin Falling/Rising Edge Detect Enable */
  34757. + irqchip->irq_set_type(irqdata,
  34758. + IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);
  34759. +
  34760. + /* unmask the irq */
  34761. + irqchip->irq_unmask(irqdata);
  34762. +
  34763. + spin_unlock_irqrestore(&lock, flags);
  34764. +
  34765. + return 0;
  34766. +}
  34767. +
  34768. +static void set_use_dec(void *data)
  34769. +{
  34770. + unsigned long flags;
  34771. +
  34772. + spin_lock_irqsave(&lock, flags);
  34773. +
  34774. + /* GPIO Pin Falling/Rising Edge Detect Disable */
  34775. + irqchip->irq_set_type(irqdata, 0);
  34776. + irqchip->irq_mask(irqdata);
  34777. +
  34778. + spin_unlock_irqrestore(&lock, flags);
  34779. +
  34780. + free_irq(gpiochip->to_irq(gpiochip, gpio_in_pin), (void *) 0);
  34781. +
  34782. + dprintk(KERN_INFO LIRC_DRIVER_NAME
  34783. + ": freed IRQ %d\n", gpiochip->to_irq(gpiochip, gpio_in_pin));
  34784. +}
  34785. +
  34786. +static ssize_t lirc_write(struct file *file, const char *buf,
  34787. + size_t n, loff_t *ppos)
  34788. +{
  34789. + int i, count;
  34790. + unsigned long flags;
  34791. + long delta = 0;
  34792. + int *wbuf;
  34793. +
  34794. + count = n / sizeof(int);
  34795. + if (n % sizeof(int) || count % 2 == 0)
  34796. + return -EINVAL;
  34797. + wbuf = memdup_user(buf, n);
  34798. + if (IS_ERR(wbuf))
  34799. + return PTR_ERR(wbuf);
  34800. + spin_lock_irqsave(&lock, flags);
  34801. +
  34802. + for (i = 0; i < count; i++) {
  34803. + if (i%2)
  34804. + send_space(wbuf[i] - delta);
  34805. + else
  34806. + delta = send_pulse(wbuf[i]);
  34807. + }
  34808. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34809. +
  34810. + spin_unlock_irqrestore(&lock, flags);
  34811. + kfree(wbuf);
  34812. + return n;
  34813. +}
  34814. +
  34815. +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  34816. +{
  34817. + int result;
  34818. + __u32 value;
  34819. +
  34820. + switch (cmd) {
  34821. + case LIRC_GET_SEND_MODE:
  34822. + return -ENOIOCTLCMD;
  34823. + break;
  34824. +
  34825. + case LIRC_SET_SEND_MODE:
  34826. + result = get_user(value, (__u32 *) arg);
  34827. + if (result)
  34828. + return result;
  34829. + /* only LIRC_MODE_PULSE supported */
  34830. + if (value != LIRC_MODE_PULSE)
  34831. + return -ENOSYS;
  34832. + break;
  34833. +
  34834. + case LIRC_GET_LENGTH:
  34835. + return -ENOSYS;
  34836. + break;
  34837. +
  34838. + case LIRC_SET_SEND_DUTY_CYCLE:
  34839. + dprintk("SET_SEND_DUTY_CYCLE\n");
  34840. + result = get_user(value, (__u32 *) arg);
  34841. + if (result)
  34842. + return result;
  34843. + if (value <= 0 || value > 100)
  34844. + return -EINVAL;
  34845. + return init_timing_params(value, freq);
  34846. + break;
  34847. +
  34848. + case LIRC_SET_SEND_CARRIER:
  34849. + dprintk("SET_SEND_CARRIER\n");
  34850. + result = get_user(value, (__u32 *) arg);
  34851. + if (result)
  34852. + return result;
  34853. + if (value > 500000 || value < 20000)
  34854. + return -EINVAL;
  34855. + return init_timing_params(duty_cycle, value);
  34856. + break;
  34857. +
  34858. + default:
  34859. + return lirc_dev_fop_ioctl(filep, cmd, arg);
  34860. + }
  34861. + return 0;
  34862. +}
  34863. +
  34864. +static const struct file_operations lirc_fops = {
  34865. + .owner = THIS_MODULE,
  34866. + .write = lirc_write,
  34867. + .unlocked_ioctl = lirc_ioctl,
  34868. + .read = lirc_dev_fop_read,
  34869. + .poll = lirc_dev_fop_poll,
  34870. + .open = lirc_dev_fop_open,
  34871. + .release = lirc_dev_fop_close,
  34872. + .llseek = no_llseek,
  34873. +};
  34874. +
  34875. +static struct lirc_driver driver = {
  34876. + .name = LIRC_DRIVER_NAME,
  34877. + .minor = -1,
  34878. + .code_length = 1,
  34879. + .sample_rate = 0,
  34880. + .data = NULL,
  34881. + .add_to_buf = NULL,
  34882. + .rbuf = &rbuf,
  34883. + .set_use_inc = set_use_inc,
  34884. + .set_use_dec = set_use_dec,
  34885. + .fops = &lirc_fops,
  34886. + .dev = NULL,
  34887. + .owner = THIS_MODULE,
  34888. +};
  34889. +
  34890. +static struct platform_driver lirc_rpi_driver = {
  34891. + .driver = {
  34892. + .name = LIRC_DRIVER_NAME,
  34893. + .owner = THIS_MODULE,
  34894. + },
  34895. +};
  34896. +
  34897. +static int __init lirc_rpi_init(void)
  34898. +{
  34899. + int result;
  34900. +
  34901. + /* Init read buffer. */
  34902. + result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
  34903. + if (result < 0)
  34904. + return -ENOMEM;
  34905. +
  34906. + result = platform_driver_register(&lirc_rpi_driver);
  34907. + if (result) {
  34908. + printk(KERN_ERR LIRC_DRIVER_NAME
  34909. + ": lirc register returned %d\n", result);
  34910. + goto exit_buffer_free;
  34911. + }
  34912. +
  34913. + lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
  34914. + if (!lirc_rpi_dev) {
  34915. + result = -ENOMEM;
  34916. + goto exit_driver_unregister;
  34917. + }
  34918. +
  34919. + result = platform_device_add(lirc_rpi_dev);
  34920. + if (result)
  34921. + goto exit_device_put;
  34922. +
  34923. + return 0;
  34924. +
  34925. + exit_device_put:
  34926. + platform_device_put(lirc_rpi_dev);
  34927. +
  34928. + exit_driver_unregister:
  34929. + platform_driver_unregister(&lirc_rpi_driver);
  34930. +
  34931. + exit_buffer_free:
  34932. + lirc_buffer_free(&rbuf);
  34933. +
  34934. + return result;
  34935. +}
  34936. +
  34937. +static void lirc_rpi_exit(void)
  34938. +{
  34939. + platform_device_unregister(lirc_rpi_dev);
  34940. + platform_driver_unregister(&lirc_rpi_driver);
  34941. + lirc_buffer_free(&rbuf);
  34942. +}
  34943. +
  34944. +static int __init lirc_rpi_init_module(void)
  34945. +{
  34946. + int result, i;
  34947. +
  34948. + result = lirc_rpi_init();
  34949. + if (result)
  34950. + return result;
  34951. +
  34952. + /* check if the module received valid gpio pin numbers */
  34953. + result = 0;
  34954. + if (gpio_in_pin != gpio_out_pin) {
  34955. + for(i = 0; (i < ARRAY_SIZE(valid_gpio_pins)) && (result != 2); i++) {
  34956. + if (gpio_in_pin == valid_gpio_pins[i] ||
  34957. + gpio_out_pin == valid_gpio_pins[i]) {
  34958. + result++;
  34959. + }
  34960. + }
  34961. + }
  34962. +
  34963. + if (result != 2) {
  34964. + result = -EINVAL;
  34965. + printk(KERN_ERR LIRC_DRIVER_NAME
  34966. + ": invalid GPIO pin(s) specified!\n");
  34967. + goto exit_rpi;
  34968. + }
  34969. +
  34970. + result = init_port();
  34971. + if (result < 0)
  34972. + goto exit_rpi;
  34973. +
  34974. + driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
  34975. + LIRC_CAN_SET_SEND_CARRIER |
  34976. + LIRC_CAN_SEND_PULSE |
  34977. + LIRC_CAN_REC_MODE2;
  34978. +
  34979. + driver.dev = &lirc_rpi_dev->dev;
  34980. + driver.minor = lirc_register_driver(&driver);
  34981. +
  34982. + if (driver.minor < 0) {
  34983. + printk(KERN_ERR LIRC_DRIVER_NAME
  34984. + ": device registration failed with %d\n", result);
  34985. + result = -EIO;
  34986. + goto exit_rpi;
  34987. + }
  34988. +
  34989. + printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
  34990. +
  34991. + return 0;
  34992. +
  34993. + exit_rpi:
  34994. + lirc_rpi_exit();
  34995. +
  34996. + return result;
  34997. +}
  34998. +
  34999. +static void __exit lirc_rpi_exit_module(void)
  35000. +{
  35001. + gpio_free(gpio_out_pin);
  35002. + gpio_free(gpio_in_pin);
  35003. +
  35004. + lirc_rpi_exit();
  35005. +
  35006. + lirc_unregister_driver(driver.minor);
  35007. + printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
  35008. +}
  35009. +
  35010. +module_init(lirc_rpi_init_module);
  35011. +module_exit(lirc_rpi_exit_module);
  35012. +
  35013. +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
  35014. +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
  35015. +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
  35016. +MODULE_LICENSE("GPL");
  35017. +
  35018. +module_param(gpio_out_pin, int, S_IRUGO);
  35019. +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
  35020. + " processor. Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11,"
  35021. + " 14, 15, 17, 18, 21, 22, 23, 24, 25, default 17");
  35022. +
  35023. +module_param(gpio_in_pin, int, S_IRUGO);
  35024. +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
  35025. + " Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11, 14, 15,"
  35026. + " 17, 18, 21, 22, 23, 24, 25, default 18");
  35027. +
  35028. +module_param(sense, int, S_IRUGO);
  35029. +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
  35030. + " (0 = active high, 1 = active low )");
  35031. +
  35032. +module_param(softcarrier, bool, S_IRUGO);
  35033. +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
  35034. +
  35035. +module_param(invert, bool, S_IRUGO);
  35036. +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
  35037. +
  35038. +module_param(debug, bool, S_IRUGO | S_IWUSR);
  35039. +MODULE_PARM_DESC(debug, "Enable debugging messages");
  35040. diff -Nur linux-3.12.18/drivers/staging/media/lirc/Makefile linux-rpi/drivers/staging/media/lirc/Makefile
  35041. --- linux-3.12.18/drivers/staging/media/lirc/Makefile 2014-04-18 11:14:28.000000000 +0200
  35042. +++ linux-rpi/drivers/staging/media/lirc/Makefile 2014-04-24 15:35:03.925563013 +0200
  35043. @@ -7,6 +7,7 @@
  35044. obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
  35045. obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
  35046. obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
  35047. +obj-$(CONFIG_LIRC_RPI) += lirc_rpi.o
  35048. obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
  35049. obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
  35050. obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
  35051. diff -Nur linux-3.12.18/drivers/thermal/bcm2835-thermal.c linux-rpi/drivers/thermal/bcm2835-thermal.c
  35052. --- linux-3.12.18/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
  35053. +++ linux-rpi/drivers/thermal/bcm2835-thermal.c 2014-04-24 15:35:04.089564840 +0200
  35054. @@ -0,0 +1,184 @@
  35055. +/*****************************************************************************
  35056. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  35057. +*
  35058. +* Unless you and Broadcom execute a separate written software license
  35059. +* agreement governing use of this software, this software is licensed to you
  35060. +* under the terms of the GNU General Public License version 2, available at
  35061. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  35062. +*
  35063. +* Notwithstanding the above, under no circumstances may you combine this
  35064. +* software in any way with any other Broadcom software provided under a
  35065. +* license other than the GPL, without Broadcom's express prior written
  35066. +* consent.
  35067. +*****************************************************************************/
  35068. +
  35069. +#include <linux/kernel.h>
  35070. +#include <linux/module.h>
  35071. +#include <linux/init.h>
  35072. +#include <linux/platform_device.h>
  35073. +#include <linux/slab.h>
  35074. +#include <linux/sysfs.h>
  35075. +#include <mach/vcio.h>
  35076. +#include <linux/thermal.h>
  35077. +
  35078. +
  35079. +/* --- DEFINITIONS --- */
  35080. +#define MODULE_NAME "bcm2835_thermal"
  35081. +
  35082. +/*#define THERMAL_DEBUG_ENABLE*/
  35083. +
  35084. +#ifdef THERMAL_DEBUG_ENABLE
  35085. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  35086. +#else
  35087. +#define print_debug(fmt,...)
  35088. +#endif
  35089. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  35090. +
  35091. +#define VC_TAG_GET_TEMP 0x00030006
  35092. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  35093. +
  35094. +typedef enum {
  35095. + TEMP,
  35096. + MAX_TEMP,
  35097. +} temp_type;
  35098. +
  35099. +/* --- STRUCTS --- */
  35100. +/* tag part of the message */
  35101. +struct vc_msg_tag {
  35102. + uint32_t tag_id; /* the tag ID for the temperature */
  35103. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  35104. + uint32_t request_code; /* identifies message as a request (should be 0) */
  35105. + uint32_t id; /* extra ID field (should be 0) */
  35106. + uint32_t val; /* returned value of the temperature */
  35107. +};
  35108. +
  35109. +/* message structure to be sent to videocore */
  35110. +struct vc_msg {
  35111. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  35112. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  35113. + struct vc_msg_tag tag; /* the tag structure above to make */
  35114. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  35115. +};
  35116. +
  35117. +struct bcm2835_thermal_data {
  35118. + struct thermal_zone_device *thermal_dev;
  35119. + struct vc_msg msg;
  35120. +};
  35121. +
  35122. +/* --- GLOBALS --- */
  35123. +static struct bcm2835_thermal_data bcm2835_data;
  35124. +
  35125. +/* Thermal Device Operations */
  35126. +static struct thermal_zone_device_ops ops;
  35127. +
  35128. +/* --- FUNCTIONS --- */
  35129. +
  35130. +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
  35131. +{
  35132. + int result = -1, retry = 3;
  35133. + print_debug("IN");
  35134. +
  35135. + *temp = 0;
  35136. + while (result != 0 && retry-- > 0) {
  35137. + /* wipe all previous message data */
  35138. + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
  35139. +
  35140. + /* prepare message */
  35141. + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
  35142. + bcm2835_data.msg.tag.buffer_size = 8;
  35143. + bcm2835_data.msg.tag.tag_id = tag_id;
  35144. +
  35145. + /* send the message */
  35146. + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
  35147. + 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);
  35148. + if (!(bcm2835_data.msg.request_code & 0x80000000))
  35149. + result = -1;
  35150. + }
  35151. +
  35152. + /* check if it was all ok and return the rate in milli degrees C */
  35153. + if (result == 0)
  35154. + *temp = (uint)bcm2835_data.msg.tag.val;
  35155. + else
  35156. + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
  35157. + print_debug("OUT");
  35158. + return result;
  35159. +}
  35160. +
  35161. +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
  35162. +{
  35163. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
  35164. +}
  35165. +
  35166. +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
  35167. +{
  35168. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
  35169. +}
  35170. +
  35171. +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
  35172. +{
  35173. + *trip_type = THERMAL_TRIP_HOT;
  35174. + return 0;
  35175. +}
  35176. +
  35177. +
  35178. +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
  35179. +{
  35180. + *dev_mode = THERMAL_DEVICE_ENABLED;
  35181. + return 0;
  35182. +}
  35183. +
  35184. +
  35185. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  35186. +{
  35187. + print_debug("IN");
  35188. + print_debug("THERMAL Driver has been probed!");
  35189. +
  35190. + /* check that the device isn't null!*/
  35191. + if(pdev == NULL)
  35192. + {
  35193. + print_debug("Platform device is empty!");
  35194. + return -ENODEV;
  35195. + }
  35196. +
  35197. + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
  35198. + {
  35199. + print_debug("Unable to register the thermal device!");
  35200. + return -EFAULT;
  35201. + }
  35202. + return 0;
  35203. +}
  35204. +
  35205. +
  35206. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  35207. +{
  35208. + print_debug("IN");
  35209. +
  35210. + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
  35211. +
  35212. + print_debug("OUT");
  35213. +
  35214. + return 0;
  35215. +}
  35216. +
  35217. +static struct thermal_zone_device_ops ops = {
  35218. + .get_temp = bcm2835_get_temp,
  35219. + .get_trip_temp = bcm2835_get_max_temp,
  35220. + .get_trip_type = bcm2835_get_trip_type,
  35221. + .get_mode = bcm2835_get_mode,
  35222. +};
  35223. +
  35224. +/* Thermal Driver */
  35225. +static struct platform_driver bcm2835_thermal_driver = {
  35226. + .probe = bcm2835_thermal_probe,
  35227. + .remove = bcm2835_thermal_remove,
  35228. + .driver = {
  35229. + .name = "bcm2835_thermal",
  35230. + .owner = THIS_MODULE,
  35231. + },
  35232. +};
  35233. +
  35234. +MODULE_LICENSE("GPL");
  35235. +MODULE_AUTHOR("Dorian Peake");
  35236. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  35237. +
  35238. +module_platform_driver(bcm2835_thermal_driver);
  35239. diff -Nur linux-3.12.18/drivers/thermal/Kconfig linux-rpi/drivers/thermal/Kconfig
  35240. --- linux-3.12.18/drivers/thermal/Kconfig 2014-04-18 11:14:28.000000000 +0200
  35241. +++ linux-rpi/drivers/thermal/Kconfig 2014-04-24 16:04:39.655122669 +0200
  35242. @@ -181,6 +181,12 @@
  35243. enforce idle time which results in more package C-state residency. The
  35244. user interface is exposed via generic thermal framework.
  35245. +config THERMAL_BCM2835
  35246. + tristate "BCM2835 Thermal Driver"
  35247. + help
  35248. + This will enable temperature monitoring for the Broadcom BCM2835
  35249. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  35250. +
  35251. config X86_PKG_TEMP_THERMAL
  35252. tristate "X86 package temperature thermal driver"
  35253. depends on X86_THERMAL_VECTOR
  35254. diff -Nur linux-3.12.18/drivers/thermal/Makefile linux-rpi/drivers/thermal/Makefile
  35255. --- linux-3.12.18/drivers/thermal/Makefile 2014-04-18 11:14:28.000000000 +0200
  35256. +++ linux-rpi/drivers/thermal/Makefile 2014-04-24 16:04:39.655122669 +0200
  35257. @@ -27,5 +27,6 @@
  35258. obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
  35259. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  35260. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  35261. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  35262. obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
  35263. obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
  35264. diff -Nur linux-3.12.18/drivers/tty/serial/amba-pl011.c linux-rpi/drivers/tty/serial/amba-pl011.c
  35265. --- linux-3.12.18/drivers/tty/serial/amba-pl011.c 2014-04-18 11:14:28.000000000 +0200
  35266. +++ linux-rpi/drivers/tty/serial/amba-pl011.c 2014-04-24 16:04:39.667122784 +0200
  35267. @@ -84,7 +84,7 @@
  35268. static unsigned int get_fifosize_arm(struct amba_device *dev)
  35269. {
  35270. - return amba_rev(dev) < 3 ? 16 : 32;
  35271. + return 16; //TODO: fix: amba_rev(dev) < 3 ? 16 : 32;
  35272. }
  35273. static struct vendor_data vendor_arm = {
  35274. diff -Nur linux-3.12.18/drivers/usb/core/generic.c linux-rpi/drivers/usb/core/generic.c
  35275. --- linux-3.12.18/drivers/usb/core/generic.c 2014-04-18 11:14:28.000000000 +0200
  35276. +++ linux-rpi/drivers/usb/core/generic.c 2014-04-24 15:35:04.137565375 +0200
  35277. @@ -152,6 +152,7 @@
  35278. dev_warn(&udev->dev,
  35279. "no configuration chosen from %d choice%s\n",
  35280. num_configs, plural(num_configs));
  35281. + dev_warn(&udev->dev, "No support over %dmA\n", udev->bus_mA);
  35282. }
  35283. return i;
  35284. }
  35285. diff -Nur linux-3.12.18/drivers/usb/core/message.c linux-rpi/drivers/usb/core/message.c
  35286. --- linux-3.12.18/drivers/usb/core/message.c 2014-04-18 11:14:28.000000000 +0200
  35287. +++ linux-rpi/drivers/usb/core/message.c 2014-04-24 16:04:39.763123712 +0200
  35288. @@ -1885,6 +1885,85 @@
  35289. if (cp->string == NULL &&
  35290. !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
  35291. cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
  35292. +/* Uncomment this define to enable the HS Electrical Test support */
  35293. +#define DWC_HS_ELECT_TST 1
  35294. +#ifdef DWC_HS_ELECT_TST
  35295. + /* Here we implement the HS Electrical Test support. The
  35296. + * tester uses a vendor ID of 0x1A0A to indicate we should
  35297. + * run a special test sequence. The product ID tells us
  35298. + * which sequence to run. We invoke the test sequence by
  35299. + * sending a non-standard SetFeature command to our root
  35300. + * hub port. Our dwc_otg_hcd_hub_control() routine will
  35301. + * recognize the command and perform the desired test
  35302. + * sequence.
  35303. + */
  35304. + if (dev->descriptor.idVendor == 0x1A0A) {
  35305. + /* HSOTG Electrical Test */
  35306. + dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
  35307. +
  35308. + if (dev->bus && dev->bus->root_hub) {
  35309. + struct usb_device *hdev = dev->bus->root_hub;
  35310. + dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
  35311. +
  35312. + switch (dev->descriptor.idProduct) {
  35313. + case 0x0101: /* TEST_SE0_NAK */
  35314. + dev_warn(&dev->dev, "TEST_SE0_NAK\n");
  35315. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35316. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35317. + USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
  35318. + break;
  35319. +
  35320. + case 0x0102: /* TEST_J */
  35321. + dev_warn(&dev->dev, "TEST_J\n");
  35322. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35323. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35324. + USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
  35325. + break;
  35326. +
  35327. + case 0x0103: /* TEST_K */
  35328. + dev_warn(&dev->dev, "TEST_K\n");
  35329. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35330. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35331. + USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
  35332. + break;
  35333. +
  35334. + case 0x0104: /* TEST_PACKET */
  35335. + dev_warn(&dev->dev, "TEST_PACKET\n");
  35336. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35337. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35338. + USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
  35339. + break;
  35340. +
  35341. + case 0x0105: /* TEST_FORCE_ENABLE */
  35342. + dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
  35343. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35344. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35345. + USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
  35346. + break;
  35347. +
  35348. + case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
  35349. + dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
  35350. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35351. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35352. + USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
  35353. + break;
  35354. +
  35355. + case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  35356. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
  35357. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35358. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35359. + USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
  35360. + break;
  35361. +
  35362. + case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  35363. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
  35364. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35365. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35366. + USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
  35367. + }
  35368. + }
  35369. + }
  35370. +#endif /* DWC_HS_ELECT_TST */
  35371. /* Now that the interfaces are installed, re-enable LPM. */
  35372. usb_unlocked_enable_lpm(dev);
  35373. diff -Nur linux-3.12.18/drivers/usb/core/otg_whitelist.h linux-rpi/drivers/usb/core/otg_whitelist.h
  35374. --- linux-3.12.18/drivers/usb/core/otg_whitelist.h 2014-04-18 11:14:28.000000000 +0200
  35375. +++ linux-rpi/drivers/usb/core/otg_whitelist.h 2014-04-24 16:04:39.763123712 +0200
  35376. @@ -19,33 +19,82 @@
  35377. static struct usb_device_id whitelist_table [] = {
  35378. /* hubs are optional in OTG, but very handy ... */
  35379. +#define CERT_WITHOUT_HUBS
  35380. +#if defined(CERT_WITHOUT_HUBS)
  35381. +{ USB_DEVICE( 0x0000, 0x0000 ), }, /* Root HUB Only*/
  35382. +#else
  35383. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
  35384. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
  35385. +{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 2), },
  35386. +#endif
  35387. #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
  35388. /* FIXME actually, printers are NOT supposed to use device classes;
  35389. * they're supposed to use interface classes...
  35390. */
  35391. -{ USB_DEVICE_INFO(7, 1, 1) },
  35392. -{ USB_DEVICE_INFO(7, 1, 2) },
  35393. -{ USB_DEVICE_INFO(7, 1, 3) },
  35394. +//{ USB_DEVICE_INFO(7, 1, 1) },
  35395. +//{ USB_DEVICE_INFO(7, 1, 2) },
  35396. +//{ USB_DEVICE_INFO(7, 1, 3) },
  35397. #endif
  35398. #ifdef CONFIG_USB_NET_CDCETHER
  35399. /* Linux-USB CDC Ethernet gadget */
  35400. -{ USB_DEVICE(0x0525, 0xa4a1), },
  35401. +//{ USB_DEVICE(0x0525, 0xa4a1), },
  35402. /* Linux-USB CDC Ethernet + RNDIS gadget */
  35403. -{ USB_DEVICE(0x0525, 0xa4a2), },
  35404. +//{ USB_DEVICE(0x0525, 0xa4a2), },
  35405. #endif
  35406. #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
  35407. /* gadget zero, for testing */
  35408. -{ USB_DEVICE(0x0525, 0xa4a0), },
  35409. +//{ USB_DEVICE(0x0525, 0xa4a0), },
  35410. #endif
  35411. +/* OPT Tester */
  35412. +{ USB_DEVICE( 0x1a0a, 0x0101 ), }, /* TEST_SE0_NAK */
  35413. +{ USB_DEVICE( 0x1a0a, 0x0102 ), }, /* Test_J */
  35414. +{ USB_DEVICE( 0x1a0a, 0x0103 ), }, /* Test_K */
  35415. +{ USB_DEVICE( 0x1a0a, 0x0104 ), }, /* Test_PACKET */
  35416. +{ USB_DEVICE( 0x1a0a, 0x0105 ), }, /* Test_FORCE_ENABLE */
  35417. +{ USB_DEVICE( 0x1a0a, 0x0106 ), }, /* HS_PORT_SUSPEND_RESUME */
  35418. +{ USB_DEVICE( 0x1a0a, 0x0107 ), }, /* SINGLE_STEP_GET_DESCRIPTOR setup */
  35419. +{ USB_DEVICE( 0x1a0a, 0x0108 ), }, /* SINGLE_STEP_GET_DESCRIPTOR execute */
  35420. +
  35421. +/* Sony cameras */
  35422. +{ USB_DEVICE_VER(0x054c,0x0010,0x0410, 0x0500), },
  35423. +
  35424. +/* Memory Devices */
  35425. +//{ USB_DEVICE( 0x0781, 0x5150 ), }, /* SanDisk */
  35426. +//{ USB_DEVICE( 0x05DC, 0x0080 ), }, /* Lexar */
  35427. +//{ USB_DEVICE( 0x4146, 0x9281 ), }, /* IOMEGA */
  35428. +//{ USB_DEVICE( 0x067b, 0x2507 ), }, /* Hammer 20GB External HD */
  35429. +{ USB_DEVICE( 0x0EA0, 0x2168 ), }, /* Ours Technology Inc. (BUFFALO ClipDrive)*/
  35430. +//{ USB_DEVICE( 0x0457, 0x0150 ), }, /* Silicon Integrated Systems Corp. */
  35431. +
  35432. +/* HP Printers */
  35433. +//{ USB_DEVICE( 0x03F0, 0x1102 ), }, /* HP Photosmart 245 */
  35434. +//{ USB_DEVICE( 0x03F0, 0x1302 ), }, /* HP Photosmart 370 Series */
  35435. +
  35436. +/* Speakers */
  35437. +//{ USB_DEVICE( 0x0499, 0x3002 ), }, /* YAMAHA YST-MS35D USB Speakers */
  35438. +//{ USB_DEVICE( 0x0672, 0x1041 ), }, /* Labtec USB Headset */
  35439. +
  35440. { } /* Terminating entry */
  35441. };
  35442. +static inline void report_errors(struct usb_device *dev)
  35443. +{
  35444. + /* OTG MESSAGE: report errors here, customize to match your product */
  35445. + dev_info(&dev->dev, "device Vendor:%04x Product:%04x is not supported\n",
  35446. + le16_to_cpu(dev->descriptor.idVendor),
  35447. + le16_to_cpu(dev->descriptor.idProduct));
  35448. + if (USB_CLASS_HUB == dev->descriptor.bDeviceClass){
  35449. + dev_printk(KERN_CRIT, &dev->dev, "Unsupported Hub Topology\n");
  35450. + } else {
  35451. + dev_printk(KERN_CRIT, &dev->dev, "Attached Device is not Supported\n");
  35452. + }
  35453. +}
  35454. +
  35455. +
  35456. static int is_targeted(struct usb_device *dev)
  35457. {
  35458. struct usb_device_id *id = whitelist_table;
  35459. @@ -55,58 +104,83 @@
  35460. return 1;
  35461. /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
  35462. - if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
  35463. - le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
  35464. - return 0;
  35465. + if (dev->descriptor.idVendor == 0x1a0a &&
  35466. + dev->descriptor.idProduct == 0xbadd) {
  35467. + return 0;
  35468. + } else if (!enable_whitelist) {
  35469. + return 1;
  35470. + } else {
  35471. - /* NOTE: can't use usb_match_id() since interface caches
  35472. - * aren't set up yet. this is cut/paste from that code.
  35473. - */
  35474. - for (id = whitelist_table; id->match_flags; id++) {
  35475. - if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  35476. - id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  35477. - continue;
  35478. -
  35479. - if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  35480. - id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  35481. - continue;
  35482. -
  35483. - /* No need to test id->bcdDevice_lo != 0, since 0 is never
  35484. - greater than any unsigned number. */
  35485. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  35486. - (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  35487. - continue;
  35488. -
  35489. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  35490. - (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  35491. - continue;
  35492. -
  35493. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  35494. - (id->bDeviceClass != dev->descriptor.bDeviceClass))
  35495. - continue;
  35496. -
  35497. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  35498. - (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  35499. - continue;
  35500. -
  35501. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  35502. - (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  35503. - continue;
  35504. +#ifdef DEBUG
  35505. + dev_dbg(&dev->dev, "device V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  35506. + dev->descriptor.idVendor,
  35507. + dev->descriptor.idProduct,
  35508. + dev->descriptor.bDeviceClass,
  35509. + dev->descriptor.bDeviceSubClass,
  35510. + dev->descriptor.bDeviceProtocol);
  35511. +#endif
  35512. return 1;
  35513. + /* NOTE: can't use usb_match_id() since interface caches
  35514. + * aren't set up yet. this is cut/paste from that code.
  35515. + */
  35516. + for (id = whitelist_table; id->match_flags; id++) {
  35517. +#ifdef DEBUG
  35518. + dev_dbg(&dev->dev,
  35519. + "ID: V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  35520. + id->idVendor,
  35521. + id->idProduct,
  35522. + id->bDeviceClass,
  35523. + id->bDeviceSubClass,
  35524. + id->bDeviceProtocol);
  35525. +#endif
  35526. +
  35527. + if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  35528. + id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  35529. + continue;
  35530. +
  35531. + if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  35532. + id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  35533. + continue;
  35534. +
  35535. + /* No need to test id->bcdDevice_lo != 0, since 0 is never
  35536. + greater than any unsigned number. */
  35537. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  35538. + (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  35539. + continue;
  35540. +
  35541. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  35542. + (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  35543. + continue;
  35544. +
  35545. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  35546. + (id->bDeviceClass != dev->descriptor.bDeviceClass))
  35547. + continue;
  35548. +
  35549. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  35550. + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  35551. + continue;
  35552. +
  35553. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  35554. + (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  35555. + continue;
  35556. +
  35557. + return 1;
  35558. + }
  35559. }
  35560. /* add other match criteria here ... */
  35561. -
  35562. - /* OTG MESSAGE: report errors here, customize to match your product */
  35563. - dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
  35564. - le16_to_cpu(dev->descriptor.idVendor),
  35565. - le16_to_cpu(dev->descriptor.idProduct));
  35566. #ifdef CONFIG_USB_OTG_WHITELIST
  35567. + report_errors(dev);
  35568. return 0;
  35569. #else
  35570. - return 1;
  35571. + if (enable_whitelist) {
  35572. + report_errors(dev);
  35573. + return 0;
  35574. + } else {
  35575. + return 1;
  35576. + }
  35577. #endif
  35578. }
  35579. diff -Nur linux-3.12.18/drivers/usb/gadget/file_storage.c linux-rpi/drivers/usb/gadget/file_storage.c
  35580. --- linux-3.12.18/drivers/usb/gadget/file_storage.c 1970-01-01 01:00:00.000000000 +0100
  35581. +++ linux-rpi/drivers/usb/gadget/file_storage.c 2014-04-24 15:35:04.153565553 +0200
  35582. @@ -0,0 +1,3676 @@
  35583. +/*
  35584. + * file_storage.c -- File-backed USB Storage Gadget, for USB development
  35585. + *
  35586. + * Copyright (C) 2003-2008 Alan Stern
  35587. + * All rights reserved.
  35588. + *
  35589. + * Redistribution and use in source and binary forms, with or without
  35590. + * modification, are permitted provided that the following conditions
  35591. + * are met:
  35592. + * 1. Redistributions of source code must retain the above copyright
  35593. + * notice, this list of conditions, and the following disclaimer,
  35594. + * without modification.
  35595. + * 2. Redistributions in binary form must reproduce the above copyright
  35596. + * notice, this list of conditions and the following disclaimer in the
  35597. + * documentation and/or other materials provided with the distribution.
  35598. + * 3. The names of the above-listed copyright holders may not be used
  35599. + * to endorse or promote products derived from this software without
  35600. + * specific prior written permission.
  35601. + *
  35602. + * ALTERNATIVELY, this software may be distributed under the terms of the
  35603. + * GNU General Public License ("GPL") as published by the Free Software
  35604. + * Foundation, either version 2 of that License or (at your option) any
  35605. + * later version.
  35606. + *
  35607. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  35608. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  35609. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35610. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35611. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  35612. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35613. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35614. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35615. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35616. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35617. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35618. + */
  35619. +
  35620. +
  35621. +/*
  35622. + * The File-backed Storage Gadget acts as a USB Mass Storage device,
  35623. + * appearing to the host as a disk drive or as a CD-ROM drive. In addition
  35624. + * to providing an example of a genuinely useful gadget driver for a USB
  35625. + * device, it also illustrates a technique of double-buffering for increased
  35626. + * throughput. Last but not least, it gives an easy way to probe the
  35627. + * behavior of the Mass Storage drivers in a USB host.
  35628. + *
  35629. + * Backing storage is provided by a regular file or a block device, specified
  35630. + * by the "file" module parameter. Access can be limited to read-only by
  35631. + * setting the optional "ro" module parameter. (For CD-ROM emulation,
  35632. + * access is always read-only.) The gadget will indicate that it has
  35633. + * removable media if the optional "removable" module parameter is set.
  35634. + *
  35635. + * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
  35636. + * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
  35637. + * by the optional "transport" module parameter. It also supports the
  35638. + * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
  35639. + * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
  35640. + * the optional "protocol" module parameter. In addition, the default
  35641. + * Vendor ID, Product ID, release number and serial number can be overridden.
  35642. + *
  35643. + * There is support for multiple logical units (LUNs), each of which has
  35644. + * its own backing file. The number of LUNs can be set using the optional
  35645. + * "luns" module parameter (anywhere from 1 to 8), and the corresponding
  35646. + * files are specified using comma-separated lists for "file" and "ro".
  35647. + * The default number of LUNs is taken from the number of "file" elements;
  35648. + * it is 1 if "file" is not given. If "removable" is not set then a backing
  35649. + * file must be specified for each LUN. If it is set, then an unspecified
  35650. + * or empty backing filename means the LUN's medium is not loaded. Ideally
  35651. + * each LUN would be settable independently as a disk drive or a CD-ROM
  35652. + * drive, but currently all LUNs have to be the same type. The CD-ROM
  35653. + * emulation includes a single data track and no audio tracks; hence there
  35654. + * need be only one backing file per LUN.
  35655. + *
  35656. + * Requirements are modest; only a bulk-in and a bulk-out endpoint are
  35657. + * needed (an interrupt-out endpoint is also needed for CBI). The memory
  35658. + * requirement amounts to two 16K buffers, size configurable by a parameter.
  35659. + * Support is included for both full-speed and high-speed operation.
  35660. + *
  35661. + * Note that the driver is slightly non-portable in that it assumes a
  35662. + * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
  35663. + * interrupt-in endpoints. With most device controllers this isn't an
  35664. + * issue, but there may be some with hardware restrictions that prevent
  35665. + * a buffer from being used by more than one endpoint.
  35666. + *
  35667. + * Module options:
  35668. + *
  35669. + * file=filename[,filename...]
  35670. + * Required if "removable" is not set, names of
  35671. + * the files or block devices used for
  35672. + * backing storage
  35673. + * serial=HHHH... Required serial number (string of hex chars)
  35674. + * ro=b[,b...] Default false, booleans for read-only access
  35675. + * removable Default false, boolean for removable media
  35676. + * luns=N Default N = number of filenames, number of
  35677. + * LUNs to support
  35678. + * nofua=b[,b...] Default false, booleans for ignore FUA flag
  35679. + * in SCSI WRITE(10,12) commands
  35680. + * stall Default determined according to the type of
  35681. + * USB device controller (usually true),
  35682. + * boolean to permit the driver to halt
  35683. + * bulk endpoints
  35684. + * cdrom Default false, boolean for whether to emulate
  35685. + * a CD-ROM drive
  35686. + * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
  35687. + * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
  35688. + * ATAPI, QIC, UFI, 8070, or SCSI;
  35689. + * also 1 - 6)
  35690. + * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
  35691. + * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
  35692. + * release=0xRRRR Override the USB release number (bcdDevice)
  35693. + * buflen=N Default N=16384, buffer size used (will be
  35694. + * rounded down to a multiple of
  35695. + * PAGE_CACHE_SIZE)
  35696. + *
  35697. + * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
  35698. + * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
  35699. + * default values are used for everything else.
  35700. + *
  35701. + * The pathnames of the backing files and the ro settings are available in
  35702. + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
  35703. + * the gadget's sysfs directory. If the "removable" option is set, writing to
  35704. + * these files will simulate ejecting/loading the medium (writing an empty
  35705. + * line means eject) and adjusting a write-enable tab. Changes to the ro
  35706. + * setting are not allowed when the medium is loaded or if CD-ROM emulation
  35707. + * is being used.
  35708. + *
  35709. + * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
  35710. + * The driver's SCSI command interface was based on the "Information
  35711. + * technology - Small Computer System Interface - 2" document from
  35712. + * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
  35713. + * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
  35714. + * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
  35715. + * "Universal Serial Bus Mass Storage Class UFI Command Specification"
  35716. + * document, Revision 1.0, December 14, 1998, available at
  35717. + * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
  35718. + */
  35719. +
  35720. +
  35721. +/*
  35722. + * Driver Design
  35723. + *
  35724. + * The FSG driver is fairly straightforward. There is a main kernel
  35725. + * thread that handles most of the work. Interrupt routines field
  35726. + * callbacks from the controller driver: bulk- and interrupt-request
  35727. + * completion notifications, endpoint-0 events, and disconnect events.
  35728. + * Completion events are passed to the main thread by wakeup calls. Many
  35729. + * ep0 requests are handled at interrupt time, but SetInterface,
  35730. + * SetConfiguration, and device reset requests are forwarded to the
  35731. + * thread in the form of "exceptions" using SIGUSR1 signals (since they
  35732. + * should interrupt any ongoing file I/O operations).
  35733. + *
  35734. + * The thread's main routine implements the standard command/data/status
  35735. + * parts of a SCSI interaction. It and its subroutines are full of tests
  35736. + * for pending signals/exceptions -- all this polling is necessary since
  35737. + * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
  35738. + * indication that the driver really wants to be running in userspace.)
  35739. + * An important point is that so long as the thread is alive it keeps an
  35740. + * open reference to the backing file. This will prevent unmounting
  35741. + * the backing file's underlying filesystem and could cause problems
  35742. + * during system shutdown, for example. To prevent such problems, the
  35743. + * thread catches INT, TERM, and KILL signals and converts them into
  35744. + * an EXIT exception.
  35745. + *
  35746. + * In normal operation the main thread is started during the gadget's
  35747. + * fsg_bind() callback and stopped during fsg_unbind(). But it can also
  35748. + * exit when it receives a signal, and there's no point leaving the
  35749. + * gadget running when the thread is dead. So just before the thread
  35750. + * exits, it deregisters the gadget driver. This makes things a little
  35751. + * tricky: The driver is deregistered at two places, and the exiting
  35752. + * thread can indirectly call fsg_unbind() which in turn can tell the
  35753. + * thread to exit. The first problem is resolved through the use of the
  35754. + * REGISTERED atomic bitflag; the driver will only be deregistered once.
  35755. + * The second problem is resolved by having fsg_unbind() check
  35756. + * fsg->state; it won't try to stop the thread if the state is already
  35757. + * FSG_STATE_TERMINATED.
  35758. + *
  35759. + * To provide maximum throughput, the driver uses a circular pipeline of
  35760. + * buffer heads (struct fsg_buffhd). In principle the pipeline can be
  35761. + * arbitrarily long; in practice the benefits don't justify having more
  35762. + * than 2 stages (i.e., double buffering). But it helps to think of the
  35763. + * pipeline as being a long one. Each buffer head contains a bulk-in and
  35764. + * a bulk-out request pointer (since the buffer can be used for both
  35765. + * output and input -- directions always are given from the host's
  35766. + * point of view) as well as a pointer to the buffer and various state
  35767. + * variables.
  35768. + *
  35769. + * Use of the pipeline follows a simple protocol. There is a variable
  35770. + * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
  35771. + * At any time that buffer head may still be in use from an earlier
  35772. + * request, so each buffer head has a state variable indicating whether
  35773. + * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
  35774. + * buffer head to be EMPTY, filling the buffer either by file I/O or by
  35775. + * USB I/O (during which the buffer head is BUSY), and marking the buffer
  35776. + * head FULL when the I/O is complete. Then the buffer will be emptied
  35777. + * (again possibly by USB I/O, during which it is marked BUSY) and
  35778. + * finally marked EMPTY again (possibly by a completion routine).
  35779. + *
  35780. + * A module parameter tells the driver to avoid stalling the bulk
  35781. + * endpoints wherever the transport specification allows. This is
  35782. + * necessary for some UDCs like the SuperH, which cannot reliably clear a
  35783. + * halt on a bulk endpoint. However, under certain circumstances the
  35784. + * Bulk-only specification requires a stall. In such cases the driver
  35785. + * will halt the endpoint and set a flag indicating that it should clear
  35786. + * the halt in software during the next device reset. Hopefully this
  35787. + * will permit everything to work correctly. Furthermore, although the
  35788. + * specification allows the bulk-out endpoint to halt when the host sends
  35789. + * too much data, implementing this would cause an unavoidable race.
  35790. + * The driver will always use the "no-stall" approach for OUT transfers.
  35791. + *
  35792. + * One subtle point concerns sending status-stage responses for ep0
  35793. + * requests. Some of these requests, such as device reset, can involve
  35794. + * interrupting an ongoing file I/O operation, which might take an
  35795. + * arbitrarily long time. During that delay the host might give up on
  35796. + * the original ep0 request and issue a new one. When that happens the
  35797. + * driver should not notify the host about completion of the original
  35798. + * request, as the host will no longer be waiting for it. So the driver
  35799. + * assigns to each ep0 request a unique tag, and it keeps track of the
  35800. + * tag value of the request associated with a long-running exception
  35801. + * (device-reset, interface-change, or configuration-change). When the
  35802. + * exception handler is finished, the status-stage response is submitted
  35803. + * only if the current ep0 request tag is equal to the exception request
  35804. + * tag. Thus only the most recently received ep0 request will get a
  35805. + * status-stage response.
  35806. + *
  35807. + * Warning: This driver source file is too long. It ought to be split up
  35808. + * into a header file plus about 3 separate .c files, to handle the details
  35809. + * of the Gadget, USB Mass Storage, and SCSI protocols.
  35810. + */
  35811. +
  35812. +
  35813. +/* #define VERBOSE_DEBUG */
  35814. +/* #define DUMP_MSGS */
  35815. +
  35816. +
  35817. +#include <linux/blkdev.h>
  35818. +#include <linux/completion.h>
  35819. +#include <linux/dcache.h>
  35820. +#include <linux/delay.h>
  35821. +#include <linux/device.h>
  35822. +#include <linux/fcntl.h>
  35823. +#include <linux/file.h>
  35824. +#include <linux/fs.h>
  35825. +#include <linux/kref.h>
  35826. +#include <linux/kthread.h>
  35827. +#include <linux/limits.h>
  35828. +#include <linux/module.h>
  35829. +#include <linux/rwsem.h>
  35830. +#include <linux/slab.h>
  35831. +#include <linux/spinlock.h>
  35832. +#include <linux/string.h>
  35833. +#include <linux/freezer.h>
  35834. +#include <linux/utsname.h>
  35835. +
  35836. +#include <linux/usb/ch9.h>
  35837. +#include <linux/usb/gadget.h>
  35838. +
  35839. +#include "gadget_chips.h"
  35840. +
  35841. +
  35842. +
  35843. +/*
  35844. + * Kbuild is not very cooperative with respect to linking separately
  35845. + * compiled library objects into one module. So for now we won't use
  35846. + * separate compilation ... ensuring init/exit sections work to shrink
  35847. + * the runtime footprint, and giving us at least some parts of what
  35848. + * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  35849. + */
  35850. +#include "usbstring.c"
  35851. +#include "config.c"
  35852. +#include "epautoconf.c"
  35853. +
  35854. +/*-------------------------------------------------------------------------*/
  35855. +
  35856. +#define DRIVER_DESC "File-backed Storage Gadget"
  35857. +#define DRIVER_NAME "g_file_storage"
  35858. +#define DRIVER_VERSION "1 September 2010"
  35859. +
  35860. +static char fsg_string_manufacturer[64];
  35861. +static const char fsg_string_product[] = DRIVER_DESC;
  35862. +static const char fsg_string_config[] = "Self-powered";
  35863. +static const char fsg_string_interface[] = "Mass Storage";
  35864. +
  35865. +
  35866. +#include "storage_common.c"
  35867. +
  35868. +
  35869. +MODULE_DESCRIPTION(DRIVER_DESC);
  35870. +MODULE_AUTHOR("Alan Stern");
  35871. +MODULE_LICENSE("Dual BSD/GPL");
  35872. +
  35873. +/*
  35874. + * This driver assumes self-powered hardware and has no way for users to
  35875. + * trigger remote wakeup. It uses autoconfiguration to select endpoints
  35876. + * and endpoint addresses.
  35877. + */
  35878. +
  35879. +
  35880. +/*-------------------------------------------------------------------------*/
  35881. +
  35882. +
  35883. +/* Encapsulate the module parameter settings */
  35884. +
  35885. +static struct {
  35886. + char *file[FSG_MAX_LUNS];
  35887. + char *serial;
  35888. + bool ro[FSG_MAX_LUNS];
  35889. + bool nofua[FSG_MAX_LUNS];
  35890. + unsigned int num_filenames;
  35891. + unsigned int num_ros;
  35892. + unsigned int num_nofuas;
  35893. + unsigned int nluns;
  35894. +
  35895. + bool removable;
  35896. + bool can_stall;
  35897. + bool cdrom;
  35898. +
  35899. + char *transport_parm;
  35900. + char *protocol_parm;
  35901. + unsigned short vendor;
  35902. + unsigned short product;
  35903. + unsigned short release;
  35904. + unsigned int buflen;
  35905. +
  35906. + int transport_type;
  35907. + char *transport_name;
  35908. + int protocol_type;
  35909. + char *protocol_name;
  35910. +
  35911. +} mod_data = { // Default values
  35912. + .transport_parm = "BBB",
  35913. + .protocol_parm = "SCSI",
  35914. + .removable = 0,
  35915. + .can_stall = 1,
  35916. + .cdrom = 0,
  35917. + .vendor = FSG_VENDOR_ID,
  35918. + .product = FSG_PRODUCT_ID,
  35919. + .release = 0xffff, // Use controller chip type
  35920. + .buflen = 16384,
  35921. + };
  35922. +
  35923. +
  35924. +module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
  35925. + S_IRUGO);
  35926. +MODULE_PARM_DESC(file, "names of backing files or devices");
  35927. +
  35928. +module_param_named(serial, mod_data.serial, charp, S_IRUGO);
  35929. +MODULE_PARM_DESC(serial, "USB serial number");
  35930. +
  35931. +module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
  35932. +MODULE_PARM_DESC(ro, "true to force read-only");
  35933. +
  35934. +module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
  35935. + S_IRUGO);
  35936. +MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
  35937. +
  35938. +module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
  35939. +MODULE_PARM_DESC(luns, "number of LUNs");
  35940. +
  35941. +module_param_named(removable, mod_data.removable, bool, S_IRUGO);
  35942. +MODULE_PARM_DESC(removable, "true to simulate removable media");
  35943. +
  35944. +module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
  35945. +MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
  35946. +
  35947. +module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
  35948. +MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
  35949. +
  35950. +/* In the non-TEST version, only the module parameters listed above
  35951. + * are available. */
  35952. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35953. +
  35954. +module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
  35955. +MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
  35956. +
  35957. +module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
  35958. +MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
  35959. + "8070, or SCSI)");
  35960. +
  35961. +module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
  35962. +MODULE_PARM_DESC(vendor, "USB Vendor ID");
  35963. +
  35964. +module_param_named(product, mod_data.product, ushort, S_IRUGO);
  35965. +MODULE_PARM_DESC(product, "USB Product ID");
  35966. +
  35967. +module_param_named(release, mod_data.release, ushort, S_IRUGO);
  35968. +MODULE_PARM_DESC(release, "USB release number");
  35969. +
  35970. +module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
  35971. +MODULE_PARM_DESC(buflen, "I/O buffer size");
  35972. +
  35973. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35974. +
  35975. +
  35976. +/*
  35977. + * These definitions will permit the compiler to avoid generating code for
  35978. + * parts of the driver that aren't used in the non-TEST version. Even gcc
  35979. + * can recognize when a test of a constant expression yields a dead code
  35980. + * path.
  35981. + */
  35982. +
  35983. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35984. +
  35985. +#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
  35986. +#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
  35987. +#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
  35988. +
  35989. +#else
  35990. +
  35991. +#define transport_is_bbb() 1
  35992. +#define transport_is_cbi() 0
  35993. +#define protocol_is_scsi() 1
  35994. +
  35995. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35996. +
  35997. +
  35998. +/*-------------------------------------------------------------------------*/
  35999. +
  36000. +
  36001. +struct fsg_dev {
  36002. + /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
  36003. + spinlock_t lock;
  36004. + struct usb_gadget *gadget;
  36005. +
  36006. + /* filesem protects: backing files in use */
  36007. + struct rw_semaphore filesem;
  36008. +
  36009. + /* reference counting: wait until all LUNs are released */
  36010. + struct kref ref;
  36011. +
  36012. + struct usb_ep *ep0; // Handy copy of gadget->ep0
  36013. + struct usb_request *ep0req; // For control responses
  36014. + unsigned int ep0_req_tag;
  36015. + const char *ep0req_name;
  36016. +
  36017. + struct usb_request *intreq; // For interrupt responses
  36018. + int intreq_busy;
  36019. + struct fsg_buffhd *intr_buffhd;
  36020. +
  36021. + unsigned int bulk_out_maxpacket;
  36022. + enum fsg_state state; // For exception handling
  36023. + unsigned int exception_req_tag;
  36024. +
  36025. + u8 config, new_config;
  36026. +
  36027. + unsigned int running : 1;
  36028. + unsigned int bulk_in_enabled : 1;
  36029. + unsigned int bulk_out_enabled : 1;
  36030. + unsigned int intr_in_enabled : 1;
  36031. + unsigned int phase_error : 1;
  36032. + unsigned int short_packet_received : 1;
  36033. + unsigned int bad_lun_okay : 1;
  36034. +
  36035. + unsigned long atomic_bitflags;
  36036. +#define REGISTERED 0
  36037. +#define IGNORE_BULK_OUT 1
  36038. +#define SUSPENDED 2
  36039. +
  36040. + struct usb_ep *bulk_in;
  36041. + struct usb_ep *bulk_out;
  36042. + struct usb_ep *intr_in;
  36043. +
  36044. + struct fsg_buffhd *next_buffhd_to_fill;
  36045. + struct fsg_buffhd *next_buffhd_to_drain;
  36046. +
  36047. + int thread_wakeup_needed;
  36048. + struct completion thread_notifier;
  36049. + struct task_struct *thread_task;
  36050. +
  36051. + int cmnd_size;
  36052. + u8 cmnd[MAX_COMMAND_SIZE];
  36053. + enum data_direction data_dir;
  36054. + u32 data_size;
  36055. + u32 data_size_from_cmnd;
  36056. + u32 tag;
  36057. + unsigned int lun;
  36058. + u32 residue;
  36059. + u32 usb_amount_left;
  36060. +
  36061. + /* The CB protocol offers no way for a host to know when a command
  36062. + * has completed. As a result the next command may arrive early,
  36063. + * and we will still have to handle it. For that reason we need
  36064. + * a buffer to store new commands when using CB (or CBI, which
  36065. + * does not oblige a host to wait for command completion either). */
  36066. + int cbbuf_cmnd_size;
  36067. + u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
  36068. +
  36069. + unsigned int nluns;
  36070. + struct fsg_lun *luns;
  36071. + struct fsg_lun *curlun;
  36072. + /* Must be the last entry */
  36073. + struct fsg_buffhd buffhds[];
  36074. +};
  36075. +
  36076. +typedef void (*fsg_routine_t)(struct fsg_dev *);
  36077. +
  36078. +static int exception_in_progress(struct fsg_dev *fsg)
  36079. +{
  36080. + return (fsg->state > FSG_STATE_IDLE);
  36081. +}
  36082. +
  36083. +/* Make bulk-out requests be divisible by the maxpacket size */
  36084. +static void set_bulk_out_req_length(struct fsg_dev *fsg,
  36085. + struct fsg_buffhd *bh, unsigned int length)
  36086. +{
  36087. + unsigned int rem;
  36088. +
  36089. + bh->bulk_out_intended_length = length;
  36090. + rem = length % fsg->bulk_out_maxpacket;
  36091. + if (rem > 0)
  36092. + length += fsg->bulk_out_maxpacket - rem;
  36093. + bh->outreq->length = length;
  36094. +}
  36095. +
  36096. +static struct fsg_dev *the_fsg;
  36097. +static struct usb_gadget_driver fsg_driver;
  36098. +
  36099. +
  36100. +/*-------------------------------------------------------------------------*/
  36101. +
  36102. +static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
  36103. +{
  36104. + const char *name;
  36105. +
  36106. + if (ep == fsg->bulk_in)
  36107. + name = "bulk-in";
  36108. + else if (ep == fsg->bulk_out)
  36109. + name = "bulk-out";
  36110. + else
  36111. + name = ep->name;
  36112. + DBG(fsg, "%s set halt\n", name);
  36113. + return usb_ep_set_halt(ep);
  36114. +}
  36115. +
  36116. +
  36117. +/*-------------------------------------------------------------------------*/
  36118. +
  36119. +/*
  36120. + * DESCRIPTORS ... most are static, but strings and (full) configuration
  36121. + * descriptors are built on demand. Also the (static) config and interface
  36122. + * descriptors are adjusted during fsg_bind().
  36123. + */
  36124. +
  36125. +/* There is only one configuration. */
  36126. +#define CONFIG_VALUE 1
  36127. +
  36128. +static struct usb_device_descriptor
  36129. +device_desc = {
  36130. + .bLength = sizeof device_desc,
  36131. + .bDescriptorType = USB_DT_DEVICE,
  36132. +
  36133. + .bcdUSB = cpu_to_le16(0x0200),
  36134. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  36135. +
  36136. + /* The next three values can be overridden by module parameters */
  36137. + .idVendor = cpu_to_le16(FSG_VENDOR_ID),
  36138. + .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
  36139. + .bcdDevice = cpu_to_le16(0xffff),
  36140. +
  36141. + .iManufacturer = FSG_STRING_MANUFACTURER,
  36142. + .iProduct = FSG_STRING_PRODUCT,
  36143. + .iSerialNumber = FSG_STRING_SERIAL,
  36144. + .bNumConfigurations = 1,
  36145. +};
  36146. +
  36147. +static struct usb_config_descriptor
  36148. +config_desc = {
  36149. + .bLength = sizeof config_desc,
  36150. + .bDescriptorType = USB_DT_CONFIG,
  36151. +
  36152. + /* wTotalLength computed by usb_gadget_config_buf() */
  36153. + .bNumInterfaces = 1,
  36154. + .bConfigurationValue = CONFIG_VALUE,
  36155. + .iConfiguration = FSG_STRING_CONFIG,
  36156. + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
  36157. + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
  36158. +};
  36159. +
  36160. +
  36161. +static struct usb_qualifier_descriptor
  36162. +dev_qualifier = {
  36163. + .bLength = sizeof dev_qualifier,
  36164. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  36165. +
  36166. + .bcdUSB = cpu_to_le16(0x0200),
  36167. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  36168. +
  36169. + .bNumConfigurations = 1,
  36170. +};
  36171. +
  36172. +static int populate_bos(struct fsg_dev *fsg, u8 *buf)
  36173. +{
  36174. + memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE);
  36175. + buf += USB_DT_BOS_SIZE;
  36176. +
  36177. + memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE);
  36178. + buf += USB_DT_USB_EXT_CAP_SIZE;
  36179. +
  36180. + memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE);
  36181. +
  36182. + return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE
  36183. + + USB_DT_USB_EXT_CAP_SIZE;
  36184. +}
  36185. +
  36186. +/*
  36187. + * Config descriptors must agree with the code that sets configurations
  36188. + * and with code managing interfaces and their altsettings. They must
  36189. + * also handle different speeds and other-speed requests.
  36190. + */
  36191. +static int populate_config_buf(struct usb_gadget *gadget,
  36192. + u8 *buf, u8 type, unsigned index)
  36193. +{
  36194. + enum usb_device_speed speed = gadget->speed;
  36195. + int len;
  36196. + const struct usb_descriptor_header **function;
  36197. +
  36198. + if (index > 0)
  36199. + return -EINVAL;
  36200. +
  36201. + if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
  36202. + speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
  36203. + function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
  36204. + ? (const struct usb_descriptor_header **)fsg_hs_function
  36205. + : (const struct usb_descriptor_header **)fsg_fs_function;
  36206. +
  36207. + /* for now, don't advertise srp-only devices */
  36208. + if (!gadget_is_otg(gadget))
  36209. + function++;
  36210. +
  36211. + len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
  36212. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  36213. + return len;
  36214. +}
  36215. +
  36216. +
  36217. +/*-------------------------------------------------------------------------*/
  36218. +
  36219. +/* These routines may be called in process context or in_irq */
  36220. +
  36221. +/* Caller must hold fsg->lock */
  36222. +static void wakeup_thread(struct fsg_dev *fsg)
  36223. +{
  36224. + /* Tell the main thread that something has happened */
  36225. + fsg->thread_wakeup_needed = 1;
  36226. + if (fsg->thread_task)
  36227. + wake_up_process(fsg->thread_task);
  36228. +}
  36229. +
  36230. +
  36231. +static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
  36232. +{
  36233. + unsigned long flags;
  36234. +
  36235. + /* Do nothing if a higher-priority exception is already in progress.
  36236. + * If a lower-or-equal priority exception is in progress, preempt it
  36237. + * and notify the main thread by sending it a signal. */
  36238. + spin_lock_irqsave(&fsg->lock, flags);
  36239. + if (fsg->state <= new_state) {
  36240. + fsg->exception_req_tag = fsg->ep0_req_tag;
  36241. + fsg->state = new_state;
  36242. + if (fsg->thread_task)
  36243. + send_sig_info(SIGUSR1, SEND_SIG_FORCED,
  36244. + fsg->thread_task);
  36245. + }
  36246. + spin_unlock_irqrestore(&fsg->lock, flags);
  36247. +}
  36248. +
  36249. +
  36250. +/*-------------------------------------------------------------------------*/
  36251. +
  36252. +/* The disconnect callback and ep0 routines. These always run in_irq,
  36253. + * except that ep0_queue() is called in the main thread to acknowledge
  36254. + * completion of various requests: set config, set interface, and
  36255. + * Bulk-only device reset. */
  36256. +
  36257. +static void fsg_disconnect(struct usb_gadget *gadget)
  36258. +{
  36259. + struct fsg_dev *fsg = get_gadget_data(gadget);
  36260. +
  36261. + DBG(fsg, "disconnect or port reset\n");
  36262. + raise_exception(fsg, FSG_STATE_DISCONNECT);
  36263. +}
  36264. +
  36265. +
  36266. +static int ep0_queue(struct fsg_dev *fsg)
  36267. +{
  36268. + int rc;
  36269. +
  36270. + rc = usb_ep_queue(fsg->ep0, fsg->ep0req, GFP_ATOMIC);
  36271. + if (rc != 0 && rc != -ESHUTDOWN) {
  36272. +
  36273. + /* We can't do much more than wait for a reset */
  36274. + WARNING(fsg, "error in submission: %s --> %d\n",
  36275. + fsg->ep0->name, rc);
  36276. + }
  36277. + return rc;
  36278. +}
  36279. +
  36280. +static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
  36281. +{
  36282. + struct fsg_dev *fsg = ep->driver_data;
  36283. +
  36284. + if (req->actual > 0)
  36285. + dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
  36286. + if (req->status || req->actual != req->length)
  36287. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36288. + req->status, req->actual, req->length);
  36289. + if (req->status == -ECONNRESET) // Request was cancelled
  36290. + usb_ep_fifo_flush(ep);
  36291. +
  36292. + if (req->status == 0 && req->context)
  36293. + ((fsg_routine_t) (req->context))(fsg);
  36294. +}
  36295. +
  36296. +
  36297. +/*-------------------------------------------------------------------------*/
  36298. +
  36299. +/* Bulk and interrupt endpoint completion handlers.
  36300. + * These always run in_irq. */
  36301. +
  36302. +static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
  36303. +{
  36304. + struct fsg_dev *fsg = ep->driver_data;
  36305. + struct fsg_buffhd *bh = req->context;
  36306. +
  36307. + if (req->status || req->actual != req->length)
  36308. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36309. + req->status, req->actual, req->length);
  36310. + if (req->status == -ECONNRESET) // Request was cancelled
  36311. + usb_ep_fifo_flush(ep);
  36312. +
  36313. + /* Hold the lock while we update the request and buffer states */
  36314. + smp_wmb();
  36315. + spin_lock(&fsg->lock);
  36316. + bh->inreq_busy = 0;
  36317. + bh->state = BUF_STATE_EMPTY;
  36318. + wakeup_thread(fsg);
  36319. + spin_unlock(&fsg->lock);
  36320. +}
  36321. +
  36322. +static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
  36323. +{
  36324. + struct fsg_dev *fsg = ep->driver_data;
  36325. + struct fsg_buffhd *bh = req->context;
  36326. +
  36327. + dump_msg(fsg, "bulk-out", req->buf, req->actual);
  36328. + if (req->status || req->actual != bh->bulk_out_intended_length)
  36329. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36330. + req->status, req->actual,
  36331. + bh->bulk_out_intended_length);
  36332. + if (req->status == -ECONNRESET) // Request was cancelled
  36333. + usb_ep_fifo_flush(ep);
  36334. +
  36335. + /* Hold the lock while we update the request and buffer states */
  36336. + smp_wmb();
  36337. + spin_lock(&fsg->lock);
  36338. + bh->outreq_busy = 0;
  36339. + bh->state = BUF_STATE_FULL;
  36340. + wakeup_thread(fsg);
  36341. + spin_unlock(&fsg->lock);
  36342. +}
  36343. +
  36344. +
  36345. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  36346. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  36347. +{
  36348. + struct fsg_dev *fsg = ep->driver_data;
  36349. + struct fsg_buffhd *bh = req->context;
  36350. +
  36351. + if (req->status || req->actual != req->length)
  36352. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36353. + req->status, req->actual, req->length);
  36354. + if (req->status == -ECONNRESET) // Request was cancelled
  36355. + usb_ep_fifo_flush(ep);
  36356. +
  36357. + /* Hold the lock while we update the request and buffer states */
  36358. + smp_wmb();
  36359. + spin_lock(&fsg->lock);
  36360. + fsg->intreq_busy = 0;
  36361. + bh->state = BUF_STATE_EMPTY;
  36362. + wakeup_thread(fsg);
  36363. + spin_unlock(&fsg->lock);
  36364. +}
  36365. +
  36366. +#else
  36367. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  36368. +{}
  36369. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  36370. +
  36371. +
  36372. +/*-------------------------------------------------------------------------*/
  36373. +
  36374. +/* Ep0 class-specific handlers. These always run in_irq. */
  36375. +
  36376. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  36377. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36378. +{
  36379. + struct usb_request *req = fsg->ep0req;
  36380. + static u8 cbi_reset_cmnd[6] = {
  36381. + SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
  36382. +
  36383. + /* Error in command transfer? */
  36384. + if (req->status || req->length != req->actual ||
  36385. + req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
  36386. +
  36387. + /* Not all controllers allow a protocol stall after
  36388. + * receiving control-out data, but we'll try anyway. */
  36389. + fsg_set_halt(fsg, fsg->ep0);
  36390. + return; // Wait for reset
  36391. + }
  36392. +
  36393. + /* Is it the special reset command? */
  36394. + if (req->actual >= sizeof cbi_reset_cmnd &&
  36395. + memcmp(req->buf, cbi_reset_cmnd,
  36396. + sizeof cbi_reset_cmnd) == 0) {
  36397. +
  36398. + /* Raise an exception to stop the current operation
  36399. + * and reinitialize our state. */
  36400. + DBG(fsg, "cbi reset request\n");
  36401. + raise_exception(fsg, FSG_STATE_RESET);
  36402. + return;
  36403. + }
  36404. +
  36405. + VDBG(fsg, "CB[I] accept device-specific command\n");
  36406. + spin_lock(&fsg->lock);
  36407. +
  36408. + /* Save the command for later */
  36409. + if (fsg->cbbuf_cmnd_size)
  36410. + WARNING(fsg, "CB[I] overwriting previous command\n");
  36411. + fsg->cbbuf_cmnd_size = req->actual;
  36412. + memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
  36413. +
  36414. + wakeup_thread(fsg);
  36415. + spin_unlock(&fsg->lock);
  36416. +}
  36417. +
  36418. +#else
  36419. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36420. +{}
  36421. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  36422. +
  36423. +
  36424. +static int class_setup_req(struct fsg_dev *fsg,
  36425. + const struct usb_ctrlrequest *ctrl)
  36426. +{
  36427. + struct usb_request *req = fsg->ep0req;
  36428. + int value = -EOPNOTSUPP;
  36429. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  36430. + u16 w_value = le16_to_cpu(ctrl->wValue);
  36431. + u16 w_length = le16_to_cpu(ctrl->wLength);
  36432. +
  36433. + if (!fsg->config)
  36434. + return value;
  36435. +
  36436. + /* Handle Bulk-only class-specific requests */
  36437. + if (transport_is_bbb()) {
  36438. + switch (ctrl->bRequest) {
  36439. +
  36440. + case US_BULK_RESET_REQUEST:
  36441. + if (ctrl->bRequestType != (USB_DIR_OUT |
  36442. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  36443. + break;
  36444. + if (w_index != 0 || w_value != 0 || w_length != 0) {
  36445. + value = -EDOM;
  36446. + break;
  36447. + }
  36448. +
  36449. + /* Raise an exception to stop the current operation
  36450. + * and reinitialize our state. */
  36451. + DBG(fsg, "bulk reset request\n");
  36452. + raise_exception(fsg, FSG_STATE_RESET);
  36453. + value = DELAYED_STATUS;
  36454. + break;
  36455. +
  36456. + case US_BULK_GET_MAX_LUN:
  36457. + if (ctrl->bRequestType != (USB_DIR_IN |
  36458. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  36459. + break;
  36460. + if (w_index != 0 || w_value != 0 || w_length != 1) {
  36461. + value = -EDOM;
  36462. + break;
  36463. + }
  36464. + VDBG(fsg, "get max LUN\n");
  36465. + *(u8 *) req->buf = fsg->nluns - 1;
  36466. + value = 1;
  36467. + break;
  36468. + }
  36469. + }
  36470. +
  36471. + /* Handle CBI class-specific requests */
  36472. + else {
  36473. + switch (ctrl->bRequest) {
  36474. +
  36475. + case USB_CBI_ADSC_REQUEST:
  36476. + if (ctrl->bRequestType != (USB_DIR_OUT |
  36477. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  36478. + break;
  36479. + if (w_index != 0 || w_value != 0) {
  36480. + value = -EDOM;
  36481. + break;
  36482. + }
  36483. + if (w_length > MAX_COMMAND_SIZE) {
  36484. + value = -EOVERFLOW;
  36485. + break;
  36486. + }
  36487. + value = w_length;
  36488. + fsg->ep0req->context = received_cbi_adsc;
  36489. + break;
  36490. + }
  36491. + }
  36492. +
  36493. + if (value == -EOPNOTSUPP)
  36494. + VDBG(fsg,
  36495. + "unknown class-specific control req "
  36496. + "%02x.%02x v%04x i%04x l%u\n",
  36497. + ctrl->bRequestType, ctrl->bRequest,
  36498. + le16_to_cpu(ctrl->wValue), w_index, w_length);
  36499. + return value;
  36500. +}
  36501. +
  36502. +
  36503. +/*-------------------------------------------------------------------------*/
  36504. +
  36505. +/* Ep0 standard request handlers. These always run in_irq. */
  36506. +
  36507. +static int standard_setup_req(struct fsg_dev *fsg,
  36508. + const struct usb_ctrlrequest *ctrl)
  36509. +{
  36510. + struct usb_request *req = fsg->ep0req;
  36511. + int value = -EOPNOTSUPP;
  36512. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  36513. + u16 w_value = le16_to_cpu(ctrl->wValue);
  36514. +
  36515. + /* Usually this just stores reply data in the pre-allocated ep0 buffer,
  36516. + * but config change events will also reconfigure hardware. */
  36517. + switch (ctrl->bRequest) {
  36518. +
  36519. + case USB_REQ_GET_DESCRIPTOR:
  36520. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  36521. + USB_RECIP_DEVICE))
  36522. + break;
  36523. + switch (w_value >> 8) {
  36524. +
  36525. + case USB_DT_DEVICE:
  36526. + VDBG(fsg, "get device descriptor\n");
  36527. + device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
  36528. + value = sizeof device_desc;
  36529. + memcpy(req->buf, &device_desc, value);
  36530. + break;
  36531. + case USB_DT_DEVICE_QUALIFIER:
  36532. + VDBG(fsg, "get device qualifier\n");
  36533. + if (!gadget_is_dualspeed(fsg->gadget) ||
  36534. + fsg->gadget->speed == USB_SPEED_SUPER)
  36535. + break;
  36536. + /*
  36537. + * Assume ep0 uses the same maxpacket value for both
  36538. + * speeds
  36539. + */
  36540. + dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
  36541. + value = sizeof dev_qualifier;
  36542. + memcpy(req->buf, &dev_qualifier, value);
  36543. + break;
  36544. +
  36545. + case USB_DT_OTHER_SPEED_CONFIG:
  36546. + VDBG(fsg, "get other-speed config descriptor\n");
  36547. + if (!gadget_is_dualspeed(fsg->gadget) ||
  36548. + fsg->gadget->speed == USB_SPEED_SUPER)
  36549. + break;
  36550. + goto get_config;
  36551. + case USB_DT_CONFIG:
  36552. + VDBG(fsg, "get configuration descriptor\n");
  36553. +get_config:
  36554. + value = populate_config_buf(fsg->gadget,
  36555. + req->buf,
  36556. + w_value >> 8,
  36557. + w_value & 0xff);
  36558. + break;
  36559. +
  36560. + case USB_DT_STRING:
  36561. + VDBG(fsg, "get string descriptor\n");
  36562. +
  36563. + /* wIndex == language code */
  36564. + value = usb_gadget_get_string(&fsg_stringtab,
  36565. + w_value & 0xff, req->buf);
  36566. + break;
  36567. +
  36568. + case USB_DT_BOS:
  36569. + VDBG(fsg, "get bos descriptor\n");
  36570. +
  36571. + if (gadget_is_superspeed(fsg->gadget))
  36572. + value = populate_bos(fsg, req->buf);
  36573. + break;
  36574. + }
  36575. +
  36576. + break;
  36577. +
  36578. + /* One config, two speeds */
  36579. + case USB_REQ_SET_CONFIGURATION:
  36580. + if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD |
  36581. + USB_RECIP_DEVICE))
  36582. + break;
  36583. + VDBG(fsg, "set configuration\n");
  36584. + if (w_value == CONFIG_VALUE || w_value == 0) {
  36585. + fsg->new_config = w_value;
  36586. +
  36587. + /* Raise an exception to wipe out previous transaction
  36588. + * state (queued bufs, etc) and set the new config. */
  36589. + raise_exception(fsg, FSG_STATE_CONFIG_CHANGE);
  36590. + value = DELAYED_STATUS;
  36591. + }
  36592. + break;
  36593. + case USB_REQ_GET_CONFIGURATION:
  36594. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  36595. + USB_RECIP_DEVICE))
  36596. + break;
  36597. + VDBG(fsg, "get configuration\n");
  36598. + *(u8 *) req->buf = fsg->config;
  36599. + value = 1;
  36600. + break;
  36601. +
  36602. + case USB_REQ_SET_INTERFACE:
  36603. + if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD |
  36604. + USB_RECIP_INTERFACE))
  36605. + break;
  36606. + if (fsg->config && w_index == 0) {
  36607. +
  36608. + /* Raise an exception to wipe out previous transaction
  36609. + * state (queued bufs, etc) and install the new
  36610. + * interface altsetting. */
  36611. + raise_exception(fsg, FSG_STATE_INTERFACE_CHANGE);
  36612. + value = DELAYED_STATUS;
  36613. + }
  36614. + break;
  36615. + case USB_REQ_GET_INTERFACE:
  36616. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  36617. + USB_RECIP_INTERFACE))
  36618. + break;
  36619. + if (!fsg->config)
  36620. + break;
  36621. + if (w_index != 0) {
  36622. + value = -EDOM;
  36623. + break;
  36624. + }
  36625. + VDBG(fsg, "get interface\n");
  36626. + *(u8 *) req->buf = 0;
  36627. + value = 1;
  36628. + break;
  36629. +
  36630. + default:
  36631. + VDBG(fsg,
  36632. + "unknown control req %02x.%02x v%04x i%04x l%u\n",
  36633. + ctrl->bRequestType, ctrl->bRequest,
  36634. + w_value, w_index, le16_to_cpu(ctrl->wLength));
  36635. + }
  36636. +
  36637. + return value;
  36638. +}
  36639. +
  36640. +
  36641. +static int fsg_setup(struct usb_gadget *gadget,
  36642. + const struct usb_ctrlrequest *ctrl)
  36643. +{
  36644. + struct fsg_dev *fsg = get_gadget_data(gadget);
  36645. + int rc;
  36646. + int w_length = le16_to_cpu(ctrl->wLength);
  36647. +
  36648. + ++fsg->ep0_req_tag; // Record arrival of a new request
  36649. + fsg->ep0req->context = NULL;
  36650. + fsg->ep0req->length = 0;
  36651. + dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
  36652. +
  36653. + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
  36654. + rc = class_setup_req(fsg, ctrl);
  36655. + else
  36656. + rc = standard_setup_req(fsg, ctrl);
  36657. +
  36658. + /* Respond with data/status or defer until later? */
  36659. + if (rc >= 0 && rc != DELAYED_STATUS) {
  36660. + rc = min(rc, w_length);
  36661. + fsg->ep0req->length = rc;
  36662. + fsg->ep0req->zero = rc < w_length;
  36663. + fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
  36664. + "ep0-in" : "ep0-out");
  36665. + rc = ep0_queue(fsg);
  36666. + }
  36667. +
  36668. + /* Device either stalls (rc < 0) or reports success */
  36669. + return rc;
  36670. +}
  36671. +
  36672. +
  36673. +/*-------------------------------------------------------------------------*/
  36674. +
  36675. +/* All the following routines run in process context */
  36676. +
  36677. +
  36678. +/* Use this for bulk or interrupt transfers, not ep0 */
  36679. +static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
  36680. + struct usb_request *req, int *pbusy,
  36681. + enum fsg_buffer_state *state)
  36682. +{
  36683. + int rc;
  36684. +
  36685. + if (ep == fsg->bulk_in)
  36686. + dump_msg(fsg, "bulk-in", req->buf, req->length);
  36687. + else if (ep == fsg->intr_in)
  36688. + dump_msg(fsg, "intr-in", req->buf, req->length);
  36689. +
  36690. + spin_lock_irq(&fsg->lock);
  36691. + *pbusy = 1;
  36692. + *state = BUF_STATE_BUSY;
  36693. + spin_unlock_irq(&fsg->lock);
  36694. + rc = usb_ep_queue(ep, req, GFP_KERNEL);
  36695. + if (rc != 0) {
  36696. + *pbusy = 0;
  36697. + *state = BUF_STATE_EMPTY;
  36698. +
  36699. + /* We can't do much more than wait for a reset */
  36700. +
  36701. + /* Note: currently the net2280 driver fails zero-length
  36702. + * submissions if DMA is enabled. */
  36703. + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
  36704. + req->length == 0))
  36705. + WARNING(fsg, "error in submission: %s --> %d\n",
  36706. + ep->name, rc);
  36707. + }
  36708. +}
  36709. +
  36710. +
  36711. +static int sleep_thread(struct fsg_dev *fsg)
  36712. +{
  36713. + int rc = 0;
  36714. +
  36715. + /* Wait until a signal arrives or we are woken up */
  36716. + for (;;) {
  36717. + try_to_freeze();
  36718. + set_current_state(TASK_INTERRUPTIBLE);
  36719. + if (signal_pending(current)) {
  36720. + rc = -EINTR;
  36721. + break;
  36722. + }
  36723. + if (fsg->thread_wakeup_needed)
  36724. + break;
  36725. + schedule();
  36726. + }
  36727. + __set_current_state(TASK_RUNNING);
  36728. + fsg->thread_wakeup_needed = 0;
  36729. + return rc;
  36730. +}
  36731. +
  36732. +
  36733. +/*-------------------------------------------------------------------------*/
  36734. +
  36735. +static int do_read(struct fsg_dev *fsg)
  36736. +{
  36737. + struct fsg_lun *curlun = fsg->curlun;
  36738. + u32 lba;
  36739. + struct fsg_buffhd *bh;
  36740. + int rc;
  36741. + u32 amount_left;
  36742. + loff_t file_offset, file_offset_tmp;
  36743. + unsigned int amount;
  36744. + ssize_t nread;
  36745. +
  36746. + /* Get the starting Logical Block Address and check that it's
  36747. + * not too big */
  36748. + if (fsg->cmnd[0] == READ_6)
  36749. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  36750. + else {
  36751. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36752. +
  36753. + /* We allow DPO (Disable Page Out = don't save data in the
  36754. + * cache) and FUA (Force Unit Access = don't read from the
  36755. + * cache), but we don't implement them. */
  36756. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  36757. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36758. + return -EINVAL;
  36759. + }
  36760. + }
  36761. + if (lba >= curlun->num_sectors) {
  36762. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36763. + return -EINVAL;
  36764. + }
  36765. + file_offset = ((loff_t) lba) << curlun->blkbits;
  36766. +
  36767. + /* Carry out the file reads */
  36768. + amount_left = fsg->data_size_from_cmnd;
  36769. + if (unlikely(amount_left == 0))
  36770. + return -EIO; // No default reply
  36771. +
  36772. + for (;;) {
  36773. +
  36774. + /* Figure out how much we need to read:
  36775. + * Try to read the remaining amount.
  36776. + * But don't read more than the buffer size.
  36777. + * And don't try to read past the end of the file.
  36778. + */
  36779. + amount = min((unsigned int) amount_left, mod_data.buflen);
  36780. + amount = min((loff_t) amount,
  36781. + curlun->file_length - file_offset);
  36782. +
  36783. + /* Wait for the next buffer to become available */
  36784. + bh = fsg->next_buffhd_to_fill;
  36785. + while (bh->state != BUF_STATE_EMPTY) {
  36786. + rc = sleep_thread(fsg);
  36787. + if (rc)
  36788. + return rc;
  36789. + }
  36790. +
  36791. + /* If we were asked to read past the end of file,
  36792. + * end with an empty buffer. */
  36793. + if (amount == 0) {
  36794. + curlun->sense_data =
  36795. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36796. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36797. + curlun->info_valid = 1;
  36798. + bh->inreq->length = 0;
  36799. + bh->state = BUF_STATE_FULL;
  36800. + break;
  36801. + }
  36802. +
  36803. + /* Perform the read */
  36804. + file_offset_tmp = file_offset;
  36805. + nread = vfs_read(curlun->filp,
  36806. + (char __user *) bh->buf,
  36807. + amount, &file_offset_tmp);
  36808. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  36809. + (unsigned long long) file_offset,
  36810. + (int) nread);
  36811. + if (signal_pending(current))
  36812. + return -EINTR;
  36813. +
  36814. + if (nread < 0) {
  36815. + LDBG(curlun, "error in file read: %d\n",
  36816. + (int) nread);
  36817. + nread = 0;
  36818. + } else if (nread < amount) {
  36819. + LDBG(curlun, "partial file read: %d/%u\n",
  36820. + (int) nread, amount);
  36821. + nread = round_down(nread, curlun->blksize);
  36822. + }
  36823. + file_offset += nread;
  36824. + amount_left -= nread;
  36825. + fsg->residue -= nread;
  36826. +
  36827. + /* Except at the end of the transfer, nread will be
  36828. + * equal to the buffer size, which is divisible by the
  36829. + * bulk-in maxpacket size.
  36830. + */
  36831. + bh->inreq->length = nread;
  36832. + bh->state = BUF_STATE_FULL;
  36833. +
  36834. + /* If an error occurred, report it and its position */
  36835. + if (nread < amount) {
  36836. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  36837. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36838. + curlun->info_valid = 1;
  36839. + break;
  36840. + }
  36841. +
  36842. + if (amount_left == 0)
  36843. + break; // No more left to read
  36844. +
  36845. + /* Send this buffer and go read some more */
  36846. + bh->inreq->zero = 0;
  36847. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36848. + &bh->inreq_busy, &bh->state);
  36849. + fsg->next_buffhd_to_fill = bh->next;
  36850. + }
  36851. +
  36852. + return -EIO; // No default reply
  36853. +}
  36854. +
  36855. +
  36856. +/*-------------------------------------------------------------------------*/
  36857. +
  36858. +static int do_write(struct fsg_dev *fsg)
  36859. +{
  36860. + struct fsg_lun *curlun = fsg->curlun;
  36861. + u32 lba;
  36862. + struct fsg_buffhd *bh;
  36863. + int get_some_more;
  36864. + u32 amount_left_to_req, amount_left_to_write;
  36865. + loff_t usb_offset, file_offset, file_offset_tmp;
  36866. + unsigned int amount;
  36867. + ssize_t nwritten;
  36868. + int rc;
  36869. +
  36870. + if (curlun->ro) {
  36871. + curlun->sense_data = SS_WRITE_PROTECTED;
  36872. + return -EINVAL;
  36873. + }
  36874. + spin_lock(&curlun->filp->f_lock);
  36875. + curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
  36876. + spin_unlock(&curlun->filp->f_lock);
  36877. +
  36878. + /* Get the starting Logical Block Address and check that it's
  36879. + * not too big */
  36880. + if (fsg->cmnd[0] == WRITE_6)
  36881. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  36882. + else {
  36883. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36884. +
  36885. + /* We allow DPO (Disable Page Out = don't save data in the
  36886. + * cache) and FUA (Force Unit Access = write directly to the
  36887. + * medium). We don't implement DPO; we implement FUA by
  36888. + * performing synchronous output. */
  36889. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  36890. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36891. + return -EINVAL;
  36892. + }
  36893. + /* FUA */
  36894. + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
  36895. + spin_lock(&curlun->filp->f_lock);
  36896. + curlun->filp->f_flags |= O_DSYNC;
  36897. + spin_unlock(&curlun->filp->f_lock);
  36898. + }
  36899. + }
  36900. + if (lba >= curlun->num_sectors) {
  36901. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36902. + return -EINVAL;
  36903. + }
  36904. +
  36905. + /* Carry out the file writes */
  36906. + get_some_more = 1;
  36907. + file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
  36908. + amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  36909. +
  36910. + while (amount_left_to_write > 0) {
  36911. +
  36912. + /* Queue a request for more data from the host */
  36913. + bh = fsg->next_buffhd_to_fill;
  36914. + if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  36915. +
  36916. + /* Figure out how much we want to get:
  36917. + * Try to get the remaining amount,
  36918. + * but not more than the buffer size.
  36919. + */
  36920. + amount = min(amount_left_to_req, mod_data.buflen);
  36921. +
  36922. + /* Beyond the end of the backing file? */
  36923. + if (usb_offset >= curlun->file_length) {
  36924. + get_some_more = 0;
  36925. + curlun->sense_data =
  36926. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36927. + curlun->sense_data_info = usb_offset >> curlun->blkbits;
  36928. + curlun->info_valid = 1;
  36929. + continue;
  36930. + }
  36931. +
  36932. + /* Get the next buffer */
  36933. + usb_offset += amount;
  36934. + fsg->usb_amount_left -= amount;
  36935. + amount_left_to_req -= amount;
  36936. + if (amount_left_to_req == 0)
  36937. + get_some_more = 0;
  36938. +
  36939. + /* Except at the end of the transfer, amount will be
  36940. + * equal to the buffer size, which is divisible by
  36941. + * the bulk-out maxpacket size.
  36942. + */
  36943. + set_bulk_out_req_length(fsg, bh, amount);
  36944. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  36945. + &bh->outreq_busy, &bh->state);
  36946. + fsg->next_buffhd_to_fill = bh->next;
  36947. + continue;
  36948. + }
  36949. +
  36950. + /* Write the received data to the backing file */
  36951. + bh = fsg->next_buffhd_to_drain;
  36952. + if (bh->state == BUF_STATE_EMPTY && !get_some_more)
  36953. + break; // We stopped early
  36954. + if (bh->state == BUF_STATE_FULL) {
  36955. + smp_rmb();
  36956. + fsg->next_buffhd_to_drain = bh->next;
  36957. + bh->state = BUF_STATE_EMPTY;
  36958. +
  36959. + /* Did something go wrong with the transfer? */
  36960. + if (bh->outreq->status != 0) {
  36961. + curlun->sense_data = SS_COMMUNICATION_FAILURE;
  36962. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36963. + curlun->info_valid = 1;
  36964. + break;
  36965. + }
  36966. +
  36967. + amount = bh->outreq->actual;
  36968. + if (curlun->file_length - file_offset < amount) {
  36969. + LERROR(curlun,
  36970. + "write %u @ %llu beyond end %llu\n",
  36971. + amount, (unsigned long long) file_offset,
  36972. + (unsigned long long) curlun->file_length);
  36973. + amount = curlun->file_length - file_offset;
  36974. + }
  36975. +
  36976. + /* Don't accept excess data. The spec doesn't say
  36977. + * what to do in this case. We'll ignore the error.
  36978. + */
  36979. + amount = min(amount, bh->bulk_out_intended_length);
  36980. +
  36981. + /* Don't write a partial block */
  36982. + amount = round_down(amount, curlun->blksize);
  36983. + if (amount == 0)
  36984. + goto empty_write;
  36985. +
  36986. + /* Perform the write */
  36987. + file_offset_tmp = file_offset;
  36988. + nwritten = vfs_write(curlun->filp,
  36989. + (char __user *) bh->buf,
  36990. + amount, &file_offset_tmp);
  36991. + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
  36992. + (unsigned long long) file_offset,
  36993. + (int) nwritten);
  36994. + if (signal_pending(current))
  36995. + return -EINTR; // Interrupted!
  36996. +
  36997. + if (nwritten < 0) {
  36998. + LDBG(curlun, "error in file write: %d\n",
  36999. + (int) nwritten);
  37000. + nwritten = 0;
  37001. + } else if (nwritten < amount) {
  37002. + LDBG(curlun, "partial file write: %d/%u\n",
  37003. + (int) nwritten, amount);
  37004. + nwritten = round_down(nwritten, curlun->blksize);
  37005. + }
  37006. + file_offset += nwritten;
  37007. + amount_left_to_write -= nwritten;
  37008. + fsg->residue -= nwritten;
  37009. +
  37010. + /* If an error occurred, report it and its position */
  37011. + if (nwritten < amount) {
  37012. + curlun->sense_data = SS_WRITE_ERROR;
  37013. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  37014. + curlun->info_valid = 1;
  37015. + break;
  37016. + }
  37017. +
  37018. + empty_write:
  37019. + /* Did the host decide to stop early? */
  37020. + if (bh->outreq->actual < bh->bulk_out_intended_length) {
  37021. + fsg->short_packet_received = 1;
  37022. + break;
  37023. + }
  37024. + continue;
  37025. + }
  37026. +
  37027. + /* Wait for something to happen */
  37028. + rc = sleep_thread(fsg);
  37029. + if (rc)
  37030. + return rc;
  37031. + }
  37032. +
  37033. + return -EIO; // No default reply
  37034. +}
  37035. +
  37036. +
  37037. +/*-------------------------------------------------------------------------*/
  37038. +
  37039. +static int do_synchronize_cache(struct fsg_dev *fsg)
  37040. +{
  37041. + struct fsg_lun *curlun = fsg->curlun;
  37042. + int rc;
  37043. +
  37044. + /* We ignore the requested LBA and write out all file's
  37045. + * dirty data buffers. */
  37046. + rc = fsg_lun_fsync_sub(curlun);
  37047. + if (rc)
  37048. + curlun->sense_data = SS_WRITE_ERROR;
  37049. + return 0;
  37050. +}
  37051. +
  37052. +
  37053. +/*-------------------------------------------------------------------------*/
  37054. +
  37055. +static void invalidate_sub(struct fsg_lun *curlun)
  37056. +{
  37057. + struct file *filp = curlun->filp;
  37058. + struct inode *inode = filp->f_path.dentry->d_inode;
  37059. + unsigned long rc;
  37060. +
  37061. + rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
  37062. + VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
  37063. +}
  37064. +
  37065. +static int do_verify(struct fsg_dev *fsg)
  37066. +{
  37067. + struct fsg_lun *curlun = fsg->curlun;
  37068. + u32 lba;
  37069. + u32 verification_length;
  37070. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  37071. + loff_t file_offset, file_offset_tmp;
  37072. + u32 amount_left;
  37073. + unsigned int amount;
  37074. + ssize_t nread;
  37075. +
  37076. + /* Get the starting Logical Block Address and check that it's
  37077. + * not too big */
  37078. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  37079. + if (lba >= curlun->num_sectors) {
  37080. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37081. + return -EINVAL;
  37082. + }
  37083. +
  37084. + /* We allow DPO (Disable Page Out = don't save data in the
  37085. + * cache) but we don't implement it. */
  37086. + if ((fsg->cmnd[1] & ~0x10) != 0) {
  37087. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37088. + return -EINVAL;
  37089. + }
  37090. +
  37091. + verification_length = get_unaligned_be16(&fsg->cmnd[7]);
  37092. + if (unlikely(verification_length == 0))
  37093. + return -EIO; // No default reply
  37094. +
  37095. + /* Prepare to carry out the file verify */
  37096. + amount_left = verification_length << curlun->blkbits;
  37097. + file_offset = ((loff_t) lba) << curlun->blkbits;
  37098. +
  37099. + /* Write out all the dirty buffers before invalidating them */
  37100. + fsg_lun_fsync_sub(curlun);
  37101. + if (signal_pending(current))
  37102. + return -EINTR;
  37103. +
  37104. + invalidate_sub(curlun);
  37105. + if (signal_pending(current))
  37106. + return -EINTR;
  37107. +
  37108. + /* Just try to read the requested blocks */
  37109. + while (amount_left > 0) {
  37110. +
  37111. + /* Figure out how much we need to read:
  37112. + * Try to read the remaining amount, but not more than
  37113. + * the buffer size.
  37114. + * And don't try to read past the end of the file.
  37115. + */
  37116. + amount = min((unsigned int) amount_left, mod_data.buflen);
  37117. + amount = min((loff_t) amount,
  37118. + curlun->file_length - file_offset);
  37119. + if (amount == 0) {
  37120. + curlun->sense_data =
  37121. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37122. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  37123. + curlun->info_valid = 1;
  37124. + break;
  37125. + }
  37126. +
  37127. + /* Perform the read */
  37128. + file_offset_tmp = file_offset;
  37129. + nread = vfs_read(curlun->filp,
  37130. + (char __user *) bh->buf,
  37131. + amount, &file_offset_tmp);
  37132. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  37133. + (unsigned long long) file_offset,
  37134. + (int) nread);
  37135. + if (signal_pending(current))
  37136. + return -EINTR;
  37137. +
  37138. + if (nread < 0) {
  37139. + LDBG(curlun, "error in file verify: %d\n",
  37140. + (int) nread);
  37141. + nread = 0;
  37142. + } else if (nread < amount) {
  37143. + LDBG(curlun, "partial file verify: %d/%u\n",
  37144. + (int) nread, amount);
  37145. + nread = round_down(nread, curlun->blksize);
  37146. + }
  37147. + if (nread == 0) {
  37148. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  37149. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  37150. + curlun->info_valid = 1;
  37151. + break;
  37152. + }
  37153. + file_offset += nread;
  37154. + amount_left -= nread;
  37155. + }
  37156. + return 0;
  37157. +}
  37158. +
  37159. +
  37160. +/*-------------------------------------------------------------------------*/
  37161. +
  37162. +static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37163. +{
  37164. + u8 *buf = (u8 *) bh->buf;
  37165. +
  37166. + static char vendor_id[] = "Linux ";
  37167. + static char product_disk_id[] = "File-Stor Gadget";
  37168. + static char product_cdrom_id[] = "File-CD Gadget ";
  37169. +
  37170. + if (!fsg->curlun) { // Unsupported LUNs are okay
  37171. + fsg->bad_lun_okay = 1;
  37172. + memset(buf, 0, 36);
  37173. + buf[0] = 0x7f; // Unsupported, no device-type
  37174. + buf[4] = 31; // Additional length
  37175. + return 36;
  37176. + }
  37177. +
  37178. + memset(buf, 0, 8);
  37179. + buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
  37180. + if (mod_data.removable)
  37181. + buf[1] = 0x80;
  37182. + buf[2] = 2; // ANSI SCSI level 2
  37183. + buf[3] = 2; // SCSI-2 INQUIRY data format
  37184. + buf[4] = 31; // Additional length
  37185. + // No special options
  37186. + sprintf(buf + 8, "%-8s%-16s%04x", vendor_id,
  37187. + (mod_data.cdrom ? product_cdrom_id :
  37188. + product_disk_id),
  37189. + mod_data.release);
  37190. + return 36;
  37191. +}
  37192. +
  37193. +
  37194. +static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37195. +{
  37196. + struct fsg_lun *curlun = fsg->curlun;
  37197. + u8 *buf = (u8 *) bh->buf;
  37198. + u32 sd, sdinfo;
  37199. + int valid;
  37200. +
  37201. + /*
  37202. + * From the SCSI-2 spec., section 7.9 (Unit attention condition):
  37203. + *
  37204. + * If a REQUEST SENSE command is received from an initiator
  37205. + * with a pending unit attention condition (before the target
  37206. + * generates the contingent allegiance condition), then the
  37207. + * target shall either:
  37208. + * a) report any pending sense data and preserve the unit
  37209. + * attention condition on the logical unit, or,
  37210. + * b) report the unit attention condition, may discard any
  37211. + * pending sense data, and clear the unit attention
  37212. + * condition on the logical unit for that initiator.
  37213. + *
  37214. + * FSG normally uses option a); enable this code to use option b).
  37215. + */
  37216. +#if 0
  37217. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
  37218. + curlun->sense_data = curlun->unit_attention_data;
  37219. + curlun->unit_attention_data = SS_NO_SENSE;
  37220. + }
  37221. +#endif
  37222. +
  37223. + if (!curlun) { // Unsupported LUNs are okay
  37224. + fsg->bad_lun_okay = 1;
  37225. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  37226. + sdinfo = 0;
  37227. + valid = 0;
  37228. + } else {
  37229. + sd = curlun->sense_data;
  37230. + sdinfo = curlun->sense_data_info;
  37231. + valid = curlun->info_valid << 7;
  37232. + curlun->sense_data = SS_NO_SENSE;
  37233. + curlun->sense_data_info = 0;
  37234. + curlun->info_valid = 0;
  37235. + }
  37236. +
  37237. + memset(buf, 0, 18);
  37238. + buf[0] = valid | 0x70; // Valid, current error
  37239. + buf[2] = SK(sd);
  37240. + put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
  37241. + buf[7] = 18 - 8; // Additional sense length
  37242. + buf[12] = ASC(sd);
  37243. + buf[13] = ASCQ(sd);
  37244. + return 18;
  37245. +}
  37246. +
  37247. +
  37248. +static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37249. +{
  37250. + struct fsg_lun *curlun = fsg->curlun;
  37251. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  37252. + int pmi = fsg->cmnd[8];
  37253. + u8 *buf = (u8 *) bh->buf;
  37254. +
  37255. + /* Check the PMI and LBA fields */
  37256. + if (pmi > 1 || (pmi == 0 && lba != 0)) {
  37257. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37258. + return -EINVAL;
  37259. + }
  37260. +
  37261. + put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
  37262. + /* Max logical block */
  37263. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  37264. + return 8;
  37265. +}
  37266. +
  37267. +
  37268. +static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37269. +{
  37270. + struct fsg_lun *curlun = fsg->curlun;
  37271. + int msf = fsg->cmnd[1] & 0x02;
  37272. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  37273. + u8 *buf = (u8 *) bh->buf;
  37274. +
  37275. + if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */
  37276. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37277. + return -EINVAL;
  37278. + }
  37279. + if (lba >= curlun->num_sectors) {
  37280. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37281. + return -EINVAL;
  37282. + }
  37283. +
  37284. + memset(buf, 0, 8);
  37285. + buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
  37286. + store_cdrom_address(&buf[4], msf, lba);
  37287. + return 8;
  37288. +}
  37289. +
  37290. +
  37291. +static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37292. +{
  37293. + struct fsg_lun *curlun = fsg->curlun;
  37294. + int msf = fsg->cmnd[1] & 0x02;
  37295. + int start_track = fsg->cmnd[6];
  37296. + u8 *buf = (u8 *) bh->buf;
  37297. +
  37298. + if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
  37299. + start_track > 1) {
  37300. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37301. + return -EINVAL;
  37302. + }
  37303. +
  37304. + memset(buf, 0, 20);
  37305. + buf[1] = (20-2); /* TOC data length */
  37306. + buf[2] = 1; /* First track number */
  37307. + buf[3] = 1; /* Last track number */
  37308. + buf[5] = 0x16; /* Data track, copying allowed */
  37309. + buf[6] = 0x01; /* Only track is number 1 */
  37310. + store_cdrom_address(&buf[8], msf, 0);
  37311. +
  37312. + buf[13] = 0x16; /* Lead-out track is data */
  37313. + buf[14] = 0xAA; /* Lead-out track number */
  37314. + store_cdrom_address(&buf[16], msf, curlun->num_sectors);
  37315. + return 20;
  37316. +}
  37317. +
  37318. +
  37319. +static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37320. +{
  37321. + struct fsg_lun *curlun = fsg->curlun;
  37322. + int mscmnd = fsg->cmnd[0];
  37323. + u8 *buf = (u8 *) bh->buf;
  37324. + u8 *buf0 = buf;
  37325. + int pc, page_code;
  37326. + int changeable_values, all_pages;
  37327. + int valid_page = 0;
  37328. + int len, limit;
  37329. +
  37330. + if ((fsg->cmnd[1] & ~0x08) != 0) { // Mask away DBD
  37331. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37332. + return -EINVAL;
  37333. + }
  37334. + pc = fsg->cmnd[2] >> 6;
  37335. + page_code = fsg->cmnd[2] & 0x3f;
  37336. + if (pc == 3) {
  37337. + curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
  37338. + return -EINVAL;
  37339. + }
  37340. + changeable_values = (pc == 1);
  37341. + all_pages = (page_code == 0x3f);
  37342. +
  37343. + /* Write the mode parameter header. Fixed values are: default
  37344. + * medium type, no cache control (DPOFUA), and no block descriptors.
  37345. + * The only variable value is the WriteProtect bit. We will fill in
  37346. + * the mode data length later. */
  37347. + memset(buf, 0, 8);
  37348. + if (mscmnd == MODE_SENSE) {
  37349. + buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  37350. + buf += 4;
  37351. + limit = 255;
  37352. + } else { // MODE_SENSE_10
  37353. + buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  37354. + buf += 8;
  37355. + limit = 65535; // Should really be mod_data.buflen
  37356. + }
  37357. +
  37358. + /* No block descriptors */
  37359. +
  37360. + /* The mode pages, in numerical order. The only page we support
  37361. + * is the Caching page. */
  37362. + if (page_code == 0x08 || all_pages) {
  37363. + valid_page = 1;
  37364. + buf[0] = 0x08; // Page code
  37365. + buf[1] = 10; // Page length
  37366. + memset(buf+2, 0, 10); // None of the fields are changeable
  37367. +
  37368. + if (!changeable_values) {
  37369. + buf[2] = 0x04; // Write cache enable,
  37370. + // Read cache not disabled
  37371. + // No cache retention priorities
  37372. + put_unaligned_be16(0xffff, &buf[4]);
  37373. + /* Don't disable prefetch */
  37374. + /* Minimum prefetch = 0 */
  37375. + put_unaligned_be16(0xffff, &buf[8]);
  37376. + /* Maximum prefetch */
  37377. + put_unaligned_be16(0xffff, &buf[10]);
  37378. + /* Maximum prefetch ceiling */
  37379. + }
  37380. + buf += 12;
  37381. + }
  37382. +
  37383. + /* Check that a valid page was requested and the mode data length
  37384. + * isn't too long. */
  37385. + len = buf - buf0;
  37386. + if (!valid_page || len > limit) {
  37387. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37388. + return -EINVAL;
  37389. + }
  37390. +
  37391. + /* Store the mode data length */
  37392. + if (mscmnd == MODE_SENSE)
  37393. + buf0[0] = len - 1;
  37394. + else
  37395. + put_unaligned_be16(len - 2, buf0);
  37396. + return len;
  37397. +}
  37398. +
  37399. +
  37400. +static int do_start_stop(struct fsg_dev *fsg)
  37401. +{
  37402. + struct fsg_lun *curlun = fsg->curlun;
  37403. + int loej, start;
  37404. +
  37405. + if (!mod_data.removable) {
  37406. + curlun->sense_data = SS_INVALID_COMMAND;
  37407. + return -EINVAL;
  37408. + }
  37409. +
  37410. + // int immed = fsg->cmnd[1] & 0x01;
  37411. + loej = fsg->cmnd[4] & 0x02;
  37412. + start = fsg->cmnd[4] & 0x01;
  37413. +
  37414. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  37415. + if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
  37416. + (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
  37417. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37418. + return -EINVAL;
  37419. + }
  37420. +
  37421. + if (!start) {
  37422. +
  37423. + /* Are we allowed to unload the media? */
  37424. + if (curlun->prevent_medium_removal) {
  37425. + LDBG(curlun, "unload attempt prevented\n");
  37426. + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
  37427. + return -EINVAL;
  37428. + }
  37429. + if (loej) { // Simulate an unload/eject
  37430. + up_read(&fsg->filesem);
  37431. + down_write(&fsg->filesem);
  37432. + fsg_lun_close(curlun);
  37433. + up_write(&fsg->filesem);
  37434. + down_read(&fsg->filesem);
  37435. + }
  37436. + } else {
  37437. +
  37438. + /* Our emulation doesn't support mounting; the medium is
  37439. + * available for use as soon as it is loaded. */
  37440. + if (!fsg_lun_is_open(curlun)) {
  37441. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  37442. + return -EINVAL;
  37443. + }
  37444. + }
  37445. +#endif
  37446. + return 0;
  37447. +}
  37448. +
  37449. +
  37450. +static int do_prevent_allow(struct fsg_dev *fsg)
  37451. +{
  37452. + struct fsg_lun *curlun = fsg->curlun;
  37453. + int prevent;
  37454. +
  37455. + if (!mod_data.removable) {
  37456. + curlun->sense_data = SS_INVALID_COMMAND;
  37457. + return -EINVAL;
  37458. + }
  37459. +
  37460. + prevent = fsg->cmnd[4] & 0x01;
  37461. + if ((fsg->cmnd[4] & ~0x01) != 0) { // Mask away Prevent
  37462. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37463. + return -EINVAL;
  37464. + }
  37465. +
  37466. + if (curlun->prevent_medium_removal && !prevent)
  37467. + fsg_lun_fsync_sub(curlun);
  37468. + curlun->prevent_medium_removal = prevent;
  37469. + return 0;
  37470. +}
  37471. +
  37472. +
  37473. +static int do_read_format_capacities(struct fsg_dev *fsg,
  37474. + struct fsg_buffhd *bh)
  37475. +{
  37476. + struct fsg_lun *curlun = fsg->curlun;
  37477. + u8 *buf = (u8 *) bh->buf;
  37478. +
  37479. + buf[0] = buf[1] = buf[2] = 0;
  37480. + buf[3] = 8; // Only the Current/Maximum Capacity Descriptor
  37481. + buf += 4;
  37482. +
  37483. + put_unaligned_be32(curlun->num_sectors, &buf[0]);
  37484. + /* Number of blocks */
  37485. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  37486. + buf[4] = 0x02; /* Current capacity */
  37487. + return 12;
  37488. +}
  37489. +
  37490. +
  37491. +static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37492. +{
  37493. + struct fsg_lun *curlun = fsg->curlun;
  37494. +
  37495. + /* We don't support MODE SELECT */
  37496. + curlun->sense_data = SS_INVALID_COMMAND;
  37497. + return -EINVAL;
  37498. +}
  37499. +
  37500. +
  37501. +/*-------------------------------------------------------------------------*/
  37502. +
  37503. +static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
  37504. +{
  37505. + int rc;
  37506. +
  37507. + rc = fsg_set_halt(fsg, fsg->bulk_in);
  37508. + if (rc == -EAGAIN)
  37509. + VDBG(fsg, "delayed bulk-in endpoint halt\n");
  37510. + while (rc != 0) {
  37511. + if (rc != -EAGAIN) {
  37512. + WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
  37513. + rc = 0;
  37514. + break;
  37515. + }
  37516. +
  37517. + /* Wait for a short time and then try again */
  37518. + if (msleep_interruptible(100) != 0)
  37519. + return -EINTR;
  37520. + rc = usb_ep_set_halt(fsg->bulk_in);
  37521. + }
  37522. + return rc;
  37523. +}
  37524. +
  37525. +static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
  37526. +{
  37527. + int rc;
  37528. +
  37529. + DBG(fsg, "bulk-in set wedge\n");
  37530. + rc = usb_ep_set_wedge(fsg->bulk_in);
  37531. + if (rc == -EAGAIN)
  37532. + VDBG(fsg, "delayed bulk-in endpoint wedge\n");
  37533. + while (rc != 0) {
  37534. + if (rc != -EAGAIN) {
  37535. + WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
  37536. + rc = 0;
  37537. + break;
  37538. + }
  37539. +
  37540. + /* Wait for a short time and then try again */
  37541. + if (msleep_interruptible(100) != 0)
  37542. + return -EINTR;
  37543. + rc = usb_ep_set_wedge(fsg->bulk_in);
  37544. + }
  37545. + return rc;
  37546. +}
  37547. +
  37548. +static int throw_away_data(struct fsg_dev *fsg)
  37549. +{
  37550. + struct fsg_buffhd *bh;
  37551. + u32 amount;
  37552. + int rc;
  37553. +
  37554. + while ((bh = fsg->next_buffhd_to_drain)->state != BUF_STATE_EMPTY ||
  37555. + fsg->usb_amount_left > 0) {
  37556. +
  37557. + /* Throw away the data in a filled buffer */
  37558. + if (bh->state == BUF_STATE_FULL) {
  37559. + smp_rmb();
  37560. + bh->state = BUF_STATE_EMPTY;
  37561. + fsg->next_buffhd_to_drain = bh->next;
  37562. +
  37563. + /* A short packet or an error ends everything */
  37564. + if (bh->outreq->actual < bh->bulk_out_intended_length ||
  37565. + bh->outreq->status != 0) {
  37566. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  37567. + return -EINTR;
  37568. + }
  37569. + continue;
  37570. + }
  37571. +
  37572. + /* Try to submit another request if we need one */
  37573. + bh = fsg->next_buffhd_to_fill;
  37574. + if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
  37575. + amount = min(fsg->usb_amount_left,
  37576. + (u32) mod_data.buflen);
  37577. +
  37578. + /* Except at the end of the transfer, amount will be
  37579. + * equal to the buffer size, which is divisible by
  37580. + * the bulk-out maxpacket size.
  37581. + */
  37582. + set_bulk_out_req_length(fsg, bh, amount);
  37583. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  37584. + &bh->outreq_busy, &bh->state);
  37585. + fsg->next_buffhd_to_fill = bh->next;
  37586. + fsg->usb_amount_left -= amount;
  37587. + continue;
  37588. + }
  37589. +
  37590. + /* Otherwise wait for something to happen */
  37591. + rc = sleep_thread(fsg);
  37592. + if (rc)
  37593. + return rc;
  37594. + }
  37595. + return 0;
  37596. +}
  37597. +
  37598. +
  37599. +static int finish_reply(struct fsg_dev *fsg)
  37600. +{
  37601. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  37602. + int rc = 0;
  37603. +
  37604. + switch (fsg->data_dir) {
  37605. + case DATA_DIR_NONE:
  37606. + break; // Nothing to send
  37607. +
  37608. + /* If we don't know whether the host wants to read or write,
  37609. + * this must be CB or CBI with an unknown command. We mustn't
  37610. + * try to send or receive any data. So stall both bulk pipes
  37611. + * if we can and wait for a reset. */
  37612. + case DATA_DIR_UNKNOWN:
  37613. + if (mod_data.can_stall) {
  37614. + fsg_set_halt(fsg, fsg->bulk_out);
  37615. + rc = halt_bulk_in_endpoint(fsg);
  37616. + }
  37617. + break;
  37618. +
  37619. + /* All but the last buffer of data must have already been sent */
  37620. + case DATA_DIR_TO_HOST:
  37621. + if (fsg->data_size == 0)
  37622. + ; // Nothing to send
  37623. +
  37624. + /* If there's no residue, simply send the last buffer */
  37625. + else if (fsg->residue == 0) {
  37626. + bh->inreq->zero = 0;
  37627. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37628. + &bh->inreq_busy, &bh->state);
  37629. + fsg->next_buffhd_to_fill = bh->next;
  37630. + }
  37631. +
  37632. + /* There is a residue. For CB and CBI, simply mark the end
  37633. + * of the data with a short packet. However, if we are
  37634. + * allowed to stall, there was no data at all (residue ==
  37635. + * data_size), and the command failed (invalid LUN or
  37636. + * sense data is set), then halt the bulk-in endpoint
  37637. + * instead. */
  37638. + else if (!transport_is_bbb()) {
  37639. + if (mod_data.can_stall &&
  37640. + fsg->residue == fsg->data_size &&
  37641. + (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
  37642. + bh->state = BUF_STATE_EMPTY;
  37643. + rc = halt_bulk_in_endpoint(fsg);
  37644. + } else {
  37645. + bh->inreq->zero = 1;
  37646. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37647. + &bh->inreq_busy, &bh->state);
  37648. + fsg->next_buffhd_to_fill = bh->next;
  37649. + }
  37650. + }
  37651. +
  37652. + /*
  37653. + * For Bulk-only, mark the end of the data with a short
  37654. + * packet. If we are allowed to stall, halt the bulk-in
  37655. + * endpoint. (Note: This violates the Bulk-Only Transport
  37656. + * specification, which requires us to pad the data if we
  37657. + * don't halt the endpoint. Presumably nobody will mind.)
  37658. + */
  37659. + else {
  37660. + bh->inreq->zero = 1;
  37661. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37662. + &bh->inreq_busy, &bh->state);
  37663. + fsg->next_buffhd_to_fill = bh->next;
  37664. + if (mod_data.can_stall)
  37665. + rc = halt_bulk_in_endpoint(fsg);
  37666. + }
  37667. + break;
  37668. +
  37669. + /* We have processed all we want from the data the host has sent.
  37670. + * There may still be outstanding bulk-out requests. */
  37671. + case DATA_DIR_FROM_HOST:
  37672. + if (fsg->residue == 0)
  37673. + ; // Nothing to receive
  37674. +
  37675. + /* Did the host stop sending unexpectedly early? */
  37676. + else if (fsg->short_packet_received) {
  37677. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  37678. + rc = -EINTR;
  37679. + }
  37680. +
  37681. + /* We haven't processed all the incoming data. Even though
  37682. + * we may be allowed to stall, doing so would cause a race.
  37683. + * The controller may already have ACK'ed all the remaining
  37684. + * bulk-out packets, in which case the host wouldn't see a
  37685. + * STALL. Not realizing the endpoint was halted, it wouldn't
  37686. + * clear the halt -- leading to problems later on. */
  37687. +#if 0
  37688. + else if (mod_data.can_stall) {
  37689. + fsg_set_halt(fsg, fsg->bulk_out);
  37690. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  37691. + rc = -EINTR;
  37692. + }
  37693. +#endif
  37694. +
  37695. + /* We can't stall. Read in the excess data and throw it
  37696. + * all away. */
  37697. + else
  37698. + rc = throw_away_data(fsg);
  37699. + break;
  37700. + }
  37701. + return rc;
  37702. +}
  37703. +
  37704. +
  37705. +static int send_status(struct fsg_dev *fsg)
  37706. +{
  37707. + struct fsg_lun *curlun = fsg->curlun;
  37708. + struct fsg_buffhd *bh;
  37709. + int rc;
  37710. + u8 status = US_BULK_STAT_OK;
  37711. + u32 sd, sdinfo = 0;
  37712. +
  37713. + /* Wait for the next buffer to become available */
  37714. + bh = fsg->next_buffhd_to_fill;
  37715. + while (bh->state != BUF_STATE_EMPTY) {
  37716. + rc = sleep_thread(fsg);
  37717. + if (rc)
  37718. + return rc;
  37719. + }
  37720. +
  37721. + if (curlun) {
  37722. + sd = curlun->sense_data;
  37723. + sdinfo = curlun->sense_data_info;
  37724. + } else if (fsg->bad_lun_okay)
  37725. + sd = SS_NO_SENSE;
  37726. + else
  37727. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  37728. +
  37729. + if (fsg->phase_error) {
  37730. + DBG(fsg, "sending phase-error status\n");
  37731. + status = US_BULK_STAT_PHASE;
  37732. + sd = SS_INVALID_COMMAND;
  37733. + } else if (sd != SS_NO_SENSE) {
  37734. + DBG(fsg, "sending command-failure status\n");
  37735. + status = US_BULK_STAT_FAIL;
  37736. + VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
  37737. + " info x%x\n",
  37738. + SK(sd), ASC(sd), ASCQ(sd), sdinfo);
  37739. + }
  37740. +
  37741. + if (transport_is_bbb()) {
  37742. + struct bulk_cs_wrap *csw = bh->buf;
  37743. +
  37744. + /* Store and send the Bulk-only CSW */
  37745. + csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
  37746. + csw->Tag = fsg->tag;
  37747. + csw->Residue = cpu_to_le32(fsg->residue);
  37748. + csw->Status = status;
  37749. +
  37750. + bh->inreq->length = US_BULK_CS_WRAP_LEN;
  37751. + bh->inreq->zero = 0;
  37752. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37753. + &bh->inreq_busy, &bh->state);
  37754. +
  37755. + } else if (mod_data.transport_type == USB_PR_CB) {
  37756. +
  37757. + /* Control-Bulk transport has no status phase! */
  37758. + return 0;
  37759. +
  37760. + } else { // USB_PR_CBI
  37761. + struct interrupt_data *buf = bh->buf;
  37762. +
  37763. + /* Store and send the Interrupt data. UFI sends the ASC
  37764. + * and ASCQ bytes. Everything else sends a Type (which
  37765. + * is always 0) and the status Value. */
  37766. + if (mod_data.protocol_type == USB_SC_UFI) {
  37767. + buf->bType = ASC(sd);
  37768. + buf->bValue = ASCQ(sd);
  37769. + } else {
  37770. + buf->bType = 0;
  37771. + buf->bValue = status;
  37772. + }
  37773. + fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
  37774. +
  37775. + fsg->intr_buffhd = bh; // Point to the right buffhd
  37776. + fsg->intreq->buf = bh->inreq->buf;
  37777. + fsg->intreq->context = bh;
  37778. + start_transfer(fsg, fsg->intr_in, fsg->intreq,
  37779. + &fsg->intreq_busy, &bh->state);
  37780. + }
  37781. +
  37782. + fsg->next_buffhd_to_fill = bh->next;
  37783. + return 0;
  37784. +}
  37785. +
  37786. +
  37787. +/*-------------------------------------------------------------------------*/
  37788. +
  37789. +/* Check whether the command is properly formed and whether its data size
  37790. + * and direction agree with the values we already have. */
  37791. +static int check_command(struct fsg_dev *fsg, int cmnd_size,
  37792. + enum data_direction data_dir, unsigned int mask,
  37793. + int needs_medium, const char *name)
  37794. +{
  37795. + int i;
  37796. + int lun = fsg->cmnd[1] >> 5;
  37797. + static const char dirletter[4] = {'u', 'o', 'i', 'n'};
  37798. + char hdlen[20];
  37799. + struct fsg_lun *curlun;
  37800. +
  37801. + /* Adjust the expected cmnd_size for protocol encapsulation padding.
  37802. + * Transparent SCSI doesn't pad. */
  37803. + if (protocol_is_scsi())
  37804. + ;
  37805. +
  37806. + /* There's some disagreement as to whether RBC pads commands or not.
  37807. + * We'll play it safe and accept either form. */
  37808. + else if (mod_data.protocol_type == USB_SC_RBC) {
  37809. + if (fsg->cmnd_size == 12)
  37810. + cmnd_size = 12;
  37811. +
  37812. + /* All the other protocols pad to 12 bytes */
  37813. + } else
  37814. + cmnd_size = 12;
  37815. +
  37816. + hdlen[0] = 0;
  37817. + if (fsg->data_dir != DATA_DIR_UNKNOWN)
  37818. + sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
  37819. + fsg->data_size);
  37820. + VDBG(fsg, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
  37821. + name, cmnd_size, dirletter[(int) data_dir],
  37822. + fsg->data_size_from_cmnd, fsg->cmnd_size, hdlen);
  37823. +
  37824. + /* We can't reply at all until we know the correct data direction
  37825. + * and size. */
  37826. + if (fsg->data_size_from_cmnd == 0)
  37827. + data_dir = DATA_DIR_NONE;
  37828. + if (fsg->data_dir == DATA_DIR_UNKNOWN) { // CB or CBI
  37829. + fsg->data_dir = data_dir;
  37830. + fsg->data_size = fsg->data_size_from_cmnd;
  37831. +
  37832. + } else { // Bulk-only
  37833. + if (fsg->data_size < fsg->data_size_from_cmnd) {
  37834. +
  37835. + /* Host data size < Device data size is a phase error.
  37836. + * Carry out the command, but only transfer as much
  37837. + * as we are allowed. */
  37838. + fsg->data_size_from_cmnd = fsg->data_size;
  37839. + fsg->phase_error = 1;
  37840. + }
  37841. + }
  37842. + fsg->residue = fsg->usb_amount_left = fsg->data_size;
  37843. +
  37844. + /* Conflicting data directions is a phase error */
  37845. + if (fsg->data_dir != data_dir && fsg->data_size_from_cmnd > 0) {
  37846. + fsg->phase_error = 1;
  37847. + return -EINVAL;
  37848. + }
  37849. +
  37850. + /* Verify the length of the command itself */
  37851. + if (cmnd_size != fsg->cmnd_size) {
  37852. +
  37853. + /* Special case workaround: There are plenty of buggy SCSI
  37854. + * implementations. Many have issues with cbw->Length
  37855. + * field passing a wrong command size. For those cases we
  37856. + * always try to work around the problem by using the length
  37857. + * sent by the host side provided it is at least as large
  37858. + * as the correct command length.
  37859. + * Examples of such cases would be MS-Windows, which issues
  37860. + * REQUEST SENSE with cbw->Length == 12 where it should
  37861. + * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
  37862. + * REQUEST SENSE with cbw->Length == 10 where it should
  37863. + * be 6 as well.
  37864. + */
  37865. + if (cmnd_size <= fsg->cmnd_size) {
  37866. + DBG(fsg, "%s is buggy! Expected length %d "
  37867. + "but we got %d\n", name,
  37868. + cmnd_size, fsg->cmnd_size);
  37869. + cmnd_size = fsg->cmnd_size;
  37870. + } else {
  37871. + fsg->phase_error = 1;
  37872. + return -EINVAL;
  37873. + }
  37874. + }
  37875. +
  37876. + /* Check that the LUN values are consistent */
  37877. + if (transport_is_bbb()) {
  37878. + if (fsg->lun != lun)
  37879. + DBG(fsg, "using LUN %d from CBW, "
  37880. + "not LUN %d from CDB\n",
  37881. + fsg->lun, lun);
  37882. + }
  37883. +
  37884. + /* Check the LUN */
  37885. + curlun = fsg->curlun;
  37886. + if (curlun) {
  37887. + if (fsg->cmnd[0] != REQUEST_SENSE) {
  37888. + curlun->sense_data = SS_NO_SENSE;
  37889. + curlun->sense_data_info = 0;
  37890. + curlun->info_valid = 0;
  37891. + }
  37892. + } else {
  37893. + fsg->bad_lun_okay = 0;
  37894. +
  37895. + /* INQUIRY and REQUEST SENSE commands are explicitly allowed
  37896. + * to use unsupported LUNs; all others may not. */
  37897. + if (fsg->cmnd[0] != INQUIRY &&
  37898. + fsg->cmnd[0] != REQUEST_SENSE) {
  37899. + DBG(fsg, "unsupported LUN %d\n", fsg->lun);
  37900. + return -EINVAL;
  37901. + }
  37902. + }
  37903. +
  37904. + /* If a unit attention condition exists, only INQUIRY and
  37905. + * REQUEST SENSE commands are allowed; anything else must fail. */
  37906. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
  37907. + fsg->cmnd[0] != INQUIRY &&
  37908. + fsg->cmnd[0] != REQUEST_SENSE) {
  37909. + curlun->sense_data = curlun->unit_attention_data;
  37910. + curlun->unit_attention_data = SS_NO_SENSE;
  37911. + return -EINVAL;
  37912. + }
  37913. +
  37914. + /* Check that only command bytes listed in the mask are non-zero */
  37915. + fsg->cmnd[1] &= 0x1f; // Mask away the LUN
  37916. + for (i = 1; i < cmnd_size; ++i) {
  37917. + if (fsg->cmnd[i] && !(mask & (1 << i))) {
  37918. + if (curlun)
  37919. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37920. + return -EINVAL;
  37921. + }
  37922. + }
  37923. +
  37924. + /* If the medium isn't mounted and the command needs to access
  37925. + * it, return an error. */
  37926. + if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
  37927. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  37928. + return -EINVAL;
  37929. + }
  37930. +
  37931. + return 0;
  37932. +}
  37933. +
  37934. +/* wrapper of check_command for data size in blocks handling */
  37935. +static int check_command_size_in_blocks(struct fsg_dev *fsg, int cmnd_size,
  37936. + enum data_direction data_dir, unsigned int mask,
  37937. + int needs_medium, const char *name)
  37938. +{
  37939. + if (fsg->curlun)
  37940. + fsg->data_size_from_cmnd <<= fsg->curlun->blkbits;
  37941. + return check_command(fsg, cmnd_size, data_dir,
  37942. + mask, needs_medium, name);
  37943. +}
  37944. +
  37945. +static int do_scsi_command(struct fsg_dev *fsg)
  37946. +{
  37947. + struct fsg_buffhd *bh;
  37948. + int rc;
  37949. + int reply = -EINVAL;
  37950. + int i;
  37951. + static char unknown[16];
  37952. +
  37953. + dump_cdb(fsg);
  37954. +
  37955. + /* Wait for the next buffer to become available for data or status */
  37956. + bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
  37957. + while (bh->state != BUF_STATE_EMPTY) {
  37958. + rc = sleep_thread(fsg);
  37959. + if (rc)
  37960. + return rc;
  37961. + }
  37962. + fsg->phase_error = 0;
  37963. + fsg->short_packet_received = 0;
  37964. +
  37965. + down_read(&fsg->filesem); // We're using the backing file
  37966. + switch (fsg->cmnd[0]) {
  37967. +
  37968. + case INQUIRY:
  37969. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37970. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  37971. + (1<<4), 0,
  37972. + "INQUIRY")) == 0)
  37973. + reply = do_inquiry(fsg, bh);
  37974. + break;
  37975. +
  37976. + case MODE_SELECT:
  37977. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37978. + if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
  37979. + (1<<1) | (1<<4), 0,
  37980. + "MODE SELECT(6)")) == 0)
  37981. + reply = do_mode_select(fsg, bh);
  37982. + break;
  37983. +
  37984. + case MODE_SELECT_10:
  37985. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37986. + if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
  37987. + (1<<1) | (3<<7), 0,
  37988. + "MODE SELECT(10)")) == 0)
  37989. + reply = do_mode_select(fsg, bh);
  37990. + break;
  37991. +
  37992. + case MODE_SENSE:
  37993. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37994. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  37995. + (1<<1) | (1<<2) | (1<<4), 0,
  37996. + "MODE SENSE(6)")) == 0)
  37997. + reply = do_mode_sense(fsg, bh);
  37998. + break;
  37999. +
  38000. + case MODE_SENSE_10:
  38001. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38002. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  38003. + (1<<1) | (1<<2) | (3<<7), 0,
  38004. + "MODE SENSE(10)")) == 0)
  38005. + reply = do_mode_sense(fsg, bh);
  38006. + break;
  38007. +
  38008. + case ALLOW_MEDIUM_REMOVAL:
  38009. + fsg->data_size_from_cmnd = 0;
  38010. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  38011. + (1<<4), 0,
  38012. + "PREVENT-ALLOW MEDIUM REMOVAL")) == 0)
  38013. + reply = do_prevent_allow(fsg);
  38014. + break;
  38015. +
  38016. + case READ_6:
  38017. + i = fsg->cmnd[4];
  38018. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  38019. + if ((reply = check_command_size_in_blocks(fsg, 6,
  38020. + DATA_DIR_TO_HOST,
  38021. + (7<<1) | (1<<4), 1,
  38022. + "READ(6)")) == 0)
  38023. + reply = do_read(fsg);
  38024. + break;
  38025. +
  38026. + case READ_10:
  38027. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38028. + if ((reply = check_command_size_in_blocks(fsg, 10,
  38029. + DATA_DIR_TO_HOST,
  38030. + (1<<1) | (0xf<<2) | (3<<7), 1,
  38031. + "READ(10)")) == 0)
  38032. + reply = do_read(fsg);
  38033. + break;
  38034. +
  38035. + case READ_12:
  38036. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  38037. + if ((reply = check_command_size_in_blocks(fsg, 12,
  38038. + DATA_DIR_TO_HOST,
  38039. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  38040. + "READ(12)")) == 0)
  38041. + reply = do_read(fsg);
  38042. + break;
  38043. +
  38044. + case READ_CAPACITY:
  38045. + fsg->data_size_from_cmnd = 8;
  38046. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  38047. + (0xf<<2) | (1<<8), 1,
  38048. + "READ CAPACITY")) == 0)
  38049. + reply = do_read_capacity(fsg, bh);
  38050. + break;
  38051. +
  38052. + case READ_HEADER:
  38053. + if (!mod_data.cdrom)
  38054. + goto unknown_cmnd;
  38055. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38056. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  38057. + (3<<7) | (0x1f<<1), 1,
  38058. + "READ HEADER")) == 0)
  38059. + reply = do_read_header(fsg, bh);
  38060. + break;
  38061. +
  38062. + case READ_TOC:
  38063. + if (!mod_data.cdrom)
  38064. + goto unknown_cmnd;
  38065. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38066. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  38067. + (7<<6) | (1<<1), 1,
  38068. + "READ TOC")) == 0)
  38069. + reply = do_read_toc(fsg, bh);
  38070. + break;
  38071. +
  38072. + case READ_FORMAT_CAPACITIES:
  38073. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38074. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  38075. + (3<<7), 1,
  38076. + "READ FORMAT CAPACITIES")) == 0)
  38077. + reply = do_read_format_capacities(fsg, bh);
  38078. + break;
  38079. +
  38080. + case REQUEST_SENSE:
  38081. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  38082. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  38083. + (1<<4), 0,
  38084. + "REQUEST SENSE")) == 0)
  38085. + reply = do_request_sense(fsg, bh);
  38086. + break;
  38087. +
  38088. + case START_STOP:
  38089. + fsg->data_size_from_cmnd = 0;
  38090. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  38091. + (1<<1) | (1<<4), 0,
  38092. + "START-STOP UNIT")) == 0)
  38093. + reply = do_start_stop(fsg);
  38094. + break;
  38095. +
  38096. + case SYNCHRONIZE_CACHE:
  38097. + fsg->data_size_from_cmnd = 0;
  38098. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  38099. + (0xf<<2) | (3<<7), 1,
  38100. + "SYNCHRONIZE CACHE")) == 0)
  38101. + reply = do_synchronize_cache(fsg);
  38102. + break;
  38103. +
  38104. + case TEST_UNIT_READY:
  38105. + fsg->data_size_from_cmnd = 0;
  38106. + reply = check_command(fsg, 6, DATA_DIR_NONE,
  38107. + 0, 1,
  38108. + "TEST UNIT READY");
  38109. + break;
  38110. +
  38111. + /* Although optional, this command is used by MS-Windows. We
  38112. + * support a minimal version: BytChk must be 0. */
  38113. + case VERIFY:
  38114. + fsg->data_size_from_cmnd = 0;
  38115. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  38116. + (1<<1) | (0xf<<2) | (3<<7), 1,
  38117. + "VERIFY")) == 0)
  38118. + reply = do_verify(fsg);
  38119. + break;
  38120. +
  38121. + case WRITE_6:
  38122. + i = fsg->cmnd[4];
  38123. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  38124. + if ((reply = check_command_size_in_blocks(fsg, 6,
  38125. + DATA_DIR_FROM_HOST,
  38126. + (7<<1) | (1<<4), 1,
  38127. + "WRITE(6)")) == 0)
  38128. + reply = do_write(fsg);
  38129. + break;
  38130. +
  38131. + case WRITE_10:
  38132. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38133. + if ((reply = check_command_size_in_blocks(fsg, 10,
  38134. + DATA_DIR_FROM_HOST,
  38135. + (1<<1) | (0xf<<2) | (3<<7), 1,
  38136. + "WRITE(10)")) == 0)
  38137. + reply = do_write(fsg);
  38138. + break;
  38139. +
  38140. + case WRITE_12:
  38141. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  38142. + if ((reply = check_command_size_in_blocks(fsg, 12,
  38143. + DATA_DIR_FROM_HOST,
  38144. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  38145. + "WRITE(12)")) == 0)
  38146. + reply = do_write(fsg);
  38147. + break;
  38148. +
  38149. + /* Some mandatory commands that we recognize but don't implement.
  38150. + * They don't mean much in this setting. It's left as an exercise
  38151. + * for anyone interested to implement RESERVE and RELEASE in terms
  38152. + * of Posix locks. */
  38153. + case FORMAT_UNIT:
  38154. + case RELEASE:
  38155. + case RESERVE:
  38156. + case SEND_DIAGNOSTIC:
  38157. + // Fall through
  38158. +
  38159. + default:
  38160. + unknown_cmnd:
  38161. + fsg->data_size_from_cmnd = 0;
  38162. + sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
  38163. + if ((reply = check_command(fsg, fsg->cmnd_size,
  38164. + DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
  38165. + fsg->curlun->sense_data = SS_INVALID_COMMAND;
  38166. + reply = -EINVAL;
  38167. + }
  38168. + break;
  38169. + }
  38170. + up_read(&fsg->filesem);
  38171. +
  38172. + if (reply == -EINTR || signal_pending(current))
  38173. + return -EINTR;
  38174. +
  38175. + /* Set up the single reply buffer for finish_reply() */
  38176. + if (reply == -EINVAL)
  38177. + reply = 0; // Error reply length
  38178. + if (reply >= 0 && fsg->data_dir == DATA_DIR_TO_HOST) {
  38179. + reply = min((u32) reply, fsg->data_size_from_cmnd);
  38180. + bh->inreq->length = reply;
  38181. + bh->state = BUF_STATE_FULL;
  38182. + fsg->residue -= reply;
  38183. + } // Otherwise it's already set
  38184. +
  38185. + return 0;
  38186. +}
  38187. +
  38188. +
  38189. +/*-------------------------------------------------------------------------*/
  38190. +
  38191. +static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  38192. +{
  38193. + struct usb_request *req = bh->outreq;
  38194. + struct bulk_cb_wrap *cbw = req->buf;
  38195. +
  38196. + /* Was this a real packet? Should it be ignored? */
  38197. + if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  38198. + return -EINVAL;
  38199. +
  38200. + /* Is the CBW valid? */
  38201. + if (req->actual != US_BULK_CB_WRAP_LEN ||
  38202. + cbw->Signature != cpu_to_le32(
  38203. + US_BULK_CB_SIGN)) {
  38204. + DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
  38205. + req->actual,
  38206. + le32_to_cpu(cbw->Signature));
  38207. +
  38208. + /* The Bulk-only spec says we MUST stall the IN endpoint
  38209. + * (6.6.1), so it's unavoidable. It also says we must
  38210. + * retain this state until the next reset, but there's
  38211. + * no way to tell the controller driver it should ignore
  38212. + * Clear-Feature(HALT) requests.
  38213. + *
  38214. + * We aren't required to halt the OUT endpoint; instead
  38215. + * we can simply accept and discard any data received
  38216. + * until the next reset. */
  38217. + wedge_bulk_in_endpoint(fsg);
  38218. + set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  38219. + return -EINVAL;
  38220. + }
  38221. +
  38222. + /* Is the CBW meaningful? */
  38223. + if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
  38224. + cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
  38225. + DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
  38226. + "cmdlen %u\n",
  38227. + cbw->Lun, cbw->Flags, cbw->Length);
  38228. +
  38229. + /* We can do anything we want here, so let's stall the
  38230. + * bulk pipes if we are allowed to. */
  38231. + if (mod_data.can_stall) {
  38232. + fsg_set_halt(fsg, fsg->bulk_out);
  38233. + halt_bulk_in_endpoint(fsg);
  38234. + }
  38235. + return -EINVAL;
  38236. + }
  38237. +
  38238. + /* Save the command for later */
  38239. + fsg->cmnd_size = cbw->Length;
  38240. + memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
  38241. + if (cbw->Flags & US_BULK_FLAG_IN)
  38242. + fsg->data_dir = DATA_DIR_TO_HOST;
  38243. + else
  38244. + fsg->data_dir = DATA_DIR_FROM_HOST;
  38245. + fsg->data_size = le32_to_cpu(cbw->DataTransferLength);
  38246. + if (fsg->data_size == 0)
  38247. + fsg->data_dir = DATA_DIR_NONE;
  38248. + fsg->lun = cbw->Lun;
  38249. + fsg->tag = cbw->Tag;
  38250. + return 0;
  38251. +}
  38252. +
  38253. +
  38254. +static int get_next_command(struct fsg_dev *fsg)
  38255. +{
  38256. + struct fsg_buffhd *bh;
  38257. + int rc = 0;
  38258. +
  38259. + if (transport_is_bbb()) {
  38260. +
  38261. + /* Wait for the next buffer to become available */
  38262. + bh = fsg->next_buffhd_to_fill;
  38263. + while (bh->state != BUF_STATE_EMPTY) {
  38264. + rc = sleep_thread(fsg);
  38265. + if (rc)
  38266. + return rc;
  38267. + }
  38268. +
  38269. + /* Queue a request to read a Bulk-only CBW */
  38270. + set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
  38271. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  38272. + &bh->outreq_busy, &bh->state);
  38273. +
  38274. + /* We will drain the buffer in software, which means we
  38275. + * can reuse it for the next filling. No need to advance
  38276. + * next_buffhd_to_fill. */
  38277. +
  38278. + /* Wait for the CBW to arrive */
  38279. + while (bh->state != BUF_STATE_FULL) {
  38280. + rc = sleep_thread(fsg);
  38281. + if (rc)
  38282. + return rc;
  38283. + }
  38284. + smp_rmb();
  38285. + rc = received_cbw(fsg, bh);
  38286. + bh->state = BUF_STATE_EMPTY;
  38287. +
  38288. + } else { // USB_PR_CB or USB_PR_CBI
  38289. +
  38290. + /* Wait for the next command to arrive */
  38291. + while (fsg->cbbuf_cmnd_size == 0) {
  38292. + rc = sleep_thread(fsg);
  38293. + if (rc)
  38294. + return rc;
  38295. + }
  38296. +
  38297. + /* Is the previous status interrupt request still busy?
  38298. + * The host is allowed to skip reading the status,
  38299. + * so we must cancel it. */
  38300. + if (fsg->intreq_busy)
  38301. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  38302. +
  38303. + /* Copy the command and mark the buffer empty */
  38304. + fsg->data_dir = DATA_DIR_UNKNOWN;
  38305. + spin_lock_irq(&fsg->lock);
  38306. + fsg->cmnd_size = fsg->cbbuf_cmnd_size;
  38307. + memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size);
  38308. + fsg->cbbuf_cmnd_size = 0;
  38309. + spin_unlock_irq(&fsg->lock);
  38310. +
  38311. + /* Use LUN from the command */
  38312. + fsg->lun = fsg->cmnd[1] >> 5;
  38313. + }
  38314. +
  38315. + /* Update current lun */
  38316. + if (fsg->lun >= 0 && fsg->lun < fsg->nluns)
  38317. + fsg->curlun = &fsg->luns[fsg->lun];
  38318. + else
  38319. + fsg->curlun = NULL;
  38320. +
  38321. + return rc;
  38322. +}
  38323. +
  38324. +
  38325. +/*-------------------------------------------------------------------------*/
  38326. +
  38327. +static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
  38328. + const struct usb_endpoint_descriptor *d)
  38329. +{
  38330. + int rc;
  38331. +
  38332. + ep->driver_data = fsg;
  38333. + ep->desc = d;
  38334. + rc = usb_ep_enable(ep);
  38335. + if (rc)
  38336. + ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
  38337. + return rc;
  38338. +}
  38339. +
  38340. +static int alloc_request(struct fsg_dev *fsg, struct usb_ep *ep,
  38341. + struct usb_request **preq)
  38342. +{
  38343. + *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
  38344. + if (*preq)
  38345. + return 0;
  38346. + ERROR(fsg, "can't allocate request for %s\n", ep->name);
  38347. + return -ENOMEM;
  38348. +}
  38349. +
  38350. +/*
  38351. + * Reset interface setting and re-init endpoint state (toggle etc).
  38352. + * Call with altsetting < 0 to disable the interface. The only other
  38353. + * available altsetting is 0, which enables the interface.
  38354. + */
  38355. +static int do_set_interface(struct fsg_dev *fsg, int altsetting)
  38356. +{
  38357. + int rc = 0;
  38358. + int i;
  38359. + const struct usb_endpoint_descriptor *d;
  38360. +
  38361. + if (fsg->running)
  38362. + DBG(fsg, "reset interface\n");
  38363. +
  38364. +reset:
  38365. + /* Deallocate the requests */
  38366. + for (i = 0; i < fsg_num_buffers; ++i) {
  38367. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  38368. +
  38369. + if (bh->inreq) {
  38370. + usb_ep_free_request(fsg->bulk_in, bh->inreq);
  38371. + bh->inreq = NULL;
  38372. + }
  38373. + if (bh->outreq) {
  38374. + usb_ep_free_request(fsg->bulk_out, bh->outreq);
  38375. + bh->outreq = NULL;
  38376. + }
  38377. + }
  38378. + if (fsg->intreq) {
  38379. + usb_ep_free_request(fsg->intr_in, fsg->intreq);
  38380. + fsg->intreq = NULL;
  38381. + }
  38382. +
  38383. + /* Disable the endpoints */
  38384. + if (fsg->bulk_in_enabled) {
  38385. + usb_ep_disable(fsg->bulk_in);
  38386. + fsg->bulk_in_enabled = 0;
  38387. + }
  38388. + if (fsg->bulk_out_enabled) {
  38389. + usb_ep_disable(fsg->bulk_out);
  38390. + fsg->bulk_out_enabled = 0;
  38391. + }
  38392. + if (fsg->intr_in_enabled) {
  38393. + usb_ep_disable(fsg->intr_in);
  38394. + fsg->intr_in_enabled = 0;
  38395. + }
  38396. +
  38397. + fsg->running = 0;
  38398. + if (altsetting < 0 || rc != 0)
  38399. + return rc;
  38400. +
  38401. + DBG(fsg, "set interface %d\n", altsetting);
  38402. +
  38403. + /* Enable the endpoints */
  38404. + d = fsg_ep_desc(fsg->gadget,
  38405. + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
  38406. + &fsg_ss_bulk_in_desc);
  38407. + if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
  38408. + goto reset;
  38409. + fsg->bulk_in_enabled = 1;
  38410. +
  38411. + d = fsg_ep_desc(fsg->gadget,
  38412. + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
  38413. + &fsg_ss_bulk_out_desc);
  38414. + if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
  38415. + goto reset;
  38416. + fsg->bulk_out_enabled = 1;
  38417. + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d);
  38418. + clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  38419. +
  38420. + if (transport_is_cbi()) {
  38421. + d = fsg_ep_desc(fsg->gadget,
  38422. + &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc,
  38423. + &fsg_ss_intr_in_desc);
  38424. + if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
  38425. + goto reset;
  38426. + fsg->intr_in_enabled = 1;
  38427. + }
  38428. +
  38429. + /* Allocate the requests */
  38430. + for (i = 0; i < fsg_num_buffers; ++i) {
  38431. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  38432. +
  38433. + if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
  38434. + goto reset;
  38435. + if ((rc = alloc_request(fsg, fsg->bulk_out, &bh->outreq)) != 0)
  38436. + goto reset;
  38437. + bh->inreq->buf = bh->outreq->buf = bh->buf;
  38438. + bh->inreq->context = bh->outreq->context = bh;
  38439. + bh->inreq->complete = bulk_in_complete;
  38440. + bh->outreq->complete = bulk_out_complete;
  38441. + }
  38442. + if (transport_is_cbi()) {
  38443. + if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
  38444. + goto reset;
  38445. + fsg->intreq->complete = intr_in_complete;
  38446. + }
  38447. +
  38448. + fsg->running = 1;
  38449. + for (i = 0; i < fsg->nluns; ++i)
  38450. + fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  38451. + return rc;
  38452. +}
  38453. +
  38454. +
  38455. +/*
  38456. + * Change our operational configuration. This code must agree with the code
  38457. + * that returns config descriptors, and with interface altsetting code.
  38458. + *
  38459. + * It's also responsible for power management interactions. Some
  38460. + * configurations might not work with our current power sources.
  38461. + * For now we just assume the gadget is always self-powered.
  38462. + */
  38463. +static int do_set_config(struct fsg_dev *fsg, u8 new_config)
  38464. +{
  38465. + int rc = 0;
  38466. +
  38467. + /* Disable the single interface */
  38468. + if (fsg->config != 0) {
  38469. + DBG(fsg, "reset config\n");
  38470. + fsg->config = 0;
  38471. + rc = do_set_interface(fsg, -1);
  38472. + }
  38473. +
  38474. + /* Enable the interface */
  38475. + if (new_config != 0) {
  38476. + fsg->config = new_config;
  38477. + if ((rc = do_set_interface(fsg, 0)) != 0)
  38478. + fsg->config = 0; // Reset on errors
  38479. + else
  38480. + INFO(fsg, "%s config #%d\n",
  38481. + usb_speed_string(fsg->gadget->speed),
  38482. + fsg->config);
  38483. + }
  38484. + return rc;
  38485. +}
  38486. +
  38487. +
  38488. +/*-------------------------------------------------------------------------*/
  38489. +
  38490. +static void handle_exception(struct fsg_dev *fsg)
  38491. +{
  38492. + siginfo_t info;
  38493. + int sig;
  38494. + int i;
  38495. + int num_active;
  38496. + struct fsg_buffhd *bh;
  38497. + enum fsg_state old_state;
  38498. + u8 new_config;
  38499. + struct fsg_lun *curlun;
  38500. + unsigned int exception_req_tag;
  38501. + int rc;
  38502. +
  38503. + /* Clear the existing signals. Anything but SIGUSR1 is converted
  38504. + * into a high-priority EXIT exception. */
  38505. + for (;;) {
  38506. + sig = dequeue_signal_lock(current, &current->blocked, &info);
  38507. + if (!sig)
  38508. + break;
  38509. + if (sig != SIGUSR1) {
  38510. + if (fsg->state < FSG_STATE_EXIT)
  38511. + DBG(fsg, "Main thread exiting on signal\n");
  38512. + raise_exception(fsg, FSG_STATE_EXIT);
  38513. + }
  38514. + }
  38515. +
  38516. + /* Cancel all the pending transfers */
  38517. + if (fsg->intreq_busy)
  38518. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  38519. + for (i = 0; i < fsg_num_buffers; ++i) {
  38520. + bh = &fsg->buffhds[i];
  38521. + if (bh->inreq_busy)
  38522. + usb_ep_dequeue(fsg->bulk_in, bh->inreq);
  38523. + if (bh->outreq_busy)
  38524. + usb_ep_dequeue(fsg->bulk_out, bh->outreq);
  38525. + }
  38526. +
  38527. + /* Wait until everything is idle */
  38528. + for (;;) {
  38529. + num_active = fsg->intreq_busy;
  38530. + for (i = 0; i < fsg_num_buffers; ++i) {
  38531. + bh = &fsg->buffhds[i];
  38532. + num_active += bh->inreq_busy + bh->outreq_busy;
  38533. + }
  38534. + if (num_active == 0)
  38535. + break;
  38536. + if (sleep_thread(fsg))
  38537. + return;
  38538. + }
  38539. +
  38540. + /* Clear out the controller's fifos */
  38541. + if (fsg->bulk_in_enabled)
  38542. + usb_ep_fifo_flush(fsg->bulk_in);
  38543. + if (fsg->bulk_out_enabled)
  38544. + usb_ep_fifo_flush(fsg->bulk_out);
  38545. + if (fsg->intr_in_enabled)
  38546. + usb_ep_fifo_flush(fsg->intr_in);
  38547. +
  38548. + /* Reset the I/O buffer states and pointers, the SCSI
  38549. + * state, and the exception. Then invoke the handler. */
  38550. + spin_lock_irq(&fsg->lock);
  38551. +
  38552. + for (i = 0; i < fsg_num_buffers; ++i) {
  38553. + bh = &fsg->buffhds[i];
  38554. + bh->state = BUF_STATE_EMPTY;
  38555. + }
  38556. + fsg->next_buffhd_to_fill = fsg->next_buffhd_to_drain =
  38557. + &fsg->buffhds[0];
  38558. +
  38559. + exception_req_tag = fsg->exception_req_tag;
  38560. + new_config = fsg->new_config;
  38561. + old_state = fsg->state;
  38562. +
  38563. + if (old_state == FSG_STATE_ABORT_BULK_OUT)
  38564. + fsg->state = FSG_STATE_STATUS_PHASE;
  38565. + else {
  38566. + for (i = 0; i < fsg->nluns; ++i) {
  38567. + curlun = &fsg->luns[i];
  38568. + curlun->prevent_medium_removal = 0;
  38569. + curlun->sense_data = curlun->unit_attention_data =
  38570. + SS_NO_SENSE;
  38571. + curlun->sense_data_info = 0;
  38572. + curlun->info_valid = 0;
  38573. + }
  38574. + fsg->state = FSG_STATE_IDLE;
  38575. + }
  38576. + spin_unlock_irq(&fsg->lock);
  38577. +
  38578. + /* Carry out any extra actions required for the exception */
  38579. + switch (old_state) {
  38580. + default:
  38581. + break;
  38582. +
  38583. + case FSG_STATE_ABORT_BULK_OUT:
  38584. + send_status(fsg);
  38585. + spin_lock_irq(&fsg->lock);
  38586. + if (fsg->state == FSG_STATE_STATUS_PHASE)
  38587. + fsg->state = FSG_STATE_IDLE;
  38588. + spin_unlock_irq(&fsg->lock);
  38589. + break;
  38590. +
  38591. + case FSG_STATE_RESET:
  38592. + /* In case we were forced against our will to halt a
  38593. + * bulk endpoint, clear the halt now. (The SuperH UDC
  38594. + * requires this.) */
  38595. + if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  38596. + usb_ep_clear_halt(fsg->bulk_in);
  38597. +
  38598. + if (transport_is_bbb()) {
  38599. + if (fsg->ep0_req_tag == exception_req_tag)
  38600. + ep0_queue(fsg); // Complete the status stage
  38601. +
  38602. + } else if (transport_is_cbi())
  38603. + send_status(fsg); // Status by interrupt pipe
  38604. +
  38605. + /* Technically this should go here, but it would only be
  38606. + * a waste of time. Ditto for the INTERFACE_CHANGE and
  38607. + * CONFIG_CHANGE cases. */
  38608. + // for (i = 0; i < fsg->nluns; ++i)
  38609. + // fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  38610. + break;
  38611. +
  38612. + case FSG_STATE_INTERFACE_CHANGE:
  38613. + rc = do_set_interface(fsg, 0);
  38614. + if (fsg->ep0_req_tag != exception_req_tag)
  38615. + break;
  38616. + if (rc != 0) // STALL on errors
  38617. + fsg_set_halt(fsg, fsg->ep0);
  38618. + else // Complete the status stage
  38619. + ep0_queue(fsg);
  38620. + break;
  38621. +
  38622. + case FSG_STATE_CONFIG_CHANGE:
  38623. + rc = do_set_config(fsg, new_config);
  38624. + if (fsg->ep0_req_tag != exception_req_tag)
  38625. + break;
  38626. + if (rc != 0) // STALL on errors
  38627. + fsg_set_halt(fsg, fsg->ep0);
  38628. + else // Complete the status stage
  38629. + ep0_queue(fsg);
  38630. + break;
  38631. +
  38632. + case FSG_STATE_DISCONNECT:
  38633. + for (i = 0; i < fsg->nluns; ++i)
  38634. + fsg_lun_fsync_sub(fsg->luns + i);
  38635. + do_set_config(fsg, 0); // Unconfigured state
  38636. + break;
  38637. +
  38638. + case FSG_STATE_EXIT:
  38639. + case FSG_STATE_TERMINATED:
  38640. + do_set_config(fsg, 0); // Free resources
  38641. + spin_lock_irq(&fsg->lock);
  38642. + fsg->state = FSG_STATE_TERMINATED; // Stop the thread
  38643. + spin_unlock_irq(&fsg->lock);
  38644. + break;
  38645. + }
  38646. +}
  38647. +
  38648. +
  38649. +/*-------------------------------------------------------------------------*/
  38650. +
  38651. +static int fsg_main_thread(void *fsg_)
  38652. +{
  38653. + struct fsg_dev *fsg = fsg_;
  38654. +
  38655. + /* Allow the thread to be killed by a signal, but set the signal mask
  38656. + * to block everything but INT, TERM, KILL, and USR1. */
  38657. + allow_signal(SIGINT);
  38658. + allow_signal(SIGTERM);
  38659. + allow_signal(SIGKILL);
  38660. + allow_signal(SIGUSR1);
  38661. +
  38662. + /* Allow the thread to be frozen */
  38663. + set_freezable();
  38664. +
  38665. + /* Arrange for userspace references to be interpreted as kernel
  38666. + * pointers. That way we can pass a kernel pointer to a routine
  38667. + * that expects a __user pointer and it will work okay. */
  38668. + set_fs(get_ds());
  38669. +
  38670. + /* The main loop */
  38671. + while (fsg->state != FSG_STATE_TERMINATED) {
  38672. + if (exception_in_progress(fsg) || signal_pending(current)) {
  38673. + handle_exception(fsg);
  38674. + continue;
  38675. + }
  38676. +
  38677. + if (!fsg->running) {
  38678. + sleep_thread(fsg);
  38679. + continue;
  38680. + }
  38681. +
  38682. + if (get_next_command(fsg))
  38683. + continue;
  38684. +
  38685. + spin_lock_irq(&fsg->lock);
  38686. + if (!exception_in_progress(fsg))
  38687. + fsg->state = FSG_STATE_DATA_PHASE;
  38688. + spin_unlock_irq(&fsg->lock);
  38689. +
  38690. + if (do_scsi_command(fsg) || finish_reply(fsg))
  38691. + continue;
  38692. +
  38693. + spin_lock_irq(&fsg->lock);
  38694. + if (!exception_in_progress(fsg))
  38695. + fsg->state = FSG_STATE_STATUS_PHASE;
  38696. + spin_unlock_irq(&fsg->lock);
  38697. +
  38698. + if (send_status(fsg))
  38699. + continue;
  38700. +
  38701. + spin_lock_irq(&fsg->lock);
  38702. + if (!exception_in_progress(fsg))
  38703. + fsg->state = FSG_STATE_IDLE;
  38704. + spin_unlock_irq(&fsg->lock);
  38705. + }
  38706. +
  38707. + spin_lock_irq(&fsg->lock);
  38708. + fsg->thread_task = NULL;
  38709. + spin_unlock_irq(&fsg->lock);
  38710. +
  38711. + /* If we are exiting because of a signal, unregister the
  38712. + * gadget driver. */
  38713. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  38714. + usb_gadget_unregister_driver(&fsg_driver);
  38715. +
  38716. + /* Let the unbind and cleanup routines know the thread has exited */
  38717. + complete_and_exit(&fsg->thread_notifier, 0);
  38718. +}
  38719. +
  38720. +
  38721. +/*-------------------------------------------------------------------------*/
  38722. +
  38723. +
  38724. +/* The write permissions and store_xxx pointers are set in fsg_bind() */
  38725. +static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
  38726. +static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
  38727. +static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
  38728. +
  38729. +
  38730. +/*-------------------------------------------------------------------------*/
  38731. +
  38732. +static void fsg_release(struct kref *ref)
  38733. +{
  38734. + struct fsg_dev *fsg = container_of(ref, struct fsg_dev, ref);
  38735. +
  38736. + kfree(fsg->luns);
  38737. + kfree(fsg);
  38738. +}
  38739. +
  38740. +static void lun_release(struct device *dev)
  38741. +{
  38742. + struct rw_semaphore *filesem = dev_get_drvdata(dev);
  38743. + struct fsg_dev *fsg =
  38744. + container_of(filesem, struct fsg_dev, filesem);
  38745. +
  38746. + kref_put(&fsg->ref, fsg_release);
  38747. +}
  38748. +
  38749. +static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
  38750. +{
  38751. + struct fsg_dev *fsg = get_gadget_data(gadget);
  38752. + int i;
  38753. + struct fsg_lun *curlun;
  38754. + struct usb_request *req = fsg->ep0req;
  38755. +
  38756. + DBG(fsg, "unbind\n");
  38757. + clear_bit(REGISTERED, &fsg->atomic_bitflags);
  38758. +
  38759. + /* If the thread isn't already dead, tell it to exit now */
  38760. + if (fsg->state != FSG_STATE_TERMINATED) {
  38761. + raise_exception(fsg, FSG_STATE_EXIT);
  38762. + wait_for_completion(&fsg->thread_notifier);
  38763. +
  38764. + /* The cleanup routine waits for this completion also */
  38765. + complete(&fsg->thread_notifier);
  38766. + }
  38767. +
  38768. + /* Unregister the sysfs attribute files and the LUNs */
  38769. + for (i = 0; i < fsg->nluns; ++i) {
  38770. + curlun = &fsg->luns[i];
  38771. + if (curlun->registered) {
  38772. + device_remove_file(&curlun->dev, &dev_attr_nofua);
  38773. + device_remove_file(&curlun->dev, &dev_attr_ro);
  38774. + device_remove_file(&curlun->dev, &dev_attr_file);
  38775. + fsg_lun_close(curlun);
  38776. + device_unregister(&curlun->dev);
  38777. + curlun->registered = 0;
  38778. + }
  38779. + }
  38780. +
  38781. + /* Free the data buffers */
  38782. + for (i = 0; i < fsg_num_buffers; ++i)
  38783. + kfree(fsg->buffhds[i].buf);
  38784. +
  38785. + /* Free the request and buffer for endpoint 0 */
  38786. + if (req) {
  38787. + kfree(req->buf);
  38788. + usb_ep_free_request(fsg->ep0, req);
  38789. + }
  38790. +
  38791. + set_gadget_data(gadget, NULL);
  38792. +}
  38793. +
  38794. +
  38795. +static int __init check_parameters(struct fsg_dev *fsg)
  38796. +{
  38797. + int prot;
  38798. + int gcnum;
  38799. +
  38800. + /* Store the default values */
  38801. + mod_data.transport_type = USB_PR_BULK;
  38802. + mod_data.transport_name = "Bulk-only";
  38803. + mod_data.protocol_type = USB_SC_SCSI;
  38804. + mod_data.protocol_name = "Transparent SCSI";
  38805. +
  38806. + /* Some peripheral controllers are known not to be able to
  38807. + * halt bulk endpoints correctly. If one of them is present,
  38808. + * disable stalls.
  38809. + */
  38810. + if (gadget_is_at91(fsg->gadget))
  38811. + mod_data.can_stall = 0;
  38812. +
  38813. + if (mod_data.release == 0xffff) { // Parameter wasn't set
  38814. + gcnum = usb_gadget_controller_number(fsg->gadget);
  38815. + if (gcnum >= 0)
  38816. + mod_data.release = 0x0300 + gcnum;
  38817. + else {
  38818. + WARNING(fsg, "controller '%s' not recognized\n",
  38819. + fsg->gadget->name);
  38820. + mod_data.release = 0x0399;
  38821. + }
  38822. + }
  38823. +
  38824. + prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
  38825. +
  38826. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  38827. + if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
  38828. + ; // Use default setting
  38829. + } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
  38830. + mod_data.transport_type = USB_PR_CB;
  38831. + mod_data.transport_name = "Control-Bulk";
  38832. + } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
  38833. + mod_data.transport_type = USB_PR_CBI;
  38834. + mod_data.transport_name = "Control-Bulk-Interrupt";
  38835. + } else {
  38836. + ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
  38837. + return -EINVAL;
  38838. + }
  38839. +
  38840. + if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
  38841. + prot == USB_SC_SCSI) {
  38842. + ; // Use default setting
  38843. + } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
  38844. + prot == USB_SC_RBC) {
  38845. + mod_data.protocol_type = USB_SC_RBC;
  38846. + mod_data.protocol_name = "RBC";
  38847. + } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
  38848. + strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
  38849. + prot == USB_SC_8020) {
  38850. + mod_data.protocol_type = USB_SC_8020;
  38851. + mod_data.protocol_name = "8020i (ATAPI)";
  38852. + } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
  38853. + prot == USB_SC_QIC) {
  38854. + mod_data.protocol_type = USB_SC_QIC;
  38855. + mod_data.protocol_name = "QIC-157";
  38856. + } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
  38857. + prot == USB_SC_UFI) {
  38858. + mod_data.protocol_type = USB_SC_UFI;
  38859. + mod_data.protocol_name = "UFI";
  38860. + } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
  38861. + prot == USB_SC_8070) {
  38862. + mod_data.protocol_type = USB_SC_8070;
  38863. + mod_data.protocol_name = "8070i";
  38864. + } else {
  38865. + ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
  38866. + return -EINVAL;
  38867. + }
  38868. +
  38869. + mod_data.buflen &= PAGE_CACHE_MASK;
  38870. + if (mod_data.buflen <= 0) {
  38871. + ERROR(fsg, "invalid buflen\n");
  38872. + return -ETOOSMALL;
  38873. + }
  38874. +
  38875. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  38876. +
  38877. + /* Serial string handling.
  38878. + * On a real device, the serial string would be loaded
  38879. + * from permanent storage. */
  38880. + if (mod_data.serial) {
  38881. + const char *ch;
  38882. + unsigned len = 0;
  38883. +
  38884. + /* Sanity check :
  38885. + * The CB[I] specification limits the serial string to
  38886. + * 12 uppercase hexadecimal characters.
  38887. + * BBB need at least 12 uppercase hexadecimal characters,
  38888. + * with a maximum of 126. */
  38889. + for (ch = mod_data.serial; *ch; ++ch) {
  38890. + ++len;
  38891. + if ((*ch < '0' || *ch > '9') &&
  38892. + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
  38893. + WARNING(fsg,
  38894. + "Invalid serial string character: %c\n",
  38895. + *ch);
  38896. + goto no_serial;
  38897. + }
  38898. + }
  38899. + if (len > 126 ||
  38900. + (mod_data.transport_type == USB_PR_BULK && len < 12) ||
  38901. + (mod_data.transport_type != USB_PR_BULK && len > 12)) {
  38902. + WARNING(fsg, "Invalid serial string length!\n");
  38903. + goto no_serial;
  38904. + }
  38905. + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
  38906. + } else {
  38907. + WARNING(fsg, "No serial-number string provided!\n");
  38908. + no_serial:
  38909. + device_desc.iSerialNumber = 0;
  38910. + }
  38911. +
  38912. + return 0;
  38913. +}
  38914. +
  38915. +
  38916. +static int __init fsg_bind(struct usb_gadget *gadget)
  38917. +{
  38918. + struct fsg_dev *fsg = the_fsg;
  38919. + int rc;
  38920. + int i;
  38921. + struct fsg_lun *curlun;
  38922. + struct usb_ep *ep;
  38923. + struct usb_request *req;
  38924. + char *pathbuf, *p;
  38925. +
  38926. + fsg->gadget = gadget;
  38927. + set_gadget_data(gadget, fsg);
  38928. + fsg->ep0 = gadget->ep0;
  38929. + fsg->ep0->driver_data = fsg;
  38930. +
  38931. + if ((rc = check_parameters(fsg)) != 0)
  38932. + goto out;
  38933. +
  38934. + if (mod_data.removable) { // Enable the store_xxx attributes
  38935. + dev_attr_file.attr.mode = 0644;
  38936. + dev_attr_file.store = fsg_store_file;
  38937. + if (!mod_data.cdrom) {
  38938. + dev_attr_ro.attr.mode = 0644;
  38939. + dev_attr_ro.store = fsg_store_ro;
  38940. + }
  38941. + }
  38942. +
  38943. + /* Only for removable media? */
  38944. + dev_attr_nofua.attr.mode = 0644;
  38945. + dev_attr_nofua.store = fsg_store_nofua;
  38946. +
  38947. + /* Find out how many LUNs there should be */
  38948. + i = mod_data.nluns;
  38949. + if (i == 0)
  38950. + i = max(mod_data.num_filenames, 1u);
  38951. + if (i > FSG_MAX_LUNS) {
  38952. + ERROR(fsg, "invalid number of LUNs: %d\n", i);
  38953. + rc = -EINVAL;
  38954. + goto out;
  38955. + }
  38956. +
  38957. + /* Create the LUNs, open their backing files, and register the
  38958. + * LUN devices in sysfs. */
  38959. + fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
  38960. + if (!fsg->luns) {
  38961. + rc = -ENOMEM;
  38962. + goto out;
  38963. + }
  38964. + fsg->nluns = i;
  38965. +
  38966. + for (i = 0; i < fsg->nluns; ++i) {
  38967. + curlun = &fsg->luns[i];
  38968. + curlun->cdrom = !!mod_data.cdrom;
  38969. + curlun->ro = mod_data.cdrom || mod_data.ro[i];
  38970. + curlun->initially_ro = curlun->ro;
  38971. + curlun->removable = mod_data.removable;
  38972. + curlun->nofua = mod_data.nofua[i];
  38973. + curlun->dev.release = lun_release;
  38974. + curlun->dev.parent = &gadget->dev;
  38975. + curlun->dev.driver = &fsg_driver.driver;
  38976. + dev_set_drvdata(&curlun->dev, &fsg->filesem);
  38977. + dev_set_name(&curlun->dev,"%s-lun%d",
  38978. + dev_name(&gadget->dev), i);
  38979. +
  38980. + kref_get(&fsg->ref);
  38981. + rc = device_register(&curlun->dev);
  38982. + if (rc) {
  38983. + INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
  38984. + put_device(&curlun->dev);
  38985. + goto out;
  38986. + }
  38987. + curlun->registered = 1;
  38988. +
  38989. + rc = device_create_file(&curlun->dev, &dev_attr_ro);
  38990. + if (rc)
  38991. + goto out;
  38992. + rc = device_create_file(&curlun->dev, &dev_attr_nofua);
  38993. + if (rc)
  38994. + goto out;
  38995. + rc = device_create_file(&curlun->dev, &dev_attr_file);
  38996. + if (rc)
  38997. + goto out;
  38998. +
  38999. + if (mod_data.file[i] && *mod_data.file[i]) {
  39000. + rc = fsg_lun_open(curlun, mod_data.file[i]);
  39001. + if (rc)
  39002. + goto out;
  39003. + } else if (!mod_data.removable) {
  39004. + ERROR(fsg, "no file given for LUN%d\n", i);
  39005. + rc = -EINVAL;
  39006. + goto out;
  39007. + }
  39008. + }
  39009. +
  39010. + /* Find all the endpoints we will use */
  39011. + usb_ep_autoconfig_reset(gadget);
  39012. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
  39013. + if (!ep)
  39014. + goto autoconf_fail;
  39015. + ep->driver_data = fsg; // claim the endpoint
  39016. + fsg->bulk_in = ep;
  39017. +
  39018. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
  39019. + if (!ep)
  39020. + goto autoconf_fail;
  39021. + ep->driver_data = fsg; // claim the endpoint
  39022. + fsg->bulk_out = ep;
  39023. +
  39024. + if (transport_is_cbi()) {
  39025. + ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
  39026. + if (!ep)
  39027. + goto autoconf_fail;
  39028. + ep->driver_data = fsg; // claim the endpoint
  39029. + fsg->intr_in = ep;
  39030. + }
  39031. +
  39032. + /* Fix up the descriptors */
  39033. + device_desc.idVendor = cpu_to_le16(mod_data.vendor);
  39034. + device_desc.idProduct = cpu_to_le16(mod_data.product);
  39035. + device_desc.bcdDevice = cpu_to_le16(mod_data.release);
  39036. +
  39037. + i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
  39038. + fsg_intf_desc.bNumEndpoints = i;
  39039. + fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
  39040. + fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
  39041. + fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  39042. +
  39043. + if (gadget_is_dualspeed(gadget)) {
  39044. + fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  39045. +
  39046. + /* Assume endpoint addresses are the same for both speeds */
  39047. + fsg_hs_bulk_in_desc.bEndpointAddress =
  39048. + fsg_fs_bulk_in_desc.bEndpointAddress;
  39049. + fsg_hs_bulk_out_desc.bEndpointAddress =
  39050. + fsg_fs_bulk_out_desc.bEndpointAddress;
  39051. + fsg_hs_intr_in_desc.bEndpointAddress =
  39052. + fsg_fs_intr_in_desc.bEndpointAddress;
  39053. + }
  39054. +
  39055. + if (gadget_is_superspeed(gadget)) {
  39056. + unsigned max_burst;
  39057. +
  39058. + fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  39059. +
  39060. + /* Calculate bMaxBurst, we know packet size is 1024 */
  39061. + max_burst = min_t(unsigned, mod_data.buflen / 1024, 15);
  39062. +
  39063. + /* Assume endpoint addresses are the same for both speeds */
  39064. + fsg_ss_bulk_in_desc.bEndpointAddress =
  39065. + fsg_fs_bulk_in_desc.bEndpointAddress;
  39066. + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
  39067. +
  39068. + fsg_ss_bulk_out_desc.bEndpointAddress =
  39069. + fsg_fs_bulk_out_desc.bEndpointAddress;
  39070. + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
  39071. + }
  39072. +
  39073. + if (gadget_is_otg(gadget))
  39074. + fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
  39075. +
  39076. + rc = -ENOMEM;
  39077. +
  39078. + /* Allocate the request and buffer for endpoint 0 */
  39079. + fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
  39080. + if (!req)
  39081. + goto out;
  39082. + req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
  39083. + if (!req->buf)
  39084. + goto out;
  39085. + req->complete = ep0_complete;
  39086. +
  39087. + /* Allocate the data buffers */
  39088. + for (i = 0; i < fsg_num_buffers; ++i) {
  39089. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  39090. +
  39091. + /* Allocate for the bulk-in endpoint. We assume that
  39092. + * the buffer will also work with the bulk-out (and
  39093. + * interrupt-in) endpoint. */
  39094. + bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
  39095. + if (!bh->buf)
  39096. + goto out;
  39097. + bh->next = bh + 1;
  39098. + }
  39099. + fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  39100. +
  39101. + /* This should reflect the actual gadget power source */
  39102. + usb_gadget_set_selfpowered(gadget);
  39103. +
  39104. + snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
  39105. + "%s %s with %s",
  39106. + init_utsname()->sysname, init_utsname()->release,
  39107. + gadget->name);
  39108. +
  39109. + fsg->thread_task = kthread_create(fsg_main_thread, fsg,
  39110. + "file-storage-gadget");
  39111. + if (IS_ERR(fsg->thread_task)) {
  39112. + rc = PTR_ERR(fsg->thread_task);
  39113. + goto out;
  39114. + }
  39115. +
  39116. + INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
  39117. + INFO(fsg, "NOTE: This driver is deprecated. "
  39118. + "Consider using g_mass_storage instead.\n");
  39119. + INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
  39120. +
  39121. + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  39122. + for (i = 0; i < fsg->nluns; ++i) {
  39123. + curlun = &fsg->luns[i];
  39124. + if (fsg_lun_is_open(curlun)) {
  39125. + p = NULL;
  39126. + if (pathbuf) {
  39127. + p = d_path(&curlun->filp->f_path,
  39128. + pathbuf, PATH_MAX);
  39129. + if (IS_ERR(p))
  39130. + p = NULL;
  39131. + }
  39132. + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
  39133. + curlun->ro, curlun->nofua, (p ? p : "(error)"));
  39134. + }
  39135. + }
  39136. + kfree(pathbuf);
  39137. +
  39138. + DBG(fsg, "transport=%s (x%02x)\n",
  39139. + mod_data.transport_name, mod_data.transport_type);
  39140. + DBG(fsg, "protocol=%s (x%02x)\n",
  39141. + mod_data.protocol_name, mod_data.protocol_type);
  39142. + DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
  39143. + mod_data.vendor, mod_data.product, mod_data.release);
  39144. + DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
  39145. + mod_data.removable, mod_data.can_stall,
  39146. + mod_data.cdrom, mod_data.buflen);
  39147. + DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
  39148. +
  39149. + set_bit(REGISTERED, &fsg->atomic_bitflags);
  39150. +
  39151. + /* Tell the thread to start working */
  39152. + wake_up_process(fsg->thread_task);
  39153. + return 0;
  39154. +
  39155. +autoconf_fail:
  39156. + ERROR(fsg, "unable to autoconfigure all endpoints\n");
  39157. + rc = -ENOTSUPP;
  39158. +
  39159. +out:
  39160. + fsg->state = FSG_STATE_TERMINATED; // The thread is dead
  39161. + fsg_unbind(gadget);
  39162. + complete(&fsg->thread_notifier);
  39163. + return rc;
  39164. +}
  39165. +
  39166. +
  39167. +/*-------------------------------------------------------------------------*/
  39168. +
  39169. +static void fsg_suspend(struct usb_gadget *gadget)
  39170. +{
  39171. + struct fsg_dev *fsg = get_gadget_data(gadget);
  39172. +
  39173. + DBG(fsg, "suspend\n");
  39174. + set_bit(SUSPENDED, &fsg->atomic_bitflags);
  39175. +}
  39176. +
  39177. +static void fsg_resume(struct usb_gadget *gadget)
  39178. +{
  39179. + struct fsg_dev *fsg = get_gadget_data(gadget);
  39180. +
  39181. + DBG(fsg, "resume\n");
  39182. + clear_bit(SUSPENDED, &fsg->atomic_bitflags);
  39183. +}
  39184. +
  39185. +
  39186. +/*-------------------------------------------------------------------------*/
  39187. +
  39188. +static struct usb_gadget_driver fsg_driver = {
  39189. + .max_speed = USB_SPEED_SUPER,
  39190. + .function = (char *) fsg_string_product,
  39191. + .unbind = fsg_unbind,
  39192. + .disconnect = fsg_disconnect,
  39193. + .setup = fsg_setup,
  39194. + .suspend = fsg_suspend,
  39195. + .resume = fsg_resume,
  39196. +
  39197. + .driver = {
  39198. + .name = DRIVER_NAME,
  39199. + .owner = THIS_MODULE,
  39200. + // .release = ...
  39201. + // .suspend = ...
  39202. + // .resume = ...
  39203. + },
  39204. +};
  39205. +
  39206. +
  39207. +static int __init fsg_alloc(void)
  39208. +{
  39209. + struct fsg_dev *fsg;
  39210. +
  39211. + fsg = kzalloc(sizeof *fsg +
  39212. + fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
  39213. +
  39214. + if (!fsg)
  39215. + return -ENOMEM;
  39216. + spin_lock_init(&fsg->lock);
  39217. + init_rwsem(&fsg->filesem);
  39218. + kref_init(&fsg->ref);
  39219. + init_completion(&fsg->thread_notifier);
  39220. +
  39221. + the_fsg = fsg;
  39222. + return 0;
  39223. +}
  39224. +
  39225. +
  39226. +static int __init fsg_init(void)
  39227. +{
  39228. + int rc;
  39229. + struct fsg_dev *fsg;
  39230. +
  39231. + rc = fsg_num_buffers_validate();
  39232. + if (rc != 0)
  39233. + return rc;
  39234. +
  39235. + if ((rc = fsg_alloc()) != 0)
  39236. + return rc;
  39237. + fsg = the_fsg;
  39238. + if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
  39239. + kref_put(&fsg->ref, fsg_release);
  39240. + return rc;
  39241. +}
  39242. +module_init(fsg_init);
  39243. +
  39244. +
  39245. +static void __exit fsg_cleanup(void)
  39246. +{
  39247. + struct fsg_dev *fsg = the_fsg;
  39248. +
  39249. + /* Unregister the driver iff the thread hasn't already done so */
  39250. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  39251. + usb_gadget_unregister_driver(&fsg_driver);
  39252. +
  39253. + /* Wait for the thread to finish up */
  39254. + wait_for_completion(&fsg->thread_notifier);
  39255. +
  39256. + kref_put(&fsg->ref, fsg_release);
  39257. +}
  39258. +module_exit(fsg_cleanup);
  39259. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/changes.txt linux-rpi/drivers/usb/host/dwc_common_port/changes.txt
  39260. --- linux-3.12.18/drivers/usb/host/dwc_common_port/changes.txt 1970-01-01 01:00:00.000000000 +0100
  39261. +++ linux-rpi/drivers/usb/host/dwc_common_port/changes.txt 2014-04-24 15:35:04.169565731 +0200
  39262. @@ -0,0 +1,174 @@
  39263. +
  39264. +dwc_read_reg32() and friends now take an additional parameter, a pointer to an
  39265. +IO context struct. The IO context struct should live in an os-dependent struct
  39266. +in your driver. As an example, the dwc_usb3 driver has an os-dependent struct
  39267. +named 'os_dep' embedded in the main device struct. So there these calls look
  39268. +like this:
  39269. +
  39270. + dwc_read_reg32(&usb3_dev->os_dep.ioctx, &pcd->dev_global_regs->dcfg);
  39271. +
  39272. + dwc_write_reg32(&usb3_dev->os_dep.ioctx,
  39273. + &pcd->dev_global_regs->dcfg, 0);
  39274. +
  39275. +Note that for the existing Linux driver ports, it is not necessary to actually
  39276. +define the 'ioctx' member in the os-dependent struct. Since Linux does not
  39277. +require an IO context, its macros for dwc_read_reg32() and friends do not
  39278. +use the context pointer, so it is optimized away by the compiler. But it is
  39279. +necessary to add the pointer parameter to all of the call sites, to be ready
  39280. +for any future ports (such as FreeBSD) which do require an IO context.
  39281. +
  39282. +
  39283. +Similarly, dwc_alloc(), dwc_alloc_atomic(), dwc_strdup(), and dwc_free() now
  39284. +take an additional parameter, a pointer to a memory context. Examples:
  39285. +
  39286. + addr = dwc_alloc(&usb3_dev->os_dep.memctx, size);
  39287. +
  39288. + dwc_free(&usb3_dev->os_dep.memctx, addr);
  39289. +
  39290. +Again, for the Linux ports, it is not necessary to actually define the memctx
  39291. +member, but it is necessary to add the pointer parameter to all of the call
  39292. +sites.
  39293. +
  39294. +
  39295. +Same for dwc_dma_alloc() and dwc_dma_free(). Examples:
  39296. +
  39297. + virt_addr = dwc_dma_alloc(&usb3_dev->os_dep.dmactx, size, &phys_addr);
  39298. +
  39299. + dwc_dma_free(&usb3_dev->os_dep.dmactx, size, virt_addr, phys_addr);
  39300. +
  39301. +
  39302. +Same for dwc_mutex_alloc() and dwc_mutex_free(). Examples:
  39303. +
  39304. + mutex = dwc_mutex_alloc(&usb3_dev->os_dep.mtxctx);
  39305. +
  39306. + dwc_mutex_free(&usb3_dev->os_dep.mtxctx, mutex);
  39307. +
  39308. +
  39309. +Same for dwc_spinlock_alloc() and dwc_spinlock_free(). Examples:
  39310. +
  39311. + lock = dwc_spinlock_alloc(&usb3_dev->osdep.splctx);
  39312. +
  39313. + dwc_spinlock_free(&usb3_dev->osdep.splctx, lock);
  39314. +
  39315. +
  39316. +Same for dwc_timer_alloc(). Example:
  39317. +
  39318. + timer = dwc_timer_alloc(&usb3_dev->os_dep.tmrctx, "dwc_usb3_tmr1",
  39319. + cb_func, cb_data);
  39320. +
  39321. +
  39322. +Same for dwc_waitq_alloc(). Example:
  39323. +
  39324. + waitq = dwc_waitq_alloc(&usb3_dev->os_dep.wtqctx);
  39325. +
  39326. +
  39327. +Same for dwc_thread_run(). Example:
  39328. +
  39329. + thread = dwc_thread_run(&usb3_dev->os_dep.thdctx, func,
  39330. + "dwc_usb3_thd1", data);
  39331. +
  39332. +
  39333. +Same for dwc_workq_alloc(). Example:
  39334. +
  39335. + workq = dwc_workq_alloc(&usb3_dev->osdep.wkqctx, "dwc_usb3_wkq1");
  39336. +
  39337. +
  39338. +Same for dwc_task_alloc(). Example:
  39339. +
  39340. + task = dwc_task_alloc(&usb3_dev->os_dep.tskctx, "dwc_usb3_tsk1",
  39341. + cb_func, cb_data);
  39342. +
  39343. +
  39344. +In addition to the context pointer additions, a few core functions have had
  39345. +other changes made to their parameters:
  39346. +
  39347. +The 'flags' parameter to dwc_spinlock_irqsave() and dwc_spinunlock_irqrestore()
  39348. +has been changed from a uint64_t to a dwc_irqflags_t.
  39349. +
  39350. +dwc_thread_should_stop() now takes a 'dwc_thread_t *' parameter, because the
  39351. +FreeBSD equivalent of that function requires it.
  39352. +
  39353. +And, in addition to the context pointer, dwc_task_alloc() also adds a
  39354. +'char *name' parameter, to be consistent with dwc_thread_run() and
  39355. +dwc_workq_alloc(), and because the FreeBSD equivalent of that function
  39356. +requires a unique name.
  39357. +
  39358. +
  39359. +Here is a complete list of the core functions that now take a pointer to a
  39360. +context as their first parameter:
  39361. +
  39362. + dwc_read_reg32
  39363. + dwc_read_reg64
  39364. + dwc_write_reg32
  39365. + dwc_write_reg64
  39366. + dwc_modify_reg32
  39367. + dwc_modify_reg64
  39368. + dwc_alloc
  39369. + dwc_alloc_atomic
  39370. + dwc_strdup
  39371. + dwc_free
  39372. + dwc_dma_alloc
  39373. + dwc_dma_free
  39374. + dwc_mutex_alloc
  39375. + dwc_mutex_free
  39376. + dwc_spinlock_alloc
  39377. + dwc_spinlock_free
  39378. + dwc_timer_alloc
  39379. + dwc_waitq_alloc
  39380. + dwc_thread_run
  39381. + dwc_workq_alloc
  39382. + dwc_task_alloc Also adds a 'char *name' as its 2nd parameter
  39383. +
  39384. +And here are the core functions that have other changes to their parameters:
  39385. +
  39386. + dwc_spinlock_irqsave 'flags' param is now a 'dwc_irqflags_t *'
  39387. + dwc_spinunlock_irqrestore 'flags' param is now a 'dwc_irqflags_t'
  39388. + dwc_thread_should_stop Adds a 'dwc_thread_t *' parameter
  39389. +
  39390. +
  39391. +
  39392. +The changes to the core functions also require some of the other library
  39393. +functions to change:
  39394. +
  39395. + dwc_cc_if_alloc() and dwc_cc_if_free() now take a 'void *memctx'
  39396. + (for memory allocation) as the 1st param and a 'void *mtxctx'
  39397. + (for mutex allocation) as the 2nd param.
  39398. +
  39399. + dwc_cc_clear(), dwc_cc_add(), dwc_cc_change(), dwc_cc_remove(),
  39400. + dwc_cc_data_for_save(), and dwc_cc_restore_from_data() now take a
  39401. + 'void *memctx' as the 1st param.
  39402. +
  39403. + dwc_dh_modpow(), dwc_dh_pk(), and dwc_dh_derive_keys() now take a
  39404. + 'void *memctx' as the 1st param.
  39405. +
  39406. + dwc_modpow() now takes a 'void *memctx' as the 1st param.
  39407. +
  39408. + dwc_alloc_notification_manager() now takes a 'void *memctx' as the
  39409. + 1st param and a 'void *wkqctx' (for work queue allocation) as the 2nd
  39410. + param, and also now returns an integer value that is non-zero if
  39411. + allocation of its data structures or work queue fails.
  39412. +
  39413. + dwc_register_notifier() now takes a 'void *memctx' as the 1st param.
  39414. +
  39415. + dwc_memory_debug_start() now takes a 'void *mem_ctx' as the first
  39416. + param, and also now returns an integer value that is non-zero if
  39417. + allocation of its data structures fails.
  39418. +
  39419. +
  39420. +
  39421. +Other miscellaneous changes:
  39422. +
  39423. +The DEBUG_MEMORY and DEBUG_REGS #define's have been renamed to
  39424. +DWC_DEBUG_MEMORY and DWC_DEBUG_REGS.
  39425. +
  39426. +The following #define's have been added to allow selectively compiling library
  39427. +features:
  39428. +
  39429. + DWC_CCLIB
  39430. + DWC_CRYPTOLIB
  39431. + DWC_NOTIFYLIB
  39432. + DWC_UTFLIB
  39433. +
  39434. +A DWC_LIBMODULE #define has also been added. If this is not defined, then the
  39435. +module code in dwc_common_linux.c is not compiled in. This allows linking the
  39436. +library code directly into a driver module, instead of as a standalone module.
  39437. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg
  39438. --- linux-3.12.18/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  39439. +++ linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 2014-04-24 16:04:39.811124176 +0200
  39440. @@ -0,0 +1,270 @@
  39441. +# Doxyfile 1.4.5
  39442. +
  39443. +#---------------------------------------------------------------------------
  39444. +# Project related configuration options
  39445. +#---------------------------------------------------------------------------
  39446. +PROJECT_NAME = "Synopsys DWC Portability and Common Library for UWB"
  39447. +PROJECT_NUMBER =
  39448. +OUTPUT_DIRECTORY = doc
  39449. +CREATE_SUBDIRS = NO
  39450. +OUTPUT_LANGUAGE = English
  39451. +BRIEF_MEMBER_DESC = YES
  39452. +REPEAT_BRIEF = YES
  39453. +ABBREVIATE_BRIEF = "The $name class" \
  39454. + "The $name widget" \
  39455. + "The $name file" \
  39456. + is \
  39457. + provides \
  39458. + specifies \
  39459. + contains \
  39460. + represents \
  39461. + a \
  39462. + an \
  39463. + the
  39464. +ALWAYS_DETAILED_SEC = YES
  39465. +INLINE_INHERITED_MEMB = NO
  39466. +FULL_PATH_NAMES = NO
  39467. +STRIP_FROM_PATH = ..
  39468. +STRIP_FROM_INC_PATH =
  39469. +SHORT_NAMES = NO
  39470. +JAVADOC_AUTOBRIEF = YES
  39471. +MULTILINE_CPP_IS_BRIEF = NO
  39472. +DETAILS_AT_TOP = YES
  39473. +INHERIT_DOCS = YES
  39474. +SEPARATE_MEMBER_PAGES = NO
  39475. +TAB_SIZE = 8
  39476. +ALIASES =
  39477. +OPTIMIZE_OUTPUT_FOR_C = YES
  39478. +OPTIMIZE_OUTPUT_JAVA = NO
  39479. +BUILTIN_STL_SUPPORT = NO
  39480. +DISTRIBUTE_GROUP_DOC = NO
  39481. +SUBGROUPING = NO
  39482. +#---------------------------------------------------------------------------
  39483. +# Build related configuration options
  39484. +#---------------------------------------------------------------------------
  39485. +EXTRACT_ALL = NO
  39486. +EXTRACT_PRIVATE = NO
  39487. +EXTRACT_STATIC = YES
  39488. +EXTRACT_LOCAL_CLASSES = NO
  39489. +EXTRACT_LOCAL_METHODS = NO
  39490. +HIDE_UNDOC_MEMBERS = NO
  39491. +HIDE_UNDOC_CLASSES = NO
  39492. +HIDE_FRIEND_COMPOUNDS = NO
  39493. +HIDE_IN_BODY_DOCS = NO
  39494. +INTERNAL_DOCS = NO
  39495. +CASE_SENSE_NAMES = YES
  39496. +HIDE_SCOPE_NAMES = NO
  39497. +SHOW_INCLUDE_FILES = NO
  39498. +INLINE_INFO = YES
  39499. +SORT_MEMBER_DOCS = NO
  39500. +SORT_BRIEF_DOCS = NO
  39501. +SORT_BY_SCOPE_NAME = NO
  39502. +GENERATE_TODOLIST = YES
  39503. +GENERATE_TESTLIST = YES
  39504. +GENERATE_BUGLIST = YES
  39505. +GENERATE_DEPRECATEDLIST= YES
  39506. +ENABLED_SECTIONS =
  39507. +MAX_INITIALIZER_LINES = 30
  39508. +SHOW_USED_FILES = YES
  39509. +SHOW_DIRECTORIES = YES
  39510. +FILE_VERSION_FILTER =
  39511. +#---------------------------------------------------------------------------
  39512. +# configuration options related to warning and progress messages
  39513. +#---------------------------------------------------------------------------
  39514. +QUIET = YES
  39515. +WARNINGS = YES
  39516. +WARN_IF_UNDOCUMENTED = NO
  39517. +WARN_IF_DOC_ERROR = YES
  39518. +WARN_NO_PARAMDOC = YES
  39519. +WARN_FORMAT = "$file:$line: $text"
  39520. +WARN_LOGFILE =
  39521. +#---------------------------------------------------------------------------
  39522. +# configuration options related to the input files
  39523. +#---------------------------------------------------------------------------
  39524. +INPUT = .
  39525. +FILE_PATTERNS = *.c \
  39526. + *.cc \
  39527. + *.cxx \
  39528. + *.cpp \
  39529. + *.c++ \
  39530. + *.d \
  39531. + *.java \
  39532. + *.ii \
  39533. + *.ixx \
  39534. + *.ipp \
  39535. + *.i++ \
  39536. + *.inl \
  39537. + *.h \
  39538. + *.hh \
  39539. + *.hxx \
  39540. + *.hpp \
  39541. + *.h++ \
  39542. + *.idl \
  39543. + *.odl \
  39544. + *.cs \
  39545. + *.php \
  39546. + *.php3 \
  39547. + *.inc \
  39548. + *.m \
  39549. + *.mm \
  39550. + *.dox \
  39551. + *.py \
  39552. + *.C \
  39553. + *.CC \
  39554. + *.C++ \
  39555. + *.II \
  39556. + *.I++ \
  39557. + *.H \
  39558. + *.HH \
  39559. + *.H++ \
  39560. + *.CS \
  39561. + *.PHP \
  39562. + *.PHP3 \
  39563. + *.M \
  39564. + *.MM \
  39565. + *.PY
  39566. +RECURSIVE = NO
  39567. +EXCLUDE =
  39568. +EXCLUDE_SYMLINKS = NO
  39569. +EXCLUDE_PATTERNS =
  39570. +EXAMPLE_PATH =
  39571. +EXAMPLE_PATTERNS = *
  39572. +EXAMPLE_RECURSIVE = NO
  39573. +IMAGE_PATH =
  39574. +INPUT_FILTER =
  39575. +FILTER_PATTERNS =
  39576. +FILTER_SOURCE_FILES = NO
  39577. +#---------------------------------------------------------------------------
  39578. +# configuration options related to source browsing
  39579. +#---------------------------------------------------------------------------
  39580. +SOURCE_BROWSER = NO
  39581. +INLINE_SOURCES = NO
  39582. +STRIP_CODE_COMMENTS = YES
  39583. +REFERENCED_BY_RELATION = YES
  39584. +REFERENCES_RELATION = YES
  39585. +USE_HTAGS = NO
  39586. +VERBATIM_HEADERS = NO
  39587. +#---------------------------------------------------------------------------
  39588. +# configuration options related to the alphabetical class index
  39589. +#---------------------------------------------------------------------------
  39590. +ALPHABETICAL_INDEX = NO
  39591. +COLS_IN_ALPHA_INDEX = 5
  39592. +IGNORE_PREFIX =
  39593. +#---------------------------------------------------------------------------
  39594. +# configuration options related to the HTML output
  39595. +#---------------------------------------------------------------------------
  39596. +GENERATE_HTML = YES
  39597. +HTML_OUTPUT = html
  39598. +HTML_FILE_EXTENSION = .html
  39599. +HTML_HEADER =
  39600. +HTML_FOOTER =
  39601. +HTML_STYLESHEET =
  39602. +HTML_ALIGN_MEMBERS = YES
  39603. +GENERATE_HTMLHELP = NO
  39604. +CHM_FILE =
  39605. +HHC_LOCATION =
  39606. +GENERATE_CHI = NO
  39607. +BINARY_TOC = NO
  39608. +TOC_EXPAND = NO
  39609. +DISABLE_INDEX = NO
  39610. +ENUM_VALUES_PER_LINE = 4
  39611. +GENERATE_TREEVIEW = YES
  39612. +TREEVIEW_WIDTH = 250
  39613. +#---------------------------------------------------------------------------
  39614. +# configuration options related to the LaTeX output
  39615. +#---------------------------------------------------------------------------
  39616. +GENERATE_LATEX = NO
  39617. +LATEX_OUTPUT = latex
  39618. +LATEX_CMD_NAME = latex
  39619. +MAKEINDEX_CMD_NAME = makeindex
  39620. +COMPACT_LATEX = NO
  39621. +PAPER_TYPE = a4wide
  39622. +EXTRA_PACKAGES =
  39623. +LATEX_HEADER =
  39624. +PDF_HYPERLINKS = NO
  39625. +USE_PDFLATEX = NO
  39626. +LATEX_BATCHMODE = NO
  39627. +LATEX_HIDE_INDICES = NO
  39628. +#---------------------------------------------------------------------------
  39629. +# configuration options related to the RTF output
  39630. +#---------------------------------------------------------------------------
  39631. +GENERATE_RTF = NO
  39632. +RTF_OUTPUT = rtf
  39633. +COMPACT_RTF = NO
  39634. +RTF_HYPERLINKS = NO
  39635. +RTF_STYLESHEET_FILE =
  39636. +RTF_EXTENSIONS_FILE =
  39637. +#---------------------------------------------------------------------------
  39638. +# configuration options related to the man page output
  39639. +#---------------------------------------------------------------------------
  39640. +GENERATE_MAN = NO
  39641. +MAN_OUTPUT = man
  39642. +MAN_EXTENSION = .3
  39643. +MAN_LINKS = NO
  39644. +#---------------------------------------------------------------------------
  39645. +# configuration options related to the XML output
  39646. +#---------------------------------------------------------------------------
  39647. +GENERATE_XML = NO
  39648. +XML_OUTPUT = xml
  39649. +XML_SCHEMA =
  39650. +XML_DTD =
  39651. +XML_PROGRAMLISTING = YES
  39652. +#---------------------------------------------------------------------------
  39653. +# configuration options for the AutoGen Definitions output
  39654. +#---------------------------------------------------------------------------
  39655. +GENERATE_AUTOGEN_DEF = NO
  39656. +#---------------------------------------------------------------------------
  39657. +# configuration options related to the Perl module output
  39658. +#---------------------------------------------------------------------------
  39659. +GENERATE_PERLMOD = NO
  39660. +PERLMOD_LATEX = NO
  39661. +PERLMOD_PRETTY = YES
  39662. +PERLMOD_MAKEVAR_PREFIX =
  39663. +#---------------------------------------------------------------------------
  39664. +# Configuration options related to the preprocessor
  39665. +#---------------------------------------------------------------------------
  39666. +ENABLE_PREPROCESSING = YES
  39667. +MACRO_EXPANSION = NO
  39668. +EXPAND_ONLY_PREDEF = NO
  39669. +SEARCH_INCLUDES = YES
  39670. +INCLUDE_PATH =
  39671. +INCLUDE_FILE_PATTERNS =
  39672. +PREDEFINED = DEBUG DEBUG_MEMORY
  39673. +EXPAND_AS_DEFINED =
  39674. +SKIP_FUNCTION_MACROS = YES
  39675. +#---------------------------------------------------------------------------
  39676. +# Configuration::additions related to external references
  39677. +#---------------------------------------------------------------------------
  39678. +TAGFILES =
  39679. +GENERATE_TAGFILE =
  39680. +ALLEXTERNALS = NO
  39681. +EXTERNAL_GROUPS = YES
  39682. +PERL_PATH = /usr/bin/perl
  39683. +#---------------------------------------------------------------------------
  39684. +# Configuration options related to the dot tool
  39685. +#---------------------------------------------------------------------------
  39686. +CLASS_DIAGRAMS = YES
  39687. +HIDE_UNDOC_RELATIONS = YES
  39688. +HAVE_DOT = NO
  39689. +CLASS_GRAPH = YES
  39690. +COLLABORATION_GRAPH = YES
  39691. +GROUP_GRAPHS = YES
  39692. +UML_LOOK = NO
  39693. +TEMPLATE_RELATIONS = NO
  39694. +INCLUDE_GRAPH = NO
  39695. +INCLUDED_BY_GRAPH = YES
  39696. +CALL_GRAPH = NO
  39697. +GRAPHICAL_HIERARCHY = YES
  39698. +DIRECTORY_GRAPH = YES
  39699. +DOT_IMAGE_FORMAT = png
  39700. +DOT_PATH =
  39701. +DOTFILE_DIRS =
  39702. +MAX_DOT_GRAPH_DEPTH = 1000
  39703. +DOT_TRANSPARENT = NO
  39704. +DOT_MULTI_TARGETS = NO
  39705. +GENERATE_LEGEND = YES
  39706. +DOT_CLEANUP = YES
  39707. +#---------------------------------------------------------------------------
  39708. +# Configuration::additions related to the search engine
  39709. +#---------------------------------------------------------------------------
  39710. +SEARCHENGINE = NO
  39711. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_cc.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c
  39712. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_cc.c 1970-01-01 01:00:00.000000000 +0100
  39713. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c 2014-04-24 16:04:39.811124176 +0200
  39714. @@ -0,0 +1,532 @@
  39715. +/* =========================================================================
  39716. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.c $
  39717. + * $Revision: #4 $
  39718. + * $Date: 2010/11/04 $
  39719. + * $Change: 1621692 $
  39720. + *
  39721. + * Synopsys Portability Library Software and documentation
  39722. + * (hereinafter, "Software") is an Unsupported proprietary work of
  39723. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  39724. + * between Synopsys and you.
  39725. + *
  39726. + * The Software IS NOT an item of Licensed Software or Licensed Product
  39727. + * under any End User Software License Agreement or Agreement for
  39728. + * Licensed Product with Synopsys or any supplement thereto. You are
  39729. + * permitted to use and redistribute this Software in source and binary
  39730. + * forms, with or without modification, provided that redistributions
  39731. + * of source code must retain this notice. You may not view, use,
  39732. + * disclose, copy or distribute this file or any information contained
  39733. + * herein except pursuant to this license grant from Synopsys. If you
  39734. + * do not agree with this notice, including the disclaimer below, then
  39735. + * you are not authorized to use the Software.
  39736. + *
  39737. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  39738. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  39739. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  39740. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  39741. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  39742. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  39743. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  39744. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  39745. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39746. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  39747. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  39748. + * DAMAGE.
  39749. + * ========================================================================= */
  39750. +#ifdef DWC_CCLIB
  39751. +
  39752. +#include "dwc_cc.h"
  39753. +
  39754. +typedef struct dwc_cc
  39755. +{
  39756. + uint32_t uid;
  39757. + uint8_t chid[16];
  39758. + uint8_t cdid[16];
  39759. + uint8_t ck[16];
  39760. + uint8_t *name;
  39761. + uint8_t length;
  39762. + DWC_CIRCLEQ_ENTRY(dwc_cc) list_entry;
  39763. +} dwc_cc_t;
  39764. +
  39765. +DWC_CIRCLEQ_HEAD(context_list, dwc_cc);
  39766. +
  39767. +/** The main structure for CC management. */
  39768. +struct dwc_cc_if
  39769. +{
  39770. + dwc_mutex_t *mutex;
  39771. + char *filename;
  39772. +
  39773. + unsigned is_host:1;
  39774. +
  39775. + dwc_notifier_t *notifier;
  39776. +
  39777. + struct context_list list;
  39778. +};
  39779. +
  39780. +#ifdef DEBUG
  39781. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  39782. +{
  39783. + int i;
  39784. + DWC_PRINTF("%s: ", name);
  39785. + for (i=0; i<len; i++) {
  39786. + DWC_PRINTF("%02x ", bytes[i]);
  39787. + }
  39788. + DWC_PRINTF("\n");
  39789. +}
  39790. +#else
  39791. +#define dump_bytes(x...)
  39792. +#endif
  39793. +
  39794. +static dwc_cc_t *alloc_cc(void *mem_ctx, uint8_t *name, uint32_t length)
  39795. +{
  39796. + dwc_cc_t *cc = dwc_alloc(mem_ctx, sizeof(dwc_cc_t));
  39797. + if (!cc) {
  39798. + return NULL;
  39799. + }
  39800. + DWC_MEMSET(cc, 0, sizeof(dwc_cc_t));
  39801. +
  39802. + if (name) {
  39803. + cc->length = length;
  39804. + cc->name = dwc_alloc(mem_ctx, length);
  39805. + if (!cc->name) {
  39806. + dwc_free(mem_ctx, cc);
  39807. + return NULL;
  39808. + }
  39809. +
  39810. + DWC_MEMCPY(cc->name, name, length);
  39811. + }
  39812. +
  39813. + return cc;
  39814. +}
  39815. +
  39816. +static void free_cc(void *mem_ctx, dwc_cc_t *cc)
  39817. +{
  39818. + if (cc->name) {
  39819. + dwc_free(mem_ctx, cc->name);
  39820. + }
  39821. + dwc_free(mem_ctx, cc);
  39822. +}
  39823. +
  39824. +static uint32_t next_uid(dwc_cc_if_t *cc_if)
  39825. +{
  39826. + uint32_t uid = 0;
  39827. + dwc_cc_t *cc;
  39828. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39829. + if (cc->uid > uid) {
  39830. + uid = cc->uid;
  39831. + }
  39832. + }
  39833. +
  39834. + if (uid == 0) {
  39835. + uid = 255;
  39836. + }
  39837. +
  39838. + return uid + 1;
  39839. +}
  39840. +
  39841. +static dwc_cc_t *cc_find(dwc_cc_if_t *cc_if, uint32_t uid)
  39842. +{
  39843. + dwc_cc_t *cc;
  39844. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39845. + if (cc->uid == uid) {
  39846. + return cc;
  39847. + }
  39848. + }
  39849. + return NULL;
  39850. +}
  39851. +
  39852. +static unsigned int cc_data_size(dwc_cc_if_t *cc_if)
  39853. +{
  39854. + unsigned int size = 0;
  39855. + dwc_cc_t *cc;
  39856. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39857. + size += (48 + 1);
  39858. + if (cc->name) {
  39859. + size += cc->length;
  39860. + }
  39861. + }
  39862. + return size;
  39863. +}
  39864. +
  39865. +static uint32_t cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  39866. +{
  39867. + uint32_t uid = 0;
  39868. + dwc_cc_t *cc;
  39869. +
  39870. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39871. + if (DWC_MEMCMP(cc->chid, chid, 16) == 0) {
  39872. + uid = cc->uid;
  39873. + break;
  39874. + }
  39875. + }
  39876. + return uid;
  39877. +}
  39878. +static uint32_t cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  39879. +{
  39880. + uint32_t uid = 0;
  39881. + dwc_cc_t *cc;
  39882. +
  39883. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39884. + if (DWC_MEMCMP(cc->cdid, cdid, 16) == 0) {
  39885. + uid = cc->uid;
  39886. + break;
  39887. + }
  39888. + }
  39889. + return uid;
  39890. +}
  39891. +
  39892. +/* Internal cc_add */
  39893. +static int32_t cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39894. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39895. +{
  39896. + dwc_cc_t *cc;
  39897. + uint32_t uid;
  39898. +
  39899. + if (cc_if->is_host) {
  39900. + uid = cc_match_cdid(cc_if, cdid);
  39901. + }
  39902. + else {
  39903. + uid = cc_match_chid(cc_if, chid);
  39904. + }
  39905. +
  39906. + if (uid) {
  39907. + DWC_DEBUGC("Replacing previous connection context id=%d name=%p name_len=%d", uid, name, length);
  39908. + cc = cc_find(cc_if, uid);
  39909. + }
  39910. + else {
  39911. + cc = alloc_cc(mem_ctx, name, length);
  39912. + cc->uid = next_uid(cc_if);
  39913. + DWC_CIRCLEQ_INSERT_TAIL(&cc_if->list, cc, list_entry);
  39914. + }
  39915. +
  39916. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  39917. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  39918. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  39919. +
  39920. + DWC_DEBUGC("Added connection context id=%d name=%p name_len=%d", cc->uid, name, length);
  39921. + dump_bytes("CHID", cc->chid, 16);
  39922. + dump_bytes("CDID", cc->cdid, 16);
  39923. + dump_bytes("CK", cc->ck, 16);
  39924. + return cc->uid;
  39925. +}
  39926. +
  39927. +/* Internal cc_clear */
  39928. +static void cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  39929. +{
  39930. + while (!DWC_CIRCLEQ_EMPTY(&cc_if->list)) {
  39931. + dwc_cc_t *cc = DWC_CIRCLEQ_FIRST(&cc_if->list);
  39932. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  39933. + free_cc(mem_ctx, cc);
  39934. + }
  39935. +}
  39936. +
  39937. +dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  39938. + dwc_notifier_t *notifier, unsigned is_host)
  39939. +{
  39940. + dwc_cc_if_t *cc_if = NULL;
  39941. +
  39942. + /* Allocate a common_cc_if structure */
  39943. + cc_if = dwc_alloc(mem_ctx, sizeof(dwc_cc_if_t));
  39944. +
  39945. + if (!cc_if)
  39946. + return NULL;
  39947. +
  39948. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  39949. + DWC_MUTEX_ALLOC_LINUX_DEBUG(cc_if->mutex);
  39950. +#else
  39951. + cc_if->mutex = dwc_mutex_alloc(mtx_ctx);
  39952. +#endif
  39953. + if (!cc_if->mutex) {
  39954. + dwc_free(mem_ctx, cc_if);
  39955. + return NULL;
  39956. + }
  39957. +
  39958. + DWC_CIRCLEQ_INIT(&cc_if->list);
  39959. + cc_if->is_host = is_host;
  39960. + cc_if->notifier = notifier;
  39961. + return cc_if;
  39962. +}
  39963. +
  39964. +void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if)
  39965. +{
  39966. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  39967. + DWC_MUTEX_FREE(cc_if->mutex);
  39968. +#else
  39969. + dwc_mutex_free(mtx_ctx, cc_if->mutex);
  39970. +#endif
  39971. + cc_clear(mem_ctx, cc_if);
  39972. + dwc_free(mem_ctx, cc_if);
  39973. +}
  39974. +
  39975. +static void cc_changed(dwc_cc_if_t *cc_if)
  39976. +{
  39977. + if (cc_if->notifier) {
  39978. + dwc_notify(cc_if->notifier, DWC_CC_LIST_CHANGED_NOTIFICATION, cc_if);
  39979. + }
  39980. +}
  39981. +
  39982. +void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  39983. +{
  39984. + DWC_MUTEX_LOCK(cc_if->mutex);
  39985. + cc_clear(mem_ctx, cc_if);
  39986. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39987. + cc_changed(cc_if);
  39988. +}
  39989. +
  39990. +int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39991. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39992. +{
  39993. + uint32_t uid;
  39994. +
  39995. + DWC_MUTEX_LOCK(cc_if->mutex);
  39996. + uid = cc_add(mem_ctx, cc_if, chid, cdid, ck, name, length);
  39997. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39998. + cc_changed(cc_if);
  39999. +
  40000. + return uid;
  40001. +}
  40002. +
  40003. +void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id, uint8_t *chid,
  40004. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  40005. +{
  40006. + dwc_cc_t* cc;
  40007. +
  40008. + DWC_DEBUGC("Change connection context %d", id);
  40009. +
  40010. + DWC_MUTEX_LOCK(cc_if->mutex);
  40011. + cc = cc_find(cc_if, id);
  40012. + if (!cc) {
  40013. + DWC_ERROR("Uid %d not found in cc list\n", id);
  40014. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40015. + return;
  40016. + }
  40017. +
  40018. + if (chid) {
  40019. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  40020. + }
  40021. + if (cdid) {
  40022. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  40023. + }
  40024. + if (ck) {
  40025. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  40026. + }
  40027. +
  40028. + if (name) {
  40029. + if (cc->name) {
  40030. + dwc_free(mem_ctx, cc->name);
  40031. + }
  40032. + cc->name = dwc_alloc(mem_ctx, length);
  40033. + if (!cc->name) {
  40034. + DWC_ERROR("Out of memory in dwc_cc_change()\n");
  40035. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40036. + return;
  40037. + }
  40038. + cc->length = length;
  40039. + DWC_MEMCPY(cc->name, name, length);
  40040. + }
  40041. +
  40042. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40043. +
  40044. + cc_changed(cc_if);
  40045. +
  40046. + DWC_DEBUGC("Changed connection context id=%d\n", id);
  40047. + dump_bytes("New CHID", cc->chid, 16);
  40048. + dump_bytes("New CDID", cc->cdid, 16);
  40049. + dump_bytes("New CK", cc->ck, 16);
  40050. +}
  40051. +
  40052. +void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id)
  40053. +{
  40054. + dwc_cc_t *cc;
  40055. +
  40056. + DWC_DEBUGC("Removing connection context %d", id);
  40057. +
  40058. + DWC_MUTEX_LOCK(cc_if->mutex);
  40059. + cc = cc_find(cc_if, id);
  40060. + if (!cc) {
  40061. + DWC_ERROR("Uid %d not found in cc list\n", id);
  40062. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40063. + return;
  40064. + }
  40065. +
  40066. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  40067. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40068. + free_cc(mem_ctx, cc);
  40069. +
  40070. + cc_changed(cc_if);
  40071. +}
  40072. +
  40073. +uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if, unsigned int *length)
  40074. +{
  40075. + uint8_t *buf, *x;
  40076. + uint8_t zero = 0;
  40077. + dwc_cc_t *cc;
  40078. +
  40079. + DWC_MUTEX_LOCK(cc_if->mutex);
  40080. + *length = cc_data_size(cc_if);
  40081. + if (!(*length)) {
  40082. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40083. + return NULL;
  40084. + }
  40085. +
  40086. + DWC_DEBUGC("Creating data for saving (length=%d)", *length);
  40087. +
  40088. + buf = dwc_alloc(mem_ctx, *length);
  40089. + if (!buf) {
  40090. + *length = 0;
  40091. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40092. + return NULL;
  40093. + }
  40094. +
  40095. + x = buf;
  40096. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  40097. + DWC_MEMCPY(x, cc->chid, 16);
  40098. + x += 16;
  40099. + DWC_MEMCPY(x, cc->cdid, 16);
  40100. + x += 16;
  40101. + DWC_MEMCPY(x, cc->ck, 16);
  40102. + x += 16;
  40103. + if (cc->name) {
  40104. + DWC_MEMCPY(x, &cc->length, 1);
  40105. + x += 1;
  40106. + DWC_MEMCPY(x, cc->name, cc->length);
  40107. + x += cc->length;
  40108. + }
  40109. + else {
  40110. + DWC_MEMCPY(x, &zero, 1);
  40111. + x += 1;
  40112. + }
  40113. + }
  40114. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40115. +
  40116. + return buf;
  40117. +}
  40118. +
  40119. +void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *data, uint32_t length)
  40120. +{
  40121. + uint8_t name_length;
  40122. + uint8_t *name;
  40123. + uint8_t *chid;
  40124. + uint8_t *cdid;
  40125. + uint8_t *ck;
  40126. + uint32_t i = 0;
  40127. +
  40128. + DWC_MUTEX_LOCK(cc_if->mutex);
  40129. + cc_clear(mem_ctx, cc_if);
  40130. +
  40131. + while (i < length) {
  40132. + chid = &data[i];
  40133. + i += 16;
  40134. + cdid = &data[i];
  40135. + i += 16;
  40136. + ck = &data[i];
  40137. + i += 16;
  40138. +
  40139. + name_length = data[i];
  40140. + i ++;
  40141. +
  40142. + if (name_length) {
  40143. + name = &data[i];
  40144. + i += name_length;
  40145. + }
  40146. + else {
  40147. + name = NULL;
  40148. + }
  40149. +
  40150. + /* check to see if we haven't overflown the buffer */
  40151. + if (i > length) {
  40152. + DWC_ERROR("Data format error while attempting to load CCs "
  40153. + "(nlen=%d, iter=%d, buflen=%d).\n", name_length, i, length);
  40154. + break;
  40155. + }
  40156. +
  40157. + cc_add(mem_ctx, cc_if, chid, cdid, ck, name, name_length);
  40158. + }
  40159. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40160. +
  40161. + cc_changed(cc_if);
  40162. +}
  40163. +
  40164. +uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  40165. +{
  40166. + uint32_t uid = 0;
  40167. +
  40168. + DWC_MUTEX_LOCK(cc_if->mutex);
  40169. + uid = cc_match_chid(cc_if, chid);
  40170. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40171. + return uid;
  40172. +}
  40173. +uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  40174. +{
  40175. + uint32_t uid = 0;
  40176. +
  40177. + DWC_MUTEX_LOCK(cc_if->mutex);
  40178. + uid = cc_match_cdid(cc_if, cdid);
  40179. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40180. + return uid;
  40181. +}
  40182. +
  40183. +uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id)
  40184. +{
  40185. + uint8_t *ck = NULL;
  40186. + dwc_cc_t *cc;
  40187. +
  40188. + DWC_MUTEX_LOCK(cc_if->mutex);
  40189. + cc = cc_find(cc_if, id);
  40190. + if (cc) {
  40191. + ck = cc->ck;
  40192. + }
  40193. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40194. +
  40195. + return ck;
  40196. +
  40197. +}
  40198. +
  40199. +uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id)
  40200. +{
  40201. + uint8_t *retval = NULL;
  40202. + dwc_cc_t *cc;
  40203. +
  40204. + DWC_MUTEX_LOCK(cc_if->mutex);
  40205. + cc = cc_find(cc_if, id);
  40206. + if (cc) {
  40207. + retval = cc->chid;
  40208. + }
  40209. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40210. +
  40211. + return retval;
  40212. +}
  40213. +
  40214. +uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id)
  40215. +{
  40216. + uint8_t *retval = NULL;
  40217. + dwc_cc_t *cc;
  40218. +
  40219. + DWC_MUTEX_LOCK(cc_if->mutex);
  40220. + cc = cc_find(cc_if, id);
  40221. + if (cc) {
  40222. + retval = cc->cdid;
  40223. + }
  40224. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40225. +
  40226. + return retval;
  40227. +}
  40228. +
  40229. +uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length)
  40230. +{
  40231. + uint8_t *retval = NULL;
  40232. + dwc_cc_t *cc;
  40233. +
  40234. + DWC_MUTEX_LOCK(cc_if->mutex);
  40235. + *length = 0;
  40236. + cc = cc_find(cc_if, id);
  40237. + if (cc) {
  40238. + *length = cc->length;
  40239. + retval = cc->name;
  40240. + }
  40241. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40242. +
  40243. + return retval;
  40244. +}
  40245. +
  40246. +#endif /* DWC_CCLIB */
  40247. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_cc.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h
  40248. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_cc.h 1970-01-01 01:00:00.000000000 +0100
  40249. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h 2014-04-24 16:04:39.811124176 +0200
  40250. @@ -0,0 +1,224 @@
  40251. +/* =========================================================================
  40252. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.h $
  40253. + * $Revision: #4 $
  40254. + * $Date: 2010/09/28 $
  40255. + * $Change: 1596182 $
  40256. + *
  40257. + * Synopsys Portability Library Software and documentation
  40258. + * (hereinafter, "Software") is an Unsupported proprietary work of
  40259. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  40260. + * between Synopsys and you.
  40261. + *
  40262. + * The Software IS NOT an item of Licensed Software or Licensed Product
  40263. + * under any End User Software License Agreement or Agreement for
  40264. + * Licensed Product with Synopsys or any supplement thereto. You are
  40265. + * permitted to use and redistribute this Software in source and binary
  40266. + * forms, with or without modification, provided that redistributions
  40267. + * of source code must retain this notice. You may not view, use,
  40268. + * disclose, copy or distribute this file or any information contained
  40269. + * herein except pursuant to this license grant from Synopsys. If you
  40270. + * do not agree with this notice, including the disclaimer below, then
  40271. + * you are not authorized to use the Software.
  40272. + *
  40273. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  40274. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40275. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  40276. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  40277. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  40278. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  40279. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  40280. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  40281. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40282. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  40283. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  40284. + * DAMAGE.
  40285. + * ========================================================================= */
  40286. +#ifndef _DWC_CC_H_
  40287. +#define _DWC_CC_H_
  40288. +
  40289. +#ifdef __cplusplus
  40290. +extern "C" {
  40291. +#endif
  40292. +
  40293. +/** @file
  40294. + *
  40295. + * This file defines the Context Context library.
  40296. + *
  40297. + * The main data structure is dwc_cc_if_t which is returned by either the
  40298. + * dwc_cc_if_alloc function or returned by the module to the user via a provided
  40299. + * function. The data structure is opaque and should only be manipulated via the
  40300. + * functions provied in this API.
  40301. + *
  40302. + * It manages a list of connection contexts and operations can be performed to
  40303. + * add, remove, query, search, and change, those contexts. Additionally,
  40304. + * a dwc_notifier_t object can be requested from the manager so that
  40305. + * the user can be notified whenever the context list has changed.
  40306. + */
  40307. +
  40308. +#include "dwc_os.h"
  40309. +#include "dwc_list.h"
  40310. +#include "dwc_notifier.h"
  40311. +
  40312. +
  40313. +/* Notifications */
  40314. +#define DWC_CC_LIST_CHANGED_NOTIFICATION "DWC_CC_LIST_CHANGED_NOTIFICATION"
  40315. +
  40316. +struct dwc_cc_if;
  40317. +typedef struct dwc_cc_if dwc_cc_if_t;
  40318. +
  40319. +
  40320. +/** @name Connection Context Operations */
  40321. +/** @{ */
  40322. +
  40323. +/** This function allocates memory for a dwc_cc_if_t structure, initializes
  40324. + * fields to default values, and returns a pointer to the structure or NULL on
  40325. + * error. */
  40326. +extern dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  40327. + dwc_notifier_t *notifier, unsigned is_host);
  40328. +
  40329. +/** Frees the memory for the specified CC structure allocated from
  40330. + * dwc_cc_if_alloc(). */
  40331. +extern void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if);
  40332. +
  40333. +/** Removes all contexts from the connection context list */
  40334. +extern void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if);
  40335. +
  40336. +/** Adds a connection context (CHID, CK, CDID, Name) to the connection context list.
  40337. + * If a CHID already exists, the CK and name are overwritten. Statistics are
  40338. + * not overwritten.
  40339. + *
  40340. + * @param cc_if The cc_if structure.
  40341. + * @param chid A pointer to the 16-byte CHID. This value will be copied.
  40342. + * @param ck A pointer to the 16-byte CK. This value will be copied.
  40343. + * @param cdid A pointer to the 16-byte CDID. This value will be copied.
  40344. + * @param name An optional host friendly name as defined in the association model
  40345. + * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name.
  40346. + * @param length The length othe unicode string.
  40347. + * @return A unique identifier used to refer to this context that is valid for
  40348. + * as long as this context is still in the list. */
  40349. +extern int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  40350. + uint8_t *cdid, uint8_t *ck, uint8_t *name,
  40351. + uint8_t length);
  40352. +
  40353. +/** Changes the CHID, CK, CDID, or Name values of a connection context in the
  40354. + * list, preserving any accumulated statistics. This would typically be called
  40355. + * if the host decideds to change the context with a SET_CONNECTION request.
  40356. + *
  40357. + * @param cc_if The cc_if structure.
  40358. + * @param id The identifier of the connection context.
  40359. + * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL
  40360. + * indicates no change.
  40361. + * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL
  40362. + * indicates no change.
  40363. + * @param ck A pointer to the 16-byte CK. This value will be copied. NULL
  40364. + * indicates no change.
  40365. + * @param name Host friendly name UTF16-LE. NULL indicates no change.
  40366. + * @param length Length of name. */
  40367. +extern void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id,
  40368. + uint8_t *chid, uint8_t *cdid, uint8_t *ck,
  40369. + uint8_t *name, uint8_t length);
  40370. +
  40371. +/** Remove the specified connection context.
  40372. + * @param cc_if The cc_if structure.
  40373. + * @param id The identifier of the connection context to remove. */
  40374. +extern void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id);
  40375. +
  40376. +/** Get a binary block of data for the connection context list and attributes.
  40377. + * This data can be used by the OS specific driver to save the connection
  40378. + * context list into non-volatile memory.
  40379. + *
  40380. + * @param cc_if The cc_if structure.
  40381. + * @param length Return the length of the data buffer.
  40382. + * @return A pointer to the data buffer. The memory for this buffer should be
  40383. + * freed with DWC_FREE() after use. */
  40384. +extern uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if,
  40385. + unsigned int *length);
  40386. +
  40387. +/** Restore the connection context list from the binary data that was previously
  40388. + * returned from a call to dwc_cc_data_for_save. This can be used by the OS specific
  40389. + * driver to load a connection context list from non-volatile memory.
  40390. + *
  40391. + * @param cc_if The cc_if structure.
  40392. + * @param data The data bytes as returned from dwc_cc_data_for_save.
  40393. + * @param length The length of the data. */
  40394. +extern void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if,
  40395. + uint8_t *data, unsigned int length);
  40396. +
  40397. +/** Find the connection context from the specified CHID.
  40398. + *
  40399. + * @param cc_if The cc_if structure.
  40400. + * @param chid A pointer to the CHID data.
  40401. + * @return A non-zero identifier of the connection context if the CHID matches.
  40402. + * Otherwise returns 0. */
  40403. +extern uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid);
  40404. +
  40405. +/** Find the connection context from the specified CDID.
  40406. + *
  40407. + * @param cc_if The cc_if structure.
  40408. + * @param cdid A pointer to the CDID data.
  40409. + * @return A non-zero identifier of the connection context if the CHID matches.
  40410. + * Otherwise returns 0. */
  40411. +extern uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid);
  40412. +
  40413. +/** Retrieve the CK from the specified connection context.
  40414. + *
  40415. + * @param cc_if The cc_if structure.
  40416. + * @param id The identifier of the connection context.
  40417. + * @return A pointer to the CK data. The memory does not need to be freed. */
  40418. +extern uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id);
  40419. +
  40420. +/** Retrieve the CHID from the specified connection context.
  40421. + *
  40422. + * @param cc_if The cc_if structure.
  40423. + * @param id The identifier of the connection context.
  40424. + * @return A pointer to the CHID data. The memory does not need to be freed. */
  40425. +extern uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id);
  40426. +
  40427. +/** Retrieve the CDID from the specified connection context.
  40428. + *
  40429. + * @param cc_if The cc_if structure.
  40430. + * @param id The identifier of the connection context.
  40431. + * @return A pointer to the CDID data. The memory does not need to be freed. */
  40432. +extern uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id);
  40433. +
  40434. +extern uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length);
  40435. +
  40436. +/** Checks a buffer for non-zero.
  40437. + * @param id A pointer to a 16 byte buffer.
  40438. + * @return true if the 16 byte value is non-zero. */
  40439. +static inline unsigned dwc_assoc_is_not_zero_id(uint8_t *id) {
  40440. + int i;
  40441. + for (i=0; i<16; i++) {
  40442. + if (id[i]) return 1;
  40443. + }
  40444. + return 0;
  40445. +}
  40446. +
  40447. +/** Checks a buffer for zero.
  40448. + * @param id A pointer to a 16 byte buffer.
  40449. + * @return true if the 16 byte value is zero. */
  40450. +static inline unsigned dwc_assoc_is_zero_id(uint8_t *id) {
  40451. + return !dwc_assoc_is_not_zero_id(id);
  40452. +}
  40453. +
  40454. +/** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into
  40455. + * buffer. */
  40456. +static inline int dwc_print_id_string(char *buffer, uint8_t *id) {
  40457. + char *ptr = buffer;
  40458. + int i;
  40459. + for (i=0; i<16; i++) {
  40460. + ptr += DWC_SPRINTF(ptr, "%02x", id[i]);
  40461. + if (i < 15) {
  40462. + ptr += DWC_SPRINTF(ptr, " ");
  40463. + }
  40464. + }
  40465. + return ptr - buffer;
  40466. +}
  40467. +
  40468. +/** @} */
  40469. +
  40470. +#ifdef __cplusplus
  40471. +}
  40472. +#endif
  40473. +
  40474. +#endif /* _DWC_CC_H_ */
  40475. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c
  40476. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 1970-01-01 01:00:00.000000000 +0100
  40477. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 2014-04-24 15:35:04.169565731 +0200
  40478. @@ -0,0 +1,1308 @@
  40479. +#include "dwc_os.h"
  40480. +#include "dwc_list.h"
  40481. +
  40482. +#ifdef DWC_CCLIB
  40483. +# include "dwc_cc.h"
  40484. +#endif
  40485. +
  40486. +#ifdef DWC_CRYPTOLIB
  40487. +# include "dwc_modpow.h"
  40488. +# include "dwc_dh.h"
  40489. +# include "dwc_crypto.h"
  40490. +#endif
  40491. +
  40492. +#ifdef DWC_NOTIFYLIB
  40493. +# include "dwc_notifier.h"
  40494. +#endif
  40495. +
  40496. +/* OS-Level Implementations */
  40497. +
  40498. +/* This is the FreeBSD 7.0 kernel implementation of the DWC platform library. */
  40499. +
  40500. +
  40501. +/* MISC */
  40502. +
  40503. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  40504. +{
  40505. + return memset(dest, byte, size);
  40506. +}
  40507. +
  40508. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  40509. +{
  40510. + return memcpy(dest, src, size);
  40511. +}
  40512. +
  40513. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  40514. +{
  40515. + bcopy(src, dest, size);
  40516. + return dest;
  40517. +}
  40518. +
  40519. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  40520. +{
  40521. + return memcmp(m1, m2, size);
  40522. +}
  40523. +
  40524. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  40525. +{
  40526. + return strncmp(s1, s2, size);
  40527. +}
  40528. +
  40529. +int DWC_STRCMP(void *s1, void *s2)
  40530. +{
  40531. + return strcmp(s1, s2);
  40532. +}
  40533. +
  40534. +int DWC_STRLEN(char const *str)
  40535. +{
  40536. + return strlen(str);
  40537. +}
  40538. +
  40539. +char *DWC_STRCPY(char *to, char const *from)
  40540. +{
  40541. + return strcpy(to, from);
  40542. +}
  40543. +
  40544. +char *DWC_STRDUP(char const *str)
  40545. +{
  40546. + int len = DWC_STRLEN(str) + 1;
  40547. + char *new = DWC_ALLOC_ATOMIC(len);
  40548. +
  40549. + if (!new) {
  40550. + return NULL;
  40551. + }
  40552. +
  40553. + DWC_MEMCPY(new, str, len);
  40554. + return new;
  40555. +}
  40556. +
  40557. +int DWC_ATOI(char *str, int32_t *value)
  40558. +{
  40559. + char *end = NULL;
  40560. +
  40561. + *value = strtol(str, &end, 0);
  40562. + if (*end == '\0') {
  40563. + return 0;
  40564. + }
  40565. +
  40566. + return -1;
  40567. +}
  40568. +
  40569. +int DWC_ATOUI(char *str, uint32_t *value)
  40570. +{
  40571. + char *end = NULL;
  40572. +
  40573. + *value = strtoul(str, &end, 0);
  40574. + if (*end == '\0') {
  40575. + return 0;
  40576. + }
  40577. +
  40578. + return -1;
  40579. +}
  40580. +
  40581. +
  40582. +#ifdef DWC_UTFLIB
  40583. +/* From usbstring.c */
  40584. +
  40585. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  40586. +{
  40587. + int count = 0;
  40588. + u8 c;
  40589. + u16 uchar;
  40590. +
  40591. + /* this insists on correct encodings, though not minimal ones.
  40592. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  40593. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  40594. + */
  40595. + while (len != 0 && (c = (u8) *s++) != 0) {
  40596. + if (unlikely(c & 0x80)) {
  40597. + // 2-byte sequence:
  40598. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  40599. + if ((c & 0xe0) == 0xc0) {
  40600. + uchar = (c & 0x1f) << 6;
  40601. +
  40602. + c = (u8) *s++;
  40603. + if ((c & 0xc0) != 0xc0)
  40604. + goto fail;
  40605. + c &= 0x3f;
  40606. + uchar |= c;
  40607. +
  40608. + // 3-byte sequence (most CJKV characters):
  40609. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  40610. + } else if ((c & 0xf0) == 0xe0) {
  40611. + uchar = (c & 0x0f) << 12;
  40612. +
  40613. + c = (u8) *s++;
  40614. + if ((c & 0xc0) != 0xc0)
  40615. + goto fail;
  40616. + c &= 0x3f;
  40617. + uchar |= c << 6;
  40618. +
  40619. + c = (u8) *s++;
  40620. + if ((c & 0xc0) != 0xc0)
  40621. + goto fail;
  40622. + c &= 0x3f;
  40623. + uchar |= c;
  40624. +
  40625. + /* no bogus surrogates */
  40626. + if (0xd800 <= uchar && uchar <= 0xdfff)
  40627. + goto fail;
  40628. +
  40629. + // 4-byte sequence (surrogate pairs, currently rare):
  40630. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  40631. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  40632. + // (uuuuu = wwww + 1)
  40633. + // FIXME accept the surrogate code points (only)
  40634. + } else
  40635. + goto fail;
  40636. + } else
  40637. + uchar = c;
  40638. + put_unaligned (cpu_to_le16 (uchar), cp++);
  40639. + count++;
  40640. + len--;
  40641. + }
  40642. + return count;
  40643. +fail:
  40644. + return -1;
  40645. +}
  40646. +
  40647. +#endif /* DWC_UTFLIB */
  40648. +
  40649. +
  40650. +/* dwc_debug.h */
  40651. +
  40652. +dwc_bool_t DWC_IN_IRQ(void)
  40653. +{
  40654. +// return in_irq();
  40655. + return 0;
  40656. +}
  40657. +
  40658. +dwc_bool_t DWC_IN_BH(void)
  40659. +{
  40660. +// return in_softirq();
  40661. + return 0;
  40662. +}
  40663. +
  40664. +void DWC_VPRINTF(char *format, va_list args)
  40665. +{
  40666. + vprintf(format, args);
  40667. +}
  40668. +
  40669. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  40670. +{
  40671. + return vsnprintf(str, size, format, args);
  40672. +}
  40673. +
  40674. +void DWC_PRINTF(char *format, ...)
  40675. +{
  40676. + va_list args;
  40677. +
  40678. + va_start(args, format);
  40679. + DWC_VPRINTF(format, args);
  40680. + va_end(args);
  40681. +}
  40682. +
  40683. +int DWC_SPRINTF(char *buffer, char *format, ...)
  40684. +{
  40685. + int retval;
  40686. + va_list args;
  40687. +
  40688. + va_start(args, format);
  40689. + retval = vsprintf(buffer, format, args);
  40690. + va_end(args);
  40691. + return retval;
  40692. +}
  40693. +
  40694. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  40695. +{
  40696. + int retval;
  40697. + va_list args;
  40698. +
  40699. + va_start(args, format);
  40700. + retval = vsnprintf(buffer, size, format, args);
  40701. + va_end(args);
  40702. + return retval;
  40703. +}
  40704. +
  40705. +void __DWC_WARN(char *format, ...)
  40706. +{
  40707. + va_list args;
  40708. +
  40709. + va_start(args, format);
  40710. + DWC_VPRINTF(format, args);
  40711. + va_end(args);
  40712. +}
  40713. +
  40714. +void __DWC_ERROR(char *format, ...)
  40715. +{
  40716. + va_list args;
  40717. +
  40718. + va_start(args, format);
  40719. + DWC_VPRINTF(format, args);
  40720. + va_end(args);
  40721. +}
  40722. +
  40723. +void DWC_EXCEPTION(char *format, ...)
  40724. +{
  40725. + va_list args;
  40726. +
  40727. + va_start(args, format);
  40728. + DWC_VPRINTF(format, args);
  40729. + va_end(args);
  40730. +// BUG_ON(1); ???
  40731. +}
  40732. +
  40733. +#ifdef DEBUG
  40734. +void __DWC_DEBUG(char *format, ...)
  40735. +{
  40736. + va_list args;
  40737. +
  40738. + va_start(args, format);
  40739. + DWC_VPRINTF(format, args);
  40740. + va_end(args);
  40741. +}
  40742. +#endif
  40743. +
  40744. +
  40745. +/* dwc_mem.h */
  40746. +
  40747. +#if 0
  40748. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  40749. + uint32_t align,
  40750. + uint32_t alloc)
  40751. +{
  40752. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  40753. + size, align, alloc);
  40754. + return (dwc_pool_t *)pool;
  40755. +}
  40756. +
  40757. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  40758. +{
  40759. + dma_pool_destroy((struct dma_pool *)pool);
  40760. +}
  40761. +
  40762. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  40763. +{
  40764. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  40765. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  40766. +}
  40767. +
  40768. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  40769. +{
  40770. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  40771. + memset(..);
  40772. +}
  40773. +
  40774. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  40775. +{
  40776. + dma_pool_free(pool, vaddr, daddr);
  40777. +}
  40778. +#endif
  40779. +
  40780. +static void dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  40781. +{
  40782. + if (error)
  40783. + return;
  40784. + *(bus_addr_t *)arg = segs[0].ds_addr;
  40785. +}
  40786. +
  40787. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  40788. +{
  40789. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  40790. + int error;
  40791. +
  40792. + error = bus_dma_tag_create(
  40793. +#if __FreeBSD_version >= 700000
  40794. + bus_get_dma_tag(dma->dev), /* parent */
  40795. +#else
  40796. + NULL, /* parent */
  40797. +#endif
  40798. + 4, 0, /* alignment, bounds */
  40799. + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  40800. + BUS_SPACE_MAXADDR, /* highaddr */
  40801. + NULL, NULL, /* filter, filterarg */
  40802. + size, /* maxsize */
  40803. + 1, /* nsegments */
  40804. + size, /* maxsegsize */
  40805. + 0, /* flags */
  40806. + NULL, /* lockfunc */
  40807. + NULL, /* lockarg */
  40808. + &dma->dma_tag);
  40809. + if (error) {
  40810. + device_printf(dma->dev, "%s: bus_dma_tag_create failed: %d\n",
  40811. + __func__, error);
  40812. + goto fail_0;
  40813. + }
  40814. +
  40815. + error = bus_dmamem_alloc(dma->dma_tag, &dma->dma_vaddr,
  40816. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dma->dma_map);
  40817. + if (error) {
  40818. + device_printf(dma->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
  40819. + __func__, (uintmax_t)size, error);
  40820. + goto fail_1;
  40821. + }
  40822. +
  40823. + dma->dma_paddr = 0;
  40824. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size,
  40825. + dmamap_cb, &dma->dma_paddr, BUS_DMA_NOWAIT);
  40826. + if (error || dma->dma_paddr == 0) {
  40827. + device_printf(dma->dev, "%s: bus_dmamap_load failed: %d\n",
  40828. + __func__, error);
  40829. + goto fail_2;
  40830. + }
  40831. +
  40832. + *dma_addr = dma->dma_paddr;
  40833. + return dma->dma_vaddr;
  40834. +
  40835. +fail_2:
  40836. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  40837. +fail_1:
  40838. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  40839. + bus_dma_tag_destroy(dma->dma_tag);
  40840. +fail_0:
  40841. + dma->dma_map = NULL;
  40842. + dma->dma_tag = NULL;
  40843. +
  40844. + return NULL;
  40845. +}
  40846. +
  40847. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  40848. +{
  40849. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  40850. +
  40851. + if (dma->dma_tag == NULL)
  40852. + return;
  40853. + if (dma->dma_map != NULL) {
  40854. + bus_dmamap_sync(dma->dma_tag, dma->dma_map,
  40855. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  40856. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  40857. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  40858. + dma->dma_map = NULL;
  40859. + }
  40860. +
  40861. + bus_dma_tag_destroy(dma->dma_tag);
  40862. + dma->dma_tag = NULL;
  40863. +}
  40864. +
  40865. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  40866. +{
  40867. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  40868. +}
  40869. +
  40870. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  40871. +{
  40872. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  40873. +}
  40874. +
  40875. +void __DWC_FREE(void *mem_ctx, void *addr)
  40876. +{
  40877. + free(addr, M_DEVBUF);
  40878. +}
  40879. +
  40880. +
  40881. +#ifdef DWC_CRYPTOLIB
  40882. +/* dwc_crypto.h */
  40883. +
  40884. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  40885. +{
  40886. + get_random_bytes(buffer, length);
  40887. +}
  40888. +
  40889. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  40890. +{
  40891. + struct crypto_blkcipher *tfm;
  40892. + struct blkcipher_desc desc;
  40893. + struct scatterlist sgd;
  40894. + struct scatterlist sgs;
  40895. +
  40896. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  40897. + if (tfm == NULL) {
  40898. + printk("failed to load transform for aes CBC\n");
  40899. + return -1;
  40900. + }
  40901. +
  40902. + crypto_blkcipher_setkey(tfm, key, keylen);
  40903. + crypto_blkcipher_set_iv(tfm, iv, 16);
  40904. +
  40905. + sg_init_one(&sgd, out, messagelen);
  40906. + sg_init_one(&sgs, message, messagelen);
  40907. +
  40908. + desc.tfm = tfm;
  40909. + desc.flags = 0;
  40910. +
  40911. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  40912. + crypto_free_blkcipher(tfm);
  40913. + DWC_ERROR("AES CBC encryption failed");
  40914. + return -1;
  40915. + }
  40916. +
  40917. + crypto_free_blkcipher(tfm);
  40918. + return 0;
  40919. +}
  40920. +
  40921. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  40922. +{
  40923. + struct crypto_hash *tfm;
  40924. + struct hash_desc desc;
  40925. + struct scatterlist sg;
  40926. +
  40927. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  40928. + if (IS_ERR(tfm)) {
  40929. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  40930. + return 0;
  40931. + }
  40932. + desc.tfm = tfm;
  40933. + desc.flags = 0;
  40934. +
  40935. + sg_init_one(&sg, message, len);
  40936. + crypto_hash_digest(&desc, &sg, len, out);
  40937. + crypto_free_hash(tfm);
  40938. +
  40939. + return 1;
  40940. +}
  40941. +
  40942. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  40943. + uint8_t *key, uint32_t keylen, uint8_t *out)
  40944. +{
  40945. + struct crypto_hash *tfm;
  40946. + struct hash_desc desc;
  40947. + struct scatterlist sg;
  40948. +
  40949. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  40950. + if (IS_ERR(tfm)) {
  40951. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  40952. + return 0;
  40953. + }
  40954. + desc.tfm = tfm;
  40955. + desc.flags = 0;
  40956. +
  40957. + sg_init_one(&sg, message, messagelen);
  40958. + crypto_hash_setkey(tfm, key, keylen);
  40959. + crypto_hash_digest(&desc, &sg, messagelen, out);
  40960. + crypto_free_hash(tfm);
  40961. +
  40962. + return 1;
  40963. +}
  40964. +
  40965. +#endif /* DWC_CRYPTOLIB */
  40966. +
  40967. +
  40968. +/* Byte Ordering Conversions */
  40969. +
  40970. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  40971. +{
  40972. +#ifdef __LITTLE_ENDIAN
  40973. + return *p;
  40974. +#else
  40975. + uint8_t *u_p = (uint8_t *)p;
  40976. +
  40977. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40978. +#endif
  40979. +}
  40980. +
  40981. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  40982. +{
  40983. +#ifdef __BIG_ENDIAN
  40984. + return *p;
  40985. +#else
  40986. + uint8_t *u_p = (uint8_t *)p;
  40987. +
  40988. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40989. +#endif
  40990. +}
  40991. +
  40992. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  40993. +{
  40994. +#ifdef __LITTLE_ENDIAN
  40995. + return *p;
  40996. +#else
  40997. + uint8_t *u_p = (uint8_t *)p;
  40998. +
  40999. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41000. +#endif
  41001. +}
  41002. +
  41003. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  41004. +{
  41005. +#ifdef __BIG_ENDIAN
  41006. + return *p;
  41007. +#else
  41008. + uint8_t *u_p = (uint8_t *)p;
  41009. +
  41010. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41011. +#endif
  41012. +}
  41013. +
  41014. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  41015. +{
  41016. +#ifdef __LITTLE_ENDIAN
  41017. + return *p;
  41018. +#else
  41019. + uint8_t *u_p = (uint8_t *)p;
  41020. + return (u_p[1] | (u_p[0] << 8));
  41021. +#endif
  41022. +}
  41023. +
  41024. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  41025. +{
  41026. +#ifdef __BIG_ENDIAN
  41027. + return *p;
  41028. +#else
  41029. + uint8_t *u_p = (uint8_t *)p;
  41030. + return (u_p[1] | (u_p[0] << 8));
  41031. +#endif
  41032. +}
  41033. +
  41034. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  41035. +{
  41036. +#ifdef __LITTLE_ENDIAN
  41037. + return *p;
  41038. +#else
  41039. + uint8_t *u_p = (uint8_t *)p;
  41040. + return (u_p[1] | (u_p[0] << 8));
  41041. +#endif
  41042. +}
  41043. +
  41044. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  41045. +{
  41046. +#ifdef __BIG_ENDIAN
  41047. + return *p;
  41048. +#else
  41049. + uint8_t *u_p = (uint8_t *)p;
  41050. + return (u_p[1] | (u_p[0] << 8));
  41051. +#endif
  41052. +}
  41053. +
  41054. +
  41055. +/* Registers */
  41056. +
  41057. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  41058. +{
  41059. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41060. + bus_size_t ior = (bus_size_t)reg;
  41061. +
  41062. + return bus_space_read_4(io->iot, io->ioh, ior);
  41063. +}
  41064. +
  41065. +#if 0
  41066. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  41067. +{
  41068. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41069. + bus_size_t ior = (bus_size_t)reg;
  41070. +
  41071. + return bus_space_read_8(io->iot, io->ioh, ior);
  41072. +}
  41073. +#endif
  41074. +
  41075. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  41076. +{
  41077. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41078. + bus_size_t ior = (bus_size_t)reg;
  41079. +
  41080. + bus_space_write_4(io->iot, io->ioh, ior, value);
  41081. +}
  41082. +
  41083. +#if 0
  41084. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  41085. +{
  41086. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41087. + bus_size_t ior = (bus_size_t)reg;
  41088. +
  41089. + bus_space_write_8(io->iot, io->ioh, ior, value);
  41090. +}
  41091. +#endif
  41092. +
  41093. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  41094. + uint32_t set_mask)
  41095. +{
  41096. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41097. + bus_size_t ior = (bus_size_t)reg;
  41098. +
  41099. + bus_space_write_4(io->iot, io->ioh, ior,
  41100. + (bus_space_read_4(io->iot, io->ioh, ior) &
  41101. + ~clear_mask) | set_mask);
  41102. +}
  41103. +
  41104. +#if 0
  41105. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  41106. + uint64_t set_mask)
  41107. +{
  41108. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41109. + bus_size_t ior = (bus_size_t)reg;
  41110. +
  41111. + bus_space_write_8(io->iot, io->ioh, ior,
  41112. + (bus_space_read_8(io->iot, io->ioh, ior) &
  41113. + ~clear_mask) | set_mask);
  41114. +}
  41115. +#endif
  41116. +
  41117. +
  41118. +/* Locking */
  41119. +
  41120. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  41121. +{
  41122. + struct mtx *sl = DWC_ALLOC(sizeof(*sl));
  41123. +
  41124. + if (!sl) {
  41125. + DWC_ERROR("Cannot allocate memory for spinlock");
  41126. + return NULL;
  41127. + }
  41128. +
  41129. + mtx_init(sl, "dw3spn", NULL, MTX_SPIN);
  41130. + return (dwc_spinlock_t *)sl;
  41131. +}
  41132. +
  41133. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  41134. +{
  41135. + struct mtx *sl = (struct mtx *)lock;
  41136. +
  41137. + mtx_destroy(sl);
  41138. + DWC_FREE(sl);
  41139. +}
  41140. +
  41141. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  41142. +{
  41143. + mtx_lock_spin((struct mtx *)lock); // ???
  41144. +}
  41145. +
  41146. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  41147. +{
  41148. + mtx_unlock_spin((struct mtx *)lock); // ???
  41149. +}
  41150. +
  41151. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  41152. +{
  41153. + mtx_lock_spin((struct mtx *)lock);
  41154. +}
  41155. +
  41156. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  41157. +{
  41158. + mtx_unlock_spin((struct mtx *)lock);
  41159. +}
  41160. +
  41161. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  41162. +{
  41163. + struct mtx *m;
  41164. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mtx));
  41165. +
  41166. + if (!mutex) {
  41167. + DWC_ERROR("Cannot allocate memory for mutex");
  41168. + return NULL;
  41169. + }
  41170. +
  41171. + m = (struct mtx *)mutex;
  41172. + mtx_init(m, "dw3mtx", NULL, MTX_DEF);
  41173. + return mutex;
  41174. +}
  41175. +
  41176. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  41177. +#else
  41178. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  41179. +{
  41180. + mtx_destroy((struct mtx *)mutex);
  41181. + DWC_FREE(mutex);
  41182. +}
  41183. +#endif
  41184. +
  41185. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  41186. +{
  41187. + struct mtx *m = (struct mtx *)mutex;
  41188. +
  41189. + mtx_lock(m);
  41190. +}
  41191. +
  41192. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  41193. +{
  41194. + struct mtx *m = (struct mtx *)mutex;
  41195. +
  41196. + return mtx_trylock(m);
  41197. +}
  41198. +
  41199. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  41200. +{
  41201. + struct mtx *m = (struct mtx *)mutex;
  41202. +
  41203. + mtx_unlock(m);
  41204. +}
  41205. +
  41206. +
  41207. +/* Timing */
  41208. +
  41209. +void DWC_UDELAY(uint32_t usecs)
  41210. +{
  41211. + DELAY(usecs);
  41212. +}
  41213. +
  41214. +void DWC_MDELAY(uint32_t msecs)
  41215. +{
  41216. + do {
  41217. + DELAY(1000);
  41218. + } while (--msecs);
  41219. +}
  41220. +
  41221. +void DWC_MSLEEP(uint32_t msecs)
  41222. +{
  41223. + struct timeval tv;
  41224. +
  41225. + tv.tv_sec = msecs / 1000;
  41226. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  41227. + pause("dw3slp", tvtohz(&tv));
  41228. +}
  41229. +
  41230. +uint32_t DWC_TIME(void)
  41231. +{
  41232. + struct timeval tv;
  41233. +
  41234. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  41235. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  41236. +}
  41237. +
  41238. +
  41239. +/* Timers */
  41240. +
  41241. +struct dwc_timer {
  41242. + struct callout t;
  41243. + char *name;
  41244. + dwc_spinlock_t *lock;
  41245. + dwc_timer_callback_t cb;
  41246. + void *data;
  41247. +};
  41248. +
  41249. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  41250. +{
  41251. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  41252. +
  41253. + if (!t) {
  41254. + DWC_ERROR("Cannot allocate memory for timer");
  41255. + return NULL;
  41256. + }
  41257. +
  41258. + callout_init(&t->t, 1);
  41259. +
  41260. + t->name = DWC_STRDUP(name);
  41261. + if (!t->name) {
  41262. + DWC_ERROR("Cannot allocate memory for timer->name");
  41263. + goto no_name;
  41264. + }
  41265. +
  41266. + t->lock = DWC_SPINLOCK_ALLOC();
  41267. + if (!t->lock) {
  41268. + DWC_ERROR("Cannot allocate memory for lock");
  41269. + goto no_lock;
  41270. + }
  41271. +
  41272. + t->cb = cb;
  41273. + t->data = data;
  41274. +
  41275. + return t;
  41276. +
  41277. + no_lock:
  41278. + DWC_FREE(t->name);
  41279. + no_name:
  41280. + DWC_FREE(t);
  41281. +
  41282. + return NULL;
  41283. +}
  41284. +
  41285. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  41286. +{
  41287. + callout_stop(&timer->t);
  41288. + DWC_SPINLOCK_FREE(timer->lock);
  41289. + DWC_FREE(timer->name);
  41290. + DWC_FREE(timer);
  41291. +}
  41292. +
  41293. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  41294. +{
  41295. + struct timeval tv;
  41296. +
  41297. + tv.tv_sec = time / 1000;
  41298. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  41299. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  41300. +}
  41301. +
  41302. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  41303. +{
  41304. + callout_stop(&timer->t);
  41305. +}
  41306. +
  41307. +
  41308. +/* Wait Queues */
  41309. +
  41310. +struct dwc_waitq {
  41311. + struct mtx lock;
  41312. + int abort;
  41313. +};
  41314. +
  41315. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  41316. +{
  41317. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  41318. +
  41319. + if (!wq) {
  41320. + DWC_ERROR("Cannot allocate memory for waitqueue");
  41321. + return NULL;
  41322. + }
  41323. +
  41324. + mtx_init(&wq->lock, "dw3wtq", NULL, MTX_DEF);
  41325. + wq->abort = 0;
  41326. +
  41327. + return wq;
  41328. +}
  41329. +
  41330. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  41331. +{
  41332. + mtx_destroy(&wq->lock);
  41333. + DWC_FREE(wq);
  41334. +}
  41335. +
  41336. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  41337. +{
  41338. +// intrmask_t ipl;
  41339. + int result = 0;
  41340. +
  41341. + mtx_lock(&wq->lock);
  41342. +// ipl = splbio();
  41343. +
  41344. + /* Skip the sleep if already aborted or triggered */
  41345. + if (!wq->abort && !cond(data)) {
  41346. +// splx(ipl);
  41347. + result = msleep(wq, &wq->lock, PCATCH, "dw3wat", 0); // infinite timeout
  41348. +// ipl = splbio();
  41349. + }
  41350. +
  41351. + if (result == ERESTART) { // signaled - restart
  41352. + result = -DWC_E_RESTART;
  41353. +
  41354. + } else if (result == EINTR) { // signaled - interrupt
  41355. + result = -DWC_E_ABORT;
  41356. +
  41357. + } else if (wq->abort) {
  41358. + result = -DWC_E_ABORT;
  41359. +
  41360. + } else {
  41361. + result = 0;
  41362. + }
  41363. +
  41364. + wq->abort = 0;
  41365. +// splx(ipl);
  41366. + mtx_unlock(&wq->lock);
  41367. + return result;
  41368. +}
  41369. +
  41370. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  41371. + void *data, int32_t msecs)
  41372. +{
  41373. + struct timeval tv, tv1, tv2;
  41374. +// intrmask_t ipl;
  41375. + int result = 0;
  41376. +
  41377. + tv.tv_sec = msecs / 1000;
  41378. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  41379. +
  41380. + mtx_lock(&wq->lock);
  41381. +// ipl = splbio();
  41382. +
  41383. + /* Skip the sleep if already aborted or triggered */
  41384. + if (!wq->abort && !cond(data)) {
  41385. +// splx(ipl);
  41386. + getmicrouptime(&tv1);
  41387. + result = msleep(wq, &wq->lock, PCATCH, "dw3wto", tvtohz(&tv));
  41388. + getmicrouptime(&tv2);
  41389. +// ipl = splbio();
  41390. + }
  41391. +
  41392. + if (result == 0) { // awoken
  41393. + if (wq->abort) {
  41394. + result = -DWC_E_ABORT;
  41395. + } else {
  41396. + tv2.tv_usec -= tv1.tv_usec;
  41397. + if (tv2.tv_usec < 0) {
  41398. + tv2.tv_usec += 1000000;
  41399. + tv2.tv_sec--;
  41400. + }
  41401. +
  41402. + tv2.tv_sec -= tv1.tv_sec;
  41403. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  41404. + result = msecs - result;
  41405. + if (result <= 0)
  41406. + result = 1;
  41407. + }
  41408. + } else if (result == ERESTART) { // signaled - restart
  41409. + result = -DWC_E_RESTART;
  41410. +
  41411. + } else if (result == EINTR) { // signaled - interrupt
  41412. + result = -DWC_E_ABORT;
  41413. +
  41414. + } else { // timed out
  41415. + result = -DWC_E_TIMEOUT;
  41416. + }
  41417. +
  41418. + wq->abort = 0;
  41419. +// splx(ipl);
  41420. + mtx_unlock(&wq->lock);
  41421. + return result;
  41422. +}
  41423. +
  41424. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  41425. +{
  41426. + wakeup(wq);
  41427. +}
  41428. +
  41429. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  41430. +{
  41431. +// intrmask_t ipl;
  41432. +
  41433. + mtx_lock(&wq->lock);
  41434. +// ipl = splbio();
  41435. + wq->abort = 1;
  41436. + wakeup(wq);
  41437. +// splx(ipl);
  41438. + mtx_unlock(&wq->lock);
  41439. +}
  41440. +
  41441. +
  41442. +/* Threading */
  41443. +
  41444. +struct dwc_thread {
  41445. + struct proc *proc;
  41446. + int abort;
  41447. +};
  41448. +
  41449. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  41450. +{
  41451. + int retval;
  41452. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  41453. +
  41454. + if (!thread) {
  41455. + return NULL;
  41456. + }
  41457. +
  41458. + thread->abort = 0;
  41459. + retval = kthread_create((void (*)(void *))func, data, &thread->proc,
  41460. + RFPROC | RFNOWAIT, 0, "%s", name);
  41461. + if (retval) {
  41462. + DWC_FREE(thread);
  41463. + return NULL;
  41464. + }
  41465. +
  41466. + return thread;
  41467. +}
  41468. +
  41469. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  41470. +{
  41471. + int retval;
  41472. +
  41473. + thread->abort = 1;
  41474. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  41475. +
  41476. + if (retval == 0) {
  41477. + /* DWC_THREAD_EXIT() will free the thread struct */
  41478. + return 0;
  41479. + }
  41480. +
  41481. + /* NOTE: We leak the thread struct if thread doesn't die */
  41482. +
  41483. + if (retval == EWOULDBLOCK) {
  41484. + return -DWC_E_TIMEOUT;
  41485. + }
  41486. +
  41487. + return -DWC_E_UNKNOWN;
  41488. +}
  41489. +
  41490. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  41491. +{
  41492. + return thread->abort;
  41493. +}
  41494. +
  41495. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  41496. +{
  41497. + wakeup(&thread->abort);
  41498. + DWC_FREE(thread);
  41499. + kthread_exit(0);
  41500. +}
  41501. +
  41502. +
  41503. +/* tasklets
  41504. + - Runs in interrupt context (cannot sleep)
  41505. + - Each tasklet runs on a single CPU [ How can we ensure this on FreeBSD? Does it matter? ]
  41506. + - Different tasklets can be running simultaneously on different CPUs [ shouldn't matter ]
  41507. + */
  41508. +struct dwc_tasklet {
  41509. + struct task t;
  41510. + dwc_tasklet_callback_t cb;
  41511. + void *data;
  41512. +};
  41513. +
  41514. +static void tasklet_callback(void *data, int pending) // what to do with pending ???
  41515. +{
  41516. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  41517. +
  41518. + task->cb(task->data);
  41519. +}
  41520. +
  41521. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  41522. +{
  41523. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  41524. +
  41525. + if (task) {
  41526. + task->cb = cb;
  41527. + task->data = data;
  41528. + TASK_INIT(&task->t, 0, tasklet_callback, task);
  41529. + } else {
  41530. + DWC_ERROR("Cannot allocate memory for tasklet");
  41531. + }
  41532. +
  41533. + return task;
  41534. +}
  41535. +
  41536. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  41537. +{
  41538. + taskqueue_drain(taskqueue_fast, &task->t); // ???
  41539. + DWC_FREE(task);
  41540. +}
  41541. +
  41542. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  41543. +{
  41544. + /* Uses predefined system queue */
  41545. + taskqueue_enqueue_fast(taskqueue_fast, &task->t);
  41546. +}
  41547. +
  41548. +
  41549. +/* workqueues
  41550. + - Runs in process context (can sleep)
  41551. + */
  41552. +typedef struct work_container {
  41553. + dwc_work_callback_t cb;
  41554. + void *data;
  41555. + dwc_workq_t *wq;
  41556. + char *name;
  41557. + int hz;
  41558. +
  41559. +#ifdef DEBUG
  41560. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  41561. +#endif
  41562. + struct task task;
  41563. +} work_container_t;
  41564. +
  41565. +#ifdef DEBUG
  41566. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  41567. +#endif
  41568. +
  41569. +struct dwc_workq {
  41570. + struct taskqueue *taskq;
  41571. + dwc_spinlock_t *lock;
  41572. + dwc_waitq_t *waitq;
  41573. + int pending;
  41574. +
  41575. +#ifdef DEBUG
  41576. + struct work_container_queue entries;
  41577. +#endif
  41578. +};
  41579. +
  41580. +static void do_work(void *data, int pending) // what to do with pending ???
  41581. +{
  41582. + work_container_t *container = (work_container_t *)data;
  41583. + dwc_workq_t *wq = container->wq;
  41584. + dwc_irqflags_t flags;
  41585. +
  41586. + if (container->hz) {
  41587. + pause("dw3wrk", container->hz);
  41588. + }
  41589. +
  41590. + container->cb(container->data);
  41591. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  41592. +
  41593. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41594. +
  41595. +#ifdef DEBUG
  41596. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  41597. +#endif
  41598. + if (container->name)
  41599. + DWC_FREE(container->name);
  41600. + DWC_FREE(container);
  41601. + wq->pending--;
  41602. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41603. + DWC_WAITQ_TRIGGER(wq->waitq);
  41604. +}
  41605. +
  41606. +static int work_done(void *data)
  41607. +{
  41608. + dwc_workq_t *workq = (dwc_workq_t *)data;
  41609. +
  41610. + return workq->pending == 0;
  41611. +}
  41612. +
  41613. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  41614. +{
  41615. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  41616. +}
  41617. +
  41618. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  41619. +{
  41620. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  41621. +
  41622. + if (!wq) {
  41623. + DWC_ERROR("Cannot allocate memory for workqueue");
  41624. + return NULL;
  41625. + }
  41626. +
  41627. + wq->taskq = taskqueue_create(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->taskq);
  41628. + if (!wq->taskq) {
  41629. + DWC_ERROR("Cannot allocate memory for taskqueue");
  41630. + goto no_taskq;
  41631. + }
  41632. +
  41633. + wq->pending = 0;
  41634. +
  41635. + wq->lock = DWC_SPINLOCK_ALLOC();
  41636. + if (!wq->lock) {
  41637. + DWC_ERROR("Cannot allocate memory for spinlock");
  41638. + goto no_lock;
  41639. + }
  41640. +
  41641. + wq->waitq = DWC_WAITQ_ALLOC();
  41642. + if (!wq->waitq) {
  41643. + DWC_ERROR("Cannot allocate memory for waitqueue");
  41644. + goto no_waitq;
  41645. + }
  41646. +
  41647. + taskqueue_start_threads(&wq->taskq, 1, PWAIT, "%s taskq", "dw3tsk");
  41648. +
  41649. +#ifdef DEBUG
  41650. + DWC_CIRCLEQ_INIT(&wq->entries);
  41651. +#endif
  41652. + return wq;
  41653. +
  41654. + no_waitq:
  41655. + DWC_SPINLOCK_FREE(wq->lock);
  41656. + no_lock:
  41657. + taskqueue_free(wq->taskq);
  41658. + no_taskq:
  41659. + DWC_FREE(wq);
  41660. +
  41661. + return NULL;
  41662. +}
  41663. +
  41664. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  41665. +{
  41666. +#ifdef DEBUG
  41667. + dwc_irqflags_t flags;
  41668. +
  41669. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41670. +
  41671. + if (wq->pending != 0) {
  41672. + struct work_container *container;
  41673. +
  41674. + DWC_ERROR("Destroying work queue with pending work");
  41675. +
  41676. + DWC_CIRCLEQ_FOREACH(container, &wq->entries, entry) {
  41677. + DWC_ERROR("Work %s still pending", container->name);
  41678. + }
  41679. + }
  41680. +
  41681. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41682. +#endif
  41683. + DWC_WAITQ_FREE(wq->waitq);
  41684. + DWC_SPINLOCK_FREE(wq->lock);
  41685. + taskqueue_free(wq->taskq);
  41686. + DWC_FREE(wq);
  41687. +}
  41688. +
  41689. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  41690. + char *format, ...)
  41691. +{
  41692. + dwc_irqflags_t flags;
  41693. + work_container_t *container;
  41694. + static char name[128];
  41695. + va_list args;
  41696. +
  41697. + va_start(args, format);
  41698. + DWC_VSNPRINTF(name, 128, format, args);
  41699. + va_end(args);
  41700. +
  41701. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41702. + wq->pending++;
  41703. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41704. + DWC_WAITQ_TRIGGER(wq->waitq);
  41705. +
  41706. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41707. + if (!container) {
  41708. + DWC_ERROR("Cannot allocate memory for container");
  41709. + return;
  41710. + }
  41711. +
  41712. + container->name = DWC_STRDUP(name);
  41713. + if (!container->name) {
  41714. + DWC_ERROR("Cannot allocate memory for container->name");
  41715. + DWC_FREE(container);
  41716. + return;
  41717. + }
  41718. +
  41719. + container->cb = cb;
  41720. + container->data = data;
  41721. + container->wq = wq;
  41722. + container->hz = 0;
  41723. +
  41724. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  41725. +
  41726. + TASK_INIT(&container->task, 0, do_work, container);
  41727. +
  41728. +#ifdef DEBUG
  41729. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41730. +#endif
  41731. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  41732. +}
  41733. +
  41734. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  41735. + void *data, uint32_t time, char *format, ...)
  41736. +{
  41737. + dwc_irqflags_t flags;
  41738. + work_container_t *container;
  41739. + static char name[128];
  41740. + struct timeval tv;
  41741. + va_list args;
  41742. +
  41743. + va_start(args, format);
  41744. + DWC_VSNPRINTF(name, 128, format, args);
  41745. + va_end(args);
  41746. +
  41747. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41748. + wq->pending++;
  41749. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41750. + DWC_WAITQ_TRIGGER(wq->waitq);
  41751. +
  41752. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41753. + if (!container) {
  41754. + DWC_ERROR("Cannot allocate memory for container");
  41755. + return;
  41756. + }
  41757. +
  41758. + container->name = DWC_STRDUP(name);
  41759. + if (!container->name) {
  41760. + DWC_ERROR("Cannot allocate memory for container->name");
  41761. + DWC_FREE(container);
  41762. + return;
  41763. + }
  41764. +
  41765. + container->cb = cb;
  41766. + container->data = data;
  41767. + container->wq = wq;
  41768. +
  41769. + tv.tv_sec = time / 1000;
  41770. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  41771. + container->hz = tvtohz(&tv);
  41772. +
  41773. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  41774. +
  41775. + TASK_INIT(&container->task, 0, do_work, container);
  41776. +
  41777. +#ifdef DEBUG
  41778. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41779. +#endif
  41780. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  41781. +}
  41782. +
  41783. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  41784. +{
  41785. + return wq->pending;
  41786. +}
  41787. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_common_linux.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c
  41788. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_common_linux.c 1970-01-01 01:00:00.000000000 +0100
  41789. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c 2014-04-24 16:04:39.811124176 +0200
  41790. @@ -0,0 +1,1432 @@
  41791. +#include <linux/kernel.h>
  41792. +#include <linux/init.h>
  41793. +#include <linux/module.h>
  41794. +#include <linux/kthread.h>
  41795. +
  41796. +#ifdef DWC_CCLIB
  41797. +# include "dwc_cc.h"
  41798. +#endif
  41799. +
  41800. +#ifdef DWC_CRYPTOLIB
  41801. +# include "dwc_modpow.h"
  41802. +# include "dwc_dh.h"
  41803. +# include "dwc_crypto.h"
  41804. +#endif
  41805. +
  41806. +#ifdef DWC_NOTIFYLIB
  41807. +# include "dwc_notifier.h"
  41808. +#endif
  41809. +
  41810. +/* OS-Level Implementations */
  41811. +
  41812. +/* This is the Linux kernel implementation of the DWC platform library. */
  41813. +#include <linux/moduleparam.h>
  41814. +#include <linux/ctype.h>
  41815. +#include <linux/crypto.h>
  41816. +#include <linux/delay.h>
  41817. +#include <linux/device.h>
  41818. +#include <linux/dma-mapping.h>
  41819. +#include <linux/cdev.h>
  41820. +#include <linux/errno.h>
  41821. +#include <linux/interrupt.h>
  41822. +#include <linux/jiffies.h>
  41823. +#include <linux/list.h>
  41824. +#include <linux/pci.h>
  41825. +#include <linux/random.h>
  41826. +#include <linux/scatterlist.h>
  41827. +#include <linux/slab.h>
  41828. +#include <linux/stat.h>
  41829. +#include <linux/string.h>
  41830. +#include <linux/timer.h>
  41831. +#include <linux/usb.h>
  41832. +
  41833. +#include <linux/version.h>
  41834. +
  41835. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  41836. +# include <linux/usb/gadget.h>
  41837. +#else
  41838. +# include <linux/usb_gadget.h>
  41839. +#endif
  41840. +
  41841. +#include <asm/io.h>
  41842. +#include <asm/page.h>
  41843. +#include <asm/uaccess.h>
  41844. +#include <asm/unaligned.h>
  41845. +
  41846. +#include "dwc_os.h"
  41847. +#include "dwc_list.h"
  41848. +
  41849. +
  41850. +/* MISC */
  41851. +
  41852. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  41853. +{
  41854. + return memset(dest, byte, size);
  41855. +}
  41856. +
  41857. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  41858. +{
  41859. + return memcpy(dest, src, size);
  41860. +}
  41861. +
  41862. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  41863. +{
  41864. + return memmove(dest, src, size);
  41865. +}
  41866. +
  41867. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  41868. +{
  41869. + return memcmp(m1, m2, size);
  41870. +}
  41871. +
  41872. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  41873. +{
  41874. + return strncmp(s1, s2, size);
  41875. +}
  41876. +
  41877. +int DWC_STRCMP(void *s1, void *s2)
  41878. +{
  41879. + return strcmp(s1, s2);
  41880. +}
  41881. +
  41882. +int DWC_STRLEN(char const *str)
  41883. +{
  41884. + return strlen(str);
  41885. +}
  41886. +
  41887. +char *DWC_STRCPY(char *to, char const *from)
  41888. +{
  41889. + return strcpy(to, from);
  41890. +}
  41891. +
  41892. +char *DWC_STRDUP(char const *str)
  41893. +{
  41894. + int len = DWC_STRLEN(str) + 1;
  41895. + char *new = DWC_ALLOC_ATOMIC(len);
  41896. +
  41897. + if (!new) {
  41898. + return NULL;
  41899. + }
  41900. +
  41901. + DWC_MEMCPY(new, str, len);
  41902. + return new;
  41903. +}
  41904. +
  41905. +int DWC_ATOI(const char *str, int32_t *value)
  41906. +{
  41907. + char *end = NULL;
  41908. +
  41909. + *value = simple_strtol(str, &end, 0);
  41910. + if (*end == '\0') {
  41911. + return 0;
  41912. + }
  41913. +
  41914. + return -1;
  41915. +}
  41916. +
  41917. +int DWC_ATOUI(const char *str, uint32_t *value)
  41918. +{
  41919. + char *end = NULL;
  41920. +
  41921. + *value = simple_strtoul(str, &end, 0);
  41922. + if (*end == '\0') {
  41923. + return 0;
  41924. + }
  41925. +
  41926. + return -1;
  41927. +}
  41928. +
  41929. +
  41930. +#ifdef DWC_UTFLIB
  41931. +/* From usbstring.c */
  41932. +
  41933. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  41934. +{
  41935. + int count = 0;
  41936. + u8 c;
  41937. + u16 uchar;
  41938. +
  41939. + /* this insists on correct encodings, though not minimal ones.
  41940. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  41941. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  41942. + */
  41943. + while (len != 0 && (c = (u8) *s++) != 0) {
  41944. + if (unlikely(c & 0x80)) {
  41945. + // 2-byte sequence:
  41946. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  41947. + if ((c & 0xe0) == 0xc0) {
  41948. + uchar = (c & 0x1f) << 6;
  41949. +
  41950. + c = (u8) *s++;
  41951. + if ((c & 0xc0) != 0xc0)
  41952. + goto fail;
  41953. + c &= 0x3f;
  41954. + uchar |= c;
  41955. +
  41956. + // 3-byte sequence (most CJKV characters):
  41957. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  41958. + } else if ((c & 0xf0) == 0xe0) {
  41959. + uchar = (c & 0x0f) << 12;
  41960. +
  41961. + c = (u8) *s++;
  41962. + if ((c & 0xc0) != 0xc0)
  41963. + goto fail;
  41964. + c &= 0x3f;
  41965. + uchar |= c << 6;
  41966. +
  41967. + c = (u8) *s++;
  41968. + if ((c & 0xc0) != 0xc0)
  41969. + goto fail;
  41970. + c &= 0x3f;
  41971. + uchar |= c;
  41972. +
  41973. + /* no bogus surrogates */
  41974. + if (0xd800 <= uchar && uchar <= 0xdfff)
  41975. + goto fail;
  41976. +
  41977. + // 4-byte sequence (surrogate pairs, currently rare):
  41978. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  41979. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  41980. + // (uuuuu = wwww + 1)
  41981. + // FIXME accept the surrogate code points (only)
  41982. + } else
  41983. + goto fail;
  41984. + } else
  41985. + uchar = c;
  41986. + put_unaligned (cpu_to_le16 (uchar), cp++);
  41987. + count++;
  41988. + len--;
  41989. + }
  41990. + return count;
  41991. +fail:
  41992. + return -1;
  41993. +}
  41994. +#endif /* DWC_UTFLIB */
  41995. +
  41996. +
  41997. +/* dwc_debug.h */
  41998. +
  41999. +dwc_bool_t DWC_IN_IRQ(void)
  42000. +{
  42001. + return in_irq();
  42002. +}
  42003. +
  42004. +dwc_bool_t DWC_IN_BH(void)
  42005. +{
  42006. + return in_softirq();
  42007. +}
  42008. +
  42009. +void DWC_VPRINTF(char *format, va_list args)
  42010. +{
  42011. + vprintk(format, args);
  42012. +}
  42013. +
  42014. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  42015. +{
  42016. + return vsnprintf(str, size, format, args);
  42017. +}
  42018. +
  42019. +void DWC_PRINTF(char *format, ...)
  42020. +{
  42021. + va_list args;
  42022. +
  42023. + va_start(args, format);
  42024. + DWC_VPRINTF(format, args);
  42025. + va_end(args);
  42026. +}
  42027. +
  42028. +int DWC_SPRINTF(char *buffer, char *format, ...)
  42029. +{
  42030. + int retval;
  42031. + va_list args;
  42032. +
  42033. + va_start(args, format);
  42034. + retval = vsprintf(buffer, format, args);
  42035. + va_end(args);
  42036. + return retval;
  42037. +}
  42038. +
  42039. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  42040. +{
  42041. + int retval;
  42042. + va_list args;
  42043. +
  42044. + va_start(args, format);
  42045. + retval = vsnprintf(buffer, size, format, args);
  42046. + va_end(args);
  42047. + return retval;
  42048. +}
  42049. +
  42050. +void __DWC_WARN(char *format, ...)
  42051. +{
  42052. + va_list args;
  42053. +
  42054. + va_start(args, format);
  42055. + DWC_PRINTF(KERN_WARNING);
  42056. + DWC_VPRINTF(format, args);
  42057. + va_end(args);
  42058. +}
  42059. +
  42060. +void __DWC_ERROR(char *format, ...)
  42061. +{
  42062. + va_list args;
  42063. +
  42064. + va_start(args, format);
  42065. + DWC_PRINTF(KERN_ERR);
  42066. + DWC_VPRINTF(format, args);
  42067. + va_end(args);
  42068. +}
  42069. +
  42070. +void DWC_EXCEPTION(char *format, ...)
  42071. +{
  42072. + va_list args;
  42073. +
  42074. + va_start(args, format);
  42075. + DWC_PRINTF(KERN_ERR);
  42076. + DWC_VPRINTF(format, args);
  42077. + va_end(args);
  42078. + BUG_ON(1);
  42079. +}
  42080. +
  42081. +#ifdef DEBUG
  42082. +void __DWC_DEBUG(char *format, ...)
  42083. +{
  42084. + va_list args;
  42085. +
  42086. + va_start(args, format);
  42087. + DWC_PRINTF(KERN_DEBUG);
  42088. + DWC_VPRINTF(format, args);
  42089. + va_end(args);
  42090. +}
  42091. +#endif
  42092. +
  42093. +
  42094. +/* dwc_mem.h */
  42095. +
  42096. +#if 0
  42097. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  42098. + uint32_t align,
  42099. + uint32_t alloc)
  42100. +{
  42101. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  42102. + size, align, alloc);
  42103. + return (dwc_pool_t *)pool;
  42104. +}
  42105. +
  42106. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  42107. +{
  42108. + dma_pool_destroy((struct dma_pool *)pool);
  42109. +}
  42110. +
  42111. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42112. +{
  42113. + return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  42114. +}
  42115. +
  42116. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42117. +{
  42118. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  42119. + memset(..);
  42120. +}
  42121. +
  42122. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  42123. +{
  42124. + dma_pool_free(pool, vaddr, daddr);
  42125. +}
  42126. +#endif
  42127. +
  42128. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  42129. +{
  42130. +#ifdef xxCOSIM /* Only works for 32-bit cosim */
  42131. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL);
  42132. +#else
  42133. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL | GFP_DMA32);
  42134. +#endif
  42135. + if (!buf) {
  42136. + return NULL;
  42137. + }
  42138. +
  42139. + memset(buf, 0, (size_t)size);
  42140. + return buf;
  42141. +}
  42142. +
  42143. +void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  42144. +{
  42145. + void *buf = dma_alloc_coherent(NULL, (size_t)size, dma_addr, GFP_ATOMIC);
  42146. + if (!buf) {
  42147. + return NULL;
  42148. + }
  42149. + memset(buf, 0, (size_t)size);
  42150. + return buf;
  42151. +}
  42152. +
  42153. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  42154. +{
  42155. + dma_free_coherent(dma_ctx, size, virt_addr, dma_addr);
  42156. +}
  42157. +
  42158. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  42159. +{
  42160. + return kzalloc(size, GFP_KERNEL);
  42161. +}
  42162. +
  42163. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  42164. +{
  42165. + return kzalloc(size, GFP_ATOMIC);
  42166. +}
  42167. +
  42168. +void __DWC_FREE(void *mem_ctx, void *addr)
  42169. +{
  42170. + kfree(addr);
  42171. +}
  42172. +
  42173. +
  42174. +#ifdef DWC_CRYPTOLIB
  42175. +/* dwc_crypto.h */
  42176. +
  42177. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  42178. +{
  42179. + get_random_bytes(buffer, length);
  42180. +}
  42181. +
  42182. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  42183. +{
  42184. + struct crypto_blkcipher *tfm;
  42185. + struct blkcipher_desc desc;
  42186. + struct scatterlist sgd;
  42187. + struct scatterlist sgs;
  42188. +
  42189. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  42190. + if (tfm == NULL) {
  42191. + printk("failed to load transform for aes CBC\n");
  42192. + return -1;
  42193. + }
  42194. +
  42195. + crypto_blkcipher_setkey(tfm, key, keylen);
  42196. + crypto_blkcipher_set_iv(tfm, iv, 16);
  42197. +
  42198. + sg_init_one(&sgd, out, messagelen);
  42199. + sg_init_one(&sgs, message, messagelen);
  42200. +
  42201. + desc.tfm = tfm;
  42202. + desc.flags = 0;
  42203. +
  42204. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  42205. + crypto_free_blkcipher(tfm);
  42206. + DWC_ERROR("AES CBC encryption failed");
  42207. + return -1;
  42208. + }
  42209. +
  42210. + crypto_free_blkcipher(tfm);
  42211. + return 0;
  42212. +}
  42213. +
  42214. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  42215. +{
  42216. + struct crypto_hash *tfm;
  42217. + struct hash_desc desc;
  42218. + struct scatterlist sg;
  42219. +
  42220. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  42221. + if (IS_ERR(tfm)) {
  42222. + DWC_ERROR("Failed to load transform for sha256: %ld\n", PTR_ERR(tfm));
  42223. + return 0;
  42224. + }
  42225. + desc.tfm = tfm;
  42226. + desc.flags = 0;
  42227. +
  42228. + sg_init_one(&sg, message, len);
  42229. + crypto_hash_digest(&desc, &sg, len, out);
  42230. + crypto_free_hash(tfm);
  42231. +
  42232. + return 1;
  42233. +}
  42234. +
  42235. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  42236. + uint8_t *key, uint32_t keylen, uint8_t *out)
  42237. +{
  42238. + struct crypto_hash *tfm;
  42239. + struct hash_desc desc;
  42240. + struct scatterlist sg;
  42241. +
  42242. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  42243. + if (IS_ERR(tfm)) {
  42244. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld\n", PTR_ERR(tfm));
  42245. + return 0;
  42246. + }
  42247. + desc.tfm = tfm;
  42248. + desc.flags = 0;
  42249. +
  42250. + sg_init_one(&sg, message, messagelen);
  42251. + crypto_hash_setkey(tfm, key, keylen);
  42252. + crypto_hash_digest(&desc, &sg, messagelen, out);
  42253. + crypto_free_hash(tfm);
  42254. +
  42255. + return 1;
  42256. +}
  42257. +#endif /* DWC_CRYPTOLIB */
  42258. +
  42259. +
  42260. +/* Byte Ordering Conversions */
  42261. +
  42262. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  42263. +{
  42264. +#ifdef __LITTLE_ENDIAN
  42265. + return *p;
  42266. +#else
  42267. + uint8_t *u_p = (uint8_t *)p;
  42268. +
  42269. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42270. +#endif
  42271. +}
  42272. +
  42273. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  42274. +{
  42275. +#ifdef __BIG_ENDIAN
  42276. + return *p;
  42277. +#else
  42278. + uint8_t *u_p = (uint8_t *)p;
  42279. +
  42280. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42281. +#endif
  42282. +}
  42283. +
  42284. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  42285. +{
  42286. +#ifdef __LITTLE_ENDIAN
  42287. + return *p;
  42288. +#else
  42289. + uint8_t *u_p = (uint8_t *)p;
  42290. +
  42291. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42292. +#endif
  42293. +}
  42294. +
  42295. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  42296. +{
  42297. +#ifdef __BIG_ENDIAN
  42298. + return *p;
  42299. +#else
  42300. + uint8_t *u_p = (uint8_t *)p;
  42301. +
  42302. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42303. +#endif
  42304. +}
  42305. +
  42306. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  42307. +{
  42308. +#ifdef __LITTLE_ENDIAN
  42309. + return *p;
  42310. +#else
  42311. + uint8_t *u_p = (uint8_t *)p;
  42312. + return (u_p[1] | (u_p[0] << 8));
  42313. +#endif
  42314. +}
  42315. +
  42316. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  42317. +{
  42318. +#ifdef __BIG_ENDIAN
  42319. + return *p;
  42320. +#else
  42321. + uint8_t *u_p = (uint8_t *)p;
  42322. + return (u_p[1] | (u_p[0] << 8));
  42323. +#endif
  42324. +}
  42325. +
  42326. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  42327. +{
  42328. +#ifdef __LITTLE_ENDIAN
  42329. + return *p;
  42330. +#else
  42331. + uint8_t *u_p = (uint8_t *)p;
  42332. + return (u_p[1] | (u_p[0] << 8));
  42333. +#endif
  42334. +}
  42335. +
  42336. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  42337. +{
  42338. +#ifdef __BIG_ENDIAN
  42339. + return *p;
  42340. +#else
  42341. + uint8_t *u_p = (uint8_t *)p;
  42342. + return (u_p[1] | (u_p[0] << 8));
  42343. +#endif
  42344. +}
  42345. +
  42346. +
  42347. +/* Registers */
  42348. +
  42349. +uint32_t DWC_READ_REG32(uint32_t volatile *reg)
  42350. +{
  42351. + return readl(reg);
  42352. +}
  42353. +
  42354. +#if 0
  42355. +uint64_t DWC_READ_REG64(uint64_t volatile *reg)
  42356. +{
  42357. +}
  42358. +#endif
  42359. +
  42360. +void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value)
  42361. +{
  42362. + writel(value, reg);
  42363. +}
  42364. +
  42365. +#if 0
  42366. +void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
  42367. +{
  42368. +}
  42369. +#endif
  42370. +
  42371. +void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
  42372. +{
  42373. + unsigned long flags;
  42374. +
  42375. + local_irq_save(flags);
  42376. + local_fiq_disable();
  42377. + writel((readl(reg) & ~clear_mask) | set_mask, reg);
  42378. + local_fiq_enable();
  42379. + local_irq_restore(flags);
  42380. +}
  42381. +
  42382. +#if 0
  42383. +void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask)
  42384. +{
  42385. +}
  42386. +#endif
  42387. +
  42388. +
  42389. +/* Locking */
  42390. +
  42391. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  42392. +{
  42393. + spinlock_t *sl = (spinlock_t *)1;
  42394. +
  42395. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42396. + sl = DWC_ALLOC(sizeof(*sl));
  42397. + if (!sl) {
  42398. + DWC_ERROR("Cannot allocate memory for spinlock\n");
  42399. + return NULL;
  42400. + }
  42401. +
  42402. + spin_lock_init(sl);
  42403. +#endif
  42404. + return (dwc_spinlock_t *)sl;
  42405. +}
  42406. +
  42407. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  42408. +{
  42409. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42410. + DWC_FREE(lock);
  42411. +#endif
  42412. +}
  42413. +
  42414. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  42415. +{
  42416. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42417. + spin_lock((spinlock_t *)lock);
  42418. +#endif
  42419. +}
  42420. +
  42421. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  42422. +{
  42423. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42424. + spin_unlock((spinlock_t *)lock);
  42425. +#endif
  42426. +}
  42427. +
  42428. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  42429. +{
  42430. + dwc_irqflags_t f;
  42431. +
  42432. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42433. + spin_lock_irqsave((spinlock_t *)lock, f);
  42434. +#else
  42435. + local_irq_save(f);
  42436. +#endif
  42437. + *flags = f;
  42438. +}
  42439. +
  42440. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  42441. +{
  42442. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42443. + spin_unlock_irqrestore((spinlock_t *)lock, flags);
  42444. +#else
  42445. + local_irq_restore(flags);
  42446. +#endif
  42447. +}
  42448. +
  42449. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  42450. +{
  42451. + struct mutex *m;
  42452. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex));
  42453. +
  42454. + if (!mutex) {
  42455. + DWC_ERROR("Cannot allocate memory for mutex\n");
  42456. + return NULL;
  42457. + }
  42458. +
  42459. + m = (struct mutex *)mutex;
  42460. + mutex_init(m);
  42461. + return mutex;
  42462. +}
  42463. +
  42464. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  42465. +#else
  42466. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  42467. +{
  42468. + mutex_destroy((struct mutex *)mutex);
  42469. + DWC_FREE(mutex);
  42470. +}
  42471. +#endif
  42472. +
  42473. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  42474. +{
  42475. + struct mutex *m = (struct mutex *)mutex;
  42476. + mutex_lock(m);
  42477. +}
  42478. +
  42479. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  42480. +{
  42481. + struct mutex *m = (struct mutex *)mutex;
  42482. + return mutex_trylock(m);
  42483. +}
  42484. +
  42485. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  42486. +{
  42487. + struct mutex *m = (struct mutex *)mutex;
  42488. + mutex_unlock(m);
  42489. +}
  42490. +
  42491. +
  42492. +/* Timing */
  42493. +
  42494. +void DWC_UDELAY(uint32_t usecs)
  42495. +{
  42496. + udelay(usecs);
  42497. +}
  42498. +
  42499. +void DWC_MDELAY(uint32_t msecs)
  42500. +{
  42501. + mdelay(msecs);
  42502. +}
  42503. +
  42504. +void DWC_MSLEEP(uint32_t msecs)
  42505. +{
  42506. + msleep(msecs);
  42507. +}
  42508. +
  42509. +uint32_t DWC_TIME(void)
  42510. +{
  42511. + return jiffies_to_msecs(jiffies);
  42512. +}
  42513. +
  42514. +
  42515. +/* Timers */
  42516. +
  42517. +struct dwc_timer {
  42518. + struct timer_list *t;
  42519. + char *name;
  42520. + dwc_timer_callback_t cb;
  42521. + void *data;
  42522. + uint8_t scheduled;
  42523. + dwc_spinlock_t *lock;
  42524. +};
  42525. +
  42526. +static void timer_callback(unsigned long data)
  42527. +{
  42528. + dwc_timer_t *timer = (dwc_timer_t *)data;
  42529. + dwc_irqflags_t flags;
  42530. +
  42531. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  42532. + timer->scheduled = 0;
  42533. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  42534. + DWC_DEBUGC("Timer %s callback", timer->name);
  42535. + timer->cb(timer->data);
  42536. +}
  42537. +
  42538. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  42539. +{
  42540. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  42541. +
  42542. + if (!t) {
  42543. + DWC_ERROR("Cannot allocate memory for timer");
  42544. + return NULL;
  42545. + }
  42546. +
  42547. + t->t = DWC_ALLOC(sizeof(*t->t));
  42548. + if (!t->t) {
  42549. + DWC_ERROR("Cannot allocate memory for timer->t");
  42550. + goto no_timer;
  42551. + }
  42552. +
  42553. + t->name = DWC_STRDUP(name);
  42554. + if (!t->name) {
  42555. + DWC_ERROR("Cannot allocate memory for timer->name");
  42556. + goto no_name;
  42557. + }
  42558. +
  42559. + t->lock = DWC_SPINLOCK_ALLOC();
  42560. + if (!t->lock) {
  42561. + DWC_ERROR("Cannot allocate memory for lock");
  42562. + goto no_lock;
  42563. + }
  42564. +
  42565. + t->scheduled = 0;
  42566. + t->t->base = &boot_tvec_bases;
  42567. + t->t->expires = jiffies;
  42568. + setup_timer(t->t, timer_callback, (unsigned long)t);
  42569. +
  42570. + t->cb = cb;
  42571. + t->data = data;
  42572. +
  42573. + return t;
  42574. +
  42575. + no_lock:
  42576. + DWC_FREE(t->name);
  42577. + no_name:
  42578. + DWC_FREE(t->t);
  42579. + no_timer:
  42580. + DWC_FREE(t);
  42581. + return NULL;
  42582. +}
  42583. +
  42584. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  42585. +{
  42586. + dwc_irqflags_t flags;
  42587. +
  42588. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  42589. +
  42590. + if (timer->scheduled) {
  42591. + del_timer(timer->t);
  42592. + timer->scheduled = 0;
  42593. + }
  42594. +
  42595. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  42596. + DWC_SPINLOCK_FREE(timer->lock);
  42597. + DWC_FREE(timer->t);
  42598. + DWC_FREE(timer->name);
  42599. + DWC_FREE(timer);
  42600. +}
  42601. +
  42602. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  42603. +{
  42604. + dwc_irqflags_t flags;
  42605. +
  42606. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  42607. +
  42608. + if (!timer->scheduled) {
  42609. + timer->scheduled = 1;
  42610. + DWC_DEBUGC("Scheduling timer %s to expire in +%d msec", timer->name, time);
  42611. + timer->t->expires = jiffies + msecs_to_jiffies(time);
  42612. + add_timer(timer->t);
  42613. + } else {
  42614. + DWC_DEBUGC("Modifying timer %s to expire in +%d msec", timer->name, time);
  42615. + mod_timer(timer->t, jiffies + msecs_to_jiffies(time));
  42616. + }
  42617. +
  42618. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  42619. +}
  42620. +
  42621. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  42622. +{
  42623. + del_timer(timer->t);
  42624. +}
  42625. +
  42626. +
  42627. +/* Wait Queues */
  42628. +
  42629. +struct dwc_waitq {
  42630. + wait_queue_head_t queue;
  42631. + int abort;
  42632. +};
  42633. +
  42634. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  42635. +{
  42636. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  42637. +
  42638. + if (!wq) {
  42639. + DWC_ERROR("Cannot allocate memory for waitqueue\n");
  42640. + return NULL;
  42641. + }
  42642. +
  42643. + init_waitqueue_head(&wq->queue);
  42644. + wq->abort = 0;
  42645. + return wq;
  42646. +}
  42647. +
  42648. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  42649. +{
  42650. + DWC_FREE(wq);
  42651. +}
  42652. +
  42653. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  42654. +{
  42655. + int result = wait_event_interruptible(wq->queue,
  42656. + cond(data) || wq->abort);
  42657. + if (result == -ERESTARTSYS) {
  42658. + wq->abort = 0;
  42659. + return -DWC_E_RESTART;
  42660. + }
  42661. +
  42662. + if (wq->abort == 1) {
  42663. + wq->abort = 0;
  42664. + return -DWC_E_ABORT;
  42665. + }
  42666. +
  42667. + wq->abort = 0;
  42668. +
  42669. + if (result == 0) {
  42670. + return 0;
  42671. + }
  42672. +
  42673. + return -DWC_E_UNKNOWN;
  42674. +}
  42675. +
  42676. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  42677. + void *data, int32_t msecs)
  42678. +{
  42679. + int32_t tmsecs;
  42680. + int result = wait_event_interruptible_timeout(wq->queue,
  42681. + cond(data) || wq->abort,
  42682. + msecs_to_jiffies(msecs));
  42683. + if (result == -ERESTARTSYS) {
  42684. + wq->abort = 0;
  42685. + return -DWC_E_RESTART;
  42686. + }
  42687. +
  42688. + if (wq->abort == 1) {
  42689. + wq->abort = 0;
  42690. + return -DWC_E_ABORT;
  42691. + }
  42692. +
  42693. + wq->abort = 0;
  42694. +
  42695. + if (result > 0) {
  42696. + tmsecs = jiffies_to_msecs(result);
  42697. + if (!tmsecs) {
  42698. + return 1;
  42699. + }
  42700. +
  42701. + return tmsecs;
  42702. + }
  42703. +
  42704. + if (result == 0) {
  42705. + return -DWC_E_TIMEOUT;
  42706. + }
  42707. +
  42708. + return -DWC_E_UNKNOWN;
  42709. +}
  42710. +
  42711. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  42712. +{
  42713. + wq->abort = 0;
  42714. + wake_up_interruptible(&wq->queue);
  42715. +}
  42716. +
  42717. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  42718. +{
  42719. + wq->abort = 1;
  42720. + wake_up_interruptible(&wq->queue);
  42721. +}
  42722. +
  42723. +
  42724. +/* Threading */
  42725. +
  42726. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  42727. +{
  42728. + struct task_struct *thread = kthread_run(func, data, name);
  42729. +
  42730. + if (thread == ERR_PTR(-ENOMEM)) {
  42731. + return NULL;
  42732. + }
  42733. +
  42734. + return (dwc_thread_t *)thread;
  42735. +}
  42736. +
  42737. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  42738. +{
  42739. + return kthread_stop((struct task_struct *)thread);
  42740. +}
  42741. +
  42742. +dwc_bool_t DWC_THREAD_SHOULD_STOP(void)
  42743. +{
  42744. + return kthread_should_stop();
  42745. +}
  42746. +
  42747. +
  42748. +/* tasklets
  42749. + - run in interrupt context (cannot sleep)
  42750. + - each tasklet runs on a single CPU
  42751. + - different tasklets can be running simultaneously on different CPUs
  42752. + */
  42753. +struct dwc_tasklet {
  42754. + struct tasklet_struct t;
  42755. + dwc_tasklet_callback_t cb;
  42756. + void *data;
  42757. +};
  42758. +
  42759. +static void tasklet_callback(unsigned long data)
  42760. +{
  42761. + dwc_tasklet_t *t = (dwc_tasklet_t *)data;
  42762. + t->cb(t->data);
  42763. +}
  42764. +
  42765. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  42766. +{
  42767. + dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t));
  42768. +
  42769. + if (t) {
  42770. + t->cb = cb;
  42771. + t->data = data;
  42772. + tasklet_init(&t->t, tasklet_callback, (unsigned long)t);
  42773. + } else {
  42774. + DWC_ERROR("Cannot allocate memory for tasklet\n");
  42775. + }
  42776. +
  42777. + return t;
  42778. +}
  42779. +
  42780. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  42781. +{
  42782. + DWC_FREE(task);
  42783. +}
  42784. +
  42785. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  42786. +{
  42787. + tasklet_schedule(&task->t);
  42788. +}
  42789. +
  42790. +void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task)
  42791. +{
  42792. + tasklet_hi_schedule(&task->t);
  42793. +}
  42794. +
  42795. +
  42796. +/* workqueues
  42797. + - run in process context (can sleep)
  42798. + */
  42799. +typedef struct work_container {
  42800. + dwc_work_callback_t cb;
  42801. + void *data;
  42802. + dwc_workq_t *wq;
  42803. + char *name;
  42804. +
  42805. +#ifdef DEBUG
  42806. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  42807. +#endif
  42808. + struct delayed_work work;
  42809. +} work_container_t;
  42810. +
  42811. +#ifdef DEBUG
  42812. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  42813. +#endif
  42814. +
  42815. +struct dwc_workq {
  42816. + struct workqueue_struct *wq;
  42817. + dwc_spinlock_t *lock;
  42818. + dwc_waitq_t *waitq;
  42819. + int pending;
  42820. +
  42821. +#ifdef DEBUG
  42822. + struct work_container_queue entries;
  42823. +#endif
  42824. +};
  42825. +
  42826. +static void do_work(struct work_struct *work)
  42827. +{
  42828. + dwc_irqflags_t flags;
  42829. + struct delayed_work *dw = container_of(work, struct delayed_work, work);
  42830. + work_container_t *container = container_of(dw, struct work_container, work);
  42831. + dwc_workq_t *wq = container->wq;
  42832. +
  42833. + container->cb(container->data);
  42834. +
  42835. +#ifdef DEBUG
  42836. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  42837. +#endif
  42838. + DWC_DEBUGC("Work done: %s, container=%p", container->name, container);
  42839. + if (container->name) {
  42840. + DWC_FREE(container->name);
  42841. + }
  42842. + DWC_FREE(container);
  42843. +
  42844. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42845. + wq->pending--;
  42846. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42847. + DWC_WAITQ_TRIGGER(wq->waitq);
  42848. +}
  42849. +
  42850. +static int work_done(void *data)
  42851. +{
  42852. + dwc_workq_t *workq = (dwc_workq_t *)data;
  42853. + return workq->pending == 0;
  42854. +}
  42855. +
  42856. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  42857. +{
  42858. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  42859. +}
  42860. +
  42861. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  42862. +{
  42863. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  42864. +
  42865. + if (!wq) {
  42866. + return NULL;
  42867. + }
  42868. +
  42869. + wq->wq = create_singlethread_workqueue(name);
  42870. + if (!wq->wq) {
  42871. + goto no_wq;
  42872. + }
  42873. +
  42874. + wq->pending = 0;
  42875. +
  42876. + wq->lock = DWC_SPINLOCK_ALLOC();
  42877. + if (!wq->lock) {
  42878. + goto no_lock;
  42879. + }
  42880. +
  42881. + wq->waitq = DWC_WAITQ_ALLOC();
  42882. + if (!wq->waitq) {
  42883. + goto no_waitq;
  42884. + }
  42885. +
  42886. +#ifdef DEBUG
  42887. + DWC_CIRCLEQ_INIT(&wq->entries);
  42888. +#endif
  42889. + return wq;
  42890. +
  42891. + no_waitq:
  42892. + DWC_SPINLOCK_FREE(wq->lock);
  42893. + no_lock:
  42894. + destroy_workqueue(wq->wq);
  42895. + no_wq:
  42896. + DWC_FREE(wq);
  42897. +
  42898. + return NULL;
  42899. +}
  42900. +
  42901. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  42902. +{
  42903. +#ifdef DEBUG
  42904. + if (wq->pending != 0) {
  42905. + struct work_container *wc;
  42906. + DWC_ERROR("Destroying work queue with pending work");
  42907. + DWC_CIRCLEQ_FOREACH(wc, &wq->entries, entry) {
  42908. + DWC_ERROR("Work %s still pending", wc->name);
  42909. + }
  42910. + }
  42911. +#endif
  42912. + destroy_workqueue(wq->wq);
  42913. + DWC_SPINLOCK_FREE(wq->lock);
  42914. + DWC_WAITQ_FREE(wq->waitq);
  42915. + DWC_FREE(wq);
  42916. +}
  42917. +
  42918. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  42919. + char *format, ...)
  42920. +{
  42921. + dwc_irqflags_t flags;
  42922. + work_container_t *container;
  42923. + static char name[128];
  42924. + va_list args;
  42925. +
  42926. + va_start(args, format);
  42927. + DWC_VSNPRINTF(name, 128, format, args);
  42928. + va_end(args);
  42929. +
  42930. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42931. + wq->pending++;
  42932. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42933. + DWC_WAITQ_TRIGGER(wq->waitq);
  42934. +
  42935. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  42936. + if (!container) {
  42937. + DWC_ERROR("Cannot allocate memory for container\n");
  42938. + return;
  42939. + }
  42940. +
  42941. + container->name = DWC_STRDUP(name);
  42942. + if (!container->name) {
  42943. + DWC_ERROR("Cannot allocate memory for container->name\n");
  42944. + DWC_FREE(container);
  42945. + return;
  42946. + }
  42947. +
  42948. + container->cb = cb;
  42949. + container->data = data;
  42950. + container->wq = wq;
  42951. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  42952. + INIT_WORK(&container->work.work, do_work);
  42953. +
  42954. +#ifdef DEBUG
  42955. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  42956. +#endif
  42957. + queue_work(wq->wq, &container->work.work);
  42958. +}
  42959. +
  42960. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  42961. + void *data, uint32_t time, char *format, ...)
  42962. +{
  42963. + dwc_irqflags_t flags;
  42964. + work_container_t *container;
  42965. + static char name[128];
  42966. + va_list args;
  42967. +
  42968. + va_start(args, format);
  42969. + DWC_VSNPRINTF(name, 128, format, args);
  42970. + va_end(args);
  42971. +
  42972. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42973. + wq->pending++;
  42974. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42975. + DWC_WAITQ_TRIGGER(wq->waitq);
  42976. +
  42977. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  42978. + if (!container) {
  42979. + DWC_ERROR("Cannot allocate memory for container\n");
  42980. + return;
  42981. + }
  42982. +
  42983. + container->name = DWC_STRDUP(name);
  42984. + if (!container->name) {
  42985. + DWC_ERROR("Cannot allocate memory for container->name\n");
  42986. + DWC_FREE(container);
  42987. + return;
  42988. + }
  42989. +
  42990. + container->cb = cb;
  42991. + container->data = data;
  42992. + container->wq = wq;
  42993. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  42994. + INIT_DELAYED_WORK(&container->work, do_work);
  42995. +
  42996. +#ifdef DEBUG
  42997. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  42998. +#endif
  42999. + queue_delayed_work(wq->wq, &container->work, msecs_to_jiffies(time));
  43000. +}
  43001. +
  43002. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  43003. +{
  43004. + return wq->pending;
  43005. +}
  43006. +
  43007. +
  43008. +#ifdef DWC_LIBMODULE
  43009. +
  43010. +#ifdef DWC_CCLIB
  43011. +/* CC */
  43012. +EXPORT_SYMBOL(dwc_cc_if_alloc);
  43013. +EXPORT_SYMBOL(dwc_cc_if_free);
  43014. +EXPORT_SYMBOL(dwc_cc_clear);
  43015. +EXPORT_SYMBOL(dwc_cc_add);
  43016. +EXPORT_SYMBOL(dwc_cc_remove);
  43017. +EXPORT_SYMBOL(dwc_cc_change);
  43018. +EXPORT_SYMBOL(dwc_cc_data_for_save);
  43019. +EXPORT_SYMBOL(dwc_cc_restore_from_data);
  43020. +EXPORT_SYMBOL(dwc_cc_match_chid);
  43021. +EXPORT_SYMBOL(dwc_cc_match_cdid);
  43022. +EXPORT_SYMBOL(dwc_cc_ck);
  43023. +EXPORT_SYMBOL(dwc_cc_chid);
  43024. +EXPORT_SYMBOL(dwc_cc_cdid);
  43025. +EXPORT_SYMBOL(dwc_cc_name);
  43026. +#endif /* DWC_CCLIB */
  43027. +
  43028. +#ifdef DWC_CRYPTOLIB
  43029. +# ifndef CONFIG_MACH_IPMATE
  43030. +/* Modpow */
  43031. +EXPORT_SYMBOL(dwc_modpow);
  43032. +
  43033. +/* DH */
  43034. +EXPORT_SYMBOL(dwc_dh_modpow);
  43035. +EXPORT_SYMBOL(dwc_dh_derive_keys);
  43036. +EXPORT_SYMBOL(dwc_dh_pk);
  43037. +# endif /* CONFIG_MACH_IPMATE */
  43038. +
  43039. +/* Crypto */
  43040. +EXPORT_SYMBOL(dwc_wusb_aes_encrypt);
  43041. +EXPORT_SYMBOL(dwc_wusb_cmf);
  43042. +EXPORT_SYMBOL(dwc_wusb_prf);
  43043. +EXPORT_SYMBOL(dwc_wusb_fill_ccm_nonce);
  43044. +EXPORT_SYMBOL(dwc_wusb_gen_nonce);
  43045. +EXPORT_SYMBOL(dwc_wusb_gen_key);
  43046. +EXPORT_SYMBOL(dwc_wusb_gen_mic);
  43047. +#endif /* DWC_CRYPTOLIB */
  43048. +
  43049. +/* Notification */
  43050. +#ifdef DWC_NOTIFYLIB
  43051. +EXPORT_SYMBOL(dwc_alloc_notification_manager);
  43052. +EXPORT_SYMBOL(dwc_free_notification_manager);
  43053. +EXPORT_SYMBOL(dwc_register_notifier);
  43054. +EXPORT_SYMBOL(dwc_unregister_notifier);
  43055. +EXPORT_SYMBOL(dwc_add_observer);
  43056. +EXPORT_SYMBOL(dwc_remove_observer);
  43057. +EXPORT_SYMBOL(dwc_notify);
  43058. +#endif
  43059. +
  43060. +/* Memory Debugging Routines */
  43061. +#ifdef DWC_DEBUG_MEMORY
  43062. +EXPORT_SYMBOL(dwc_alloc_debug);
  43063. +EXPORT_SYMBOL(dwc_alloc_atomic_debug);
  43064. +EXPORT_SYMBOL(dwc_free_debug);
  43065. +EXPORT_SYMBOL(dwc_dma_alloc_debug);
  43066. +EXPORT_SYMBOL(dwc_dma_free_debug);
  43067. +#endif
  43068. +
  43069. +EXPORT_SYMBOL(DWC_MEMSET);
  43070. +EXPORT_SYMBOL(DWC_MEMCPY);
  43071. +EXPORT_SYMBOL(DWC_MEMMOVE);
  43072. +EXPORT_SYMBOL(DWC_MEMCMP);
  43073. +EXPORT_SYMBOL(DWC_STRNCMP);
  43074. +EXPORT_SYMBOL(DWC_STRCMP);
  43075. +EXPORT_SYMBOL(DWC_STRLEN);
  43076. +EXPORT_SYMBOL(DWC_STRCPY);
  43077. +EXPORT_SYMBOL(DWC_STRDUP);
  43078. +EXPORT_SYMBOL(DWC_ATOI);
  43079. +EXPORT_SYMBOL(DWC_ATOUI);
  43080. +
  43081. +#ifdef DWC_UTFLIB
  43082. +EXPORT_SYMBOL(DWC_UTF8_TO_UTF16LE);
  43083. +#endif /* DWC_UTFLIB */
  43084. +
  43085. +EXPORT_SYMBOL(DWC_IN_IRQ);
  43086. +EXPORT_SYMBOL(DWC_IN_BH);
  43087. +EXPORT_SYMBOL(DWC_VPRINTF);
  43088. +EXPORT_SYMBOL(DWC_VSNPRINTF);
  43089. +EXPORT_SYMBOL(DWC_PRINTF);
  43090. +EXPORT_SYMBOL(DWC_SPRINTF);
  43091. +EXPORT_SYMBOL(DWC_SNPRINTF);
  43092. +EXPORT_SYMBOL(__DWC_WARN);
  43093. +EXPORT_SYMBOL(__DWC_ERROR);
  43094. +EXPORT_SYMBOL(DWC_EXCEPTION);
  43095. +
  43096. +#ifdef DEBUG
  43097. +EXPORT_SYMBOL(__DWC_DEBUG);
  43098. +#endif
  43099. +
  43100. +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
  43101. +EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
  43102. +EXPORT_SYMBOL(__DWC_DMA_FREE);
  43103. +EXPORT_SYMBOL(__DWC_ALLOC);
  43104. +EXPORT_SYMBOL(__DWC_ALLOC_ATOMIC);
  43105. +EXPORT_SYMBOL(__DWC_FREE);
  43106. +
  43107. +#ifdef DWC_CRYPTOLIB
  43108. +EXPORT_SYMBOL(DWC_RANDOM_BYTES);
  43109. +EXPORT_SYMBOL(DWC_AES_CBC);
  43110. +EXPORT_SYMBOL(DWC_SHA256);
  43111. +EXPORT_SYMBOL(DWC_HMAC_SHA256);
  43112. +#endif
  43113. +
  43114. +EXPORT_SYMBOL(DWC_CPU_TO_LE32);
  43115. +EXPORT_SYMBOL(DWC_CPU_TO_BE32);
  43116. +EXPORT_SYMBOL(DWC_LE32_TO_CPU);
  43117. +EXPORT_SYMBOL(DWC_BE32_TO_CPU);
  43118. +EXPORT_SYMBOL(DWC_CPU_TO_LE16);
  43119. +EXPORT_SYMBOL(DWC_CPU_TO_BE16);
  43120. +EXPORT_SYMBOL(DWC_LE16_TO_CPU);
  43121. +EXPORT_SYMBOL(DWC_BE16_TO_CPU);
  43122. +EXPORT_SYMBOL(DWC_READ_REG32);
  43123. +EXPORT_SYMBOL(DWC_WRITE_REG32);
  43124. +EXPORT_SYMBOL(DWC_MODIFY_REG32);
  43125. +
  43126. +#if 0
  43127. +EXPORT_SYMBOL(DWC_READ_REG64);
  43128. +EXPORT_SYMBOL(DWC_WRITE_REG64);
  43129. +EXPORT_SYMBOL(DWC_MODIFY_REG64);
  43130. +#endif
  43131. +
  43132. +EXPORT_SYMBOL(DWC_SPINLOCK_ALLOC);
  43133. +EXPORT_SYMBOL(DWC_SPINLOCK_FREE);
  43134. +EXPORT_SYMBOL(DWC_SPINLOCK);
  43135. +EXPORT_SYMBOL(DWC_SPINUNLOCK);
  43136. +EXPORT_SYMBOL(DWC_SPINLOCK_IRQSAVE);
  43137. +EXPORT_SYMBOL(DWC_SPINUNLOCK_IRQRESTORE);
  43138. +EXPORT_SYMBOL(DWC_MUTEX_ALLOC);
  43139. +
  43140. +#if (!defined(DWC_LINUX) || !defined(CONFIG_DEBUG_MUTEXES))
  43141. +EXPORT_SYMBOL(DWC_MUTEX_FREE);
  43142. +#endif
  43143. +
  43144. +EXPORT_SYMBOL(DWC_MUTEX_LOCK);
  43145. +EXPORT_SYMBOL(DWC_MUTEX_TRYLOCK);
  43146. +EXPORT_SYMBOL(DWC_MUTEX_UNLOCK);
  43147. +EXPORT_SYMBOL(DWC_UDELAY);
  43148. +EXPORT_SYMBOL(DWC_MDELAY);
  43149. +EXPORT_SYMBOL(DWC_MSLEEP);
  43150. +EXPORT_SYMBOL(DWC_TIME);
  43151. +EXPORT_SYMBOL(DWC_TIMER_ALLOC);
  43152. +EXPORT_SYMBOL(DWC_TIMER_FREE);
  43153. +EXPORT_SYMBOL(DWC_TIMER_SCHEDULE);
  43154. +EXPORT_SYMBOL(DWC_TIMER_CANCEL);
  43155. +EXPORT_SYMBOL(DWC_WAITQ_ALLOC);
  43156. +EXPORT_SYMBOL(DWC_WAITQ_FREE);
  43157. +EXPORT_SYMBOL(DWC_WAITQ_WAIT);
  43158. +EXPORT_SYMBOL(DWC_WAITQ_WAIT_TIMEOUT);
  43159. +EXPORT_SYMBOL(DWC_WAITQ_TRIGGER);
  43160. +EXPORT_SYMBOL(DWC_WAITQ_ABORT);
  43161. +EXPORT_SYMBOL(DWC_THREAD_RUN);
  43162. +EXPORT_SYMBOL(DWC_THREAD_STOP);
  43163. +EXPORT_SYMBOL(DWC_THREAD_SHOULD_STOP);
  43164. +EXPORT_SYMBOL(DWC_TASK_ALLOC);
  43165. +EXPORT_SYMBOL(DWC_TASK_FREE);
  43166. +EXPORT_SYMBOL(DWC_TASK_SCHEDULE);
  43167. +EXPORT_SYMBOL(DWC_WORKQ_WAIT_WORK_DONE);
  43168. +EXPORT_SYMBOL(DWC_WORKQ_ALLOC);
  43169. +EXPORT_SYMBOL(DWC_WORKQ_FREE);
  43170. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE);
  43171. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE_DELAYED);
  43172. +EXPORT_SYMBOL(DWC_WORKQ_PENDING);
  43173. +
  43174. +static int dwc_common_port_init_module(void)
  43175. +{
  43176. + int result = 0;
  43177. +
  43178. + printk(KERN_DEBUG "Module dwc_common_port init\n" );
  43179. +
  43180. +#ifdef DWC_DEBUG_MEMORY
  43181. + result = dwc_memory_debug_start(NULL);
  43182. + if (result) {
  43183. + printk(KERN_ERR
  43184. + "dwc_memory_debug_start() failed with error %d\n",
  43185. + result);
  43186. + return result;
  43187. + }
  43188. +#endif
  43189. +
  43190. +#ifdef DWC_NOTIFYLIB
  43191. + result = dwc_alloc_notification_manager(NULL, NULL);
  43192. + if (result) {
  43193. + printk(KERN_ERR
  43194. + "dwc_alloc_notification_manager() failed with error %d\n",
  43195. + result);
  43196. + return result;
  43197. + }
  43198. +#endif
  43199. + return result;
  43200. +}
  43201. +
  43202. +static void dwc_common_port_exit_module(void)
  43203. +{
  43204. + printk(KERN_DEBUG "Module dwc_common_port exit\n" );
  43205. +
  43206. +#ifdef DWC_NOTIFYLIB
  43207. + dwc_free_notification_manager();
  43208. +#endif
  43209. +
  43210. +#ifdef DWC_DEBUG_MEMORY
  43211. + dwc_memory_debug_stop();
  43212. +#endif
  43213. +}
  43214. +
  43215. +module_init(dwc_common_port_init_module);
  43216. +module_exit(dwc_common_port_exit_module);
  43217. +
  43218. +MODULE_DESCRIPTION("DWC Common Library - Portable version");
  43219. +MODULE_AUTHOR("Synopsys Inc.");
  43220. +MODULE_LICENSE ("GPL");
  43221. +
  43222. +#endif /* DWC_LIBMODULE */
  43223. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c
  43224. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 1970-01-01 01:00:00.000000000 +0100
  43225. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 2014-04-24 15:35:04.169565731 +0200
  43226. @@ -0,0 +1,1275 @@
  43227. +#include "dwc_os.h"
  43228. +#include "dwc_list.h"
  43229. +
  43230. +#ifdef DWC_CCLIB
  43231. +# include "dwc_cc.h"
  43232. +#endif
  43233. +
  43234. +#ifdef DWC_CRYPTOLIB
  43235. +# include "dwc_modpow.h"
  43236. +# include "dwc_dh.h"
  43237. +# include "dwc_crypto.h"
  43238. +#endif
  43239. +
  43240. +#ifdef DWC_NOTIFYLIB
  43241. +# include "dwc_notifier.h"
  43242. +#endif
  43243. +
  43244. +/* OS-Level Implementations */
  43245. +
  43246. +/* This is the NetBSD 4.0.1 kernel implementation of the DWC platform library. */
  43247. +
  43248. +
  43249. +/* MISC */
  43250. +
  43251. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  43252. +{
  43253. + return memset(dest, byte, size);
  43254. +}
  43255. +
  43256. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  43257. +{
  43258. + return memcpy(dest, src, size);
  43259. +}
  43260. +
  43261. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  43262. +{
  43263. + bcopy(src, dest, size);
  43264. + return dest;
  43265. +}
  43266. +
  43267. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  43268. +{
  43269. + return memcmp(m1, m2, size);
  43270. +}
  43271. +
  43272. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  43273. +{
  43274. + return strncmp(s1, s2, size);
  43275. +}
  43276. +
  43277. +int DWC_STRCMP(void *s1, void *s2)
  43278. +{
  43279. + return strcmp(s1, s2);
  43280. +}
  43281. +
  43282. +int DWC_STRLEN(char const *str)
  43283. +{
  43284. + return strlen(str);
  43285. +}
  43286. +
  43287. +char *DWC_STRCPY(char *to, char const *from)
  43288. +{
  43289. + return strcpy(to, from);
  43290. +}
  43291. +
  43292. +char *DWC_STRDUP(char const *str)
  43293. +{
  43294. + int len = DWC_STRLEN(str) + 1;
  43295. + char *new = DWC_ALLOC_ATOMIC(len);
  43296. +
  43297. + if (!new) {
  43298. + return NULL;
  43299. + }
  43300. +
  43301. + DWC_MEMCPY(new, str, len);
  43302. + return new;
  43303. +}
  43304. +
  43305. +int DWC_ATOI(char *str, int32_t *value)
  43306. +{
  43307. + char *end = NULL;
  43308. +
  43309. + /* NetBSD doesn't have 'strtol' in the kernel, but 'strtoul'
  43310. + * should be equivalent on 2's complement machines
  43311. + */
  43312. + *value = strtoul(str, &end, 0);
  43313. + if (*end == '\0') {
  43314. + return 0;
  43315. + }
  43316. +
  43317. + return -1;
  43318. +}
  43319. +
  43320. +int DWC_ATOUI(char *str, uint32_t *value)
  43321. +{
  43322. + char *end = NULL;
  43323. +
  43324. + *value = strtoul(str, &end, 0);
  43325. + if (*end == '\0') {
  43326. + return 0;
  43327. + }
  43328. +
  43329. + return -1;
  43330. +}
  43331. +
  43332. +
  43333. +#ifdef DWC_UTFLIB
  43334. +/* From usbstring.c */
  43335. +
  43336. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  43337. +{
  43338. + int count = 0;
  43339. + u8 c;
  43340. + u16 uchar;
  43341. +
  43342. + /* this insists on correct encodings, though not minimal ones.
  43343. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  43344. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  43345. + */
  43346. + while (len != 0 && (c = (u8) *s++) != 0) {
  43347. + if (unlikely(c & 0x80)) {
  43348. + // 2-byte sequence:
  43349. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  43350. + if ((c & 0xe0) == 0xc0) {
  43351. + uchar = (c & 0x1f) << 6;
  43352. +
  43353. + c = (u8) *s++;
  43354. + if ((c & 0xc0) != 0xc0)
  43355. + goto fail;
  43356. + c &= 0x3f;
  43357. + uchar |= c;
  43358. +
  43359. + // 3-byte sequence (most CJKV characters):
  43360. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  43361. + } else if ((c & 0xf0) == 0xe0) {
  43362. + uchar = (c & 0x0f) << 12;
  43363. +
  43364. + c = (u8) *s++;
  43365. + if ((c & 0xc0) != 0xc0)
  43366. + goto fail;
  43367. + c &= 0x3f;
  43368. + uchar |= c << 6;
  43369. +
  43370. + c = (u8) *s++;
  43371. + if ((c & 0xc0) != 0xc0)
  43372. + goto fail;
  43373. + c &= 0x3f;
  43374. + uchar |= c;
  43375. +
  43376. + /* no bogus surrogates */
  43377. + if (0xd800 <= uchar && uchar <= 0xdfff)
  43378. + goto fail;
  43379. +
  43380. + // 4-byte sequence (surrogate pairs, currently rare):
  43381. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  43382. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  43383. + // (uuuuu = wwww + 1)
  43384. + // FIXME accept the surrogate code points (only)
  43385. + } else
  43386. + goto fail;
  43387. + } else
  43388. + uchar = c;
  43389. + put_unaligned (cpu_to_le16 (uchar), cp++);
  43390. + count++;
  43391. + len--;
  43392. + }
  43393. + return count;
  43394. +fail:
  43395. + return -1;
  43396. +}
  43397. +
  43398. +#endif /* DWC_UTFLIB */
  43399. +
  43400. +
  43401. +/* dwc_debug.h */
  43402. +
  43403. +dwc_bool_t DWC_IN_IRQ(void)
  43404. +{
  43405. +// return in_irq();
  43406. + return 0;
  43407. +}
  43408. +
  43409. +dwc_bool_t DWC_IN_BH(void)
  43410. +{
  43411. +// return in_softirq();
  43412. + return 0;
  43413. +}
  43414. +
  43415. +void DWC_VPRINTF(char *format, va_list args)
  43416. +{
  43417. + vprintf(format, args);
  43418. +}
  43419. +
  43420. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  43421. +{
  43422. + return vsnprintf(str, size, format, args);
  43423. +}
  43424. +
  43425. +void DWC_PRINTF(char *format, ...)
  43426. +{
  43427. + va_list args;
  43428. +
  43429. + va_start(args, format);
  43430. + DWC_VPRINTF(format, args);
  43431. + va_end(args);
  43432. +}
  43433. +
  43434. +int DWC_SPRINTF(char *buffer, char *format, ...)
  43435. +{
  43436. + int retval;
  43437. + va_list args;
  43438. +
  43439. + va_start(args, format);
  43440. + retval = vsprintf(buffer, format, args);
  43441. + va_end(args);
  43442. + return retval;
  43443. +}
  43444. +
  43445. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  43446. +{
  43447. + int retval;
  43448. + va_list args;
  43449. +
  43450. + va_start(args, format);
  43451. + retval = vsnprintf(buffer, size, format, args);
  43452. + va_end(args);
  43453. + return retval;
  43454. +}
  43455. +
  43456. +void __DWC_WARN(char *format, ...)
  43457. +{
  43458. + va_list args;
  43459. +
  43460. + va_start(args, format);
  43461. + DWC_VPRINTF(format, args);
  43462. + va_end(args);
  43463. +}
  43464. +
  43465. +void __DWC_ERROR(char *format, ...)
  43466. +{
  43467. + va_list args;
  43468. +
  43469. + va_start(args, format);
  43470. + DWC_VPRINTF(format, args);
  43471. + va_end(args);
  43472. +}
  43473. +
  43474. +void DWC_EXCEPTION(char *format, ...)
  43475. +{
  43476. + va_list args;
  43477. +
  43478. + va_start(args, format);
  43479. + DWC_VPRINTF(format, args);
  43480. + va_end(args);
  43481. +// BUG_ON(1); ???
  43482. +}
  43483. +
  43484. +#ifdef DEBUG
  43485. +void __DWC_DEBUG(char *format, ...)
  43486. +{
  43487. + va_list args;
  43488. +
  43489. + va_start(args, format);
  43490. + DWC_VPRINTF(format, args);
  43491. + va_end(args);
  43492. +}
  43493. +#endif
  43494. +
  43495. +
  43496. +/* dwc_mem.h */
  43497. +
  43498. +#if 0
  43499. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  43500. + uint32_t align,
  43501. + uint32_t alloc)
  43502. +{
  43503. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  43504. + size, align, alloc);
  43505. + return (dwc_pool_t *)pool;
  43506. +}
  43507. +
  43508. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  43509. +{
  43510. + dma_pool_destroy((struct dma_pool *)pool);
  43511. +}
  43512. +
  43513. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  43514. +{
  43515. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  43516. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  43517. +}
  43518. +
  43519. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  43520. +{
  43521. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  43522. + memset(..);
  43523. +}
  43524. +
  43525. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  43526. +{
  43527. + dma_pool_free(pool, vaddr, daddr);
  43528. +}
  43529. +#endif
  43530. +
  43531. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  43532. +{
  43533. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  43534. + int error;
  43535. +
  43536. + error = bus_dmamem_alloc(dma->dma_tag, size, 1, size, dma->segs,
  43537. + sizeof(dma->segs) / sizeof(dma->segs[0]),
  43538. + &dma->nsegs, BUS_DMA_NOWAIT);
  43539. + if (error) {
  43540. + printf("%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__,
  43541. + (uintmax_t)size, error);
  43542. + goto fail_0;
  43543. + }
  43544. +
  43545. + error = bus_dmamem_map(dma->dma_tag, dma->segs, dma->nsegs, size,
  43546. + (caddr_t *)&dma->dma_vaddr,
  43547. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
  43548. + if (error) {
  43549. + printf("%s: bus_dmamem_map failed: %d\n", __func__, error);
  43550. + goto fail_1;
  43551. + }
  43552. +
  43553. + error = bus_dmamap_create(dma->dma_tag, size, 1, size, 0,
  43554. + BUS_DMA_NOWAIT, &dma->dma_map);
  43555. + if (error) {
  43556. + printf("%s: bus_dmamap_create failed: %d\n", __func__, error);
  43557. + goto fail_2;
  43558. + }
  43559. +
  43560. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
  43561. + size, NULL, BUS_DMA_NOWAIT);
  43562. + if (error) {
  43563. + printf("%s: bus_dmamap_load failed: %d\n", __func__, error);
  43564. + goto fail_3;
  43565. + }
  43566. +
  43567. + dma->dma_paddr = (bus_addr_t)dma->segs[0].ds_addr;
  43568. + *dma_addr = dma->dma_paddr;
  43569. + return dma->dma_vaddr;
  43570. +
  43571. +fail_3:
  43572. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  43573. +fail_2:
  43574. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  43575. +fail_1:
  43576. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  43577. +fail_0:
  43578. + dma->dma_map = NULL;
  43579. + dma->dma_vaddr = NULL;
  43580. + dma->nsegs = 0;
  43581. +
  43582. + return NULL;
  43583. +}
  43584. +
  43585. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  43586. +{
  43587. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  43588. +
  43589. + if (dma->dma_map != NULL) {
  43590. + bus_dmamap_sync(dma->dma_tag, dma->dma_map, 0, size,
  43591. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  43592. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  43593. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  43594. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  43595. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  43596. + dma->dma_paddr = 0;
  43597. + dma->dma_map = NULL;
  43598. + dma->dma_vaddr = NULL;
  43599. + dma->nsegs = 0;
  43600. + }
  43601. +}
  43602. +
  43603. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  43604. +{
  43605. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  43606. +}
  43607. +
  43608. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  43609. +{
  43610. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  43611. +}
  43612. +
  43613. +void __DWC_FREE(void *mem_ctx, void *addr)
  43614. +{
  43615. + free(addr, M_DEVBUF);
  43616. +}
  43617. +
  43618. +
  43619. +#ifdef DWC_CRYPTOLIB
  43620. +/* dwc_crypto.h */
  43621. +
  43622. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  43623. +{
  43624. + get_random_bytes(buffer, length);
  43625. +}
  43626. +
  43627. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  43628. +{
  43629. + struct crypto_blkcipher *tfm;
  43630. + struct blkcipher_desc desc;
  43631. + struct scatterlist sgd;
  43632. + struct scatterlist sgs;
  43633. +
  43634. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  43635. + if (tfm == NULL) {
  43636. + printk("failed to load transform for aes CBC\n");
  43637. + return -1;
  43638. + }
  43639. +
  43640. + crypto_blkcipher_setkey(tfm, key, keylen);
  43641. + crypto_blkcipher_set_iv(tfm, iv, 16);
  43642. +
  43643. + sg_init_one(&sgd, out, messagelen);
  43644. + sg_init_one(&sgs, message, messagelen);
  43645. +
  43646. + desc.tfm = tfm;
  43647. + desc.flags = 0;
  43648. +
  43649. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  43650. + crypto_free_blkcipher(tfm);
  43651. + DWC_ERROR("AES CBC encryption failed");
  43652. + return -1;
  43653. + }
  43654. +
  43655. + crypto_free_blkcipher(tfm);
  43656. + return 0;
  43657. +}
  43658. +
  43659. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  43660. +{
  43661. + struct crypto_hash *tfm;
  43662. + struct hash_desc desc;
  43663. + struct scatterlist sg;
  43664. +
  43665. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  43666. + if (IS_ERR(tfm)) {
  43667. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  43668. + return 0;
  43669. + }
  43670. + desc.tfm = tfm;
  43671. + desc.flags = 0;
  43672. +
  43673. + sg_init_one(&sg, message, len);
  43674. + crypto_hash_digest(&desc, &sg, len, out);
  43675. + crypto_free_hash(tfm);
  43676. +
  43677. + return 1;
  43678. +}
  43679. +
  43680. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  43681. + uint8_t *key, uint32_t keylen, uint8_t *out)
  43682. +{
  43683. + struct crypto_hash *tfm;
  43684. + struct hash_desc desc;
  43685. + struct scatterlist sg;
  43686. +
  43687. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  43688. + if (IS_ERR(tfm)) {
  43689. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  43690. + return 0;
  43691. + }
  43692. + desc.tfm = tfm;
  43693. + desc.flags = 0;
  43694. +
  43695. + sg_init_one(&sg, message, messagelen);
  43696. + crypto_hash_setkey(tfm, key, keylen);
  43697. + crypto_hash_digest(&desc, &sg, messagelen, out);
  43698. + crypto_free_hash(tfm);
  43699. +
  43700. + return 1;
  43701. +}
  43702. +
  43703. +#endif /* DWC_CRYPTOLIB */
  43704. +
  43705. +
  43706. +/* Byte Ordering Conversions */
  43707. +
  43708. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  43709. +{
  43710. +#ifdef __LITTLE_ENDIAN
  43711. + return *p;
  43712. +#else
  43713. + uint8_t *u_p = (uint8_t *)p;
  43714. +
  43715. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43716. +#endif
  43717. +}
  43718. +
  43719. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  43720. +{
  43721. +#ifdef __BIG_ENDIAN
  43722. + return *p;
  43723. +#else
  43724. + uint8_t *u_p = (uint8_t *)p;
  43725. +
  43726. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43727. +#endif
  43728. +}
  43729. +
  43730. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  43731. +{
  43732. +#ifdef __LITTLE_ENDIAN
  43733. + return *p;
  43734. +#else
  43735. + uint8_t *u_p = (uint8_t *)p;
  43736. +
  43737. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43738. +#endif
  43739. +}
  43740. +
  43741. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  43742. +{
  43743. +#ifdef __BIG_ENDIAN
  43744. + return *p;
  43745. +#else
  43746. + uint8_t *u_p = (uint8_t *)p;
  43747. +
  43748. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43749. +#endif
  43750. +}
  43751. +
  43752. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  43753. +{
  43754. +#ifdef __LITTLE_ENDIAN
  43755. + return *p;
  43756. +#else
  43757. + uint8_t *u_p = (uint8_t *)p;
  43758. + return (u_p[1] | (u_p[0] << 8));
  43759. +#endif
  43760. +}
  43761. +
  43762. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  43763. +{
  43764. +#ifdef __BIG_ENDIAN
  43765. + return *p;
  43766. +#else
  43767. + uint8_t *u_p = (uint8_t *)p;
  43768. + return (u_p[1] | (u_p[0] << 8));
  43769. +#endif
  43770. +}
  43771. +
  43772. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  43773. +{
  43774. +#ifdef __LITTLE_ENDIAN
  43775. + return *p;
  43776. +#else
  43777. + uint8_t *u_p = (uint8_t *)p;
  43778. + return (u_p[1] | (u_p[0] << 8));
  43779. +#endif
  43780. +}
  43781. +
  43782. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  43783. +{
  43784. +#ifdef __BIG_ENDIAN
  43785. + return *p;
  43786. +#else
  43787. + uint8_t *u_p = (uint8_t *)p;
  43788. + return (u_p[1] | (u_p[0] << 8));
  43789. +#endif
  43790. +}
  43791. +
  43792. +
  43793. +/* Registers */
  43794. +
  43795. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  43796. +{
  43797. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43798. + bus_size_t ior = (bus_size_t)reg;
  43799. +
  43800. + return bus_space_read_4(io->iot, io->ioh, ior);
  43801. +}
  43802. +
  43803. +#if 0
  43804. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  43805. +{
  43806. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43807. + bus_size_t ior = (bus_size_t)reg;
  43808. +
  43809. + return bus_space_read_8(io->iot, io->ioh, ior);
  43810. +}
  43811. +#endif
  43812. +
  43813. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  43814. +{
  43815. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43816. + bus_size_t ior = (bus_size_t)reg;
  43817. +
  43818. + bus_space_write_4(io->iot, io->ioh, ior, value);
  43819. +}
  43820. +
  43821. +#if 0
  43822. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  43823. +{
  43824. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43825. + bus_size_t ior = (bus_size_t)reg;
  43826. +
  43827. + bus_space_write_8(io->iot, io->ioh, ior, value);
  43828. +}
  43829. +#endif
  43830. +
  43831. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  43832. + uint32_t set_mask)
  43833. +{
  43834. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43835. + bus_size_t ior = (bus_size_t)reg;
  43836. +
  43837. + bus_space_write_4(io->iot, io->ioh, ior,
  43838. + (bus_space_read_4(io->iot, io->ioh, ior) &
  43839. + ~clear_mask) | set_mask);
  43840. +}
  43841. +
  43842. +#if 0
  43843. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  43844. + uint64_t set_mask)
  43845. +{
  43846. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43847. + bus_size_t ior = (bus_size_t)reg;
  43848. +
  43849. + bus_space_write_8(io->iot, io->ioh, ior,
  43850. + (bus_space_read_8(io->iot, io->ioh, ior) &
  43851. + ~clear_mask) | set_mask);
  43852. +}
  43853. +#endif
  43854. +
  43855. +
  43856. +/* Locking */
  43857. +
  43858. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  43859. +{
  43860. + struct simplelock *sl = DWC_ALLOC(sizeof(*sl));
  43861. +
  43862. + if (!sl) {
  43863. + DWC_ERROR("Cannot allocate memory for spinlock");
  43864. + return NULL;
  43865. + }
  43866. +
  43867. + simple_lock_init(sl);
  43868. + return (dwc_spinlock_t *)sl;
  43869. +}
  43870. +
  43871. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  43872. +{
  43873. + struct simplelock *sl = (struct simplelock *)lock;
  43874. +
  43875. + DWC_FREE(sl);
  43876. +}
  43877. +
  43878. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  43879. +{
  43880. + simple_lock((struct simplelock *)lock);
  43881. +}
  43882. +
  43883. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  43884. +{
  43885. + simple_unlock((struct simplelock *)lock);
  43886. +}
  43887. +
  43888. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  43889. +{
  43890. + simple_lock((struct simplelock *)lock);
  43891. + *flags = splbio();
  43892. +}
  43893. +
  43894. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  43895. +{
  43896. + splx(flags);
  43897. + simple_unlock((struct simplelock *)lock);
  43898. +}
  43899. +
  43900. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  43901. +{
  43902. + dwc_mutex_t *mutex = DWC_ALLOC(sizeof(struct lock));
  43903. +
  43904. + if (!mutex) {
  43905. + DWC_ERROR("Cannot allocate memory for mutex");
  43906. + return NULL;
  43907. + }
  43908. +
  43909. + lockinit((struct lock *)mutex, 0, "dw3mtx", 0, 0);
  43910. + return mutex;
  43911. +}
  43912. +
  43913. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  43914. +#else
  43915. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  43916. +{
  43917. + DWC_FREE(mutex);
  43918. +}
  43919. +#endif
  43920. +
  43921. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  43922. +{
  43923. + lockmgr((struct lock *)mutex, LK_EXCLUSIVE, NULL);
  43924. +}
  43925. +
  43926. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  43927. +{
  43928. + int status;
  43929. +
  43930. + status = lockmgr((struct lock *)mutex, LK_EXCLUSIVE | LK_NOWAIT, NULL);
  43931. + return status == 0;
  43932. +}
  43933. +
  43934. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  43935. +{
  43936. + lockmgr((struct lock *)mutex, LK_RELEASE, NULL);
  43937. +}
  43938. +
  43939. +
  43940. +/* Timing */
  43941. +
  43942. +void DWC_UDELAY(uint32_t usecs)
  43943. +{
  43944. + DELAY(usecs);
  43945. +}
  43946. +
  43947. +void DWC_MDELAY(uint32_t msecs)
  43948. +{
  43949. + do {
  43950. + DELAY(1000);
  43951. + } while (--msecs);
  43952. +}
  43953. +
  43954. +void DWC_MSLEEP(uint32_t msecs)
  43955. +{
  43956. + struct timeval tv;
  43957. +
  43958. + tv.tv_sec = msecs / 1000;
  43959. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  43960. + tsleep(&tv, 0, "dw3slp", tvtohz(&tv));
  43961. +}
  43962. +
  43963. +uint32_t DWC_TIME(void)
  43964. +{
  43965. + struct timeval tv;
  43966. +
  43967. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  43968. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  43969. +}
  43970. +
  43971. +
  43972. +/* Timers */
  43973. +
  43974. +struct dwc_timer {
  43975. + struct callout t;
  43976. + char *name;
  43977. + dwc_spinlock_t *lock;
  43978. + dwc_timer_callback_t cb;
  43979. + void *data;
  43980. +};
  43981. +
  43982. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  43983. +{
  43984. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  43985. +
  43986. + if (!t) {
  43987. + DWC_ERROR("Cannot allocate memory for timer");
  43988. + return NULL;
  43989. + }
  43990. +
  43991. + callout_init(&t->t);
  43992. +
  43993. + t->name = DWC_STRDUP(name);
  43994. + if (!t->name) {
  43995. + DWC_ERROR("Cannot allocate memory for timer->name");
  43996. + goto no_name;
  43997. + }
  43998. +
  43999. + t->lock = DWC_SPINLOCK_ALLOC();
  44000. + if (!t->lock) {
  44001. + DWC_ERROR("Cannot allocate memory for timer->lock");
  44002. + goto no_lock;
  44003. + }
  44004. +
  44005. + t->cb = cb;
  44006. + t->data = data;
  44007. +
  44008. + return t;
  44009. +
  44010. + no_lock:
  44011. + DWC_FREE(t->name);
  44012. + no_name:
  44013. + DWC_FREE(t);
  44014. +
  44015. + return NULL;
  44016. +}
  44017. +
  44018. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  44019. +{
  44020. + callout_stop(&timer->t);
  44021. + DWC_SPINLOCK_FREE(timer->lock);
  44022. + DWC_FREE(timer->name);
  44023. + DWC_FREE(timer);
  44024. +}
  44025. +
  44026. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  44027. +{
  44028. + struct timeval tv;
  44029. +
  44030. + tv.tv_sec = time / 1000;
  44031. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  44032. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  44033. +}
  44034. +
  44035. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  44036. +{
  44037. + callout_stop(&timer->t);
  44038. +}
  44039. +
  44040. +
  44041. +/* Wait Queues */
  44042. +
  44043. +struct dwc_waitq {
  44044. + struct simplelock lock;
  44045. + int abort;
  44046. +};
  44047. +
  44048. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  44049. +{
  44050. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  44051. +
  44052. + if (!wq) {
  44053. + DWC_ERROR("Cannot allocate memory for waitqueue");
  44054. + return NULL;
  44055. + }
  44056. +
  44057. + simple_lock_init(&wq->lock);
  44058. + wq->abort = 0;
  44059. +
  44060. + return wq;
  44061. +}
  44062. +
  44063. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  44064. +{
  44065. + DWC_FREE(wq);
  44066. +}
  44067. +
  44068. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  44069. +{
  44070. + int ipl;
  44071. + int result = 0;
  44072. +
  44073. + simple_lock(&wq->lock);
  44074. + ipl = splbio();
  44075. +
  44076. + /* Skip the sleep if already aborted or triggered */
  44077. + if (!wq->abort && !cond(data)) {
  44078. + splx(ipl);
  44079. + result = ltsleep(wq, PCATCH, "dw3wat", 0, &wq->lock); // infinite timeout
  44080. + ipl = splbio();
  44081. + }
  44082. +
  44083. + if (result == 0) { // awoken
  44084. + if (wq->abort) {
  44085. + wq->abort = 0;
  44086. + result = -DWC_E_ABORT;
  44087. + } else {
  44088. + result = 0;
  44089. + }
  44090. +
  44091. + splx(ipl);
  44092. + simple_unlock(&wq->lock);
  44093. + } else {
  44094. + wq->abort = 0;
  44095. + splx(ipl);
  44096. + simple_unlock(&wq->lock);
  44097. +
  44098. + if (result == ERESTART) { // signaled - restart
  44099. + result = -DWC_E_RESTART;
  44100. + } else { // signaled - must be EINTR
  44101. + result = -DWC_E_ABORT;
  44102. + }
  44103. + }
  44104. +
  44105. + return result;
  44106. +}
  44107. +
  44108. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  44109. + void *data, int32_t msecs)
  44110. +{
  44111. + struct timeval tv, tv1, tv2;
  44112. + int ipl;
  44113. + int result = 0;
  44114. +
  44115. + tv.tv_sec = msecs / 1000;
  44116. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  44117. +
  44118. + simple_lock(&wq->lock);
  44119. + ipl = splbio();
  44120. +
  44121. + /* Skip the sleep if already aborted or triggered */
  44122. + if (!wq->abort && !cond(data)) {
  44123. + splx(ipl);
  44124. + getmicrouptime(&tv1);
  44125. + result = ltsleep(wq, PCATCH, "dw3wto", tvtohz(&tv), &wq->lock);
  44126. + getmicrouptime(&tv2);
  44127. + ipl = splbio();
  44128. + }
  44129. +
  44130. + if (result == 0) { // awoken
  44131. + if (wq->abort) {
  44132. + wq->abort = 0;
  44133. + splx(ipl);
  44134. + simple_unlock(&wq->lock);
  44135. + result = -DWC_E_ABORT;
  44136. + } else {
  44137. + splx(ipl);
  44138. + simple_unlock(&wq->lock);
  44139. +
  44140. + tv2.tv_usec -= tv1.tv_usec;
  44141. + if (tv2.tv_usec < 0) {
  44142. + tv2.tv_usec += 1000000;
  44143. + tv2.tv_sec--;
  44144. + }
  44145. +
  44146. + tv2.tv_sec -= tv1.tv_sec;
  44147. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  44148. + result = msecs - result;
  44149. + if (result <= 0)
  44150. + result = 1;
  44151. + }
  44152. + } else {
  44153. + wq->abort = 0;
  44154. + splx(ipl);
  44155. + simple_unlock(&wq->lock);
  44156. +
  44157. + if (result == ERESTART) { // signaled - restart
  44158. + result = -DWC_E_RESTART;
  44159. +
  44160. + } else if (result == EINTR) { // signaled - interrupt
  44161. + result = -DWC_E_ABORT;
  44162. +
  44163. + } else { // timed out
  44164. + result = -DWC_E_TIMEOUT;
  44165. + }
  44166. + }
  44167. +
  44168. + return result;
  44169. +}
  44170. +
  44171. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  44172. +{
  44173. + wakeup(wq);
  44174. +}
  44175. +
  44176. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  44177. +{
  44178. + int ipl;
  44179. +
  44180. + simple_lock(&wq->lock);
  44181. + ipl = splbio();
  44182. + wq->abort = 1;
  44183. + wakeup(wq);
  44184. + splx(ipl);
  44185. + simple_unlock(&wq->lock);
  44186. +}
  44187. +
  44188. +
  44189. +/* Threading */
  44190. +
  44191. +struct dwc_thread {
  44192. + struct proc *proc;
  44193. + int abort;
  44194. +};
  44195. +
  44196. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  44197. +{
  44198. + int retval;
  44199. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  44200. +
  44201. + if (!thread) {
  44202. + return NULL;
  44203. + }
  44204. +
  44205. + thread->abort = 0;
  44206. + retval = kthread_create1((void (*)(void *))func, data, &thread->proc,
  44207. + "%s", name);
  44208. + if (retval) {
  44209. + DWC_FREE(thread);
  44210. + return NULL;
  44211. + }
  44212. +
  44213. + return thread;
  44214. +}
  44215. +
  44216. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  44217. +{
  44218. + int retval;
  44219. +
  44220. + thread->abort = 1;
  44221. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  44222. +
  44223. + if (retval == 0) {
  44224. + /* DWC_THREAD_EXIT() will free the thread struct */
  44225. + return 0;
  44226. + }
  44227. +
  44228. + /* NOTE: We leak the thread struct if thread doesn't die */
  44229. +
  44230. + if (retval == EWOULDBLOCK) {
  44231. + return -DWC_E_TIMEOUT;
  44232. + }
  44233. +
  44234. + return -DWC_E_UNKNOWN;
  44235. +}
  44236. +
  44237. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  44238. +{
  44239. + return thread->abort;
  44240. +}
  44241. +
  44242. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  44243. +{
  44244. + wakeup(&thread->abort);
  44245. + DWC_FREE(thread);
  44246. + kthread_exit(0);
  44247. +}
  44248. +
  44249. +/* tasklets
  44250. + - Runs in interrupt context (cannot sleep)
  44251. + - Each tasklet runs on a single CPU
  44252. + - Different tasklets can be running simultaneously on different CPUs
  44253. + [ On NetBSD there is no corresponding mechanism, drivers don't have bottom-
  44254. + halves. So we just call the callback directly from DWC_TASK_SCHEDULE() ]
  44255. + */
  44256. +struct dwc_tasklet {
  44257. + dwc_tasklet_callback_t cb;
  44258. + void *data;
  44259. +};
  44260. +
  44261. +static void tasklet_callback(void *data)
  44262. +{
  44263. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  44264. +
  44265. + task->cb(task->data);
  44266. +}
  44267. +
  44268. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  44269. +{
  44270. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  44271. +
  44272. + if (task) {
  44273. + task->cb = cb;
  44274. + task->data = data;
  44275. + } else {
  44276. + DWC_ERROR("Cannot allocate memory for tasklet");
  44277. + }
  44278. +
  44279. + return task;
  44280. +}
  44281. +
  44282. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  44283. +{
  44284. + DWC_FREE(task);
  44285. +}
  44286. +
  44287. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  44288. +{
  44289. + tasklet_callback(task);
  44290. +}
  44291. +
  44292. +
  44293. +/* workqueues
  44294. + - Runs in process context (can sleep)
  44295. + */
  44296. +typedef struct work_container {
  44297. + dwc_work_callback_t cb;
  44298. + void *data;
  44299. + dwc_workq_t *wq;
  44300. + char *name;
  44301. + int hz;
  44302. + struct work task;
  44303. +} work_container_t;
  44304. +
  44305. +struct dwc_workq {
  44306. + struct workqueue *taskq;
  44307. + dwc_spinlock_t *lock;
  44308. + dwc_waitq_t *waitq;
  44309. + int pending;
  44310. + struct work_container *container;
  44311. +};
  44312. +
  44313. +static void do_work(struct work *task, void *data)
  44314. +{
  44315. + dwc_workq_t *wq = (dwc_workq_t *)data;
  44316. + work_container_t *container = wq->container;
  44317. + dwc_irqflags_t flags;
  44318. +
  44319. + if (container->hz) {
  44320. + tsleep(container, 0, "dw3wrk", container->hz);
  44321. + }
  44322. +
  44323. + container->cb(container->data);
  44324. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  44325. +
  44326. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  44327. + if (container->name)
  44328. + DWC_FREE(container->name);
  44329. + DWC_FREE(container);
  44330. + wq->pending--;
  44331. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  44332. + DWC_WAITQ_TRIGGER(wq->waitq);
  44333. +}
  44334. +
  44335. +static int work_done(void *data)
  44336. +{
  44337. + dwc_workq_t *workq = (dwc_workq_t *)data;
  44338. +
  44339. + return workq->pending == 0;
  44340. +}
  44341. +
  44342. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  44343. +{
  44344. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  44345. +}
  44346. +
  44347. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  44348. +{
  44349. + int result;
  44350. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  44351. +
  44352. + if (!wq) {
  44353. + DWC_ERROR("Cannot allocate memory for workqueue");
  44354. + return NULL;
  44355. + }
  44356. +
  44357. + result = workqueue_create(&wq->taskq, name, do_work, wq, 0 /*PWAIT*/,
  44358. + IPL_BIO, 0);
  44359. + if (result) {
  44360. + DWC_ERROR("Cannot create workqueue");
  44361. + goto no_taskq;
  44362. + }
  44363. +
  44364. + wq->pending = 0;
  44365. +
  44366. + wq->lock = DWC_SPINLOCK_ALLOC();
  44367. + if (!wq->lock) {
  44368. + DWC_ERROR("Cannot allocate memory for spinlock");
  44369. + goto no_lock;
  44370. + }
  44371. +
  44372. + wq->waitq = DWC_WAITQ_ALLOC();
  44373. + if (!wq->waitq) {
  44374. + DWC_ERROR("Cannot allocate memory for waitqueue");
  44375. + goto no_waitq;
  44376. + }
  44377. +
  44378. + return wq;
  44379. +
  44380. + no_waitq:
  44381. + DWC_SPINLOCK_FREE(wq->lock);
  44382. + no_lock:
  44383. + workqueue_destroy(wq->taskq);
  44384. + no_taskq:
  44385. + DWC_FREE(wq);
  44386. +
  44387. + return NULL;
  44388. +}
  44389. +
  44390. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  44391. +{
  44392. +#ifdef DEBUG
  44393. + dwc_irqflags_t flags;
  44394. +
  44395. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  44396. +
  44397. + if (wq->pending != 0) {
  44398. + struct work_container *container = wq->container;
  44399. +
  44400. + DWC_ERROR("Destroying work queue with pending work");
  44401. +
  44402. + if (container && container->name) {
  44403. + DWC_ERROR("Work %s still pending", container->name);
  44404. + }
  44405. + }
  44406. +
  44407. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  44408. +#endif
  44409. + DWC_WAITQ_FREE(wq->waitq);
  44410. + DWC_SPINLOCK_FREE(wq->lock);
  44411. + workqueue_destroy(wq->taskq);
  44412. + DWC_FREE(wq);
  44413. +}
  44414. +
  44415. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  44416. + char *format, ...)
  44417. +{
  44418. + dwc_irqflags_t flags;
  44419. + work_container_t *container;
  44420. + static char name[128];
  44421. + va_list args;
  44422. +
  44423. + va_start(args, format);
  44424. + DWC_VSNPRINTF(name, 128, format, args);
  44425. + va_end(args);
  44426. +
  44427. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  44428. + wq->pending++;
  44429. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  44430. + DWC_WAITQ_TRIGGER(wq->waitq);
  44431. +
  44432. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  44433. + if (!container) {
  44434. + DWC_ERROR("Cannot allocate memory for container");
  44435. + return;
  44436. + }
  44437. +
  44438. + container->name = DWC_STRDUP(name);
  44439. + if (!container->name) {
  44440. + DWC_ERROR("Cannot allocate memory for container->name");
  44441. + DWC_FREE(container);
  44442. + return;
  44443. + }
  44444. +
  44445. + container->cb = cb;
  44446. + container->data = data;
  44447. + container->wq = wq;
  44448. + container->hz = 0;
  44449. + wq->container = container;
  44450. +
  44451. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  44452. + workqueue_enqueue(wq->taskq, &container->task);
  44453. +}
  44454. +
  44455. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  44456. + void *data, uint32_t time, char *format, ...)
  44457. +{
  44458. + dwc_irqflags_t flags;
  44459. + work_container_t *container;
  44460. + static char name[128];
  44461. + struct timeval tv;
  44462. + va_list args;
  44463. +
  44464. + va_start(args, format);
  44465. + DWC_VSNPRINTF(name, 128, format, args);
  44466. + va_end(args);
  44467. +
  44468. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  44469. + wq->pending++;
  44470. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  44471. + DWC_WAITQ_TRIGGER(wq->waitq);
  44472. +
  44473. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  44474. + if (!container) {
  44475. + DWC_ERROR("Cannot allocate memory for container");
  44476. + return;
  44477. + }
  44478. +
  44479. + container->name = DWC_STRDUP(name);
  44480. + if (!container->name) {
  44481. + DWC_ERROR("Cannot allocate memory for container->name");
  44482. + DWC_FREE(container);
  44483. + return;
  44484. + }
  44485. +
  44486. + container->cb = cb;
  44487. + container->data = data;
  44488. + container->wq = wq;
  44489. + tv.tv_sec = time / 1000;
  44490. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  44491. + container->hz = tvtohz(&tv);
  44492. + wq->container = container;
  44493. +
  44494. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  44495. + workqueue_enqueue(wq->taskq, &container->task);
  44496. +}
  44497. +
  44498. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  44499. +{
  44500. + return wq->pending;
  44501. +}
  44502. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_crypto.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c
  44503. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_crypto.c 1970-01-01 01:00:00.000000000 +0100
  44504. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c 2014-04-24 15:35:04.169565731 +0200
  44505. @@ -0,0 +1,308 @@
  44506. +/* =========================================================================
  44507. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.c $
  44508. + * $Revision: #5 $
  44509. + * $Date: 2010/09/28 $
  44510. + * $Change: 1596182 $
  44511. + *
  44512. + * Synopsys Portability Library Software and documentation
  44513. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44514. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44515. + * between Synopsys and you.
  44516. + *
  44517. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44518. + * under any End User Software License Agreement or Agreement for
  44519. + * Licensed Product with Synopsys or any supplement thereto. You are
  44520. + * permitted to use and redistribute this Software in source and binary
  44521. + * forms, with or without modification, provided that redistributions
  44522. + * of source code must retain this notice. You may not view, use,
  44523. + * disclose, copy or distribute this file or any information contained
  44524. + * herein except pursuant to this license grant from Synopsys. If you
  44525. + * do not agree with this notice, including the disclaimer below, then
  44526. + * you are not authorized to use the Software.
  44527. + *
  44528. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44529. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44530. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44531. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44532. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44533. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44534. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44535. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44536. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44537. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44538. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44539. + * DAMAGE.
  44540. + * ========================================================================= */
  44541. +
  44542. +/** @file
  44543. + * This file contains the WUSB cryptographic routines.
  44544. + */
  44545. +
  44546. +#ifdef DWC_CRYPTOLIB
  44547. +
  44548. +#include "dwc_crypto.h"
  44549. +#include "usb.h"
  44550. +
  44551. +#ifdef DEBUG
  44552. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  44553. +{
  44554. + int i;
  44555. + DWC_PRINTF("%s: ", name);
  44556. + for (i=0; i<len; i++) {
  44557. + DWC_PRINTF("%02x ", bytes[i]);
  44558. + }
  44559. + DWC_PRINTF("\n");
  44560. +}
  44561. +#else
  44562. +#define dump_bytes(x...)
  44563. +#endif
  44564. +
  44565. +/* Display a block */
  44566. +void show_block(const u8 *blk, const char *prefix, const char *suffix, int a)
  44567. +{
  44568. +#ifdef DWC_DEBUG_CRYPTO
  44569. + int i, blksize = 16;
  44570. +
  44571. + DWC_DEBUG("%s", prefix);
  44572. +
  44573. + if (suffix == NULL) {
  44574. + suffix = "\n";
  44575. + blksize = a;
  44576. + }
  44577. +
  44578. + for (i = 0; i < blksize; i++)
  44579. + DWC_PRINT("%02x%s", *blk++, ((i & 3) == 3) ? " " : " ");
  44580. + DWC_PRINT(suffix);
  44581. +#endif
  44582. +}
  44583. +
  44584. +/**
  44585. + * Encrypts an array of bytes using the AES encryption engine.
  44586. + * If <code>dst</code> == <code>src</code>, then the bytes will be encrypted
  44587. + * in-place.
  44588. + *
  44589. + * @return 0 on success, negative error code on error.
  44590. + */
  44591. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst)
  44592. +{
  44593. + u8 block_t[16];
  44594. + DWC_MEMSET(block_t, 0, 16);
  44595. +
  44596. + return DWC_AES_CBC(src, 16, key, 16, block_t, dst);
  44597. +}
  44598. +
  44599. +/**
  44600. + * The CCM-MAC-FUNCTION described in section 6.5 of the WUSB spec.
  44601. + * This function takes a data string and returns the encrypted CBC
  44602. + * Counter-mode MIC.
  44603. + *
  44604. + * @param key The 128-bit symmetric key.
  44605. + * @param nonce The CCM nonce.
  44606. + * @param label The unique 14-byte ASCII text label.
  44607. + * @param bytes The byte array to be encrypted.
  44608. + * @param len Length of the byte array.
  44609. + * @param result Byte array to receive the 8-byte encrypted MIC.
  44610. + */
  44611. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  44612. + char *label, u8 *bytes, int len, u8 *result)
  44613. +{
  44614. + u8 block_m[16];
  44615. + u8 block_x[16];
  44616. + u8 block_t[8];
  44617. + int idx, blkNum;
  44618. + u16 la = (u16)(len + 14);
  44619. +
  44620. + /* Set the AES-128 key */
  44621. + //dwc_aes_setkey(tfm, key, 16);
  44622. +
  44623. + /* Fill block B0 from flags = 0x59, N, and l(m) = 0 */
  44624. + block_m[0] = 0x59;
  44625. + for (idx = 0; idx < 13; idx++)
  44626. + block_m[idx + 1] = nonce[idx];
  44627. + block_m[14] = 0;
  44628. + block_m[15] = 0;
  44629. +
  44630. + /* Produce the CBC IV */
  44631. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  44632. + show_block(block_m, "CBC IV in: ", "\n", 0);
  44633. + show_block(block_x, "CBC IV out:", "\n", 0);
  44634. +
  44635. + /* Fill block B1 from l(a) = Blen + 14, and A */
  44636. + block_x[0] ^= (u8)(la >> 8);
  44637. + block_x[1] ^= (u8)la;
  44638. + for (idx = 0; idx < 14; idx++)
  44639. + block_x[idx + 2] ^= label[idx];
  44640. + show_block(block_x, "After xor: ", "b1\n", 16);
  44641. +
  44642. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  44643. + show_block(block_x, "After AES: ", "b1\n", 16);
  44644. +
  44645. + idx = 0;
  44646. + blkNum = 0;
  44647. +
  44648. + /* Fill remaining blocks with B */
  44649. + while (len-- > 0) {
  44650. + block_x[idx] ^= *bytes++;
  44651. + if (++idx >= 16) {
  44652. + idx = 0;
  44653. + show_block(block_x, "After xor: ", "\n", blkNum);
  44654. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  44655. + show_block(block_x, "After AES: ", "\n", blkNum);
  44656. + blkNum++;
  44657. + }
  44658. + }
  44659. +
  44660. + /* Handle partial last block */
  44661. + if (idx > 0) {
  44662. + show_block(block_x, "After xor: ", "\n", blkNum);
  44663. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  44664. + show_block(block_x, "After AES: ", "\n", blkNum);
  44665. + }
  44666. +
  44667. + /* Save the MIC tag */
  44668. + DWC_MEMCPY(block_t, block_x, 8);
  44669. + show_block(block_t, "MIC tag : ", NULL, 8);
  44670. +
  44671. + /* Fill block A0 from flags = 0x01, N, and counter = 0 */
  44672. + block_m[0] = 0x01;
  44673. + block_m[14] = 0;
  44674. + block_m[15] = 0;
  44675. +
  44676. + /* Encrypt the counter */
  44677. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  44678. + show_block(block_x, "CTR[MIC] : ", NULL, 8);
  44679. +
  44680. + /* XOR with MIC tag */
  44681. + for (idx = 0; idx < 8; idx++) {
  44682. + block_t[idx] ^= block_x[idx];
  44683. + }
  44684. +
  44685. + /* Return result to caller */
  44686. + DWC_MEMCPY(result, block_t, 8);
  44687. + show_block(result, "CCM-MIC : ", NULL, 8);
  44688. +
  44689. +}
  44690. +
  44691. +/**
  44692. + * The PRF function described in section 6.5 of the WUSB spec. This function
  44693. + * concatenates MIC values returned from dwc_cmf() to create a value of
  44694. + * the requested length.
  44695. + *
  44696. + * @param prf_len Length of the PRF function in bits (64, 128, or 256).
  44697. + * @param key, nonce, label, bytes, len Same as for dwc_cmf().
  44698. + * @param result Byte array to receive the result.
  44699. + */
  44700. +void dwc_wusb_prf(int prf_len, u8 *key,
  44701. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result)
  44702. +{
  44703. + int i;
  44704. +
  44705. + nonce[0] = 0;
  44706. + for (i = 0; i < prf_len >> 6; i++, nonce[0]++) {
  44707. + dwc_wusb_cmf(key, nonce, label, bytes, len, result);
  44708. + result += 8;
  44709. + }
  44710. +}
  44711. +
  44712. +/**
  44713. + * Fills in CCM Nonce per the WUSB spec.
  44714. + *
  44715. + * @param[in] haddr Host address.
  44716. + * @param[in] daddr Device address.
  44717. + * @param[in] tkid Session Key(PTK) identifier.
  44718. + * @param[out] nonce Pointer to where the CCM Nonce output is to be written.
  44719. + */
  44720. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  44721. + uint8_t *nonce)
  44722. +{
  44723. +
  44724. + DWC_DEBUG("%s %x %x\n", __func__, daddr, haddr);
  44725. +
  44726. + DWC_MEMSET(&nonce[0], 0, 16);
  44727. +
  44728. + DWC_MEMCPY(&nonce[6], tkid, 3);
  44729. + nonce[9] = daddr & 0xFF;
  44730. + nonce[10] = (daddr >> 8) & 0xFF;
  44731. + nonce[11] = haddr & 0xFF;
  44732. + nonce[12] = (haddr >> 8) & 0xFF;
  44733. +
  44734. + dump_bytes("CCM nonce", nonce, 16);
  44735. +}
  44736. +
  44737. +/**
  44738. + * Generates a 16-byte cryptographic-grade random number for the Host/Device
  44739. + * Nonce.
  44740. + */
  44741. +void dwc_wusb_gen_nonce(uint16_t addr, uint8_t *nonce)
  44742. +{
  44743. + uint8_t inonce[16];
  44744. + uint32_t temp[4];
  44745. +
  44746. + /* Fill in the Nonce */
  44747. + DWC_MEMSET(&inonce[0], 0, sizeof(inonce));
  44748. + inonce[9] = addr & 0xFF;
  44749. + inonce[10] = (addr >> 8) & 0xFF;
  44750. + inonce[11] = inonce[9];
  44751. + inonce[12] = inonce[10];
  44752. +
  44753. + /* Collect "randomness samples" */
  44754. + DWC_RANDOM_BYTES((uint8_t *)temp, 16);
  44755. +
  44756. + dwc_wusb_prf_128((uint8_t *)temp, nonce,
  44757. + "Random Numbers", (uint8_t *)temp, sizeof(temp),
  44758. + nonce);
  44759. +}
  44760. +
  44761. +/**
  44762. + * Generates the Session Key (PTK) and Key Confirmation Key (KCK) per the
  44763. + * WUSB spec.
  44764. + *
  44765. + * @param[in] ccm_nonce Pointer to CCM Nonce.
  44766. + * @param[in] mk Master Key to derive the session from
  44767. + * @param[in] hnonce Pointer to Host Nonce.
  44768. + * @param[in] dnonce Pointer to Device Nonce.
  44769. + * @param[out] kck Pointer to where the KCK output is to be written.
  44770. + * @param[out] ptk Pointer to where the PTK output is to be written.
  44771. + */
  44772. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk, uint8_t *hnonce,
  44773. + uint8_t *dnonce, uint8_t *kck, uint8_t *ptk)
  44774. +{
  44775. + uint8_t idata[32];
  44776. + uint8_t odata[32];
  44777. +
  44778. + dump_bytes("ck", mk, 16);
  44779. + dump_bytes("hnonce", hnonce, 16);
  44780. + dump_bytes("dnonce", dnonce, 16);
  44781. +
  44782. + /* The data is the HNonce and DNonce concatenated */
  44783. + DWC_MEMCPY(&idata[0], hnonce, 16);
  44784. + DWC_MEMCPY(&idata[16], dnonce, 16);
  44785. +
  44786. + dwc_wusb_prf_256(mk, ccm_nonce, "Pair-wise keys", idata, 32, odata);
  44787. +
  44788. + /* Low 16 bytes of the result is the KCK, high 16 is the PTK */
  44789. + DWC_MEMCPY(kck, &odata[0], 16);
  44790. + DWC_MEMCPY(ptk, &odata[16], 16);
  44791. +
  44792. + dump_bytes("kck", kck, 16);
  44793. + dump_bytes("ptk", ptk, 16);
  44794. +}
  44795. +
  44796. +/**
  44797. + * Generates the Message Integrity Code over the Handshake data per the
  44798. + * WUSB spec.
  44799. + *
  44800. + * @param ccm_nonce Pointer to CCM Nonce.
  44801. + * @param kck Pointer to Key Confirmation Key.
  44802. + * @param data Pointer to Handshake data to be checked.
  44803. + * @param mic Pointer to where the MIC output is to be written.
  44804. + */
  44805. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t *kck,
  44806. + uint8_t *data, uint8_t *mic)
  44807. +{
  44808. +
  44809. + dwc_wusb_prf_64(kck, ccm_nonce, "out-of-bandMIC",
  44810. + data, WUSB_HANDSHAKE_LEN_FOR_MIC, mic);
  44811. +}
  44812. +
  44813. +#endif /* DWC_CRYPTOLIB */
  44814. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_crypto.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h
  44815. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_crypto.h 1970-01-01 01:00:00.000000000 +0100
  44816. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h 2014-04-24 15:35:04.169565731 +0200
  44817. @@ -0,0 +1,111 @@
  44818. +/* =========================================================================
  44819. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.h $
  44820. + * $Revision: #3 $
  44821. + * $Date: 2010/09/28 $
  44822. + * $Change: 1596182 $
  44823. + *
  44824. + * Synopsys Portability Library Software and documentation
  44825. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44826. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44827. + * between Synopsys and you.
  44828. + *
  44829. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44830. + * under any End User Software License Agreement or Agreement for
  44831. + * Licensed Product with Synopsys or any supplement thereto. You are
  44832. + * permitted to use and redistribute this Software in source and binary
  44833. + * forms, with or without modification, provided that redistributions
  44834. + * of source code must retain this notice. You may not view, use,
  44835. + * disclose, copy or distribute this file or any information contained
  44836. + * herein except pursuant to this license grant from Synopsys. If you
  44837. + * do not agree with this notice, including the disclaimer below, then
  44838. + * you are not authorized to use the Software.
  44839. + *
  44840. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44841. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44842. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44843. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44844. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44845. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44846. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44847. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44848. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44849. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44850. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44851. + * DAMAGE.
  44852. + * ========================================================================= */
  44853. +
  44854. +#ifndef _DWC_CRYPTO_H_
  44855. +#define _DWC_CRYPTO_H_
  44856. +
  44857. +#ifdef __cplusplus
  44858. +extern "C" {
  44859. +#endif
  44860. +
  44861. +/** @file
  44862. + *
  44863. + * This file contains declarations for the WUSB Cryptographic routines as
  44864. + * defined in the WUSB spec. They are only to be used internally by the DWC UWB
  44865. + * modules.
  44866. + */
  44867. +
  44868. +#include "dwc_os.h"
  44869. +
  44870. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst);
  44871. +
  44872. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  44873. + char *label, u8 *bytes, int len, u8 *result);
  44874. +void dwc_wusb_prf(int prf_len, u8 *key,
  44875. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result);
  44876. +
  44877. +/**
  44878. + * The PRF-64 function described in section 6.5 of the WUSB spec.
  44879. + *
  44880. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  44881. + */
  44882. +static inline void dwc_wusb_prf_64(u8 *key, u8 *nonce,
  44883. + char *label, u8 *bytes, int len, u8 *result)
  44884. +{
  44885. + dwc_wusb_prf(64, key, nonce, label, bytes, len, result);
  44886. +}
  44887. +
  44888. +/**
  44889. + * The PRF-128 function described in section 6.5 of the WUSB spec.
  44890. + *
  44891. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  44892. + */
  44893. +static inline void dwc_wusb_prf_128(u8 *key, u8 *nonce,
  44894. + char *label, u8 *bytes, int len, u8 *result)
  44895. +{
  44896. + dwc_wusb_prf(128, key, nonce, label, bytes, len, result);
  44897. +}
  44898. +
  44899. +/**
  44900. + * The PRF-256 function described in section 6.5 of the WUSB spec.
  44901. + *
  44902. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  44903. + */
  44904. +static inline void dwc_wusb_prf_256(u8 *key, u8 *nonce,
  44905. + char *label, u8 *bytes, int len, u8 *result)
  44906. +{
  44907. + dwc_wusb_prf(256, key, nonce, label, bytes, len, result);
  44908. +}
  44909. +
  44910. +
  44911. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  44912. + uint8_t *nonce);
  44913. +void dwc_wusb_gen_nonce(uint16_t addr,
  44914. + uint8_t *nonce);
  44915. +
  44916. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk,
  44917. + uint8_t *hnonce, uint8_t *dnonce,
  44918. + uint8_t *kck, uint8_t *ptk);
  44919. +
  44920. +
  44921. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t
  44922. + *kck, uint8_t *data, uint8_t *mic);
  44923. +
  44924. +#ifdef __cplusplus
  44925. +}
  44926. +#endif
  44927. +
  44928. +#endif /* _DWC_CRYPTO_H_ */
  44929. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_dh.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c
  44930. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_dh.c 1970-01-01 01:00:00.000000000 +0100
  44931. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c 2014-04-24 16:04:39.811124176 +0200
  44932. @@ -0,0 +1,291 @@
  44933. +/* =========================================================================
  44934. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.c $
  44935. + * $Revision: #3 $
  44936. + * $Date: 2010/09/28 $
  44937. + * $Change: 1596182 $
  44938. + *
  44939. + * Synopsys Portability Library Software and documentation
  44940. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44941. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44942. + * between Synopsys and you.
  44943. + *
  44944. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44945. + * under any End User Software License Agreement or Agreement for
  44946. + * Licensed Product with Synopsys or any supplement thereto. You are
  44947. + * permitted to use and redistribute this Software in source and binary
  44948. + * forms, with or without modification, provided that redistributions
  44949. + * of source code must retain this notice. You may not view, use,
  44950. + * disclose, copy or distribute this file or any information contained
  44951. + * herein except pursuant to this license grant from Synopsys. If you
  44952. + * do not agree with this notice, including the disclaimer below, then
  44953. + * you are not authorized to use the Software.
  44954. + *
  44955. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44956. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44957. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44958. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44959. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44960. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44961. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44962. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44963. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44964. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44965. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44966. + * DAMAGE.
  44967. + * ========================================================================= */
  44968. +#ifdef DWC_CRYPTOLIB
  44969. +
  44970. +#ifndef CONFIG_MACH_IPMATE
  44971. +
  44972. +#include "dwc_dh.h"
  44973. +#include "dwc_modpow.h"
  44974. +
  44975. +#ifdef DEBUG
  44976. +/* This function prints out a buffer in the format described in the Association
  44977. + * Model specification. */
  44978. +static void dh_dump(char *str, void *_num, int len)
  44979. +{
  44980. + uint8_t *num = _num;
  44981. + int i;
  44982. + DWC_PRINTF("%s\n", str);
  44983. + for (i = 0; i < len; i ++) {
  44984. + DWC_PRINTF("%02x", num[i]);
  44985. + if (((i + 1) % 2) == 0) DWC_PRINTF(" ");
  44986. + if (((i + 1) % 26) == 0) DWC_PRINTF("\n");
  44987. + }
  44988. +
  44989. + DWC_PRINTF("\n");
  44990. +}
  44991. +#else
  44992. +#define dh_dump(_x...) do {; } while(0)
  44993. +#endif
  44994. +
  44995. +/* Constant g value */
  44996. +static __u32 dh_g[] = {
  44997. + 0x02000000,
  44998. +};
  44999. +
  45000. +/* Constant p value */
  45001. +static __u32 dh_p[] = {
  45002. + 0xFFFFFFFF, 0xFFFFFFFF, 0xA2DA0FC9, 0x34C26821, 0x8B62C6C4, 0xD11CDC80, 0x084E0229, 0x74CC678A,
  45003. + 0xA6BE0B02, 0x229B133B, 0x79084A51, 0xDD04348E, 0xB31995EF, 0x1B433ACD, 0x6D0A2B30, 0x37145FF2,
  45004. + 0x6D35E14F, 0x45C2516D, 0x76B585E4, 0xC67E5E62, 0xE9424CF4, 0x6BED37A6, 0xB65CFF0B, 0xEDB706F4,
  45005. + 0xFB6B38EE, 0xA59F895A, 0x11249FAE, 0xE61F4B7C, 0x51662849, 0x3D5BE4EC, 0xB87C00C2, 0x05BF63A1,
  45006. + 0x3648DA98, 0x9AD3551C, 0xA83F1669, 0x5FCF24FD, 0x235D6583, 0x96ADA3DC, 0x56F3621C, 0xBB528520,
  45007. + 0x0729D59E, 0x6D969670, 0x4E350C67, 0x0498BC4A, 0x086C74F1, 0x7C2118CA, 0x465E9032, 0x3BCE362E,
  45008. + 0x2C779EE3, 0x03860E18, 0xA283279B, 0x8FA207EC, 0xF05DC5B5, 0xC9524C6F, 0xF6CB2BDE, 0x18175895,
  45009. + 0x7C499539, 0xE56A95EA, 0x1826D215, 0x1005FA98, 0x5A8E7215, 0x2DC4AA8A, 0x0D1733AD, 0x337A5004,
  45010. + 0xAB2155A8, 0x64BA1CDF, 0x0485FBEC, 0x0AEFDB58, 0x5771EA8A, 0x7D0C065D, 0x850F97B3, 0xC7E4E1A6,
  45011. + 0x8CAEF5AB, 0xD73309DB, 0xE0948C1E, 0x9D61254A, 0x26D2E3CE, 0x6BEED21A, 0x06FA2FF1, 0x64088AD9,
  45012. + 0x730276D8, 0x646AC83E, 0x182B1F52, 0x0C207B17, 0x5717E1BB, 0x6C5D617A, 0xC0880977, 0xE246D9BA,
  45013. + 0xA04FE208, 0x31ABE574, 0xFC5BDB43, 0x8E10FDE0, 0x20D1824B, 0xCAD23AA9, 0xFFFFFFFF, 0xFFFFFFFF,
  45014. +};
  45015. +
  45016. +static void dh_swap_bytes(void *_in, void *_out, uint32_t len)
  45017. +{
  45018. + uint8_t *in = _in;
  45019. + uint8_t *out = _out;
  45020. + int i;
  45021. + for (i=0; i<len; i++) {
  45022. + out[i] = in[len-1-i];
  45023. + }
  45024. +}
  45025. +
  45026. +/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are
  45027. + * big endian numbers of size len, in bytes. Each len value must be a multiple
  45028. + * of 4. */
  45029. +int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  45030. + void *exp, uint32_t exp_len,
  45031. + void *mod, uint32_t mod_len,
  45032. + void *out)
  45033. +{
  45034. + /* modpow() takes little endian numbers. AM uses big-endian. This
  45035. + * function swaps bytes of numbers before passing onto modpow. */
  45036. +
  45037. + int retval = 0;
  45038. + uint32_t *result;
  45039. +
  45040. + uint32_t *bignum_num = dwc_alloc(mem_ctx, num_len + 4);
  45041. + uint32_t *bignum_exp = dwc_alloc(mem_ctx, exp_len + 4);
  45042. + uint32_t *bignum_mod = dwc_alloc(mem_ctx, mod_len + 4);
  45043. +
  45044. + dh_swap_bytes(num, &bignum_num[1], num_len);
  45045. + bignum_num[0] = num_len / 4;
  45046. +
  45047. + dh_swap_bytes(exp, &bignum_exp[1], exp_len);
  45048. + bignum_exp[0] = exp_len / 4;
  45049. +
  45050. + dh_swap_bytes(mod, &bignum_mod[1], mod_len);
  45051. + bignum_mod[0] = mod_len / 4;
  45052. +
  45053. + result = dwc_modpow(mem_ctx, bignum_num, bignum_exp, bignum_mod);
  45054. + if (!result) {
  45055. + retval = -1;
  45056. + goto dh_modpow_nomem;
  45057. + }
  45058. +
  45059. + dh_swap_bytes(&result[1], out, result[0] * 4);
  45060. + dwc_free(mem_ctx, result);
  45061. +
  45062. + dh_modpow_nomem:
  45063. + dwc_free(mem_ctx, bignum_num);
  45064. + dwc_free(mem_ctx, bignum_exp);
  45065. + dwc_free(mem_ctx, bignum_mod);
  45066. + return retval;
  45067. +}
  45068. +
  45069. +
  45070. +int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pk, uint8_t *hash)
  45071. +{
  45072. + int retval;
  45073. + uint8_t m3[385];
  45074. +
  45075. +#ifndef DH_TEST_VECTORS
  45076. + DWC_RANDOM_BYTES(exp, 32);
  45077. +#endif
  45078. +
  45079. + /* Compute the pkd */
  45080. + if ((retval = dwc_dh_modpow(mem_ctx, dh_g, 4,
  45081. + exp, 32,
  45082. + dh_p, 384, pk))) {
  45083. + return retval;
  45084. + }
  45085. +
  45086. + m3[384] = nd;
  45087. + DWC_MEMCPY(&m3[0], pk, 384);
  45088. + DWC_SHA256(m3, 385, hash);
  45089. +
  45090. + dh_dump("PK", pk, 384);
  45091. + dh_dump("SHA-256(M3)", hash, 32);
  45092. + return 0;
  45093. +}
  45094. +
  45095. +int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  45096. + uint8_t *exp, int is_host,
  45097. + char *dd, uint8_t *ck, uint8_t *kdk)
  45098. +{
  45099. + int retval;
  45100. + uint8_t mv[784];
  45101. + uint8_t sha_result[32];
  45102. + uint8_t dhkey[384];
  45103. + uint8_t shared_secret[384];
  45104. + char *message;
  45105. + uint32_t vd;
  45106. +
  45107. + uint8_t *pk;
  45108. +
  45109. + if (is_host) {
  45110. + pk = pkd;
  45111. + }
  45112. + else {
  45113. + pk = pkh;
  45114. + }
  45115. +
  45116. + if ((retval = dwc_dh_modpow(mem_ctx, pk, 384,
  45117. + exp, 32,
  45118. + dh_p, 384, shared_secret))) {
  45119. + return retval;
  45120. + }
  45121. + dh_dump("Shared Secret", shared_secret, 384);
  45122. +
  45123. + DWC_SHA256(shared_secret, 384, dhkey);
  45124. + dh_dump("DHKEY", dhkey, 384);
  45125. +
  45126. + DWC_MEMCPY(&mv[0], pkd, 384);
  45127. + DWC_MEMCPY(&mv[384], pkh, 384);
  45128. + DWC_MEMCPY(&mv[768], "displayed digest", 16);
  45129. + dh_dump("MV", mv, 784);
  45130. +
  45131. + DWC_SHA256(mv, 784, sha_result);
  45132. + dh_dump("SHA-256(MV)", sha_result, 32);
  45133. + dh_dump("First 32-bits of SHA-256(MV)", sha_result, 4);
  45134. +
  45135. + dh_swap_bytes(sha_result, &vd, 4);
  45136. +#ifdef DEBUG
  45137. + DWC_PRINTF("Vd (decimal) = %d\n", vd);
  45138. +#endif
  45139. +
  45140. + switch (nd) {
  45141. + case 2:
  45142. + vd = vd % 100;
  45143. + DWC_SPRINTF(dd, "%02d", vd);
  45144. + break;
  45145. + case 3:
  45146. + vd = vd % 1000;
  45147. + DWC_SPRINTF(dd, "%03d", vd);
  45148. + break;
  45149. + case 4:
  45150. + vd = vd % 10000;
  45151. + DWC_SPRINTF(dd, "%04d", vd);
  45152. + break;
  45153. + }
  45154. +#ifdef DEBUG
  45155. + DWC_PRINTF("Display Digits: %s\n", dd);
  45156. +#endif
  45157. +
  45158. + message = "connection key";
  45159. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  45160. + dh_dump("HMAC(SHA-256, DHKey, connection key)", sha_result, 32);
  45161. + DWC_MEMCPY(ck, sha_result, 16);
  45162. +
  45163. + message = "key derivation key";
  45164. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  45165. + dh_dump("HMAC(SHA-256, DHKey, key derivation key)", sha_result, 32);
  45166. + DWC_MEMCPY(kdk, sha_result, 32);
  45167. +
  45168. + return 0;
  45169. +}
  45170. +
  45171. +
  45172. +#ifdef DH_TEST_VECTORS
  45173. +
  45174. +static __u8 dh_a[] = {
  45175. + 0x44, 0x00, 0x51, 0xd6,
  45176. + 0xf0, 0xb5, 0x5e, 0xa9,
  45177. + 0x67, 0xab, 0x31, 0xc6,
  45178. + 0x8a, 0x8b, 0x5e, 0x37,
  45179. + 0xd9, 0x10, 0xda, 0xe0,
  45180. + 0xe2, 0xd4, 0x59, 0xa4,
  45181. + 0x86, 0x45, 0x9c, 0xaa,
  45182. + 0xdf, 0x36, 0x75, 0x16,
  45183. +};
  45184. +
  45185. +static __u8 dh_b[] = {
  45186. + 0x5d, 0xae, 0xc7, 0x86,
  45187. + 0x79, 0x80, 0xa3, 0x24,
  45188. + 0x8c, 0xe3, 0x57, 0x8f,
  45189. + 0xc7, 0x5f, 0x1b, 0x0f,
  45190. + 0x2d, 0xf8, 0x9d, 0x30,
  45191. + 0x6f, 0xa4, 0x52, 0xcd,
  45192. + 0xe0, 0x7a, 0x04, 0x8a,
  45193. + 0xde, 0xd9, 0x26, 0x56,
  45194. +};
  45195. +
  45196. +void dwc_run_dh_test_vectors(void *mem_ctx)
  45197. +{
  45198. + uint8_t pkd[384];
  45199. + uint8_t pkh[384];
  45200. + uint8_t hashd[32];
  45201. + uint8_t hashh[32];
  45202. + uint8_t ck[16];
  45203. + uint8_t kdk[32];
  45204. + char dd[5];
  45205. +
  45206. + DWC_PRINTF("\n\n\nDH_TEST_VECTORS\n\n");
  45207. +
  45208. + /* compute the PKd and SHA-256(PKd || Nd) */
  45209. + DWC_PRINTF("Computing PKd\n");
  45210. + dwc_dh_pk(mem_ctx, 2, dh_a, pkd, hashd);
  45211. +
  45212. + /* compute the PKd and SHA-256(PKh || Nd) */
  45213. + DWC_PRINTF("Computing PKh\n");
  45214. + dwc_dh_pk(mem_ctx, 2, dh_b, pkh, hashh);
  45215. +
  45216. + /* compute the dhkey */
  45217. + dwc_dh_derive_keys(mem_ctx, 2, pkh, pkd, dh_a, 0, dd, ck, kdk);
  45218. +}
  45219. +#endif /* DH_TEST_VECTORS */
  45220. +
  45221. +#endif /* !CONFIG_MACH_IPMATE */
  45222. +
  45223. +#endif /* DWC_CRYPTOLIB */
  45224. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_dh.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h
  45225. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_dh.h 1970-01-01 01:00:00.000000000 +0100
  45226. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h 2014-04-24 15:35:04.169565731 +0200
  45227. @@ -0,0 +1,106 @@
  45228. +/* =========================================================================
  45229. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
  45230. + * $Revision: #4 $
  45231. + * $Date: 2010/09/28 $
  45232. + * $Change: 1596182 $
  45233. + *
  45234. + * Synopsys Portability Library Software and documentation
  45235. + * (hereinafter, "Software") is an Unsupported proprietary work of
  45236. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  45237. + * between Synopsys and you.
  45238. + *
  45239. + * The Software IS NOT an item of Licensed Software or Licensed Product
  45240. + * under any End User Software License Agreement or Agreement for
  45241. + * Licensed Product with Synopsys or any supplement thereto. You are
  45242. + * permitted to use and redistribute this Software in source and binary
  45243. + * forms, with or without modification, provided that redistributions
  45244. + * of source code must retain this notice. You may not view, use,
  45245. + * disclose, copy or distribute this file or any information contained
  45246. + * herein except pursuant to this license grant from Synopsys. If you
  45247. + * do not agree with this notice, including the disclaimer below, then
  45248. + * you are not authorized to use the Software.
  45249. + *
  45250. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  45251. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45252. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  45253. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  45254. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45255. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45256. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45257. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  45258. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45259. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  45260. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  45261. + * DAMAGE.
  45262. + * ========================================================================= */
  45263. +#ifndef _DWC_DH_H_
  45264. +#define _DWC_DH_H_
  45265. +
  45266. +#ifdef __cplusplus
  45267. +extern "C" {
  45268. +#endif
  45269. +
  45270. +#include "dwc_os.h"
  45271. +
  45272. +/** @file
  45273. + *
  45274. + * This file defines the common functions on device and host for performing
  45275. + * numeric association as defined in the WUSB spec. They are only to be
  45276. + * used internally by the DWC UWB modules. */
  45277. +
  45278. +extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
  45279. +extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
  45280. + uint8_t *key, uint32_t keylen,
  45281. + uint8_t *out);
  45282. +extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  45283. + void *exp, uint32_t exp_len,
  45284. + void *mod, uint32_t mod_len,
  45285. + void *out);
  45286. +
  45287. +/** Computes PKD or PKH, and SHA-256(PKd || Nd)
  45288. + *
  45289. + * PK = g^exp mod p.
  45290. + *
  45291. + * Input:
  45292. + * Nd = Number of digits on the device.
  45293. + *
  45294. + * Output:
  45295. + * exp = A 32-byte buffer to be filled with a randomly generated number.
  45296. + * used as either A or B.
  45297. + * pk = A 384-byte buffer to be filled with the PKH or PKD.
  45298. + * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
  45299. + */
  45300. +extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
  45301. +
  45302. +/** Computes the DHKEY, and VD.
  45303. + *
  45304. + * If called from host, then it will comput DHKEY=PKD^exp % p.
  45305. + * If called from device, then it will comput DHKEY=PKH^exp % p.
  45306. + *
  45307. + * Input:
  45308. + * pkd = The PKD value.
  45309. + * pkh = The PKH value.
  45310. + * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
  45311. + * is_host = Set to non zero if a WUSB host is calling this function.
  45312. + *
  45313. + * Output:
  45314. +
  45315. + * dd = A pointer to an buffer to be set to the displayed digits string to be shown
  45316. + * to the user. This buffer should be at 5 bytes long to hold 4 digits plus a
  45317. + * null termination character. This buffer can be used directly for display.
  45318. + * ck = A 16-byte buffer to be filled with the CK.
  45319. + * kdk = A 32-byte buffer to be filled with the KDK.
  45320. + */
  45321. +extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  45322. + uint8_t *exp, int is_host,
  45323. + char *dd, uint8_t *ck, uint8_t *kdk);
  45324. +
  45325. +#ifdef DH_TEST_VECTORS
  45326. +extern void dwc_run_dh_test_vectors(void);
  45327. +#endif
  45328. +
  45329. +#ifdef __cplusplus
  45330. +}
  45331. +#endif
  45332. +
  45333. +#endif /* _DWC_DH_H_ */
  45334. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_list.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h
  45335. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_list.h 1970-01-01 01:00:00.000000000 +0100
  45336. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h 2014-04-24 15:35:04.169565731 +0200
  45337. @@ -0,0 +1,594 @@
  45338. +/* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
  45339. +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
  45340. +
  45341. +/*
  45342. + * Copyright (c) 1991, 1993
  45343. + * The Regents of the University of California. All rights reserved.
  45344. + *
  45345. + * Redistribution and use in source and binary forms, with or without
  45346. + * modification, are permitted provided that the following conditions
  45347. + * are met:
  45348. + * 1. Redistributions of source code must retain the above copyright
  45349. + * notice, this list of conditions and the following disclaimer.
  45350. + * 2. Redistributions in binary form must reproduce the above copyright
  45351. + * notice, this list of conditions and the following disclaimer in the
  45352. + * documentation and/or other materials provided with the distribution.
  45353. + * 3. Neither the name of the University nor the names of its contributors
  45354. + * may be used to endorse or promote products derived from this software
  45355. + * without specific prior written permission.
  45356. + *
  45357. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  45358. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  45359. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  45360. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  45361. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45362. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  45363. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45364. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  45365. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  45366. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  45367. + * SUCH DAMAGE.
  45368. + *
  45369. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  45370. + */
  45371. +
  45372. +#ifndef _DWC_LIST_H_
  45373. +#define _DWC_LIST_H_
  45374. +
  45375. +#ifdef __cplusplus
  45376. +extern "C" {
  45377. +#endif
  45378. +
  45379. +/** @file
  45380. + *
  45381. + * This file defines linked list operations. It is derived from BSD with
  45382. + * only the MACRO names being prefixed with DWC_. This is because a few of
  45383. + * these names conflict with those on Linux. For documentation on use, see the
  45384. + * inline comments in the source code. The original license for this source
  45385. + * code applies and is preserved in the dwc_list.h source file.
  45386. + */
  45387. +
  45388. +/*
  45389. + * This file defines five types of data structures: singly-linked lists,
  45390. + * lists, simple queues, tail queues, and circular queues.
  45391. + *
  45392. + *
  45393. + * A singly-linked list is headed by a single forward pointer. The elements
  45394. + * are singly linked for minimum space and pointer manipulation overhead at
  45395. + * the expense of O(n) removal for arbitrary elements. New elements can be
  45396. + * added to the list after an existing element or at the head of the list.
  45397. + * Elements being removed from the head of the list should use the explicit
  45398. + * macro for this purpose for optimum efficiency. A singly-linked list may
  45399. + * only be traversed in the forward direction. Singly-linked lists are ideal
  45400. + * for applications with large datasets and few or no removals or for
  45401. + * implementing a LIFO queue.
  45402. + *
  45403. + * A list is headed by a single forward pointer (or an array of forward
  45404. + * pointers for a hash table header). The elements are doubly linked
  45405. + * so that an arbitrary element can be removed without a need to
  45406. + * traverse the list. New elements can be added to the list before
  45407. + * or after an existing element or at the head of the list. A list
  45408. + * may only be traversed in the forward direction.
  45409. + *
  45410. + * A simple queue is headed by a pair of pointers, one the head of the
  45411. + * list and the other to the tail of the list. The elements are singly
  45412. + * linked to save space, so elements can only be removed from the
  45413. + * head of the list. New elements can be added to the list before or after
  45414. + * an existing element, at the head of the list, or at the end of the
  45415. + * list. A simple queue may only be traversed in the forward direction.
  45416. + *
  45417. + * A tail queue is headed by a pair of pointers, one to the head of the
  45418. + * list and the other to the tail of the list. The elements are doubly
  45419. + * linked so that an arbitrary element can be removed without a need to
  45420. + * traverse the list. New elements can be added to the list before or
  45421. + * after an existing element, at the head of the list, or at the end of
  45422. + * the list. A tail queue may be traversed in either direction.
  45423. + *
  45424. + * A circle queue is headed by a pair of pointers, one to the head of the
  45425. + * list and the other to the tail of the list. The elements are doubly
  45426. + * linked so that an arbitrary element can be removed without a need to
  45427. + * traverse the list. New elements can be added to the list before or after
  45428. + * an existing element, at the head of the list, or at the end of the list.
  45429. + * A circle queue may be traversed in either direction, but has a more
  45430. + * complex end of list detection.
  45431. + *
  45432. + * For details on the use of these macros, see the queue(3) manual page.
  45433. + */
  45434. +
  45435. +/*
  45436. + * Double-linked List.
  45437. + */
  45438. +
  45439. +typedef struct dwc_list_link {
  45440. + struct dwc_list_link *next;
  45441. + struct dwc_list_link *prev;
  45442. +} dwc_list_link_t;
  45443. +
  45444. +#define DWC_LIST_INIT(link) do { \
  45445. + (link)->next = (link); \
  45446. + (link)->prev = (link); \
  45447. +} while (0)
  45448. +
  45449. +#define DWC_LIST_FIRST(link) ((link)->next)
  45450. +#define DWC_LIST_LAST(link) ((link)->prev)
  45451. +#define DWC_LIST_END(link) (link)
  45452. +#define DWC_LIST_NEXT(link) ((link)->next)
  45453. +#define DWC_LIST_PREV(link) ((link)->prev)
  45454. +#define DWC_LIST_EMPTY(link) \
  45455. + (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
  45456. +#define DWC_LIST_ENTRY(link, type, field) \
  45457. + (type *)((uint8_t *)(link) - (size_t)(&((type *)0)->field))
  45458. +
  45459. +#if 0
  45460. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  45461. + (link)->next = (list)->next; \
  45462. + (link)->prev = (list); \
  45463. + (list)->next->prev = (link); \
  45464. + (list)->next = (link); \
  45465. +} while (0)
  45466. +
  45467. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  45468. + (link)->next = (list); \
  45469. + (link)->prev = (list)->prev; \
  45470. + (list)->prev->next = (link); \
  45471. + (list)->prev = (link); \
  45472. +} while (0)
  45473. +#else
  45474. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  45475. + dwc_list_link_t *__next__ = (list)->next; \
  45476. + __next__->prev = (link); \
  45477. + (link)->next = __next__; \
  45478. + (link)->prev = (list); \
  45479. + (list)->next = (link); \
  45480. +} while (0)
  45481. +
  45482. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  45483. + dwc_list_link_t *__prev__ = (list)->prev; \
  45484. + (list)->prev = (link); \
  45485. + (link)->next = (list); \
  45486. + (link)->prev = __prev__; \
  45487. + __prev__->next = (link); \
  45488. +} while (0)
  45489. +#endif
  45490. +
  45491. +#if 0
  45492. +static inline void __list_add(struct list_head *new,
  45493. + struct list_head *prev,
  45494. + struct list_head *next)
  45495. +{
  45496. + next->prev = new;
  45497. + new->next = next;
  45498. + new->prev = prev;
  45499. + prev->next = new;
  45500. +}
  45501. +
  45502. +static inline void list_add(struct list_head *new, struct list_head *head)
  45503. +{
  45504. + __list_add(new, head, head->next);
  45505. +}
  45506. +
  45507. +static inline void list_add_tail(struct list_head *new, struct list_head *head)
  45508. +{
  45509. + __list_add(new, head->prev, head);
  45510. +}
  45511. +
  45512. +static inline void __list_del(struct list_head * prev, struct list_head * next)
  45513. +{
  45514. + next->prev = prev;
  45515. + prev->next = next;
  45516. +}
  45517. +
  45518. +static inline void list_del(struct list_head *entry)
  45519. +{
  45520. + __list_del(entry->prev, entry->next);
  45521. + entry->next = LIST_POISON1;
  45522. + entry->prev = LIST_POISON2;
  45523. +}
  45524. +#endif
  45525. +
  45526. +#define DWC_LIST_REMOVE(link) do { \
  45527. + (link)->next->prev = (link)->prev; \
  45528. + (link)->prev->next = (link)->next; \
  45529. +} while (0)
  45530. +
  45531. +#define DWC_LIST_REMOVE_INIT(link) do { \
  45532. + DWC_LIST_REMOVE(link); \
  45533. + DWC_LIST_INIT(link); \
  45534. +} while (0)
  45535. +
  45536. +#define DWC_LIST_MOVE_HEAD(list, link) do { \
  45537. + DWC_LIST_REMOVE(link); \
  45538. + DWC_LIST_INSERT_HEAD(list, link); \
  45539. +} while (0)
  45540. +
  45541. +#define DWC_LIST_MOVE_TAIL(list, link) do { \
  45542. + DWC_LIST_REMOVE(link); \
  45543. + DWC_LIST_INSERT_TAIL(list, link); \
  45544. +} while (0)
  45545. +
  45546. +#define DWC_LIST_FOREACH(var, list) \
  45547. + for((var) = DWC_LIST_FIRST(list); \
  45548. + (var) != DWC_LIST_END(list); \
  45549. + (var) = DWC_LIST_NEXT(var))
  45550. +
  45551. +#define DWC_LIST_FOREACH_SAFE(var, var2, list) \
  45552. + for((var) = DWC_LIST_FIRST(list), (var2) = DWC_LIST_NEXT(var); \
  45553. + (var) != DWC_LIST_END(list); \
  45554. + (var) = (var2), (var2) = DWC_LIST_NEXT(var2))
  45555. +
  45556. +#define DWC_LIST_FOREACH_REVERSE(var, list) \
  45557. + for((var) = DWC_LIST_LAST(list); \
  45558. + (var) != DWC_LIST_END(list); \
  45559. + (var) = DWC_LIST_PREV(var))
  45560. +
  45561. +/*
  45562. + * Singly-linked List definitions.
  45563. + */
  45564. +#define DWC_SLIST_HEAD(name, type) \
  45565. +struct name { \
  45566. + struct type *slh_first; /* first element */ \
  45567. +}
  45568. +
  45569. +#define DWC_SLIST_HEAD_INITIALIZER(head) \
  45570. + { NULL }
  45571. +
  45572. +#define DWC_SLIST_ENTRY(type) \
  45573. +struct { \
  45574. + struct type *sle_next; /* next element */ \
  45575. +}
  45576. +
  45577. +/*
  45578. + * Singly-linked List access methods.
  45579. + */
  45580. +#define DWC_SLIST_FIRST(head) ((head)->slh_first)
  45581. +#define DWC_SLIST_END(head) NULL
  45582. +#define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
  45583. +#define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  45584. +
  45585. +#define DWC_SLIST_FOREACH(var, head, field) \
  45586. + for((var) = SLIST_FIRST(head); \
  45587. + (var) != SLIST_END(head); \
  45588. + (var) = SLIST_NEXT(var, field))
  45589. +
  45590. +#define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
  45591. + for((varp) = &SLIST_FIRST((head)); \
  45592. + ((var) = *(varp)) != SLIST_END(head); \
  45593. + (varp) = &SLIST_NEXT((var), field))
  45594. +
  45595. +/*
  45596. + * Singly-linked List functions.
  45597. + */
  45598. +#define DWC_SLIST_INIT(head) { \
  45599. + SLIST_FIRST(head) = SLIST_END(head); \
  45600. +}
  45601. +
  45602. +#define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  45603. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  45604. + (slistelm)->field.sle_next = (elm); \
  45605. +} while (0)
  45606. +
  45607. +#define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
  45608. + (elm)->field.sle_next = (head)->slh_first; \
  45609. + (head)->slh_first = (elm); \
  45610. +} while (0)
  45611. +
  45612. +#define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
  45613. + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
  45614. +} while (0)
  45615. +
  45616. +#define DWC_SLIST_REMOVE_HEAD(head, field) do { \
  45617. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  45618. +} while (0)
  45619. +
  45620. +#define DWC_SLIST_REMOVE(head, elm, type, field) do { \
  45621. + if ((head)->slh_first == (elm)) { \
  45622. + SLIST_REMOVE_HEAD((head), field); \
  45623. + } \
  45624. + else { \
  45625. + struct type *curelm = (head)->slh_first; \
  45626. + while( curelm->field.sle_next != (elm) ) \
  45627. + curelm = curelm->field.sle_next; \
  45628. + curelm->field.sle_next = \
  45629. + curelm->field.sle_next->field.sle_next; \
  45630. + } \
  45631. +} while (0)
  45632. +
  45633. +/*
  45634. + * Simple queue definitions.
  45635. + */
  45636. +#define DWC_SIMPLEQ_HEAD(name, type) \
  45637. +struct name { \
  45638. + struct type *sqh_first; /* first element */ \
  45639. + struct type **sqh_last; /* addr of last next element */ \
  45640. +}
  45641. +
  45642. +#define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
  45643. + { NULL, &(head).sqh_first }
  45644. +
  45645. +#define DWC_SIMPLEQ_ENTRY(type) \
  45646. +struct { \
  45647. + struct type *sqe_next; /* next element */ \
  45648. +}
  45649. +
  45650. +/*
  45651. + * Simple queue access methods.
  45652. + */
  45653. +#define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
  45654. +#define DWC_SIMPLEQ_END(head) NULL
  45655. +#define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  45656. +#define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  45657. +
  45658. +#define DWC_SIMPLEQ_FOREACH(var, head, field) \
  45659. + for((var) = SIMPLEQ_FIRST(head); \
  45660. + (var) != SIMPLEQ_END(head); \
  45661. + (var) = SIMPLEQ_NEXT(var, field))
  45662. +
  45663. +/*
  45664. + * Simple queue functions.
  45665. + */
  45666. +#define DWC_SIMPLEQ_INIT(head) do { \
  45667. + (head)->sqh_first = NULL; \
  45668. + (head)->sqh_last = &(head)->sqh_first; \
  45669. +} while (0)
  45670. +
  45671. +#define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  45672. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  45673. + (head)->sqh_last = &(elm)->field.sqe_next; \
  45674. + (head)->sqh_first = (elm); \
  45675. +} while (0)
  45676. +
  45677. +#define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  45678. + (elm)->field.sqe_next = NULL; \
  45679. + *(head)->sqh_last = (elm); \
  45680. + (head)->sqh_last = &(elm)->field.sqe_next; \
  45681. +} while (0)
  45682. +
  45683. +#define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  45684. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  45685. + (head)->sqh_last = &(elm)->field.sqe_next; \
  45686. + (listelm)->field.sqe_next = (elm); \
  45687. +} while (0)
  45688. +
  45689. +#define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
  45690. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  45691. + (head)->sqh_last = &(head)->sqh_first; \
  45692. +} while (0)
  45693. +
  45694. +/*
  45695. + * Tail queue definitions.
  45696. + */
  45697. +#define DWC_TAILQ_HEAD(name, type) \
  45698. +struct name { \
  45699. + struct type *tqh_first; /* first element */ \
  45700. + struct type **tqh_last; /* addr of last next element */ \
  45701. +}
  45702. +
  45703. +#define DWC_TAILQ_HEAD_INITIALIZER(head) \
  45704. + { NULL, &(head).tqh_first }
  45705. +
  45706. +#define DWC_TAILQ_ENTRY(type) \
  45707. +struct { \
  45708. + struct type *tqe_next; /* next element */ \
  45709. + struct type **tqe_prev; /* address of previous next element */ \
  45710. +}
  45711. +
  45712. +/*
  45713. + * tail queue access methods
  45714. + */
  45715. +#define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
  45716. +#define DWC_TAILQ_END(head) NULL
  45717. +#define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  45718. +#define DWC_TAILQ_LAST(head, headname) \
  45719. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  45720. +/* XXX */
  45721. +#define DWC_TAILQ_PREV(elm, headname, field) \
  45722. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  45723. +#define DWC_TAILQ_EMPTY(head) \
  45724. + (DWC_TAILQ_FIRST(head) == DWC_TAILQ_END(head))
  45725. +
  45726. +#define DWC_TAILQ_FOREACH(var, head, field) \
  45727. + for ((var) = DWC_TAILQ_FIRST(head); \
  45728. + (var) != DWC_TAILQ_END(head); \
  45729. + (var) = DWC_TAILQ_NEXT(var, field))
  45730. +
  45731. +#define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  45732. + for ((var) = DWC_TAILQ_LAST(head, headname); \
  45733. + (var) != DWC_TAILQ_END(head); \
  45734. + (var) = DWC_TAILQ_PREV(var, headname, field))
  45735. +
  45736. +/*
  45737. + * Tail queue functions.
  45738. + */
  45739. +#define DWC_TAILQ_INIT(head) do { \
  45740. + (head)->tqh_first = NULL; \
  45741. + (head)->tqh_last = &(head)->tqh_first; \
  45742. +} while (0)
  45743. +
  45744. +#define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
  45745. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  45746. + (head)->tqh_first->field.tqe_prev = \
  45747. + &(elm)->field.tqe_next; \
  45748. + else \
  45749. + (head)->tqh_last = &(elm)->field.tqe_next; \
  45750. + (head)->tqh_first = (elm); \
  45751. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  45752. +} while (0)
  45753. +
  45754. +#define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
  45755. + (elm)->field.tqe_next = NULL; \
  45756. + (elm)->field.tqe_prev = (head)->tqh_last; \
  45757. + *(head)->tqh_last = (elm); \
  45758. + (head)->tqh_last = &(elm)->field.tqe_next; \
  45759. +} while (0)
  45760. +
  45761. +#define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  45762. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  45763. + (elm)->field.tqe_next->field.tqe_prev = \
  45764. + &(elm)->field.tqe_next; \
  45765. + else \
  45766. + (head)->tqh_last = &(elm)->field.tqe_next; \
  45767. + (listelm)->field.tqe_next = (elm); \
  45768. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  45769. +} while (0)
  45770. +
  45771. +#define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  45772. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  45773. + (elm)->field.tqe_next = (listelm); \
  45774. + *(listelm)->field.tqe_prev = (elm); \
  45775. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  45776. +} while (0)
  45777. +
  45778. +#define DWC_TAILQ_REMOVE(head, elm, field) do { \
  45779. + if (((elm)->field.tqe_next) != NULL) \
  45780. + (elm)->field.tqe_next->field.tqe_prev = \
  45781. + (elm)->field.tqe_prev; \
  45782. + else \
  45783. + (head)->tqh_last = (elm)->field.tqe_prev; \
  45784. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  45785. +} while (0)
  45786. +
  45787. +#define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
  45788. + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
  45789. + (elm2)->field.tqe_next->field.tqe_prev = \
  45790. + &(elm2)->field.tqe_next; \
  45791. + else \
  45792. + (head)->tqh_last = &(elm2)->field.tqe_next; \
  45793. + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
  45794. + *(elm2)->field.tqe_prev = (elm2); \
  45795. +} while (0)
  45796. +
  45797. +/*
  45798. + * Circular queue definitions.
  45799. + */
  45800. +#define DWC_CIRCLEQ_HEAD(name, type) \
  45801. +struct name { \
  45802. + struct type *cqh_first; /* first element */ \
  45803. + struct type *cqh_last; /* last element */ \
  45804. +}
  45805. +
  45806. +#define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
  45807. + { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
  45808. +
  45809. +#define DWC_CIRCLEQ_ENTRY(type) \
  45810. +struct { \
  45811. + struct type *cqe_next; /* next element */ \
  45812. + struct type *cqe_prev; /* previous element */ \
  45813. +}
  45814. +
  45815. +/*
  45816. + * Circular queue access methods
  45817. + */
  45818. +#define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
  45819. +#define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
  45820. +#define DWC_CIRCLEQ_END(head) ((void *)(head))
  45821. +#define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  45822. +#define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  45823. +#define DWC_CIRCLEQ_EMPTY(head) \
  45824. + (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
  45825. +
  45826. +#define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
  45827. +
  45828. +#define DWC_CIRCLEQ_FOREACH(var, head, field) \
  45829. + for((var) = DWC_CIRCLEQ_FIRST(head); \
  45830. + (var) != DWC_CIRCLEQ_END(head); \
  45831. + (var) = DWC_CIRCLEQ_NEXT(var, field))
  45832. +
  45833. +#define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
  45834. + for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
  45835. + (var) != DWC_CIRCLEQ_END(head); \
  45836. + (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
  45837. +
  45838. +#define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  45839. + for((var) = DWC_CIRCLEQ_LAST(head); \
  45840. + (var) != DWC_CIRCLEQ_END(head); \
  45841. + (var) = DWC_CIRCLEQ_PREV(var, field))
  45842. +
  45843. +/*
  45844. + * Circular queue functions.
  45845. + */
  45846. +#define DWC_CIRCLEQ_INIT(head) do { \
  45847. + (head)->cqh_first = DWC_CIRCLEQ_END(head); \
  45848. + (head)->cqh_last = DWC_CIRCLEQ_END(head); \
  45849. +} while (0)
  45850. +
  45851. +#define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
  45852. + (elm)->field.cqe_next = NULL; \
  45853. + (elm)->field.cqe_prev = NULL; \
  45854. +} while (0)
  45855. +
  45856. +#define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  45857. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  45858. + (elm)->field.cqe_prev = (listelm); \
  45859. + if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  45860. + (head)->cqh_last = (elm); \
  45861. + else \
  45862. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  45863. + (listelm)->field.cqe_next = (elm); \
  45864. +} while (0)
  45865. +
  45866. +#define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  45867. + (elm)->field.cqe_next = (listelm); \
  45868. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  45869. + if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  45870. + (head)->cqh_first = (elm); \
  45871. + else \
  45872. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  45873. + (listelm)->field.cqe_prev = (elm); \
  45874. +} while (0)
  45875. +
  45876. +#define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  45877. + (elm)->field.cqe_next = (head)->cqh_first; \
  45878. + (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
  45879. + if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
  45880. + (head)->cqh_last = (elm); \
  45881. + else \
  45882. + (head)->cqh_first->field.cqe_prev = (elm); \
  45883. + (head)->cqh_first = (elm); \
  45884. +} while (0)
  45885. +
  45886. +#define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  45887. + (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
  45888. + (elm)->field.cqe_prev = (head)->cqh_last; \
  45889. + if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
  45890. + (head)->cqh_first = (elm); \
  45891. + else \
  45892. + (head)->cqh_last->field.cqe_next = (elm); \
  45893. + (head)->cqh_last = (elm); \
  45894. +} while (0)
  45895. +
  45896. +#define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
  45897. + if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  45898. + (head)->cqh_last = (elm)->field.cqe_prev; \
  45899. + else \
  45900. + (elm)->field.cqe_next->field.cqe_prev = \
  45901. + (elm)->field.cqe_prev; \
  45902. + if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  45903. + (head)->cqh_first = (elm)->field.cqe_next; \
  45904. + else \
  45905. + (elm)->field.cqe_prev->field.cqe_next = \
  45906. + (elm)->field.cqe_next; \
  45907. +} while (0)
  45908. +
  45909. +#define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
  45910. + DWC_CIRCLEQ_REMOVE(head, elm, field); \
  45911. + DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
  45912. +} while (0)
  45913. +
  45914. +#define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
  45915. + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
  45916. + DWC_CIRCLEQ_END(head)) \
  45917. + (head).cqh_last = (elm2); \
  45918. + else \
  45919. + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
  45920. + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
  45921. + DWC_CIRCLEQ_END(head)) \
  45922. + (head).cqh_first = (elm2); \
  45923. + else \
  45924. + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
  45925. +} while (0)
  45926. +
  45927. +#ifdef __cplusplus
  45928. +}
  45929. +#endif
  45930. +
  45931. +#endif /* _DWC_LIST_H_ */
  45932. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_mem.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c
  45933. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_mem.c 1970-01-01 01:00:00.000000000 +0100
  45934. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c 2014-04-24 15:35:04.169565731 +0200
  45935. @@ -0,0 +1,245 @@
  45936. +/* Memory Debugging */
  45937. +#ifdef DWC_DEBUG_MEMORY
  45938. +
  45939. +#include "dwc_os.h"
  45940. +#include "dwc_list.h"
  45941. +
  45942. +struct allocation {
  45943. + void *addr;
  45944. + void *ctx;
  45945. + char *func;
  45946. + int line;
  45947. + uint32_t size;
  45948. + int dma;
  45949. + DWC_CIRCLEQ_ENTRY(allocation) entry;
  45950. +};
  45951. +
  45952. +DWC_CIRCLEQ_HEAD(allocation_queue, allocation);
  45953. +
  45954. +struct allocation_manager {
  45955. + void *mem_ctx;
  45956. + struct allocation_queue allocations;
  45957. +
  45958. + /* statistics */
  45959. + int num;
  45960. + int num_freed;
  45961. + int num_active;
  45962. + uint32_t total;
  45963. + uint32_t cur;
  45964. + uint32_t max;
  45965. +};
  45966. +
  45967. +static struct allocation_manager *manager = NULL;
  45968. +
  45969. +static int add_allocation(void *ctx, uint32_t size, char const *func, int line, void *addr,
  45970. + int dma)
  45971. +{
  45972. + struct allocation *a;
  45973. +
  45974. + DWC_ASSERT(manager != NULL, "manager not allocated");
  45975. +
  45976. + a = __DWC_ALLOC_ATOMIC(manager->mem_ctx, sizeof(*a));
  45977. + if (!a) {
  45978. + return -DWC_E_NO_MEMORY;
  45979. + }
  45980. +
  45981. + a->func = __DWC_ALLOC_ATOMIC(manager->mem_ctx, DWC_STRLEN(func) + 1);
  45982. + if (!a->func) {
  45983. + __DWC_FREE(manager->mem_ctx, a);
  45984. + return -DWC_E_NO_MEMORY;
  45985. + }
  45986. +
  45987. + DWC_MEMCPY(a->func, func, DWC_STRLEN(func) + 1);
  45988. + a->addr = addr;
  45989. + a->ctx = ctx;
  45990. + a->line = line;
  45991. + a->size = size;
  45992. + a->dma = dma;
  45993. + DWC_CIRCLEQ_INSERT_TAIL(&manager->allocations, a, entry);
  45994. +
  45995. + /* Update stats */
  45996. + manager->num++;
  45997. + manager->num_active++;
  45998. + manager->total += size;
  45999. + manager->cur += size;
  46000. +
  46001. + if (manager->max < manager->cur) {
  46002. + manager->max = manager->cur;
  46003. + }
  46004. +
  46005. + return 0;
  46006. +}
  46007. +
  46008. +static struct allocation *find_allocation(void *ctx, void *addr)
  46009. +{
  46010. + struct allocation *a;
  46011. +
  46012. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  46013. + if (a->ctx == ctx && a->addr == addr) {
  46014. + return a;
  46015. + }
  46016. + }
  46017. +
  46018. + return NULL;
  46019. +}
  46020. +
  46021. +static void free_allocation(void *ctx, void *addr, char const *func, int line)
  46022. +{
  46023. + struct allocation *a = find_allocation(ctx, addr);
  46024. +
  46025. + if (!a) {
  46026. + DWC_ASSERT(0,
  46027. + "Free of address %p that was never allocated or already freed %s:%d",
  46028. + addr, func, line);
  46029. + return;
  46030. + }
  46031. +
  46032. + DWC_CIRCLEQ_REMOVE(&manager->allocations, a, entry);
  46033. +
  46034. + manager->num_active--;
  46035. + manager->num_freed++;
  46036. + manager->cur -= a->size;
  46037. + __DWC_FREE(manager->mem_ctx, a->func);
  46038. + __DWC_FREE(manager->mem_ctx, a);
  46039. +}
  46040. +
  46041. +int dwc_memory_debug_start(void *mem_ctx)
  46042. +{
  46043. + DWC_ASSERT(manager == NULL, "Memory debugging has already started\n");
  46044. +
  46045. + if (manager) {
  46046. + return -DWC_E_BUSY;
  46047. + }
  46048. +
  46049. + manager = __DWC_ALLOC(mem_ctx, sizeof(*manager));
  46050. + if (!manager) {
  46051. + return -DWC_E_NO_MEMORY;
  46052. + }
  46053. +
  46054. + DWC_CIRCLEQ_INIT(&manager->allocations);
  46055. + manager->mem_ctx = mem_ctx;
  46056. + manager->num = 0;
  46057. + manager->num_freed = 0;
  46058. + manager->num_active = 0;
  46059. + manager->total = 0;
  46060. + manager->cur = 0;
  46061. + manager->max = 0;
  46062. +
  46063. + return 0;
  46064. +}
  46065. +
  46066. +void dwc_memory_debug_stop(void)
  46067. +{
  46068. + struct allocation *a;
  46069. +
  46070. + dwc_memory_debug_report();
  46071. +
  46072. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  46073. + DWC_ERROR("Memory leaked from %s:%d\n", a->func, a->line);
  46074. + free_allocation(a->ctx, a->addr, NULL, -1);
  46075. + }
  46076. +
  46077. + __DWC_FREE(manager->mem_ctx, manager);
  46078. +}
  46079. +
  46080. +void dwc_memory_debug_report(void)
  46081. +{
  46082. + struct allocation *a;
  46083. +
  46084. + DWC_PRINTF("\n\n\n----------------- Memory Debugging Report -----------------\n\n");
  46085. + DWC_PRINTF("Num Allocations = %d\n", manager->num);
  46086. + DWC_PRINTF("Freed = %d\n", manager->num_freed);
  46087. + DWC_PRINTF("Active = %d\n", manager->num_active);
  46088. + DWC_PRINTF("Current Memory Used = %d\n", manager->cur);
  46089. + DWC_PRINTF("Total Memory Used = %d\n", manager->total);
  46090. + DWC_PRINTF("Maximum Memory Used at Once = %d\n", manager->max);
  46091. + DWC_PRINTF("Unfreed allocations:\n");
  46092. +
  46093. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  46094. + DWC_PRINTF(" addr=%p, size=%d from %s:%d, DMA=%d\n",
  46095. + a->addr, a->size, a->func, a->line, a->dma);
  46096. + }
  46097. +}
  46098. +
  46099. +/* The replacement functions */
  46100. +void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line)
  46101. +{
  46102. + void *addr = __DWC_ALLOC(mem_ctx, size);
  46103. +
  46104. + if (!addr) {
  46105. + return NULL;
  46106. + }
  46107. +
  46108. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  46109. + __DWC_FREE(mem_ctx, addr);
  46110. + return NULL;
  46111. + }
  46112. +
  46113. + return addr;
  46114. +}
  46115. +
  46116. +void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func,
  46117. + int line)
  46118. +{
  46119. + void *addr = __DWC_ALLOC_ATOMIC(mem_ctx, size);
  46120. +
  46121. + if (!addr) {
  46122. + return NULL;
  46123. + }
  46124. +
  46125. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  46126. + __DWC_FREE(mem_ctx, addr);
  46127. + return NULL;
  46128. + }
  46129. +
  46130. + return addr;
  46131. +}
  46132. +
  46133. +void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line)
  46134. +{
  46135. + free_allocation(mem_ctx, addr, func, line);
  46136. + __DWC_FREE(mem_ctx, addr);
  46137. +}
  46138. +
  46139. +void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  46140. + char const *func, int line)
  46141. +{
  46142. + void *addr = __DWC_DMA_ALLOC(dma_ctx, size, dma_addr);
  46143. +
  46144. + if (!addr) {
  46145. + return NULL;
  46146. + }
  46147. +
  46148. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  46149. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  46150. + return NULL;
  46151. + }
  46152. +
  46153. + return addr;
  46154. +}
  46155. +
  46156. +void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size,
  46157. + dwc_dma_t *dma_addr, char const *func, int line)
  46158. +{
  46159. + void *addr = __DWC_DMA_ALLOC_ATOMIC(dma_ctx, size, dma_addr);
  46160. +
  46161. + if (!addr) {
  46162. + return NULL;
  46163. + }
  46164. +
  46165. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  46166. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  46167. + return NULL;
  46168. + }
  46169. +
  46170. + return addr;
  46171. +}
  46172. +
  46173. +void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  46174. + dwc_dma_t dma_addr, char const *func, int line)
  46175. +{
  46176. + free_allocation(dma_ctx, virt_addr, func, line);
  46177. + __DWC_DMA_FREE(dma_ctx, size, virt_addr, dma_addr);
  46178. +}
  46179. +
  46180. +#endif /* DWC_DEBUG_MEMORY */
  46181. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_modpow.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c
  46182. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_modpow.c 1970-01-01 01:00:00.000000000 +0100
  46183. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c 2014-04-24 16:04:39.811124176 +0200
  46184. @@ -0,0 +1,636 @@
  46185. +/* Bignum routines adapted from PUTTY sources. PuTTY copyright notice follows.
  46186. + *
  46187. + * PuTTY is copyright 1997-2007 Simon Tatham.
  46188. + *
  46189. + * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
  46190. + * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
  46191. + * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
  46192. + * Kuhn, and CORE SDI S.A.
  46193. + *
  46194. + * Permission is hereby granted, free of charge, to any person
  46195. + * obtaining a copy of this software and associated documentation files
  46196. + * (the "Software"), to deal in the Software without restriction,
  46197. + * including without limitation the rights to use, copy, modify, merge,
  46198. + * publish, distribute, sublicense, and/or sell copies of the Software,
  46199. + * and to permit persons to whom the Software is furnished to do so,
  46200. + * subject to the following conditions:
  46201. + *
  46202. + * The above copyright notice and this permission notice shall be
  46203. + * included in all copies or substantial portions of the Software.
  46204. +
  46205. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  46206. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  46207. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  46208. + * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
  46209. + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  46210. + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  46211. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  46212. + *
  46213. + */
  46214. +#ifdef DWC_CRYPTOLIB
  46215. +
  46216. +#ifndef CONFIG_MACH_IPMATE
  46217. +
  46218. +#include "dwc_modpow.h"
  46219. +
  46220. +#define BIGNUM_INT_MASK 0xFFFFFFFFUL
  46221. +#define BIGNUM_TOP_BIT 0x80000000UL
  46222. +#define BIGNUM_INT_BITS 32
  46223. +
  46224. +
  46225. +static void *snmalloc(void *mem_ctx, size_t n, size_t size)
  46226. +{
  46227. + void *p;
  46228. + size *= n;
  46229. + if (size == 0) size = 1;
  46230. + p = dwc_alloc(mem_ctx, size);
  46231. + return p;
  46232. +}
  46233. +
  46234. +#define snewn(ctx, n, type) ((type *)snmalloc((ctx), (n), sizeof(type)))
  46235. +#define sfree dwc_free
  46236. +
  46237. +/*
  46238. + * Usage notes:
  46239. + * * Do not call the DIVMOD_WORD macro with expressions such as array
  46240. + * subscripts, as some implementations object to this (see below).
  46241. + * * Note that none of the division methods below will cope if the
  46242. + * quotient won't fit into BIGNUM_INT_BITS. Callers should be careful
  46243. + * to avoid this case.
  46244. + * If this condition occurs, in the case of the x86 DIV instruction,
  46245. + * an overflow exception will occur, which (according to a correspondent)
  46246. + * will manifest on Windows as something like
  46247. + * 0xC0000095: Integer overflow
  46248. + * The C variant won't give the right answer, either.
  46249. + */
  46250. +
  46251. +#define MUL_WORD(w1, w2) ((BignumDblInt)w1 * w2)
  46252. +
  46253. +#if defined __GNUC__ && defined __i386__
  46254. +#define DIVMOD_WORD(q, r, hi, lo, w) \
  46255. + __asm__("div %2" : \
  46256. + "=d" (r), "=a" (q) : \
  46257. + "r" (w), "d" (hi), "a" (lo))
  46258. +#else
  46259. +#define DIVMOD_WORD(q, r, hi, lo, w) do { \
  46260. + BignumDblInt n = (((BignumDblInt)hi) << BIGNUM_INT_BITS) | lo; \
  46261. + q = n / w; \
  46262. + r = n % w; \
  46263. +} while (0)
  46264. +#endif
  46265. +
  46266. +// q = n / w;
  46267. +// r = n % w;
  46268. +
  46269. +#define BIGNUM_INT_BYTES (BIGNUM_INT_BITS / 8)
  46270. +
  46271. +#define BIGNUM_INTERNAL
  46272. +
  46273. +static Bignum newbn(void *mem_ctx, int length)
  46274. +{
  46275. + Bignum b = snewn(mem_ctx, length + 1, BignumInt);
  46276. + //if (!b)
  46277. + //abort(); /* FIXME */
  46278. + DWC_MEMSET(b, 0, (length + 1) * sizeof(*b));
  46279. + b[0] = length;
  46280. + return b;
  46281. +}
  46282. +
  46283. +void freebn(void *mem_ctx, Bignum b)
  46284. +{
  46285. + /*
  46286. + * Burn the evidence, just in case.
  46287. + */
  46288. + DWC_MEMSET(b, 0, sizeof(b[0]) * (b[0] + 1));
  46289. + sfree(mem_ctx, b);
  46290. +}
  46291. +
  46292. +/*
  46293. + * Compute c = a * b.
  46294. + * Input is in the first len words of a and b.
  46295. + * Result is returned in the first 2*len words of c.
  46296. + */
  46297. +static void internal_mul(BignumInt *a, BignumInt *b,
  46298. + BignumInt *c, int len)
  46299. +{
  46300. + int i, j;
  46301. + BignumDblInt t;
  46302. +
  46303. + for (j = 0; j < 2 * len; j++)
  46304. + c[j] = 0;
  46305. +
  46306. + for (i = len - 1; i >= 0; i--) {
  46307. + t = 0;
  46308. + for (j = len - 1; j >= 0; j--) {
  46309. + t += MUL_WORD(a[i], (BignumDblInt) b[j]);
  46310. + t += (BignumDblInt) c[i + j + 1];
  46311. + c[i + j + 1] = (BignumInt) t;
  46312. + t = t >> BIGNUM_INT_BITS;
  46313. + }
  46314. + c[i] = (BignumInt) t;
  46315. + }
  46316. +}
  46317. +
  46318. +static void internal_add_shifted(BignumInt *number,
  46319. + unsigned n, int shift)
  46320. +{
  46321. + int word = 1 + (shift / BIGNUM_INT_BITS);
  46322. + int bshift = shift % BIGNUM_INT_BITS;
  46323. + BignumDblInt addend;
  46324. +
  46325. + addend = (BignumDblInt)n << bshift;
  46326. +
  46327. + while (addend) {
  46328. + addend += number[word];
  46329. + number[word] = (BignumInt) addend & BIGNUM_INT_MASK;
  46330. + addend >>= BIGNUM_INT_BITS;
  46331. + word++;
  46332. + }
  46333. +}
  46334. +
  46335. +/*
  46336. + * Compute a = a % m.
  46337. + * Input in first alen words of a and first mlen words of m.
  46338. + * Output in first alen words of a
  46339. + * (of which first alen-mlen words will be zero).
  46340. + * The MSW of m MUST have its high bit set.
  46341. + * Quotient is accumulated in the `quotient' array, which is a Bignum
  46342. + * rather than the internal bigendian format. Quotient parts are shifted
  46343. + * left by `qshift' before adding into quot.
  46344. + */
  46345. +static void internal_mod(BignumInt *a, int alen,
  46346. + BignumInt *m, int mlen,
  46347. + BignumInt *quot, int qshift)
  46348. +{
  46349. + BignumInt m0, m1;
  46350. + unsigned int h;
  46351. + int i, k;
  46352. +
  46353. + m0 = m[0];
  46354. + if (mlen > 1)
  46355. + m1 = m[1];
  46356. + else
  46357. + m1 = 0;
  46358. +
  46359. + for (i = 0; i <= alen - mlen; i++) {
  46360. + BignumDblInt t;
  46361. + unsigned int q, r, c, ai1;
  46362. +
  46363. + if (i == 0) {
  46364. + h = 0;
  46365. + } else {
  46366. + h = a[i - 1];
  46367. + a[i - 1] = 0;
  46368. + }
  46369. +
  46370. + if (i == alen - 1)
  46371. + ai1 = 0;
  46372. + else
  46373. + ai1 = a[i + 1];
  46374. +
  46375. + /* Find q = h:a[i] / m0 */
  46376. + if (h >= m0) {
  46377. + /*
  46378. + * Special case.
  46379. + *
  46380. + * To illustrate it, suppose a BignumInt is 8 bits, and
  46381. + * we are dividing (say) A1:23:45:67 by A1:B2:C3. Then
  46382. + * our initial division will be 0xA123 / 0xA1, which
  46383. + * will give a quotient of 0x100 and a divide overflow.
  46384. + * However, the invariants in this division algorithm
  46385. + * are not violated, since the full number A1:23:... is
  46386. + * _less_ than the quotient prefix A1:B2:... and so the
  46387. + * following correction loop would have sorted it out.
  46388. + *
  46389. + * In this situation we set q to be the largest
  46390. + * quotient we _can_ stomach (0xFF, of course).
  46391. + */
  46392. + q = BIGNUM_INT_MASK;
  46393. + } else {
  46394. + /* Macro doesn't want an array subscript expression passed
  46395. + * into it (see definition), so use a temporary. */
  46396. + BignumInt tmplo = a[i];
  46397. + DIVMOD_WORD(q, r, h, tmplo, m0);
  46398. +
  46399. + /* Refine our estimate of q by looking at
  46400. + h:a[i]:a[i+1] / m0:m1 */
  46401. + t = MUL_WORD(m1, q);
  46402. + if (t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) {
  46403. + q--;
  46404. + t -= m1;
  46405. + r = (r + m0) & BIGNUM_INT_MASK; /* overflow? */
  46406. + if (r >= (BignumDblInt) m0 &&
  46407. + t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) q--;
  46408. + }
  46409. + }
  46410. +
  46411. + /* Subtract q * m from a[i...] */
  46412. + c = 0;
  46413. + for (k = mlen - 1; k >= 0; k--) {
  46414. + t = MUL_WORD(q, m[k]);
  46415. + t += c;
  46416. + c = (unsigned)(t >> BIGNUM_INT_BITS);
  46417. + if ((BignumInt) t > a[i + k])
  46418. + c++;
  46419. + a[i + k] -= (BignumInt) t;
  46420. + }
  46421. +
  46422. + /* Add back m in case of borrow */
  46423. + if (c != h) {
  46424. + t = 0;
  46425. + for (k = mlen - 1; k >= 0; k--) {
  46426. + t += m[k];
  46427. + t += a[i + k];
  46428. + a[i + k] = (BignumInt) t;
  46429. + t = t >> BIGNUM_INT_BITS;
  46430. + }
  46431. + q--;
  46432. + }
  46433. + if (quot)
  46434. + internal_add_shifted(quot, q, qshift + BIGNUM_INT_BITS * (alen - mlen - i));
  46435. + }
  46436. +}
  46437. +
  46438. +/*
  46439. + * Compute p % mod.
  46440. + * The most significant word of mod MUST be non-zero.
  46441. + * We assume that the result array is the same size as the mod array.
  46442. + * We optionally write out a quotient if `quotient' is non-NULL.
  46443. + * We can avoid writing out the result if `result' is NULL.
  46444. + */
  46445. +void bigdivmod(void *mem_ctx, Bignum p, Bignum mod, Bignum result, Bignum quotient)
  46446. +{
  46447. + BignumInt *n, *m;
  46448. + int mshift;
  46449. + int plen, mlen, i, j;
  46450. +
  46451. + /* Allocate m of size mlen, copy mod to m */
  46452. + /* We use big endian internally */
  46453. + mlen = mod[0];
  46454. + m = snewn(mem_ctx, mlen, BignumInt);
  46455. + //if (!m)
  46456. + //abort(); /* FIXME */
  46457. + for (j = 0; j < mlen; j++)
  46458. + m[j] = mod[mod[0] - j];
  46459. +
  46460. + /* Shift m left to make msb bit set */
  46461. + for (mshift = 0; mshift < BIGNUM_INT_BITS-1; mshift++)
  46462. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  46463. + break;
  46464. + if (mshift) {
  46465. + for (i = 0; i < mlen - 1; i++)
  46466. + m[i] = (m[i] << mshift) | (m[i + 1] >> (BIGNUM_INT_BITS - mshift));
  46467. + m[mlen - 1] = m[mlen - 1] << mshift;
  46468. + }
  46469. +
  46470. + plen = p[0];
  46471. + /* Ensure plen > mlen */
  46472. + if (plen <= mlen)
  46473. + plen = mlen + 1;
  46474. +
  46475. + /* Allocate n of size plen, copy p to n */
  46476. + n = snewn(mem_ctx, plen, BignumInt);
  46477. + //if (!n)
  46478. + //abort(); /* FIXME */
  46479. + for (j = 0; j < plen; j++)
  46480. + n[j] = 0;
  46481. + for (j = 1; j <= (int)p[0]; j++)
  46482. + n[plen - j] = p[j];
  46483. +
  46484. + /* Main computation */
  46485. + internal_mod(n, plen, m, mlen, quotient, mshift);
  46486. +
  46487. + /* Fixup result in case the modulus was shifted */
  46488. + if (mshift) {
  46489. + for (i = plen - mlen - 1; i < plen - 1; i++)
  46490. + n[i] = (n[i] << mshift) | (n[i + 1] >> (BIGNUM_INT_BITS - mshift));
  46491. + n[plen - 1] = n[plen - 1] << mshift;
  46492. + internal_mod(n, plen, m, mlen, quotient, 0);
  46493. + for (i = plen - 1; i >= plen - mlen; i--)
  46494. + n[i] = (n[i] >> mshift) | (n[i - 1] << (BIGNUM_INT_BITS - mshift));
  46495. + }
  46496. +
  46497. + /* Copy result to buffer */
  46498. + if (result) {
  46499. + for (i = 1; i <= (int)result[0]; i++) {
  46500. + int j = plen - i;
  46501. + result[i] = j >= 0 ? n[j] : 0;
  46502. + }
  46503. + }
  46504. +
  46505. + /* Free temporary arrays */
  46506. + for (i = 0; i < mlen; i++)
  46507. + m[i] = 0;
  46508. + sfree(mem_ctx, m);
  46509. + for (i = 0; i < plen; i++)
  46510. + n[i] = 0;
  46511. + sfree(mem_ctx, n);
  46512. +}
  46513. +
  46514. +/*
  46515. + * Simple remainder.
  46516. + */
  46517. +Bignum bigmod(void *mem_ctx, Bignum a, Bignum b)
  46518. +{
  46519. + Bignum r = newbn(mem_ctx, b[0]);
  46520. + bigdivmod(mem_ctx, a, b, r, NULL);
  46521. + return r;
  46522. +}
  46523. +
  46524. +/*
  46525. + * Compute (base ^ exp) % mod.
  46526. + */
  46527. +Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod)
  46528. +{
  46529. + BignumInt *a, *b, *n, *m;
  46530. + int mshift;
  46531. + int mlen, i, j;
  46532. + Bignum base, result;
  46533. +
  46534. + /*
  46535. + * The most significant word of mod needs to be non-zero. It
  46536. + * should already be, but let's make sure.
  46537. + */
  46538. + //assert(mod[mod[0]] != 0);
  46539. +
  46540. + /*
  46541. + * Make sure the base is smaller than the modulus, by reducing
  46542. + * it modulo the modulus if not.
  46543. + */
  46544. + base = bigmod(mem_ctx, base_in, mod);
  46545. +
  46546. + /* Allocate m of size mlen, copy mod to m */
  46547. + /* We use big endian internally */
  46548. + mlen = mod[0];
  46549. + m = snewn(mem_ctx, mlen, BignumInt);
  46550. + //if (!m)
  46551. + //abort(); /* FIXME */
  46552. + for (j = 0; j < mlen; j++)
  46553. + m[j] = mod[mod[0] - j];
  46554. +
  46555. + /* Shift m left to make msb bit set */
  46556. + for (mshift = 0; mshift < BIGNUM_INT_BITS - 1; mshift++)
  46557. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  46558. + break;
  46559. + if (mshift) {
  46560. + for (i = 0; i < mlen - 1; i++)
  46561. + m[i] =
  46562. + (m[i] << mshift) | (m[i + 1] >>
  46563. + (BIGNUM_INT_BITS - mshift));
  46564. + m[mlen - 1] = m[mlen - 1] << mshift;
  46565. + }
  46566. +
  46567. + /* Allocate n of size mlen, copy base to n */
  46568. + n = snewn(mem_ctx, mlen, BignumInt);
  46569. + //if (!n)
  46570. + //abort(); /* FIXME */
  46571. + i = mlen - base[0];
  46572. + for (j = 0; j < i; j++)
  46573. + n[j] = 0;
  46574. + for (j = 0; j < base[0]; j++)
  46575. + n[i + j] = base[base[0] - j];
  46576. +
  46577. + /* Allocate a and b of size 2*mlen. Set a = 1 */
  46578. + a = snewn(mem_ctx, 2 * mlen, BignumInt);
  46579. + //if (!a)
  46580. + //abort(); /* FIXME */
  46581. + b = snewn(mem_ctx, 2 * mlen, BignumInt);
  46582. + //if (!b)
  46583. + //abort(); /* FIXME */
  46584. + for (i = 0; i < 2 * mlen; i++)
  46585. + a[i] = 0;
  46586. + a[2 * mlen - 1] = 1;
  46587. +
  46588. + /* Skip leading zero bits of exp. */
  46589. + i = 0;
  46590. + j = BIGNUM_INT_BITS - 1;
  46591. + while (i < exp[0] && (exp[exp[0] - i] & (1 << j)) == 0) {
  46592. + j--;
  46593. + if (j < 0) {
  46594. + i++;
  46595. + j = BIGNUM_INT_BITS - 1;
  46596. + }
  46597. + }
  46598. +
  46599. + /* Main computation */
  46600. + while (i < exp[0]) {
  46601. + while (j >= 0) {
  46602. + internal_mul(a + mlen, a + mlen, b, mlen);
  46603. + internal_mod(b, mlen * 2, m, mlen, NULL, 0);
  46604. + if ((exp[exp[0] - i] & (1 << j)) != 0) {
  46605. + internal_mul(b + mlen, n, a, mlen);
  46606. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  46607. + } else {
  46608. + BignumInt *t;
  46609. + t = a;
  46610. + a = b;
  46611. + b = t;
  46612. + }
  46613. + j--;
  46614. + }
  46615. + i++;
  46616. + j = BIGNUM_INT_BITS - 1;
  46617. + }
  46618. +
  46619. + /* Fixup result in case the modulus was shifted */
  46620. + if (mshift) {
  46621. + for (i = mlen - 1; i < 2 * mlen - 1; i++)
  46622. + a[i] =
  46623. + (a[i] << mshift) | (a[i + 1] >>
  46624. + (BIGNUM_INT_BITS - mshift));
  46625. + a[2 * mlen - 1] = a[2 * mlen - 1] << mshift;
  46626. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  46627. + for (i = 2 * mlen - 1; i >= mlen; i--)
  46628. + a[i] =
  46629. + (a[i] >> mshift) | (a[i - 1] <<
  46630. + (BIGNUM_INT_BITS - mshift));
  46631. + }
  46632. +
  46633. + /* Copy result to buffer */
  46634. + result = newbn(mem_ctx, mod[0]);
  46635. + for (i = 0; i < mlen; i++)
  46636. + result[result[0] - i] = a[i + mlen];
  46637. + while (result[0] > 1 && result[result[0]] == 0)
  46638. + result[0]--;
  46639. +
  46640. + /* Free temporary arrays */
  46641. + for (i = 0; i < 2 * mlen; i++)
  46642. + a[i] = 0;
  46643. + sfree(mem_ctx, a);
  46644. + for (i = 0; i < 2 * mlen; i++)
  46645. + b[i] = 0;
  46646. + sfree(mem_ctx, b);
  46647. + for (i = 0; i < mlen; i++)
  46648. + m[i] = 0;
  46649. + sfree(mem_ctx, m);
  46650. + for (i = 0; i < mlen; i++)
  46651. + n[i] = 0;
  46652. + sfree(mem_ctx, n);
  46653. +
  46654. + freebn(mem_ctx, base);
  46655. +
  46656. + return result;
  46657. +}
  46658. +
  46659. +
  46660. +#ifdef UNITTEST
  46661. +
  46662. +static __u32 dh_p[] = {
  46663. + 96,
  46664. + 0xFFFFFFFF,
  46665. + 0xFFFFFFFF,
  46666. + 0xA93AD2CA,
  46667. + 0x4B82D120,
  46668. + 0xE0FD108E,
  46669. + 0x43DB5BFC,
  46670. + 0x74E5AB31,
  46671. + 0x08E24FA0,
  46672. + 0xBAD946E2,
  46673. + 0x770988C0,
  46674. + 0x7A615D6C,
  46675. + 0xBBE11757,
  46676. + 0x177B200C,
  46677. + 0x521F2B18,
  46678. + 0x3EC86A64,
  46679. + 0xD8760273,
  46680. + 0xD98A0864,
  46681. + 0xF12FFA06,
  46682. + 0x1AD2EE6B,
  46683. + 0xCEE3D226,
  46684. + 0x4A25619D,
  46685. + 0x1E8C94E0,
  46686. + 0xDB0933D7,
  46687. + 0xABF5AE8C,
  46688. + 0xA6E1E4C7,
  46689. + 0xB3970F85,
  46690. + 0x5D060C7D,
  46691. + 0x8AEA7157,
  46692. + 0x58DBEF0A,
  46693. + 0xECFB8504,
  46694. + 0xDF1CBA64,
  46695. + 0xA85521AB,
  46696. + 0x04507A33,
  46697. + 0xAD33170D,
  46698. + 0x8AAAC42D,
  46699. + 0x15728E5A,
  46700. + 0x98FA0510,
  46701. + 0x15D22618,
  46702. + 0xEA956AE5,
  46703. + 0x3995497C,
  46704. + 0x95581718,
  46705. + 0xDE2BCBF6,
  46706. + 0x6F4C52C9,
  46707. + 0xB5C55DF0,
  46708. + 0xEC07A28F,
  46709. + 0x9B2783A2,
  46710. + 0x180E8603,
  46711. + 0xE39E772C,
  46712. + 0x2E36CE3B,
  46713. + 0x32905E46,
  46714. + 0xCA18217C,
  46715. + 0xF1746C08,
  46716. + 0x4ABC9804,
  46717. + 0x670C354E,
  46718. + 0x7096966D,
  46719. + 0x9ED52907,
  46720. + 0x208552BB,
  46721. + 0x1C62F356,
  46722. + 0xDCA3AD96,
  46723. + 0x83655D23,
  46724. + 0xFD24CF5F,
  46725. + 0x69163FA8,
  46726. + 0x1C55D39A,
  46727. + 0x98DA4836,
  46728. + 0xA163BF05,
  46729. + 0xC2007CB8,
  46730. + 0xECE45B3D,
  46731. + 0x49286651,
  46732. + 0x7C4B1FE6,
  46733. + 0xAE9F2411,
  46734. + 0x5A899FA5,
  46735. + 0xEE386BFB,
  46736. + 0xF406B7ED,
  46737. + 0x0BFF5CB6,
  46738. + 0xA637ED6B,
  46739. + 0xF44C42E9,
  46740. + 0x625E7EC6,
  46741. + 0xE485B576,
  46742. + 0x6D51C245,
  46743. + 0x4FE1356D,
  46744. + 0xF25F1437,
  46745. + 0x302B0A6D,
  46746. + 0xCD3A431B,
  46747. + 0xEF9519B3,
  46748. + 0x8E3404DD,
  46749. + 0x514A0879,
  46750. + 0x3B139B22,
  46751. + 0x020BBEA6,
  46752. + 0x8A67CC74,
  46753. + 0x29024E08,
  46754. + 0x80DC1CD1,
  46755. + 0xC4C6628B,
  46756. + 0x2168C234,
  46757. + 0xC90FDAA2,
  46758. + 0xFFFFFFFF,
  46759. + 0xFFFFFFFF,
  46760. +};
  46761. +
  46762. +static __u32 dh_a[] = {
  46763. + 8,
  46764. + 0xdf367516,
  46765. + 0x86459caa,
  46766. + 0xe2d459a4,
  46767. + 0xd910dae0,
  46768. + 0x8a8b5e37,
  46769. + 0x67ab31c6,
  46770. + 0xf0b55ea9,
  46771. + 0x440051d6,
  46772. +};
  46773. +
  46774. +static __u32 dh_b[] = {
  46775. + 8,
  46776. + 0xded92656,
  46777. + 0xe07a048a,
  46778. + 0x6fa452cd,
  46779. + 0x2df89d30,
  46780. + 0xc75f1b0f,
  46781. + 0x8ce3578f,
  46782. + 0x7980a324,
  46783. + 0x5daec786,
  46784. +};
  46785. +
  46786. +static __u32 dh_g[] = {
  46787. + 1,
  46788. + 2,
  46789. +};
  46790. +
  46791. +int main(void)
  46792. +{
  46793. + int i;
  46794. + __u32 *k;
  46795. + k = dwc_modpow(NULL, dh_g, dh_a, dh_p);
  46796. +
  46797. + printf("\n\n");
  46798. + for (i=0; i<k[0]; i++) {
  46799. + __u32 word32 = k[k[0] - i];
  46800. + __u16 l = word32 & 0xffff;
  46801. + __u16 m = (word32 & 0xffff0000) >> 16;
  46802. + printf("%04x %04x ", m, l);
  46803. + if (!((i + 1)%13)) printf("\n");
  46804. + }
  46805. + printf("\n\n");
  46806. +
  46807. + if ((k[0] == 0x60) && (k[1] == 0x28e490e5) && (k[0x60] == 0x5a0d3d4e)) {
  46808. + printf("PASS\n\n");
  46809. + }
  46810. + else {
  46811. + printf("FAIL\n\n");
  46812. + }
  46813. +
  46814. +}
  46815. +
  46816. +#endif /* UNITTEST */
  46817. +
  46818. +#endif /* CONFIG_MACH_IPMATE */
  46819. +
  46820. +#endif /*DWC_CRYPTOLIB */
  46821. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_modpow.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h
  46822. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_modpow.h 1970-01-01 01:00:00.000000000 +0100
  46823. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h 2014-04-24 15:35:04.169565731 +0200
  46824. @@ -0,0 +1,34 @@
  46825. +/*
  46826. + * dwc_modpow.h
  46827. + * See dwc_modpow.c for license and changes
  46828. + */
  46829. +#ifndef _DWC_MODPOW_H
  46830. +#define _DWC_MODPOW_H
  46831. +
  46832. +#ifdef __cplusplus
  46833. +extern "C" {
  46834. +#endif
  46835. +
  46836. +#include "dwc_os.h"
  46837. +
  46838. +/** @file
  46839. + *
  46840. + * This file defines the module exponentiation function which is only used
  46841. + * internally by the DWC UWB modules for calculation of PKs during numeric
  46842. + * association. The routine is taken from the PUTTY, an open source terminal
  46843. + * emulator. The PUTTY License is preserved in the dwc_modpow.c file.
  46844. + *
  46845. + */
  46846. +
  46847. +typedef uint32_t BignumInt;
  46848. +typedef uint64_t BignumDblInt;
  46849. +typedef BignumInt *Bignum;
  46850. +
  46851. +/* Compute modular exponentiaion */
  46852. +extern Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod);
  46853. +
  46854. +#ifdef __cplusplus
  46855. +}
  46856. +#endif
  46857. +
  46858. +#endif /* _LINUX_BIGNUM_H */
  46859. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_notifier.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c
  46860. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_notifier.c 1970-01-01 01:00:00.000000000 +0100
  46861. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c 2014-04-24 15:35:04.169565731 +0200
  46862. @@ -0,0 +1,319 @@
  46863. +#ifdef DWC_NOTIFYLIB
  46864. +
  46865. +#include "dwc_notifier.h"
  46866. +#include "dwc_list.h"
  46867. +
  46868. +typedef struct dwc_observer {
  46869. + void *observer;
  46870. + dwc_notifier_callback_t callback;
  46871. + void *data;
  46872. + char *notification;
  46873. + DWC_CIRCLEQ_ENTRY(dwc_observer) list_entry;
  46874. +} observer_t;
  46875. +
  46876. +DWC_CIRCLEQ_HEAD(observer_queue, dwc_observer);
  46877. +
  46878. +typedef struct dwc_notifier {
  46879. + void *mem_ctx;
  46880. + void *object;
  46881. + struct observer_queue observers;
  46882. + DWC_CIRCLEQ_ENTRY(dwc_notifier) list_entry;
  46883. +} notifier_t;
  46884. +
  46885. +DWC_CIRCLEQ_HEAD(notifier_queue, dwc_notifier);
  46886. +
  46887. +typedef struct manager {
  46888. + void *mem_ctx;
  46889. + void *wkq_ctx;
  46890. + dwc_workq_t *wq;
  46891. +// dwc_mutex_t *mutex;
  46892. + struct notifier_queue notifiers;
  46893. +} manager_t;
  46894. +
  46895. +static manager_t *manager = NULL;
  46896. +
  46897. +static int create_manager(void *mem_ctx, void *wkq_ctx)
  46898. +{
  46899. + manager = dwc_alloc(mem_ctx, sizeof(manager_t));
  46900. + if (!manager) {
  46901. + return -DWC_E_NO_MEMORY;
  46902. + }
  46903. +
  46904. + DWC_CIRCLEQ_INIT(&manager->notifiers);
  46905. +
  46906. + manager->wq = dwc_workq_alloc(wkq_ctx, "DWC Notification WorkQ");
  46907. + if (!manager->wq) {
  46908. + return -DWC_E_NO_MEMORY;
  46909. + }
  46910. +
  46911. + return 0;
  46912. +}
  46913. +
  46914. +static void free_manager(void)
  46915. +{
  46916. + dwc_workq_free(manager->wq);
  46917. +
  46918. + /* All notifiers must have unregistered themselves before this module
  46919. + * can be removed. Hitting this assertion indicates a programmer
  46920. + * error. */
  46921. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&manager->notifiers),
  46922. + "Notification manager being freed before all notifiers have been removed");
  46923. + dwc_free(manager->mem_ctx, manager);
  46924. +}
  46925. +
  46926. +#ifdef DEBUG
  46927. +static void dump_manager(void)
  46928. +{
  46929. + notifier_t *n;
  46930. + observer_t *o;
  46931. +
  46932. + DWC_ASSERT(manager, "Notification manager not found");
  46933. +
  46934. + DWC_DEBUG("List of all notifiers and observers:\n");
  46935. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  46936. + DWC_DEBUG("Notifier %p has observers:\n", n->object);
  46937. + DWC_CIRCLEQ_FOREACH(o, &n->observers, list_entry) {
  46938. + DWC_DEBUG(" %p watching %s\n", o->observer, o->notification);
  46939. + }
  46940. + }
  46941. +}
  46942. +#else
  46943. +#define dump_manager(...)
  46944. +#endif
  46945. +
  46946. +static observer_t *alloc_observer(void *mem_ctx, void *observer, char *notification,
  46947. + dwc_notifier_callback_t callback, void *data)
  46948. +{
  46949. + observer_t *new_observer = dwc_alloc(mem_ctx, sizeof(observer_t));
  46950. +
  46951. + if (!new_observer) {
  46952. + return NULL;
  46953. + }
  46954. +
  46955. + DWC_CIRCLEQ_INIT_ENTRY(new_observer, list_entry);
  46956. + new_observer->observer = observer;
  46957. + new_observer->notification = notification;
  46958. + new_observer->callback = callback;
  46959. + new_observer->data = data;
  46960. + return new_observer;
  46961. +}
  46962. +
  46963. +static void free_observer(void *mem_ctx, observer_t *observer)
  46964. +{
  46965. + dwc_free(mem_ctx, observer);
  46966. +}
  46967. +
  46968. +static notifier_t *alloc_notifier(void *mem_ctx, void *object)
  46969. +{
  46970. + notifier_t *notifier;
  46971. +
  46972. + if (!object) {
  46973. + return NULL;
  46974. + }
  46975. +
  46976. + notifier = dwc_alloc(mem_ctx, sizeof(notifier_t));
  46977. + if (!notifier) {
  46978. + return NULL;
  46979. + }
  46980. +
  46981. + DWC_CIRCLEQ_INIT(&notifier->observers);
  46982. + DWC_CIRCLEQ_INIT_ENTRY(notifier, list_entry);
  46983. +
  46984. + notifier->mem_ctx = mem_ctx;
  46985. + notifier->object = object;
  46986. + return notifier;
  46987. +}
  46988. +
  46989. +static void free_notifier(notifier_t *notifier)
  46990. +{
  46991. + observer_t *observer;
  46992. +
  46993. + DWC_CIRCLEQ_FOREACH(observer, &notifier->observers, list_entry) {
  46994. + free_observer(notifier->mem_ctx, observer);
  46995. + }
  46996. +
  46997. + dwc_free(notifier->mem_ctx, notifier);
  46998. +}
  46999. +
  47000. +static notifier_t *find_notifier(void *object)
  47001. +{
  47002. + notifier_t *notifier;
  47003. +
  47004. + DWC_ASSERT(manager, "Notification manager not found");
  47005. +
  47006. + if (!object) {
  47007. + return NULL;
  47008. + }
  47009. +
  47010. + DWC_CIRCLEQ_FOREACH(notifier, &manager->notifiers, list_entry) {
  47011. + if (notifier->object == object) {
  47012. + return notifier;
  47013. + }
  47014. + }
  47015. +
  47016. + return NULL;
  47017. +}
  47018. +
  47019. +int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx)
  47020. +{
  47021. + return create_manager(mem_ctx, wkq_ctx);
  47022. +}
  47023. +
  47024. +void dwc_free_notification_manager(void)
  47025. +{
  47026. + free_manager();
  47027. +}
  47028. +
  47029. +dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object)
  47030. +{
  47031. + notifier_t *notifier;
  47032. +
  47033. + DWC_ASSERT(manager, "Notification manager not found");
  47034. +
  47035. + notifier = find_notifier(object);
  47036. + if (notifier) {
  47037. + DWC_ERROR("Notifier %p is already registered\n", object);
  47038. + return NULL;
  47039. + }
  47040. +
  47041. + notifier = alloc_notifier(mem_ctx, object);
  47042. + if (!notifier) {
  47043. + return NULL;
  47044. + }
  47045. +
  47046. + DWC_CIRCLEQ_INSERT_TAIL(&manager->notifiers, notifier, list_entry);
  47047. +
  47048. + DWC_INFO("Notifier %p registered", object);
  47049. + dump_manager();
  47050. +
  47051. + return notifier;
  47052. +}
  47053. +
  47054. +void dwc_unregister_notifier(dwc_notifier_t *notifier)
  47055. +{
  47056. + DWC_ASSERT(manager, "Notification manager not found");
  47057. +
  47058. + if (!DWC_CIRCLEQ_EMPTY(&notifier->observers)) {
  47059. + observer_t *o;
  47060. +
  47061. + DWC_ERROR("Notifier %p has active observers when removing\n", notifier->object);
  47062. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  47063. + DWC_DEBUGC(" %p watching %s\n", o->observer, o->notification);
  47064. + }
  47065. +
  47066. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&notifier->observers),
  47067. + "Notifier %p has active observers when removing", notifier);
  47068. + }
  47069. +
  47070. + DWC_CIRCLEQ_REMOVE_INIT(&manager->notifiers, notifier, list_entry);
  47071. + free_notifier(notifier);
  47072. +
  47073. + DWC_INFO("Notifier unregistered");
  47074. + dump_manager();
  47075. +}
  47076. +
  47077. +/* Add an observer to observe the notifier for a particular state, event, or notification. */
  47078. +int dwc_add_observer(void *observer, void *object, char *notification,
  47079. + dwc_notifier_callback_t callback, void *data)
  47080. +{
  47081. + notifier_t *notifier = find_notifier(object);
  47082. + observer_t *new_observer;
  47083. +
  47084. + if (!notifier) {
  47085. + DWC_ERROR("Notifier %p is not found when adding observer\n", object);
  47086. + return -DWC_E_INVALID;
  47087. + }
  47088. +
  47089. + new_observer = alloc_observer(notifier->mem_ctx, observer, notification, callback, data);
  47090. + if (!new_observer) {
  47091. + return -DWC_E_NO_MEMORY;
  47092. + }
  47093. +
  47094. + DWC_CIRCLEQ_INSERT_TAIL(&notifier->observers, new_observer, list_entry);
  47095. +
  47096. + DWC_INFO("Added observer %p to notifier %p observing notification %s, callback=%p, data=%p",
  47097. + observer, object, notification, callback, data);
  47098. +
  47099. + dump_manager();
  47100. + return 0;
  47101. +}
  47102. +
  47103. +int dwc_remove_observer(void *observer)
  47104. +{
  47105. + notifier_t *n;
  47106. +
  47107. + DWC_ASSERT(manager, "Notification manager not found");
  47108. +
  47109. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  47110. + observer_t *o;
  47111. + observer_t *o2;
  47112. +
  47113. + DWC_CIRCLEQ_FOREACH_SAFE(o, o2, &n->observers, list_entry) {
  47114. + if (o->observer == observer) {
  47115. + DWC_CIRCLEQ_REMOVE_INIT(&n->observers, o, list_entry);
  47116. + DWC_INFO("Removing observer %p from notifier %p watching notification %s:",
  47117. + o->observer, n->object, o->notification);
  47118. + free_observer(n->mem_ctx, o);
  47119. + }
  47120. + }
  47121. + }
  47122. +
  47123. + dump_manager();
  47124. + return 0;
  47125. +}
  47126. +
  47127. +typedef struct callback_data {
  47128. + void *mem_ctx;
  47129. + dwc_notifier_callback_t cb;
  47130. + void *observer;
  47131. + void *data;
  47132. + void *object;
  47133. + char *notification;
  47134. + void *notification_data;
  47135. +} cb_data_t;
  47136. +
  47137. +static void cb_task(void *data)
  47138. +{
  47139. + cb_data_t *cb = (cb_data_t *)data;
  47140. +
  47141. + cb->cb(cb->object, cb->notification, cb->observer, cb->notification_data, cb->data);
  47142. + dwc_free(cb->mem_ctx, cb);
  47143. +}
  47144. +
  47145. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data)
  47146. +{
  47147. + observer_t *o;
  47148. +
  47149. + DWC_ASSERT(manager, "Notification manager not found");
  47150. +
  47151. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  47152. + int len = DWC_STRLEN(notification);
  47153. +
  47154. + if (DWC_STRLEN(o->notification) != len) {
  47155. + continue;
  47156. + }
  47157. +
  47158. + if (DWC_STRNCMP(o->notification, notification, len) == 0) {
  47159. + cb_data_t *cb_data = dwc_alloc(notifier->mem_ctx, sizeof(cb_data_t));
  47160. +
  47161. + if (!cb_data) {
  47162. + DWC_ERROR("Failed to allocate callback data\n");
  47163. + return;
  47164. + }
  47165. +
  47166. + cb_data->mem_ctx = notifier->mem_ctx;
  47167. + cb_data->cb = o->callback;
  47168. + cb_data->observer = o->observer;
  47169. + cb_data->data = o->data;
  47170. + cb_data->object = notifier->object;
  47171. + cb_data->notification = notification;
  47172. + cb_data->notification_data = notification_data;
  47173. + DWC_DEBUGC("Observer found %p for notification %s\n", o->observer, notification);
  47174. + DWC_WORKQ_SCHEDULE(manager->wq, cb_task, cb_data,
  47175. + "Notify callback from %p for Notification %s, to observer %p",
  47176. + cb_data->object, notification, cb_data->observer);
  47177. + }
  47178. + }
  47179. +}
  47180. +
  47181. +#endif /* DWC_NOTIFYLIB */
  47182. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_notifier.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h
  47183. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_notifier.h 1970-01-01 01:00:00.000000000 +0100
  47184. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h 2014-04-24 15:35:04.169565731 +0200
  47185. @@ -0,0 +1,122 @@
  47186. +
  47187. +#ifndef __DWC_NOTIFIER_H__
  47188. +#define __DWC_NOTIFIER_H__
  47189. +
  47190. +#ifdef __cplusplus
  47191. +extern "C" {
  47192. +#endif
  47193. +
  47194. +#include "dwc_os.h"
  47195. +
  47196. +/** @file
  47197. + *
  47198. + * A simple implementation of the Observer pattern. Any "module" can
  47199. + * register as an observer or notifier. The notion of "module" is abstract and
  47200. + * can mean anything used to identify either an observer or notifier. Usually
  47201. + * it will be a pointer to a data structure which contains some state, ie an
  47202. + * object.
  47203. + *
  47204. + * Before any notifiers can be added, the global notification manager must be
  47205. + * brought up with dwc_alloc_notification_manager().
  47206. + * dwc_free_notification_manager() will bring it down and free all resources.
  47207. + * These would typically be called upon module load and unload. The
  47208. + * notification manager is a single global instance that handles all registered
  47209. + * observable modules and observers so this should be done only once.
  47210. + *
  47211. + * A module can be observable by using Notifications to publicize some general
  47212. + * information about it's state or operation. It does not care who listens, or
  47213. + * even if anyone listens, or what they do with the information. The observable
  47214. + * modules do not need to know any information about it's observers or their
  47215. + * interface, or their state or data.
  47216. + *
  47217. + * Any module can register to emit Notifications. It should publish a list of
  47218. + * notifications that it can emit and their behavior, such as when they will get
  47219. + * triggered, and what information will be provided to the observer. Then it
  47220. + * should register itself as an observable module. See dwc_register_notifier().
  47221. + *
  47222. + * Any module can observe any observable, registered module, provided it has a
  47223. + * handle to the other module and knows what notifications to observe. See
  47224. + * dwc_add_observer().
  47225. + *
  47226. + * A function of type dwc_notifier_callback_t is called whenever a notification
  47227. + * is triggered with one or more observers observing it. This function is
  47228. + * called in it's own process so it may sleep or block if needed. It is
  47229. + * guaranteed to be called sometime after the notification has occurred and will
  47230. + * be called once per each time the notification is triggered. It will NOT be
  47231. + * called in the same process context used to trigger the notification.
  47232. + *
  47233. + * @section Limitiations
  47234. + *
  47235. + * Keep in mind that Notifications that can be triggered in rapid sucession may
  47236. + * schedule too many processes too handle. Be aware of this limitation when
  47237. + * designing to use notifications, and only add notifications for appropriate
  47238. + * observable information.
  47239. + *
  47240. + * Also Notification callbacks are not synchronous. If you need to synchronize
  47241. + * the behavior between module/observer you must use other means. And perhaps
  47242. + * that will mean Notifications are not the proper solution.
  47243. + */
  47244. +
  47245. +struct dwc_notifier;
  47246. +typedef struct dwc_notifier dwc_notifier_t;
  47247. +
  47248. +/** The callback function must be of this type.
  47249. + *
  47250. + * @param object This is the object that is being observed.
  47251. + * @param notification This is the notification that was triggered.
  47252. + * @param observer This is the observer
  47253. + * @param notification_data This is notification-specific data that the notifier
  47254. + * has included in this notification. The value of this should be published in
  47255. + * the documentation of the observable module with the notifications.
  47256. + * @param user_data This is any custom data that the observer provided when
  47257. + * adding itself as an observer to the notification. */
  47258. +typedef void (*dwc_notifier_callback_t)(void *object, char *notification, void *observer,
  47259. + void *notification_data, void *user_data);
  47260. +
  47261. +/** Brings up the notification manager. */
  47262. +extern int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx);
  47263. +/** Brings down the notification manager. */
  47264. +extern void dwc_free_notification_manager(void);
  47265. +
  47266. +/** This function registers an observable module. A dwc_notifier_t object is
  47267. + * returned to the observable module. This is an opaque object that is used by
  47268. + * the observable module to trigger notifications. This object should only be
  47269. + * accessible to functions that are authorized to trigger notifications for this
  47270. + * module. Observers do not need this object. */
  47271. +extern dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object);
  47272. +
  47273. +/** This function unregisters an observable module. All observers have to be
  47274. + * removed prior to unregistration. */
  47275. +extern void dwc_unregister_notifier(dwc_notifier_t *notifier);
  47276. +
  47277. +/** Add a module as an observer to the observable module. The observable module
  47278. + * needs to have previously registered with the notification manager.
  47279. + *
  47280. + * @param observer The observer module
  47281. + * @param object The module to observe
  47282. + * @param notification The notification to observe
  47283. + * @param callback The callback function to call
  47284. + * @param user_data Any additional user data to pass into the callback function */
  47285. +extern int dwc_add_observer(void *observer, void *object, char *notification,
  47286. + dwc_notifier_callback_t callback, void *user_data);
  47287. +
  47288. +/** Removes the specified observer from all notifications that it is currently
  47289. + * observing. */
  47290. +extern int dwc_remove_observer(void *observer);
  47291. +
  47292. +/** This function triggers a Notification. It should be called by the
  47293. + * observable module, or any module or library which the observable module
  47294. + * allows to trigger notification on it's behalf. Such as the dwc_cc_t.
  47295. + *
  47296. + * dwc_notify is a non-blocking function. Callbacks are scheduled called in
  47297. + * their own process context for each trigger. Callbacks can be blocking.
  47298. + * dwc_notify can be called from interrupt context if needed.
  47299. + *
  47300. + */
  47301. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data);
  47302. +
  47303. +#ifdef __cplusplus
  47304. +}
  47305. +#endif
  47306. +
  47307. +#endif /* __DWC_NOTIFIER_H__ */
  47308. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_os.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h
  47309. --- linux-3.12.18/drivers/usb/host/dwc_common_port/dwc_os.h 1970-01-01 01:00:00.000000000 +0100
  47310. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h 2014-04-24 16:04:39.815124215 +0200
  47311. @@ -0,0 +1,1262 @@
  47312. +/* =========================================================================
  47313. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
  47314. + * $Revision: #14 $
  47315. + * $Date: 2010/11/04 $
  47316. + * $Change: 1621695 $
  47317. + *
  47318. + * Synopsys Portability Library Software and documentation
  47319. + * (hereinafter, "Software") is an Unsupported proprietary work of
  47320. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  47321. + * between Synopsys and you.
  47322. + *
  47323. + * The Software IS NOT an item of Licensed Software or Licensed Product
  47324. + * under any End User Software License Agreement or Agreement for
  47325. + * Licensed Product with Synopsys or any supplement thereto. You are
  47326. + * permitted to use and redistribute this Software in source and binary
  47327. + * forms, with or without modification, provided that redistributions
  47328. + * of source code must retain this notice. You may not view, use,
  47329. + * disclose, copy or distribute this file or any information contained
  47330. + * herein except pursuant to this license grant from Synopsys. If you
  47331. + * do not agree with this notice, including the disclaimer below, then
  47332. + * you are not authorized to use the Software.
  47333. + *
  47334. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  47335. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  47336. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  47337. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  47338. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  47339. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  47340. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  47341. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  47342. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  47343. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  47344. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  47345. + * DAMAGE.
  47346. + * ========================================================================= */
  47347. +#ifndef _DWC_OS_H_
  47348. +#define _DWC_OS_H_
  47349. +
  47350. +#ifdef __cplusplus
  47351. +extern "C" {
  47352. +#endif
  47353. +
  47354. +/** @file
  47355. + *
  47356. + * DWC portability library, low level os-wrapper functions
  47357. + *
  47358. + */
  47359. +
  47360. +/* These basic types need to be defined by some OS header file or custom header
  47361. + * file for your specific target architecture.
  47362. + *
  47363. + * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  47364. + *
  47365. + * Any custom or alternate header file must be added and enabled here.
  47366. + */
  47367. +
  47368. +#ifdef DWC_LINUX
  47369. +# include <linux/types.h>
  47370. +# ifdef CONFIG_DEBUG_MUTEXES
  47371. +# include <linux/mutex.h>
  47372. +# endif
  47373. +# include <linux/errno.h>
  47374. +# include <stdarg.h>
  47375. +#endif
  47376. +
  47377. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47378. +# include <os_dep.h>
  47379. +#endif
  47380. +
  47381. +
  47382. +/** @name Primitive Types and Values */
  47383. +
  47384. +/** We define a boolean type for consistency. Can be either YES or NO */
  47385. +typedef uint8_t dwc_bool_t;
  47386. +#define YES 1
  47387. +#define NO 0
  47388. +
  47389. +#ifdef DWC_LINUX
  47390. +
  47391. +/** @name Error Codes */
  47392. +#define DWC_E_INVALID EINVAL
  47393. +#define DWC_E_NO_MEMORY ENOMEM
  47394. +#define DWC_E_NO_DEVICE ENODEV
  47395. +#define DWC_E_NOT_SUPPORTED EOPNOTSUPP
  47396. +#define DWC_E_TIMEOUT ETIMEDOUT
  47397. +#define DWC_E_BUSY EBUSY
  47398. +#define DWC_E_AGAIN EAGAIN
  47399. +#define DWC_E_RESTART ERESTART
  47400. +#define DWC_E_ABORT ECONNABORTED
  47401. +#define DWC_E_SHUTDOWN ESHUTDOWN
  47402. +#define DWC_E_NO_DATA ENODATA
  47403. +#define DWC_E_DISCONNECT ECONNRESET
  47404. +#define DWC_E_UNKNOWN EINVAL
  47405. +#define DWC_E_NO_STREAM_RES ENOSR
  47406. +#define DWC_E_COMMUNICATION ECOMM
  47407. +#define DWC_E_OVERFLOW EOVERFLOW
  47408. +#define DWC_E_PROTOCOL EPROTO
  47409. +#define DWC_E_IN_PROGRESS EINPROGRESS
  47410. +#define DWC_E_PIPE EPIPE
  47411. +#define DWC_E_IO EIO
  47412. +#define DWC_E_NO_SPACE ENOSPC
  47413. +
  47414. +#else
  47415. +
  47416. +/** @name Error Codes */
  47417. +#define DWC_E_INVALID 1001
  47418. +#define DWC_E_NO_MEMORY 1002
  47419. +#define DWC_E_NO_DEVICE 1003
  47420. +#define DWC_E_NOT_SUPPORTED 1004
  47421. +#define DWC_E_TIMEOUT 1005
  47422. +#define DWC_E_BUSY 1006
  47423. +#define DWC_E_AGAIN 1007
  47424. +#define DWC_E_RESTART 1008
  47425. +#define DWC_E_ABORT 1009
  47426. +#define DWC_E_SHUTDOWN 1010
  47427. +#define DWC_E_NO_DATA 1011
  47428. +#define DWC_E_DISCONNECT 2000
  47429. +#define DWC_E_UNKNOWN 3000
  47430. +#define DWC_E_NO_STREAM_RES 4001
  47431. +#define DWC_E_COMMUNICATION 4002
  47432. +#define DWC_E_OVERFLOW 4003
  47433. +#define DWC_E_PROTOCOL 4004
  47434. +#define DWC_E_IN_PROGRESS 4005
  47435. +#define DWC_E_PIPE 4006
  47436. +#define DWC_E_IO 4007
  47437. +#define DWC_E_NO_SPACE 4008
  47438. +
  47439. +#endif
  47440. +
  47441. +
  47442. +/** @name Tracing/Logging Functions
  47443. + *
  47444. + * These function provide the capability to add tracing, debugging, and error
  47445. + * messages, as well exceptions as assertions. The WUDEV uses these
  47446. + * extensively. These could be logged to the main console, the serial port, an
  47447. + * internal buffer, etc. These functions could also be no-op if they are too
  47448. + * expensive on your system. By default undefining the DEBUG macro already
  47449. + * no-ops some of these functions. */
  47450. +
  47451. +/** Returns non-zero if in interrupt context. */
  47452. +extern dwc_bool_t DWC_IN_IRQ(void);
  47453. +#define dwc_in_irq DWC_IN_IRQ
  47454. +
  47455. +/** Returns "IRQ" if DWC_IN_IRQ is true. */
  47456. +static inline char *dwc_irq(void) {
  47457. + return DWC_IN_IRQ() ? "IRQ" : "";
  47458. +}
  47459. +
  47460. +/** Returns non-zero if in bottom-half context. */
  47461. +extern dwc_bool_t DWC_IN_BH(void);
  47462. +#define dwc_in_bh DWC_IN_BH
  47463. +
  47464. +/** Returns "BH" if DWC_IN_BH is true. */
  47465. +static inline char *dwc_bh(void) {
  47466. + return DWC_IN_BH() ? "BH" : "";
  47467. +}
  47468. +
  47469. +/**
  47470. + * A vprintf() clone. Just call vprintf if you've got it.
  47471. + */
  47472. +extern void DWC_VPRINTF(char *format, va_list args);
  47473. +#define dwc_vprintf DWC_VPRINTF
  47474. +
  47475. +/**
  47476. + * A vsnprintf() clone. Just call vprintf if you've got it.
  47477. + */
  47478. +extern int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
  47479. +#define dwc_vsnprintf DWC_VSNPRINTF
  47480. +
  47481. +/**
  47482. + * printf() clone. Just call printf if you've go it.
  47483. + */
  47484. +extern void DWC_PRINTF(char *format, ...)
  47485. +/* This provides compiler level static checking of the parameters if you're
  47486. + * using GCC. */
  47487. +#ifdef __GNUC__
  47488. + __attribute__ ((format(printf, 1, 2)));
  47489. +#else
  47490. + ;
  47491. +#endif
  47492. +#define dwc_printf DWC_PRINTF
  47493. +
  47494. +/**
  47495. + * sprintf() clone. Just call sprintf if you've got it.
  47496. + */
  47497. +extern int DWC_SPRINTF(char *string, char *format, ...)
  47498. +#ifdef __GNUC__
  47499. + __attribute__ ((format(printf, 2, 3)));
  47500. +#else
  47501. + ;
  47502. +#endif
  47503. +#define dwc_sprintf DWC_SPRINTF
  47504. +
  47505. +/**
  47506. + * snprintf() clone. Just call snprintf if you've got it.
  47507. + */
  47508. +extern int DWC_SNPRINTF(char *string, int size, char *format, ...)
  47509. +#ifdef __GNUC__
  47510. + __attribute__ ((format(printf, 3, 4)));
  47511. +#else
  47512. + ;
  47513. +#endif
  47514. +#define dwc_snprintf DWC_SNPRINTF
  47515. +
  47516. +/**
  47517. + * Prints a WARNING message. On systems that don't differentiate between
  47518. + * warnings and regular log messages, just print it. Indicates that something
  47519. + * may be wrong with the driver. Works like printf().
  47520. + *
  47521. + * Use the DWC_WARN macro to call this function.
  47522. + */
  47523. +extern void __DWC_WARN(char *format, ...)
  47524. +#ifdef __GNUC__
  47525. + __attribute__ ((format(printf, 1, 2)));
  47526. +#else
  47527. + ;
  47528. +#endif
  47529. +
  47530. +/**
  47531. + * Prints an error message. On systems that don't differentiate between errors
  47532. + * and regular log messages, just print it. Indicates that something went wrong
  47533. + * with the driver. Works like printf().
  47534. + *
  47535. + * Use the DWC_ERROR macro to call this function.
  47536. + */
  47537. +extern void __DWC_ERROR(char *format, ...)
  47538. +#ifdef __GNUC__
  47539. + __attribute__ ((format(printf, 1, 2)));
  47540. +#else
  47541. + ;
  47542. +#endif
  47543. +
  47544. +/**
  47545. + * Prints an exception error message and takes some user-defined action such as
  47546. + * print out a backtrace or trigger a breakpoint. Indicates that something went
  47547. + * abnormally wrong with the driver such as programmer error, or other
  47548. + * exceptional condition. It should not be ignored so even on systems without
  47549. + * printing capability, some action should be taken to notify the developer of
  47550. + * it. Works like printf().
  47551. + */
  47552. +extern void DWC_EXCEPTION(char *format, ...)
  47553. +#ifdef __GNUC__
  47554. + __attribute__ ((format(printf, 1, 2)));
  47555. +#else
  47556. + ;
  47557. +#endif
  47558. +#define dwc_exception DWC_EXCEPTION
  47559. +
  47560. +#ifndef DWC_OTG_DEBUG_LEV
  47561. +#define DWC_OTG_DEBUG_LEV 0
  47562. +#endif
  47563. +
  47564. +#ifdef DEBUG
  47565. +/**
  47566. + * Prints out a debug message. Used for logging/trace messages.
  47567. + *
  47568. + * Use the DWC_DEBUG macro to call this function
  47569. + */
  47570. +extern void __DWC_DEBUG(char *format, ...)
  47571. +#ifdef __GNUC__
  47572. + __attribute__ ((format(printf, 1, 2)));
  47573. +#else
  47574. + ;
  47575. +#endif
  47576. +#else
  47577. +#define __DWC_DEBUG printk
  47578. +#endif
  47579. +
  47580. +/**
  47581. + * Prints out a Debug message.
  47582. + */
  47583. +#define DWC_DEBUG(_format, _args...) __DWC_DEBUG("DEBUG:%s:%s: " _format "\n", \
  47584. + __func__, dwc_irq(), ## _args)
  47585. +#define dwc_debug DWC_DEBUG
  47586. +/**
  47587. + * Prints out a Debug message if enabled at compile time.
  47588. + */
  47589. +#if DWC_OTG_DEBUG_LEV > 0
  47590. +#define DWC_DEBUGC(_format, _args...) DWC_DEBUG(_format, ##_args )
  47591. +#else
  47592. +#define DWC_DEBUGC(_format, _args...)
  47593. +#endif
  47594. +#define dwc_debugc DWC_DEBUGC
  47595. +/**
  47596. + * Prints out an informative message.
  47597. + */
  47598. +#define DWC_INFO(_format, _args...) DWC_PRINTF("INFO:%s: " _format "\n", \
  47599. + dwc_irq(), ## _args)
  47600. +#define dwc_info DWC_INFO
  47601. +/**
  47602. + * Prints out an informative message if enabled at compile time.
  47603. + */
  47604. +#if DWC_OTG_DEBUG_LEV > 1
  47605. +#define DWC_INFOC(_format, _args...) DWC_INFO(_format, ##_args )
  47606. +#else
  47607. +#define DWC_INFOC(_format, _args...)
  47608. +#endif
  47609. +#define dwc_infoc DWC_INFOC
  47610. +/**
  47611. + * Prints out a warning message.
  47612. + */
  47613. +#define DWC_WARN(_format, _args...) __DWC_WARN("WARN:%s:%s:%d: " _format "\n", \
  47614. + dwc_irq(), __func__, __LINE__, ## _args)
  47615. +#define dwc_warn DWC_WARN
  47616. +/**
  47617. + * Prints out an error message.
  47618. + */
  47619. +#define DWC_ERROR(_format, _args...) __DWC_ERROR("ERROR:%s:%s:%d: " _format "\n", \
  47620. + dwc_irq(), __func__, __LINE__, ## _args)
  47621. +#define dwc_error DWC_ERROR
  47622. +
  47623. +#define DWC_PROTO_ERROR(_format, _args...) __DWC_WARN("ERROR:%s:%s:%d: " _format "\n", \
  47624. + dwc_irq(), __func__, __LINE__, ## _args)
  47625. +#define dwc_proto_error DWC_PROTO_ERROR
  47626. +
  47627. +#ifdef DEBUG
  47628. +/** Prints out a exception error message if the _expr expression fails. Disabled
  47629. + * if DEBUG is not enabled. */
  47630. +#define DWC_ASSERT(_expr, _format, _args...) do { \
  47631. + if (!(_expr)) { DWC_EXCEPTION("%s:%s:%d: " _format "\n", dwc_irq(), \
  47632. + __FILE__, __LINE__, ## _args); } \
  47633. + } while (0)
  47634. +#else
  47635. +#define DWC_ASSERT(_x...)
  47636. +#endif
  47637. +#define dwc_assert DWC_ASSERT
  47638. +
  47639. +
  47640. +/** @name Byte Ordering
  47641. + * The following functions are for conversions between processor's byte ordering
  47642. + * and specific ordering you want.
  47643. + */
  47644. +
  47645. +/** Converts 32 bit data in CPU byte ordering to little endian. */
  47646. +extern uint32_t DWC_CPU_TO_LE32(uint32_t *p);
  47647. +#define dwc_cpu_to_le32 DWC_CPU_TO_LE32
  47648. +
  47649. +/** Converts 32 bit data in CPU byte orderint to big endian. */
  47650. +extern uint32_t DWC_CPU_TO_BE32(uint32_t *p);
  47651. +#define dwc_cpu_to_be32 DWC_CPU_TO_BE32
  47652. +
  47653. +/** Converts 32 bit little endian data to CPU byte ordering. */
  47654. +extern uint32_t DWC_LE32_TO_CPU(uint32_t *p);
  47655. +#define dwc_le32_to_cpu DWC_LE32_TO_CPU
  47656. +
  47657. +/** Converts 32 bit big endian data to CPU byte ordering. */
  47658. +extern uint32_t DWC_BE32_TO_CPU(uint32_t *p);
  47659. +#define dwc_be32_to_cpu DWC_BE32_TO_CPU
  47660. +
  47661. +/** Converts 16 bit data in CPU byte ordering to little endian. */
  47662. +extern uint16_t DWC_CPU_TO_LE16(uint16_t *p);
  47663. +#define dwc_cpu_to_le16 DWC_CPU_TO_LE16
  47664. +
  47665. +/** Converts 16 bit data in CPU byte orderint to big endian. */
  47666. +extern uint16_t DWC_CPU_TO_BE16(uint16_t *p);
  47667. +#define dwc_cpu_to_be16 DWC_CPU_TO_BE16
  47668. +
  47669. +/** Converts 16 bit little endian data to CPU byte ordering. */
  47670. +extern uint16_t DWC_LE16_TO_CPU(uint16_t *p);
  47671. +#define dwc_le16_to_cpu DWC_LE16_TO_CPU
  47672. +
  47673. +/** Converts 16 bit bi endian data to CPU byte ordering. */
  47674. +extern uint16_t DWC_BE16_TO_CPU(uint16_t *p);
  47675. +#define dwc_be16_to_cpu DWC_BE16_TO_CPU
  47676. +
  47677. +
  47678. +/** @name Register Read/Write
  47679. + *
  47680. + * The following six functions should be implemented to read/write registers of
  47681. + * 32-bit and 64-bit sizes. All modules use this to read/write register values.
  47682. + * The reg value is a pointer to the register calculated from the void *base
  47683. + * variable passed into the driver when it is started. */
  47684. +
  47685. +#ifdef DWC_LINUX
  47686. +/* Linux doesn't need any extra parameters for register read/write, so we
  47687. + * just throw away the IO context parameter.
  47688. + */
  47689. +/** Reads the content of a 32-bit register. */
  47690. +extern uint32_t DWC_READ_REG32(uint32_t volatile *reg);
  47691. +#define dwc_read_reg32(_ctx_,_reg_) DWC_READ_REG32(_reg_)
  47692. +
  47693. +/** Reads the content of a 64-bit register. */
  47694. +extern uint64_t DWC_READ_REG64(uint64_t volatile *reg);
  47695. +#define dwc_read_reg64(_ctx_,_reg_) DWC_READ_REG64(_reg_)
  47696. +
  47697. +/** Writes to a 32-bit register. */
  47698. +extern void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value);
  47699. +#define dwc_write_reg32(_ctx_,_reg_,_val_) DWC_WRITE_REG32(_reg_, _val_)
  47700. +
  47701. +/** Writes to a 64-bit register. */
  47702. +extern void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value);
  47703. +#define dwc_write_reg64(_ctx_,_reg_,_val_) DWC_WRITE_REG64(_reg_, _val_)
  47704. +
  47705. +/**
  47706. + * Modify bit values in a register. Using the
  47707. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  47708. + */
  47709. +extern void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  47710. +#define dwc_modify_reg32(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG32(_reg_,_cmsk_,_smsk_)
  47711. +extern void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  47712. +#define dwc_modify_reg64(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG64(_reg_,_cmsk_,_smsk_)
  47713. +
  47714. +#endif /* DWC_LINUX */
  47715. +
  47716. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47717. +typedef struct dwc_ioctx {
  47718. + struct device *dev;
  47719. + bus_space_tag_t iot;
  47720. + bus_space_handle_t ioh;
  47721. +} dwc_ioctx_t;
  47722. +
  47723. +/** BSD needs two extra parameters for register read/write, so we pass
  47724. + * them in using the IO context parameter.
  47725. + */
  47726. +/** Reads the content of a 32-bit register. */
  47727. +extern uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg);
  47728. +#define dwc_read_reg32 DWC_READ_REG32
  47729. +
  47730. +/** Reads the content of a 64-bit register. */
  47731. +extern uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg);
  47732. +#define dwc_read_reg64 DWC_READ_REG64
  47733. +
  47734. +/** Writes to a 32-bit register. */
  47735. +extern void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value);
  47736. +#define dwc_write_reg32 DWC_WRITE_REG32
  47737. +
  47738. +/** Writes to a 64-bit register. */
  47739. +extern void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value);
  47740. +#define dwc_write_reg64 DWC_WRITE_REG64
  47741. +
  47742. +/**
  47743. + * Modify bit values in a register. Using the
  47744. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  47745. + */
  47746. +extern void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  47747. +#define dwc_modify_reg32 DWC_MODIFY_REG32
  47748. +extern void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  47749. +#define dwc_modify_reg64 DWC_MODIFY_REG64
  47750. +
  47751. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  47752. +
  47753. +/** @cond */
  47754. +
  47755. +/** @name Some convenience MACROS used internally. Define DWC_DEBUG_REGS to log the
  47756. + * register writes. */
  47757. +
  47758. +#ifdef DWC_LINUX
  47759. +
  47760. +# ifdef DWC_DEBUG_REGS
  47761. +
  47762. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47763. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  47764. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  47765. +} \
  47766. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  47767. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  47768. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  47769. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  47770. +}
  47771. +
  47772. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47773. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  47774. + return DWC_READ_REG32(&container->regs->_reg); \
  47775. +} \
  47776. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  47777. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  47778. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  47779. +}
  47780. +
  47781. +# else /* DWC_DEBUG_REGS */
  47782. +
  47783. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47784. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  47785. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  47786. +} \
  47787. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  47788. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  47789. +}
  47790. +
  47791. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47792. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  47793. + return DWC_READ_REG32(&container->regs->_reg); \
  47794. +} \
  47795. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  47796. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  47797. +}
  47798. +
  47799. +# endif /* DWC_DEBUG_REGS */
  47800. +
  47801. +#endif /* DWC_LINUX */
  47802. +
  47803. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47804. +
  47805. +# ifdef DWC_DEBUG_REGS
  47806. +
  47807. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47808. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  47809. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  47810. +} \
  47811. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  47812. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  47813. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  47814. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  47815. +}
  47816. +
  47817. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47818. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  47819. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  47820. +} \
  47821. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  47822. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  47823. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  47824. +}
  47825. +
  47826. +# else /* DWC_DEBUG_REGS */
  47827. +
  47828. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47829. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  47830. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  47831. +} \
  47832. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  47833. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  47834. +}
  47835. +
  47836. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47837. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  47838. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  47839. +} \
  47840. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  47841. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  47842. +}
  47843. +
  47844. +# endif /* DWC_DEBUG_REGS */
  47845. +
  47846. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  47847. +
  47848. +/** @endcond */
  47849. +
  47850. +
  47851. +#ifdef DWC_CRYPTOLIB
  47852. +/** @name Crypto Functions
  47853. + *
  47854. + * These are the low-level cryptographic functions used by the driver. */
  47855. +
  47856. +/** Perform AES CBC */
  47857. +extern int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
  47858. +#define dwc_aes_cbc DWC_AES_CBC
  47859. +
  47860. +/** Fill the provided buffer with random bytes. These should be cryptographic grade random numbers. */
  47861. +extern void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
  47862. +#define dwc_random_bytes DWC_RANDOM_BYTES
  47863. +
  47864. +/** Perform the SHA-256 hash function */
  47865. +extern int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
  47866. +#define dwc_sha256 DWC_SHA256
  47867. +
  47868. +/** Calculated the HMAC-SHA256 */
  47869. +extern int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
  47870. +#define dwc_hmac_sha256 DWC_HMAC_SHA256
  47871. +
  47872. +#endif /* DWC_CRYPTOLIB */
  47873. +
  47874. +
  47875. +/** @name Memory Allocation
  47876. + *
  47877. + * These function provide access to memory allocation. There are only 2 DMA
  47878. + * functions and 3 Regular memory functions that need to be implemented. None
  47879. + * of the memory debugging routines need to be implemented. The allocation
  47880. + * routines all ZERO the contents of the memory.
  47881. + *
  47882. + * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
  47883. + * This checks for memory leaks, keeping track of alloc/free pairs. It also
  47884. + * keeps track of how much memory the driver is using at any given time. */
  47885. +
  47886. +#define DWC_PAGE_SIZE 4096
  47887. +#define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
  47888. +#define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
  47889. +
  47890. +#define DWC_INVALID_DMA_ADDR 0x0
  47891. +
  47892. +#ifdef DWC_LINUX
  47893. +/** Type for a DMA address */
  47894. +typedef dma_addr_t dwc_dma_t;
  47895. +#endif
  47896. +
  47897. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47898. +typedef bus_addr_t dwc_dma_t;
  47899. +#endif
  47900. +
  47901. +#ifdef DWC_FREEBSD
  47902. +typedef struct dwc_dmactx {
  47903. + struct device *dev;
  47904. + bus_dma_tag_t dma_tag;
  47905. + bus_dmamap_t dma_map;
  47906. + bus_addr_t dma_paddr;
  47907. + void *dma_vaddr;
  47908. +} dwc_dmactx_t;
  47909. +#endif
  47910. +
  47911. +#ifdef DWC_NETBSD
  47912. +typedef struct dwc_dmactx {
  47913. + struct device *dev;
  47914. + bus_dma_tag_t dma_tag;
  47915. + bus_dmamap_t dma_map;
  47916. + bus_dma_segment_t segs[1];
  47917. + int nsegs;
  47918. + bus_addr_t dma_paddr;
  47919. + void *dma_vaddr;
  47920. +} dwc_dmactx_t;
  47921. +#endif
  47922. +
  47923. +/* @todo these functions will be added in the future */
  47924. +#if 0
  47925. +/**
  47926. + * Creates a DMA pool from which you can allocate DMA buffers. Buffers
  47927. + * allocated from this pool will be guaranteed to meet the size, alignment, and
  47928. + * boundary requirements specified.
  47929. + *
  47930. + * @param[in] size Specifies the size of the buffers that will be allocated from
  47931. + * this pool.
  47932. + * @param[in] align Specifies the byte alignment requirements of the buffers
  47933. + * allocated from this pool. Must be a power of 2.
  47934. + * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
  47935. + * this pool must not cross.
  47936. + *
  47937. + * @returns A pointer to an internal opaque structure which is not to be
  47938. + * accessed outside of these library functions. Use this handle to specify
  47939. + * which pools to allocate/free DMA buffers from and also to destroy the pool,
  47940. + * when you are done with it.
  47941. + */
  47942. +extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
  47943. +
  47944. +/**
  47945. + * Destroy a DMA pool. All buffers allocated from that pool must be freed first.
  47946. + */
  47947. +extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
  47948. +
  47949. +/**
  47950. + * Allocate a buffer from the specified DMA pool and zeros its contents.
  47951. + */
  47952. +extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
  47953. +
  47954. +/**
  47955. + * Free a previously allocated buffer from the DMA pool.
  47956. + */
  47957. +extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
  47958. +#endif
  47959. +
  47960. +/** Allocates a DMA capable buffer and zeroes its contents. */
  47961. +extern void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  47962. +
  47963. +/** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
  47964. +extern void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  47965. +
  47966. +/** Frees a previously allocated buffer. */
  47967. +extern void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
  47968. +
  47969. +/** Allocates a block of memory and zeroes its contents. */
  47970. +extern void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
  47971. +
  47972. +/** Allocates a block of memory and zeroes its contents, in an atomic manner
  47973. + * which can be used inside interrupt context. The size should be sufficiently
  47974. + * small, a few KB at most, such that failures are not likely to occur. Can just call
  47975. + * __DWC_ALLOC if it is atomic. */
  47976. +extern void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
  47977. +
  47978. +/** Frees a previously allocated buffer. */
  47979. +extern void __DWC_FREE(void *mem_ctx, void *addr);
  47980. +
  47981. +#ifndef DWC_DEBUG_MEMORY
  47982. +
  47983. +#define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
  47984. +#define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
  47985. +#define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
  47986. +
  47987. +# ifdef DWC_LINUX
  47988. +#define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
  47989. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
  47990. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
  47991. +# endif
  47992. +
  47993. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47994. +#define DWC_DMA_ALLOC __DWC_DMA_ALLOC
  47995. +#define DWC_DMA_FREE __DWC_DMA_FREE
  47996. +# endif
  47997. +extern void *dwc_dma_alloc_atomic_debug(uint32_t size, dwc_dma_t *dma_addr, char const *func, int line);
  47998. +
  47999. +#else /* DWC_DEBUG_MEMORY */
  48000. +
  48001. +extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  48002. +extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  48003. +extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
  48004. +extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  48005. + char const *func, int line);
  48006. +extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  48007. + char const *func, int line);
  48008. +extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  48009. + dwc_dma_t dma_addr, char const *func, int line);
  48010. +
  48011. +extern int dwc_memory_debug_start(void *mem_ctx);
  48012. +extern void dwc_memory_debug_stop(void);
  48013. +extern void dwc_memory_debug_report(void);
  48014. +
  48015. +#define DWC_ALLOC(_size_) dwc_alloc_debug(NULL, _size_, __func__, __LINE__)
  48016. +#define DWC_ALLOC_ATOMIC(_size_) dwc_alloc_atomic_debug(NULL, _size_, \
  48017. + __func__, __LINE__)
  48018. +#define DWC_FREE(_addr_) dwc_free_debug(NULL, _addr_, __func__, __LINE__)
  48019. +
  48020. +# ifdef DWC_LINUX
  48021. +#define DWC_DMA_ALLOC(_size_,_dma_) dwc_dma_alloc_debug(NULL, _size_, \
  48022. + _dma_, __func__, __LINE__)
  48023. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) dwc_dma_alloc_atomic_debug(NULL, _size_, \
  48024. + _dma_, __func__, __LINE__)
  48025. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) dwc_dma_free_debug(NULL, _size_, \
  48026. + _virt_, _dma_, __func__, __LINE__)
  48027. +# endif
  48028. +
  48029. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48030. +#define DWC_DMA_ALLOC(_ctx_,_size_,_dma_) dwc_dma_alloc_debug(_ctx_, _size_, \
  48031. + _dma_, __func__, __LINE__)
  48032. +#define DWC_DMA_FREE(_ctx_,_size_,_virt_,_dma_) dwc_dma_free_debug(_ctx_, _size_, \
  48033. + _virt_, _dma_, __func__, __LINE__)
  48034. +# endif
  48035. +
  48036. +#endif /* DWC_DEBUG_MEMORY */
  48037. +
  48038. +#define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
  48039. +#define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
  48040. +#define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
  48041. +
  48042. +#ifdef DWC_LINUX
  48043. +/* Linux doesn't need any extra parameters for DMA buffer allocation, so we
  48044. + * just throw away the DMA context parameter.
  48045. + */
  48046. +#define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
  48047. +#define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
  48048. +#define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
  48049. +#endif
  48050. +
  48051. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48052. +/** BSD needs several extra parameters for DMA buffer allocation, so we pass
  48053. + * them in using the DMA context parameter.
  48054. + */
  48055. +#define dwc_dma_alloc DWC_DMA_ALLOC
  48056. +#define dwc_dma_free DWC_DMA_FREE
  48057. +#endif
  48058. +
  48059. +
  48060. +/** @name Memory and String Processing */
  48061. +
  48062. +/** memset() clone */
  48063. +extern void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
  48064. +#define dwc_memset DWC_MEMSET
  48065. +
  48066. +/** memcpy() clone */
  48067. +extern void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
  48068. +#define dwc_memcpy DWC_MEMCPY
  48069. +
  48070. +/** memmove() clone */
  48071. +extern void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
  48072. +#define dwc_memmove DWC_MEMMOVE
  48073. +
  48074. +/** memcmp() clone */
  48075. +extern int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
  48076. +#define dwc_memcmp DWC_MEMCMP
  48077. +
  48078. +/** strcmp() clone */
  48079. +extern int DWC_STRCMP(void *s1, void *s2);
  48080. +#define dwc_strcmp DWC_STRCMP
  48081. +
  48082. +/** strncmp() clone */
  48083. +extern int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
  48084. +#define dwc_strncmp DWC_STRNCMP
  48085. +
  48086. +/** strlen() clone, for NULL terminated ASCII strings */
  48087. +extern int DWC_STRLEN(char const *str);
  48088. +#define dwc_strlen DWC_STRLEN
  48089. +
  48090. +/** strcpy() clone, for NULL terminated ASCII strings */
  48091. +extern char *DWC_STRCPY(char *to, const char *from);
  48092. +#define dwc_strcpy DWC_STRCPY
  48093. +
  48094. +/** strdup() clone. If you wish to use memory allocation debugging, this
  48095. + * implementation of strdup should use the DWC_* memory routines instead of
  48096. + * calling a predefined strdup. Otherwise the memory allocated by this routine
  48097. + * will not be seen by the debugging routines. */
  48098. +extern char *DWC_STRDUP(char const *str);
  48099. +#define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
  48100. +
  48101. +/** NOT an atoi() clone. Read the description carefully. Returns an integer
  48102. + * converted from the string str in base 10 unless the string begins with a "0x"
  48103. + * in which case it is base 16. String must be a NULL terminated sequence of
  48104. + * ASCII characters and may optionally begin with whitespace, a + or -, and a
  48105. + * "0x" prefix if base 16. The remaining characters must be valid digits for
  48106. + * the number and end with a NULL character. If any invalid characters are
  48107. + * encountered or it returns with a negative error code and the results of the
  48108. + * conversion are undefined. On sucess it returns 0. Overflow conditions are
  48109. + * undefined. An example implementation using atoi() can be referenced from the
  48110. + * Linux implementation. */
  48111. +extern int DWC_ATOI(const char *str, int32_t *value);
  48112. +#define dwc_atoi DWC_ATOI
  48113. +
  48114. +/** Same as above but for unsigned. */
  48115. +extern int DWC_ATOUI(const char *str, uint32_t *value);
  48116. +#define dwc_atoui DWC_ATOUI
  48117. +
  48118. +#ifdef DWC_UTFLIB
  48119. +/** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
  48120. +extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
  48121. +#define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
  48122. +#endif
  48123. +
  48124. +
  48125. +/** @name Wait queues
  48126. + *
  48127. + * Wait queues provide a means of synchronizing between threads or processes. A
  48128. + * process can block on a waitq if some condition is not true, waiting for it to
  48129. + * become true. When the waitq is triggered all waiting process will get
  48130. + * unblocked and the condition will be check again. Waitqs should be triggered
  48131. + * every time a condition can potentially change.*/
  48132. +struct dwc_waitq;
  48133. +
  48134. +/** Type for a waitq */
  48135. +typedef struct dwc_waitq dwc_waitq_t;
  48136. +
  48137. +/** The type of waitq condition callback function. This is called every time
  48138. + * condition is evaluated. */
  48139. +typedef int (*dwc_waitq_condition_t)(void *data);
  48140. +
  48141. +/** Allocate a waitq */
  48142. +extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
  48143. +#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
  48144. +
  48145. +/** Free a waitq */
  48146. +extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
  48147. +#define dwc_waitq_free DWC_WAITQ_FREE
  48148. +
  48149. +/** Check the condition and if it is false, block on the waitq. When unblocked, check the
  48150. + * condition again. The function returns when the condition becomes true. The return value
  48151. + * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
  48152. +extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
  48153. +#define dwc_waitq_wait DWC_WAITQ_WAIT
  48154. +
  48155. +/** Check the condition and if it is false, block on the waitq. When unblocked,
  48156. + * check the condition again. The function returns when the condition become
  48157. + * true or the timeout has passed. The return value is 0 on condition true or
  48158. + * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
  48159. + * error. */
  48160. +extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  48161. + void *data, int32_t msecs);
  48162. +#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
  48163. +
  48164. +/** Trigger a waitq, unblocking all processes. This should be called whenever a condition
  48165. + * has potentially changed. */
  48166. +extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
  48167. +#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
  48168. +
  48169. +/** Unblock all processes waiting on the waitq with an ABORTED result. */
  48170. +extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
  48171. +#define dwc_waitq_abort DWC_WAITQ_ABORT
  48172. +
  48173. +
  48174. +/** @name Threads
  48175. + *
  48176. + * A thread must be explicitly stopped. It must check DWC_THREAD_SHOULD_STOP
  48177. + * whenever it is woken up, and then return. The DWC_THREAD_STOP function
  48178. + * returns the value from the thread.
  48179. + */
  48180. +
  48181. +struct dwc_thread;
  48182. +
  48183. +/** Type for a thread */
  48184. +typedef struct dwc_thread dwc_thread_t;
  48185. +
  48186. +/** The thread function */
  48187. +typedef int (*dwc_thread_function_t)(void *data);
  48188. +
  48189. +/** Create a thread and start it running the thread_function. Returns a handle
  48190. + * to the thread */
  48191. +extern dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data);
  48192. +#define dwc_thread_run(_ctx_,_func_,_name_,_data_) DWC_THREAD_RUN(_func_, _name_, _data_)
  48193. +
  48194. +/** Stops a thread. Return the value returned by the thread. Or will return
  48195. + * DWC_ABORT if the thread never started. */
  48196. +extern int DWC_THREAD_STOP(dwc_thread_t *thread);
  48197. +#define dwc_thread_stop DWC_THREAD_STOP
  48198. +
  48199. +/** Signifies to the thread that it must stop. */
  48200. +#ifdef DWC_LINUX
  48201. +/* Linux doesn't need any parameters for kthread_should_stop() */
  48202. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(void);
  48203. +#define dwc_thread_should_stop(_thrd_) DWC_THREAD_SHOULD_STOP()
  48204. +
  48205. +/* No thread_exit function in Linux */
  48206. +#define dwc_thread_exit(_thrd_)
  48207. +#endif
  48208. +
  48209. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48210. +/** BSD needs the thread pointer for kthread_suspend_check() */
  48211. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread);
  48212. +#define dwc_thread_should_stop DWC_THREAD_SHOULD_STOP
  48213. +
  48214. +/** The thread must call this to exit. */
  48215. +extern void DWC_THREAD_EXIT(dwc_thread_t *thread);
  48216. +#define dwc_thread_exit DWC_THREAD_EXIT
  48217. +#endif
  48218. +
  48219. +
  48220. +/** @name Work queues
  48221. + *
  48222. + * Workqs are used to queue a callback function to be called at some later time,
  48223. + * in another thread. */
  48224. +struct dwc_workq;
  48225. +
  48226. +/** Type for a workq */
  48227. +typedef struct dwc_workq dwc_workq_t;
  48228. +
  48229. +/** The type of the callback function to be called. */
  48230. +typedef void (*dwc_work_callback_t)(void *data);
  48231. +
  48232. +/** Allocate a workq */
  48233. +extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
  48234. +#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
  48235. +
  48236. +/** Free a workq. All work must be completed before being freed. */
  48237. +extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
  48238. +#define dwc_workq_free DWC_WORKQ_FREE
  48239. +
  48240. +/** Schedule a callback on the workq, passing in data. The function will be
  48241. + * scheduled at some later time. */
  48242. +extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
  48243. + void *data, char *format, ...)
  48244. +#ifdef __GNUC__
  48245. + __attribute__ ((format(printf, 4, 5)));
  48246. +#else
  48247. + ;
  48248. +#endif
  48249. +#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
  48250. +
  48251. +/** Schedule a callback on the workq, that will be called until at least
  48252. + * given number miliseconds have passed. */
  48253. +extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
  48254. + void *data, uint32_t time, char *format, ...)
  48255. +#ifdef __GNUC__
  48256. + __attribute__ ((format(printf, 5, 6)));
  48257. +#else
  48258. + ;
  48259. +#endif
  48260. +#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
  48261. +
  48262. +/** The number of processes in the workq */
  48263. +extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
  48264. +#define dwc_workq_pending DWC_WORKQ_PENDING
  48265. +
  48266. +/** Blocks until all the work in the workq is complete or timed out. Returns <
  48267. + * 0 on timeout. */
  48268. +extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
  48269. +#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
  48270. +
  48271. +
  48272. +/** @name Tasklets
  48273. + *
  48274. + */
  48275. +struct dwc_tasklet;
  48276. +
  48277. +/** Type for a tasklet */
  48278. +typedef struct dwc_tasklet dwc_tasklet_t;
  48279. +
  48280. +/** The type of the callback function to be called */
  48281. +typedef void (*dwc_tasklet_callback_t)(void *data);
  48282. +
  48283. +/** Allocates a tasklet */
  48284. +extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
  48285. +#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
  48286. +
  48287. +/** Frees a tasklet */
  48288. +extern void DWC_TASK_FREE(dwc_tasklet_t *task);
  48289. +#define dwc_task_free DWC_TASK_FREE
  48290. +
  48291. +/** Schedules a tasklet to run */
  48292. +extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
  48293. +#define dwc_task_schedule DWC_TASK_SCHEDULE
  48294. +
  48295. +extern void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task);
  48296. +#define dwc_task_hi_schedule DWC_TASK_HI_SCHEDULE
  48297. +
  48298. +/** @name Timer
  48299. + *
  48300. + * Callbacks must be small and atomic.
  48301. + */
  48302. +struct dwc_timer;
  48303. +
  48304. +/** Type for a timer */
  48305. +typedef struct dwc_timer dwc_timer_t;
  48306. +
  48307. +/** The type of the callback function to be called */
  48308. +typedef void (*dwc_timer_callback_t)(void *data);
  48309. +
  48310. +/** Allocates a timer */
  48311. +extern dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
  48312. +#define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
  48313. +
  48314. +/** Frees a timer */
  48315. +extern void DWC_TIMER_FREE(dwc_timer_t *timer);
  48316. +#define dwc_timer_free DWC_TIMER_FREE
  48317. +
  48318. +/** Schedules the timer to run at time ms from now. And will repeat at every
  48319. + * repeat_interval msec therafter
  48320. + *
  48321. + * Modifies a timer that is still awaiting execution to a new expiration time.
  48322. + * The mod_time is added to the old time. */
  48323. +extern void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
  48324. +#define dwc_timer_schedule DWC_TIMER_SCHEDULE
  48325. +
  48326. +/** Disables the timer from execution. */
  48327. +extern void DWC_TIMER_CANCEL(dwc_timer_t *timer);
  48328. +#define dwc_timer_cancel DWC_TIMER_CANCEL
  48329. +
  48330. +
  48331. +/** @name Spinlocks
  48332. + *
  48333. + * These locks are used when the work between the lock/unlock is atomic and
  48334. + * short. Interrupts are also disabled during the lock/unlock and thus they are
  48335. + * suitable to lock between interrupt/non-interrupt context. They also lock
  48336. + * between processes if you have multiple CPUs or Preemption. If you don't have
  48337. + * multiple CPUS or Preemption, then the you can simply implement the
  48338. + * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts. Because
  48339. + * the work between the lock/unlock is atomic, the process context will never
  48340. + * change, and so you never have to lock between processes. */
  48341. +
  48342. +struct dwc_spinlock;
  48343. +
  48344. +/** Type for a spinlock */
  48345. +typedef struct dwc_spinlock dwc_spinlock_t;
  48346. +
  48347. +/** Type for the 'flags' argument to spinlock funtions */
  48348. +typedef unsigned long dwc_irqflags_t;
  48349. +
  48350. +/** Returns an initialized lock variable. This function should allocate and
  48351. + * initialize the OS-specific data structure used for locking. This data
  48352. + * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
  48353. + * be freed by the DWC_FREE_LOCK when it is no longer used. */
  48354. +extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
  48355. +#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
  48356. +
  48357. +/** Frees an initialized lock variable. */
  48358. +extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
  48359. +#define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
  48360. +
  48361. +/** Disables interrupts and blocks until it acquires the lock.
  48362. + *
  48363. + * @param lock Pointer to the spinlock.
  48364. + * @param flags Unsigned long for irq flags storage.
  48365. + */
  48366. +extern void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
  48367. +#define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
  48368. +
  48369. +/** Re-enables the interrupt and releases the lock.
  48370. + *
  48371. + * @param lock Pointer to the spinlock.
  48372. + * @param flags Unsigned long for irq flags storage. Must be the same as was
  48373. + * passed into DWC_LOCK.
  48374. + */
  48375. +extern void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
  48376. +#define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
  48377. +
  48378. +/** Blocks until it acquires the lock.
  48379. + *
  48380. + * @param lock Pointer to the spinlock.
  48381. + */
  48382. +extern void DWC_SPINLOCK(dwc_spinlock_t *lock);
  48383. +#define dwc_spinlock DWC_SPINLOCK
  48384. +
  48385. +/** Releases the lock.
  48386. + *
  48387. + * @param lock Pointer to the spinlock.
  48388. + */
  48389. +extern void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
  48390. +#define dwc_spinunlock DWC_SPINUNLOCK
  48391. +
  48392. +
  48393. +/** @name Mutexes
  48394. + *
  48395. + * Unlike spinlocks Mutexes lock only between processes and the work between the
  48396. + * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
  48397. + */
  48398. +
  48399. +struct dwc_mutex;
  48400. +
  48401. +/** Type for a mutex */
  48402. +typedef struct dwc_mutex dwc_mutex_t;
  48403. +
  48404. +/* For Linux Mutex Debugging make it inline because the debugging routines use
  48405. + * the symbol to determine recursive locking. This makes it falsely think
  48406. + * recursive locking occurs. */
  48407. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  48408. +#define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
  48409. + __mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
  48410. + mutex_init((struct mutex *)__mutexp); \
  48411. +})
  48412. +#endif
  48413. +
  48414. +/** Allocate a mutex */
  48415. +extern dwc_mutex_t *DWC_MUTEX_ALLOC(void);
  48416. +#define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
  48417. +
  48418. +/* For memory leak debugging when using Linux Mutex Debugging */
  48419. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  48420. +#define DWC_MUTEX_FREE(__mutexp) do { \
  48421. + mutex_destroy((struct mutex *)__mutexp); \
  48422. + DWC_FREE(__mutexp); \
  48423. +} while(0)
  48424. +#else
  48425. +/** Free a mutex */
  48426. +extern void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
  48427. +#define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
  48428. +#endif
  48429. +
  48430. +/** Lock a mutex */
  48431. +extern void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
  48432. +#define dwc_mutex_lock DWC_MUTEX_LOCK
  48433. +
  48434. +/** Non-blocking lock returns 1 on successful lock. */
  48435. +extern int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
  48436. +#define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
  48437. +
  48438. +/** Unlock a mutex */
  48439. +extern void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
  48440. +#define dwc_mutex_unlock DWC_MUTEX_UNLOCK
  48441. +
  48442. +
  48443. +/** @name Time */
  48444. +
  48445. +/** Microsecond delay.
  48446. + *
  48447. + * @param usecs Microseconds to delay.
  48448. + */
  48449. +extern void DWC_UDELAY(uint32_t usecs);
  48450. +#define dwc_udelay DWC_UDELAY
  48451. +
  48452. +/** Millisecond delay.
  48453. + *
  48454. + * @param msecs Milliseconds to delay.
  48455. + */
  48456. +extern void DWC_MDELAY(uint32_t msecs);
  48457. +#define dwc_mdelay DWC_MDELAY
  48458. +
  48459. +/** Non-busy waiting.
  48460. + * Sleeps for specified number of milliseconds.
  48461. + *
  48462. + * @param msecs Milliseconds to sleep.
  48463. + */
  48464. +extern void DWC_MSLEEP(uint32_t msecs);
  48465. +#define dwc_msleep DWC_MSLEEP
  48466. +
  48467. +/**
  48468. + * Returns number of milliseconds since boot.
  48469. + */
  48470. +extern uint32_t DWC_TIME(void);
  48471. +#define dwc_time DWC_TIME
  48472. +
  48473. +
  48474. +
  48475. +
  48476. +/* @mainpage DWC Portability and Common Library
  48477. + *
  48478. + * This is the documentation for the DWC Portability and Common Library.
  48479. + *
  48480. + * @section intro Introduction
  48481. + *
  48482. + * The DWC Portability library consists of wrapper calls and data structures to
  48483. + * all low-level functions which are typically provided by the OS. The WUDEV
  48484. + * driver uses only these functions. In order to port the WUDEV driver, only
  48485. + * the functions in this library need to be re-implemented, with the same
  48486. + * behavior as documented here.
  48487. + *
  48488. + * The Common library consists of higher level functions, which rely only on
  48489. + * calling the functions from the DWC Portability library. These common
  48490. + * routines are shared across modules. Some of the common libraries need to be
  48491. + * used directly by the driver programmer when porting WUDEV. Such as the
  48492. + * parameter and notification libraries.
  48493. + *
  48494. + * @section low Portability Library OS Wrapper Functions
  48495. + *
  48496. + * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
  48497. + * needs to be implemented when porting, for example DWC_MUTEX_ALLOC(). All of
  48498. + * these functions are included in the dwc_os.h file.
  48499. + *
  48500. + * There are many functions here covering a wide array of OS services. Please
  48501. + * see dwc_os.h for details, and implementation notes for each function.
  48502. + *
  48503. + * @section common Common Library Functions
  48504. + *
  48505. + * Any function starting with dwc and in all lowercase is a common library
  48506. + * routine. These functions have a portable implementation and do not need to
  48507. + * be reimplemented when porting. The common routines can be used by any
  48508. + * driver, and some must be used by the end user to control the drivers. For
  48509. + * example, you must use the Parameter common library in order to set the
  48510. + * parameters in the WUDEV module.
  48511. + *
  48512. + * The common libraries consist of the following:
  48513. + *
  48514. + * - Connection Contexts - Used internally and can be used by end-user. See dwc_cc.h
  48515. + * - Parameters - Used internally and can be used by end-user. See dwc_params.h
  48516. + * - Notifications - Used internally and can be used by end-user. See dwc_notifier.h
  48517. + * - Lists - Used internally and can be used by end-user. See dwc_list.h
  48518. + * - Memory Debugging - Used internally and can be used by end-user. See dwc_os.h
  48519. + * - Modpow - Used internally only. See dwc_modpow.h
  48520. + * - DH - Used internally only. See dwc_dh.h
  48521. + * - Crypto - Used internally only. See dwc_crypto.h
  48522. + *
  48523. + *
  48524. + * @section prereq Prerequistes For dwc_os.h
  48525. + * @subsection types Data Types
  48526. + *
  48527. + * The dwc_os.h file assumes that several low-level data types are pre defined for the
  48528. + * compilation environment. These data types are:
  48529. + *
  48530. + * - uint8_t - unsigned 8-bit data type
  48531. + * - int8_t - signed 8-bit data type
  48532. + * - uint16_t - unsigned 16-bit data type
  48533. + * - int16_t - signed 16-bit data type
  48534. + * - uint32_t - unsigned 32-bit data type
  48535. + * - int32_t - signed 32-bit data type
  48536. + * - uint64_t - unsigned 64-bit data type
  48537. + * - int64_t - signed 64-bit data type
  48538. + *
  48539. + * Ensure that these are defined before using dwc_os.h. The easiest way to do
  48540. + * that is to modify the top of the file to include the appropriate header.
  48541. + * This is already done for the Linux environment. If the DWC_LINUX macro is
  48542. + * defined, the correct header will be added. A standard header <stdint.h> is
  48543. + * also used for environments where standard C headers are available.
  48544. + *
  48545. + * @subsection stdarg Variable Arguments
  48546. + *
  48547. + * Variable arguments are provided by a standard C header <stdarg.h>. it is
  48548. + * available in Both the Linux and ANSI C enviornment. An equivalent must be
  48549. + * provided in your enviornment in order to use dwc_os.h with the debug and
  48550. + * tracing message functionality.
  48551. + *
  48552. + * @subsection thread Threading
  48553. + *
  48554. + * WUDEV Core must be run on an operating system that provides for multiple
  48555. + * threads/processes. Threading can be implemented in many ways, even in
  48556. + * embedded systems without an operating system. At the bare minimum, the
  48557. + * system should be able to start any number of processes at any time to handle
  48558. + * special work. It need not be a pre-emptive system. Process context can
  48559. + * change upon a call to a blocking function. The hardware interrupt context
  48560. + * that calls the module's ISR() function must be differentiable from process
  48561. + * context, even if your processes are impemented via a hardware interrupt.
  48562. + * Further locking mechanism between process must exist (or be implemented), and
  48563. + * process context must have a way to disable interrupts for a period of time to
  48564. + * lock them out. If all of this exists, the functions in dwc_os.h related to
  48565. + * threading should be able to be implemented with the defined behavior.
  48566. + *
  48567. + */
  48568. +
  48569. +#ifdef __cplusplus
  48570. +}
  48571. +#endif
  48572. +
  48573. +#endif /* _DWC_OS_H_ */
  48574. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/Makefile linux-rpi/drivers/usb/host/dwc_common_port/Makefile
  48575. --- linux-3.12.18/drivers/usb/host/dwc_common_port/Makefile 1970-01-01 01:00:00.000000000 +0100
  48576. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile 2014-04-24 16:04:39.811124176 +0200
  48577. @@ -0,0 +1,58 @@
  48578. +#
  48579. +# Makefile for DWC_common library
  48580. +#
  48581. +
  48582. +ifneq ($(KERNELRELEASE),)
  48583. +
  48584. +ccflags-y += -DDWC_LINUX
  48585. +#ccflags-y += -DDEBUG
  48586. +#ccflags-y += -DDWC_DEBUG_REGS
  48587. +#ccflags-y += -DDWC_DEBUG_MEMORY
  48588. +
  48589. +ccflags-y += -DDWC_LIBMODULE
  48590. +ccflags-y += -DDWC_CCLIB
  48591. +#ccflags-y += -DDWC_CRYPTOLIB
  48592. +ccflags-y += -DDWC_NOTIFYLIB
  48593. +ccflags-y += -DDWC_UTFLIB
  48594. +
  48595. +obj-$(CONFIG_USB_DWCOTG) += dwc_common_port_lib.o
  48596. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  48597. + dwc_crypto.o dwc_notifier.o \
  48598. + dwc_common_linux.o dwc_mem.o
  48599. +
  48600. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  48601. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  48602. +
  48603. +ifneq ($(kernrel3),2.6.20)
  48604. +# grayg - I only know that we use ccflags-y in 2.6.31 actually
  48605. +ccflags-y += $(CPPFLAGS)
  48606. +endif
  48607. +
  48608. +else
  48609. +
  48610. +#ifeq ($(KDIR),)
  48611. +#$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  48612. +#endif
  48613. +
  48614. +ifeq ($(ARCH),)
  48615. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  48616. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  48617. +endif
  48618. +
  48619. +ifeq ($(DOXYGEN),)
  48620. +DOXYGEN := doxygen
  48621. +endif
  48622. +
  48623. +default:
  48624. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  48625. +
  48626. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  48627. + $(DOXYGEN) doc/doxygen.cfg
  48628. +
  48629. +tags: $(wildcard *.[hc])
  48630. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  48631. +
  48632. +endif
  48633. +
  48634. +clean:
  48635. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  48636. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/Makefile.fbsd linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd
  48637. --- linux-3.12.18/drivers/usb/host/dwc_common_port/Makefile.fbsd 1970-01-01 01:00:00.000000000 +0100
  48638. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd 2014-04-24 15:35:04.169565731 +0200
  48639. @@ -0,0 +1,17 @@
  48640. +CFLAGS += -I/sys/i386/compile/GENERIC -I/sys/i386/include -I/usr/include
  48641. +CFLAGS += -DDWC_FREEBSD
  48642. +CFLAGS += -DDEBUG
  48643. +#CFLAGS += -DDWC_DEBUG_REGS
  48644. +#CFLAGS += -DDWC_DEBUG_MEMORY
  48645. +
  48646. +#CFLAGS += -DDWC_LIBMODULE
  48647. +#CFLAGS += -DDWC_CCLIB
  48648. +#CFLAGS += -DDWC_CRYPTOLIB
  48649. +#CFLAGS += -DDWC_NOTIFYLIB
  48650. +#CFLAGS += -DDWC_UTFLIB
  48651. +
  48652. +KMOD = dwc_common_port_lib
  48653. +SRCS = dwc_cc.c dwc_modpow.c dwc_dh.c dwc_crypto.c dwc_notifier.c \
  48654. + dwc_common_fbsd.c dwc_mem.c
  48655. +
  48656. +.include <bsd.kmod.mk>
  48657. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/Makefile.linux linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux
  48658. --- linux-3.12.18/drivers/usb/host/dwc_common_port/Makefile.linux 1970-01-01 01:00:00.000000000 +0100
  48659. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux 2014-04-24 15:35:04.169565731 +0200
  48660. @@ -0,0 +1,49 @@
  48661. +#
  48662. +# Makefile for DWC_common library
  48663. +#
  48664. +ifneq ($(KERNELRELEASE),)
  48665. +
  48666. +ccflags-y += -DDWC_LINUX
  48667. +#ccflags-y += -DDEBUG
  48668. +#ccflags-y += -DDWC_DEBUG_REGS
  48669. +#ccflags-y += -DDWC_DEBUG_MEMORY
  48670. +
  48671. +ccflags-y += -DDWC_LIBMODULE
  48672. +ccflags-y += -DDWC_CCLIB
  48673. +ccflags-y += -DDWC_CRYPTOLIB
  48674. +ccflags-y += -DDWC_NOTIFYLIB
  48675. +ccflags-y += -DDWC_UTFLIB
  48676. +
  48677. +obj-m := dwc_common_port_lib.o
  48678. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  48679. + dwc_crypto.o dwc_notifier.o \
  48680. + dwc_common_linux.o dwc_mem.o
  48681. +
  48682. +else
  48683. +
  48684. +ifeq ($(KDIR),)
  48685. +$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  48686. +endif
  48687. +
  48688. +ifeq ($(ARCH),)
  48689. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  48690. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  48691. +endif
  48692. +
  48693. +ifeq ($(DOXYGEN),)
  48694. +DOXYGEN := doxygen
  48695. +endif
  48696. +
  48697. +default:
  48698. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  48699. +
  48700. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  48701. + $(DOXYGEN) doc/doxygen.cfg
  48702. +
  48703. +tags: $(wildcard *.[hc])
  48704. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  48705. +
  48706. +endif
  48707. +
  48708. +clean:
  48709. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  48710. diff -Nur linux-3.12.18/drivers/usb/host/dwc_common_port/usb.h linux-rpi/drivers/usb/host/dwc_common_port/usb.h
  48711. --- linux-3.12.18/drivers/usb/host/dwc_common_port/usb.h 1970-01-01 01:00:00.000000000 +0100
  48712. +++ linux-rpi/drivers/usb/host/dwc_common_port/usb.h 2014-04-24 15:35:04.169565731 +0200
  48713. @@ -0,0 +1,946 @@
  48714. +/*
  48715. + * Copyright (c) 1998 The NetBSD Foundation, Inc.
  48716. + * All rights reserved.
  48717. + *
  48718. + * This code is derived from software contributed to The NetBSD Foundation
  48719. + * by Lennart Augustsson (lennart@augustsson.net) at
  48720. + * Carlstedt Research & Technology.
  48721. + *
  48722. + * Redistribution and use in source and binary forms, with or without
  48723. + * modification, are permitted provided that the following conditions
  48724. + * are met:
  48725. + * 1. Redistributions of source code must retain the above copyright
  48726. + * notice, this list of conditions and the following disclaimer.
  48727. + * 2. Redistributions in binary form must reproduce the above copyright
  48728. + * notice, this list of conditions and the following disclaimer in the
  48729. + * documentation and/or other materials provided with the distribution.
  48730. + * 3. All advertising materials mentioning features or use of this software
  48731. + * must display the following acknowledgement:
  48732. + * This product includes software developed by the NetBSD
  48733. + * Foundation, Inc. and its contributors.
  48734. + * 4. Neither the name of The NetBSD Foundation nor the names of its
  48735. + * contributors may be used to endorse or promote products derived
  48736. + * from this software without specific prior written permission.
  48737. + *
  48738. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  48739. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  48740. + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  48741. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  48742. + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  48743. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  48744. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48745. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  48746. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  48747. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  48748. + * POSSIBILITY OF SUCH DAMAGE.
  48749. + */
  48750. +
  48751. +/* Modified by Synopsys, Inc, 12/12/2007 */
  48752. +
  48753. +
  48754. +#ifndef _USB_H_
  48755. +#define _USB_H_
  48756. +
  48757. +#ifdef __cplusplus
  48758. +extern "C" {
  48759. +#endif
  48760. +
  48761. +/*
  48762. + * The USB records contain some unaligned little-endian word
  48763. + * components. The U[SG]ETW macros take care of both the alignment
  48764. + * and endian problem and should always be used to access non-byte
  48765. + * values.
  48766. + */
  48767. +typedef u_int8_t uByte;
  48768. +typedef u_int8_t uWord[2];
  48769. +typedef u_int8_t uDWord[4];
  48770. +
  48771. +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  48772. +#define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  48773. +#define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  48774. + ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  48775. +
  48776. +#if 1
  48777. +#define UGETW(w) ((w)[0] | ((w)[1] << 8))
  48778. +#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  48779. +#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  48780. +#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  48781. + (w)[1] = (u_int8_t)((v) >> 8), \
  48782. + (w)[2] = (u_int8_t)((v) >> 16), \
  48783. + (w)[3] = (u_int8_t)((v) >> 24))
  48784. +#else
  48785. +/*
  48786. + * On little-endian machines that can handle unanliged accesses
  48787. + * (e.g. i386) these macros can be replaced by the following.
  48788. + */
  48789. +#define UGETW(w) (*(u_int16_t *)(w))
  48790. +#define USETW(w,v) (*(u_int16_t *)(w) = (v))
  48791. +#define UGETDW(w) (*(u_int32_t *)(w))
  48792. +#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  48793. +#endif
  48794. +
  48795. +/*
  48796. + * Macros for accessing UAS IU fields, which are big-endian
  48797. + */
  48798. +#define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  48799. +#define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  48800. +#define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  48801. + ((x) >> 8) & 0xff, (x) & 0xff }
  48802. +#define IUGETW(w) (((w)[0] << 8) | (w)[1])
  48803. +#define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  48804. +#define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  48805. +#define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  48806. + (w)[1] = (u_int8_t)((v) >> 16), \
  48807. + (w)[2] = (u_int8_t)((v) >> 8), \
  48808. + (w)[3] = (u_int8_t)(v))
  48809. +
  48810. +#define UPACKED __attribute__((__packed__))
  48811. +
  48812. +typedef struct {
  48813. + uByte bmRequestType;
  48814. + uByte bRequest;
  48815. + uWord wValue;
  48816. + uWord wIndex;
  48817. + uWord wLength;
  48818. +} UPACKED usb_device_request_t;
  48819. +
  48820. +#define UT_GET_DIR(a) ((a) & 0x80)
  48821. +#define UT_WRITE 0x00
  48822. +#define UT_READ 0x80
  48823. +
  48824. +#define UT_GET_TYPE(a) ((a) & 0x60)
  48825. +#define UT_STANDARD 0x00
  48826. +#define UT_CLASS 0x20
  48827. +#define UT_VENDOR 0x40
  48828. +
  48829. +#define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  48830. +#define UT_DEVICE 0x00
  48831. +#define UT_INTERFACE 0x01
  48832. +#define UT_ENDPOINT 0x02
  48833. +#define UT_OTHER 0x03
  48834. +
  48835. +#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  48836. +#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  48837. +#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  48838. +#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  48839. +#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  48840. +#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  48841. +#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  48842. +#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  48843. +#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  48844. +#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  48845. +#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  48846. +#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  48847. +#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  48848. +#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  48849. +#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  48850. +#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  48851. +#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  48852. +#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  48853. +#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  48854. +#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  48855. +#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  48856. +#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  48857. +
  48858. +/* Requests */
  48859. +#define UR_GET_STATUS 0x00
  48860. +#define USTAT_STANDARD_STATUS 0x00
  48861. +#define WUSTAT_WUSB_FEATURE 0x01
  48862. +#define WUSTAT_CHANNEL_INFO 0x02
  48863. +#define WUSTAT_RECEIVED_DATA 0x03
  48864. +#define WUSTAT_MAS_AVAILABILITY 0x04
  48865. +#define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  48866. +#define UR_CLEAR_FEATURE 0x01
  48867. +#define UR_SET_FEATURE 0x03
  48868. +#define UR_SET_AND_TEST_FEATURE 0x0c
  48869. +#define UR_SET_ADDRESS 0x05
  48870. +#define UR_GET_DESCRIPTOR 0x06
  48871. +#define UDESC_DEVICE 0x01
  48872. +#define UDESC_CONFIG 0x02
  48873. +#define UDESC_STRING 0x03
  48874. +#define UDESC_INTERFACE 0x04
  48875. +#define UDESC_ENDPOINT 0x05
  48876. +#define UDESC_SS_USB_COMPANION 0x30
  48877. +#define UDESC_DEVICE_QUALIFIER 0x06
  48878. +#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  48879. +#define UDESC_INTERFACE_POWER 0x08
  48880. +#define UDESC_OTG 0x09
  48881. +#define WUDESC_SECURITY 0x0c
  48882. +#define WUDESC_KEY 0x0d
  48883. +#define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  48884. +#define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  48885. +#define WUD_KEY_TYPE_ASSOC 0x01
  48886. +#define WUD_KEY_TYPE_GTK 0x02
  48887. +#define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  48888. +#define WUD_KEY_ORIGIN_HOST 0x00
  48889. +#define WUD_KEY_ORIGIN_DEVICE 0x01
  48890. +#define WUDESC_ENCRYPTION_TYPE 0x0e
  48891. +#define WUDESC_BOS 0x0f
  48892. +#define WUDESC_DEVICE_CAPABILITY 0x10
  48893. +#define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  48894. +#define UDESC_BOS 0x0f
  48895. +#define UDESC_DEVICE_CAPABILITY 0x10
  48896. +#define UDESC_CS_DEVICE 0x21 /* class specific */
  48897. +#define UDESC_CS_CONFIG 0x22
  48898. +#define UDESC_CS_STRING 0x23
  48899. +#define UDESC_CS_INTERFACE 0x24
  48900. +#define UDESC_CS_ENDPOINT 0x25
  48901. +#define UDESC_HUB 0x29
  48902. +#define UR_SET_DESCRIPTOR 0x07
  48903. +#define UR_GET_CONFIG 0x08
  48904. +#define UR_SET_CONFIG 0x09
  48905. +#define UR_GET_INTERFACE 0x0a
  48906. +#define UR_SET_INTERFACE 0x0b
  48907. +#define UR_SYNCH_FRAME 0x0c
  48908. +#define WUR_SET_ENCRYPTION 0x0d
  48909. +#define WUR_GET_ENCRYPTION 0x0e
  48910. +#define WUR_SET_HANDSHAKE 0x0f
  48911. +#define WUR_GET_HANDSHAKE 0x10
  48912. +#define WUR_SET_CONNECTION 0x11
  48913. +#define WUR_SET_SECURITY_DATA 0x12
  48914. +#define WUR_GET_SECURITY_DATA 0x13
  48915. +#define WUR_SET_WUSB_DATA 0x14
  48916. +#define WUDATA_DRPIE_INFO 0x01
  48917. +#define WUDATA_TRANSMIT_DATA 0x02
  48918. +#define WUDATA_TRANSMIT_PARAMS 0x03
  48919. +#define WUDATA_RECEIVE_PARAMS 0x04
  48920. +#define WUDATA_TRANSMIT_POWER 0x05
  48921. +#define WUR_LOOPBACK_DATA_WRITE 0x15
  48922. +#define WUR_LOOPBACK_DATA_READ 0x16
  48923. +#define WUR_SET_INTERFACE_DS 0x17
  48924. +
  48925. +/* Feature numbers */
  48926. +#define UF_ENDPOINT_HALT 0
  48927. +#define UF_DEVICE_REMOTE_WAKEUP 1
  48928. +#define UF_TEST_MODE 2
  48929. +#define UF_DEVICE_B_HNP_ENABLE 3
  48930. +#define UF_DEVICE_A_HNP_SUPPORT 4
  48931. +#define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  48932. +#define WUF_WUSB 3
  48933. +#define WUF_TX_DRPIE 0x0
  48934. +#define WUF_DEV_XMIT_PACKET 0x1
  48935. +#define WUF_COUNT_PACKETS 0x2
  48936. +#define WUF_CAPTURE_PACKETS 0x3
  48937. +#define UF_FUNCTION_SUSPEND 0
  48938. +#define UF_U1_ENABLE 48
  48939. +#define UF_U2_ENABLE 49
  48940. +#define UF_LTM_ENABLE 50
  48941. +
  48942. +/* Class requests from the USB 2.0 hub spec, table 11-15 */
  48943. +#define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  48944. +#define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  48945. +#define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  48946. +#define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  48947. +#define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  48948. +#define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  48949. +#define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  48950. +#define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  48951. +
  48952. +#ifdef _MSC_VER
  48953. +#include <pshpack1.h>
  48954. +#endif
  48955. +
  48956. +typedef struct {
  48957. + uByte bLength;
  48958. + uByte bDescriptorType;
  48959. + uByte bDescriptorSubtype;
  48960. +} UPACKED usb_descriptor_t;
  48961. +
  48962. +typedef struct {
  48963. + uByte bLength;
  48964. + uByte bDescriptorType;
  48965. +} UPACKED usb_descriptor_header_t;
  48966. +
  48967. +typedef struct {
  48968. + uByte bLength;
  48969. + uByte bDescriptorType;
  48970. + uWord bcdUSB;
  48971. +#define UD_USB_2_0 0x0200
  48972. +#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  48973. + uByte bDeviceClass;
  48974. + uByte bDeviceSubClass;
  48975. + uByte bDeviceProtocol;
  48976. + uByte bMaxPacketSize;
  48977. + /* The fields below are not part of the initial descriptor. */
  48978. + uWord idVendor;
  48979. + uWord idProduct;
  48980. + uWord bcdDevice;
  48981. + uByte iManufacturer;
  48982. + uByte iProduct;
  48983. + uByte iSerialNumber;
  48984. + uByte bNumConfigurations;
  48985. +} UPACKED usb_device_descriptor_t;
  48986. +#define USB_DEVICE_DESCRIPTOR_SIZE 18
  48987. +
  48988. +typedef struct {
  48989. + uByte bLength;
  48990. + uByte bDescriptorType;
  48991. + uWord wTotalLength;
  48992. + uByte bNumInterface;
  48993. + uByte bConfigurationValue;
  48994. + uByte iConfiguration;
  48995. +#define UC_ATT_ONE (1 << 7) /* must be set */
  48996. +#define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  48997. +#define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  48998. +#define UC_ATT_BATTERY (1 << 4) /* battery powered */
  48999. + uByte bmAttributes;
  49000. +#define UC_BUS_POWERED 0x80
  49001. +#define UC_SELF_POWERED 0x40
  49002. +#define UC_REMOTE_WAKEUP 0x20
  49003. + uByte bMaxPower; /* max current in 2 mA units */
  49004. +#define UC_POWER_FACTOR 2
  49005. +} UPACKED usb_config_descriptor_t;
  49006. +#define USB_CONFIG_DESCRIPTOR_SIZE 9
  49007. +
  49008. +typedef struct {
  49009. + uByte bLength;
  49010. + uByte bDescriptorType;
  49011. + uByte bInterfaceNumber;
  49012. + uByte bAlternateSetting;
  49013. + uByte bNumEndpoints;
  49014. + uByte bInterfaceClass;
  49015. + uByte bInterfaceSubClass;
  49016. + uByte bInterfaceProtocol;
  49017. + uByte iInterface;
  49018. +} UPACKED usb_interface_descriptor_t;
  49019. +#define USB_INTERFACE_DESCRIPTOR_SIZE 9
  49020. +
  49021. +typedef struct {
  49022. + uByte bLength;
  49023. + uByte bDescriptorType;
  49024. + uByte bEndpointAddress;
  49025. +#define UE_GET_DIR(a) ((a) & 0x80)
  49026. +#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  49027. +#define UE_DIR_IN 0x80
  49028. +#define UE_DIR_OUT 0x00
  49029. +#define UE_ADDR 0x0f
  49030. +#define UE_GET_ADDR(a) ((a) & UE_ADDR)
  49031. + uByte bmAttributes;
  49032. +#define UE_XFERTYPE 0x03
  49033. +#define UE_CONTROL 0x00
  49034. +#define UE_ISOCHRONOUS 0x01
  49035. +#define UE_BULK 0x02
  49036. +#define UE_INTERRUPT 0x03
  49037. +#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  49038. +#define UE_ISO_TYPE 0x0c
  49039. +#define UE_ISO_ASYNC 0x04
  49040. +#define UE_ISO_ADAPT 0x08
  49041. +#define UE_ISO_SYNC 0x0c
  49042. +#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  49043. + uWord wMaxPacketSize;
  49044. + uByte bInterval;
  49045. +} UPACKED usb_endpoint_descriptor_t;
  49046. +#define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  49047. +
  49048. +typedef struct ss_endpoint_companion_descriptor {
  49049. + uByte bLength;
  49050. + uByte bDescriptorType;
  49051. + uByte bMaxBurst;
  49052. +#define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  49053. +#define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  49054. +#define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  49055. +#define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  49056. + uByte bmAttributes;
  49057. + uWord wBytesPerInterval;
  49058. +} UPACKED ss_endpoint_companion_descriptor_t;
  49059. +#define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  49060. +
  49061. +typedef struct {
  49062. + uByte bLength;
  49063. + uByte bDescriptorType;
  49064. + uWord bString[127];
  49065. +} UPACKED usb_string_descriptor_t;
  49066. +#define USB_MAX_STRING_LEN 128
  49067. +#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  49068. +
  49069. +/* Hub specific request */
  49070. +#define UR_GET_BUS_STATE 0x02
  49071. +#define UR_CLEAR_TT_BUFFER 0x08
  49072. +#define UR_RESET_TT 0x09
  49073. +#define UR_GET_TT_STATE 0x0a
  49074. +#define UR_STOP_TT 0x0b
  49075. +
  49076. +/* Hub features */
  49077. +#define UHF_C_HUB_LOCAL_POWER 0
  49078. +#define UHF_C_HUB_OVER_CURRENT 1
  49079. +#define UHF_PORT_CONNECTION 0
  49080. +#define UHF_PORT_ENABLE 1
  49081. +#define UHF_PORT_SUSPEND 2
  49082. +#define UHF_PORT_OVER_CURRENT 3
  49083. +#define UHF_PORT_RESET 4
  49084. +#define UHF_PORT_L1 5
  49085. +#define UHF_PORT_POWER 8
  49086. +#define UHF_PORT_LOW_SPEED 9
  49087. +#define UHF_PORT_HIGH_SPEED 10
  49088. +#define UHF_C_PORT_CONNECTION 16
  49089. +#define UHF_C_PORT_ENABLE 17
  49090. +#define UHF_C_PORT_SUSPEND 18
  49091. +#define UHF_C_PORT_OVER_CURRENT 19
  49092. +#define UHF_C_PORT_RESET 20
  49093. +#define UHF_C_PORT_L1 23
  49094. +#define UHF_PORT_TEST 21
  49095. +#define UHF_PORT_INDICATOR 22
  49096. +
  49097. +typedef struct {
  49098. + uByte bDescLength;
  49099. + uByte bDescriptorType;
  49100. + uByte bNbrPorts;
  49101. + uWord wHubCharacteristics;
  49102. +#define UHD_PWR 0x0003
  49103. +#define UHD_PWR_GANGED 0x0000
  49104. +#define UHD_PWR_INDIVIDUAL 0x0001
  49105. +#define UHD_PWR_NO_SWITCH 0x0002
  49106. +#define UHD_COMPOUND 0x0004
  49107. +#define UHD_OC 0x0018
  49108. +#define UHD_OC_GLOBAL 0x0000
  49109. +#define UHD_OC_INDIVIDUAL 0x0008
  49110. +#define UHD_OC_NONE 0x0010
  49111. +#define UHD_TT_THINK 0x0060
  49112. +#define UHD_TT_THINK_8 0x0000
  49113. +#define UHD_TT_THINK_16 0x0020
  49114. +#define UHD_TT_THINK_24 0x0040
  49115. +#define UHD_TT_THINK_32 0x0060
  49116. +#define UHD_PORT_IND 0x0080
  49117. + uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  49118. +#define UHD_PWRON_FACTOR 2
  49119. + uByte bHubContrCurrent;
  49120. + uByte DeviceRemovable[32]; /* max 255 ports */
  49121. +#define UHD_NOT_REMOV(desc, i) \
  49122. + (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  49123. + /* deprecated */ uByte PortPowerCtrlMask[1];
  49124. +} UPACKED usb_hub_descriptor_t;
  49125. +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  49126. +
  49127. +typedef struct {
  49128. + uByte bLength;
  49129. + uByte bDescriptorType;
  49130. + uWord bcdUSB;
  49131. + uByte bDeviceClass;
  49132. + uByte bDeviceSubClass;
  49133. + uByte bDeviceProtocol;
  49134. + uByte bMaxPacketSize0;
  49135. + uByte bNumConfigurations;
  49136. + uByte bReserved;
  49137. +} UPACKED usb_device_qualifier_t;
  49138. +#define USB_DEVICE_QUALIFIER_SIZE 10
  49139. +
  49140. +typedef struct {
  49141. + uByte bLength;
  49142. + uByte bDescriptorType;
  49143. + uByte bmAttributes;
  49144. +#define UOTG_SRP 0x01
  49145. +#define UOTG_HNP 0x02
  49146. +} UPACKED usb_otg_descriptor_t;
  49147. +
  49148. +/* OTG feature selectors */
  49149. +#define UOTG_B_HNP_ENABLE 3
  49150. +#define UOTG_A_HNP_SUPPORT 4
  49151. +#define UOTG_A_ALT_HNP_SUPPORT 5
  49152. +
  49153. +typedef struct {
  49154. + uWord wStatus;
  49155. +/* Device status flags */
  49156. +#define UDS_SELF_POWERED 0x0001
  49157. +#define UDS_REMOTE_WAKEUP 0x0002
  49158. +/* Endpoint status flags */
  49159. +#define UES_HALT 0x0001
  49160. +} UPACKED usb_status_t;
  49161. +
  49162. +typedef struct {
  49163. + uWord wHubStatus;
  49164. +#define UHS_LOCAL_POWER 0x0001
  49165. +#define UHS_OVER_CURRENT 0x0002
  49166. + uWord wHubChange;
  49167. +} UPACKED usb_hub_status_t;
  49168. +
  49169. +typedef struct {
  49170. + uWord wPortStatus;
  49171. +#define UPS_CURRENT_CONNECT_STATUS 0x0001
  49172. +#define UPS_PORT_ENABLED 0x0002
  49173. +#define UPS_SUSPEND 0x0004
  49174. +#define UPS_OVERCURRENT_INDICATOR 0x0008
  49175. +#define UPS_RESET 0x0010
  49176. +#define UPS_PORT_POWER 0x0100
  49177. +#define UPS_LOW_SPEED 0x0200
  49178. +#define UPS_HIGH_SPEED 0x0400
  49179. +#define UPS_PORT_TEST 0x0800
  49180. +#define UPS_PORT_INDICATOR 0x1000
  49181. + uWord wPortChange;
  49182. +#define UPS_C_CONNECT_STATUS 0x0001
  49183. +#define UPS_C_PORT_ENABLED 0x0002
  49184. +#define UPS_C_SUSPEND 0x0004
  49185. +#define UPS_C_OVERCURRENT_INDICATOR 0x0008
  49186. +#define UPS_C_PORT_RESET 0x0010
  49187. +} UPACKED usb_port_status_t;
  49188. +
  49189. +#ifdef _MSC_VER
  49190. +#include <poppack.h>
  49191. +#endif
  49192. +
  49193. +/* Device class codes */
  49194. +#define UDCLASS_IN_INTERFACE 0x00
  49195. +#define UDCLASS_COMM 0x02
  49196. +#define UDCLASS_HUB 0x09
  49197. +#define UDSUBCLASS_HUB 0x00
  49198. +#define UDPROTO_FSHUB 0x00
  49199. +#define UDPROTO_HSHUBSTT 0x01
  49200. +#define UDPROTO_HSHUBMTT 0x02
  49201. +#define UDCLASS_DIAGNOSTIC 0xdc
  49202. +#define UDCLASS_WIRELESS 0xe0
  49203. +#define UDSUBCLASS_RF 0x01
  49204. +#define UDPROTO_BLUETOOTH 0x01
  49205. +#define UDCLASS_VENDOR 0xff
  49206. +
  49207. +/* Interface class codes */
  49208. +#define UICLASS_UNSPEC 0x00
  49209. +
  49210. +#define UICLASS_AUDIO 0x01
  49211. +#define UISUBCLASS_AUDIOCONTROL 1
  49212. +#define UISUBCLASS_AUDIOSTREAM 2
  49213. +#define UISUBCLASS_MIDISTREAM 3
  49214. +
  49215. +#define UICLASS_CDC 0x02 /* communication */
  49216. +#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  49217. +#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  49218. +#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  49219. +#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  49220. +#define UISUBCLASS_CAPI_CONTROLMODEL 5
  49221. +#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  49222. +#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  49223. +#define UIPROTO_CDC_AT 1
  49224. +
  49225. +#define UICLASS_HID 0x03
  49226. +#define UISUBCLASS_BOOT 1
  49227. +#define UIPROTO_BOOT_KEYBOARD 1
  49228. +
  49229. +#define UICLASS_PHYSICAL 0x05
  49230. +
  49231. +#define UICLASS_IMAGE 0x06
  49232. +
  49233. +#define UICLASS_PRINTER 0x07
  49234. +#define UISUBCLASS_PRINTER 1
  49235. +#define UIPROTO_PRINTER_UNI 1
  49236. +#define UIPROTO_PRINTER_BI 2
  49237. +#define UIPROTO_PRINTER_1284 3
  49238. +
  49239. +#define UICLASS_MASS 0x08
  49240. +#define UISUBCLASS_RBC 1
  49241. +#define UISUBCLASS_SFF8020I 2
  49242. +#define UISUBCLASS_QIC157 3
  49243. +#define UISUBCLASS_UFI 4
  49244. +#define UISUBCLASS_SFF8070I 5
  49245. +#define UISUBCLASS_SCSI 6
  49246. +#define UIPROTO_MASS_CBI_I 0
  49247. +#define UIPROTO_MASS_CBI 1
  49248. +#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  49249. +#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  49250. +
  49251. +#define UICLASS_HUB 0x09
  49252. +#define UISUBCLASS_HUB 0
  49253. +#define UIPROTO_FSHUB 0
  49254. +#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  49255. +#define UIPROTO_HSHUBMTT 1
  49256. +
  49257. +#define UICLASS_CDC_DATA 0x0a
  49258. +#define UISUBCLASS_DATA 0
  49259. +#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  49260. +#define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  49261. +#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  49262. +#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  49263. +#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  49264. +#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  49265. +#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  49266. +#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  49267. +#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  49268. +#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  49269. +#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  49270. +#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  49271. +#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  49272. +
  49273. +#define UICLASS_SMARTCARD 0x0b
  49274. +
  49275. +/*#define UICLASS_FIRM_UPD 0x0c*/
  49276. +
  49277. +#define UICLASS_SECURITY 0x0d
  49278. +
  49279. +#define UICLASS_DIAGNOSTIC 0xdc
  49280. +
  49281. +#define UICLASS_WIRELESS 0xe0
  49282. +#define UISUBCLASS_RF 0x01
  49283. +#define UIPROTO_BLUETOOTH 0x01
  49284. +
  49285. +#define UICLASS_APPL_SPEC 0xfe
  49286. +#define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  49287. +#define UISUBCLASS_IRDA 2
  49288. +#define UIPROTO_IRDA 0
  49289. +
  49290. +#define UICLASS_VENDOR 0xff
  49291. +
  49292. +#define USB_HUB_MAX_DEPTH 5
  49293. +
  49294. +/*
  49295. + * Minimum time a device needs to be powered down to go through
  49296. + * a power cycle. XXX Are these time in the spec?
  49297. + */
  49298. +#define USB_POWER_DOWN_TIME 200 /* ms */
  49299. +#define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  49300. +
  49301. +#if 0
  49302. +/* These are the values from the spec. */
  49303. +#define USB_PORT_RESET_DELAY 10 /* ms */
  49304. +#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  49305. +#define USB_PORT_RESET_RECOVERY 10 /* ms */
  49306. +#define USB_PORT_POWERUP_DELAY 100 /* ms */
  49307. +#define USB_SET_ADDRESS_SETTLE 2 /* ms */
  49308. +#define USB_RESUME_DELAY (20*5) /* ms */
  49309. +#define USB_RESUME_WAIT 10 /* ms */
  49310. +#define USB_RESUME_RECOVERY 10 /* ms */
  49311. +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  49312. +#else
  49313. +/* Allow for marginal (i.e. non-conforming) devices. */
  49314. +#define USB_PORT_RESET_DELAY 50 /* ms */
  49315. +#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  49316. +#define USB_PORT_RESET_RECOVERY 250 /* ms */
  49317. +#define USB_PORT_POWERUP_DELAY 300 /* ms */
  49318. +#define USB_SET_ADDRESS_SETTLE 10 /* ms */
  49319. +#define USB_RESUME_DELAY (50*5) /* ms */
  49320. +#define USB_RESUME_WAIT 50 /* ms */
  49321. +#define USB_RESUME_RECOVERY 50 /* ms */
  49322. +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  49323. +#endif
  49324. +
  49325. +#define USB_MIN_POWER 100 /* mA */
  49326. +#define USB_MAX_POWER 500 /* mA */
  49327. +
  49328. +#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  49329. +
  49330. +#define USB_UNCONFIG_NO 0
  49331. +#define USB_UNCONFIG_INDEX (-1)
  49332. +
  49333. +/*** ioctl() related stuff ***/
  49334. +
  49335. +struct usb_ctl_request {
  49336. + int ucr_addr;
  49337. + usb_device_request_t ucr_request;
  49338. + void *ucr_data;
  49339. + int ucr_flags;
  49340. +#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  49341. + int ucr_actlen; /* actual length transferred */
  49342. +};
  49343. +
  49344. +struct usb_alt_interface {
  49345. + int uai_config_index;
  49346. + int uai_interface_index;
  49347. + int uai_alt_no;
  49348. +};
  49349. +
  49350. +#define USB_CURRENT_CONFIG_INDEX (-1)
  49351. +#define USB_CURRENT_ALT_INDEX (-1)
  49352. +
  49353. +struct usb_config_desc {
  49354. + int ucd_config_index;
  49355. + usb_config_descriptor_t ucd_desc;
  49356. +};
  49357. +
  49358. +struct usb_interface_desc {
  49359. + int uid_config_index;
  49360. + int uid_interface_index;
  49361. + int uid_alt_index;
  49362. + usb_interface_descriptor_t uid_desc;
  49363. +};
  49364. +
  49365. +struct usb_endpoint_desc {
  49366. + int ued_config_index;
  49367. + int ued_interface_index;
  49368. + int ued_alt_index;
  49369. + int ued_endpoint_index;
  49370. + usb_endpoint_descriptor_t ued_desc;
  49371. +};
  49372. +
  49373. +struct usb_full_desc {
  49374. + int ufd_config_index;
  49375. + u_int ufd_size;
  49376. + u_char *ufd_data;
  49377. +};
  49378. +
  49379. +struct usb_string_desc {
  49380. + int usd_string_index;
  49381. + int usd_language_id;
  49382. + usb_string_descriptor_t usd_desc;
  49383. +};
  49384. +
  49385. +struct usb_ctl_report_desc {
  49386. + int ucrd_size;
  49387. + u_char ucrd_data[1024]; /* filled data size will vary */
  49388. +};
  49389. +
  49390. +typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  49391. +
  49392. +#define USB_MAX_DEVNAMES 4
  49393. +#define USB_MAX_DEVNAMELEN 16
  49394. +struct usb_device_info {
  49395. + u_int8_t udi_bus;
  49396. + u_int8_t udi_addr; /* device address */
  49397. + usb_event_cookie_t udi_cookie;
  49398. + char udi_product[USB_MAX_STRING_LEN];
  49399. + char udi_vendor[USB_MAX_STRING_LEN];
  49400. + char udi_release[8];
  49401. + u_int16_t udi_productNo;
  49402. + u_int16_t udi_vendorNo;
  49403. + u_int16_t udi_releaseNo;
  49404. + u_int8_t udi_class;
  49405. + u_int8_t udi_subclass;
  49406. + u_int8_t udi_protocol;
  49407. + u_int8_t udi_config;
  49408. + u_int8_t udi_speed;
  49409. +#define USB_SPEED_UNKNOWN 0
  49410. +#define USB_SPEED_LOW 1
  49411. +#define USB_SPEED_FULL 2
  49412. +#define USB_SPEED_HIGH 3
  49413. +#define USB_SPEED_VARIABLE 4
  49414. +#define USB_SPEED_SUPER 5
  49415. + int udi_power; /* power consumption in mA, 0 if selfpowered */
  49416. + int udi_nports;
  49417. + char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  49418. + u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  49419. +#define USB_PORT_ENABLED 0xff
  49420. +#define USB_PORT_SUSPENDED 0xfe
  49421. +#define USB_PORT_POWERED 0xfd
  49422. +#define USB_PORT_DISABLED 0xfc
  49423. +};
  49424. +
  49425. +struct usb_ctl_report {
  49426. + int ucr_report;
  49427. + u_char ucr_data[1024]; /* filled data size will vary */
  49428. +};
  49429. +
  49430. +struct usb_device_stats {
  49431. + u_long uds_requests[4]; /* indexed by transfer type UE_* */
  49432. +};
  49433. +
  49434. +#define WUSB_MIN_IE 0x80
  49435. +#define WUSB_WCTA_IE 0x80
  49436. +#define WUSB_WCONNECTACK_IE 0x81
  49437. +#define WUSB_WHOSTINFO_IE 0x82
  49438. +#define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  49439. +#define WUHI_CA_RECONN 0x00
  49440. +#define WUHI_CA_LIMITED 0x01
  49441. +#define WUHI_CA_ALL 0x03
  49442. +#define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  49443. +#define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  49444. +#define WUSB_WDEV_DISCONNECT_IE 0x84
  49445. +#define WUSB_WHOST_DISCONNECT_IE 0x85
  49446. +#define WUSB_WRELEASE_CHANNEL_IE 0x86
  49447. +#define WUSB_WWORK_IE 0x87
  49448. +#define WUSB_WCHANNEL_STOP_IE 0x88
  49449. +#define WUSB_WDEV_KEEPALIVE_IE 0x89
  49450. +#define WUSB_WISOCH_DISCARD_IE 0x8A
  49451. +#define WUSB_WRESETDEVICE_IE 0x8B
  49452. +#define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  49453. +#define WUSB_MAX_IE 0x8C
  49454. +
  49455. +/* Device Notification Types */
  49456. +
  49457. +#define WUSB_DN_MIN 0x01
  49458. +#define WUSB_DN_CONNECT 0x01
  49459. +# define WUSB_DA_OLDCONN 0x00
  49460. +# define WUSB_DA_NEWCONN 0x01
  49461. +# define WUSB_DA_SELF_BEACON 0x02
  49462. +# define WUSB_DA_DIR_BEACON 0x04
  49463. +# define WUSB_DA_NO_BEACON 0x06
  49464. +#define WUSB_DN_DISCONNECT 0x02
  49465. +#define WUSB_DN_EPRDY 0x03
  49466. +#define WUSB_DN_MASAVAILCHANGED 0x04
  49467. +#define WUSB_DN_REMOTEWAKEUP 0x05
  49468. +#define WUSB_DN_SLEEP 0x06
  49469. +#define WUSB_DN_ALIVE 0x07
  49470. +#define WUSB_DN_MAX 0x07
  49471. +
  49472. +#ifdef _MSC_VER
  49473. +#include <pshpack1.h>
  49474. +#endif
  49475. +
  49476. +/* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  49477. +typedef struct wusb_hndshk_data {
  49478. + uByte bMessageNumber;
  49479. + uByte bStatus;
  49480. + uByte tTKID[3];
  49481. + uByte bReserved;
  49482. + uByte CDID[16];
  49483. + uByte Nonce[16];
  49484. + uByte MIC[8];
  49485. +} UPACKED wusb_hndshk_data_t;
  49486. +#define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  49487. +
  49488. +/* WUSB Connection Context */
  49489. +typedef struct wusb_conn_context {
  49490. + uByte CHID [16];
  49491. + uByte CDID [16];
  49492. + uByte CK [16];
  49493. +} UPACKED wusb_conn_context_t;
  49494. +
  49495. +/* WUSB Security Descriptor */
  49496. +typedef struct wusb_security_desc {
  49497. + uByte bLength;
  49498. + uByte bDescriptorType;
  49499. + uWord wTotalLength;
  49500. + uByte bNumEncryptionTypes;
  49501. +} UPACKED wusb_security_desc_t;
  49502. +
  49503. +/* WUSB Encryption Type Descriptor */
  49504. +typedef struct wusb_encrypt_type_desc {
  49505. + uByte bLength;
  49506. + uByte bDescriptorType;
  49507. +
  49508. + uByte bEncryptionType;
  49509. +#define WUETD_UNSECURE 0
  49510. +#define WUETD_WIRED 1
  49511. +#define WUETD_CCM_1 2
  49512. +#define WUETD_RSA_1 3
  49513. +
  49514. + uByte bEncryptionValue;
  49515. + uByte bAuthKeyIndex;
  49516. +} UPACKED wusb_encrypt_type_desc_t;
  49517. +
  49518. +/* WUSB Key Descriptor */
  49519. +typedef struct wusb_key_desc {
  49520. + uByte bLength;
  49521. + uByte bDescriptorType;
  49522. + uByte tTKID[3];
  49523. + uByte bReserved;
  49524. + uByte KeyData[1]; /* variable length */
  49525. +} UPACKED wusb_key_desc_t;
  49526. +
  49527. +/* WUSB BOS Descriptor (Binary device Object Store) */
  49528. +typedef struct wusb_bos_desc {
  49529. + uByte bLength;
  49530. + uByte bDescriptorType;
  49531. + uWord wTotalLength;
  49532. + uByte bNumDeviceCaps;
  49533. +} UPACKED wusb_bos_desc_t;
  49534. +
  49535. +#define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  49536. +typedef struct usb_dev_cap_20_ext_desc {
  49537. + uByte bLength;
  49538. + uByte bDescriptorType;
  49539. + uByte bDevCapabilityType;
  49540. +#define USB_20_EXT_LPM 0x02
  49541. + uDWord bmAttributes;
  49542. +} UPACKED usb_dev_cap_20_ext_desc_t;
  49543. +
  49544. +#define USB_DEVICE_CAPABILITY_SS_USB 0x03
  49545. +typedef struct usb_dev_cap_ss_usb {
  49546. + uByte bLength;
  49547. + uByte bDescriptorType;
  49548. + uByte bDevCapabilityType;
  49549. +#define USB_DC_SS_USB_LTM_CAPABLE 0x02
  49550. + uByte bmAttributes;
  49551. +#define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  49552. +#define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  49553. +#define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  49554. +#define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  49555. + uWord wSpeedsSupported;
  49556. + uByte bFunctionalitySupport;
  49557. + uByte bU1DevExitLat;
  49558. + uWord wU2DevExitLat;
  49559. +} UPACKED usb_dev_cap_ss_usb_t;
  49560. +
  49561. +#define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  49562. +typedef struct usb_dev_cap_container_id {
  49563. + uByte bLength;
  49564. + uByte bDescriptorType;
  49565. + uByte bDevCapabilityType;
  49566. + uByte bReserved;
  49567. + uByte containerID[16];
  49568. +} UPACKED usb_dev_cap_container_id_t;
  49569. +
  49570. +/* Device Capability Type Codes */
  49571. +#define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  49572. +
  49573. +/* Device Capability Descriptor */
  49574. +typedef struct wusb_dev_cap_desc {
  49575. + uByte bLength;
  49576. + uByte bDescriptorType;
  49577. + uByte bDevCapabilityType;
  49578. + uByte caps[1]; /* Variable length */
  49579. +} UPACKED wusb_dev_cap_desc_t;
  49580. +
  49581. +/* Device Capability Descriptor */
  49582. +typedef struct wusb_dev_cap_uwb_desc {
  49583. + uByte bLength;
  49584. + uByte bDescriptorType;
  49585. + uByte bDevCapabilityType;
  49586. + uByte bmAttributes;
  49587. + uWord wPHYRates; /* Bitmap */
  49588. + uByte bmTFITXPowerInfo;
  49589. + uByte bmFFITXPowerInfo;
  49590. + uWord bmBandGroup;
  49591. + uByte bReserved;
  49592. +} UPACKED wusb_dev_cap_uwb_desc_t;
  49593. +
  49594. +/* Wireless USB Endpoint Companion Descriptor */
  49595. +typedef struct wusb_endpoint_companion_desc {
  49596. + uByte bLength;
  49597. + uByte bDescriptorType;
  49598. + uByte bMaxBurst;
  49599. + uByte bMaxSequence;
  49600. + uWord wMaxStreamDelay;
  49601. + uWord wOverTheAirPacketSize;
  49602. + uByte bOverTheAirInterval;
  49603. + uByte bmCompAttributes;
  49604. +} UPACKED wusb_endpoint_companion_desc_t;
  49605. +
  49606. +/* Wireless USB Numeric Association M1 Data Structure */
  49607. +typedef struct wusb_m1_data {
  49608. + uByte version;
  49609. + uWord langId;
  49610. + uByte deviceFriendlyNameLength;
  49611. + uByte sha_256_m3[32];
  49612. + uByte deviceFriendlyName[256];
  49613. +} UPACKED wusb_m1_data_t;
  49614. +
  49615. +typedef struct wusb_m2_data {
  49616. + uByte version;
  49617. + uWord langId;
  49618. + uByte hostFriendlyNameLength;
  49619. + uByte pkh[384];
  49620. + uByte hostFriendlyName[256];
  49621. +} UPACKED wusb_m2_data_t;
  49622. +
  49623. +typedef struct wusb_m3_data {
  49624. + uByte pkd[384];
  49625. + uByte nd;
  49626. +} UPACKED wusb_m3_data_t;
  49627. +
  49628. +typedef struct wusb_m4_data {
  49629. + uDWord _attributeTypeIdAndLength_1;
  49630. + uWord associationTypeId;
  49631. +
  49632. + uDWord _attributeTypeIdAndLength_2;
  49633. + uWord associationSubTypeId;
  49634. +
  49635. + uDWord _attributeTypeIdAndLength_3;
  49636. + uDWord length;
  49637. +
  49638. + uDWord _attributeTypeIdAndLength_4;
  49639. + uDWord associationStatus;
  49640. +
  49641. + uDWord _attributeTypeIdAndLength_5;
  49642. + uByte chid[16];
  49643. +
  49644. + uDWord _attributeTypeIdAndLength_6;
  49645. + uByte cdid[16];
  49646. +
  49647. + uDWord _attributeTypeIdAndLength_7;
  49648. + uByte bandGroups[2];
  49649. +} UPACKED wusb_m4_data_t;
  49650. +
  49651. +#ifdef _MSC_VER
  49652. +#include <poppack.h>
  49653. +#endif
  49654. +
  49655. +#ifdef __cplusplus
  49656. +}
  49657. +#endif
  49658. +
  49659. +#endif /* _USB_H_ */
  49660. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg
  49661. --- linux-3.12.18/drivers/usb/host/dwc_otg/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  49662. +++ linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg 2014-04-24 16:04:39.815124215 +0200
  49663. @@ -0,0 +1,224 @@
  49664. +# Doxyfile 1.3.9.1
  49665. +
  49666. +#---------------------------------------------------------------------------
  49667. +# Project related configuration options
  49668. +#---------------------------------------------------------------------------
  49669. +PROJECT_NAME = "DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver"
  49670. +PROJECT_NUMBER = v3.00a
  49671. +OUTPUT_DIRECTORY = ./doc/
  49672. +CREATE_SUBDIRS = NO
  49673. +OUTPUT_LANGUAGE = English
  49674. +BRIEF_MEMBER_DESC = YES
  49675. +REPEAT_BRIEF = YES
  49676. +ABBREVIATE_BRIEF = "The $name class" \
  49677. + "The $name widget" \
  49678. + "The $name file" \
  49679. + is \
  49680. + provides \
  49681. + specifies \
  49682. + contains \
  49683. + represents \
  49684. + a \
  49685. + an \
  49686. + the
  49687. +ALWAYS_DETAILED_SEC = NO
  49688. +INLINE_INHERITED_MEMB = NO
  49689. +FULL_PATH_NAMES = NO
  49690. +STRIP_FROM_PATH =
  49691. +STRIP_FROM_INC_PATH =
  49692. +SHORT_NAMES = NO
  49693. +JAVADOC_AUTOBRIEF = YES
  49694. +MULTILINE_CPP_IS_BRIEF = NO
  49695. +INHERIT_DOCS = YES
  49696. +DISTRIBUTE_GROUP_DOC = NO
  49697. +TAB_SIZE = 8
  49698. +ALIASES =
  49699. +OPTIMIZE_OUTPUT_FOR_C = YES
  49700. +OPTIMIZE_OUTPUT_JAVA = NO
  49701. +SUBGROUPING = YES
  49702. +#---------------------------------------------------------------------------
  49703. +# Build related configuration options
  49704. +#---------------------------------------------------------------------------
  49705. +EXTRACT_ALL = NO
  49706. +EXTRACT_PRIVATE = YES
  49707. +EXTRACT_STATIC = YES
  49708. +EXTRACT_LOCAL_CLASSES = YES
  49709. +EXTRACT_LOCAL_METHODS = NO
  49710. +HIDE_UNDOC_MEMBERS = NO
  49711. +HIDE_UNDOC_CLASSES = NO
  49712. +HIDE_FRIEND_COMPOUNDS = NO
  49713. +HIDE_IN_BODY_DOCS = NO
  49714. +INTERNAL_DOCS = NO
  49715. +CASE_SENSE_NAMES = NO
  49716. +HIDE_SCOPE_NAMES = NO
  49717. +SHOW_INCLUDE_FILES = YES
  49718. +INLINE_INFO = YES
  49719. +SORT_MEMBER_DOCS = NO
  49720. +SORT_BRIEF_DOCS = NO
  49721. +SORT_BY_SCOPE_NAME = NO
  49722. +GENERATE_TODOLIST = YES
  49723. +GENERATE_TESTLIST = YES
  49724. +GENERATE_BUGLIST = YES
  49725. +GENERATE_DEPRECATEDLIST= YES
  49726. +ENABLED_SECTIONS =
  49727. +MAX_INITIALIZER_LINES = 30
  49728. +SHOW_USED_FILES = YES
  49729. +SHOW_DIRECTORIES = YES
  49730. +#---------------------------------------------------------------------------
  49731. +# configuration options related to warning and progress messages
  49732. +#---------------------------------------------------------------------------
  49733. +QUIET = YES
  49734. +WARNINGS = YES
  49735. +WARN_IF_UNDOCUMENTED = NO
  49736. +WARN_IF_DOC_ERROR = YES
  49737. +WARN_FORMAT = "$file:$line: $text"
  49738. +WARN_LOGFILE =
  49739. +#---------------------------------------------------------------------------
  49740. +# configuration options related to the input files
  49741. +#---------------------------------------------------------------------------
  49742. +INPUT = .
  49743. +FILE_PATTERNS = *.c \
  49744. + *.h \
  49745. + ./linux/*.c \
  49746. + ./linux/*.h
  49747. +RECURSIVE = NO
  49748. +EXCLUDE = ./test/ \
  49749. + ./dwc_otg/.AppleDouble/
  49750. +EXCLUDE_SYMLINKS = YES
  49751. +EXCLUDE_PATTERNS = *.mod.*
  49752. +EXAMPLE_PATH =
  49753. +EXAMPLE_PATTERNS = *
  49754. +EXAMPLE_RECURSIVE = NO
  49755. +IMAGE_PATH =
  49756. +INPUT_FILTER =
  49757. +FILTER_PATTERNS =
  49758. +FILTER_SOURCE_FILES = NO
  49759. +#---------------------------------------------------------------------------
  49760. +# configuration options related to source browsing
  49761. +#---------------------------------------------------------------------------
  49762. +SOURCE_BROWSER = YES
  49763. +INLINE_SOURCES = NO
  49764. +STRIP_CODE_COMMENTS = YES
  49765. +REFERENCED_BY_RELATION = NO
  49766. +REFERENCES_RELATION = NO
  49767. +VERBATIM_HEADERS = NO
  49768. +#---------------------------------------------------------------------------
  49769. +# configuration options related to the alphabetical class index
  49770. +#---------------------------------------------------------------------------
  49771. +ALPHABETICAL_INDEX = NO
  49772. +COLS_IN_ALPHA_INDEX = 5
  49773. +IGNORE_PREFIX =
  49774. +#---------------------------------------------------------------------------
  49775. +# configuration options related to the HTML output
  49776. +#---------------------------------------------------------------------------
  49777. +GENERATE_HTML = YES
  49778. +HTML_OUTPUT = html
  49779. +HTML_FILE_EXTENSION = .html
  49780. +HTML_HEADER =
  49781. +HTML_FOOTER =
  49782. +HTML_STYLESHEET =
  49783. +HTML_ALIGN_MEMBERS = YES
  49784. +GENERATE_HTMLHELP = NO
  49785. +CHM_FILE =
  49786. +HHC_LOCATION =
  49787. +GENERATE_CHI = NO
  49788. +BINARY_TOC = NO
  49789. +TOC_EXPAND = NO
  49790. +DISABLE_INDEX = NO
  49791. +ENUM_VALUES_PER_LINE = 4
  49792. +GENERATE_TREEVIEW = YES
  49793. +TREEVIEW_WIDTH = 250
  49794. +#---------------------------------------------------------------------------
  49795. +# configuration options related to the LaTeX output
  49796. +#---------------------------------------------------------------------------
  49797. +GENERATE_LATEX = NO
  49798. +LATEX_OUTPUT = latex
  49799. +LATEX_CMD_NAME = latex
  49800. +MAKEINDEX_CMD_NAME = makeindex
  49801. +COMPACT_LATEX = NO
  49802. +PAPER_TYPE = a4wide
  49803. +EXTRA_PACKAGES =
  49804. +LATEX_HEADER =
  49805. +PDF_HYPERLINKS = NO
  49806. +USE_PDFLATEX = NO
  49807. +LATEX_BATCHMODE = NO
  49808. +LATEX_HIDE_INDICES = NO
  49809. +#---------------------------------------------------------------------------
  49810. +# configuration options related to the RTF output
  49811. +#---------------------------------------------------------------------------
  49812. +GENERATE_RTF = NO
  49813. +RTF_OUTPUT = rtf
  49814. +COMPACT_RTF = NO
  49815. +RTF_HYPERLINKS = NO
  49816. +RTF_STYLESHEET_FILE =
  49817. +RTF_EXTENSIONS_FILE =
  49818. +#---------------------------------------------------------------------------
  49819. +# configuration options related to the man page output
  49820. +#---------------------------------------------------------------------------
  49821. +GENERATE_MAN = NO
  49822. +MAN_OUTPUT = man
  49823. +MAN_EXTENSION = .3
  49824. +MAN_LINKS = NO
  49825. +#---------------------------------------------------------------------------
  49826. +# configuration options related to the XML output
  49827. +#---------------------------------------------------------------------------
  49828. +GENERATE_XML = NO
  49829. +XML_OUTPUT = xml
  49830. +XML_SCHEMA =
  49831. +XML_DTD =
  49832. +XML_PROGRAMLISTING = YES
  49833. +#---------------------------------------------------------------------------
  49834. +# configuration options for the AutoGen Definitions output
  49835. +#---------------------------------------------------------------------------
  49836. +GENERATE_AUTOGEN_DEF = NO
  49837. +#---------------------------------------------------------------------------
  49838. +# configuration options related to the Perl module output
  49839. +#---------------------------------------------------------------------------
  49840. +GENERATE_PERLMOD = NO
  49841. +PERLMOD_LATEX = NO
  49842. +PERLMOD_PRETTY = YES
  49843. +PERLMOD_MAKEVAR_PREFIX =
  49844. +#---------------------------------------------------------------------------
  49845. +# Configuration options related to the preprocessor
  49846. +#---------------------------------------------------------------------------
  49847. +ENABLE_PREPROCESSING = YES
  49848. +MACRO_EXPANSION = YES
  49849. +EXPAND_ONLY_PREDEF = YES
  49850. +SEARCH_INCLUDES = YES
  49851. +INCLUDE_PATH =
  49852. +INCLUDE_FILE_PATTERNS =
  49853. +PREDEFINED = DEVICE_ATTR DWC_EN_ISOC
  49854. +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
  49855. +SKIP_FUNCTION_MACROS = NO
  49856. +#---------------------------------------------------------------------------
  49857. +# Configuration::additions related to external references
  49858. +#---------------------------------------------------------------------------
  49859. +TAGFILES =
  49860. +GENERATE_TAGFILE =
  49861. +ALLEXTERNALS = NO
  49862. +EXTERNAL_GROUPS = YES
  49863. +PERL_PATH = /usr/bin/perl
  49864. +#---------------------------------------------------------------------------
  49865. +# Configuration options related to the dot tool
  49866. +#---------------------------------------------------------------------------
  49867. +CLASS_DIAGRAMS = YES
  49868. +HIDE_UNDOC_RELATIONS = YES
  49869. +HAVE_DOT = NO
  49870. +CLASS_GRAPH = YES
  49871. +COLLABORATION_GRAPH = YES
  49872. +UML_LOOK = NO
  49873. +TEMPLATE_RELATIONS = NO
  49874. +INCLUDE_GRAPH = YES
  49875. +INCLUDED_BY_GRAPH = YES
  49876. +CALL_GRAPH = NO
  49877. +GRAPHICAL_HIERARCHY = YES
  49878. +DOT_IMAGE_FORMAT = png
  49879. +DOT_PATH =
  49880. +DOTFILE_DIRS =
  49881. +MAX_DOT_GRAPH_DEPTH = 1000
  49882. +GENERATE_LEGEND = YES
  49883. +DOT_CLEANUP = YES
  49884. +#---------------------------------------------------------------------------
  49885. +# Configuration::additions related to the search engine
  49886. +#---------------------------------------------------------------------------
  49887. +SEARCHENGINE = NO
  49888. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dummy_audio.c linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c
  49889. --- linux-3.12.18/drivers/usb/host/dwc_otg/dummy_audio.c 1970-01-01 01:00:00.000000000 +0100
  49890. +++ linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c 2014-04-24 16:04:39.815124215 +0200
  49891. @@ -0,0 +1,1575 @@
  49892. +/*
  49893. + * zero.c -- Gadget Zero, for USB development
  49894. + *
  49895. + * Copyright (C) 2003-2004 David Brownell
  49896. + * All rights reserved.
  49897. + *
  49898. + * Redistribution and use in source and binary forms, with or without
  49899. + * modification, are permitted provided that the following conditions
  49900. + * are met:
  49901. + * 1. Redistributions of source code must retain the above copyright
  49902. + * notice, this list of conditions, and the following disclaimer,
  49903. + * without modification.
  49904. + * 2. Redistributions in binary form must reproduce the above copyright
  49905. + * notice, this list of conditions and the following disclaimer in the
  49906. + * documentation and/or other materials provided with the distribution.
  49907. + * 3. The names of the above-listed copyright holders may not be used
  49908. + * to endorse or promote products derived from this software without
  49909. + * specific prior written permission.
  49910. + *
  49911. + * ALTERNATIVELY, this software may be distributed under the terms of the
  49912. + * GNU General Public License ("GPL") as published by the Free Software
  49913. + * Foundation, either version 2 of that License or (at your option) any
  49914. + * later version.
  49915. + *
  49916. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  49917. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  49918. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  49919. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  49920. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  49921. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  49922. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  49923. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  49924. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  49925. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  49926. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49927. + */
  49928. +
  49929. +
  49930. +/*
  49931. + * Gadget Zero only needs two bulk endpoints, and is an example of how you
  49932. + * can write a hardware-agnostic gadget driver running inside a USB device.
  49933. + *
  49934. + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
  49935. + * affect most of the driver.
  49936. + *
  49937. + * Use it with the Linux host/master side "usbtest" driver to get a basic
  49938. + * functional test of your device-side usb stack, or with "usb-skeleton".
  49939. + *
  49940. + * It supports two similar configurations. One sinks whatever the usb host
  49941. + * writes, and in return sources zeroes. The other loops whatever the host
  49942. + * writes back, so the host can read it. Module options include:
  49943. + *
  49944. + * buflen=N default N=4096, buffer size used
  49945. + * qlen=N default N=32, how many buffers in the loopback queue
  49946. + * loopdefault default false, list loopback config first
  49947. + *
  49948. + * Many drivers will only have one configuration, letting them be much
  49949. + * simpler if they also don't support high speed operation (like this
  49950. + * driver does).
  49951. + */
  49952. +
  49953. +#include <linux/config.h>
  49954. +#include <linux/module.h>
  49955. +#include <linux/kernel.h>
  49956. +#include <linux/delay.h>
  49957. +#include <linux/ioport.h>
  49958. +#include <linux/sched.h>
  49959. +#include <linux/slab.h>
  49960. +#include <linux/smp_lock.h>
  49961. +#include <linux/errno.h>
  49962. +#include <linux/init.h>
  49963. +#include <linux/timer.h>
  49964. +#include <linux/list.h>
  49965. +#include <linux/interrupt.h>
  49966. +#include <linux/uts.h>
  49967. +#include <linux/version.h>
  49968. +#include <linux/device.h>
  49969. +#include <linux/moduleparam.h>
  49970. +#include <linux/proc_fs.h>
  49971. +
  49972. +#include <asm/byteorder.h>
  49973. +#include <asm/io.h>
  49974. +#include <asm/irq.h>
  49975. +#include <asm/system.h>
  49976. +#include <asm/unaligned.h>
  49977. +
  49978. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  49979. +# include <linux/usb/ch9.h>
  49980. +#else
  49981. +# include <linux/usb_ch9.h>
  49982. +#endif
  49983. +
  49984. +#include <linux/usb_gadget.h>
  49985. +
  49986. +
  49987. +/*-------------------------------------------------------------------------*/
  49988. +/*-------------------------------------------------------------------------*/
  49989. +
  49990. +
  49991. +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
  49992. +{
  49993. + int count = 0;
  49994. + u8 c;
  49995. + u16 uchar;
  49996. +
  49997. + /* this insists on correct encodings, though not minimal ones.
  49998. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  49999. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  50000. + */
  50001. + while (len != 0 && (c = (u8) *s++) != 0) {
  50002. + if (unlikely(c & 0x80)) {
  50003. + // 2-byte sequence:
  50004. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  50005. + if ((c & 0xe0) == 0xc0) {
  50006. + uchar = (c & 0x1f) << 6;
  50007. +
  50008. + c = (u8) *s++;
  50009. + if ((c & 0xc0) != 0xc0)
  50010. + goto fail;
  50011. + c &= 0x3f;
  50012. + uchar |= c;
  50013. +
  50014. + // 3-byte sequence (most CJKV characters):
  50015. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  50016. + } else if ((c & 0xf0) == 0xe0) {
  50017. + uchar = (c & 0x0f) << 12;
  50018. +
  50019. + c = (u8) *s++;
  50020. + if ((c & 0xc0) != 0xc0)
  50021. + goto fail;
  50022. + c &= 0x3f;
  50023. + uchar |= c << 6;
  50024. +
  50025. + c = (u8) *s++;
  50026. + if ((c & 0xc0) != 0xc0)
  50027. + goto fail;
  50028. + c &= 0x3f;
  50029. + uchar |= c;
  50030. +
  50031. + /* no bogus surrogates */
  50032. + if (0xd800 <= uchar && uchar <= 0xdfff)
  50033. + goto fail;
  50034. +
  50035. + // 4-byte sequence (surrogate pairs, currently rare):
  50036. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  50037. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  50038. + // (uuuuu = wwww + 1)
  50039. + // FIXME accept the surrogate code points (only)
  50040. +
  50041. + } else
  50042. + goto fail;
  50043. + } else
  50044. + uchar = c;
  50045. + put_unaligned (cpu_to_le16 (uchar), cp++);
  50046. + count++;
  50047. + len--;
  50048. + }
  50049. + return count;
  50050. +fail:
  50051. + return -1;
  50052. +}
  50053. +
  50054. +
  50055. +/**
  50056. + * usb_gadget_get_string - fill out a string descriptor
  50057. + * @table: of c strings encoded using UTF-8
  50058. + * @id: string id, from low byte of wValue in get string descriptor
  50059. + * @buf: at least 256 bytes
  50060. + *
  50061. + * Finds the UTF-8 string matching the ID, and converts it into a
  50062. + * string descriptor in utf16-le.
  50063. + * Returns length of descriptor (always even) or negative errno
  50064. + *
  50065. + * If your driver needs stings in multiple languages, you'll probably
  50066. + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
  50067. + * using this routine after choosing which set of UTF-8 strings to use.
  50068. + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
  50069. + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
  50070. + * characters (which are also widely used in C strings).
  50071. + */
  50072. +int
  50073. +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
  50074. +{
  50075. + struct usb_string *s;
  50076. + int len;
  50077. +
  50078. + /* descriptor 0 has the language id */
  50079. + if (id == 0) {
  50080. + buf [0] = 4;
  50081. + buf [1] = USB_DT_STRING;
  50082. + buf [2] = (u8) table->language;
  50083. + buf [3] = (u8) (table->language >> 8);
  50084. + return 4;
  50085. + }
  50086. + for (s = table->strings; s && s->s; s++)
  50087. + if (s->id == id)
  50088. + break;
  50089. +
  50090. + /* unrecognized: stall. */
  50091. + if (!s || !s->s)
  50092. + return -EINVAL;
  50093. +
  50094. + /* string descriptors have length, tag, then UTF16-LE text */
  50095. + len = min ((size_t) 126, strlen (s->s));
  50096. + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
  50097. + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
  50098. + if (len < 0)
  50099. + return -EINVAL;
  50100. + buf [0] = (len + 1) * 2;
  50101. + buf [1] = USB_DT_STRING;
  50102. + return buf [0];
  50103. +}
  50104. +
  50105. +
  50106. +/*-------------------------------------------------------------------------*/
  50107. +/*-------------------------------------------------------------------------*/
  50108. +
  50109. +
  50110. +/**
  50111. + * usb_descriptor_fillbuf - fill buffer with descriptors
  50112. + * @buf: Buffer to be filled
  50113. + * @buflen: Size of buf
  50114. + * @src: Array of descriptor pointers, terminated by null pointer.
  50115. + *
  50116. + * Copies descriptors into the buffer, returning the length or a
  50117. + * negative error code if they can't all be copied. Useful when
  50118. + * assembling descriptors for an associated set of interfaces used
  50119. + * as part of configuring a composite device; or in other cases where
  50120. + * sets of descriptors need to be marshaled.
  50121. + */
  50122. +int
  50123. +usb_descriptor_fillbuf(void *buf, unsigned buflen,
  50124. + const struct usb_descriptor_header **src)
  50125. +{
  50126. + u8 *dest = buf;
  50127. +
  50128. + if (!src)
  50129. + return -EINVAL;
  50130. +
  50131. + /* fill buffer from src[] until null descriptor ptr */
  50132. + for (; 0 != *src; src++) {
  50133. + unsigned len = (*src)->bLength;
  50134. +
  50135. + if (len > buflen)
  50136. + return -EINVAL;
  50137. + memcpy(dest, *src, len);
  50138. + buflen -= len;
  50139. + dest += len;
  50140. + }
  50141. + return dest - (u8 *)buf;
  50142. +}
  50143. +
  50144. +
  50145. +/**
  50146. + * usb_gadget_config_buf - builts a complete configuration descriptor
  50147. + * @config: Header for the descriptor, including characteristics such
  50148. + * as power requirements and number of interfaces.
  50149. + * @desc: Null-terminated vector of pointers to the descriptors (interface,
  50150. + * endpoint, etc) defining all functions in this device configuration.
  50151. + * @buf: Buffer for the resulting configuration descriptor.
  50152. + * @length: Length of buffer. If this is not big enough to hold the
  50153. + * entire configuration descriptor, an error code will be returned.
  50154. + *
  50155. + * This copies descriptors into the response buffer, building a descriptor
  50156. + * for that configuration. It returns the buffer length or a negative
  50157. + * status code. The config.wTotalLength field is set to match the length
  50158. + * of the result, but other descriptor fields (including power usage and
  50159. + * interface count) must be set by the caller.
  50160. + *
  50161. + * Gadget drivers could use this when constructing a config descriptor
  50162. + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
  50163. + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
  50164. + */
  50165. +int usb_gadget_config_buf(
  50166. + const struct usb_config_descriptor *config,
  50167. + void *buf,
  50168. + unsigned length,
  50169. + const struct usb_descriptor_header **desc
  50170. +)
  50171. +{
  50172. + struct usb_config_descriptor *cp = buf;
  50173. + int len;
  50174. +
  50175. + /* config descriptor first */
  50176. + if (length < USB_DT_CONFIG_SIZE || !desc)
  50177. + return -EINVAL;
  50178. + *cp = *config;
  50179. +
  50180. + /* then interface/endpoint/class/vendor/... */
  50181. + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
  50182. + length - USB_DT_CONFIG_SIZE, desc);
  50183. + if (len < 0)
  50184. + return len;
  50185. + len += USB_DT_CONFIG_SIZE;
  50186. + if (len > 0xffff)
  50187. + return -EINVAL;
  50188. +
  50189. + /* patch up the config descriptor */
  50190. + cp->bLength = USB_DT_CONFIG_SIZE;
  50191. + cp->bDescriptorType = USB_DT_CONFIG;
  50192. + cp->wTotalLength = cpu_to_le16(len);
  50193. + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
  50194. + return len;
  50195. +}
  50196. +
  50197. +/*-------------------------------------------------------------------------*/
  50198. +/*-------------------------------------------------------------------------*/
  50199. +
  50200. +
  50201. +#define RBUF_LEN (1024*1024)
  50202. +static int rbuf_start;
  50203. +static int rbuf_len;
  50204. +static __u8 rbuf[RBUF_LEN];
  50205. +
  50206. +/*-------------------------------------------------------------------------*/
  50207. +
  50208. +#define DRIVER_VERSION "St Patrick's Day 2004"
  50209. +
  50210. +static const char shortname [] = "zero";
  50211. +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
  50212. +
  50213. +static const char source_sink [] = "source and sink data";
  50214. +static const char loopback [] = "loop input to output";
  50215. +
  50216. +/*-------------------------------------------------------------------------*/
  50217. +
  50218. +/*
  50219. + * driver assumes self-powered hardware, and
  50220. + * has no way for users to trigger remote wakeup.
  50221. + *
  50222. + * this version autoconfigures as much as possible,
  50223. + * which is reasonable for most "bulk-only" drivers.
  50224. + */
  50225. +static const char *EP_IN_NAME; /* source */
  50226. +static const char *EP_OUT_NAME; /* sink */
  50227. +
  50228. +/*-------------------------------------------------------------------------*/
  50229. +
  50230. +/* big enough to hold our biggest descriptor */
  50231. +#define USB_BUFSIZ 512
  50232. +
  50233. +struct zero_dev {
  50234. + spinlock_t lock;
  50235. + struct usb_gadget *gadget;
  50236. + struct usb_request *req; /* for control responses */
  50237. +
  50238. + /* when configured, we have one of two configs:
  50239. + * - source data (in to host) and sink it (out from host)
  50240. + * - or loop it back (out from host back in to host)
  50241. + */
  50242. + u8 config;
  50243. + struct usb_ep *in_ep, *out_ep;
  50244. +
  50245. + /* autoresume timer */
  50246. + struct timer_list resume;
  50247. +};
  50248. +
  50249. +#define xprintk(d,level,fmt,args...) \
  50250. + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
  50251. +
  50252. +#ifdef DEBUG
  50253. +#define DBG(dev,fmt,args...) \
  50254. + xprintk(dev , KERN_DEBUG , fmt , ## args)
  50255. +#else
  50256. +#define DBG(dev,fmt,args...) \
  50257. + do { } while (0)
  50258. +#endif /* DEBUG */
  50259. +
  50260. +#ifdef VERBOSE
  50261. +#define VDBG DBG
  50262. +#else
  50263. +#define VDBG(dev,fmt,args...) \
  50264. + do { } while (0)
  50265. +#endif /* VERBOSE */
  50266. +
  50267. +#define ERROR(dev,fmt,args...) \
  50268. + xprintk(dev , KERN_ERR , fmt , ## args)
  50269. +#define WARN(dev,fmt,args...) \
  50270. + xprintk(dev , KERN_WARNING , fmt , ## args)
  50271. +#define INFO(dev,fmt,args...) \
  50272. + xprintk(dev , KERN_INFO , fmt , ## args)
  50273. +
  50274. +/*-------------------------------------------------------------------------*/
  50275. +
  50276. +static unsigned buflen = 4096;
  50277. +static unsigned qlen = 32;
  50278. +static unsigned pattern = 0;
  50279. +
  50280. +module_param (buflen, uint, S_IRUGO|S_IWUSR);
  50281. +module_param (qlen, uint, S_IRUGO|S_IWUSR);
  50282. +module_param (pattern, uint, S_IRUGO|S_IWUSR);
  50283. +
  50284. +/*
  50285. + * if it's nonzero, autoresume says how many seconds to wait
  50286. + * before trying to wake up the host after suspend.
  50287. + */
  50288. +static unsigned autoresume = 0;
  50289. +module_param (autoresume, uint, 0);
  50290. +
  50291. +/*
  50292. + * Normally the "loopback" configuration is second (index 1) so
  50293. + * it's not the default. Here's where to change that order, to
  50294. + * work better with hosts where config changes are problematic.
  50295. + * Or controllers (like superh) that only support one config.
  50296. + */
  50297. +static int loopdefault = 0;
  50298. +
  50299. +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
  50300. +
  50301. +/*-------------------------------------------------------------------------*/
  50302. +
  50303. +/* Thanks to NetChip Technologies for donating this product ID.
  50304. + *
  50305. + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
  50306. + * Instead: allocate your own, using normal USB-IF procedures.
  50307. + */
  50308. +#ifndef CONFIG_USB_ZERO_HNPTEST
  50309. +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
  50310. +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
  50311. +#else
  50312. +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
  50313. +#define DRIVER_PRODUCT_NUM 0xbadd
  50314. +#endif
  50315. +
  50316. +/*-------------------------------------------------------------------------*/
  50317. +
  50318. +/*
  50319. + * DESCRIPTORS ... most are static, but strings and (full)
  50320. + * configuration descriptors are built on demand.
  50321. + */
  50322. +
  50323. +/*
  50324. +#define STRING_MANUFACTURER 25
  50325. +#define STRING_PRODUCT 42
  50326. +#define STRING_SERIAL 101
  50327. +*/
  50328. +#define STRING_MANUFACTURER 1
  50329. +#define STRING_PRODUCT 2
  50330. +#define STRING_SERIAL 3
  50331. +
  50332. +#define STRING_SOURCE_SINK 250
  50333. +#define STRING_LOOPBACK 251
  50334. +
  50335. +/*
  50336. + * This device advertises two configurations; these numbers work
  50337. + * on a pxa250 as well as more flexible hardware.
  50338. + */
  50339. +#define CONFIG_SOURCE_SINK 3
  50340. +#define CONFIG_LOOPBACK 2
  50341. +
  50342. +/*
  50343. +static struct usb_device_descriptor
  50344. +device_desc = {
  50345. + .bLength = sizeof device_desc,
  50346. + .bDescriptorType = USB_DT_DEVICE,
  50347. +
  50348. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  50349. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  50350. +
  50351. + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
  50352. + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
  50353. + .iManufacturer = STRING_MANUFACTURER,
  50354. + .iProduct = STRING_PRODUCT,
  50355. + .iSerialNumber = STRING_SERIAL,
  50356. + .bNumConfigurations = 2,
  50357. +};
  50358. +*/
  50359. +static struct usb_device_descriptor
  50360. +device_desc = {
  50361. + .bLength = sizeof device_desc,
  50362. + .bDescriptorType = USB_DT_DEVICE,
  50363. + .bcdUSB = __constant_cpu_to_le16 (0x0100),
  50364. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  50365. + .bDeviceSubClass = 0,
  50366. + .bDeviceProtocol = 0,
  50367. + .bMaxPacketSize0 = 64,
  50368. + .bcdDevice = __constant_cpu_to_le16 (0x0100),
  50369. + .idVendor = __constant_cpu_to_le16 (0x0499),
  50370. + .idProduct = __constant_cpu_to_le16 (0x3002),
  50371. + .iManufacturer = STRING_MANUFACTURER,
  50372. + .iProduct = STRING_PRODUCT,
  50373. + .iSerialNumber = STRING_SERIAL,
  50374. + .bNumConfigurations = 1,
  50375. +};
  50376. +
  50377. +static struct usb_config_descriptor
  50378. +z_config = {
  50379. + .bLength = sizeof z_config,
  50380. + .bDescriptorType = USB_DT_CONFIG,
  50381. +
  50382. + /* compute wTotalLength on the fly */
  50383. + .bNumInterfaces = 2,
  50384. + .bConfigurationValue = 1,
  50385. + .iConfiguration = 0,
  50386. + .bmAttributes = 0x40,
  50387. + .bMaxPower = 0, /* self-powered */
  50388. +};
  50389. +
  50390. +
  50391. +static struct usb_otg_descriptor
  50392. +otg_descriptor = {
  50393. + .bLength = sizeof otg_descriptor,
  50394. + .bDescriptorType = USB_DT_OTG,
  50395. +
  50396. + .bmAttributes = USB_OTG_SRP,
  50397. +};
  50398. +
  50399. +/* one interface in each configuration */
  50400. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50401. +
  50402. +/*
  50403. + * usb 2.0 devices need to expose both high speed and full speed
  50404. + * descriptors, unless they only run at full speed.
  50405. + *
  50406. + * that means alternate endpoint descriptors (bigger packets)
  50407. + * and a "device qualifier" ... plus more construction options
  50408. + * for the config descriptor.
  50409. + */
  50410. +
  50411. +static struct usb_qualifier_descriptor
  50412. +dev_qualifier = {
  50413. + .bLength = sizeof dev_qualifier,
  50414. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  50415. +
  50416. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  50417. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  50418. +
  50419. + .bNumConfigurations = 2,
  50420. +};
  50421. +
  50422. +
  50423. +struct usb_cs_as_general_descriptor {
  50424. + __u8 bLength;
  50425. + __u8 bDescriptorType;
  50426. +
  50427. + __u8 bDescriptorSubType;
  50428. + __u8 bTerminalLink;
  50429. + __u8 bDelay;
  50430. + __u16 wFormatTag;
  50431. +} __attribute__ ((packed));
  50432. +
  50433. +struct usb_cs_as_format_descriptor {
  50434. + __u8 bLength;
  50435. + __u8 bDescriptorType;
  50436. +
  50437. + __u8 bDescriptorSubType;
  50438. + __u8 bFormatType;
  50439. + __u8 bNrChannels;
  50440. + __u8 bSubframeSize;
  50441. + __u8 bBitResolution;
  50442. + __u8 bSamfreqType;
  50443. + __u8 tLowerSamFreq[3];
  50444. + __u8 tUpperSamFreq[3];
  50445. +} __attribute__ ((packed));
  50446. +
  50447. +static const struct usb_interface_descriptor
  50448. +z_audio_control_if_desc = {
  50449. + .bLength = sizeof z_audio_control_if_desc,
  50450. + .bDescriptorType = USB_DT_INTERFACE,
  50451. + .bInterfaceNumber = 0,
  50452. + .bAlternateSetting = 0,
  50453. + .bNumEndpoints = 0,
  50454. + .bInterfaceClass = USB_CLASS_AUDIO,
  50455. + .bInterfaceSubClass = 0x1,
  50456. + .bInterfaceProtocol = 0,
  50457. + .iInterface = 0,
  50458. +};
  50459. +
  50460. +static const struct usb_interface_descriptor
  50461. +z_audio_if_desc = {
  50462. + .bLength = sizeof z_audio_if_desc,
  50463. + .bDescriptorType = USB_DT_INTERFACE,
  50464. + .bInterfaceNumber = 1,
  50465. + .bAlternateSetting = 0,
  50466. + .bNumEndpoints = 0,
  50467. + .bInterfaceClass = USB_CLASS_AUDIO,
  50468. + .bInterfaceSubClass = 0x2,
  50469. + .bInterfaceProtocol = 0,
  50470. + .iInterface = 0,
  50471. +};
  50472. +
  50473. +static const struct usb_interface_descriptor
  50474. +z_audio_if_desc2 = {
  50475. + .bLength = sizeof z_audio_if_desc,
  50476. + .bDescriptorType = USB_DT_INTERFACE,
  50477. + .bInterfaceNumber = 1,
  50478. + .bAlternateSetting = 1,
  50479. + .bNumEndpoints = 1,
  50480. + .bInterfaceClass = USB_CLASS_AUDIO,
  50481. + .bInterfaceSubClass = 0x2,
  50482. + .bInterfaceProtocol = 0,
  50483. + .iInterface = 0,
  50484. +};
  50485. +
  50486. +static const struct usb_cs_as_general_descriptor
  50487. +z_audio_cs_as_if_desc = {
  50488. + .bLength = 7,
  50489. + .bDescriptorType = 0x24,
  50490. +
  50491. + .bDescriptorSubType = 0x01,
  50492. + .bTerminalLink = 0x01,
  50493. + .bDelay = 0x0,
  50494. + .wFormatTag = __constant_cpu_to_le16 (0x0001)
  50495. +};
  50496. +
  50497. +
  50498. +static const struct usb_cs_as_format_descriptor
  50499. +z_audio_cs_as_format_desc = {
  50500. + .bLength = 0xe,
  50501. + .bDescriptorType = 0x24,
  50502. +
  50503. + .bDescriptorSubType = 2,
  50504. + .bFormatType = 1,
  50505. + .bNrChannels = 1,
  50506. + .bSubframeSize = 1,
  50507. + .bBitResolution = 8,
  50508. + .bSamfreqType = 0,
  50509. + .tLowerSamFreq = {0x7e, 0x13, 0x00},
  50510. + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
  50511. +};
  50512. +
  50513. +static const struct usb_endpoint_descriptor
  50514. +z_iso_ep = {
  50515. + .bLength = 0x09,
  50516. + .bDescriptorType = 0x05,
  50517. + .bEndpointAddress = 0x04,
  50518. + .bmAttributes = 0x09,
  50519. + .wMaxPacketSize = 0x0038,
  50520. + .bInterval = 0x01,
  50521. + .bRefresh = 0x00,
  50522. + .bSynchAddress = 0x00,
  50523. +};
  50524. +
  50525. +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50526. +
  50527. +// 9 bytes
  50528. +static char z_ac_interface_header_desc[] =
  50529. +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
  50530. +
  50531. +// 12 bytes
  50532. +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
  50533. + 0x03, 0x00, 0x00, 0x00};
  50534. +// 13 bytes
  50535. +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
  50536. + 0x02, 0x00, 0x02, 0x00, 0x00};
  50537. +// 9 bytes
  50538. +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
  50539. + 0x00};
  50540. +
  50541. +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
  50542. + 0x00};
  50543. +
  50544. +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50545. +
  50546. +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
  50547. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50548. +
  50549. +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  50550. + 0x00};
  50551. +
  50552. +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50553. +
  50554. +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
  50555. + 0x00};
  50556. +
  50557. +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50558. +
  50559. +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
  50560. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50561. +
  50562. +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  50563. + 0x00};
  50564. +
  50565. +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50566. +
  50567. +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
  50568. + 0x00};
  50569. +
  50570. +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50571. +
  50572. +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
  50573. + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50574. +
  50575. +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
  50576. + 0x00};
  50577. +
  50578. +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50579. +
  50580. +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
  50581. + 0x00};
  50582. +
  50583. +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50584. +
  50585. +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
  50586. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50587. +
  50588. +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
  50589. + 0x00};
  50590. +
  50591. +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50592. +
  50593. +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
  50594. + 0x00};
  50595. +
  50596. +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50597. +
  50598. +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
  50599. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50600. +
  50601. +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
  50602. + 0x00};
  50603. +
  50604. +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50605. +
  50606. +
  50607. +
  50608. +static const struct usb_descriptor_header *z_function [] = {
  50609. + (struct usb_descriptor_header *) &z_audio_control_if_desc,
  50610. + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
  50611. + (struct usb_descriptor_header *) &z_0,
  50612. + (struct usb_descriptor_header *) &z_1,
  50613. + (struct usb_descriptor_header *) &z_2,
  50614. + (struct usb_descriptor_header *) &z_audio_if_desc,
  50615. + (struct usb_descriptor_header *) &z_audio_if_desc2,
  50616. + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
  50617. + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
  50618. + (struct usb_descriptor_header *) &z_iso_ep,
  50619. + (struct usb_descriptor_header *) &z_iso_ep2,
  50620. + (struct usb_descriptor_header *) &za_0,
  50621. + (struct usb_descriptor_header *) &za_1,
  50622. + (struct usb_descriptor_header *) &za_2,
  50623. + (struct usb_descriptor_header *) &za_3,
  50624. + (struct usb_descriptor_header *) &za_4,
  50625. + (struct usb_descriptor_header *) &za_5,
  50626. + (struct usb_descriptor_header *) &za_6,
  50627. + (struct usb_descriptor_header *) &za_7,
  50628. + (struct usb_descriptor_header *) &za_8,
  50629. + (struct usb_descriptor_header *) &za_9,
  50630. + (struct usb_descriptor_header *) &za_10,
  50631. + (struct usb_descriptor_header *) &za_11,
  50632. + (struct usb_descriptor_header *) &za_12,
  50633. + (struct usb_descriptor_header *) &za_13,
  50634. + (struct usb_descriptor_header *) &za_14,
  50635. + (struct usb_descriptor_header *) &za_15,
  50636. + (struct usb_descriptor_header *) &za_16,
  50637. + (struct usb_descriptor_header *) &za_17,
  50638. + (struct usb_descriptor_header *) &za_18,
  50639. + (struct usb_descriptor_header *) &za_19,
  50640. + (struct usb_descriptor_header *) &za_20,
  50641. + (struct usb_descriptor_header *) &za_21,
  50642. + (struct usb_descriptor_header *) &za_22,
  50643. + (struct usb_descriptor_header *) &za_23,
  50644. + (struct usb_descriptor_header *) &za_24,
  50645. + NULL,
  50646. +};
  50647. +
  50648. +/* maxpacket and other transfer characteristics vary by speed. */
  50649. +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
  50650. +
  50651. +#else
  50652. +
  50653. +/* if there's no high speed support, maxpacket doesn't change. */
  50654. +#define ep_desc(g,hs,fs) fs
  50655. +
  50656. +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
  50657. +
  50658. +static char manufacturer [40];
  50659. +//static char serial [40];
  50660. +static char serial [] = "Ser 00 em";
  50661. +
  50662. +/* static strings, in UTF-8 */
  50663. +static struct usb_string strings [] = {
  50664. + { STRING_MANUFACTURER, manufacturer, },
  50665. + { STRING_PRODUCT, longname, },
  50666. + { STRING_SERIAL, serial, },
  50667. + { STRING_LOOPBACK, loopback, },
  50668. + { STRING_SOURCE_SINK, source_sink, },
  50669. + { } /* end of list */
  50670. +};
  50671. +
  50672. +static struct usb_gadget_strings stringtab = {
  50673. + .language = 0x0409, /* en-us */
  50674. + .strings = strings,
  50675. +};
  50676. +
  50677. +/*
  50678. + * config descriptors are also handcrafted. these must agree with code
  50679. + * that sets configurations, and with code managing interfaces and their
  50680. + * altsettings. other complexity may come from:
  50681. + *
  50682. + * - high speed support, including "other speed config" rules
  50683. + * - multiple configurations
  50684. + * - interfaces with alternate settings
  50685. + * - embedded class or vendor-specific descriptors
  50686. + *
  50687. + * this handles high speed, and has a second config that could as easily
  50688. + * have been an alternate interface setting (on most hardware).
  50689. + *
  50690. + * NOTE: to demonstrate (and test) more USB capabilities, this driver
  50691. + * should include an altsetting to test interrupt transfers, including
  50692. + * high bandwidth modes at high speed. (Maybe work like Intel's test
  50693. + * device?)
  50694. + */
  50695. +static int
  50696. +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
  50697. +{
  50698. + int len;
  50699. + const struct usb_descriptor_header **function;
  50700. +
  50701. + function = z_function;
  50702. + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
  50703. + if (len < 0)
  50704. + return len;
  50705. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  50706. + return len;
  50707. +}
  50708. +
  50709. +/*-------------------------------------------------------------------------*/
  50710. +
  50711. +static struct usb_request *
  50712. +alloc_ep_req (struct usb_ep *ep, unsigned length)
  50713. +{
  50714. + struct usb_request *req;
  50715. +
  50716. + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
  50717. + if (req) {
  50718. + req->length = length;
  50719. + req->buf = usb_ep_alloc_buffer (ep, length,
  50720. + &req->dma, GFP_ATOMIC);
  50721. + if (!req->buf) {
  50722. + usb_ep_free_request (ep, req);
  50723. + req = NULL;
  50724. + }
  50725. + }
  50726. + return req;
  50727. +}
  50728. +
  50729. +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
  50730. +{
  50731. + if (req->buf)
  50732. + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
  50733. + usb_ep_free_request (ep, req);
  50734. +}
  50735. +
  50736. +/*-------------------------------------------------------------------------*/
  50737. +
  50738. +/* optionally require specific source/sink data patterns */
  50739. +
  50740. +static int
  50741. +check_read_data (
  50742. + struct zero_dev *dev,
  50743. + struct usb_ep *ep,
  50744. + struct usb_request *req
  50745. +)
  50746. +{
  50747. + unsigned i;
  50748. + u8 *buf = req->buf;
  50749. +
  50750. + for (i = 0; i < req->actual; i++, buf++) {
  50751. + switch (pattern) {
  50752. + /* all-zeroes has no synchronization issues */
  50753. + case 0:
  50754. + if (*buf == 0)
  50755. + continue;
  50756. + break;
  50757. + /* mod63 stays in sync with short-terminated transfers,
  50758. + * or otherwise when host and gadget agree on how large
  50759. + * each usb transfer request should be. resync is done
  50760. + * with set_interface or set_config.
  50761. + */
  50762. + case 1:
  50763. + if (*buf == (u8)(i % 63))
  50764. + continue;
  50765. + break;
  50766. + }
  50767. + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
  50768. + usb_ep_set_halt (ep);
  50769. + return -EINVAL;
  50770. + }
  50771. + return 0;
  50772. +}
  50773. +
  50774. +/*-------------------------------------------------------------------------*/
  50775. +
  50776. +static void zero_reset_config (struct zero_dev *dev)
  50777. +{
  50778. + if (dev->config == 0)
  50779. + return;
  50780. +
  50781. + DBG (dev, "reset config\n");
  50782. +
  50783. + /* just disable endpoints, forcing completion of pending i/o.
  50784. + * all our completion handlers free their requests in this case.
  50785. + */
  50786. + if (dev->in_ep) {
  50787. + usb_ep_disable (dev->in_ep);
  50788. + dev->in_ep = NULL;
  50789. + }
  50790. + if (dev->out_ep) {
  50791. + usb_ep_disable (dev->out_ep);
  50792. + dev->out_ep = NULL;
  50793. + }
  50794. + dev->config = 0;
  50795. + del_timer (&dev->resume);
  50796. +}
  50797. +
  50798. +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
  50799. +
  50800. +static void
  50801. +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
  50802. +{
  50803. + struct zero_dev *dev = ep->driver_data;
  50804. + int status = req->status;
  50805. + int i, j;
  50806. +
  50807. + switch (status) {
  50808. +
  50809. + case 0: /* normal completion? */
  50810. + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
  50811. + for (i=0, j=rbuf_start; i<req->actual; i++) {
  50812. + //printk ("%02x ", ((__u8*)req->buf)[i]);
  50813. + rbuf[j] = ((__u8*)req->buf)[i];
  50814. + j++;
  50815. + if (j >= RBUF_LEN) j=0;
  50816. + }
  50817. + rbuf_start = j;
  50818. + //printk ("\n\n");
  50819. +
  50820. + if (rbuf_len < RBUF_LEN) {
  50821. + rbuf_len += req->actual;
  50822. + if (rbuf_len > RBUF_LEN) {
  50823. + rbuf_len = RBUF_LEN;
  50824. + }
  50825. + }
  50826. +
  50827. + break;
  50828. +
  50829. + /* this endpoint is normally active while we're configured */
  50830. + case -ECONNABORTED: /* hardware forced ep reset */
  50831. + case -ECONNRESET: /* request dequeued */
  50832. + case -ESHUTDOWN: /* disconnect from host */
  50833. + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
  50834. + req->actual, req->length);
  50835. + if (ep == dev->out_ep)
  50836. + check_read_data (dev, ep, req);
  50837. + free_ep_req (ep, req);
  50838. + return;
  50839. +
  50840. + case -EOVERFLOW: /* buffer overrun on read means that
  50841. + * we didn't provide a big enough
  50842. + * buffer.
  50843. + */
  50844. + default:
  50845. +#if 1
  50846. + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
  50847. + status, req->actual, req->length);
  50848. +#endif
  50849. + case -EREMOTEIO: /* short read */
  50850. + break;
  50851. + }
  50852. +
  50853. + status = usb_ep_queue (ep, req, GFP_ATOMIC);
  50854. + if (status) {
  50855. + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
  50856. + ep->name, req->length, status);
  50857. + usb_ep_set_halt (ep);
  50858. + /* FIXME recover later ... somehow */
  50859. + }
  50860. +}
  50861. +
  50862. +static struct usb_request *
  50863. +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
  50864. +{
  50865. + struct usb_request *req;
  50866. + int status;
  50867. +
  50868. + req = alloc_ep_req (ep, 512);
  50869. + if (!req)
  50870. + return NULL;
  50871. +
  50872. + req->complete = zero_isoc_complete;
  50873. +
  50874. + status = usb_ep_queue (ep, req, gfp_flags);
  50875. + if (status) {
  50876. + struct zero_dev *dev = ep->driver_data;
  50877. +
  50878. + ERROR (dev, "start %s --> %d\n", ep->name, status);
  50879. + free_ep_req (ep, req);
  50880. + req = NULL;
  50881. + }
  50882. +
  50883. + return req;
  50884. +}
  50885. +
  50886. +/* change our operational config. this code must agree with the code
  50887. + * that returns config descriptors, and altsetting code.
  50888. + *
  50889. + * it's also responsible for power management interactions. some
  50890. + * configurations might not work with our current power sources.
  50891. + *
  50892. + * note that some device controller hardware will constrain what this
  50893. + * code can do, perhaps by disallowing more than one configuration or
  50894. + * by limiting configuration choices (like the pxa2xx).
  50895. + */
  50896. +static int
  50897. +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
  50898. +{
  50899. + int result = 0;
  50900. + struct usb_gadget *gadget = dev->gadget;
  50901. + const struct usb_endpoint_descriptor *d;
  50902. + struct usb_ep *ep;
  50903. +
  50904. + if (number == dev->config)
  50905. + return 0;
  50906. +
  50907. + zero_reset_config (dev);
  50908. +
  50909. + gadget_for_each_ep (ep, gadget) {
  50910. +
  50911. + if (strcmp (ep->name, "ep4") == 0) {
  50912. +
  50913. + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
  50914. + result = usb_ep_enable (ep, d);
  50915. +
  50916. + if (result == 0) {
  50917. + ep->driver_data = dev;
  50918. + dev->in_ep = ep;
  50919. +
  50920. + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
  50921. +
  50922. + dev->in_ep = ep;
  50923. + continue;
  50924. + }
  50925. +
  50926. + usb_ep_disable (ep);
  50927. + result = -EIO;
  50928. + }
  50929. + }
  50930. +
  50931. + }
  50932. +
  50933. + dev->config = number;
  50934. + return result;
  50935. +}
  50936. +
  50937. +/*-------------------------------------------------------------------------*/
  50938. +
  50939. +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  50940. +{
  50941. + if (req->status || req->actual != req->length)
  50942. + DBG ((struct zero_dev *) ep->driver_data,
  50943. + "setup complete --> %d, %d/%d\n",
  50944. + req->status, req->actual, req->length);
  50945. +}
  50946. +
  50947. +/*
  50948. + * The setup() callback implements all the ep0 functionality that's
  50949. + * not handled lower down, in hardware or the hardware driver (like
  50950. + * device and endpoint feature flags, and their status). It's all
  50951. + * housekeeping for the gadget function we're implementing. Most of
  50952. + * the work is in config-specific setup.
  50953. + */
  50954. +static int
  50955. +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
  50956. +{
  50957. + struct zero_dev *dev = get_gadget_data (gadget);
  50958. + struct usb_request *req = dev->req;
  50959. + int value = -EOPNOTSUPP;
  50960. +
  50961. + /* usually this stores reply data in the pre-allocated ep0 buffer,
  50962. + * but config change events will reconfigure hardware.
  50963. + */
  50964. + req->zero = 0;
  50965. + switch (ctrl->bRequest) {
  50966. +
  50967. + case USB_REQ_GET_DESCRIPTOR:
  50968. +
  50969. + switch (ctrl->wValue >> 8) {
  50970. +
  50971. + case USB_DT_DEVICE:
  50972. + value = min (ctrl->wLength, (u16) sizeof device_desc);
  50973. + memcpy (req->buf, &device_desc, value);
  50974. + break;
  50975. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50976. + case USB_DT_DEVICE_QUALIFIER:
  50977. + if (!gadget->is_dualspeed)
  50978. + break;
  50979. + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
  50980. + memcpy (req->buf, &dev_qualifier, value);
  50981. + break;
  50982. +
  50983. + case USB_DT_OTHER_SPEED_CONFIG:
  50984. + if (!gadget->is_dualspeed)
  50985. + break;
  50986. + // FALLTHROUGH
  50987. +#endif /* CONFIG_USB_GADGET_DUALSPEED */
  50988. + case USB_DT_CONFIG:
  50989. + value = config_buf (gadget, req->buf,
  50990. + ctrl->wValue >> 8,
  50991. + ctrl->wValue & 0xff);
  50992. + if (value >= 0)
  50993. + value = min (ctrl->wLength, (u16) value);
  50994. + break;
  50995. +
  50996. + case USB_DT_STRING:
  50997. + /* wIndex == language code.
  50998. + * this driver only handles one language, you can
  50999. + * add string tables for other languages, using
  51000. + * any UTF-8 characters
  51001. + */
  51002. + value = usb_gadget_get_string (&stringtab,
  51003. + ctrl->wValue & 0xff, req->buf);
  51004. + if (value >= 0) {
  51005. + value = min (ctrl->wLength, (u16) value);
  51006. + }
  51007. + break;
  51008. + }
  51009. + break;
  51010. +
  51011. + /* currently two configs, two speeds */
  51012. + case USB_REQ_SET_CONFIGURATION:
  51013. + if (ctrl->bRequestType != 0)
  51014. + goto unknown;
  51015. +
  51016. + spin_lock (&dev->lock);
  51017. + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
  51018. + spin_unlock (&dev->lock);
  51019. + break;
  51020. + case USB_REQ_GET_CONFIGURATION:
  51021. + if (ctrl->bRequestType != USB_DIR_IN)
  51022. + goto unknown;
  51023. + *(u8 *)req->buf = dev->config;
  51024. + value = min (ctrl->wLength, (u16) 1);
  51025. + break;
  51026. +
  51027. + /* until we add altsetting support, or other interfaces,
  51028. + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
  51029. + * and already killed pending endpoint I/O.
  51030. + */
  51031. + case USB_REQ_SET_INTERFACE:
  51032. +
  51033. + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
  51034. + goto unknown;
  51035. + spin_lock (&dev->lock);
  51036. + if (dev->config) {
  51037. + u8 config = dev->config;
  51038. +
  51039. + /* resets interface configuration, forgets about
  51040. + * previous transaction state (queued bufs, etc)
  51041. + * and re-inits endpoint state (toggle etc)
  51042. + * no response queued, just zero status == success.
  51043. + * if we had more than one interface we couldn't
  51044. + * use this "reset the config" shortcut.
  51045. + */
  51046. + zero_reset_config (dev);
  51047. + zero_set_config (dev, config, GFP_ATOMIC);
  51048. + value = 0;
  51049. + }
  51050. + spin_unlock (&dev->lock);
  51051. + break;
  51052. + case USB_REQ_GET_INTERFACE:
  51053. + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
  51054. + value = ctrl->wLength;
  51055. + break;
  51056. + }
  51057. + else {
  51058. + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
  51059. + goto unknown;
  51060. + if (!dev->config)
  51061. + break;
  51062. + if (ctrl->wIndex != 0) {
  51063. + value = -EDOM;
  51064. + break;
  51065. + }
  51066. + *(u8 *)req->buf = 0;
  51067. + value = min (ctrl->wLength, (u16) 1);
  51068. + }
  51069. + break;
  51070. +
  51071. + /*
  51072. + * These are the same vendor-specific requests supported by
  51073. + * Intel's USB 2.0 compliance test devices. We exceed that
  51074. + * device spec by allowing multiple-packet requests.
  51075. + */
  51076. + case 0x5b: /* control WRITE test -- fill the buffer */
  51077. + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  51078. + goto unknown;
  51079. + if (ctrl->wValue || ctrl->wIndex)
  51080. + break;
  51081. + /* just read that many bytes into the buffer */
  51082. + if (ctrl->wLength > USB_BUFSIZ)
  51083. + break;
  51084. + value = ctrl->wLength;
  51085. + break;
  51086. + case 0x5c: /* control READ test -- return the buffer */
  51087. + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  51088. + goto unknown;
  51089. + if (ctrl->wValue || ctrl->wIndex)
  51090. + break;
  51091. + /* expect those bytes are still in the buffer; send back */
  51092. + if (ctrl->wLength > USB_BUFSIZ
  51093. + || ctrl->wLength != req->length)
  51094. + break;
  51095. + value = ctrl->wLength;
  51096. + break;
  51097. +
  51098. + case 0x01: // SET_CUR
  51099. + case 0x02:
  51100. + case 0x03:
  51101. + case 0x04:
  51102. + case 0x05:
  51103. + value = ctrl->wLength;
  51104. + break;
  51105. + case 0x81:
  51106. + switch (ctrl->wValue) {
  51107. + case 0x0201:
  51108. + case 0x0202:
  51109. + ((u8*)req->buf)[0] = 0x00;
  51110. + ((u8*)req->buf)[1] = 0xe3;
  51111. + break;
  51112. + case 0x0300:
  51113. + case 0x0500:
  51114. + ((u8*)req->buf)[0] = 0x00;
  51115. + break;
  51116. + }
  51117. + //((u8*)req->buf)[0] = 0x81;
  51118. + //((u8*)req->buf)[1] = 0x81;
  51119. + value = ctrl->wLength;
  51120. + break;
  51121. + case 0x82:
  51122. + switch (ctrl->wValue) {
  51123. + case 0x0201:
  51124. + case 0x0202:
  51125. + ((u8*)req->buf)[0] = 0x00;
  51126. + ((u8*)req->buf)[1] = 0xc3;
  51127. + break;
  51128. + case 0x0300:
  51129. + case 0x0500:
  51130. + ((u8*)req->buf)[0] = 0x00;
  51131. + break;
  51132. + }
  51133. + //((u8*)req->buf)[0] = 0x82;
  51134. + //((u8*)req->buf)[1] = 0x82;
  51135. + value = ctrl->wLength;
  51136. + break;
  51137. + case 0x83:
  51138. + switch (ctrl->wValue) {
  51139. + case 0x0201:
  51140. + case 0x0202:
  51141. + ((u8*)req->buf)[0] = 0x00;
  51142. + ((u8*)req->buf)[1] = 0x00;
  51143. + break;
  51144. + case 0x0300:
  51145. + ((u8*)req->buf)[0] = 0x60;
  51146. + break;
  51147. + case 0x0500:
  51148. + ((u8*)req->buf)[0] = 0x18;
  51149. + break;
  51150. + }
  51151. + //((u8*)req->buf)[0] = 0x83;
  51152. + //((u8*)req->buf)[1] = 0x83;
  51153. + value = ctrl->wLength;
  51154. + break;
  51155. + case 0x84:
  51156. + switch (ctrl->wValue) {
  51157. + case 0x0201:
  51158. + case 0x0202:
  51159. + ((u8*)req->buf)[0] = 0x00;
  51160. + ((u8*)req->buf)[1] = 0x01;
  51161. + break;
  51162. + case 0x0300:
  51163. + case 0x0500:
  51164. + ((u8*)req->buf)[0] = 0x08;
  51165. + break;
  51166. + }
  51167. + //((u8*)req->buf)[0] = 0x84;
  51168. + //((u8*)req->buf)[1] = 0x84;
  51169. + value = ctrl->wLength;
  51170. + break;
  51171. + case 0x85:
  51172. + ((u8*)req->buf)[0] = 0x85;
  51173. + ((u8*)req->buf)[1] = 0x85;
  51174. + value = ctrl->wLength;
  51175. + break;
  51176. +
  51177. +
  51178. + default:
  51179. +unknown:
  51180. + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
  51181. + ctrl->bRequestType, ctrl->bRequest,
  51182. + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
  51183. + }
  51184. +
  51185. + /* respond with data transfer before status phase? */
  51186. + if (value >= 0) {
  51187. + req->length = value;
  51188. + req->zero = value < ctrl->wLength
  51189. + && (value % gadget->ep0->maxpacket) == 0;
  51190. + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
  51191. + if (value < 0) {
  51192. + DBG (dev, "ep_queue < 0 --> %d\n", value);
  51193. + req->status = 0;
  51194. + zero_setup_complete (gadget->ep0, req);
  51195. + }
  51196. + }
  51197. +
  51198. + /* device either stalls (value < 0) or reports success */
  51199. + return value;
  51200. +}
  51201. +
  51202. +static void
  51203. +zero_disconnect (struct usb_gadget *gadget)
  51204. +{
  51205. + struct zero_dev *dev = get_gadget_data (gadget);
  51206. + unsigned long flags;
  51207. +
  51208. + spin_lock_irqsave (&dev->lock, flags);
  51209. + zero_reset_config (dev);
  51210. +
  51211. + /* a more significant application might have some non-usb
  51212. + * activities to quiesce here, saving resources like power
  51213. + * or pushing the notification up a network stack.
  51214. + */
  51215. + spin_unlock_irqrestore (&dev->lock, flags);
  51216. +
  51217. + /* next we may get setup() calls to enumerate new connections;
  51218. + * or an unbind() during shutdown (including removing module).
  51219. + */
  51220. +}
  51221. +
  51222. +static void
  51223. +zero_autoresume (unsigned long _dev)
  51224. +{
  51225. + struct zero_dev *dev = (struct zero_dev *) _dev;
  51226. + int status;
  51227. +
  51228. + /* normally the host would be woken up for something
  51229. + * more significant than just a timer firing...
  51230. + */
  51231. + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
  51232. + status = usb_gadget_wakeup (dev->gadget);
  51233. + DBG (dev, "wakeup --> %d\n", status);
  51234. + }
  51235. +}
  51236. +
  51237. +/*-------------------------------------------------------------------------*/
  51238. +
  51239. +static void
  51240. +zero_unbind (struct usb_gadget *gadget)
  51241. +{
  51242. + struct zero_dev *dev = get_gadget_data (gadget);
  51243. +
  51244. + DBG (dev, "unbind\n");
  51245. +
  51246. + /* we've already been disconnected ... no i/o is active */
  51247. + if (dev->req)
  51248. + free_ep_req (gadget->ep0, dev->req);
  51249. + del_timer_sync (&dev->resume);
  51250. + kfree (dev);
  51251. + set_gadget_data (gadget, NULL);
  51252. +}
  51253. +
  51254. +static int
  51255. +zero_bind (struct usb_gadget *gadget)
  51256. +{
  51257. + struct zero_dev *dev;
  51258. + //struct usb_ep *ep;
  51259. +
  51260. + printk("binding\n");
  51261. + /*
  51262. + * DRIVER POLICY CHOICE: you may want to do this differently.
  51263. + * One thing to avoid is reusing a bcdDevice revision code
  51264. + * with different host-visible configurations or behavior
  51265. + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
  51266. + */
  51267. + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
  51268. +
  51269. +
  51270. + /* ok, we made sense of the hardware ... */
  51271. + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
  51272. + if (!dev)
  51273. + return -ENOMEM;
  51274. + memset (dev, 0, sizeof *dev);
  51275. + spin_lock_init (&dev->lock);
  51276. + dev->gadget = gadget;
  51277. + set_gadget_data (gadget, dev);
  51278. +
  51279. + /* preallocate control response and buffer */
  51280. + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
  51281. + if (!dev->req)
  51282. + goto enomem;
  51283. + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
  51284. + &dev->req->dma, GFP_KERNEL);
  51285. + if (!dev->req->buf)
  51286. + goto enomem;
  51287. +
  51288. + dev->req->complete = zero_setup_complete;
  51289. +
  51290. + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
  51291. +
  51292. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  51293. + /* assume ep0 uses the same value for both speeds ... */
  51294. + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
  51295. +
  51296. + /* and that all endpoints are dual-speed */
  51297. + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  51298. + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  51299. +#endif
  51300. +
  51301. + usb_gadget_set_selfpowered (gadget);
  51302. +
  51303. + init_timer (&dev->resume);
  51304. + dev->resume.function = zero_autoresume;
  51305. + dev->resume.data = (unsigned long) dev;
  51306. +
  51307. + gadget->ep0->driver_data = dev;
  51308. +
  51309. + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
  51310. + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
  51311. + EP_OUT_NAME, EP_IN_NAME);
  51312. +
  51313. + snprintf (manufacturer, sizeof manufacturer,
  51314. + UTS_SYSNAME " " UTS_RELEASE " with %s",
  51315. + gadget->name);
  51316. +
  51317. + return 0;
  51318. +
  51319. +enomem:
  51320. + zero_unbind (gadget);
  51321. + return -ENOMEM;
  51322. +}
  51323. +
  51324. +/*-------------------------------------------------------------------------*/
  51325. +
  51326. +static void
  51327. +zero_suspend (struct usb_gadget *gadget)
  51328. +{
  51329. + struct zero_dev *dev = get_gadget_data (gadget);
  51330. +
  51331. + if (gadget->speed == USB_SPEED_UNKNOWN)
  51332. + return;
  51333. +
  51334. + if (autoresume) {
  51335. + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
  51336. + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
  51337. + } else
  51338. + DBG (dev, "suspend\n");
  51339. +}
  51340. +
  51341. +static void
  51342. +zero_resume (struct usb_gadget *gadget)
  51343. +{
  51344. + struct zero_dev *dev = get_gadget_data (gadget);
  51345. +
  51346. + DBG (dev, "resume\n");
  51347. + del_timer (&dev->resume);
  51348. +}
  51349. +
  51350. +
  51351. +/*-------------------------------------------------------------------------*/
  51352. +
  51353. +static struct usb_gadget_driver zero_driver = {
  51354. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  51355. + .speed = USB_SPEED_HIGH,
  51356. +#else
  51357. + .speed = USB_SPEED_FULL,
  51358. +#endif
  51359. + .function = (char *) longname,
  51360. + .bind = zero_bind,
  51361. + .unbind = zero_unbind,
  51362. +
  51363. + .setup = zero_setup,
  51364. + .disconnect = zero_disconnect,
  51365. +
  51366. + .suspend = zero_suspend,
  51367. + .resume = zero_resume,
  51368. +
  51369. + .driver = {
  51370. + .name = (char *) shortname,
  51371. + // .shutdown = ...
  51372. + // .suspend = ...
  51373. + // .resume = ...
  51374. + },
  51375. +};
  51376. +
  51377. +MODULE_AUTHOR ("David Brownell");
  51378. +MODULE_LICENSE ("Dual BSD/GPL");
  51379. +
  51380. +static struct proc_dir_entry *pdir, *pfile;
  51381. +
  51382. +static int isoc_read_data (char *page, char **start,
  51383. + off_t off, int count,
  51384. + int *eof, void *data)
  51385. +{
  51386. + int i;
  51387. + static int c = 0;
  51388. + static int done = 0;
  51389. + static int s = 0;
  51390. +
  51391. +/*
  51392. + printk ("\ncount: %d\n", count);
  51393. + printk ("rbuf_start: %d\n", rbuf_start);
  51394. + printk ("rbuf_len: %d\n", rbuf_len);
  51395. + printk ("off: %d\n", off);
  51396. + printk ("start: %p\n\n", *start);
  51397. +*/
  51398. + if (done) {
  51399. + c = 0;
  51400. + done = 0;
  51401. + *eof = 1;
  51402. + return 0;
  51403. + }
  51404. +
  51405. + if (c == 0) {
  51406. + if (rbuf_len == RBUF_LEN)
  51407. + s = rbuf_start;
  51408. + else s = 0;
  51409. + }
  51410. +
  51411. + for (i=0; i<count && c<rbuf_len; i++, c++) {
  51412. + page[i] = rbuf[(c+s) % RBUF_LEN];
  51413. + }
  51414. + *start = page;
  51415. +
  51416. + if (c >= rbuf_len) {
  51417. + *eof = 1;
  51418. + done = 1;
  51419. + }
  51420. +
  51421. +
  51422. + return i;
  51423. +}
  51424. +
  51425. +static int __init init (void)
  51426. +{
  51427. +
  51428. + int retval = 0;
  51429. +
  51430. + pdir = proc_mkdir("isoc_test", NULL);
  51431. + if(pdir == NULL) {
  51432. + retval = -ENOMEM;
  51433. + printk("Error creating dir\n");
  51434. + goto done;
  51435. + }
  51436. + pdir->owner = THIS_MODULE;
  51437. +
  51438. + pfile = create_proc_read_entry("isoc_data",
  51439. + 0444, pdir,
  51440. + isoc_read_data,
  51441. + NULL);
  51442. + if (pfile == NULL) {
  51443. + retval = -ENOMEM;
  51444. + printk("Error creating file\n");
  51445. + goto no_file;
  51446. + }
  51447. + pfile->owner = THIS_MODULE;
  51448. +
  51449. + return usb_gadget_register_driver (&zero_driver);
  51450. +
  51451. + no_file:
  51452. + remove_proc_entry("isoc_data", NULL);
  51453. + done:
  51454. + return retval;
  51455. +}
  51456. +module_init (init);
  51457. +
  51458. +static void __exit cleanup (void)
  51459. +{
  51460. +
  51461. + usb_gadget_unregister_driver (&zero_driver);
  51462. +
  51463. + remove_proc_entry("isoc_data", pdir);
  51464. + remove_proc_entry("isoc_test", NULL);
  51465. +}
  51466. +module_exit (cleanup);
  51467. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_cfi_common.h linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h
  51468. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_cfi_common.h 1970-01-01 01:00:00.000000000 +0100
  51469. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h 2014-04-24 16:04:39.815124215 +0200
  51470. @@ -0,0 +1,142 @@
  51471. +/* ==========================================================================
  51472. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51473. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51474. + * otherwise expressly agreed to in writing between Synopsys and you.
  51475. + *
  51476. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51477. + * any End User Software License Agreement or Agreement for Licensed Product
  51478. + * with Synopsys or any supplement thereto. You are permitted to use and
  51479. + * redistribute this Software in source and binary forms, with or without
  51480. + * modification, provided that redistributions of source code must retain this
  51481. + * notice. You may not view, use, disclose, copy or distribute this file or
  51482. + * any information contained herein except pursuant to this license grant from
  51483. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51484. + * below, then you are not authorized to use the Software.
  51485. + *
  51486. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51487. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51488. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51489. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51490. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51491. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51492. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51493. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51494. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51495. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51496. + * DAMAGE.
  51497. + * ========================================================================== */
  51498. +
  51499. +#if !defined(__DWC_CFI_COMMON_H__)
  51500. +#define __DWC_CFI_COMMON_H__
  51501. +
  51502. +//#include <linux/types.h>
  51503. +
  51504. +/**
  51505. + * @file
  51506. + *
  51507. + * This file contains the CFI specific common constants, interfaces
  51508. + * (functions and macros) and structures for Linux. No PCD specific
  51509. + * data structure or definition is to be included in this file.
  51510. + *
  51511. + */
  51512. +
  51513. +/** This is a request for all Core Features */
  51514. +#define VEN_CORE_GET_FEATURES 0xB1
  51515. +
  51516. +/** This is a request to get the value of a specific Core Feature */
  51517. +#define VEN_CORE_GET_FEATURE 0xB2
  51518. +
  51519. +/** This command allows the host to set the value of a specific Core Feature */
  51520. +#define VEN_CORE_SET_FEATURE 0xB3
  51521. +
  51522. +/** This command allows the host to set the default values of
  51523. + * either all or any specific Core Feature
  51524. + */
  51525. +#define VEN_CORE_RESET_FEATURES 0xB4
  51526. +
  51527. +/** This command forces the PCD to write the deferred values of a Core Features */
  51528. +#define VEN_CORE_ACTIVATE_FEATURES 0xB5
  51529. +
  51530. +/** This request reads a DWORD value from a register at the specified offset */
  51531. +#define VEN_CORE_READ_REGISTER 0xB6
  51532. +
  51533. +/** This request writes a DWORD value into a register at the specified offset */
  51534. +#define VEN_CORE_WRITE_REGISTER 0xB7
  51535. +
  51536. +/** This structure is the header of the Core Features dataset returned to
  51537. + * the Host
  51538. + */
  51539. +struct cfi_all_features_header {
  51540. +/** The features header structure length is */
  51541. +#define CFI_ALL_FEATURES_HDR_LEN 8
  51542. + /**
  51543. + * The total length of the features dataset returned to the Host
  51544. + */
  51545. + uint16_t wTotalLen;
  51546. +
  51547. + /**
  51548. + * CFI version number inBinary-Coded Decimal (i.e., 1.00 is 100H).
  51549. + * This field identifies the version of the CFI Specification with which
  51550. + * the device is compliant.
  51551. + */
  51552. + uint16_t wVersion;
  51553. +
  51554. + /** The ID of the Core */
  51555. + uint16_t wCoreID;
  51556. +#define CFI_CORE_ID_UDC 1
  51557. +#define CFI_CORE_ID_OTG 2
  51558. +#define CFI_CORE_ID_WUDEV 3
  51559. +
  51560. + /** Number of features returned by VEN_CORE_GET_FEATURES request */
  51561. + uint16_t wNumFeatures;
  51562. +} UPACKED;
  51563. +
  51564. +typedef struct cfi_all_features_header cfi_all_features_header_t;
  51565. +
  51566. +/** This structure is a header of the Core Feature descriptor dataset returned to
  51567. + * the Host after the VEN_CORE_GET_FEATURES request
  51568. + */
  51569. +struct cfi_feature_desc_header {
  51570. +#define CFI_FEATURE_DESC_HDR_LEN 8
  51571. +
  51572. + /** The feature ID */
  51573. + uint16_t wFeatureID;
  51574. +
  51575. + /** Length of this feature descriptor in bytes - including the
  51576. + * length of the feature name string
  51577. + */
  51578. + uint16_t wLength;
  51579. +
  51580. + /** The data length of this feature in bytes */
  51581. + uint16_t wDataLength;
  51582. +
  51583. + /**
  51584. + * Attributes of this features
  51585. + * D0: Access rights
  51586. + * 0 - Read/Write
  51587. + * 1 - Read only
  51588. + */
  51589. + uint8_t bmAttributes;
  51590. +#define CFI_FEATURE_ATTR_RO 1
  51591. +#define CFI_FEATURE_ATTR_RW 0
  51592. +
  51593. + /** Length of the feature name in bytes */
  51594. + uint8_t bNameLen;
  51595. +
  51596. + /** The feature name buffer */
  51597. + //uint8_t *name;
  51598. +} UPACKED;
  51599. +
  51600. +typedef struct cfi_feature_desc_header cfi_feature_desc_header_t;
  51601. +
  51602. +/**
  51603. + * This structure describes a NULL terminated string referenced by its id field.
  51604. + * It is very similar to usb_string structure but has the id field type set to 16-bit.
  51605. + */
  51606. +struct cfi_string {
  51607. + uint16_t id;
  51608. + const uint8_t *s;
  51609. +};
  51610. +typedef struct cfi_string cfi_string_t;
  51611. +
  51612. +#endif
  51613. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_adp.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c
  51614. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_adp.c 1970-01-01 01:00:00.000000000 +0100
  51615. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c 2014-04-24 16:04:39.815124215 +0200
  51616. @@ -0,0 +1,854 @@
  51617. +/* ==========================================================================
  51618. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.c $
  51619. + * $Revision: #12 $
  51620. + * $Date: 2011/10/26 $
  51621. + * $Change: 1873028 $
  51622. + *
  51623. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51624. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51625. + * otherwise expressly agreed to in writing between Synopsys and you.
  51626. + *
  51627. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51628. + * any End User Software License Agreement or Agreement for Licensed Product
  51629. + * with Synopsys or any supplement thereto. You are permitted to use and
  51630. + * redistribute this Software in source and binary forms, with or without
  51631. + * modification, provided that redistributions of source code must retain this
  51632. + * notice. You may not view, use, disclose, copy or distribute this file or
  51633. + * any information contained herein except pursuant to this license grant from
  51634. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51635. + * below, then you are not authorized to use the Software.
  51636. + *
  51637. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51638. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51639. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51640. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51641. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51642. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51643. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51644. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51645. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51646. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51647. + * DAMAGE.
  51648. + * ========================================================================== */
  51649. +
  51650. +#include "dwc_os.h"
  51651. +#include "dwc_otg_regs.h"
  51652. +#include "dwc_otg_cil.h"
  51653. +#include "dwc_otg_adp.h"
  51654. +
  51655. +/** @file
  51656. + *
  51657. + * This file contains the most of the Attach Detect Protocol implementation for
  51658. + * the driver to support OTG Rev2.0.
  51659. + *
  51660. + */
  51661. +
  51662. +void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value)
  51663. +{
  51664. + adpctl_data_t adpctl;
  51665. +
  51666. + adpctl.d32 = value;
  51667. + adpctl.b.ar = 0x2;
  51668. +
  51669. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  51670. +
  51671. + while (adpctl.b.ar) {
  51672. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  51673. + }
  51674. +
  51675. +}
  51676. +
  51677. +/**
  51678. + * Function is called to read ADP registers
  51679. + */
  51680. +uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if)
  51681. +{
  51682. + adpctl_data_t adpctl;
  51683. +
  51684. + adpctl.d32 = 0;
  51685. + adpctl.b.ar = 0x1;
  51686. +
  51687. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  51688. +
  51689. + while (adpctl.b.ar) {
  51690. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  51691. + }
  51692. +
  51693. + return adpctl.d32;
  51694. +}
  51695. +
  51696. +/**
  51697. + * Function is called to read ADPCTL register and filter Write-clear bits
  51698. + */
  51699. +uint32_t dwc_otg_adp_read_reg_filter(dwc_otg_core_if_t * core_if)
  51700. +{
  51701. + adpctl_data_t adpctl;
  51702. +
  51703. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51704. + adpctl.b.adp_tmout_int = 0;
  51705. + adpctl.b.adp_prb_int = 0;
  51706. + adpctl.b.adp_tmout_int = 0;
  51707. +
  51708. + return adpctl.d32;
  51709. +}
  51710. +
  51711. +/**
  51712. + * Function is called to write ADP registers
  51713. + */
  51714. +void dwc_otg_adp_modify_reg(dwc_otg_core_if_t * core_if, uint32_t clr,
  51715. + uint32_t set)
  51716. +{
  51717. + dwc_otg_adp_write_reg(core_if,
  51718. + (dwc_otg_adp_read_reg(core_if) & (~clr)) | set);
  51719. +}
  51720. +
  51721. +static void adp_sense_timeout(void *ptr)
  51722. +{
  51723. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  51724. + core_if->adp.sense_timer_started = 0;
  51725. + DWC_PRINTF("ADP SENSE TIMEOUT\n");
  51726. + if (core_if->adp_enable) {
  51727. + dwc_otg_adp_sense_stop(core_if);
  51728. + dwc_otg_adp_probe_start(core_if);
  51729. + }
  51730. +}
  51731. +
  51732. +/**
  51733. + * This function is called when the ADP vbus timer expires. Timeout is 1.1s.
  51734. + */
  51735. +static void adp_vbuson_timeout(void *ptr)
  51736. +{
  51737. + gpwrdn_data_t gpwrdn;
  51738. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  51739. + hprt0_data_t hprt0 = {.d32 = 0 };
  51740. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  51741. + DWC_PRINTF("%s: 1.1 seconds expire after turning on VBUS\n",__FUNCTION__);
  51742. + if (core_if) {
  51743. + core_if->adp.vbuson_timer_started = 0;
  51744. + /* Turn off vbus */
  51745. + hprt0.b.prtpwr = 1;
  51746. + DWC_MODIFY_REG32(core_if->host_if->hprt0, hprt0.d32, 0);
  51747. + gpwrdn.d32 = 0;
  51748. +
  51749. + /* Power off the core */
  51750. + if (core_if->power_down == 2) {
  51751. + /* Enable Wakeup Logic */
  51752. +// gpwrdn.b.wkupactiv = 1;
  51753. + gpwrdn.b.pmuactv = 0;
  51754. + gpwrdn.b.pwrdnrstn = 1;
  51755. + gpwrdn.b.pwrdnclmp = 1;
  51756. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  51757. + gpwrdn.d32);
  51758. +
  51759. + /* Suspend the Phy Clock */
  51760. + pcgcctl.b.stoppclk = 1;
  51761. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  51762. +
  51763. + /* Switch on VDD */
  51764. +// gpwrdn.b.wkupactiv = 1;
  51765. + gpwrdn.b.pmuactv = 1;
  51766. + gpwrdn.b.pwrdnrstn = 1;
  51767. + gpwrdn.b.pwrdnclmp = 1;
  51768. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  51769. + gpwrdn.d32);
  51770. + } else {
  51771. + /* Enable Power Down Logic */
  51772. + gpwrdn.b.pmuintsel = 1;
  51773. + gpwrdn.b.pmuactv = 1;
  51774. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51775. + }
  51776. +
  51777. + /* Power off the core */
  51778. + if (core_if->power_down == 2) {
  51779. + gpwrdn.d32 = 0;
  51780. + gpwrdn.b.pwrdnswtch = 1;
  51781. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn,
  51782. + gpwrdn.d32, 0);
  51783. + }
  51784. +
  51785. + /* Unmask SRP detected interrupt from Power Down Logic */
  51786. + gpwrdn.d32 = 0;
  51787. + gpwrdn.b.srp_det_msk = 1;
  51788. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51789. +
  51790. + dwc_otg_adp_probe_start(core_if);
  51791. + dwc_otg_dump_global_registers(core_if);
  51792. + dwc_otg_dump_host_registers(core_if);
  51793. + }
  51794. +
  51795. +}
  51796. +
  51797. +/**
  51798. + * Start the ADP Initial Probe timer to detect if Port Connected interrupt is
  51799. + * not asserted within 1.1 seconds.
  51800. + *
  51801. + * @param core_if the pointer to core_if strucure.
  51802. + */
  51803. +void dwc_otg_adp_vbuson_timer_start(dwc_otg_core_if_t * core_if)
  51804. +{
  51805. + core_if->adp.vbuson_timer_started = 1;
  51806. + if (core_if->adp.vbuson_timer)
  51807. + {
  51808. + DWC_PRINTF("SCHEDULING VBUSON TIMER\n");
  51809. + /* 1.1 secs + 60ms necessary for cil_hcd_start*/
  51810. + DWC_TIMER_SCHEDULE(core_if->adp.vbuson_timer, 1160);
  51811. + } else {
  51812. + DWC_WARN("VBUSON_TIMER = %p\n",core_if->adp.vbuson_timer);
  51813. + }
  51814. +}
  51815. +
  51816. +#if 0
  51817. +/**
  51818. + * Masks all DWC OTG core interrupts
  51819. + *
  51820. + */
  51821. +static void mask_all_interrupts(dwc_otg_core_if_t * core_if)
  51822. +{
  51823. + int i;
  51824. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  51825. +
  51826. + /* Mask Host Interrupts */
  51827. +
  51828. + /* Clear and disable HCINTs */
  51829. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  51830. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk, 0);
  51831. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcint, 0xFFFFFFFF);
  51832. +
  51833. + }
  51834. +
  51835. + /* Clear and disable HAINT */
  51836. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk, 0x0000);
  51837. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haint, 0xFFFFFFFF);
  51838. +
  51839. + /* Mask Device Interrupts */
  51840. + if (!core_if->multiproc_int_enable) {
  51841. + /* Clear and disable IN Endpoint interrupts */
  51842. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, 0);
  51843. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  51844. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  51845. + diepint, 0xFFFFFFFF);
  51846. + }
  51847. +
  51848. + /* Clear and disable OUT Endpoint interrupts */
  51849. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, 0);
  51850. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  51851. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  51852. + doepint, 0xFFFFFFFF);
  51853. + }
  51854. +
  51855. + /* Clear and disable DAINT */
  51856. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daint,
  51857. + 0xFFFFFFFF);
  51858. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, 0);
  51859. + } else {
  51860. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  51861. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  51862. + diepeachintmsk[i], 0);
  51863. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  51864. + diepint, 0xFFFFFFFF);
  51865. + }
  51866. +
  51867. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  51868. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  51869. + doepeachintmsk[i], 0);
  51870. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  51871. + doepint, 0xFFFFFFFF);
  51872. + }
  51873. +
  51874. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  51875. + 0);
  51876. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachint,
  51877. + 0xFFFFFFFF);
  51878. +
  51879. + }
  51880. +
  51881. + /* Disable interrupts */
  51882. + ahbcfg.b.glblintrmsk = 1;
  51883. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  51884. +
  51885. + /* Disable all interrupts. */
  51886. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  51887. +
  51888. + /* Clear any pending interrupts */
  51889. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  51890. +
  51891. + /* Clear any pending OTG Interrupts */
  51892. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, 0xFFFFFFFF);
  51893. +}
  51894. +
  51895. +/**
  51896. + * Unmask Port Connection Detected interrupt
  51897. + *
  51898. + */
  51899. +static void unmask_conn_det_intr(dwc_otg_core_if_t * core_if)
  51900. +{
  51901. + gintmsk_data_t gintmsk = {.d32 = 0,.b.portintr = 1 };
  51902. +
  51903. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  51904. +}
  51905. +#endif
  51906. +
  51907. +/**
  51908. + * Starts the ADP Probing
  51909. + *
  51910. + * @param core_if the pointer to core_if structure.
  51911. + */
  51912. +uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if)
  51913. +{
  51914. +
  51915. + adpctl_data_t adpctl = {.d32 = 0};
  51916. + gpwrdn_data_t gpwrdn;
  51917. +#if 0
  51918. + adpctl_data_t adpctl_int = {.d32 = 0, .b.adp_prb_int = 1,
  51919. + .b.adp_sns_int = 1, b.adp_tmout_int};
  51920. +#endif
  51921. + dwc_otg_disable_global_interrupts(core_if);
  51922. + DWC_PRINTF("ADP Probe Start\n");
  51923. + core_if->adp.probe_enabled = 1;
  51924. +
  51925. + adpctl.b.adpres = 1;
  51926. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51927. +
  51928. + while (adpctl.b.adpres) {
  51929. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51930. + }
  51931. +
  51932. + adpctl.d32 = 0;
  51933. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51934. +
  51935. + /* In Host mode unmask SRP detected interrupt */
  51936. + gpwrdn.d32 = 0;
  51937. + gpwrdn.b.sts_chngint_msk = 1;
  51938. + if (!gpwrdn.b.idsts) {
  51939. + gpwrdn.b.srp_det_msk = 1;
  51940. + }
  51941. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51942. +
  51943. + adpctl.b.adp_tmout_int_msk = 1;
  51944. + adpctl.b.adp_prb_int_msk = 1;
  51945. + adpctl.b.prb_dschg = 1;
  51946. + adpctl.b.prb_delta = 1;
  51947. + adpctl.b.prb_per = 1;
  51948. + adpctl.b.adpen = 1;
  51949. + adpctl.b.enaprb = 1;
  51950. +
  51951. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51952. + DWC_PRINTF("ADP Probe Finish\n");
  51953. + return 0;
  51954. +}
  51955. +
  51956. +/**
  51957. + * Starts the ADP Sense timer to detect if ADP Sense interrupt is not asserted
  51958. + * within 3 seconds.
  51959. + *
  51960. + * @param core_if the pointer to core_if strucure.
  51961. + */
  51962. +void dwc_otg_adp_sense_timer_start(dwc_otg_core_if_t * core_if)
  51963. +{
  51964. + core_if->adp.sense_timer_started = 1;
  51965. + DWC_TIMER_SCHEDULE(core_if->adp.sense_timer, 3000 /* 3 secs */ );
  51966. +}
  51967. +
  51968. +/**
  51969. + * Starts the ADP Sense
  51970. + *
  51971. + * @param core_if the pointer to core_if strucure.
  51972. + */
  51973. +uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if)
  51974. +{
  51975. + adpctl_data_t adpctl;
  51976. +
  51977. + DWC_PRINTF("ADP Sense Start\n");
  51978. +
  51979. + /* Unmask ADP sense interrupt and mask all other from the core */
  51980. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  51981. + adpctl.b.adp_sns_int_msk = 1;
  51982. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51983. + dwc_otg_disable_global_interrupts(core_if); // vahrama
  51984. +
  51985. + /* Set ADP reset bit*/
  51986. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  51987. + adpctl.b.adpres = 1;
  51988. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51989. +
  51990. + while (adpctl.b.adpres) {
  51991. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51992. + }
  51993. +
  51994. + adpctl.b.adpres = 0;
  51995. + adpctl.b.adpen = 1;
  51996. + adpctl.b.enasns = 1;
  51997. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51998. +
  51999. + dwc_otg_adp_sense_timer_start(core_if);
  52000. +
  52001. + return 0;
  52002. +}
  52003. +
  52004. +/**
  52005. + * Stops the ADP Probing
  52006. + *
  52007. + * @param core_if the pointer to core_if strucure.
  52008. + */
  52009. +uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if)
  52010. +{
  52011. +
  52012. + adpctl_data_t adpctl;
  52013. + DWC_PRINTF("Stop ADP probe\n");
  52014. + core_if->adp.probe_enabled = 0;
  52015. + core_if->adp.probe_counter = 0;
  52016. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52017. +
  52018. + adpctl.b.adpen = 0;
  52019. + adpctl.b.adp_prb_int = 1;
  52020. + adpctl.b.adp_tmout_int = 1;
  52021. + adpctl.b.adp_sns_int = 1;
  52022. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52023. +
  52024. + return 0;
  52025. +}
  52026. +
  52027. +/**
  52028. + * Stops the ADP Sensing
  52029. + *
  52030. + * @param core_if the pointer to core_if strucure.
  52031. + */
  52032. +uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if)
  52033. +{
  52034. + adpctl_data_t adpctl;
  52035. +
  52036. + core_if->adp.sense_enabled = 0;
  52037. +
  52038. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  52039. + adpctl.b.enasns = 0;
  52040. + adpctl.b.adp_sns_int = 1;
  52041. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52042. +
  52043. + return 0;
  52044. +}
  52045. +
  52046. +/**
  52047. + * Called to turn on the VBUS after initial ADP probe in host mode.
  52048. + * If port power was already enabled in cil_hcd_start function then
  52049. + * only schedule a timer.
  52050. + *
  52051. + * @param core_if the pointer to core_if structure.
  52052. + */
  52053. +void dwc_otg_adp_turnon_vbus(dwc_otg_core_if_t * core_if)
  52054. +{
  52055. + hprt0_data_t hprt0 = {.d32 = 0 };
  52056. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  52057. + DWC_PRINTF("Turn on VBUS for 1.1s, port power is %d\n", hprt0.b.prtpwr);
  52058. +
  52059. + if (hprt0.b.prtpwr == 0) {
  52060. + hprt0.b.prtpwr = 1;
  52061. + //DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  52062. + }
  52063. +
  52064. + dwc_otg_adp_vbuson_timer_start(core_if);
  52065. +}
  52066. +
  52067. +/**
  52068. + * Called right after driver is loaded
  52069. + * to perform initial actions for ADP
  52070. + *
  52071. + * @param core_if the pointer to core_if structure.
  52072. + * @param is_host - flag for current mode of operation either from GINTSTS or GPWRDN
  52073. + */
  52074. +void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host)
  52075. +{
  52076. + gpwrdn_data_t gpwrdn;
  52077. +
  52078. + DWC_PRINTF("ADP Initial Start\n");
  52079. + core_if->adp.adp_started = 1;
  52080. +
  52081. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  52082. + dwc_otg_disable_global_interrupts(core_if);
  52083. + if (is_host) {
  52084. + DWC_PRINTF("HOST MODE\n");
  52085. + /* Enable Power Down Logic Interrupt*/
  52086. + gpwrdn.d32 = 0;
  52087. + gpwrdn.b.pmuintsel = 1;
  52088. + gpwrdn.b.pmuactv = 1;
  52089. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  52090. + /* Initialize first ADP probe to obtain Ramp Time value */
  52091. + core_if->adp.initial_probe = 1;
  52092. + dwc_otg_adp_probe_start(core_if);
  52093. + } else {
  52094. + gotgctl_data_t gotgctl;
  52095. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  52096. + DWC_PRINTF("DEVICE MODE\n");
  52097. + if (gotgctl.b.bsesvld == 0) {
  52098. + /* Enable Power Down Logic Interrupt*/
  52099. + gpwrdn.d32 = 0;
  52100. + DWC_PRINTF("VBUS is not valid - start ADP probe\n");
  52101. + gpwrdn.b.pmuintsel = 1;
  52102. + gpwrdn.b.pmuactv = 1;
  52103. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  52104. + core_if->adp.initial_probe = 1;
  52105. + dwc_otg_adp_probe_start(core_if);
  52106. + } else {
  52107. + DWC_PRINTF("VBUS is valid - initialize core as a Device\n");
  52108. + core_if->op_state = B_PERIPHERAL;
  52109. + dwc_otg_core_init(core_if);
  52110. + dwc_otg_enable_global_interrupts(core_if);
  52111. + cil_pcd_start(core_if);
  52112. + dwc_otg_dump_global_registers(core_if);
  52113. + dwc_otg_dump_dev_registers(core_if);
  52114. + }
  52115. + }
  52116. +}
  52117. +
  52118. +void dwc_otg_adp_init(dwc_otg_core_if_t * core_if)
  52119. +{
  52120. + core_if->adp.adp_started = 0;
  52121. + core_if->adp.initial_probe = 0;
  52122. + core_if->adp.probe_timer_values[0] = -1;
  52123. + core_if->adp.probe_timer_values[1] = -1;
  52124. + core_if->adp.probe_enabled = 0;
  52125. + core_if->adp.sense_enabled = 0;
  52126. + core_if->adp.sense_timer_started = 0;
  52127. + core_if->adp.vbuson_timer_started = 0;
  52128. + core_if->adp.probe_counter = 0;
  52129. + core_if->adp.gpwrdn = 0;
  52130. + core_if->adp.attached = DWC_OTG_ADP_UNKOWN;
  52131. + /* Initialize timers */
  52132. + core_if->adp.sense_timer =
  52133. + DWC_TIMER_ALLOC("ADP SENSE TIMER", adp_sense_timeout, core_if);
  52134. + core_if->adp.vbuson_timer =
  52135. + DWC_TIMER_ALLOC("ADP VBUS ON TIMER", adp_vbuson_timeout, core_if);
  52136. + if (!core_if->adp.sense_timer || !core_if->adp.vbuson_timer)
  52137. + {
  52138. + DWC_ERROR("Could not allocate memory for ADP timers\n");
  52139. + }
  52140. +}
  52141. +
  52142. +void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if)
  52143. +{
  52144. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  52145. + gpwrdn.b.pmuintsel = 1;
  52146. + gpwrdn.b.pmuactv = 1;
  52147. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52148. +
  52149. + if (core_if->adp.probe_enabled)
  52150. + dwc_otg_adp_probe_stop(core_if);
  52151. + if (core_if->adp.sense_enabled)
  52152. + dwc_otg_adp_sense_stop(core_if);
  52153. + if (core_if->adp.sense_timer_started)
  52154. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  52155. + if (core_if->adp.vbuson_timer_started)
  52156. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  52157. + DWC_TIMER_FREE(core_if->adp.sense_timer);
  52158. + DWC_TIMER_FREE(core_if->adp.vbuson_timer);
  52159. +}
  52160. +
  52161. +/////////////////////////////////////////////////////////////////////
  52162. +////////////// ADP Interrupt Handlers ///////////////////////////////
  52163. +/////////////////////////////////////////////////////////////////////
  52164. +/**
  52165. + * This function sets Ramp Timer values
  52166. + */
  52167. +static uint32_t set_timer_value(dwc_otg_core_if_t * core_if, uint32_t val)
  52168. +{
  52169. + if (core_if->adp.probe_timer_values[0] == -1) {
  52170. + core_if->adp.probe_timer_values[0] = val;
  52171. + core_if->adp.probe_timer_values[1] = -1;
  52172. + return 1;
  52173. + } else {
  52174. + core_if->adp.probe_timer_values[1] =
  52175. + core_if->adp.probe_timer_values[0];
  52176. + core_if->adp.probe_timer_values[0] = val;
  52177. + return 0;
  52178. + }
  52179. +}
  52180. +
  52181. +/**
  52182. + * This function compares Ramp Timer values
  52183. + */
  52184. +static uint32_t compare_timer_values(dwc_otg_core_if_t * core_if)
  52185. +{
  52186. + uint32_t diff;
  52187. + if (core_if->adp.probe_timer_values[0]>=core_if->adp.probe_timer_values[1])
  52188. + diff = core_if->adp.probe_timer_values[0]-core_if->adp.probe_timer_values[1];
  52189. + else
  52190. + diff = core_if->adp.probe_timer_values[1]-core_if->adp.probe_timer_values[0];
  52191. + if(diff < 2) {
  52192. + return 0;
  52193. + } else {
  52194. + return 1;
  52195. + }
  52196. +}
  52197. +
  52198. +/**
  52199. + * This function handles ADP Probe Interrupts
  52200. + */
  52201. +static int32_t dwc_otg_adp_handle_prb_intr(dwc_otg_core_if_t * core_if,
  52202. + uint32_t val)
  52203. +{
  52204. + adpctl_data_t adpctl = {.d32 = 0 };
  52205. + gpwrdn_data_t gpwrdn, temp;
  52206. + adpctl.d32 = val;
  52207. +
  52208. + temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52209. + core_if->adp.probe_counter++;
  52210. + core_if->adp.gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52211. + if (adpctl.b.rtim == 0 && !temp.b.idsts){
  52212. + DWC_PRINTF("RTIM value is 0\n");
  52213. + goto exit;
  52214. + }
  52215. + if (set_timer_value(core_if, adpctl.b.rtim) &&
  52216. + core_if->adp.initial_probe) {
  52217. + core_if->adp.initial_probe = 0;
  52218. + dwc_otg_adp_probe_stop(core_if);
  52219. + gpwrdn.d32 = 0;
  52220. + gpwrdn.b.pmuactv = 1;
  52221. + gpwrdn.b.pmuintsel = 1;
  52222. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52223. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  52224. +
  52225. + /* check which value is for device mode and which for Host mode */
  52226. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  52227. + /*
  52228. + * Turn on VBUS after initial ADP probe.
  52229. + */
  52230. + core_if->op_state = A_HOST;
  52231. + dwc_otg_enable_global_interrupts(core_if);
  52232. + DWC_SPINUNLOCK(core_if->lock);
  52233. + cil_hcd_start(core_if);
  52234. + dwc_otg_adp_turnon_vbus(core_if);
  52235. + DWC_SPINLOCK(core_if->lock);
  52236. + } else {
  52237. + /*
  52238. + * Initiate SRP after initial ADP probe.
  52239. + */
  52240. + dwc_otg_enable_global_interrupts(core_if);
  52241. + dwc_otg_initiate_srp(core_if);
  52242. + }
  52243. + } else if (core_if->adp.probe_counter > 2){
  52244. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52245. + if (compare_timer_values(core_if)) {
  52246. + DWC_PRINTF("Difference in timer values !!! \n");
  52247. +// core_if->adp.attached = DWC_OTG_ADP_ATTACHED;
  52248. + dwc_otg_adp_probe_stop(core_if);
  52249. +
  52250. + /* Power on the core */
  52251. + if (core_if->power_down == 2) {
  52252. + gpwrdn.b.pwrdnswtch = 1;
  52253. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52254. + gpwrdn, 0, gpwrdn.d32);
  52255. + }
  52256. +
  52257. + /* check which value is for device mode and which for Host mode */
  52258. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  52259. + /* Disable Interrupt from Power Down Logic */
  52260. + gpwrdn.d32 = 0;
  52261. + gpwrdn.b.pmuintsel = 1;
  52262. + gpwrdn.b.pmuactv = 1;
  52263. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52264. + gpwrdn, gpwrdn.d32, 0);
  52265. +
  52266. + /*
  52267. + * Initialize the Core for Host mode.
  52268. + */
  52269. + core_if->op_state = A_HOST;
  52270. + dwc_otg_core_init(core_if);
  52271. + dwc_otg_enable_global_interrupts(core_if);
  52272. + cil_hcd_start(core_if);
  52273. + } else {
  52274. + gotgctl_data_t gotgctl;
  52275. + /* Mask SRP detected interrupt from Power Down Logic */
  52276. + gpwrdn.d32 = 0;
  52277. + gpwrdn.b.srp_det_msk = 1;
  52278. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52279. + gpwrdn, gpwrdn.d32, 0);
  52280. +
  52281. + /* Disable Power Down Logic */
  52282. + gpwrdn.d32 = 0;
  52283. + gpwrdn.b.pmuintsel = 1;
  52284. + gpwrdn.b.pmuactv = 1;
  52285. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52286. + gpwrdn, gpwrdn.d32, 0);
  52287. +
  52288. + /*
  52289. + * Initialize the Core for Device mode.
  52290. + */
  52291. + core_if->op_state = B_PERIPHERAL;
  52292. + dwc_otg_core_init(core_if);
  52293. + dwc_otg_enable_global_interrupts(core_if);
  52294. + cil_pcd_start(core_if);
  52295. +
  52296. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  52297. + if (!gotgctl.b.bsesvld) {
  52298. + dwc_otg_initiate_srp(core_if);
  52299. + }
  52300. + }
  52301. + }
  52302. + if (core_if->power_down == 2) {
  52303. + if (gpwrdn.b.bsessvld) {
  52304. + /* Mask SRP detected interrupt from Power Down Logic */
  52305. + gpwrdn.d32 = 0;
  52306. + gpwrdn.b.srp_det_msk = 1;
  52307. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52308. +
  52309. + /* Disable Power Down Logic */
  52310. + gpwrdn.d32 = 0;
  52311. + gpwrdn.b.pmuactv = 1;
  52312. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52313. +
  52314. + /*
  52315. + * Initialize the Core for Device mode.
  52316. + */
  52317. + core_if->op_state = B_PERIPHERAL;
  52318. + dwc_otg_core_init(core_if);
  52319. + dwc_otg_enable_global_interrupts(core_if);
  52320. + cil_pcd_start(core_if);
  52321. + }
  52322. + }
  52323. + }
  52324. +exit:
  52325. + /* Clear interrupt */
  52326. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52327. + adpctl.b.adp_prb_int = 1;
  52328. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52329. +
  52330. + return 0;
  52331. +}
  52332. +
  52333. +/**
  52334. + * This function hadles ADP Sense Interrupt
  52335. + */
  52336. +static int32_t dwc_otg_adp_handle_sns_intr(dwc_otg_core_if_t * core_if)
  52337. +{
  52338. + adpctl_data_t adpctl;
  52339. + /* Stop ADP Sense timer */
  52340. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  52341. +
  52342. + /* Restart ADP Sense timer */
  52343. + dwc_otg_adp_sense_timer_start(core_if);
  52344. +
  52345. + /* Clear interrupt */
  52346. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52347. + adpctl.b.adp_sns_int = 1;
  52348. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52349. +
  52350. + return 0;
  52351. +}
  52352. +
  52353. +/**
  52354. + * This function handles ADP Probe Interrupts
  52355. + */
  52356. +static int32_t dwc_otg_adp_handle_prb_tmout_intr(dwc_otg_core_if_t * core_if,
  52357. + uint32_t val)
  52358. +{
  52359. + adpctl_data_t adpctl = {.d32 = 0 };
  52360. + adpctl.d32 = val;
  52361. + set_timer_value(core_if, adpctl.b.rtim);
  52362. +
  52363. + /* Clear interrupt */
  52364. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52365. + adpctl.b.adp_tmout_int = 1;
  52366. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52367. +
  52368. + return 0;
  52369. +}
  52370. +
  52371. +/**
  52372. + * ADP Interrupt handler.
  52373. + *
  52374. + */
  52375. +int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if)
  52376. +{
  52377. + int retval = 0;
  52378. + adpctl_data_t adpctl = {.d32 = 0};
  52379. +
  52380. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52381. + DWC_PRINTF("ADPCTL = %08x\n",adpctl.d32);
  52382. +
  52383. + if (adpctl.b.adp_sns_int & adpctl.b.adp_sns_int_msk) {
  52384. + DWC_PRINTF("ADP Sense interrupt\n");
  52385. + retval |= dwc_otg_adp_handle_sns_intr(core_if);
  52386. + }
  52387. + if (adpctl.b.adp_tmout_int & adpctl.b.adp_tmout_int_msk) {
  52388. + DWC_PRINTF("ADP timeout interrupt\n");
  52389. + retval |= dwc_otg_adp_handle_prb_tmout_intr(core_if, adpctl.d32);
  52390. + }
  52391. + if (adpctl.b.adp_prb_int & adpctl.b.adp_prb_int_msk) {
  52392. + DWC_PRINTF("ADP Probe interrupt\n");
  52393. + adpctl.b.adp_prb_int = 1;
  52394. + retval |= dwc_otg_adp_handle_prb_intr(core_if, adpctl.d32);
  52395. + }
  52396. +
  52397. +// dwc_otg_adp_modify_reg(core_if, adpctl.d32, 0);
  52398. + //dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52399. + DWC_PRINTF("RETURN FROM ADP ISR\n");
  52400. +
  52401. + return retval;
  52402. +}
  52403. +
  52404. +/**
  52405. + *
  52406. + * @param core_if Programming view of DWC_otg controller.
  52407. + */
  52408. +int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if)
  52409. +{
  52410. +
  52411. +#ifndef DWC_HOST_ONLY
  52412. + hprt0_data_t hprt0;
  52413. + gpwrdn_data_t gpwrdn;
  52414. + DWC_DEBUGPL(DBG_ANY, "++ Power Down Logic Session Request Interrupt++\n");
  52415. +
  52416. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52417. + /* check which value is for device mode and which for Host mode */
  52418. + if (!gpwrdn.b.idsts) { /* considered host mode value is 0 */
  52419. + DWC_PRINTF("SRP: Host mode\n");
  52420. +
  52421. + if (core_if->adp_enable) {
  52422. + dwc_otg_adp_probe_stop(core_if);
  52423. +
  52424. + /* Power on the core */
  52425. + if (core_if->power_down == 2) {
  52426. + gpwrdn.b.pwrdnswtch = 1;
  52427. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52428. + gpwrdn, 0, gpwrdn.d32);
  52429. + }
  52430. +
  52431. + core_if->op_state = A_HOST;
  52432. + dwc_otg_core_init(core_if);
  52433. + dwc_otg_enable_global_interrupts(core_if);
  52434. + cil_hcd_start(core_if);
  52435. + }
  52436. +
  52437. + /* Turn on the port power bit. */
  52438. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  52439. + hprt0.b.prtpwr = 1;
  52440. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  52441. +
  52442. + /* Start the Connection timer. So a message can be displayed
  52443. + * if connect does not occur within 10 seconds. */
  52444. + cil_hcd_session_start(core_if);
  52445. + } else {
  52446. + DWC_PRINTF("SRP: Device mode %s\n", __FUNCTION__);
  52447. + if (core_if->adp_enable) {
  52448. + dwc_otg_adp_probe_stop(core_if);
  52449. +
  52450. + /* Power on the core */
  52451. + if (core_if->power_down == 2) {
  52452. + gpwrdn.b.pwrdnswtch = 1;
  52453. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52454. + gpwrdn, 0, gpwrdn.d32);
  52455. + }
  52456. +
  52457. + gpwrdn.d32 = 0;
  52458. + gpwrdn.b.pmuactv = 0;
  52459. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  52460. + gpwrdn.d32);
  52461. +
  52462. + core_if->op_state = B_PERIPHERAL;
  52463. + dwc_otg_core_init(core_if);
  52464. + dwc_otg_enable_global_interrupts(core_if);
  52465. + cil_pcd_start(core_if);
  52466. + }
  52467. + }
  52468. +#endif
  52469. + return 1;
  52470. +}
  52471. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_adp.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h
  52472. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_adp.h 1970-01-01 01:00:00.000000000 +0100
  52473. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h 2014-04-24 16:04:39.815124215 +0200
  52474. @@ -0,0 +1,80 @@
  52475. +/* ==========================================================================
  52476. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.h $
  52477. + * $Revision: #7 $
  52478. + * $Date: 2011/10/24 $
  52479. + * $Change: 1871159 $
  52480. + *
  52481. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52482. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52483. + * otherwise expressly agreed to in writing between Synopsys and you.
  52484. + *
  52485. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52486. + * any End User Software License Agreement or Agreement for Licensed Product
  52487. + * with Synopsys or any supplement thereto. You are permitted to use and
  52488. + * redistribute this Software in source and binary forms, with or without
  52489. + * modification, provided that redistributions of source code must retain this
  52490. + * notice. You may not view, use, disclose, copy or distribute this file or
  52491. + * any information contained herein except pursuant to this license grant from
  52492. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52493. + * below, then you are not authorized to use the Software.
  52494. + *
  52495. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52496. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52497. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52498. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52499. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52500. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52501. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52502. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52503. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52504. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52505. + * DAMAGE.
  52506. + * ========================================================================== */
  52507. +
  52508. +#ifndef __DWC_OTG_ADP_H__
  52509. +#define __DWC_OTG_ADP_H__
  52510. +
  52511. +/**
  52512. + * @file
  52513. + *
  52514. + * This file contains the Attach Detect Protocol interfaces and defines
  52515. + * (functions) and structures for Linux.
  52516. + *
  52517. + */
  52518. +
  52519. +#define DWC_OTG_ADP_UNATTACHED 0
  52520. +#define DWC_OTG_ADP_ATTACHED 1
  52521. +#define DWC_OTG_ADP_UNKOWN 2
  52522. +
  52523. +typedef struct dwc_otg_adp {
  52524. + uint32_t adp_started;
  52525. + uint32_t initial_probe;
  52526. + int32_t probe_timer_values[2];
  52527. + uint32_t probe_enabled;
  52528. + uint32_t sense_enabled;
  52529. + dwc_timer_t *sense_timer;
  52530. + uint32_t sense_timer_started;
  52531. + dwc_timer_t *vbuson_timer;
  52532. + uint32_t vbuson_timer_started;
  52533. + uint32_t attached;
  52534. + uint32_t probe_counter;
  52535. + uint32_t gpwrdn;
  52536. +} dwc_otg_adp_t;
  52537. +
  52538. +/**
  52539. + * Attach Detect Protocol functions
  52540. + */
  52541. +
  52542. +extern void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value);
  52543. +extern uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if);
  52544. +extern uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if);
  52545. +extern uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if);
  52546. +extern uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if);
  52547. +extern uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if);
  52548. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  52549. +extern void dwc_otg_adp_init(dwc_otg_core_if_t * core_if);
  52550. +extern void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if);
  52551. +extern int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if);
  52552. +extern int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if);
  52553. +
  52554. +#endif //__DWC_OTG_ADP_H__
  52555. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_attr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c
  52556. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_attr.c 1970-01-01 01:00:00.000000000 +0100
  52557. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c 2014-04-24 16:04:39.815124215 +0200
  52558. @@ -0,0 +1,1210 @@
  52559. +/* ==========================================================================
  52560. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  52561. + * $Revision: #44 $
  52562. + * $Date: 2010/11/29 $
  52563. + * $Change: 1636033 $
  52564. + *
  52565. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52566. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52567. + * otherwise expressly agreed to in writing between Synopsys and you.
  52568. + *
  52569. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52570. + * any End User Software License Agreement or Agreement for Licensed Product
  52571. + * with Synopsys or any supplement thereto. You are permitted to use and
  52572. + * redistribute this Software in source and binary forms, with or without
  52573. + * modification, provided that redistributions of source code must retain this
  52574. + * notice. You may not view, use, disclose, copy or distribute this file or
  52575. + * any information contained herein except pursuant to this license grant from
  52576. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52577. + * below, then you are not authorized to use the Software.
  52578. + *
  52579. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52580. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52581. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52582. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52583. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52584. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52585. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52586. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52587. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52588. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52589. + * DAMAGE.
  52590. + * ========================================================================== */
  52591. +
  52592. +/** @file
  52593. + *
  52594. + * The diagnostic interface will provide access to the controller for
  52595. + * bringing up the hardware and testing. The Linux driver attributes
  52596. + * feature will be used to provide the Linux Diagnostic
  52597. + * Interface. These attributes are accessed through sysfs.
  52598. + */
  52599. +
  52600. +/** @page "Linux Module Attributes"
  52601. + *
  52602. + * The Linux module attributes feature is used to provide the Linux
  52603. + * Diagnostic Interface. These attributes are accessed through sysfs.
  52604. + * The diagnostic interface will provide access to the controller for
  52605. + * bringing up the hardware and testing.
  52606. +
  52607. + The following table shows the attributes.
  52608. + <table>
  52609. + <tr>
  52610. + <td><b> Name</b></td>
  52611. + <td><b> Description</b></td>
  52612. + <td><b> Access</b></td>
  52613. + </tr>
  52614. +
  52615. + <tr>
  52616. + <td> mode </td>
  52617. + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  52618. + <td> Read</td>
  52619. + </tr>
  52620. +
  52621. + <tr>
  52622. + <td> hnpcapable </td>
  52623. + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  52624. + Read returns the current value.</td>
  52625. + <td> Read/Write</td>
  52626. + </tr>
  52627. +
  52628. + <tr>
  52629. + <td> srpcapable </td>
  52630. + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  52631. + Read returns the current value.</td>
  52632. + <td> Read/Write</td>
  52633. + </tr>
  52634. +
  52635. + <tr>
  52636. + <td> hsic_connect </td>
  52637. + <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  52638. + Read returns the current value.</td>
  52639. + <td> Read/Write</td>
  52640. + </tr>
  52641. +
  52642. + <tr>
  52643. + <td> inv_sel_hsic </td>
  52644. + <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  52645. + Read returns the current value.</td>
  52646. + <td> Read/Write</td>
  52647. + </tr>
  52648. +
  52649. + <tr>
  52650. + <td> hnp </td>
  52651. + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  52652. + <td> Read/Write</td>
  52653. + </tr>
  52654. +
  52655. + <tr>
  52656. + <td> srp </td>
  52657. + <td> Initiates the Session Request Protocol. Read returns the status.</td>
  52658. + <td> Read/Write</td>
  52659. + </tr>
  52660. +
  52661. + <tr>
  52662. + <td> buspower </td>
  52663. + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  52664. + <td> Read/Write</td>
  52665. + </tr>
  52666. +
  52667. + <tr>
  52668. + <td> bussuspend </td>
  52669. + <td> Suspends the USB bus.</td>
  52670. + <td> Read/Write</td>
  52671. + </tr>
  52672. +
  52673. + <tr>
  52674. + <td> busconnected </td>
  52675. + <td> Gets the connection status of the bus</td>
  52676. + <td> Read</td>
  52677. + </tr>
  52678. +
  52679. + <tr>
  52680. + <td> gotgctl </td>
  52681. + <td> Gets or sets the Core Control Status Register.</td>
  52682. + <td> Read/Write</td>
  52683. + </tr>
  52684. +
  52685. + <tr>
  52686. + <td> gusbcfg </td>
  52687. + <td> Gets or sets the Core USB Configuration Register</td>
  52688. + <td> Read/Write</td>
  52689. + </tr>
  52690. +
  52691. + <tr>
  52692. + <td> grxfsiz </td>
  52693. + <td> Gets or sets the Receive FIFO Size Register</td>
  52694. + <td> Read/Write</td>
  52695. + </tr>
  52696. +
  52697. + <tr>
  52698. + <td> gnptxfsiz </td>
  52699. + <td> Gets or sets the non-periodic Transmit Size Register</td>
  52700. + <td> Read/Write</td>
  52701. + </tr>
  52702. +
  52703. + <tr>
  52704. + <td> gpvndctl </td>
  52705. + <td> Gets or sets the PHY Vendor Control Register</td>
  52706. + <td> Read/Write</td>
  52707. + </tr>
  52708. +
  52709. + <tr>
  52710. + <td> ggpio </td>
  52711. + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  52712. + or sets the upper 16 bits.</td>
  52713. + <td> Read/Write</td>
  52714. + </tr>
  52715. +
  52716. + <tr>
  52717. + <td> guid </td>
  52718. + <td> Gets or sets the value of the User ID Register</td>
  52719. + <td> Read/Write</td>
  52720. + </tr>
  52721. +
  52722. + <tr>
  52723. + <td> gsnpsid </td>
  52724. + <td> Gets the value of the Synopsys ID Regester</td>
  52725. + <td> Read</td>
  52726. + </tr>
  52727. +
  52728. + <tr>
  52729. + <td> devspeed </td>
  52730. + <td> Gets or sets the device speed setting in the DCFG register</td>
  52731. + <td> Read/Write</td>
  52732. + </tr>
  52733. +
  52734. + <tr>
  52735. + <td> enumspeed </td>
  52736. + <td> Gets the device enumeration Speed.</td>
  52737. + <td> Read</td>
  52738. + </tr>
  52739. +
  52740. + <tr>
  52741. + <td> hptxfsiz </td>
  52742. + <td> Gets the value of the Host Periodic Transmit FIFO</td>
  52743. + <td> Read</td>
  52744. + </tr>
  52745. +
  52746. + <tr>
  52747. + <td> hprt0 </td>
  52748. + <td> Gets or sets the value in the Host Port Control and Status Register</td>
  52749. + <td> Read/Write</td>
  52750. + </tr>
  52751. +
  52752. + <tr>
  52753. + <td> regoffset </td>
  52754. + <td> Sets the register offset for the next Register Access</td>
  52755. + <td> Read/Write</td>
  52756. + </tr>
  52757. +
  52758. + <tr>
  52759. + <td> regvalue </td>
  52760. + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  52761. + <td> Read/Write</td>
  52762. + </tr>
  52763. +
  52764. + <tr>
  52765. + <td> remote_wakeup </td>
  52766. + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  52767. + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  52768. + Wakeup signalling bit in the Device Control Register is set for 1
  52769. + milli-second.</td>
  52770. + <td> Read/Write</td>
  52771. + </tr>
  52772. +
  52773. + <tr>
  52774. + <td> rem_wakeup_pwrdn </td>
  52775. + <td> On read, shows the status core - hibernated or not. On write, initiates
  52776. + a remote wakeup of the device from Hibernation. </td>
  52777. + <td> Read/Write</td>
  52778. + </tr>
  52779. +
  52780. + <tr>
  52781. + <td> mode_ch_tim_en </td>
  52782. + <td> This bit is used to enable or disable the host core to wait for 200 PHY
  52783. + clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  52784. + after Suspend or LPM. </td>
  52785. + <td> Read/Write</td>
  52786. + </tr>
  52787. +
  52788. + <tr>
  52789. + <td> fr_interval </td>
  52790. + <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  52791. + reload HFIR register during runtime. The application can write a value to this
  52792. + register only after the Port Enable bit of the Host Port Control and Status
  52793. + register (HPRT.PrtEnaPort) has been set </td>
  52794. + <td> Read/Write</td>
  52795. + </tr>
  52796. +
  52797. + <tr>
  52798. + <td> disconnect_us </td>
  52799. + <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  52800. + which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  52801. + <td> Read/Write</td>
  52802. + </tr>
  52803. +
  52804. + <tr>
  52805. + <td> regdump </td>
  52806. + <td> Dumps the contents of core registers.</td>
  52807. + <td> Read</td>
  52808. + </tr>
  52809. +
  52810. + <tr>
  52811. + <td> spramdump </td>
  52812. + <td> Dumps the contents of core registers.</td>
  52813. + <td> Read</td>
  52814. + </tr>
  52815. +
  52816. + <tr>
  52817. + <td> hcddump </td>
  52818. + <td> Dumps the current HCD state.</td>
  52819. + <td> Read</td>
  52820. + </tr>
  52821. +
  52822. + <tr>
  52823. + <td> hcd_frrem </td>
  52824. + <td> Shows the average value of the Frame Remaining
  52825. + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  52826. + occurs. This can be used to determine the average interrupt latency. Also
  52827. + shows the average Frame Remaining value for start_transfer and the "a" and
  52828. + "b" sample points. The "a" and "b" sample points may be used during debugging
  52829. + bto determine how long it takes to execute a section of the HCD code.</td>
  52830. + <td> Read</td>
  52831. + </tr>
  52832. +
  52833. + <tr>
  52834. + <td> rd_reg_test </td>
  52835. + <td> Displays the time required to read the GNPTXFSIZ register many times
  52836. + (the output shows the number of times the register is read).
  52837. + <td> Read</td>
  52838. + </tr>
  52839. +
  52840. + <tr>
  52841. + <td> wr_reg_test </td>
  52842. + <td> Displays the time required to write the GNPTXFSIZ register many times
  52843. + (the output shows the number of times the register is written).
  52844. + <td> Read</td>
  52845. + </tr>
  52846. +
  52847. + <tr>
  52848. + <td> lpm_response </td>
  52849. + <td> Gets or sets lpm_response mode. Applicable only in device mode.
  52850. + <td> Write</td>
  52851. + </tr>
  52852. +
  52853. + <tr>
  52854. + <td> sleep_status </td>
  52855. + <td> Shows sleep status of device.
  52856. + <td> Read</td>
  52857. + </tr>
  52858. +
  52859. + </table>
  52860. +
  52861. + Example usage:
  52862. + To get the current mode:
  52863. + cat /sys/devices/lm0/mode
  52864. +
  52865. + To power down the USB:
  52866. + echo 0 > /sys/devices/lm0/buspower
  52867. + */
  52868. +
  52869. +#include "dwc_otg_os_dep.h"
  52870. +#include "dwc_os.h"
  52871. +#include "dwc_otg_driver.h"
  52872. +#include "dwc_otg_attr.h"
  52873. +#include "dwc_otg_core_if.h"
  52874. +#include "dwc_otg_pcd_if.h"
  52875. +#include "dwc_otg_hcd_if.h"
  52876. +
  52877. +/*
  52878. + * MACROs for defining sysfs attribute
  52879. + */
  52880. +#ifdef LM_INTERFACE
  52881. +
  52882. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52883. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52884. +{ \
  52885. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52886. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52887. + uint32_t val; \
  52888. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52889. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  52890. +}
  52891. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52892. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52893. + const char *buf, size_t count) \
  52894. +{ \
  52895. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52896. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52897. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  52898. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  52899. + return count; \
  52900. +}
  52901. +
  52902. +#elif defined(PCI_INTERFACE)
  52903. +
  52904. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52905. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52906. +{ \
  52907. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52908. + uint32_t val; \
  52909. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52910. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  52911. +}
  52912. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52913. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52914. + const char *buf, size_t count) \
  52915. +{ \
  52916. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52917. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  52918. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  52919. + return count; \
  52920. +}
  52921. +
  52922. +#elif defined(PLATFORM_INTERFACE)
  52923. +
  52924. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52925. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52926. +{ \
  52927. + struct platform_device *platform_dev = \
  52928. + container_of(_dev, struct platform_device, dev); \
  52929. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52930. + uint32_t val; \
  52931. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  52932. + __func__, _dev, platform_dev, otg_dev); \
  52933. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52934. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  52935. +}
  52936. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52937. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52938. + const char *buf, size_t count) \
  52939. +{ \
  52940. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52941. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52942. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  52943. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  52944. + return count; \
  52945. +}
  52946. +#endif
  52947. +
  52948. +/*
  52949. + * MACROs for defining sysfs attribute for 32-bit registers
  52950. + */
  52951. +#ifdef LM_INTERFACE
  52952. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52953. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52954. +{ \
  52955. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52956. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52957. + uint32_t val; \
  52958. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52959. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  52960. +}
  52961. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52962. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52963. + const char *buf, size_t count) \
  52964. +{ \
  52965. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52966. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52967. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  52968. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  52969. + return count; \
  52970. +}
  52971. +#elif defined(PCI_INTERFACE)
  52972. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52973. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52974. +{ \
  52975. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52976. + uint32_t val; \
  52977. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52978. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  52979. +}
  52980. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52981. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52982. + const char *buf, size_t count) \
  52983. +{ \
  52984. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52985. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  52986. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  52987. + return count; \
  52988. +}
  52989. +
  52990. +#elif defined(PLATFORM_INTERFACE)
  52991. +#include "dwc_otg_dbg.h"
  52992. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52993. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52994. +{ \
  52995. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52996. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52997. + uint32_t val; \
  52998. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  52999. + __func__, _dev, platform_dev, otg_dev); \
  53000. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  53001. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  53002. +}
  53003. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  53004. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  53005. + const char *buf, size_t count) \
  53006. +{ \
  53007. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  53008. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  53009. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  53010. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  53011. + return count; \
  53012. +}
  53013. +
  53014. +#endif
  53015. +
  53016. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  53017. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  53018. +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  53019. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  53020. +
  53021. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  53022. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  53023. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  53024. +
  53025. +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  53026. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  53027. +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  53028. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  53029. +
  53030. +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  53031. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  53032. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  53033. +
  53034. +/** @name Functions for Show/Store of Attributes */
  53035. +/**@{*/
  53036. +
  53037. +/**
  53038. + * Helper function returning the otg_device structure of the given device
  53039. + */
  53040. +static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  53041. +{
  53042. + dwc_otg_device_t *otg_dev;
  53043. + DWC_OTG_GETDRVDEV(otg_dev, _dev);
  53044. + return otg_dev;
  53045. +}
  53046. +
  53047. +/**
  53048. + * Show the register offset of the Register Access.
  53049. + */
  53050. +static ssize_t regoffset_show(struct device *_dev,
  53051. + struct device_attribute *attr, char *buf)
  53052. +{
  53053. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53054. + return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  53055. + otg_dev->os_dep.reg_offset);
  53056. +}
  53057. +
  53058. +/**
  53059. + * Set the register offset for the next Register Access Read/Write
  53060. + */
  53061. +static ssize_t regoffset_store(struct device *_dev,
  53062. + struct device_attribute *attr,
  53063. + const char *buf, size_t count)
  53064. +{
  53065. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53066. + uint32_t offset = simple_strtoul(buf, NULL, 16);
  53067. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  53068. + if (offset < SZ_256K) {
  53069. +#elif defined(PCI_INTERFACE)
  53070. + if (offset < 0x00040000) {
  53071. +#endif
  53072. + otg_dev->os_dep.reg_offset = offset;
  53073. + } else {
  53074. + dev_err(_dev, "invalid offset\n");
  53075. + }
  53076. +
  53077. + return count;
  53078. +}
  53079. +
  53080. +DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  53081. +
  53082. +/**
  53083. + * Show the value of the register at the offset in the reg_offset
  53084. + * attribute.
  53085. + */
  53086. +static ssize_t regvalue_show(struct device *_dev,
  53087. + struct device_attribute *attr, char *buf)
  53088. +{
  53089. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53090. + uint32_t val;
  53091. + volatile uint32_t *addr;
  53092. +
  53093. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  53094. + /* Calculate the address */
  53095. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  53096. + (uint8_t *) otg_dev->os_dep.base);
  53097. + val = DWC_READ_REG32(addr);
  53098. + return snprintf(buf,
  53099. + sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  53100. + "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  53101. + val);
  53102. + } else {
  53103. + dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  53104. + return sprintf(buf, "invalid offset\n");
  53105. + }
  53106. +}
  53107. +
  53108. +/**
  53109. + * Store the value in the register at the offset in the reg_offset
  53110. + * attribute.
  53111. + *
  53112. + */
  53113. +static ssize_t regvalue_store(struct device *_dev,
  53114. + struct device_attribute *attr,
  53115. + const char *buf, size_t count)
  53116. +{
  53117. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53118. + volatile uint32_t *addr;
  53119. + uint32_t val = simple_strtoul(buf, NULL, 16);
  53120. + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  53121. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  53122. + /* Calculate the address */
  53123. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  53124. + (uint8_t *) otg_dev->os_dep.base);
  53125. + DWC_WRITE_REG32(addr, val);
  53126. + } else {
  53127. + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  53128. + otg_dev->os_dep.reg_offset);
  53129. + }
  53130. + return count;
  53131. +}
  53132. +
  53133. +DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  53134. +
  53135. +/*
  53136. + * Attributes
  53137. + */
  53138. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  53139. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  53140. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  53141. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  53142. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  53143. +
  53144. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  53145. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  53146. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  53147. +
  53148. +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  53149. +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  53150. + &(otg_dev->core_if->core_global_regs->gusbcfg),
  53151. + "GUSBCFG");
  53152. +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  53153. + &(otg_dev->core_if->core_global_regs->grxfsiz),
  53154. + "GRXFSIZ");
  53155. +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  53156. + &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  53157. + "GNPTXFSIZ");
  53158. +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  53159. + &(otg_dev->core_if->core_global_regs->gpvndctl),
  53160. + "GPVNDCTL");
  53161. +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  53162. + &(otg_dev->core_if->core_global_regs->ggpio),
  53163. + "GGPIO");
  53164. +DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  53165. + "GUID");
  53166. +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  53167. + &(otg_dev->core_if->core_global_regs->gsnpsid),
  53168. + "GSNPSID");
  53169. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  53170. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  53171. +
  53172. +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  53173. + &(otg_dev->core_if->core_global_regs->hptxfsiz),
  53174. + "HPTXFSIZ");
  53175. +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
  53176. +
  53177. +/**
  53178. + * @todo Add code to initiate the HNP.
  53179. + */
  53180. +/**
  53181. + * Show the HNP status bit
  53182. + */
  53183. +static ssize_t hnp_show(struct device *_dev,
  53184. + struct device_attribute *attr, char *buf)
  53185. +{
  53186. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53187. + return sprintf(buf, "HstNegScs = 0x%x\n",
  53188. + dwc_otg_get_hnpstatus(otg_dev->core_if));
  53189. +}
  53190. +
  53191. +/**
  53192. + * Set the HNP Request bit
  53193. + */
  53194. +static ssize_t hnp_store(struct device *_dev,
  53195. + struct device_attribute *attr,
  53196. + const char *buf, size_t count)
  53197. +{
  53198. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53199. + uint32_t in = simple_strtoul(buf, NULL, 16);
  53200. + dwc_otg_set_hnpreq(otg_dev->core_if, in);
  53201. + return count;
  53202. +}
  53203. +
  53204. +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  53205. +
  53206. +/**
  53207. + * @todo Add code to initiate the SRP.
  53208. + */
  53209. +/**
  53210. + * Show the SRP status bit
  53211. + */
  53212. +static ssize_t srp_show(struct device *_dev,
  53213. + struct device_attribute *attr, char *buf)
  53214. +{
  53215. +#ifndef DWC_HOST_ONLY
  53216. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53217. + return sprintf(buf, "SesReqScs = 0x%x\n",
  53218. + dwc_otg_get_srpstatus(otg_dev->core_if));
  53219. +#else
  53220. + return sprintf(buf, "Host Only Mode!\n");
  53221. +#endif
  53222. +}
  53223. +
  53224. +/**
  53225. + * Set the SRP Request bit
  53226. + */
  53227. +static ssize_t srp_store(struct device *_dev,
  53228. + struct device_attribute *attr,
  53229. + const char *buf, size_t count)
  53230. +{
  53231. +#ifndef DWC_HOST_ONLY
  53232. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53233. + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  53234. +#endif
  53235. + return count;
  53236. +}
  53237. +
  53238. +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  53239. +
  53240. +/**
  53241. + * @todo Need to do more for power on/off?
  53242. + */
  53243. +/**
  53244. + * Show the Bus Power status
  53245. + */
  53246. +static ssize_t buspower_show(struct device *_dev,
  53247. + struct device_attribute *attr, char *buf)
  53248. +{
  53249. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53250. + return sprintf(buf, "Bus Power = 0x%x\n",
  53251. + dwc_otg_get_prtpower(otg_dev->core_if));
  53252. +}
  53253. +
  53254. +/**
  53255. + * Set the Bus Power status
  53256. + */
  53257. +static ssize_t buspower_store(struct device *_dev,
  53258. + struct device_attribute *attr,
  53259. + const char *buf, size_t count)
  53260. +{
  53261. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53262. + uint32_t on = simple_strtoul(buf, NULL, 16);
  53263. + dwc_otg_set_prtpower(otg_dev->core_if, on);
  53264. + return count;
  53265. +}
  53266. +
  53267. +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  53268. +
  53269. +/**
  53270. + * @todo Need to do more for suspend?
  53271. + */
  53272. +/**
  53273. + * Show the Bus Suspend status
  53274. + */
  53275. +static ssize_t bussuspend_show(struct device *_dev,
  53276. + struct device_attribute *attr, char *buf)
  53277. +{
  53278. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53279. + return sprintf(buf, "Bus Suspend = 0x%x\n",
  53280. + dwc_otg_get_prtsuspend(otg_dev->core_if));
  53281. +}
  53282. +
  53283. +/**
  53284. + * Set the Bus Suspend status
  53285. + */
  53286. +static ssize_t bussuspend_store(struct device *_dev,
  53287. + struct device_attribute *attr,
  53288. + const char *buf, size_t count)
  53289. +{
  53290. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53291. + uint32_t in = simple_strtoul(buf, NULL, 16);
  53292. + dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  53293. + return count;
  53294. +}
  53295. +
  53296. +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  53297. +
  53298. +/**
  53299. + * Show the Mode Change Ready Timer status
  53300. + */
  53301. +static ssize_t mode_ch_tim_en_show(struct device *_dev,
  53302. + struct device_attribute *attr, char *buf)
  53303. +{
  53304. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53305. + return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  53306. + dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  53307. +}
  53308. +
  53309. +/**
  53310. + * Set the Mode Change Ready Timer status
  53311. + */
  53312. +static ssize_t mode_ch_tim_en_store(struct device *_dev,
  53313. + struct device_attribute *attr,
  53314. + const char *buf, size_t count)
  53315. +{
  53316. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53317. + uint32_t in = simple_strtoul(buf, NULL, 16);
  53318. + dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  53319. + return count;
  53320. +}
  53321. +
  53322. +DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  53323. +
  53324. +/**
  53325. + * Show the value of HFIR Frame Interval bitfield
  53326. + */
  53327. +static ssize_t fr_interval_show(struct device *_dev,
  53328. + struct device_attribute *attr, char *buf)
  53329. +{
  53330. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53331. + return sprintf(buf, "Frame Interval = 0x%x\n",
  53332. + dwc_otg_get_fr_interval(otg_dev->core_if));
  53333. +}
  53334. +
  53335. +/**
  53336. + * Set the HFIR Frame Interval value
  53337. + */
  53338. +static ssize_t fr_interval_store(struct device *_dev,
  53339. + struct device_attribute *attr,
  53340. + const char *buf, size_t count)
  53341. +{
  53342. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53343. + uint32_t in = simple_strtoul(buf, NULL, 10);
  53344. + dwc_otg_set_fr_interval(otg_dev->core_if, in);
  53345. + return count;
  53346. +}
  53347. +
  53348. +DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  53349. +
  53350. +/**
  53351. + * Show the status of Remote Wakeup.
  53352. + */
  53353. +static ssize_t remote_wakeup_show(struct device *_dev,
  53354. + struct device_attribute *attr, char *buf)
  53355. +{
  53356. +#ifndef DWC_HOST_ONLY
  53357. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53358. +
  53359. + return sprintf(buf,
  53360. + "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  53361. + dwc_otg_get_remotewakesig(otg_dev->core_if),
  53362. + dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  53363. + dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  53364. +#else
  53365. + return sprintf(buf, "Host Only Mode!\n");
  53366. +#endif /* DWC_HOST_ONLY */
  53367. +}
  53368. +
  53369. +/**
  53370. + * Initiate a remote wakeup of the host. The Device control register
  53371. + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  53372. + * flag is set.
  53373. + *
  53374. + */
  53375. +static ssize_t remote_wakeup_store(struct device *_dev,
  53376. + struct device_attribute *attr,
  53377. + const char *buf, size_t count)
  53378. +{
  53379. +#ifndef DWC_HOST_ONLY
  53380. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53381. + uint32_t val = simple_strtoul(buf, NULL, 16);
  53382. +
  53383. + if (val & 1) {
  53384. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  53385. + } else {
  53386. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  53387. + }
  53388. +#endif /* DWC_HOST_ONLY */
  53389. + return count;
  53390. +}
  53391. +
  53392. +DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  53393. + remote_wakeup_store);
  53394. +
  53395. +/**
  53396. + * Show the whether core is hibernated or not.
  53397. + */
  53398. +static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  53399. + struct device_attribute *attr, char *buf)
  53400. +{
  53401. +#ifndef DWC_HOST_ONLY
  53402. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53403. +
  53404. + if (dwc_otg_get_core_state(otg_dev->core_if)) {
  53405. + DWC_PRINTF("Core is in hibernation\n");
  53406. + } else {
  53407. + DWC_PRINTF("Core is not in hibernation\n");
  53408. + }
  53409. +#endif /* DWC_HOST_ONLY */
  53410. + return 0;
  53411. +}
  53412. +
  53413. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  53414. + int rem_wakeup, int reset);
  53415. +
  53416. +/**
  53417. + * Initiate a remote wakeup of the device to exit from hibernation.
  53418. + */
  53419. +static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  53420. + struct device_attribute *attr,
  53421. + const char *buf, size_t count)
  53422. +{
  53423. +#ifndef DWC_HOST_ONLY
  53424. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53425. + dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  53426. +#endif
  53427. + return count;
  53428. +}
  53429. +
  53430. +DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  53431. + rem_wakeup_pwrdn_store);
  53432. +
  53433. +static ssize_t disconnect_us(struct device *_dev,
  53434. + struct device_attribute *attr,
  53435. + const char *buf, size_t count)
  53436. +{
  53437. +
  53438. +#ifndef DWC_HOST_ONLY
  53439. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53440. + uint32_t val = simple_strtoul(buf, NULL, 16);
  53441. + DWC_PRINTF("The Passed value is %04x\n", val);
  53442. +
  53443. + dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  53444. +
  53445. +#endif /* DWC_HOST_ONLY */
  53446. + return count;
  53447. +}
  53448. +
  53449. +DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  53450. +
  53451. +/**
  53452. + * Dump global registers and either host or device registers (depending on the
  53453. + * current mode of the core).
  53454. + */
  53455. +static ssize_t regdump_show(struct device *_dev,
  53456. + struct device_attribute *attr, char *buf)
  53457. +{
  53458. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53459. +
  53460. + dwc_otg_dump_global_registers(otg_dev->core_if);
  53461. + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  53462. + dwc_otg_dump_host_registers(otg_dev->core_if);
  53463. + } else {
  53464. + dwc_otg_dump_dev_registers(otg_dev->core_if);
  53465. +
  53466. + }
  53467. + return sprintf(buf, "Register Dump\n");
  53468. +}
  53469. +
  53470. +DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
  53471. +
  53472. +/**
  53473. + * Dump global registers and either host or device registers (depending on the
  53474. + * current mode of the core).
  53475. + */
  53476. +static ssize_t spramdump_show(struct device *_dev,
  53477. + struct device_attribute *attr, char *buf)
  53478. +{
  53479. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53480. +
  53481. + //dwc_otg_dump_spram(otg_dev->core_if);
  53482. +
  53483. + return sprintf(buf, "SPRAM Dump\n");
  53484. +}
  53485. +
  53486. +DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
  53487. +
  53488. +/**
  53489. + * Dump the current hcd state.
  53490. + */
  53491. +static ssize_t hcddump_show(struct device *_dev,
  53492. + struct device_attribute *attr, char *buf)
  53493. +{
  53494. +#ifndef DWC_DEVICE_ONLY
  53495. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53496. + dwc_otg_hcd_dump_state(otg_dev->hcd);
  53497. +#endif /* DWC_DEVICE_ONLY */
  53498. + return sprintf(buf, "HCD Dump\n");
  53499. +}
  53500. +
  53501. +DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
  53502. +
  53503. +/**
  53504. + * Dump the average frame remaining at SOF. This can be used to
  53505. + * determine average interrupt latency. Frame remaining is also shown for
  53506. + * start transfer and two additional sample points.
  53507. + */
  53508. +static ssize_t hcd_frrem_show(struct device *_dev,
  53509. + struct device_attribute *attr, char *buf)
  53510. +{
  53511. +#ifndef DWC_DEVICE_ONLY
  53512. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53513. +
  53514. + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  53515. +#endif /* DWC_DEVICE_ONLY */
  53516. + return sprintf(buf, "HCD Dump Frame Remaining\n");
  53517. +}
  53518. +
  53519. +DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
  53520. +
  53521. +/**
  53522. + * Displays the time required to read the GNPTXFSIZ register many times (the
  53523. + * output shows the number of times the register is read).
  53524. + */
  53525. +#define RW_REG_COUNT 10000000
  53526. +#define MSEC_PER_JIFFIE 1000/HZ
  53527. +static ssize_t rd_reg_test_show(struct device *_dev,
  53528. + struct device_attribute *attr, char *buf)
  53529. +{
  53530. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53531. + int i;
  53532. + int time;
  53533. + int start_jiffies;
  53534. +
  53535. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  53536. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  53537. + start_jiffies = jiffies;
  53538. + for (i = 0; i < RW_REG_COUNT; i++) {
  53539. + dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  53540. + }
  53541. + time = jiffies - start_jiffies;
  53542. + return sprintf(buf,
  53543. + "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  53544. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  53545. +}
  53546. +
  53547. +DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
  53548. +
  53549. +/**
  53550. + * Displays the time required to write the GNPTXFSIZ register many times (the
  53551. + * output shows the number of times the register is written).
  53552. + */
  53553. +static ssize_t wr_reg_test_show(struct device *_dev,
  53554. + struct device_attribute *attr, char *buf)
  53555. +{
  53556. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53557. + uint32_t reg_val;
  53558. + int i;
  53559. + int time;
  53560. + int start_jiffies;
  53561. +
  53562. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  53563. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  53564. + reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  53565. + start_jiffies = jiffies;
  53566. + for (i = 0; i < RW_REG_COUNT; i++) {
  53567. + dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  53568. + }
  53569. + time = jiffies - start_jiffies;
  53570. + return sprintf(buf,
  53571. + "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  53572. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  53573. +}
  53574. +
  53575. +DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
  53576. +
  53577. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53578. +
  53579. +/**
  53580. +* Show the lpm_response attribute.
  53581. +*/
  53582. +static ssize_t lpmresp_show(struct device *_dev,
  53583. + struct device_attribute *attr, char *buf)
  53584. +{
  53585. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53586. +
  53587. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  53588. + return sprintf(buf, "** LPM is DISABLED **\n");
  53589. +
  53590. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  53591. + return sprintf(buf, "** Current mode is not device mode\n");
  53592. + }
  53593. + return sprintf(buf, "lpm_response = %d\n",
  53594. + dwc_otg_get_lpmresponse(otg_dev->core_if));
  53595. +}
  53596. +
  53597. +/**
  53598. +* Store the lpm_response attribute.
  53599. +*/
  53600. +static ssize_t lpmresp_store(struct device *_dev,
  53601. + struct device_attribute *attr,
  53602. + const char *buf, size_t count)
  53603. +{
  53604. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53605. + uint32_t val = simple_strtoul(buf, NULL, 16);
  53606. +
  53607. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  53608. + return 0;
  53609. + }
  53610. +
  53611. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  53612. + return 0;
  53613. + }
  53614. +
  53615. + dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  53616. + return count;
  53617. +}
  53618. +
  53619. +DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  53620. +
  53621. +/**
  53622. +* Show the sleep_status attribute.
  53623. +*/
  53624. +static ssize_t sleepstatus_show(struct device *_dev,
  53625. + struct device_attribute *attr, char *buf)
  53626. +{
  53627. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53628. + return sprintf(buf, "Sleep Status = %d\n",
  53629. + dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  53630. +}
  53631. +
  53632. +/**
  53633. + * Store the sleep_status attribure.
  53634. + */
  53635. +static ssize_t sleepstatus_store(struct device *_dev,
  53636. + struct device_attribute *attr,
  53637. + const char *buf, size_t count)
  53638. +{
  53639. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53640. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  53641. +
  53642. + if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  53643. + if (dwc_otg_is_host_mode(core_if)) {
  53644. +
  53645. + DWC_PRINTF("Host initiated resume\n");
  53646. + dwc_otg_set_prtresume(otg_dev->core_if, 1);
  53647. + }
  53648. + }
  53649. +
  53650. + return count;
  53651. +}
  53652. +
  53653. +DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  53654. + sleepstatus_store);
  53655. +
  53656. +#endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  53657. +
  53658. +/**@}*/
  53659. +
  53660. +/**
  53661. + * Create the device files
  53662. + */
  53663. +void dwc_otg_attr_create(
  53664. +#ifdef LM_INTERFACE
  53665. + struct lm_device *dev
  53666. +#elif defined(PCI_INTERFACE)
  53667. + struct pci_dev *dev
  53668. +#elif defined(PLATFORM_INTERFACE)
  53669. + struct platform_device *dev
  53670. +#endif
  53671. + )
  53672. +{
  53673. + int error;
  53674. +
  53675. + error = device_create_file(&dev->dev, &dev_attr_regoffset);
  53676. + error = device_create_file(&dev->dev, &dev_attr_regvalue);
  53677. + error = device_create_file(&dev->dev, &dev_attr_mode);
  53678. + error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  53679. + error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  53680. + error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  53681. + error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  53682. + error = device_create_file(&dev->dev, &dev_attr_hnp);
  53683. + error = device_create_file(&dev->dev, &dev_attr_srp);
  53684. + error = device_create_file(&dev->dev, &dev_attr_buspower);
  53685. + error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  53686. + error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  53687. + error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  53688. + error = device_create_file(&dev->dev, &dev_attr_busconnected);
  53689. + error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  53690. + error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  53691. + error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  53692. + error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  53693. + error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  53694. + error = device_create_file(&dev->dev, &dev_attr_ggpio);
  53695. + error = device_create_file(&dev->dev, &dev_attr_guid);
  53696. + error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  53697. + error = device_create_file(&dev->dev, &dev_attr_devspeed);
  53698. + error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  53699. + error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  53700. + error = device_create_file(&dev->dev, &dev_attr_hprt0);
  53701. + error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  53702. + error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  53703. + error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  53704. + error = device_create_file(&dev->dev, &dev_attr_regdump);
  53705. + error = device_create_file(&dev->dev, &dev_attr_spramdump);
  53706. + error = device_create_file(&dev->dev, &dev_attr_hcddump);
  53707. + error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  53708. + error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  53709. + error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  53710. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53711. + error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  53712. + error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  53713. +#endif
  53714. +}
  53715. +
  53716. +/**
  53717. + * Remove the device files
  53718. + */
  53719. +void dwc_otg_attr_remove(
  53720. +#ifdef LM_INTERFACE
  53721. + struct lm_device *dev
  53722. +#elif defined(PCI_INTERFACE)
  53723. + struct pci_dev *dev
  53724. +#elif defined(PLATFORM_INTERFACE)
  53725. + struct platform_device *dev
  53726. +#endif
  53727. + )
  53728. +{
  53729. + device_remove_file(&dev->dev, &dev_attr_regoffset);
  53730. + device_remove_file(&dev->dev, &dev_attr_regvalue);
  53731. + device_remove_file(&dev->dev, &dev_attr_mode);
  53732. + device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  53733. + device_remove_file(&dev->dev, &dev_attr_srpcapable);
  53734. + device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  53735. + device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  53736. + device_remove_file(&dev->dev, &dev_attr_hnp);
  53737. + device_remove_file(&dev->dev, &dev_attr_srp);
  53738. + device_remove_file(&dev->dev, &dev_attr_buspower);
  53739. + device_remove_file(&dev->dev, &dev_attr_bussuspend);
  53740. + device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  53741. + device_remove_file(&dev->dev, &dev_attr_fr_interval);
  53742. + device_remove_file(&dev->dev, &dev_attr_busconnected);
  53743. + device_remove_file(&dev->dev, &dev_attr_gotgctl);
  53744. + device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  53745. + device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  53746. + device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  53747. + device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  53748. + device_remove_file(&dev->dev, &dev_attr_ggpio);
  53749. + device_remove_file(&dev->dev, &dev_attr_guid);
  53750. + device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  53751. + device_remove_file(&dev->dev, &dev_attr_devspeed);
  53752. + device_remove_file(&dev->dev, &dev_attr_enumspeed);
  53753. + device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  53754. + device_remove_file(&dev->dev, &dev_attr_hprt0);
  53755. + device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  53756. + device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  53757. + device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  53758. + device_remove_file(&dev->dev, &dev_attr_regdump);
  53759. + device_remove_file(&dev->dev, &dev_attr_spramdump);
  53760. + device_remove_file(&dev->dev, &dev_attr_hcddump);
  53761. + device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  53762. + device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  53763. + device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  53764. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53765. + device_remove_file(&dev->dev, &dev_attr_lpm_response);
  53766. + device_remove_file(&dev->dev, &dev_attr_sleep_status);
  53767. +#endif
  53768. +}
  53769. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_attr.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h
  53770. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_attr.h 1970-01-01 01:00:00.000000000 +0100
  53771. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h 2014-04-24 16:04:39.815124215 +0200
  53772. @@ -0,0 +1,89 @@
  53773. +/* ==========================================================================
  53774. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
  53775. + * $Revision: #13 $
  53776. + * $Date: 2010/06/21 $
  53777. + * $Change: 1532021 $
  53778. + *
  53779. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  53780. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  53781. + * otherwise expressly agreed to in writing between Synopsys and you.
  53782. + *
  53783. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  53784. + * any End User Software License Agreement or Agreement for Licensed Product
  53785. + * with Synopsys or any supplement thereto. You are permitted to use and
  53786. + * redistribute this Software in source and binary forms, with or without
  53787. + * modification, provided that redistributions of source code must retain this
  53788. + * notice. You may not view, use, disclose, copy or distribute this file or
  53789. + * any information contained herein except pursuant to this license grant from
  53790. + * Synopsys. If you do not agree with this notice, including the disclaimer
  53791. + * below, then you are not authorized to use the Software.
  53792. + *
  53793. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  53794. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53795. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53796. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  53797. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53798. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53799. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  53800. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53801. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  53802. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  53803. + * DAMAGE.
  53804. + * ========================================================================== */
  53805. +
  53806. +#if !defined(__DWC_OTG_ATTR_H__)
  53807. +#define __DWC_OTG_ATTR_H__
  53808. +
  53809. +/** @file
  53810. + * This file contains the interface to the Linux device attributes.
  53811. + */
  53812. +extern struct device_attribute dev_attr_regoffset;
  53813. +extern struct device_attribute dev_attr_regvalue;
  53814. +
  53815. +extern struct device_attribute dev_attr_mode;
  53816. +extern struct device_attribute dev_attr_hnpcapable;
  53817. +extern struct device_attribute dev_attr_srpcapable;
  53818. +extern struct device_attribute dev_attr_hnp;
  53819. +extern struct device_attribute dev_attr_srp;
  53820. +extern struct device_attribute dev_attr_buspower;
  53821. +extern struct device_attribute dev_attr_bussuspend;
  53822. +extern struct device_attribute dev_attr_mode_ch_tim_en;
  53823. +extern struct device_attribute dev_attr_fr_interval;
  53824. +extern struct device_attribute dev_attr_busconnected;
  53825. +extern struct device_attribute dev_attr_gotgctl;
  53826. +extern struct device_attribute dev_attr_gusbcfg;
  53827. +extern struct device_attribute dev_attr_grxfsiz;
  53828. +extern struct device_attribute dev_attr_gnptxfsiz;
  53829. +extern struct device_attribute dev_attr_gpvndctl;
  53830. +extern struct device_attribute dev_attr_ggpio;
  53831. +extern struct device_attribute dev_attr_guid;
  53832. +extern struct device_attribute dev_attr_gsnpsid;
  53833. +extern struct device_attribute dev_attr_devspeed;
  53834. +extern struct device_attribute dev_attr_enumspeed;
  53835. +extern struct device_attribute dev_attr_hptxfsiz;
  53836. +extern struct device_attribute dev_attr_hprt0;
  53837. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53838. +extern struct device_attribute dev_attr_lpm_response;
  53839. +extern struct device_attribute devi_attr_sleep_status;
  53840. +#endif
  53841. +
  53842. +void dwc_otg_attr_create(
  53843. +#ifdef LM_INTERFACE
  53844. + struct lm_device *dev
  53845. +#elif defined(PCI_INTERFACE)
  53846. + struct pci_dev *dev
  53847. +#elif defined(PLATFORM_INTERFACE)
  53848. + struct platform_device *dev
  53849. +#endif
  53850. + );
  53851. +
  53852. +void dwc_otg_attr_remove(
  53853. +#ifdef LM_INTERFACE
  53854. + struct lm_device *dev
  53855. +#elif defined(PCI_INTERFACE)
  53856. + struct pci_dev *dev
  53857. +#elif defined(PLATFORM_INTERFACE)
  53858. + struct platform_device *dev
  53859. +#endif
  53860. + );
  53861. +#endif
  53862. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_cfi.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c
  53863. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 1970-01-01 01:00:00.000000000 +0100
  53864. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 2014-04-24 16:04:39.815124215 +0200
  53865. @@ -0,0 +1,1876 @@
  53866. +/* ==========================================================================
  53867. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  53868. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  53869. + * otherwise expressly agreed to in writing between Synopsys and you.
  53870. + *
  53871. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  53872. + * any End User Software License Agreement or Agreement for Licensed Product
  53873. + * with Synopsys or any supplement thereto. You are permitted to use and
  53874. + * redistribute this Software in source and binary forms, with or without
  53875. + * modification, provided that redistributions of source code must retain this
  53876. + * notice. You may not view, use, disclose, copy or distribute this file or
  53877. + * any information contained herein except pursuant to this license grant from
  53878. + * Synopsys. If you do not agree with this notice, including the disclaimer
  53879. + * below, then you are not authorized to use the Software.
  53880. + *
  53881. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  53882. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53883. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53884. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  53885. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53886. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53887. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  53888. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53889. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  53890. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  53891. + * DAMAGE.
  53892. + * ========================================================================== */
  53893. +
  53894. +/** @file
  53895. + *
  53896. + * This file contains the most of the CFI(Core Feature Interface)
  53897. + * implementation for the OTG.
  53898. + */
  53899. +
  53900. +#ifdef DWC_UTE_CFI
  53901. +
  53902. +#include "dwc_otg_pcd.h"
  53903. +#include "dwc_otg_cfi.h"
  53904. +
  53905. +/** This definition should actually migrate to the Portability Library */
  53906. +#define DWC_CONSTANT_CPU_TO_LE16(x) (x)
  53907. +
  53908. +extern dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex);
  53909. +
  53910. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen);
  53911. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  53912. + struct dwc_otg_pcd *pcd,
  53913. + struct cfi_usb_ctrlrequest *ctrl_req);
  53914. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd);
  53915. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53916. + struct cfi_usb_ctrlrequest *req);
  53917. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53918. + struct cfi_usb_ctrlrequest *req);
  53919. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53920. + struct cfi_usb_ctrlrequest *req);
  53921. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  53922. + struct cfi_usb_ctrlrequest *req);
  53923. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep);
  53924. +
  53925. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if);
  53926. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue);
  53927. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue);
  53928. +
  53929. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if);
  53930. +
  53931. +/** This is the header of the all features descriptor */
  53932. +static cfi_all_features_header_t all_props_desc_header = {
  53933. + .wVersion = DWC_CONSTANT_CPU_TO_LE16(0x100),
  53934. + .wCoreID = DWC_CONSTANT_CPU_TO_LE16(CFI_CORE_ID_OTG),
  53935. + .wNumFeatures = DWC_CONSTANT_CPU_TO_LE16(9),
  53936. +};
  53937. +
  53938. +/** This is an array of statically allocated feature descriptors */
  53939. +static cfi_feature_desc_header_t prop_descs[] = {
  53940. +
  53941. + /* FT_ID_DMA_MODE */
  53942. + {
  53943. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_MODE),
  53944. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53945. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(1),
  53946. + },
  53947. +
  53948. + /* FT_ID_DMA_BUFFER_SETUP */
  53949. + {
  53950. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFFER_SETUP),
  53951. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53952. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53953. + },
  53954. +
  53955. + /* FT_ID_DMA_BUFF_ALIGN */
  53956. + {
  53957. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFF_ALIGN),
  53958. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53959. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53960. + },
  53961. +
  53962. + /* FT_ID_DMA_CONCAT_SETUP */
  53963. + {
  53964. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CONCAT_SETUP),
  53965. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53966. + //.wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53967. + },
  53968. +
  53969. + /* FT_ID_DMA_CIRCULAR */
  53970. + {
  53971. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CIRCULAR),
  53972. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53973. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53974. + },
  53975. +
  53976. + /* FT_ID_THRESHOLD_SETUP */
  53977. + {
  53978. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_THRESHOLD_SETUP),
  53979. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53980. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53981. + },
  53982. +
  53983. + /* FT_ID_DFIFO_DEPTH */
  53984. + {
  53985. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DFIFO_DEPTH),
  53986. + .bmAttributes = CFI_FEATURE_ATTR_RO,
  53987. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53988. + },
  53989. +
  53990. + /* FT_ID_TX_FIFO_DEPTH */
  53991. + {
  53992. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_TX_FIFO_DEPTH),
  53993. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53994. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53995. + },
  53996. +
  53997. + /* FT_ID_RX_FIFO_DEPTH */
  53998. + {
  53999. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_RX_FIFO_DEPTH),
  54000. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  54001. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  54002. + }
  54003. +};
  54004. +
  54005. +/** The table of feature names */
  54006. +cfi_string_t prop_name_table[] = {
  54007. + {FT_ID_DMA_MODE, "dma_mode"},
  54008. + {FT_ID_DMA_BUFFER_SETUP, "buffer_setup"},
  54009. + {FT_ID_DMA_BUFF_ALIGN, "buffer_align"},
  54010. + {FT_ID_DMA_CONCAT_SETUP, "concat_setup"},
  54011. + {FT_ID_DMA_CIRCULAR, "buffer_circular"},
  54012. + {FT_ID_THRESHOLD_SETUP, "threshold_setup"},
  54013. + {FT_ID_DFIFO_DEPTH, "dfifo_depth"},
  54014. + {FT_ID_TX_FIFO_DEPTH, "txfifo_depth"},
  54015. + {FT_ID_RX_FIFO_DEPTH, "rxfifo_depth"},
  54016. + {}
  54017. +};
  54018. +
  54019. +/************************************************************************/
  54020. +
  54021. +/**
  54022. + * Returns the name of the feature by its ID
  54023. + * or NULL if no featute ID matches.
  54024. + *
  54025. + */
  54026. +const uint8_t *get_prop_name(uint16_t prop_id, int *len)
  54027. +{
  54028. + cfi_string_t *pstr;
  54029. + *len = 0;
  54030. +
  54031. + for (pstr = prop_name_table; pstr && pstr->s; pstr++) {
  54032. + if (pstr->id == prop_id) {
  54033. + *len = DWC_STRLEN(pstr->s);
  54034. + return pstr->s;
  54035. + }
  54036. + }
  54037. + return NULL;
  54038. +}
  54039. +
  54040. +/**
  54041. + * This function handles all CFI specific control requests.
  54042. + *
  54043. + * Return a negative value to stall the DCE.
  54044. + */
  54045. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl)
  54046. +{
  54047. + int retval = 0;
  54048. + dwc_otg_pcd_ep_t *ep = NULL;
  54049. + cfiobject_t *cfi = pcd->cfi;
  54050. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  54051. + uint16_t wLen = DWC_LE16_TO_CPU(&ctrl->wLength);
  54052. + uint16_t wValue = DWC_LE16_TO_CPU(&ctrl->wValue);
  54053. + uint16_t wIndex = DWC_LE16_TO_CPU(&ctrl->wIndex);
  54054. + uint32_t regaddr = 0;
  54055. + uint32_t regval = 0;
  54056. +
  54057. + /* Save this Control Request in the CFI object.
  54058. + * The data field will be assigned in the data stage completion CB function.
  54059. + */
  54060. + cfi->ctrl_req = *ctrl;
  54061. + cfi->ctrl_req.data = NULL;
  54062. +
  54063. + cfi->need_gadget_att = 0;
  54064. + cfi->need_status_in_complete = 0;
  54065. +
  54066. + switch (ctrl->bRequest) {
  54067. + case VEN_CORE_GET_FEATURES:
  54068. + retval = cfi_core_features_buf(cfi->buf_in.buf, CFI_IN_BUF_LEN);
  54069. + if (retval >= 0) {
  54070. + //dump_msg(cfi->buf_in.buf, retval);
  54071. + ep = &pcd->ep0;
  54072. +
  54073. + retval = min((uint16_t) retval, wLen);
  54074. + /* Transfer this buffer to the host through the EP0-IN EP */
  54075. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  54076. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  54077. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  54078. + ep->dwc_ep.xfer_len = retval;
  54079. + ep->dwc_ep.xfer_count = 0;
  54080. + ep->dwc_ep.sent_zlp = 0;
  54081. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54082. +
  54083. + pcd->ep0_pending = 1;
  54084. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54085. + }
  54086. + retval = 0;
  54087. + break;
  54088. +
  54089. + case VEN_CORE_GET_FEATURE:
  54090. + CFI_INFO("VEN_CORE_GET_FEATURE\n");
  54091. + retval = cfi_get_feature_value(cfi->buf_in.buf, CFI_IN_BUF_LEN,
  54092. + pcd, ctrl);
  54093. + if (retval >= 0) {
  54094. + ep = &pcd->ep0;
  54095. +
  54096. + retval = min((uint16_t) retval, wLen);
  54097. + /* Transfer this buffer to the host through the EP0-IN EP */
  54098. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  54099. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  54100. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  54101. + ep->dwc_ep.xfer_len = retval;
  54102. + ep->dwc_ep.xfer_count = 0;
  54103. + ep->dwc_ep.sent_zlp = 0;
  54104. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54105. +
  54106. + pcd->ep0_pending = 1;
  54107. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54108. + }
  54109. + CFI_INFO("VEN_CORE_GET_FEATURE=%d\n", retval);
  54110. + dump_msg(cfi->buf_in.buf, retval);
  54111. + break;
  54112. +
  54113. + case VEN_CORE_SET_FEATURE:
  54114. + CFI_INFO("VEN_CORE_SET_FEATURE\n");
  54115. + /* Set up an XFER to get the data stage of the control request,
  54116. + * which is the new value of the feature to be modified.
  54117. + */
  54118. + ep = &pcd->ep0;
  54119. + ep->dwc_ep.is_in = 0;
  54120. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  54121. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  54122. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  54123. + ep->dwc_ep.xfer_len = wLen;
  54124. + ep->dwc_ep.xfer_count = 0;
  54125. + ep->dwc_ep.sent_zlp = 0;
  54126. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54127. +
  54128. + pcd->ep0_pending = 1;
  54129. + /* Read the control write's data stage */
  54130. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54131. + retval = 0;
  54132. + break;
  54133. +
  54134. + case VEN_CORE_RESET_FEATURES:
  54135. + CFI_INFO("VEN_CORE_RESET_FEATURES\n");
  54136. + cfi->need_gadget_att = 1;
  54137. + cfi->need_status_in_complete = 1;
  54138. + retval = cfi_preproc_reset(pcd, ctrl);
  54139. + CFI_INFO("VEN_CORE_RESET_FEATURES = (%d)\n", retval);
  54140. + break;
  54141. +
  54142. + case VEN_CORE_ACTIVATE_FEATURES:
  54143. + CFI_INFO("VEN_CORE_ACTIVATE_FEATURES\n");
  54144. + break;
  54145. +
  54146. + case VEN_CORE_READ_REGISTER:
  54147. + CFI_INFO("VEN_CORE_READ_REGISTER\n");
  54148. + /* wValue optionally contains the HI WORD of the register offset and
  54149. + * wIndex contains the LOW WORD of the register offset
  54150. + */
  54151. + if (wValue == 0) {
  54152. + /* @TODO - MAS - fix the access to the base field */
  54153. + regaddr = 0;
  54154. + //regaddr = (uint32_t) pcd->otg_dev->os_dep.base;
  54155. + //GET_CORE_IF(pcd)->co
  54156. + regaddr |= wIndex;
  54157. + } else {
  54158. + regaddr = (wValue << 16) | wIndex;
  54159. + }
  54160. +
  54161. + /* Read a 32-bit value of the memory at the regaddr */
  54162. + regval = DWC_READ_REG32((uint32_t *) regaddr);
  54163. +
  54164. + ep = &pcd->ep0;
  54165. + dwc_memcpy(cfi->buf_in.buf, &regval, sizeof(uint32_t));
  54166. + ep->dwc_ep.is_in = 1;
  54167. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  54168. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  54169. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  54170. + ep->dwc_ep.xfer_len = wLen;
  54171. + ep->dwc_ep.xfer_count = 0;
  54172. + ep->dwc_ep.sent_zlp = 0;
  54173. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54174. +
  54175. + pcd->ep0_pending = 1;
  54176. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54177. + cfi->need_gadget_att = 0;
  54178. + retval = 0;
  54179. + break;
  54180. +
  54181. + case VEN_CORE_WRITE_REGISTER:
  54182. + CFI_INFO("VEN_CORE_WRITE_REGISTER\n");
  54183. + /* Set up an XFER to get the data stage of the control request,
  54184. + * which is the new value of the register to be modified.
  54185. + */
  54186. + ep = &pcd->ep0;
  54187. + ep->dwc_ep.is_in = 0;
  54188. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  54189. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  54190. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  54191. + ep->dwc_ep.xfer_len = wLen;
  54192. + ep->dwc_ep.xfer_count = 0;
  54193. + ep->dwc_ep.sent_zlp = 0;
  54194. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54195. +
  54196. + pcd->ep0_pending = 1;
  54197. + /* Read the control write's data stage */
  54198. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54199. + retval = 0;
  54200. + break;
  54201. +
  54202. + default:
  54203. + retval = -DWC_E_NOT_SUPPORTED;
  54204. + break;
  54205. + }
  54206. +
  54207. + return retval;
  54208. +}
  54209. +
  54210. +/**
  54211. + * This function prepares the core features descriptors and copies its
  54212. + * raw representation into the buffer <buf>.
  54213. + *
  54214. + * The buffer structure is as follows:
  54215. + * all_features_header (8 bytes)
  54216. + * features_#1 (8 bytes + feature name string length)
  54217. + * features_#2 (8 bytes + feature name string length)
  54218. + * .....
  54219. + * features_#n - where n=the total count of feature descriptors
  54220. + */
  54221. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen)
  54222. +{
  54223. + cfi_feature_desc_header_t *prop_hdr = prop_descs;
  54224. + cfi_feature_desc_header_t *prop;
  54225. + cfi_all_features_header_t *all_props_hdr = &all_props_desc_header;
  54226. + cfi_all_features_header_t *tmp;
  54227. + uint8_t *tmpbuf = buf;
  54228. + const uint8_t *pname = NULL;
  54229. + int i, j, namelen = 0, totlen;
  54230. +
  54231. + /* Prepare and copy the core features into the buffer */
  54232. + CFI_INFO("%s:\n", __func__);
  54233. +
  54234. + tmp = (cfi_all_features_header_t *) tmpbuf;
  54235. + *tmp = *all_props_hdr;
  54236. + tmpbuf += CFI_ALL_FEATURES_HDR_LEN;
  54237. +
  54238. + j = sizeof(prop_descs) / sizeof(cfi_all_features_header_t);
  54239. + for (i = 0; i < j; i++, prop_hdr++) {
  54240. + pname = get_prop_name(prop_hdr->wFeatureID, &namelen);
  54241. + prop = (cfi_feature_desc_header_t *) tmpbuf;
  54242. + *prop = *prop_hdr;
  54243. +
  54244. + prop->bNameLen = namelen;
  54245. + prop->wLength =
  54246. + DWC_CONSTANT_CPU_TO_LE16(CFI_FEATURE_DESC_HDR_LEN +
  54247. + namelen);
  54248. +
  54249. + tmpbuf += CFI_FEATURE_DESC_HDR_LEN;
  54250. + dwc_memcpy(tmpbuf, pname, namelen);
  54251. + tmpbuf += namelen;
  54252. + }
  54253. +
  54254. + totlen = tmpbuf - buf;
  54255. +
  54256. + if (totlen > 0) {
  54257. + tmp = (cfi_all_features_header_t *) buf;
  54258. + tmp->wTotalLen = DWC_CONSTANT_CPU_TO_LE16(totlen);
  54259. + }
  54260. +
  54261. + return totlen;
  54262. +}
  54263. +
  54264. +/**
  54265. + * This function releases all the dynamic memory in the CFI object.
  54266. + */
  54267. +static void cfi_release(cfiobject_t * cfiobj)
  54268. +{
  54269. + cfi_ep_t *cfiep;
  54270. + dwc_list_link_t *tmp;
  54271. +
  54272. + CFI_INFO("%s\n", __func__);
  54273. +
  54274. + if (cfiobj->buf_in.buf) {
  54275. + DWC_DMA_FREE(CFI_IN_BUF_LEN, cfiobj->buf_in.buf,
  54276. + cfiobj->buf_in.addr);
  54277. + cfiobj->buf_in.buf = NULL;
  54278. + }
  54279. +
  54280. + if (cfiobj->buf_out.buf) {
  54281. + DWC_DMA_FREE(CFI_OUT_BUF_LEN, cfiobj->buf_out.buf,
  54282. + cfiobj->buf_out.addr);
  54283. + cfiobj->buf_out.buf = NULL;
  54284. + }
  54285. +
  54286. + /* Free the Buffer Setup values for each EP */
  54287. + //list_for_each_entry(cfiep, &cfiobj->active_eps, lh) {
  54288. + DWC_LIST_FOREACH(tmp, &cfiobj->active_eps) {
  54289. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54290. + cfi_free_ep_bs_dyn_data(cfiep);
  54291. + }
  54292. +}
  54293. +
  54294. +/**
  54295. + * This function frees the dynamically allocated EP buffer setup data.
  54296. + */
  54297. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep)
  54298. +{
  54299. + if (cfiep->bm_sg) {
  54300. + DWC_FREE(cfiep->bm_sg);
  54301. + cfiep->bm_sg = NULL;
  54302. + }
  54303. +
  54304. + if (cfiep->bm_align) {
  54305. + DWC_FREE(cfiep->bm_align);
  54306. + cfiep->bm_align = NULL;
  54307. + }
  54308. +
  54309. + if (cfiep->bm_concat) {
  54310. + if (NULL != cfiep->bm_concat->wTxBytes) {
  54311. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  54312. + cfiep->bm_concat->wTxBytes = NULL;
  54313. + }
  54314. + DWC_FREE(cfiep->bm_concat);
  54315. + cfiep->bm_concat = NULL;
  54316. + }
  54317. +}
  54318. +
  54319. +/**
  54320. + * This function initializes the default values of the features
  54321. + * for a specific endpoint and should be called only once when
  54322. + * the EP is enabled first time.
  54323. + */
  54324. +static int cfi_ep_init_defaults(struct dwc_otg_pcd *pcd, cfi_ep_t * cfiep)
  54325. +{
  54326. + int retval = 0;
  54327. +
  54328. + cfiep->bm_sg = DWC_ALLOC(sizeof(ddma_sg_buffer_setup_t));
  54329. + if (NULL == cfiep->bm_sg) {
  54330. + CFI_INFO("Failed to allocate memory for SG feature value\n");
  54331. + return -DWC_E_NO_MEMORY;
  54332. + }
  54333. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  54334. +
  54335. + /* For the Concatenation feature's default value we do not allocate
  54336. + * memory for the wTxBytes field - it will be done in the set_feature_value
  54337. + * request handler.
  54338. + */
  54339. + cfiep->bm_concat = DWC_ALLOC(sizeof(ddma_concat_buffer_setup_t));
  54340. + if (NULL == cfiep->bm_concat) {
  54341. + CFI_INFO
  54342. + ("Failed to allocate memory for CONCATENATION feature value\n");
  54343. + DWC_FREE(cfiep->bm_sg);
  54344. + return -DWC_E_NO_MEMORY;
  54345. + }
  54346. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  54347. +
  54348. + cfiep->bm_align = DWC_ALLOC(sizeof(ddma_align_buffer_setup_t));
  54349. + if (NULL == cfiep->bm_align) {
  54350. + CFI_INFO
  54351. + ("Failed to allocate memory for Alignment feature value\n");
  54352. + DWC_FREE(cfiep->bm_sg);
  54353. + DWC_FREE(cfiep->bm_concat);
  54354. + return -DWC_E_NO_MEMORY;
  54355. + }
  54356. + dwc_memset(cfiep->bm_align, 0, sizeof(ddma_align_buffer_setup_t));
  54357. +
  54358. + return retval;
  54359. +}
  54360. +
  54361. +/**
  54362. + * The callback function that notifies the CFI on the activation of
  54363. + * an endpoint in the PCD. The following steps are done in this function:
  54364. + *
  54365. + * Create a dynamically allocated cfi_ep_t object (a CFI wrapper to the PCD's
  54366. + * active endpoint)
  54367. + * Create MAX_DMA_DESCS_PER_EP count DMA Descriptors for the EP
  54368. + * Set the Buffer Mode to standard
  54369. + * Initialize the default values for all EP modes (SG, Circular, Concat, Align)
  54370. + * Add the cfi_ep_t object to the list of active endpoints in the CFI object
  54371. + */
  54372. +static int cfi_ep_enable(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  54373. + struct dwc_otg_pcd_ep *ep)
  54374. +{
  54375. + cfi_ep_t *cfiep;
  54376. + int retval = -DWC_E_NOT_SUPPORTED;
  54377. +
  54378. + CFI_INFO("%s: epname=%s; epnum=0x%02x\n", __func__,
  54379. + "EP_" /*ep->ep.name */ , ep->desc->bEndpointAddress);
  54380. + /* MAS - Check whether this endpoint already is in the list */
  54381. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  54382. +
  54383. + if (NULL == cfiep) {
  54384. + /* Allocate a cfi_ep_t object */
  54385. + cfiep = DWC_ALLOC(sizeof(cfi_ep_t));
  54386. + if (NULL == cfiep) {
  54387. + CFI_INFO
  54388. + ("Unable to allocate memory for <cfiep> in function %s\n",
  54389. + __func__);
  54390. + return -DWC_E_NO_MEMORY;
  54391. + }
  54392. + dwc_memset(cfiep, 0, sizeof(cfi_ep_t));
  54393. +
  54394. + /* Save the dwc_otg_pcd_ep pointer in the cfiep object */
  54395. + cfiep->ep = ep;
  54396. +
  54397. + /* Allocate the DMA Descriptors chain of MAX_DMA_DESCS_PER_EP count */
  54398. + ep->dwc_ep.descs =
  54399. + DWC_DMA_ALLOC(MAX_DMA_DESCS_PER_EP *
  54400. + sizeof(dwc_otg_dma_desc_t),
  54401. + &ep->dwc_ep.descs_dma_addr);
  54402. +
  54403. + if (NULL == ep->dwc_ep.descs) {
  54404. + DWC_FREE(cfiep);
  54405. + return -DWC_E_NO_MEMORY;
  54406. + }
  54407. +
  54408. + DWC_LIST_INIT(&cfiep->lh);
  54409. +
  54410. + /* Set the buffer mode to BM_STANDARD. It will be modified
  54411. + * when building descriptors for a specific buffer mode */
  54412. + ep->dwc_ep.buff_mode = BM_STANDARD;
  54413. +
  54414. + /* Create and initialize the default values for this EP's Buffer modes */
  54415. + if ((retval = cfi_ep_init_defaults(pcd, cfiep)) < 0)
  54416. + return retval;
  54417. +
  54418. + /* Add the cfi_ep_t object to the CFI object's list of active endpoints */
  54419. + DWC_LIST_INSERT_TAIL(&cfi->active_eps, &cfiep->lh);
  54420. + retval = 0;
  54421. + } else { /* The sought EP already is in the list */
  54422. + CFI_INFO("%s: The sought EP already is in the list\n",
  54423. + __func__);
  54424. + }
  54425. +
  54426. + return retval;
  54427. +}
  54428. +
  54429. +/**
  54430. + * This function is called when the data stage of a 3-stage Control Write request
  54431. + * is complete.
  54432. + *
  54433. + */
  54434. +static int cfi_ctrl_write_complete(struct cfiobject *cfi,
  54435. + struct dwc_otg_pcd *pcd)
  54436. +{
  54437. + uint32_t addr, reg_value;
  54438. + uint16_t wIndex, wValue;
  54439. + uint8_t bRequest;
  54440. + uint8_t *buf = cfi->buf_out.buf;
  54441. + //struct usb_ctrlrequest *ctrl_req = &cfi->ctrl_req_saved;
  54442. + struct cfi_usb_ctrlrequest *ctrl_req = &cfi->ctrl_req;
  54443. + int retval = -DWC_E_NOT_SUPPORTED;
  54444. +
  54445. + CFI_INFO("%s\n", __func__);
  54446. +
  54447. + bRequest = ctrl_req->bRequest;
  54448. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  54449. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  54450. +
  54451. + /*
  54452. + * Save the pointer to the data stage in the ctrl_req's <data> field.
  54453. + * The request should be already saved in the command stage by now.
  54454. + */
  54455. + ctrl_req->data = cfi->buf_out.buf;
  54456. + cfi->need_status_in_complete = 0;
  54457. + cfi->need_gadget_att = 0;
  54458. +
  54459. + switch (bRequest) {
  54460. + case VEN_CORE_WRITE_REGISTER:
  54461. + /* The buffer contains raw data of the new value for the register */
  54462. + reg_value = *((uint32_t *) buf);
  54463. + if (wValue == 0) {
  54464. + addr = 0;
  54465. + //addr = (uint32_t) pcd->otg_dev->os_dep.base;
  54466. + addr += wIndex;
  54467. + } else {
  54468. + addr = (wValue << 16) | wIndex;
  54469. + }
  54470. +
  54471. + //writel(reg_value, addr);
  54472. +
  54473. + retval = 0;
  54474. + cfi->need_status_in_complete = 1;
  54475. + break;
  54476. +
  54477. + case VEN_CORE_SET_FEATURE:
  54478. + /* The buffer contains raw data of the new value of the feature */
  54479. + retval = cfi_set_feature_value(pcd);
  54480. + if (retval < 0)
  54481. + return retval;
  54482. +
  54483. + cfi->need_status_in_complete = 1;
  54484. + break;
  54485. +
  54486. + default:
  54487. + break;
  54488. + }
  54489. +
  54490. + return retval;
  54491. +}
  54492. +
  54493. +/**
  54494. + * This function builds the DMA descriptors for the SG buffer mode.
  54495. + */
  54496. +static void cfi_build_sg_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  54497. + dwc_otg_pcd_request_t * req)
  54498. +{
  54499. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  54500. + ddma_sg_buffer_setup_t *sgval = cfiep->bm_sg;
  54501. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  54502. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  54503. + dma_addr_t buff_addr = req->dma;
  54504. + int i;
  54505. + uint32_t txsize, off;
  54506. +
  54507. + txsize = sgval->wSize;
  54508. + off = sgval->bOffset;
  54509. +
  54510. +// CFI_INFO("%s: %s TXSIZE=0x%08x; OFFSET=0x%08x\n",
  54511. +// __func__, cfiep->ep->ep.name, txsize, off);
  54512. +
  54513. + for (i = 0; i < sgval->bCount; i++) {
  54514. + desc->status.b.bs = BS_HOST_BUSY;
  54515. + desc->buf = buff_addr;
  54516. + desc->status.b.l = 0;
  54517. + desc->status.b.ioc = 0;
  54518. + desc->status.b.sp = 0;
  54519. + desc->status.b.bytes = txsize;
  54520. + desc->status.b.bs = BS_HOST_READY;
  54521. +
  54522. + /* Set the next address of the buffer */
  54523. + buff_addr += txsize + off;
  54524. + desc_last = desc;
  54525. + desc++;
  54526. + }
  54527. +
  54528. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  54529. + desc_last->status.b.l = 1;
  54530. + desc_last->status.b.ioc = 1;
  54531. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  54532. + /* Save the last DMA descriptor pointer */
  54533. + cfiep->dma_desc_last = desc_last;
  54534. + cfiep->desc_count = sgval->bCount;
  54535. +}
  54536. +
  54537. +/**
  54538. + * This function builds the DMA descriptors for the Concatenation buffer mode.
  54539. + */
  54540. +static void cfi_build_concat_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  54541. + dwc_otg_pcd_request_t * req)
  54542. +{
  54543. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  54544. + ddma_concat_buffer_setup_t *concatval = cfiep->bm_concat;
  54545. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  54546. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  54547. + dma_addr_t buff_addr = req->dma;
  54548. + int i;
  54549. + uint16_t *txsize;
  54550. +
  54551. + txsize = concatval->wTxBytes;
  54552. +
  54553. + for (i = 0; i < concatval->hdr.bDescCount; i++) {
  54554. + desc->buf = buff_addr;
  54555. + desc->status.b.bs = BS_HOST_BUSY;
  54556. + desc->status.b.l = 0;
  54557. + desc->status.b.ioc = 0;
  54558. + desc->status.b.sp = 0;
  54559. + desc->status.b.bytes = *txsize;
  54560. + desc->status.b.bs = BS_HOST_READY;
  54561. +
  54562. + txsize++;
  54563. + /* Set the next address of the buffer */
  54564. + buff_addr += UGETW(ep->desc->wMaxPacketSize);
  54565. + desc_last = desc;
  54566. + desc++;
  54567. + }
  54568. +
  54569. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  54570. + desc_last->status.b.l = 1;
  54571. + desc_last->status.b.ioc = 1;
  54572. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  54573. + cfiep->dma_desc_last = desc_last;
  54574. + cfiep->desc_count = concatval->hdr.bDescCount;
  54575. +}
  54576. +
  54577. +/**
  54578. + * This function builds the DMA descriptors for the Circular buffer mode
  54579. + */
  54580. +static void cfi_build_circ_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  54581. + dwc_otg_pcd_request_t * req)
  54582. +{
  54583. + /* @todo: MAS - add implementation when this feature needs to be tested */
  54584. +}
  54585. +
  54586. +/**
  54587. + * This function builds the DMA descriptors for the Alignment buffer mode
  54588. + */
  54589. +static void cfi_build_align_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  54590. + dwc_otg_pcd_request_t * req)
  54591. +{
  54592. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  54593. + ddma_align_buffer_setup_t *alignval = cfiep->bm_align;
  54594. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  54595. + dma_addr_t buff_addr = req->dma;
  54596. +
  54597. + desc->status.b.bs = BS_HOST_BUSY;
  54598. + desc->status.b.l = 1;
  54599. + desc->status.b.ioc = 1;
  54600. + desc->status.b.sp = ep->dwc_ep.sent_zlp;
  54601. + desc->status.b.bytes = req->length;
  54602. + /* Adjust the buffer alignment */
  54603. + desc->buf = (buff_addr + alignval->bAlign);
  54604. + desc->status.b.bs = BS_HOST_READY;
  54605. + cfiep->dma_desc_last = desc;
  54606. + cfiep->desc_count = 1;
  54607. +}
  54608. +
  54609. +/**
  54610. + * This function builds the DMA descriptors chain for different modes of the
  54611. + * buffer setup of an endpoint.
  54612. + */
  54613. +static void cfi_build_descriptors(struct cfiobject *cfi,
  54614. + struct dwc_otg_pcd *pcd,
  54615. + struct dwc_otg_pcd_ep *ep,
  54616. + dwc_otg_pcd_request_t * req)
  54617. +{
  54618. + cfi_ep_t *cfiep;
  54619. +
  54620. + /* Get the cfiep by the dwc_otg_pcd_ep */
  54621. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  54622. + if (NULL == cfiep) {
  54623. + CFI_INFO("%s: Unable to find a matching active endpoint\n",
  54624. + __func__);
  54625. + return;
  54626. + }
  54627. +
  54628. + cfiep->xfer_len = req->length;
  54629. +
  54630. + /* Iterate through all the DMA descriptors */
  54631. + switch (cfiep->ep->dwc_ep.buff_mode) {
  54632. + case BM_SG:
  54633. + cfi_build_sg_descs(cfi, cfiep, req);
  54634. + break;
  54635. +
  54636. + case BM_CONCAT:
  54637. + cfi_build_concat_descs(cfi, cfiep, req);
  54638. + break;
  54639. +
  54640. + case BM_CIRCULAR:
  54641. + cfi_build_circ_descs(cfi, cfiep, req);
  54642. + break;
  54643. +
  54644. + case BM_ALIGN:
  54645. + cfi_build_align_descs(cfi, cfiep, req);
  54646. + break;
  54647. +
  54648. + default:
  54649. + break;
  54650. + }
  54651. +}
  54652. +
  54653. +/**
  54654. + * Allocate DMA buffer for different Buffer modes.
  54655. + */
  54656. +static void *cfi_ep_alloc_buf(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  54657. + struct dwc_otg_pcd_ep *ep, dma_addr_t * dma,
  54658. + unsigned size, gfp_t flags)
  54659. +{
  54660. + return DWC_DMA_ALLOC(size, dma);
  54661. +}
  54662. +
  54663. +/**
  54664. + * This function initializes the CFI object.
  54665. + */
  54666. +int init_cfi(cfiobject_t * cfiobj)
  54667. +{
  54668. + CFI_INFO("%s\n", __func__);
  54669. +
  54670. + /* Allocate a buffer for IN XFERs */
  54671. + cfiobj->buf_in.buf =
  54672. + DWC_DMA_ALLOC(CFI_IN_BUF_LEN, &cfiobj->buf_in.addr);
  54673. + if (NULL == cfiobj->buf_in.buf) {
  54674. + CFI_INFO("Unable to allocate buffer for INs\n");
  54675. + return -DWC_E_NO_MEMORY;
  54676. + }
  54677. +
  54678. + /* Allocate a buffer for OUT XFERs */
  54679. + cfiobj->buf_out.buf =
  54680. + DWC_DMA_ALLOC(CFI_OUT_BUF_LEN, &cfiobj->buf_out.addr);
  54681. + if (NULL == cfiobj->buf_out.buf) {
  54682. + CFI_INFO("Unable to allocate buffer for OUT\n");
  54683. + return -DWC_E_NO_MEMORY;
  54684. + }
  54685. +
  54686. + /* Initialize the callback function pointers */
  54687. + cfiobj->ops.release = cfi_release;
  54688. + cfiobj->ops.ep_enable = cfi_ep_enable;
  54689. + cfiobj->ops.ctrl_write_complete = cfi_ctrl_write_complete;
  54690. + cfiobj->ops.build_descriptors = cfi_build_descriptors;
  54691. + cfiobj->ops.ep_alloc_buf = cfi_ep_alloc_buf;
  54692. +
  54693. + /* Initialize the list of active endpoints in the CFI object */
  54694. + DWC_LIST_INIT(&cfiobj->active_eps);
  54695. +
  54696. + return 0;
  54697. +}
  54698. +
  54699. +/**
  54700. + * This function reads the required feature's current value into the buffer
  54701. + *
  54702. + * @retval: Returns negative as error, or the data length of the feature
  54703. + */
  54704. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  54705. + struct dwc_otg_pcd *pcd,
  54706. + struct cfi_usb_ctrlrequest *ctrl_req)
  54707. +{
  54708. + int retval = -DWC_E_NOT_SUPPORTED;
  54709. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  54710. + uint16_t dfifo, rxfifo, txfifo;
  54711. +
  54712. + switch (ctrl_req->wIndex) {
  54713. + /* Whether the DDMA is enabled or not */
  54714. + case FT_ID_DMA_MODE:
  54715. + *buf = (coreif->dma_enable && coreif->dma_desc_enable) ? 1 : 0;
  54716. + retval = 1;
  54717. + break;
  54718. +
  54719. + case FT_ID_DMA_BUFFER_SETUP:
  54720. + retval = cfi_ep_get_sg_val(buf, pcd, ctrl_req);
  54721. + break;
  54722. +
  54723. + case FT_ID_DMA_BUFF_ALIGN:
  54724. + retval = cfi_ep_get_align_val(buf, pcd, ctrl_req);
  54725. + break;
  54726. +
  54727. + case FT_ID_DMA_CONCAT_SETUP:
  54728. + retval = cfi_ep_get_concat_val(buf, pcd, ctrl_req);
  54729. + break;
  54730. +
  54731. + case FT_ID_DMA_CIRCULAR:
  54732. + CFI_INFO("GetFeature value (FT_ID_DMA_CIRCULAR)\n");
  54733. + break;
  54734. +
  54735. + case FT_ID_THRESHOLD_SETUP:
  54736. + CFI_INFO("GetFeature value (FT_ID_THRESHOLD_SETUP)\n");
  54737. + break;
  54738. +
  54739. + case FT_ID_DFIFO_DEPTH:
  54740. + dfifo = get_dfifo_size(coreif);
  54741. + *((uint16_t *) buf) = dfifo;
  54742. + retval = sizeof(uint16_t);
  54743. + break;
  54744. +
  54745. + case FT_ID_TX_FIFO_DEPTH:
  54746. + retval = get_txfifo_size(pcd, ctrl_req->wValue);
  54747. + if (retval >= 0) {
  54748. + txfifo = retval;
  54749. + *((uint16_t *) buf) = txfifo;
  54750. + retval = sizeof(uint16_t);
  54751. + }
  54752. + break;
  54753. +
  54754. + case FT_ID_RX_FIFO_DEPTH:
  54755. + retval = get_rxfifo_size(coreif, ctrl_req->wValue);
  54756. + if (retval >= 0) {
  54757. + rxfifo = retval;
  54758. + *((uint16_t *) buf) = rxfifo;
  54759. + retval = sizeof(uint16_t);
  54760. + }
  54761. + break;
  54762. + }
  54763. +
  54764. + return retval;
  54765. +}
  54766. +
  54767. +/**
  54768. + * This function resets the SG for the specified EP to its default value
  54769. + */
  54770. +static int cfi_reset_sg_val(cfi_ep_t * cfiep)
  54771. +{
  54772. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  54773. + return 0;
  54774. +}
  54775. +
  54776. +/**
  54777. + * This function resets the Alignment for the specified EP to its default value
  54778. + */
  54779. +static int cfi_reset_align_val(cfi_ep_t * cfiep)
  54780. +{
  54781. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  54782. + return 0;
  54783. +}
  54784. +
  54785. +/**
  54786. + * This function resets the Concatenation for the specified EP to its default value
  54787. + * This function will also set the value of the wTxBytes field to NULL after
  54788. + * freeing the memory previously allocated for this field.
  54789. + */
  54790. +static int cfi_reset_concat_val(cfi_ep_t * cfiep)
  54791. +{
  54792. + /* First we need to free the wTxBytes field */
  54793. + if (cfiep->bm_concat->wTxBytes) {
  54794. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  54795. + cfiep->bm_concat->wTxBytes = NULL;
  54796. + }
  54797. +
  54798. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  54799. + return 0;
  54800. +}
  54801. +
  54802. +/**
  54803. + * This function resets all the buffer setups of the specified endpoint
  54804. + */
  54805. +static int cfi_ep_reset_all_setup_vals(cfi_ep_t * cfiep)
  54806. +{
  54807. + cfi_reset_sg_val(cfiep);
  54808. + cfi_reset_align_val(cfiep);
  54809. + cfi_reset_concat_val(cfiep);
  54810. + return 0;
  54811. +}
  54812. +
  54813. +static int cfi_handle_reset_fifo_val(struct dwc_otg_pcd *pcd, uint8_t ep_addr,
  54814. + uint8_t rx_rst, uint8_t tx_rst)
  54815. +{
  54816. + int retval = -DWC_E_INVALID;
  54817. + uint16_t tx_siz[15];
  54818. + uint16_t rx_siz = 0;
  54819. + dwc_otg_pcd_ep_t *ep = NULL;
  54820. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  54821. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  54822. +
  54823. + if (rx_rst) {
  54824. + rx_siz = params->dev_rx_fifo_size;
  54825. + params->dev_rx_fifo_size = GET_CORE_IF(pcd)->init_rxfsiz;
  54826. + }
  54827. +
  54828. + if (tx_rst) {
  54829. + if (ep_addr == 0) {
  54830. + int i;
  54831. +
  54832. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54833. + tx_siz[i] =
  54834. + core_if->core_params->dev_tx_fifo_size[i];
  54835. + core_if->core_params->dev_tx_fifo_size[i] =
  54836. + core_if->init_txfsiz[i];
  54837. + }
  54838. + } else {
  54839. +
  54840. + ep = get_ep_by_addr(pcd, ep_addr);
  54841. +
  54842. + if (NULL == ep) {
  54843. + CFI_INFO
  54844. + ("%s: Unable to get the endpoint addr=0x%02x\n",
  54845. + __func__, ep_addr);
  54846. + return -DWC_E_INVALID;
  54847. + }
  54848. +
  54849. + tx_siz[0] =
  54850. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num -
  54851. + 1];
  54852. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] =
  54853. + GET_CORE_IF(pcd)->init_txfsiz[ep->
  54854. + dwc_ep.tx_fifo_num -
  54855. + 1];
  54856. + }
  54857. + }
  54858. +
  54859. + if (resize_fifos(GET_CORE_IF(pcd))) {
  54860. + retval = 0;
  54861. + } else {
  54862. + CFI_INFO
  54863. + ("%s: Error resetting the feature Reset All(FIFO size)\n",
  54864. + __func__);
  54865. + if (rx_rst) {
  54866. + params->dev_rx_fifo_size = rx_siz;
  54867. + }
  54868. +
  54869. + if (tx_rst) {
  54870. + if (ep_addr == 0) {
  54871. + int i;
  54872. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps;
  54873. + i++) {
  54874. + core_if->
  54875. + core_params->dev_tx_fifo_size[i] =
  54876. + tx_siz[i];
  54877. + }
  54878. + } else {
  54879. + params->dev_tx_fifo_size[ep->
  54880. + dwc_ep.tx_fifo_num -
  54881. + 1] = tx_siz[0];
  54882. + }
  54883. + }
  54884. + retval = -DWC_E_INVALID;
  54885. + }
  54886. + return retval;
  54887. +}
  54888. +
  54889. +static int cfi_handle_reset_all(struct dwc_otg_pcd *pcd, uint8_t addr)
  54890. +{
  54891. + int retval = 0;
  54892. + cfi_ep_t *cfiep;
  54893. + cfiobject_t *cfi = pcd->cfi;
  54894. + dwc_list_link_t *tmp;
  54895. +
  54896. + retval = cfi_handle_reset_fifo_val(pcd, addr, 1, 1);
  54897. + if (retval < 0) {
  54898. + return retval;
  54899. + }
  54900. +
  54901. + /* If the EP address is known then reset the features for only that EP */
  54902. + if (addr) {
  54903. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54904. + if (NULL == cfiep) {
  54905. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54906. + __func__, addr);
  54907. + return -DWC_E_INVALID;
  54908. + }
  54909. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  54910. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  54911. + }
  54912. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54913. + else {
  54914. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54915. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54916. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54917. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54918. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  54919. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  54920. + if (retval < 0) {
  54921. + CFI_INFO
  54922. + ("%s: Error resetting the feature Reset All\n",
  54923. + __func__);
  54924. + return retval;
  54925. + }
  54926. + }
  54927. + }
  54928. + return retval;
  54929. +}
  54930. +
  54931. +static int cfi_handle_reset_dma_buff_setup(struct dwc_otg_pcd *pcd,
  54932. + uint8_t addr)
  54933. +{
  54934. + int retval = 0;
  54935. + cfi_ep_t *cfiep;
  54936. + cfiobject_t *cfi = pcd->cfi;
  54937. + dwc_list_link_t *tmp;
  54938. +
  54939. + /* If the EP address is known then reset the features for only that EP */
  54940. + if (addr) {
  54941. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54942. + if (NULL == cfiep) {
  54943. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54944. + __func__, addr);
  54945. + return -DWC_E_INVALID;
  54946. + }
  54947. + retval = cfi_reset_sg_val(cfiep);
  54948. + }
  54949. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54950. + else {
  54951. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54952. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54953. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54954. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54955. + retval = cfi_reset_sg_val(cfiep);
  54956. + if (retval < 0) {
  54957. + CFI_INFO
  54958. + ("%s: Error resetting the feature Buffer Setup\n",
  54959. + __func__);
  54960. + return retval;
  54961. + }
  54962. + }
  54963. + }
  54964. + return retval;
  54965. +}
  54966. +
  54967. +static int cfi_handle_reset_concat_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  54968. +{
  54969. + int retval = 0;
  54970. + cfi_ep_t *cfiep;
  54971. + cfiobject_t *cfi = pcd->cfi;
  54972. + dwc_list_link_t *tmp;
  54973. +
  54974. + /* If the EP address is known then reset the features for only that EP */
  54975. + if (addr) {
  54976. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54977. + if (NULL == cfiep) {
  54978. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54979. + __func__, addr);
  54980. + return -DWC_E_INVALID;
  54981. + }
  54982. + retval = cfi_reset_concat_val(cfiep);
  54983. + }
  54984. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54985. + else {
  54986. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54987. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54988. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54989. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54990. + retval = cfi_reset_concat_val(cfiep);
  54991. + if (retval < 0) {
  54992. + CFI_INFO
  54993. + ("%s: Error resetting the feature Concatenation Value\n",
  54994. + __func__);
  54995. + return retval;
  54996. + }
  54997. + }
  54998. + }
  54999. + return retval;
  55000. +}
  55001. +
  55002. +static int cfi_handle_reset_align_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  55003. +{
  55004. + int retval = 0;
  55005. + cfi_ep_t *cfiep;
  55006. + cfiobject_t *cfi = pcd->cfi;
  55007. + dwc_list_link_t *tmp;
  55008. +
  55009. + /* If the EP address is known then reset the features for only that EP */
  55010. + if (addr) {
  55011. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55012. + if (NULL == cfiep) {
  55013. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  55014. + __func__, addr);
  55015. + return -DWC_E_INVALID;
  55016. + }
  55017. + retval = cfi_reset_align_val(cfiep);
  55018. + }
  55019. + /* Otherwise (wValue == 0), reset all features of all EP's */
  55020. + else {
  55021. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  55022. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  55023. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55024. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55025. + retval = cfi_reset_align_val(cfiep);
  55026. + if (retval < 0) {
  55027. + CFI_INFO
  55028. + ("%s: Error resetting the feature Aliignment Value\n",
  55029. + __func__);
  55030. + return retval;
  55031. + }
  55032. + }
  55033. + }
  55034. + return retval;
  55035. +
  55036. +}
  55037. +
  55038. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  55039. + struct cfi_usb_ctrlrequest *req)
  55040. +{
  55041. + int retval = 0;
  55042. +
  55043. + switch (req->wIndex) {
  55044. + case 0:
  55045. + /* Reset all features */
  55046. + retval = cfi_handle_reset_all(pcd, req->wValue & 0xff);
  55047. + break;
  55048. +
  55049. + case FT_ID_DMA_BUFFER_SETUP:
  55050. + /* Reset the SG buffer setup */
  55051. + retval =
  55052. + cfi_handle_reset_dma_buff_setup(pcd, req->wValue & 0xff);
  55053. + break;
  55054. +
  55055. + case FT_ID_DMA_CONCAT_SETUP:
  55056. + /* Reset the Concatenation buffer setup */
  55057. + retval = cfi_handle_reset_concat_val(pcd, req->wValue & 0xff);
  55058. + break;
  55059. +
  55060. + case FT_ID_DMA_BUFF_ALIGN:
  55061. + /* Reset the Alignment buffer setup */
  55062. + retval = cfi_handle_reset_align_val(pcd, req->wValue & 0xff);
  55063. + break;
  55064. +
  55065. + case FT_ID_TX_FIFO_DEPTH:
  55066. + retval =
  55067. + cfi_handle_reset_fifo_val(pcd, req->wValue & 0xff, 0, 1);
  55068. + pcd->cfi->need_gadget_att = 0;
  55069. + break;
  55070. +
  55071. + case FT_ID_RX_FIFO_DEPTH:
  55072. + retval = cfi_handle_reset_fifo_val(pcd, 0, 1, 0);
  55073. + pcd->cfi->need_gadget_att = 0;
  55074. + break;
  55075. + default:
  55076. + break;
  55077. + }
  55078. + return retval;
  55079. +}
  55080. +
  55081. +/**
  55082. + * This function sets a new value for the SG buffer setup.
  55083. + */
  55084. +static int cfi_ep_set_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  55085. +{
  55086. + uint8_t inaddr, outaddr;
  55087. + cfi_ep_t *epin, *epout;
  55088. + ddma_sg_buffer_setup_t *psgval;
  55089. + uint32_t desccount, size;
  55090. +
  55091. + CFI_INFO("%s\n", __func__);
  55092. +
  55093. + psgval = (ddma_sg_buffer_setup_t *) buf;
  55094. + desccount = (uint32_t) psgval->bCount;
  55095. + size = (uint32_t) psgval->wSize;
  55096. +
  55097. + /* Check the DMA descriptor count */
  55098. + if ((desccount > MAX_DMA_DESCS_PER_EP) || (desccount == 0)) {
  55099. + CFI_INFO
  55100. + ("%s: The count of DMA Descriptors should be between 1 and %d\n",
  55101. + __func__, MAX_DMA_DESCS_PER_EP);
  55102. + return -DWC_E_INVALID;
  55103. + }
  55104. +
  55105. + /* Check the DMA descriptor count */
  55106. +
  55107. + if (size == 0) {
  55108. +
  55109. + CFI_INFO("%s: The transfer size should be at least 1 byte\n",
  55110. + __func__);
  55111. +
  55112. + return -DWC_E_INVALID;
  55113. +
  55114. + }
  55115. +
  55116. + inaddr = psgval->bInEndpointAddress;
  55117. + outaddr = psgval->bOutEndpointAddress;
  55118. +
  55119. + epin = get_cfi_ep_by_addr(pcd->cfi, inaddr);
  55120. + epout = get_cfi_ep_by_addr(pcd->cfi, outaddr);
  55121. +
  55122. + if (NULL == epin || NULL == epout) {
  55123. + CFI_INFO
  55124. + ("%s: Unable to get the endpoints inaddr=0x%02x outaddr=0x%02x\n",
  55125. + __func__, inaddr, outaddr);
  55126. + return -DWC_E_INVALID;
  55127. + }
  55128. +
  55129. + epin->ep->dwc_ep.buff_mode = BM_SG;
  55130. + dwc_memcpy(epin->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  55131. +
  55132. + epout->ep->dwc_ep.buff_mode = BM_SG;
  55133. + dwc_memcpy(epout->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  55134. +
  55135. + return 0;
  55136. +}
  55137. +
  55138. +/**
  55139. + * This function sets a new value for the buffer Alignment setup.
  55140. + */
  55141. +static int cfi_ep_set_alignment_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  55142. +{
  55143. + cfi_ep_t *ep;
  55144. + uint8_t addr;
  55145. + ddma_align_buffer_setup_t *palignval;
  55146. +
  55147. + palignval = (ddma_align_buffer_setup_t *) buf;
  55148. + addr = palignval->bEndpointAddress;
  55149. +
  55150. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55151. +
  55152. + if (NULL == ep) {
  55153. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55154. + __func__, addr);
  55155. + return -DWC_E_INVALID;
  55156. + }
  55157. +
  55158. + ep->ep->dwc_ep.buff_mode = BM_ALIGN;
  55159. + dwc_memcpy(ep->bm_align, palignval, sizeof(ddma_align_buffer_setup_t));
  55160. +
  55161. + return 0;
  55162. +}
  55163. +
  55164. +/**
  55165. + * This function sets a new value for the Concatenation buffer setup.
  55166. + */
  55167. +static int cfi_ep_set_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  55168. +{
  55169. + uint8_t addr;
  55170. + cfi_ep_t *ep;
  55171. + struct _ddma_concat_buffer_setup_hdr *pConcatValHdr;
  55172. + uint16_t *pVals;
  55173. + uint32_t desccount;
  55174. + int i;
  55175. + uint16_t mps;
  55176. +
  55177. + pConcatValHdr = (struct _ddma_concat_buffer_setup_hdr *)buf;
  55178. + desccount = (uint32_t) pConcatValHdr->bDescCount;
  55179. + pVals = (uint16_t *) (buf + BS_CONCAT_VAL_HDR_LEN);
  55180. +
  55181. + /* Check the DMA descriptor count */
  55182. + if (desccount > MAX_DMA_DESCS_PER_EP) {
  55183. + CFI_INFO("%s: Maximum DMA Descriptor count should be %d\n",
  55184. + __func__, MAX_DMA_DESCS_PER_EP);
  55185. + return -DWC_E_INVALID;
  55186. + }
  55187. +
  55188. + addr = pConcatValHdr->bEndpointAddress;
  55189. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55190. + if (NULL == ep) {
  55191. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55192. + __func__, addr);
  55193. + return -DWC_E_INVALID;
  55194. + }
  55195. +
  55196. + mps = UGETW(ep->ep->desc->wMaxPacketSize);
  55197. +
  55198. +#if 0
  55199. + for (i = 0; i < desccount; i++) {
  55200. + CFI_INFO("%s: wTxSize[%d]=0x%04x\n", __func__, i, pVals[i]);
  55201. + }
  55202. + CFI_INFO("%s: epname=%s; mps=%d\n", __func__, ep->ep->ep.name, mps);
  55203. +#endif
  55204. +
  55205. + /* Check the wTxSizes to be less than or equal to the mps */
  55206. + for (i = 0; i < desccount; i++) {
  55207. + if (pVals[i] > mps) {
  55208. + CFI_INFO
  55209. + ("%s: ERROR - the wTxSize[%d] should be <= MPS (wTxSize=%d)\n",
  55210. + __func__, i, pVals[i]);
  55211. + return -DWC_E_INVALID;
  55212. + }
  55213. + }
  55214. +
  55215. + ep->ep->dwc_ep.buff_mode = BM_CONCAT;
  55216. + dwc_memcpy(ep->bm_concat, pConcatValHdr, BS_CONCAT_VAL_HDR_LEN);
  55217. +
  55218. + /* Free the previously allocated storage for the wTxBytes */
  55219. + if (ep->bm_concat->wTxBytes) {
  55220. + DWC_FREE(ep->bm_concat->wTxBytes);
  55221. + }
  55222. +
  55223. + /* Allocate a new storage for the wTxBytes field */
  55224. + ep->bm_concat->wTxBytes =
  55225. + DWC_ALLOC(sizeof(uint16_t) * pConcatValHdr->bDescCount);
  55226. + if (NULL == ep->bm_concat->wTxBytes) {
  55227. + CFI_INFO("%s: Unable to allocate memory\n", __func__);
  55228. + return -DWC_E_NO_MEMORY;
  55229. + }
  55230. +
  55231. + /* Copy the new values into the wTxBytes filed */
  55232. + dwc_memcpy(ep->bm_concat->wTxBytes, buf + BS_CONCAT_VAL_HDR_LEN,
  55233. + sizeof(uint16_t) * pConcatValHdr->bDescCount);
  55234. +
  55235. + return 0;
  55236. +}
  55237. +
  55238. +/**
  55239. + * This function calculates the total of all FIFO sizes
  55240. + *
  55241. + * @param core_if Programming view of DWC_otg controller
  55242. + *
  55243. + * @return The total of data FIFO sizes.
  55244. + *
  55245. + */
  55246. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if)
  55247. +{
  55248. + dwc_otg_core_params_t *params = core_if->core_params;
  55249. + uint16_t dfifo_total = 0;
  55250. + int i;
  55251. +
  55252. + /* The shared RxFIFO size */
  55253. + dfifo_total =
  55254. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  55255. +
  55256. + /* Add up each TxFIFO size to the total */
  55257. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55258. + dfifo_total += params->dev_tx_fifo_size[i];
  55259. + }
  55260. +
  55261. + return dfifo_total;
  55262. +}
  55263. +
  55264. +/**
  55265. + * This function returns Rx FIFO size
  55266. + *
  55267. + * @param core_if Programming view of DWC_otg controller
  55268. + *
  55269. + * @return The total of data FIFO sizes.
  55270. + *
  55271. + */
  55272. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue)
  55273. +{
  55274. + switch (wValue >> 8) {
  55275. + case 0:
  55276. + return (core_if->pwron_rxfsiz <
  55277. + 32768) ? core_if->pwron_rxfsiz : 32768;
  55278. + break;
  55279. + case 1:
  55280. + return core_if->core_params->dev_rx_fifo_size;
  55281. + break;
  55282. + default:
  55283. + return -DWC_E_INVALID;
  55284. + break;
  55285. + }
  55286. +}
  55287. +
  55288. +/**
  55289. + * This function returns Tx FIFO size for IN EP
  55290. + *
  55291. + * @param core_if Programming view of DWC_otg controller
  55292. + *
  55293. + * @return The total of data FIFO sizes.
  55294. + *
  55295. + */
  55296. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue)
  55297. +{
  55298. + dwc_otg_pcd_ep_t *ep;
  55299. +
  55300. + ep = get_ep_by_addr(pcd, wValue & 0xff);
  55301. +
  55302. + if (NULL == ep) {
  55303. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55304. + __func__, wValue & 0xff);
  55305. + return -DWC_E_INVALID;
  55306. + }
  55307. +
  55308. + if (!ep->dwc_ep.is_in) {
  55309. + CFI_INFO
  55310. + ("%s: No Tx FIFO assingned to the Out endpoint addr=0x%02x\n",
  55311. + __func__, wValue & 0xff);
  55312. + return -DWC_E_INVALID;
  55313. + }
  55314. +
  55315. + switch (wValue >> 8) {
  55316. + case 0:
  55317. + return (GET_CORE_IF(pcd)->pwron_txfsiz
  55318. + [ep->dwc_ep.tx_fifo_num - 1] <
  55319. + 768) ? GET_CORE_IF(pcd)->pwron_txfsiz[ep->
  55320. + dwc_ep.tx_fifo_num
  55321. + - 1] : 32768;
  55322. + break;
  55323. + case 1:
  55324. + return GET_CORE_IF(pcd)->core_params->
  55325. + dev_tx_fifo_size[ep->dwc_ep.num - 1];
  55326. + break;
  55327. + default:
  55328. + return -DWC_E_INVALID;
  55329. + break;
  55330. + }
  55331. +}
  55332. +
  55333. +/**
  55334. + * This function checks if the submitted combination of
  55335. + * device mode FIFO sizes is possible or not.
  55336. + *
  55337. + * @param core_if Programming view of DWC_otg controller
  55338. + *
  55339. + * @return 1 if possible, 0 otherwise.
  55340. + *
  55341. + */
  55342. +static uint8_t check_fifo_sizes(dwc_otg_core_if_t * core_if)
  55343. +{
  55344. + uint16_t dfifo_actual = 0;
  55345. + dwc_otg_core_params_t *params = core_if->core_params;
  55346. + uint16_t start_addr = 0;
  55347. + int i;
  55348. +
  55349. + dfifo_actual =
  55350. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  55351. +
  55352. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55353. + dfifo_actual += params->dev_tx_fifo_size[i];
  55354. + }
  55355. +
  55356. + if (dfifo_actual > core_if->total_fifo_size) {
  55357. + return 0;
  55358. + }
  55359. +
  55360. + if (params->dev_rx_fifo_size > 32768 || params->dev_rx_fifo_size < 16)
  55361. + return 0;
  55362. +
  55363. + if (params->dev_nperio_tx_fifo_size > 32768
  55364. + || params->dev_nperio_tx_fifo_size < 16)
  55365. + return 0;
  55366. +
  55367. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55368. +
  55369. + if (params->dev_tx_fifo_size[i] > 768
  55370. + || params->dev_tx_fifo_size[i] < 4)
  55371. + return 0;
  55372. + }
  55373. +
  55374. + if (params->dev_rx_fifo_size > core_if->pwron_rxfsiz)
  55375. + return 0;
  55376. + start_addr = params->dev_rx_fifo_size;
  55377. +
  55378. + if (params->dev_nperio_tx_fifo_size > core_if->pwron_gnptxfsiz)
  55379. + return 0;
  55380. + start_addr += params->dev_nperio_tx_fifo_size;
  55381. +
  55382. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55383. +
  55384. + if (params->dev_tx_fifo_size[i] > core_if->pwron_txfsiz[i])
  55385. + return 0;
  55386. + start_addr += params->dev_tx_fifo_size[i];
  55387. + }
  55388. +
  55389. + return 1;
  55390. +}
  55391. +
  55392. +/**
  55393. + * This function resizes Device mode FIFOs
  55394. + *
  55395. + * @param core_if Programming view of DWC_otg controller
  55396. + *
  55397. + * @return 1 if successful, 0 otherwise
  55398. + *
  55399. + */
  55400. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if)
  55401. +{
  55402. + int i = 0;
  55403. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  55404. + dwc_otg_core_params_t *params = core_if->core_params;
  55405. + uint32_t rx_fifo_size;
  55406. + fifosize_data_t nptxfifosize;
  55407. + fifosize_data_t txfifosize[15];
  55408. +
  55409. + uint32_t rx_fsz_bak;
  55410. + uint32_t nptxfsz_bak;
  55411. + uint32_t txfsz_bak[15];
  55412. +
  55413. + uint16_t start_address;
  55414. + uint8_t retval = 1;
  55415. +
  55416. + if (!check_fifo_sizes(core_if)) {
  55417. + return 0;
  55418. + }
  55419. +
  55420. + /* Configure data FIFO sizes */
  55421. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  55422. + rx_fsz_bak = DWC_READ_REG32(&global_regs->grxfsiz);
  55423. + rx_fifo_size = params->dev_rx_fifo_size;
  55424. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  55425. +
  55426. + /*
  55427. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  55428. + * Indexes of the FIFO size module parameters in the
  55429. + * dev_tx_fifo_size array and the FIFO size registers in
  55430. + * the dtxfsiz array run from 0 to 14.
  55431. + */
  55432. +
  55433. + /* Non-periodic Tx FIFO */
  55434. + nptxfsz_bak = DWC_READ_REG32(&global_regs->gnptxfsiz);
  55435. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  55436. + start_address = params->dev_rx_fifo_size;
  55437. + nptxfifosize.b.startaddr = start_address;
  55438. +
  55439. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  55440. +
  55441. + start_address += nptxfifosize.b.depth;
  55442. +
  55443. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55444. + txfsz_bak[i] = DWC_READ_REG32(&global_regs->dtxfsiz[i]);
  55445. +
  55446. + txfifosize[i].b.depth = params->dev_tx_fifo_size[i];
  55447. + txfifosize[i].b.startaddr = start_address;
  55448. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  55449. + txfifosize[i].d32);
  55450. +
  55451. + start_address += txfifosize[i].b.depth;
  55452. + }
  55453. +
  55454. + /** Check if register values are set correctly */
  55455. + if (rx_fifo_size != DWC_READ_REG32(&global_regs->grxfsiz)) {
  55456. + retval = 0;
  55457. + }
  55458. +
  55459. + if (nptxfifosize.d32 != DWC_READ_REG32(&global_regs->gnptxfsiz)) {
  55460. + retval = 0;
  55461. + }
  55462. +
  55463. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55464. + if (txfifosize[i].d32 !=
  55465. + DWC_READ_REG32(&global_regs->dtxfsiz[i])) {
  55466. + retval = 0;
  55467. + }
  55468. + }
  55469. +
  55470. + /** If register values are not set correctly, reset old values */
  55471. + if (retval == 0) {
  55472. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fsz_bak);
  55473. +
  55474. + /* Non-periodic Tx FIFO */
  55475. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfsz_bak);
  55476. +
  55477. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55478. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  55479. + txfsz_bak[i]);
  55480. + }
  55481. + }
  55482. + } else {
  55483. + return 0;
  55484. + }
  55485. +
  55486. + /* Flush the FIFOs */
  55487. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  55488. + dwc_otg_flush_rx_fifo(core_if);
  55489. +
  55490. + return retval;
  55491. +}
  55492. +
  55493. +/**
  55494. + * This function sets a new value for the buffer Alignment setup.
  55495. + */
  55496. +static int cfi_ep_set_tx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  55497. +{
  55498. + int retval;
  55499. + uint32_t fsiz;
  55500. + uint16_t size;
  55501. + uint16_t ep_addr;
  55502. + dwc_otg_pcd_ep_t *ep;
  55503. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  55504. + tx_fifo_size_setup_t *ptxfifoval;
  55505. +
  55506. + ptxfifoval = (tx_fifo_size_setup_t *) buf;
  55507. + ep_addr = ptxfifoval->bEndpointAddress;
  55508. + size = ptxfifoval->wDepth;
  55509. +
  55510. + ep = get_ep_by_addr(pcd, ep_addr);
  55511. +
  55512. + CFI_INFO
  55513. + ("%s: Set Tx FIFO size: endpoint addr=0x%02x, depth=%d, FIFO Num=%d\n",
  55514. + __func__, ep_addr, size, ep->dwc_ep.tx_fifo_num);
  55515. +
  55516. + if (NULL == ep) {
  55517. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55518. + __func__, ep_addr);
  55519. + return -DWC_E_INVALID;
  55520. + }
  55521. +
  55522. + fsiz = params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1];
  55523. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = size;
  55524. +
  55525. + if (resize_fifos(GET_CORE_IF(pcd))) {
  55526. + retval = 0;
  55527. + } else {
  55528. + CFI_INFO
  55529. + ("%s: Error setting the feature Tx FIFO Size for EP%d\n",
  55530. + __func__, ep_addr);
  55531. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = fsiz;
  55532. + retval = -DWC_E_INVALID;
  55533. + }
  55534. +
  55535. + return retval;
  55536. +}
  55537. +
  55538. +/**
  55539. + * This function sets a new value for the buffer Alignment setup.
  55540. + */
  55541. +static int cfi_set_rx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  55542. +{
  55543. + int retval;
  55544. + uint32_t fsiz;
  55545. + uint16_t size;
  55546. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  55547. + rx_fifo_size_setup_t *prxfifoval;
  55548. +
  55549. + prxfifoval = (rx_fifo_size_setup_t *) buf;
  55550. + size = prxfifoval->wDepth;
  55551. +
  55552. + fsiz = params->dev_rx_fifo_size;
  55553. + params->dev_rx_fifo_size = size;
  55554. +
  55555. + if (resize_fifos(GET_CORE_IF(pcd))) {
  55556. + retval = 0;
  55557. + } else {
  55558. + CFI_INFO("%s: Error setting the feature Rx FIFO Size\n",
  55559. + __func__);
  55560. + params->dev_rx_fifo_size = fsiz;
  55561. + retval = -DWC_E_INVALID;
  55562. + }
  55563. +
  55564. + return retval;
  55565. +}
  55566. +
  55567. +/**
  55568. + * This function reads the SG of an EP's buffer setup into the buffer buf
  55569. + */
  55570. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  55571. + struct cfi_usb_ctrlrequest *req)
  55572. +{
  55573. + int retval = -DWC_E_INVALID;
  55574. + uint8_t addr;
  55575. + cfi_ep_t *ep;
  55576. +
  55577. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  55578. + addr = req->wValue & 0xFF;
  55579. + if (addr == 0) /* The address should be non-zero */
  55580. + return retval;
  55581. +
  55582. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55583. + if (NULL == ep) {
  55584. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  55585. + __func__, addr);
  55586. + return retval;
  55587. + }
  55588. +
  55589. + dwc_memcpy(buf, ep->bm_sg, BS_SG_VAL_DESC_LEN);
  55590. + retval = BS_SG_VAL_DESC_LEN;
  55591. + return retval;
  55592. +}
  55593. +
  55594. +/**
  55595. + * This function reads the Concatenation value of an EP's buffer mode into
  55596. + * the buffer buf
  55597. + */
  55598. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  55599. + struct cfi_usb_ctrlrequest *req)
  55600. +{
  55601. + int retval = -DWC_E_INVALID;
  55602. + uint8_t addr;
  55603. + cfi_ep_t *ep;
  55604. + uint8_t desc_count;
  55605. +
  55606. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  55607. + addr = req->wValue & 0xFF;
  55608. + if (addr == 0) /* The address should be non-zero */
  55609. + return retval;
  55610. +
  55611. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55612. + if (NULL == ep) {
  55613. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  55614. + __func__, addr);
  55615. + return retval;
  55616. + }
  55617. +
  55618. + /* Copy the header to the buffer */
  55619. + dwc_memcpy(buf, ep->bm_concat, BS_CONCAT_VAL_HDR_LEN);
  55620. + /* Advance the buffer pointer by the header size */
  55621. + buf += BS_CONCAT_VAL_HDR_LEN;
  55622. +
  55623. + desc_count = ep->bm_concat->hdr.bDescCount;
  55624. + /* Copy alll the wTxBytes to the buffer */
  55625. + dwc_memcpy(buf, ep->bm_concat->wTxBytes, sizeof(uid16_t) * desc_count);
  55626. +
  55627. + retval = BS_CONCAT_VAL_HDR_LEN + sizeof(uid16_t) * desc_count;
  55628. + return retval;
  55629. +}
  55630. +
  55631. +/**
  55632. + * This function reads the buffer Alignment value of an EP's buffer mode into
  55633. + * the buffer buf
  55634. + *
  55635. + * @return The total number of bytes copied to the buffer or negative error code.
  55636. + */
  55637. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  55638. + struct cfi_usb_ctrlrequest *req)
  55639. +{
  55640. + int retval = -DWC_E_INVALID;
  55641. + uint8_t addr;
  55642. + cfi_ep_t *ep;
  55643. +
  55644. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  55645. + addr = req->wValue & 0xFF;
  55646. + if (addr == 0) /* The address should be non-zero */
  55647. + return retval;
  55648. +
  55649. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55650. + if (NULL == ep) {
  55651. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  55652. + __func__, addr);
  55653. + return retval;
  55654. + }
  55655. +
  55656. + dwc_memcpy(buf, ep->bm_align, BS_ALIGN_VAL_HDR_LEN);
  55657. + retval = BS_ALIGN_VAL_HDR_LEN;
  55658. +
  55659. + return retval;
  55660. +}
  55661. +
  55662. +/**
  55663. + * This function sets a new value for the specified feature
  55664. + *
  55665. + * @param pcd A pointer to the PCD object
  55666. + *
  55667. + * @return 0 if successful, negative error code otherwise to stall the DCE.
  55668. + */
  55669. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd)
  55670. +{
  55671. + int retval = -DWC_E_NOT_SUPPORTED;
  55672. + uint16_t wIndex, wValue;
  55673. + uint8_t bRequest;
  55674. + struct dwc_otg_core_if *coreif;
  55675. + cfiobject_t *cfi = pcd->cfi;
  55676. + struct cfi_usb_ctrlrequest *ctrl_req;
  55677. + uint8_t *buf;
  55678. + ctrl_req = &cfi->ctrl_req;
  55679. +
  55680. + buf = pcd->cfi->ctrl_req.data;
  55681. +
  55682. + coreif = GET_CORE_IF(pcd);
  55683. + bRequest = ctrl_req->bRequest;
  55684. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  55685. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  55686. +
  55687. + /* See which feature is to be modified */
  55688. + switch (wIndex) {
  55689. + case FT_ID_DMA_BUFFER_SETUP:
  55690. + /* Modify the feature */
  55691. + if ((retval = cfi_ep_set_sg_val(buf, pcd)) < 0)
  55692. + return retval;
  55693. +
  55694. + /* And send this request to the gadget */
  55695. + cfi->need_gadget_att = 1;
  55696. + break;
  55697. +
  55698. + case FT_ID_DMA_BUFF_ALIGN:
  55699. + if ((retval = cfi_ep_set_alignment_val(buf, pcd)) < 0)
  55700. + return retval;
  55701. + cfi->need_gadget_att = 1;
  55702. + break;
  55703. +
  55704. + case FT_ID_DMA_CONCAT_SETUP:
  55705. + /* Modify the feature */
  55706. + if ((retval = cfi_ep_set_concat_val(buf, pcd)) < 0)
  55707. + return retval;
  55708. + cfi->need_gadget_att = 1;
  55709. + break;
  55710. +
  55711. + case FT_ID_DMA_CIRCULAR:
  55712. + CFI_INFO("FT_ID_DMA_CIRCULAR\n");
  55713. + break;
  55714. +
  55715. + case FT_ID_THRESHOLD_SETUP:
  55716. + CFI_INFO("FT_ID_THRESHOLD_SETUP\n");
  55717. + break;
  55718. +
  55719. + case FT_ID_DFIFO_DEPTH:
  55720. + CFI_INFO("FT_ID_DFIFO_DEPTH\n");
  55721. + break;
  55722. +
  55723. + case FT_ID_TX_FIFO_DEPTH:
  55724. + CFI_INFO("FT_ID_TX_FIFO_DEPTH\n");
  55725. + if ((retval = cfi_ep_set_tx_fifo_val(buf, pcd)) < 0)
  55726. + return retval;
  55727. + cfi->need_gadget_att = 0;
  55728. + break;
  55729. +
  55730. + case FT_ID_RX_FIFO_DEPTH:
  55731. + CFI_INFO("FT_ID_RX_FIFO_DEPTH\n");
  55732. + if ((retval = cfi_set_rx_fifo_val(buf, pcd)) < 0)
  55733. + return retval;
  55734. + cfi->need_gadget_att = 0;
  55735. + break;
  55736. + }
  55737. +
  55738. + return retval;
  55739. +}
  55740. +
  55741. +#endif //DWC_UTE_CFI
  55742. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_cfi.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h
  55743. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 1970-01-01 01:00:00.000000000 +0100
  55744. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 2014-04-24 16:04:39.815124215 +0200
  55745. @@ -0,0 +1,320 @@
  55746. +/* ==========================================================================
  55747. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  55748. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  55749. + * otherwise expressly agreed to in writing between Synopsys and you.
  55750. + *
  55751. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  55752. + * any End User Software License Agreement or Agreement for Licensed Product
  55753. + * with Synopsys or any supplement thereto. You are permitted to use and
  55754. + * redistribute this Software in source and binary forms, with or without
  55755. + * modification, provided that redistributions of source code must retain this
  55756. + * notice. You may not view, use, disclose, copy or distribute this file or
  55757. + * any information contained herein except pursuant to this license grant from
  55758. + * Synopsys. If you do not agree with this notice, including the disclaimer
  55759. + * below, then you are not authorized to use the Software.
  55760. + *
  55761. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  55762. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  55763. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  55764. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  55765. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  55766. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  55767. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  55768. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  55769. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  55770. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  55771. + * DAMAGE.
  55772. + * ========================================================================== */
  55773. +
  55774. +#if !defined(__DWC_OTG_CFI_H__)
  55775. +#define __DWC_OTG_CFI_H__
  55776. +
  55777. +#include "dwc_otg_pcd.h"
  55778. +#include "dwc_cfi_common.h"
  55779. +
  55780. +/**
  55781. + * @file
  55782. + * This file contains the CFI related OTG PCD specific common constants,
  55783. + * interfaces(functions and macros) and data structures.The CFI Protocol is an
  55784. + * optional interface for internal testing purposes that a DUT may implement to
  55785. + * support testing of configurable features.
  55786. + *
  55787. + */
  55788. +
  55789. +struct dwc_otg_pcd;
  55790. +struct dwc_otg_pcd_ep;
  55791. +
  55792. +/** OTG CFI Features (properties) ID constants */
  55793. +/** This is a request for all Core Features */
  55794. +#define FT_ID_DMA_MODE 0x0001
  55795. +#define FT_ID_DMA_BUFFER_SETUP 0x0002
  55796. +#define FT_ID_DMA_BUFF_ALIGN 0x0003
  55797. +#define FT_ID_DMA_CONCAT_SETUP 0x0004
  55798. +#define FT_ID_DMA_CIRCULAR 0x0005
  55799. +#define FT_ID_THRESHOLD_SETUP 0x0006
  55800. +#define FT_ID_DFIFO_DEPTH 0x0007
  55801. +#define FT_ID_TX_FIFO_DEPTH 0x0008
  55802. +#define FT_ID_RX_FIFO_DEPTH 0x0009
  55803. +
  55804. +/**********************************************************/
  55805. +#define CFI_INFO_DEF
  55806. +
  55807. +#ifdef CFI_INFO_DEF
  55808. +#define CFI_INFO(fmt...) DWC_PRINTF("CFI: " fmt);
  55809. +#else
  55810. +#define CFI_INFO(fmt...)
  55811. +#endif
  55812. +
  55813. +#define min(x,y) ({ \
  55814. + x < y ? x : y; })
  55815. +
  55816. +#define max(x,y) ({ \
  55817. + x > y ? x : y; })
  55818. +
  55819. +/**
  55820. + * Descriptor DMA SG Buffer setup structure (SG buffer). This structure is
  55821. + * also used for setting up a buffer for Circular DDMA.
  55822. + */
  55823. +struct _ddma_sg_buffer_setup {
  55824. +#define BS_SG_VAL_DESC_LEN 6
  55825. + /* The OUT EP address */
  55826. + uint8_t bOutEndpointAddress;
  55827. + /* The IN EP address */
  55828. + uint8_t bInEndpointAddress;
  55829. + /* Number of bytes to put between transfer segments (must be DWORD boundaries) */
  55830. + uint8_t bOffset;
  55831. + /* The number of transfer segments (a DMA descriptors per each segment) */
  55832. + uint8_t bCount;
  55833. + /* Size (in byte) of each transfer segment */
  55834. + uint16_t wSize;
  55835. +} __attribute__ ((packed));
  55836. +typedef struct _ddma_sg_buffer_setup ddma_sg_buffer_setup_t;
  55837. +
  55838. +/** Descriptor DMA Concatenation Buffer setup structure */
  55839. +struct _ddma_concat_buffer_setup_hdr {
  55840. +#define BS_CONCAT_VAL_HDR_LEN 4
  55841. + /* The endpoint for which the buffer is to be set up */
  55842. + uint8_t bEndpointAddress;
  55843. + /* The count of descriptors to be used */
  55844. + uint8_t bDescCount;
  55845. + /* The total size of the transfer */
  55846. + uint16_t wSize;
  55847. +} __attribute__ ((packed));
  55848. +typedef struct _ddma_concat_buffer_setup_hdr ddma_concat_buffer_setup_hdr_t;
  55849. +
  55850. +/** Descriptor DMA Concatenation Buffer setup structure */
  55851. +struct _ddma_concat_buffer_setup {
  55852. + /* The SG header */
  55853. + ddma_concat_buffer_setup_hdr_t hdr;
  55854. +
  55855. + /* The XFER sizes pointer (allocated dynamically) */
  55856. + uint16_t *wTxBytes;
  55857. +} __attribute__ ((packed));
  55858. +typedef struct _ddma_concat_buffer_setup ddma_concat_buffer_setup_t;
  55859. +
  55860. +/** Descriptor DMA Alignment Buffer setup structure */
  55861. +struct _ddma_align_buffer_setup {
  55862. +#define BS_ALIGN_VAL_HDR_LEN 2
  55863. + uint8_t bEndpointAddress;
  55864. + uint8_t bAlign;
  55865. +} __attribute__ ((packed));
  55866. +typedef struct _ddma_align_buffer_setup ddma_align_buffer_setup_t;
  55867. +
  55868. +/** Transmit FIFO Size setup structure */
  55869. +struct _tx_fifo_size_setup {
  55870. + uint8_t bEndpointAddress;
  55871. + uint16_t wDepth;
  55872. +} __attribute__ ((packed));
  55873. +typedef struct _tx_fifo_size_setup tx_fifo_size_setup_t;
  55874. +
  55875. +/** Transmit FIFO Size setup structure */
  55876. +struct _rx_fifo_size_setup {
  55877. + uint16_t wDepth;
  55878. +} __attribute__ ((packed));
  55879. +typedef struct _rx_fifo_size_setup rx_fifo_size_setup_t;
  55880. +
  55881. +/**
  55882. + * struct cfi_usb_ctrlrequest - the CFI implementation of the struct usb_ctrlrequest
  55883. + * This structure encapsulates the standard usb_ctrlrequest and adds a pointer
  55884. + * to the data returned in the data stage of a 3-stage Control Write requests.
  55885. + */
  55886. +struct cfi_usb_ctrlrequest {
  55887. + uint8_t bRequestType;
  55888. + uint8_t bRequest;
  55889. + uint16_t wValue;
  55890. + uint16_t wIndex;
  55891. + uint16_t wLength;
  55892. + uint8_t *data;
  55893. +} UPACKED;
  55894. +
  55895. +/*---------------------------------------------------------------------------*/
  55896. +
  55897. +/**
  55898. + * The CFI wrapper of the enabled and activated dwc_otg_pcd_ep structures.
  55899. + * This structure is used to store the buffer setup data for any
  55900. + * enabled endpoint in the PCD.
  55901. + */
  55902. +struct cfi_ep {
  55903. + /* Entry for the list container */
  55904. + dwc_list_link_t lh;
  55905. + /* Pointer to the active PCD endpoint structure */
  55906. + struct dwc_otg_pcd_ep *ep;
  55907. + /* The last descriptor in the chain of DMA descriptors of the endpoint */
  55908. + struct dwc_otg_dma_desc *dma_desc_last;
  55909. + /* The SG feature value */
  55910. + ddma_sg_buffer_setup_t *bm_sg;
  55911. + /* The Circular feature value */
  55912. + ddma_sg_buffer_setup_t *bm_circ;
  55913. + /* The Concatenation feature value */
  55914. + ddma_concat_buffer_setup_t *bm_concat;
  55915. + /* The Alignment feature value */
  55916. + ddma_align_buffer_setup_t *bm_align;
  55917. + /* XFER length */
  55918. + uint32_t xfer_len;
  55919. + /*
  55920. + * Count of DMA descriptors currently used.
  55921. + * The total should not exceed the MAX_DMA_DESCS_PER_EP value
  55922. + * defined in the dwc_otg_cil.h
  55923. + */
  55924. + uint32_t desc_count;
  55925. +};
  55926. +typedef struct cfi_ep cfi_ep_t;
  55927. +
  55928. +typedef struct cfi_dma_buff {
  55929. +#define CFI_IN_BUF_LEN 1024
  55930. +#define CFI_OUT_BUF_LEN 1024
  55931. + dma_addr_t addr;
  55932. + uint8_t *buf;
  55933. +} cfi_dma_buff_t;
  55934. +
  55935. +struct cfiobject;
  55936. +
  55937. +/**
  55938. + * This is the interface for the CFI operations.
  55939. + *
  55940. + * @param ep_enable Called when any endpoint is enabled and activated.
  55941. + * @param release Called when the CFI object is released and it needs to correctly
  55942. + * deallocate the dynamic memory
  55943. + * @param ctrl_write_complete Called when the data stage of the request is complete
  55944. + */
  55945. +typedef struct cfi_ops {
  55946. + int (*ep_enable) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  55947. + struct dwc_otg_pcd_ep * ep);
  55948. + void *(*ep_alloc_buf) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  55949. + struct dwc_otg_pcd_ep * ep, dma_addr_t * dma,
  55950. + unsigned size, gfp_t flags);
  55951. + void (*release) (struct cfiobject * cfi);
  55952. + int (*ctrl_write_complete) (struct cfiobject * cfi,
  55953. + struct dwc_otg_pcd * pcd);
  55954. + void (*build_descriptors) (struct cfiobject * cfi,
  55955. + struct dwc_otg_pcd * pcd,
  55956. + struct dwc_otg_pcd_ep * ep,
  55957. + dwc_otg_pcd_request_t * req);
  55958. +} cfi_ops_t;
  55959. +
  55960. +struct cfiobject {
  55961. + cfi_ops_t ops;
  55962. + struct dwc_otg_pcd *pcd;
  55963. + struct usb_gadget *gadget;
  55964. +
  55965. + /* Buffers used to send/receive CFI-related request data */
  55966. + cfi_dma_buff_t buf_in;
  55967. + cfi_dma_buff_t buf_out;
  55968. +
  55969. + /* CFI specific Control request wrapper */
  55970. + struct cfi_usb_ctrlrequest ctrl_req;
  55971. +
  55972. + /* The list of active EP's in the PCD of type cfi_ep_t */
  55973. + dwc_list_link_t active_eps;
  55974. +
  55975. + /* This flag shall control the propagation of a specific request
  55976. + * to the gadget's processing routines.
  55977. + * 0 - no gadget handling
  55978. + * 1 - the gadget needs to know about this request (w/o completing a status
  55979. + * phase - just return a 0 to the _setup callback)
  55980. + */
  55981. + uint8_t need_gadget_att;
  55982. +
  55983. + /* Flag indicating whether the status IN phase needs to be
  55984. + * completed by the PCD
  55985. + */
  55986. + uint8_t need_status_in_complete;
  55987. +};
  55988. +typedef struct cfiobject cfiobject_t;
  55989. +
  55990. +#define DUMP_MSG
  55991. +
  55992. +#if defined(DUMP_MSG)
  55993. +static inline void dump_msg(const u8 * buf, unsigned int length)
  55994. +{
  55995. + unsigned int start, num, i;
  55996. + char line[52], *p;
  55997. +
  55998. + if (length >= 512)
  55999. + return;
  56000. +
  56001. + start = 0;
  56002. + while (length > 0) {
  56003. + num = min(length, 16u);
  56004. + p = line;
  56005. + for (i = 0; i < num; ++i) {
  56006. + if (i == 8)
  56007. + *p++ = ' ';
  56008. + DWC_SPRINTF(p, " %02x", buf[i]);
  56009. + p += 3;
  56010. + }
  56011. + *p = 0;
  56012. + DWC_DEBUG("%6x: %s\n", start, line);
  56013. + buf += num;
  56014. + start += num;
  56015. + length -= num;
  56016. + }
  56017. +}
  56018. +#else
  56019. +static inline void dump_msg(const u8 * buf, unsigned int length)
  56020. +{
  56021. +}
  56022. +#endif
  56023. +
  56024. +/**
  56025. + * This function returns a pointer to cfi_ep_t object with the addr address.
  56026. + */
  56027. +static inline struct cfi_ep *get_cfi_ep_by_addr(struct cfiobject *cfi,
  56028. + uint8_t addr)
  56029. +{
  56030. + struct cfi_ep *pcfiep;
  56031. + dwc_list_link_t *tmp;
  56032. +
  56033. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  56034. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  56035. +
  56036. + if (pcfiep->ep->desc->bEndpointAddress == addr) {
  56037. + return pcfiep;
  56038. + }
  56039. + }
  56040. +
  56041. + return NULL;
  56042. +}
  56043. +
  56044. +/**
  56045. + * This function returns a pointer to cfi_ep_t object that matches
  56046. + * the dwc_otg_pcd_ep object.
  56047. + */
  56048. +static inline struct cfi_ep *get_cfi_ep_by_pcd_ep(struct cfiobject *cfi,
  56049. + struct dwc_otg_pcd_ep *ep)
  56050. +{
  56051. + struct cfi_ep *pcfiep = NULL;
  56052. + dwc_list_link_t *tmp;
  56053. +
  56054. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  56055. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  56056. + if (pcfiep->ep == ep) {
  56057. + return pcfiep;
  56058. + }
  56059. + }
  56060. + return NULL;
  56061. +}
  56062. +
  56063. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl);
  56064. +
  56065. +#endif /* (__DWC_OTG_CFI_H__) */
  56066. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_cil.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c
  56067. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_cil.c 1970-01-01 01:00:00.000000000 +0100
  56068. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c 2014-04-24 16:04:39.815124215 +0200
  56069. @@ -0,0 +1,7151 @@
  56070. +/* ==========================================================================
  56071. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  56072. + * $Revision: #191 $
  56073. + * $Date: 2012/08/10 $
  56074. + * $Change: 2047372 $
  56075. + *
  56076. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  56077. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  56078. + * otherwise expressly agreed to in writing between Synopsys and you.
  56079. + *
  56080. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  56081. + * any End User Software License Agreement or Agreement for Licensed Product
  56082. + * with Synopsys or any supplement thereto. You are permitted to use and
  56083. + * redistribute this Software in source and binary forms, with or without
  56084. + * modification, provided that redistributions of source code must retain this
  56085. + * notice. You may not view, use, disclose, copy or distribute this file or
  56086. + * any information contained herein except pursuant to this license grant from
  56087. + * Synopsys. If you do not agree with this notice, including the disclaimer
  56088. + * below, then you are not authorized to use the Software.
  56089. + *
  56090. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  56091. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  56092. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  56093. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  56094. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  56095. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  56096. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  56097. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  56098. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  56099. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  56100. + * DAMAGE.
  56101. + * ========================================================================== */
  56102. +
  56103. +/** @file
  56104. + *
  56105. + * The Core Interface Layer provides basic services for accessing and
  56106. + * managing the DWC_otg hardware. These services are used by both the
  56107. + * Host Controller Driver and the Peripheral Controller Driver.
  56108. + *
  56109. + * The CIL manages the memory map for the core so that the HCD and PCD
  56110. + * don't have to do this separately. It also handles basic tasks like
  56111. + * reading/writing the registers and data FIFOs in the controller.
  56112. + * Some of the data access functions provide encapsulation of several
  56113. + * operations required to perform a task, such as writing multiple
  56114. + * registers to start a transfer. Finally, the CIL performs basic
  56115. + * services that are not specific to either the host or device modes
  56116. + * of operation. These services include management of the OTG Host
  56117. + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  56118. + * Diagnostic API is also provided to allow testing of the controller
  56119. + * hardware.
  56120. + *
  56121. + * The Core Interface Layer has the following requirements:
  56122. + * - Provides basic controller operations.
  56123. + * - Minimal use of OS services.
  56124. + * - The OS services used will be abstracted by using inline functions
  56125. + * or macros.
  56126. + *
  56127. + */
  56128. +
  56129. +#include "dwc_os.h"
  56130. +#include "dwc_otg_regs.h"
  56131. +#include "dwc_otg_cil.h"
  56132. +
  56133. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  56134. +
  56135. +/**
  56136. + * This function is called to initialize the DWC_otg CSR data
  56137. + * structures. The register addresses in the device and host
  56138. + * structures are initialized from the base address supplied by the
  56139. + * caller. The calling function must make the OS calls to get the
  56140. + * base address of the DWC_otg controller registers. The core_params
  56141. + * argument holds the parameters that specify how the core should be
  56142. + * configured.
  56143. + *
  56144. + * @param reg_base_addr Base address of DWC_otg core registers
  56145. + *
  56146. + */
  56147. +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  56148. +{
  56149. + dwc_otg_core_if_t *core_if = 0;
  56150. + dwc_otg_dev_if_t *dev_if = 0;
  56151. + dwc_otg_host_if_t *host_if = 0;
  56152. + uint8_t *reg_base = (uint8_t *) reg_base_addr;
  56153. + int i = 0;
  56154. +
  56155. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  56156. +
  56157. + core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  56158. +
  56159. + if (core_if == NULL) {
  56160. + DWC_DEBUGPL(DBG_CIL,
  56161. + "Allocation of dwc_otg_core_if_t failed\n");
  56162. + return 0;
  56163. + }
  56164. + core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  56165. +
  56166. + /*
  56167. + * Allocate the Device Mode structures.
  56168. + */
  56169. + dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  56170. +
  56171. + if (dev_if == NULL) {
  56172. + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  56173. + DWC_FREE(core_if);
  56174. + return 0;
  56175. + }
  56176. +
  56177. + dev_if->dev_global_regs =
  56178. + (dwc_otg_device_global_regs_t *) (reg_base +
  56179. + DWC_DEV_GLOBAL_REG_OFFSET);
  56180. +
  56181. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56182. + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  56183. + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  56184. + (i * DWC_EP_REG_OFFSET));
  56185. +
  56186. + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  56187. + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  56188. + (i * DWC_EP_REG_OFFSET));
  56189. + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  56190. + i, &dev_if->in_ep_regs[i]->diepctl);
  56191. + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  56192. + i, &dev_if->out_ep_regs[i]->doepctl);
  56193. + }
  56194. +
  56195. + dev_if->speed = 0; // unknown
  56196. +
  56197. + core_if->dev_if = dev_if;
  56198. +
  56199. + /*
  56200. + * Allocate the Host Mode structures.
  56201. + */
  56202. + host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  56203. +
  56204. + if (host_if == NULL) {
  56205. + DWC_DEBUGPL(DBG_CIL,
  56206. + "Allocation of dwc_otg_host_if_t failed\n");
  56207. + DWC_FREE(dev_if);
  56208. + DWC_FREE(core_if);
  56209. + return 0;
  56210. + }
  56211. +
  56212. + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  56213. + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  56214. +
  56215. + host_if->hprt0 =
  56216. + (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  56217. +
  56218. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56219. + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  56220. + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  56221. + (i * DWC_OTG_CHAN_REGS_OFFSET));
  56222. + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  56223. + i, &host_if->hc_regs[i]->hcchar);
  56224. + }
  56225. +
  56226. + host_if->num_host_channels = MAX_EPS_CHANNELS;
  56227. + core_if->host_if = host_if;
  56228. +
  56229. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56230. + core_if->data_fifo[i] =
  56231. + (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  56232. + (i * DWC_OTG_DATA_FIFO_SIZE));
  56233. + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  56234. + i, (unsigned long)core_if->data_fifo[i]);
  56235. + }
  56236. +
  56237. + core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  56238. +
  56239. + /* Initiate lx_state to L3 disconnected state */
  56240. + core_if->lx_state = DWC_OTG_L3;
  56241. + /*
  56242. + * Store the contents of the hardware configuration registers here for
  56243. + * easy access later.
  56244. + */
  56245. + core_if->hwcfg1.d32 =
  56246. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  56247. + core_if->hwcfg2.d32 =
  56248. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  56249. + core_if->hwcfg3.d32 =
  56250. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  56251. + core_if->hwcfg4.d32 =
  56252. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  56253. +
  56254. + /* Force host mode to get HPTXFSIZ exact power on value */
  56255. + {
  56256. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56257. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  56258. + gusbcfg.b.force_host_mode = 1;
  56259. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56260. + dwc_mdelay(100);
  56261. + core_if->hptxfsiz.d32 =
  56262. + DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  56263. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  56264. + gusbcfg.b.force_host_mode = 0;
  56265. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56266. + dwc_mdelay(100);
  56267. + }
  56268. +
  56269. + DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  56270. + DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  56271. + DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  56272. + DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  56273. +
  56274. + core_if->hcfg.d32 =
  56275. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  56276. + core_if->dcfg.d32 =
  56277. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  56278. +
  56279. + DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  56280. + DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  56281. +
  56282. + DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  56283. + DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  56284. + DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  56285. + DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  56286. + core_if->hwcfg2.b.num_host_chan);
  56287. + DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  56288. + core_if->hwcfg2.b.nonperio_tx_q_depth);
  56289. + DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  56290. + core_if->hwcfg2.b.host_perio_tx_q_depth);
  56291. + DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  56292. + core_if->hwcfg2.b.dev_token_q_depth);
  56293. +
  56294. + DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  56295. + core_if->hwcfg3.b.dfifo_depth);
  56296. + DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  56297. + core_if->hwcfg3.b.xfer_size_cntr_width);
  56298. +
  56299. + /*
  56300. + * Set the SRP sucess bit for FS-I2c
  56301. + */
  56302. + core_if->srp_success = 0;
  56303. + core_if->srp_timer_started = 0;
  56304. +
  56305. + /*
  56306. + * Create new workqueue and init works
  56307. + */
  56308. + core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  56309. + if (core_if->wq_otg == 0) {
  56310. + DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  56311. + DWC_FREE(host_if);
  56312. + DWC_FREE(dev_if);
  56313. + DWC_FREE(core_if);
  56314. + return 0;
  56315. + }
  56316. +
  56317. + core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  56318. +
  56319. + DWC_PRINTF("Core Release: %x.%x%x%x\n",
  56320. + (core_if->snpsid >> 12 & 0xF),
  56321. + (core_if->snpsid >> 8 & 0xF),
  56322. + (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  56323. +
  56324. + core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  56325. + w_wakeup_detected, core_if);
  56326. + if (core_if->wkp_timer == 0) {
  56327. + DWC_WARN("DWC_TIMER_ALLOC failed\n");
  56328. + DWC_FREE(host_if);
  56329. + DWC_FREE(dev_if);
  56330. + DWC_WORKQ_FREE(core_if->wq_otg);
  56331. + DWC_FREE(core_if);
  56332. + return 0;
  56333. + }
  56334. +
  56335. + if (dwc_otg_setup_params(core_if)) {
  56336. + DWC_WARN("Error while setting core params\n");
  56337. + }
  56338. +
  56339. + core_if->hibernation_suspend = 0;
  56340. +
  56341. + /** ADP initialization */
  56342. + dwc_otg_adp_init(core_if);
  56343. +
  56344. + return core_if;
  56345. +}
  56346. +
  56347. +/**
  56348. + * This function frees the structures allocated by dwc_otg_cil_init().
  56349. + *
  56350. + * @param core_if The core interface pointer returned from
  56351. + * dwc_otg_cil_init().
  56352. + *
  56353. + */
  56354. +void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  56355. +{
  56356. + dctl_data_t dctl = {.d32 = 0 };
  56357. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  56358. +
  56359. + /* Disable all interrupts */
  56360. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  56361. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  56362. +
  56363. + dctl.b.sftdiscon = 1;
  56364. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  56365. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0,
  56366. + dctl.d32);
  56367. + }
  56368. +
  56369. + if (core_if->wq_otg) {
  56370. + DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  56371. + DWC_WORKQ_FREE(core_if->wq_otg);
  56372. + }
  56373. + if (core_if->dev_if) {
  56374. + DWC_FREE(core_if->dev_if);
  56375. + }
  56376. + if (core_if->host_if) {
  56377. + DWC_FREE(core_if->host_if);
  56378. + }
  56379. +
  56380. + /** Remove ADP Stuff */
  56381. + dwc_otg_adp_remove(core_if);
  56382. + if (core_if->core_params) {
  56383. + DWC_FREE(core_if->core_params);
  56384. + }
  56385. + if (core_if->wkp_timer) {
  56386. + DWC_TIMER_FREE(core_if->wkp_timer);
  56387. + }
  56388. + if (core_if->srp_timer) {
  56389. + DWC_TIMER_FREE(core_if->srp_timer);
  56390. + }
  56391. + DWC_FREE(core_if);
  56392. +}
  56393. +
  56394. +/**
  56395. + * This function enables the controller's Global Interrupt in the AHB Config
  56396. + * register.
  56397. + *
  56398. + * @param core_if Programming view of DWC_otg controller.
  56399. + */
  56400. +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  56401. +{
  56402. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  56403. + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  56404. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  56405. +}
  56406. +
  56407. +/**
  56408. + * This function disables the controller's Global Interrupt in the AHB Config
  56409. + * register.
  56410. + *
  56411. + * @param core_if Programming view of DWC_otg controller.
  56412. + */
  56413. +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  56414. +{
  56415. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  56416. + ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  56417. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  56418. +}
  56419. +
  56420. +/**
  56421. + * This function initializes the commmon interrupts, used in both
  56422. + * device and host modes.
  56423. + *
  56424. + * @param core_if Programming view of the DWC_otg controller
  56425. + *
  56426. + */
  56427. +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  56428. +{
  56429. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56430. + gintmsk_data_t intr_mask = {.d32 = 0 };
  56431. +
  56432. + /* Clear any pending OTG Interrupts */
  56433. + DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  56434. +
  56435. + /* Clear any pending interrupts */
  56436. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  56437. +
  56438. + /*
  56439. + * Enable the interrupts in the GINTMSK.
  56440. + */
  56441. + intr_mask.b.modemismatch = 1;
  56442. + intr_mask.b.otgintr = 1;
  56443. +
  56444. + if (!core_if->dma_enable) {
  56445. + intr_mask.b.rxstsqlvl = 1;
  56446. + }
  56447. +
  56448. + intr_mask.b.conidstschng = 1;
  56449. + intr_mask.b.wkupintr = 1;
  56450. + intr_mask.b.disconnect = 0;
  56451. + intr_mask.b.usbsuspend = 1;
  56452. + intr_mask.b.sessreqintr = 1;
  56453. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56454. + if (core_if->core_params->lpm_enable) {
  56455. + intr_mask.b.lpmtranrcvd = 1;
  56456. + }
  56457. +#endif
  56458. + DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  56459. +}
  56460. +
  56461. +/*
  56462. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  56463. + * Hibernation. This function is for exiting from Device mode hibernation by
  56464. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  56465. + * @param core_if Programming view of DWC_otg controller.
  56466. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  56467. + * @param reset - indicates whether resume is initiated by Reset.
  56468. + */
  56469. +int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  56470. + int rem_wakeup, int reset)
  56471. +{
  56472. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  56473. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  56474. + dctl_data_t dctl = {.d32 = 0 };
  56475. +
  56476. + int timeout = 2000;
  56477. +
  56478. + if (!core_if->hibernation_suspend) {
  56479. + DWC_PRINTF("Already exited from Hibernation\n");
  56480. + return 1;
  56481. + }
  56482. +
  56483. + DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  56484. + /* Switch-on voltage to the core */
  56485. + gpwrdn.b.pwrdnswtch = 1;
  56486. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56487. + dwc_udelay(10);
  56488. +
  56489. + /* Reset core */
  56490. + gpwrdn.d32 = 0;
  56491. + gpwrdn.b.pwrdnrstn = 1;
  56492. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56493. + dwc_udelay(10);
  56494. +
  56495. + /* Assert Restore signal */
  56496. + gpwrdn.d32 = 0;
  56497. + gpwrdn.b.restore = 1;
  56498. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56499. + dwc_udelay(10);
  56500. +
  56501. + /* Disable power clamps */
  56502. + gpwrdn.d32 = 0;
  56503. + gpwrdn.b.pwrdnclmp = 1;
  56504. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56505. +
  56506. + if (rem_wakeup) {
  56507. + dwc_udelay(70);
  56508. + }
  56509. +
  56510. + /* Deassert Reset core */
  56511. + gpwrdn.d32 = 0;
  56512. + gpwrdn.b.pwrdnrstn = 1;
  56513. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56514. + dwc_udelay(10);
  56515. +
  56516. + /* Disable PMU interrupt */
  56517. + gpwrdn.d32 = 0;
  56518. + gpwrdn.b.pmuintsel = 1;
  56519. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56520. +
  56521. + /* Mask interrupts from gpwrdn */
  56522. + gpwrdn.d32 = 0;
  56523. + gpwrdn.b.connect_det_msk = 1;
  56524. + gpwrdn.b.srp_det_msk = 1;
  56525. + gpwrdn.b.disconn_det_msk = 1;
  56526. + gpwrdn.b.rst_det_msk = 1;
  56527. + gpwrdn.b.lnstchng_msk = 1;
  56528. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56529. +
  56530. + /* Indicates that we are going out from hibernation */
  56531. + core_if->hibernation_suspend = 0;
  56532. +
  56533. + /*
  56534. + * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  56535. + * indicates restore from remote_wakeup
  56536. + */
  56537. + restore_essential_regs(core_if, rem_wakeup, 0);
  56538. +
  56539. + /*
  56540. + * Wait a little for seeing new value of variable hibernation_suspend if
  56541. + * Restore done interrupt received before polling
  56542. + */
  56543. + dwc_udelay(10);
  56544. +
  56545. + if (core_if->hibernation_suspend == 0) {
  56546. + /*
  56547. + * Wait For Restore_done Interrupt. This mechanism of polling the
  56548. + * interrupt is introduced to avoid any possible race conditions
  56549. + */
  56550. + do {
  56551. + gintsts_data_t gintsts;
  56552. + gintsts.d32 =
  56553. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  56554. + if (gintsts.b.restoredone) {
  56555. + gintsts.d32 = 0;
  56556. + gintsts.b.restoredone = 1;
  56557. + DWC_WRITE_REG32(&core_if->core_global_regs->
  56558. + gintsts, gintsts.d32);
  56559. + DWC_PRINTF("Restore Done Interrupt seen\n");
  56560. + break;
  56561. + }
  56562. + dwc_udelay(10);
  56563. + } while (--timeout);
  56564. + if (!timeout) {
  56565. + DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  56566. + }
  56567. + }
  56568. + /* Clear all pending interupts */
  56569. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56570. +
  56571. + /* De-assert Restore */
  56572. + gpwrdn.d32 = 0;
  56573. + gpwrdn.b.restore = 1;
  56574. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56575. + dwc_udelay(10);
  56576. +
  56577. + if (!rem_wakeup) {
  56578. + pcgcctl.d32 = 0;
  56579. + pcgcctl.b.rstpdwnmodule = 1;
  56580. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  56581. + }
  56582. +
  56583. + /* Restore GUSBCFG and DCFG */
  56584. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  56585. + core_if->gr_backup->gusbcfg_local);
  56586. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  56587. + core_if->dr_backup->dcfg);
  56588. +
  56589. + /* De-assert Wakeup Logic */
  56590. + gpwrdn.d32 = 0;
  56591. + gpwrdn.b.pmuactv = 1;
  56592. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56593. + dwc_udelay(10);
  56594. +
  56595. + if (!rem_wakeup) {
  56596. + /* Set Device programming done bit */
  56597. + dctl.b.pwronprgdone = 1;
  56598. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56599. + } else {
  56600. + /* Start Remote Wakeup Signaling */
  56601. + dctl.d32 = core_if->dr_backup->dctl;
  56602. + dctl.b.rmtwkupsig = 1;
  56603. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  56604. + }
  56605. +
  56606. + dwc_mdelay(2);
  56607. + /* Clear all pending interupts */
  56608. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56609. +
  56610. + /* Restore global registers */
  56611. + dwc_otg_restore_global_regs(core_if);
  56612. + /* Restore device global registers */
  56613. + dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  56614. +
  56615. + if (rem_wakeup) {
  56616. + dwc_mdelay(7);
  56617. + dctl.d32 = 0;
  56618. + dctl.b.rmtwkupsig = 1;
  56619. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  56620. + }
  56621. +
  56622. + core_if->hibernation_suspend = 0;
  56623. + /* The core will be in ON STATE */
  56624. + core_if->lx_state = DWC_OTG_L0;
  56625. + DWC_PRINTF("Hibernation recovery completes here\n");
  56626. +
  56627. + return 1;
  56628. +}
  56629. +
  56630. +/*
  56631. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  56632. + * Hibernation. This function is for exiting from Host mode hibernation by
  56633. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  56634. + * @param core_if Programming view of DWC_otg controller.
  56635. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  56636. + * @param reset - indicates whether resume is initiated by Reset.
  56637. + */
  56638. +int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  56639. + int rem_wakeup, int reset)
  56640. +{
  56641. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  56642. + hprt0_data_t hprt0 = {.d32 = 0 };
  56643. +
  56644. + int timeout = 2000;
  56645. +
  56646. + DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  56647. + /* Switch-on voltage to the core */
  56648. + gpwrdn.b.pwrdnswtch = 1;
  56649. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56650. + dwc_udelay(10);
  56651. +
  56652. + /* Reset core */
  56653. + gpwrdn.d32 = 0;
  56654. + gpwrdn.b.pwrdnrstn = 1;
  56655. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56656. + dwc_udelay(10);
  56657. +
  56658. + /* Assert Restore signal */
  56659. + gpwrdn.d32 = 0;
  56660. + gpwrdn.b.restore = 1;
  56661. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56662. + dwc_udelay(10);
  56663. +
  56664. + /* Disable power clamps */
  56665. + gpwrdn.d32 = 0;
  56666. + gpwrdn.b.pwrdnclmp = 1;
  56667. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56668. +
  56669. + if (!rem_wakeup) {
  56670. + dwc_udelay(50);
  56671. + }
  56672. +
  56673. + /* Deassert Reset core */
  56674. + gpwrdn.d32 = 0;
  56675. + gpwrdn.b.pwrdnrstn = 1;
  56676. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56677. + dwc_udelay(10);
  56678. +
  56679. + /* Disable PMU interrupt */
  56680. + gpwrdn.d32 = 0;
  56681. + gpwrdn.b.pmuintsel = 1;
  56682. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56683. +
  56684. + gpwrdn.d32 = 0;
  56685. + gpwrdn.b.connect_det_msk = 1;
  56686. + gpwrdn.b.srp_det_msk = 1;
  56687. + gpwrdn.b.disconn_det_msk = 1;
  56688. + gpwrdn.b.rst_det_msk = 1;
  56689. + gpwrdn.b.lnstchng_msk = 1;
  56690. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56691. +
  56692. + /* Indicates that we are going out from hibernation */
  56693. + core_if->hibernation_suspend = 0;
  56694. +
  56695. + /* Set Restore Essential Regs bit in PCGCCTL register */
  56696. + restore_essential_regs(core_if, rem_wakeup, 1);
  56697. +
  56698. + /* Wait a little for seeing new value of variable hibernation_suspend if
  56699. + * Restore done interrupt received before polling */
  56700. + dwc_udelay(10);
  56701. +
  56702. + if (core_if->hibernation_suspend == 0) {
  56703. + /* Wait For Restore_done Interrupt. This mechanism of polling the
  56704. + * interrupt is introduced to avoid any possible race conditions
  56705. + */
  56706. + do {
  56707. + gintsts_data_t gintsts;
  56708. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  56709. + if (gintsts.b.restoredone) {
  56710. + gintsts.d32 = 0;
  56711. + gintsts.b.restoredone = 1;
  56712. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  56713. + DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  56714. + break;
  56715. + }
  56716. + dwc_udelay(10);
  56717. + } while (--timeout);
  56718. + if (!timeout) {
  56719. + DWC_WARN("Restore Done interrupt wasn't generated\n");
  56720. + }
  56721. + }
  56722. +
  56723. + /* Set the flag's value to 0 again after receiving restore done interrupt */
  56724. + core_if->hibernation_suspend = 0;
  56725. +
  56726. + /* This step is not described in functional spec but if not wait for this
  56727. + * delay, mismatch interrupts occurred because just after restore core is
  56728. + * in Device mode(gintsts.curmode == 0) */
  56729. + dwc_mdelay(100);
  56730. +
  56731. + /* Clear all pending interrupts */
  56732. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56733. +
  56734. + /* De-assert Restore */
  56735. + gpwrdn.d32 = 0;
  56736. + gpwrdn.b.restore = 1;
  56737. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56738. + dwc_udelay(10);
  56739. +
  56740. + /* Restore GUSBCFG and HCFG */
  56741. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  56742. + core_if->gr_backup->gusbcfg_local);
  56743. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  56744. + core_if->hr_backup->hcfg_local);
  56745. +
  56746. + /* De-assert Wakeup Logic */
  56747. + gpwrdn.d32 = 0;
  56748. + gpwrdn.b.pmuactv = 1;
  56749. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56750. + dwc_udelay(10);
  56751. +
  56752. + /* Start the Resume operation by programming HPRT0 */
  56753. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  56754. + hprt0.b.prtpwr = 1;
  56755. + hprt0.b.prtena = 0;
  56756. + hprt0.b.prtsusp = 0;
  56757. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56758. +
  56759. + DWC_PRINTF("Resume Starts Now\n");
  56760. + if (!reset) { // Indicates it is Resume Operation
  56761. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  56762. + hprt0.b.prtres = 1;
  56763. + hprt0.b.prtpwr = 1;
  56764. + hprt0.b.prtena = 0;
  56765. + hprt0.b.prtsusp = 0;
  56766. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56767. +
  56768. + if (!rem_wakeup)
  56769. + hprt0.b.prtres = 0;
  56770. + /* Wait for Resume time and then program HPRT again */
  56771. + dwc_mdelay(100);
  56772. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56773. +
  56774. + } else { // Indicates it is Reset Operation
  56775. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  56776. + hprt0.b.prtrst = 1;
  56777. + hprt0.b.prtpwr = 1;
  56778. + hprt0.b.prtena = 0;
  56779. + hprt0.b.prtsusp = 0;
  56780. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56781. + /* Wait for Reset time and then program HPRT again */
  56782. + dwc_mdelay(60);
  56783. + hprt0.b.prtrst = 0;
  56784. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56785. + }
  56786. + /* Clear all interrupt status */
  56787. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  56788. + hprt0.b.prtconndet = 1;
  56789. + hprt0.b.prtenchng = 1;
  56790. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56791. +
  56792. + /* Clear all pending interupts */
  56793. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56794. +
  56795. + /* Restore global registers */
  56796. + dwc_otg_restore_global_regs(core_if);
  56797. + /* Restore host global registers */
  56798. + dwc_otg_restore_host_regs(core_if, reset);
  56799. +
  56800. + /* The core will be in ON STATE */
  56801. + core_if->lx_state = DWC_OTG_L0;
  56802. + DWC_PRINTF("Hibernation recovery is complete here\n");
  56803. + return 0;
  56804. +}
  56805. +
  56806. +/** Saves some register values into system memory. */
  56807. +int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  56808. +{
  56809. + struct dwc_otg_global_regs_backup *gr;
  56810. + int i;
  56811. +
  56812. + gr = core_if->gr_backup;
  56813. + if (!gr) {
  56814. + gr = DWC_ALLOC(sizeof(*gr));
  56815. + if (!gr) {
  56816. + return -DWC_E_NO_MEMORY;
  56817. + }
  56818. + core_if->gr_backup = gr;
  56819. + }
  56820. +
  56821. + gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  56822. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  56823. + gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  56824. + gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  56825. + gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  56826. + gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  56827. + gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  56828. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56829. + gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  56830. +#endif
  56831. + gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  56832. + gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  56833. + gr->gdfifocfg_local =
  56834. + DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  56835. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56836. + gr->dtxfsiz_local[i] =
  56837. + DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  56838. + }
  56839. +
  56840. + DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  56841. + DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  56842. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  56843. + DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  56844. + DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  56845. + DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  56846. + DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  56847. + gr->gnptxfsiz_local);
  56848. + DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  56849. + gr->hptxfsiz_local);
  56850. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56851. + DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  56852. +#endif
  56853. + DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  56854. + DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  56855. + DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  56856. +
  56857. + return 0;
  56858. +}
  56859. +
  56860. +/** Saves GINTMSK register before setting the msk bits. */
  56861. +int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  56862. +{
  56863. + struct dwc_otg_global_regs_backup *gr;
  56864. +
  56865. + gr = core_if->gr_backup;
  56866. + if (!gr) {
  56867. + gr = DWC_ALLOC(sizeof(*gr));
  56868. + if (!gr) {
  56869. + return -DWC_E_NO_MEMORY;
  56870. + }
  56871. + core_if->gr_backup = gr;
  56872. + }
  56873. +
  56874. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  56875. +
  56876. + DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  56877. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  56878. +
  56879. + return 0;
  56880. +}
  56881. +
  56882. +int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  56883. +{
  56884. + struct dwc_otg_dev_regs_backup *dr;
  56885. + int i;
  56886. +
  56887. + dr = core_if->dr_backup;
  56888. + if (!dr) {
  56889. + dr = DWC_ALLOC(sizeof(*dr));
  56890. + if (!dr) {
  56891. + return -DWC_E_NO_MEMORY;
  56892. + }
  56893. + core_if->dr_backup = dr;
  56894. + }
  56895. +
  56896. + dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  56897. + dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  56898. + dr->daintmsk =
  56899. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  56900. + dr->diepmsk =
  56901. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  56902. + dr->doepmsk =
  56903. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  56904. +
  56905. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56906. + dr->diepctl[i] =
  56907. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  56908. + dr->dieptsiz[i] =
  56909. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  56910. + dr->diepdma[i] =
  56911. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  56912. + }
  56913. +
  56914. + DWC_DEBUGPL(DBG_ANY,
  56915. + "=============Backing Host registers==============\n");
  56916. + DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  56917. + DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  56918. + DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  56919. + dr->daintmsk);
  56920. + DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  56921. + DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  56922. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56923. + DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  56924. + dr->diepctl[i]);
  56925. + DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  56926. + i, dr->dieptsiz[i]);
  56927. + DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  56928. + dr->diepdma[i]);
  56929. + }
  56930. +
  56931. + return 0;
  56932. +}
  56933. +
  56934. +int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  56935. +{
  56936. + struct dwc_otg_host_regs_backup *hr;
  56937. + int i;
  56938. +
  56939. + hr = core_if->hr_backup;
  56940. + if (!hr) {
  56941. + hr = DWC_ALLOC(sizeof(*hr));
  56942. + if (!hr) {
  56943. + return -DWC_E_NO_MEMORY;
  56944. + }
  56945. + core_if->hr_backup = hr;
  56946. + }
  56947. +
  56948. + hr->hcfg_local =
  56949. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  56950. + hr->haintmsk_local =
  56951. + DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  56952. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  56953. + hr->hcintmsk_local[i] =
  56954. + DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  56955. + }
  56956. + hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  56957. + hr->hfir_local =
  56958. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  56959. +
  56960. + DWC_DEBUGPL(DBG_ANY,
  56961. + "=============Backing Host registers===============\n");
  56962. + DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  56963. + hr->hcfg_local);
  56964. + DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  56965. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  56966. + DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  56967. + hr->hcintmsk_local[i]);
  56968. + }
  56969. + DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  56970. + hr->hprt0_local);
  56971. + DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  56972. + hr->hfir_local);
  56973. +
  56974. + return 0;
  56975. +}
  56976. +
  56977. +int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  56978. +{
  56979. + struct dwc_otg_global_regs_backup *gr;
  56980. + int i;
  56981. +
  56982. + gr = core_if->gr_backup;
  56983. + if (!gr) {
  56984. + return -DWC_E_INVALID;
  56985. + }
  56986. +
  56987. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  56988. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  56989. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  56990. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  56991. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  56992. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  56993. + gr->gnptxfsiz_local);
  56994. + DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  56995. + gr->hptxfsiz_local);
  56996. + DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  56997. + gr->gdfifocfg_local);
  56998. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56999. + DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  57000. + gr->dtxfsiz_local[i]);
  57001. + }
  57002. +
  57003. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  57004. + DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  57005. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  57006. + (gr->gahbcfg_local));
  57007. + return 0;
  57008. +}
  57009. +
  57010. +int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  57011. +{
  57012. + struct dwc_otg_dev_regs_backup *dr;
  57013. + int i;
  57014. +
  57015. + dr = core_if->dr_backup;
  57016. +
  57017. + if (!dr) {
  57018. + return -DWC_E_INVALID;
  57019. + }
  57020. +
  57021. + if (!rem_wakeup) {
  57022. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  57023. + dr->dctl);
  57024. + }
  57025. +
  57026. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  57027. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  57028. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  57029. +
  57030. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  57031. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  57032. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  57033. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  57034. + }
  57035. +
  57036. + return 0;
  57037. +}
  57038. +
  57039. +int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  57040. +{
  57041. + struct dwc_otg_host_regs_backup *hr;
  57042. + int i;
  57043. + hr = core_if->hr_backup;
  57044. +
  57045. + if (!hr) {
  57046. + return -DWC_E_INVALID;
  57047. + }
  57048. +
  57049. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  57050. + //if (!reset)
  57051. + //{
  57052. + // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  57053. + //}
  57054. +
  57055. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  57056. + hr->haintmsk_local);
  57057. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  57058. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  57059. + hr->hcintmsk_local[i]);
  57060. + }
  57061. +
  57062. + return 0;
  57063. +}
  57064. +
  57065. +int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  57066. +{
  57067. + struct dwc_otg_global_regs_backup *gr;
  57068. +
  57069. + gr = core_if->gr_backup;
  57070. +
  57071. + /* Restore values for LPM and I2C */
  57072. +#ifdef CONFIG_USB_DWC_OTG_LPM
  57073. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  57074. +#endif
  57075. + DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  57076. +
  57077. + return 0;
  57078. +}
  57079. +
  57080. +int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  57081. +{
  57082. + struct dwc_otg_global_regs_backup *gr;
  57083. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  57084. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  57085. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  57086. + gintmsk_data_t gintmsk = {.d32 = 0 };
  57087. +
  57088. + /* Restore LPM and I2C registers */
  57089. + restore_lpm_i2c_regs(core_if);
  57090. +
  57091. + /* Set PCGCCTL to 0 */
  57092. + DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  57093. +
  57094. + gr = core_if->gr_backup;
  57095. + /* Load restore values for [31:14] bits */
  57096. + DWC_WRITE_REG32(core_if->pcgcctl,
  57097. + ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  57098. +
  57099. + /* Umnask global Interrupt in GAHBCFG and restore it */
  57100. + gahbcfg.d32 = gr->gahbcfg_local;
  57101. + gahbcfg.b.glblintrmsk = 1;
  57102. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  57103. +
  57104. + /* Clear all pending interupts */
  57105. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  57106. +
  57107. + /* Unmask restore done interrupt */
  57108. + gintmsk.b.restoredone = 1;
  57109. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  57110. +
  57111. + /* Restore GUSBCFG and HCFG/DCFG */
  57112. + gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  57113. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  57114. +
  57115. + if (is_host) {
  57116. + hcfg_data_t hcfg = {.d32 = 0 };
  57117. + hcfg.d32 = core_if->hr_backup->hcfg_local;
  57118. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  57119. + hcfg.d32);
  57120. +
  57121. + /* Load restore values for [31:14] bits */
  57122. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57123. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  57124. +
  57125. + if (rmode)
  57126. + pcgcctl.b.restoremode = 1;
  57127. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57128. + dwc_udelay(10);
  57129. +
  57130. + /* Load restore values for [31:14] bits and set EssRegRestored bit */
  57131. + pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  57132. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57133. + pcgcctl.b.ess_reg_restored = 1;
  57134. + if (rmode)
  57135. + pcgcctl.b.restoremode = 1;
  57136. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57137. + } else {
  57138. + dcfg_data_t dcfg = {.d32 = 0 };
  57139. + dcfg.d32 = core_if->dr_backup->dcfg;
  57140. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  57141. +
  57142. + /* Load restore values for [31:14] bits */
  57143. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57144. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  57145. + if (!rmode) {
  57146. + pcgcctl.d32 |= 0x208;
  57147. + }
  57148. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57149. + dwc_udelay(10);
  57150. +
  57151. + /* Load restore values for [31:14] bits */
  57152. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57153. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  57154. + pcgcctl.b.ess_reg_restored = 1;
  57155. + if (!rmode)
  57156. + pcgcctl.d32 |= 0x208;
  57157. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57158. + }
  57159. +
  57160. + return 0;
  57161. +}
  57162. +
  57163. +/**
  57164. + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  57165. + * type.
  57166. + */
  57167. +static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  57168. +{
  57169. + uint32_t val;
  57170. + hcfg_data_t hcfg;
  57171. +
  57172. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  57173. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  57174. + (core_if->core_params->ulpi_fs_ls)) ||
  57175. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  57176. + /* Full speed PHY */
  57177. + val = DWC_HCFG_48_MHZ;
  57178. + } else {
  57179. + /* High speed PHY running at full speed or high speed */
  57180. + val = DWC_HCFG_30_60_MHZ;
  57181. + }
  57182. +
  57183. + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  57184. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  57185. + hcfg.b.fslspclksel = val;
  57186. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  57187. +}
  57188. +
  57189. +/**
  57190. + * Initializes the DevSpd field of the DCFG register depending on the PHY type
  57191. + * and the enumeration speed of the device.
  57192. + */
  57193. +static void init_devspd(dwc_otg_core_if_t * core_if)
  57194. +{
  57195. + uint32_t val;
  57196. + dcfg_data_t dcfg;
  57197. +
  57198. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  57199. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  57200. + (core_if->core_params->ulpi_fs_ls)) ||
  57201. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  57202. + /* Full speed PHY */
  57203. + val = 0x3;
  57204. + } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  57205. + /* High speed PHY running at full speed */
  57206. + val = 0x1;
  57207. + } else {
  57208. + /* High speed PHY running at high speed */
  57209. + val = 0x0;
  57210. + }
  57211. +
  57212. + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  57213. +
  57214. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  57215. + dcfg.b.devspd = val;
  57216. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  57217. +}
  57218. +
  57219. +/**
  57220. + * This function calculates the number of IN EPS
  57221. + * using GHWCFG1 and GHWCFG2 registers values
  57222. + *
  57223. + * @param core_if Programming view of the DWC_otg controller
  57224. + */
  57225. +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  57226. +{
  57227. + uint32_t num_in_eps = 0;
  57228. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  57229. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  57230. + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  57231. + int i;
  57232. +
  57233. + for (i = 0; i < num_eps; ++i) {
  57234. + if (!(hwcfg1 & 0x1))
  57235. + num_in_eps++;
  57236. +
  57237. + hwcfg1 >>= 2;
  57238. + }
  57239. +
  57240. + if (core_if->hwcfg4.b.ded_fifo_en) {
  57241. + num_in_eps =
  57242. + (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  57243. + }
  57244. +
  57245. + return num_in_eps;
  57246. +}
  57247. +
  57248. +/**
  57249. + * This function calculates the number of OUT EPS
  57250. + * using GHWCFG1 and GHWCFG2 registers values
  57251. + *
  57252. + * @param core_if Programming view of the DWC_otg controller
  57253. + */
  57254. +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  57255. +{
  57256. + uint32_t num_out_eps = 0;
  57257. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  57258. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  57259. + int i;
  57260. +
  57261. + for (i = 0; i < num_eps; ++i) {
  57262. + if (!(hwcfg1 & 0x1))
  57263. + num_out_eps++;
  57264. +
  57265. + hwcfg1 >>= 2;
  57266. + }
  57267. + return num_out_eps;
  57268. +}
  57269. +
  57270. +/**
  57271. + * This function initializes the DWC_otg controller registers and
  57272. + * prepares the core for device mode or host mode operation.
  57273. + *
  57274. + * @param core_if Programming view of the DWC_otg controller
  57275. + *
  57276. + */
  57277. +void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  57278. +{
  57279. + int i = 0;
  57280. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57281. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  57282. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  57283. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  57284. + gi2cctl_data_t i2cctl = {.d32 = 0 };
  57285. +
  57286. + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p) regs at %p\n",
  57287. + core_if, global_regs);
  57288. +
  57289. + /* Common Initialization */
  57290. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57291. +
  57292. + /* Program the ULPI External VBUS bit if needed */
  57293. + usbcfg.b.ulpi_ext_vbus_drv =
  57294. + (core_if->core_params->phy_ulpi_ext_vbus ==
  57295. + DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  57296. +
  57297. + /* Set external TS Dline pulsing */
  57298. + usbcfg.b.term_sel_dl_pulse =
  57299. + (core_if->core_params->ts_dline == 1) ? 1 : 0;
  57300. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57301. +
  57302. + /* Reset the Controller */
  57303. + dwc_otg_core_reset(core_if);
  57304. +
  57305. + core_if->adp_enable = core_if->core_params->adp_supp_enable;
  57306. + core_if->power_down = core_if->core_params->power_down;
  57307. + core_if->otg_sts = 0;
  57308. +
  57309. + /* Initialize parameters from Hardware configuration registers. */
  57310. + dev_if->num_in_eps = calc_num_in_eps(core_if);
  57311. + dev_if->num_out_eps = calc_num_out_eps(core_if);
  57312. +
  57313. + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  57314. + core_if->hwcfg4.b.num_dev_perio_in_ep);
  57315. +
  57316. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  57317. + dev_if->perio_tx_fifo_size[i] =
  57318. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  57319. + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  57320. + i, dev_if->perio_tx_fifo_size[i]);
  57321. + }
  57322. +
  57323. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  57324. + dev_if->tx_fifo_size[i] =
  57325. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  57326. + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  57327. + i, dev_if->tx_fifo_size[i]);
  57328. + }
  57329. +
  57330. + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  57331. + core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  57332. + core_if->nperio_tx_fifo_size =
  57333. + DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  57334. +
  57335. + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  57336. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  57337. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  57338. + core_if->nperio_tx_fifo_size);
  57339. +
  57340. + /* This programming sequence needs to happen in FS mode before any other
  57341. + * programming occurs */
  57342. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  57343. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  57344. + /* If FS mode with FS PHY */
  57345. +
  57346. + /* core_init() is now called on every switch so only call the
  57347. + * following for the first time through. */
  57348. + if (!core_if->phy_init_done) {
  57349. + core_if->phy_init_done = 1;
  57350. + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  57351. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57352. + usbcfg.b.physel = 1;
  57353. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57354. +
  57355. + /* Reset after a PHY select */
  57356. + dwc_otg_core_reset(core_if);
  57357. + }
  57358. +
  57359. + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  57360. + * do this on HNP Dev/Host mode switches (done in dev_init and
  57361. + * host_init). */
  57362. + if (dwc_otg_is_host_mode(core_if)) {
  57363. + init_fslspclksel(core_if);
  57364. + } else {
  57365. + init_devspd(core_if);
  57366. + }
  57367. +
  57368. + if (core_if->core_params->i2c_enable) {
  57369. + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  57370. + /* Program GUSBCFG.OtgUtmifsSel to I2C */
  57371. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57372. + usbcfg.b.otgutmifssel = 1;
  57373. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57374. +
  57375. + /* Program GI2CCTL.I2CEn */
  57376. + i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  57377. + i2cctl.b.i2cdevaddr = 1;
  57378. + i2cctl.b.i2cen = 0;
  57379. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  57380. + i2cctl.b.i2cen = 1;
  57381. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  57382. + }
  57383. +
  57384. + } /* endif speed == DWC_SPEED_PARAM_FULL */
  57385. + else {
  57386. + /* High speed PHY. */
  57387. + if (!core_if->phy_init_done) {
  57388. + core_if->phy_init_done = 1;
  57389. + /* HS PHY parameters. These parameters are preserved
  57390. + * during soft reset so only program the first time. Do
  57391. + * a soft reset immediately after setting phyif. */
  57392. +
  57393. + if (core_if->core_params->phy_type == 2) {
  57394. + /* ULPI interface */
  57395. + usbcfg.b.ulpi_utmi_sel = 1;
  57396. + usbcfg.b.phyif = 0;
  57397. + usbcfg.b.ddrsel =
  57398. + core_if->core_params->phy_ulpi_ddr;
  57399. + } else if (core_if->core_params->phy_type == 1) {
  57400. + /* UTMI+ interface */
  57401. + usbcfg.b.ulpi_utmi_sel = 0;
  57402. + if (core_if->core_params->phy_utmi_width == 16) {
  57403. + usbcfg.b.phyif = 1;
  57404. +
  57405. + } else {
  57406. + usbcfg.b.phyif = 0;
  57407. + }
  57408. + } else {
  57409. + DWC_ERROR("FS PHY TYPE\n");
  57410. + }
  57411. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57412. + /* Reset after setting the PHY parameters */
  57413. + dwc_otg_core_reset(core_if);
  57414. + }
  57415. + }
  57416. +
  57417. + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  57418. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  57419. + (core_if->core_params->ulpi_fs_ls)) {
  57420. + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  57421. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57422. + usbcfg.b.ulpi_fsls = 1;
  57423. + usbcfg.b.ulpi_clk_sus_m = 1;
  57424. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57425. + } else {
  57426. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57427. + usbcfg.b.ulpi_fsls = 0;
  57428. + usbcfg.b.ulpi_clk_sus_m = 0;
  57429. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57430. + }
  57431. +
  57432. + /* Program the GAHBCFG Register. */
  57433. + switch (core_if->hwcfg2.b.architecture) {
  57434. +
  57435. + case DWC_SLAVE_ONLY_ARCH:
  57436. + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  57437. + ahbcfg.b.nptxfemplvl_txfemplvl =
  57438. + DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  57439. + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  57440. + core_if->dma_enable = 0;
  57441. + core_if->dma_desc_enable = 0;
  57442. + break;
  57443. +
  57444. + case DWC_EXT_DMA_ARCH:
  57445. + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  57446. + {
  57447. + uint8_t brst_sz = core_if->core_params->dma_burst_size;
  57448. + ahbcfg.b.hburstlen = 0;
  57449. + while (brst_sz > 1) {
  57450. + ahbcfg.b.hburstlen++;
  57451. + brst_sz >>= 1;
  57452. + }
  57453. + }
  57454. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  57455. + core_if->dma_desc_enable =
  57456. + (core_if->core_params->dma_desc_enable != 0);
  57457. + break;
  57458. +
  57459. + case DWC_INT_DMA_ARCH:
  57460. + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  57461. + /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  57462. + Host mode ISOC in issue fix - vahrama */
  57463. + /* Broadcom had altered to (1<<3)|(0<<0) - WRESP=1, max 4 beats */
  57464. + ahbcfg.b.hburstlen = (1<<3)|(0<<0);//DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  57465. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  57466. + core_if->dma_desc_enable =
  57467. + (core_if->core_params->dma_desc_enable != 0);
  57468. + break;
  57469. +
  57470. + }
  57471. + if (core_if->dma_enable) {
  57472. + if (core_if->dma_desc_enable) {
  57473. + DWC_PRINTF("Using Descriptor DMA mode\n");
  57474. + } else {
  57475. + DWC_PRINTF("Using Buffer DMA mode\n");
  57476. +
  57477. + }
  57478. + } else {
  57479. + DWC_PRINTF("Using Slave mode\n");
  57480. + core_if->dma_desc_enable = 0;
  57481. + }
  57482. +
  57483. + if (core_if->core_params->ahb_single) {
  57484. + ahbcfg.b.ahbsingle = 1;
  57485. + }
  57486. +
  57487. + ahbcfg.b.dmaenable = core_if->dma_enable;
  57488. + DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  57489. +
  57490. + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  57491. +
  57492. + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  57493. + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  57494. + DWC_PRINTF("Periodic Transfer Interrupt Enhancement - %s\n",
  57495. + ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  57496. + DWC_PRINTF("Multiprocessor Interrupt Enhancement - %s\n",
  57497. + ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  57498. +
  57499. + /*
  57500. + * Program the GUSBCFG register.
  57501. + */
  57502. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57503. +
  57504. + switch (core_if->hwcfg2.b.op_mode) {
  57505. + case DWC_MODE_HNP_SRP_CAPABLE:
  57506. + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  57507. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  57508. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  57509. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  57510. + break;
  57511. +
  57512. + case DWC_MODE_SRP_ONLY_CAPABLE:
  57513. + usbcfg.b.hnpcap = 0;
  57514. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  57515. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  57516. + break;
  57517. +
  57518. + case DWC_MODE_NO_HNP_SRP_CAPABLE:
  57519. + usbcfg.b.hnpcap = 0;
  57520. + usbcfg.b.srpcap = 0;
  57521. + break;
  57522. +
  57523. + case DWC_MODE_SRP_CAPABLE_DEVICE:
  57524. + usbcfg.b.hnpcap = 0;
  57525. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  57526. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  57527. + break;
  57528. +
  57529. + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  57530. + usbcfg.b.hnpcap = 0;
  57531. + usbcfg.b.srpcap = 0;
  57532. + break;
  57533. +
  57534. + case DWC_MODE_SRP_CAPABLE_HOST:
  57535. + usbcfg.b.hnpcap = 0;
  57536. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  57537. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  57538. + break;
  57539. +
  57540. + case DWC_MODE_NO_SRP_CAPABLE_HOST:
  57541. + usbcfg.b.hnpcap = 0;
  57542. + usbcfg.b.srpcap = 0;
  57543. + break;
  57544. + }
  57545. +
  57546. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57547. +
  57548. +#ifdef CONFIG_USB_DWC_OTG_LPM
  57549. + if (core_if->core_params->lpm_enable) {
  57550. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  57551. +
  57552. + /* To enable LPM support set lpm_cap_en bit */
  57553. + lpmcfg.b.lpm_cap_en = 1;
  57554. +
  57555. + /* Make AppL1Res ACK */
  57556. + lpmcfg.b.appl_resp = 1;
  57557. +
  57558. + /* Retry 3 times */
  57559. + lpmcfg.b.retry_count = 3;
  57560. +
  57561. + DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  57562. + 0, lpmcfg.d32);
  57563. +
  57564. + }
  57565. +#endif
  57566. + if (core_if->core_params->ic_usb_cap) {
  57567. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  57568. + gusbcfg.b.ic_usb_cap = 1;
  57569. + DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  57570. + 0, gusbcfg.d32);
  57571. + }
  57572. + {
  57573. + gotgctl_data_t gotgctl = {.d32 = 0 };
  57574. + gotgctl.b.otgver = core_if->core_params->otg_ver;
  57575. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  57576. + gotgctl.d32);
  57577. + /* Set OTG version supported */
  57578. + core_if->otg_ver = core_if->core_params->otg_ver;
  57579. + DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  57580. + core_if->core_params->otg_ver, core_if->otg_ver);
  57581. + }
  57582. +
  57583. +
  57584. + /* Enable common interrupts */
  57585. + dwc_otg_enable_common_interrupts(core_if);
  57586. +
  57587. + /* Do device or host intialization based on mode during PCD
  57588. + * and HCD initialization */
  57589. + if (dwc_otg_is_host_mode(core_if)) {
  57590. + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  57591. + core_if->op_state = A_HOST;
  57592. + } else {
  57593. + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  57594. + core_if->op_state = B_PERIPHERAL;
  57595. +#ifdef DWC_DEVICE_ONLY
  57596. + dwc_otg_core_dev_init(core_if);
  57597. +#endif
  57598. + }
  57599. +}
  57600. +
  57601. +/**
  57602. + * This function enables the Device mode interrupts.
  57603. + *
  57604. + * @param core_if Programming view of DWC_otg controller
  57605. + */
  57606. +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  57607. +{
  57608. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57609. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57610. +
  57611. + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  57612. +
  57613. + /* Disable all interrupts. */
  57614. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  57615. +
  57616. + /* Clear any pending interrupts */
  57617. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  57618. +
  57619. + /* Enable the common interrupts */
  57620. + dwc_otg_enable_common_interrupts(core_if);
  57621. +
  57622. + /* Enable interrupts */
  57623. + intr_mask.b.usbreset = 1;
  57624. + intr_mask.b.enumdone = 1;
  57625. + /* Disable Disconnect interrupt in Device mode */
  57626. + intr_mask.b.disconnect = 0;
  57627. +
  57628. + if (!core_if->multiproc_int_enable) {
  57629. + intr_mask.b.inepintr = 1;
  57630. + intr_mask.b.outepintr = 1;
  57631. + }
  57632. +
  57633. + intr_mask.b.erlysuspend = 1;
  57634. +
  57635. + if (core_if->en_multiple_tx_fifo == 0) {
  57636. + intr_mask.b.epmismatch = 1;
  57637. + }
  57638. +
  57639. + //intr_mask.b.incomplisoout = 1;
  57640. + intr_mask.b.incomplisoin = 1;
  57641. +
  57642. +/* Enable the ignore frame number for ISOC xfers - MAS */
  57643. +/* Disable to support high bandwith ISOC transfers - manukz */
  57644. +#if 0
  57645. +#ifdef DWC_UTE_PER_IO
  57646. + if (core_if->dma_enable) {
  57647. + if (core_if->dma_desc_enable) {
  57648. + dctl_data_t dctl1 = {.d32 = 0 };
  57649. + dctl1.b.ifrmnum = 1;
  57650. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  57651. + dctl, 0, dctl1.d32);
  57652. + DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  57653. + DWC_READ_REG32(&core_if->dev_if->
  57654. + dev_global_regs->dctl));
  57655. + }
  57656. + }
  57657. +#endif
  57658. +#endif
  57659. +#ifdef DWC_EN_ISOC
  57660. + if (core_if->dma_enable) {
  57661. + if (core_if->dma_desc_enable == 0) {
  57662. + if (core_if->pti_enh_enable) {
  57663. + dctl_data_t dctl = {.d32 = 0 };
  57664. + dctl.b.ifrmnum = 1;
  57665. + DWC_MODIFY_REG32(&core_if->
  57666. + dev_if->dev_global_regs->dctl,
  57667. + 0, dctl.d32);
  57668. + } else {
  57669. + intr_mask.b.incomplisoin = 1;
  57670. + intr_mask.b.incomplisoout = 1;
  57671. + }
  57672. + }
  57673. + } else {
  57674. + intr_mask.b.incomplisoin = 1;
  57675. + intr_mask.b.incomplisoout = 1;
  57676. + }
  57677. +#endif /* DWC_EN_ISOC */
  57678. +
  57679. + /** @todo NGS: Should this be a module parameter? */
  57680. +#ifdef USE_PERIODIC_EP
  57681. + intr_mask.b.isooutdrop = 1;
  57682. + intr_mask.b.eopframe = 1;
  57683. + intr_mask.b.incomplisoin = 1;
  57684. + intr_mask.b.incomplisoout = 1;
  57685. +#endif
  57686. +
  57687. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  57688. +
  57689. + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  57690. + DWC_READ_REG32(&global_regs->gintmsk));
  57691. +}
  57692. +
  57693. +/**
  57694. + * This function initializes the DWC_otg controller registers for
  57695. + * device mode.
  57696. + *
  57697. + * @param core_if Programming view of DWC_otg controller
  57698. + *
  57699. + */
  57700. +void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  57701. +{
  57702. + int i;
  57703. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57704. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  57705. + dwc_otg_core_params_t *params = core_if->core_params;
  57706. + dcfg_data_t dcfg = {.d32 = 0 };
  57707. + depctl_data_t diepctl = {.d32 = 0 };
  57708. + grstctl_t resetctl = {.d32 = 0 };
  57709. + uint32_t rx_fifo_size;
  57710. + fifosize_data_t nptxfifosize;
  57711. + fifosize_data_t txfifosize;
  57712. + dthrctl_data_t dthrctl;
  57713. + fifosize_data_t ptxfifosize;
  57714. + uint16_t rxfsiz, nptxfsiz;
  57715. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  57716. + hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  57717. +
  57718. + /* Restart the Phy Clock */
  57719. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  57720. +
  57721. + /* Device configuration register */
  57722. + init_devspd(core_if);
  57723. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  57724. + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  57725. + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  57726. + /* Enable Device OUT NAK in case of DDMA mode*/
  57727. + if (core_if->core_params->dev_out_nak) {
  57728. + dcfg.b.endevoutnak = 1;
  57729. + }
  57730. +
  57731. + if (core_if->core_params->cont_on_bna) {
  57732. + dctl_data_t dctl = {.d32 = 0 };
  57733. + dctl.b.encontonbna = 1;
  57734. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57735. + }
  57736. +
  57737. +
  57738. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  57739. +
  57740. + /* Configure data FIFO sizes */
  57741. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  57742. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  57743. + core_if->total_fifo_size);
  57744. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  57745. + params->dev_rx_fifo_size);
  57746. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  57747. + params->dev_nperio_tx_fifo_size);
  57748. +
  57749. + /* Rx FIFO */
  57750. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  57751. + DWC_READ_REG32(&global_regs->grxfsiz));
  57752. +
  57753. +#ifdef DWC_UTE_CFI
  57754. + core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  57755. + core_if->init_rxfsiz = params->dev_rx_fifo_size;
  57756. +#endif
  57757. + rx_fifo_size = params->dev_rx_fifo_size;
  57758. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  57759. +
  57760. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  57761. + DWC_READ_REG32(&global_regs->grxfsiz));
  57762. +
  57763. + /** Set Periodic Tx FIFO Mask all bits 0 */
  57764. + core_if->p_tx_msk = 0;
  57765. +
  57766. + /** Set Tx FIFO Mask all bits 0 */
  57767. + core_if->tx_msk = 0;
  57768. +
  57769. + if (core_if->en_multiple_tx_fifo == 0) {
  57770. + /* Non-periodic Tx FIFO */
  57771. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  57772. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57773. +
  57774. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  57775. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  57776. +
  57777. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  57778. + nptxfifosize.d32);
  57779. +
  57780. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  57781. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57782. +
  57783. + /**@todo NGS: Fix Periodic FIFO Sizing! */
  57784. + /*
  57785. + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  57786. + * Indexes of the FIFO size module parameters in the
  57787. + * dev_perio_tx_fifo_size array and the FIFO size registers in
  57788. + * the dptxfsiz array run from 0 to 14.
  57789. + */
  57790. + /** @todo Finish debug of this */
  57791. + ptxfifosize.b.startaddr =
  57792. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  57793. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  57794. + ptxfifosize.b.depth =
  57795. + params->dev_perio_tx_fifo_size[i];
  57796. + DWC_DEBUGPL(DBG_CIL,
  57797. + "initial dtxfsiz[%d]=%08x\n", i,
  57798. + DWC_READ_REG32(&global_regs->dtxfsiz
  57799. + [i]));
  57800. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  57801. + ptxfifosize.d32);
  57802. + DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  57803. + i,
  57804. + DWC_READ_REG32(&global_regs->dtxfsiz
  57805. + [i]));
  57806. + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  57807. + }
  57808. + } else {
  57809. + /*
  57810. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  57811. + * Indexes of the FIFO size module parameters in the
  57812. + * dev_tx_fifo_size array and the FIFO size registers in
  57813. + * the dtxfsiz array run from 0 to 14.
  57814. + */
  57815. +
  57816. + /* Non-periodic Tx FIFO */
  57817. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  57818. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57819. +
  57820. +#ifdef DWC_UTE_CFI
  57821. + core_if->pwron_gnptxfsiz =
  57822. + (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  57823. + core_if->init_gnptxfsiz =
  57824. + params->dev_nperio_tx_fifo_size;
  57825. +#endif
  57826. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  57827. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  57828. +
  57829. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  57830. + nptxfifosize.d32);
  57831. +
  57832. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  57833. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57834. +
  57835. + txfifosize.b.startaddr =
  57836. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  57837. +
  57838. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  57839. +
  57840. + txfifosize.b.depth =
  57841. + params->dev_tx_fifo_size[i];
  57842. +
  57843. + DWC_DEBUGPL(DBG_CIL,
  57844. + "initial dtxfsiz[%d]=%08x\n",
  57845. + i,
  57846. + DWC_READ_REG32(&global_regs->dtxfsiz
  57847. + [i]));
  57848. +
  57849. +#ifdef DWC_UTE_CFI
  57850. + core_if->pwron_txfsiz[i] =
  57851. + (DWC_READ_REG32
  57852. + (&global_regs->dtxfsiz[i]) >> 16);
  57853. + core_if->init_txfsiz[i] =
  57854. + params->dev_tx_fifo_size[i];
  57855. +#endif
  57856. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  57857. + txfifosize.d32);
  57858. +
  57859. + DWC_DEBUGPL(DBG_CIL,
  57860. + "new dtxfsiz[%d]=%08x\n",
  57861. + i,
  57862. + DWC_READ_REG32(&global_regs->dtxfsiz
  57863. + [i]));
  57864. +
  57865. + txfifosize.b.startaddr += txfifosize.b.depth;
  57866. + }
  57867. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  57868. + /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  57869. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  57870. + hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  57871. + gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  57872. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  57873. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  57874. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  57875. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  57876. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  57877. + }
  57878. + }
  57879. +
  57880. + /* Flush the FIFOs */
  57881. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  57882. + dwc_otg_flush_rx_fifo(core_if);
  57883. +
  57884. + /* Flush the Learning Queue. */
  57885. + resetctl.b.intknqflsh = 1;
  57886. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  57887. +
  57888. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  57889. + core_if->start_predict = 0;
  57890. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  57891. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  57892. + }
  57893. + core_if->nextep_seq[0] = 0;
  57894. + core_if->first_in_nextep_seq = 0;
  57895. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  57896. + diepctl.b.nextep = 0;
  57897. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  57898. +
  57899. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  57900. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  57901. + dcfg.b.epmscnt = 2;
  57902. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  57903. +
  57904. + DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  57905. + __func__, core_if->first_in_nextep_seq);
  57906. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  57907. + DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  57908. + }
  57909. + DWC_DEBUGPL(DBG_CILV,"\n");
  57910. + }
  57911. +
  57912. + /* Clear all pending Device Interrupts */
  57913. + /** @todo - if the condition needed to be checked
  57914. + * or in any case all pending interrutps should be cleared?
  57915. + */
  57916. + if (core_if->multiproc_int_enable) {
  57917. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  57918. + DWC_WRITE_REG32(&dev_if->
  57919. + dev_global_regs->diepeachintmsk[i], 0);
  57920. + }
  57921. + }
  57922. +
  57923. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  57924. + DWC_WRITE_REG32(&dev_if->
  57925. + dev_global_regs->doepeachintmsk[i], 0);
  57926. + }
  57927. +
  57928. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  57929. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  57930. + } else {
  57931. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  57932. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  57933. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  57934. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  57935. + }
  57936. +
  57937. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  57938. + depctl_data_t depctl;
  57939. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  57940. + if (depctl.b.epena) {
  57941. + depctl.d32 = 0;
  57942. + depctl.b.epdis = 1;
  57943. + depctl.b.snak = 1;
  57944. + } else {
  57945. + depctl.d32 = 0;
  57946. + }
  57947. +
  57948. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  57949. +
  57950. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  57951. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  57952. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  57953. + }
  57954. +
  57955. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  57956. + depctl_data_t depctl;
  57957. + depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  57958. + if (depctl.b.epena) {
  57959. + dctl_data_t dctl = {.d32 = 0 };
  57960. + gintmsk_data_t gintsts = {.d32 = 0 };
  57961. + doepint_data_t doepint = {.d32 = 0 };
  57962. + dctl.b.sgoutnak = 1;
  57963. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57964. + do {
  57965. + dwc_udelay(10);
  57966. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  57967. + } while (!gintsts.b.goutnakeff);
  57968. + gintsts.d32 = 0;
  57969. + gintsts.b.goutnakeff = 1;
  57970. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  57971. +
  57972. + depctl.d32 = 0;
  57973. + depctl.b.epdis = 1;
  57974. + depctl.b.snak = 1;
  57975. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  57976. + do {
  57977. + dwc_udelay(10);
  57978. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  57979. + out_ep_regs[i]->doepint);
  57980. + } while (!doepint.b.epdisabled);
  57981. +
  57982. + doepint.b.epdisabled = 1;
  57983. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepint, doepint.d32);
  57984. +
  57985. + dctl.d32 = 0;
  57986. + dctl.b.cgoutnak = 1;
  57987. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57988. + } else {
  57989. + depctl.d32 = 0;
  57990. + }
  57991. +
  57992. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  57993. +
  57994. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  57995. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  57996. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  57997. + }
  57998. +
  57999. + if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  58000. + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  58001. + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  58002. + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  58003. +
  58004. + dev_if->rx_thr_length = params->rx_thr_length;
  58005. + dev_if->tx_thr_length = params->tx_thr_length;
  58006. +
  58007. + dev_if->setup_desc_index = 0;
  58008. +
  58009. + dthrctl.d32 = 0;
  58010. + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  58011. + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  58012. + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  58013. + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  58014. + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  58015. + dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  58016. +
  58017. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  58018. + dthrctl.d32);
  58019. +
  58020. + DWC_DEBUGPL(DBG_CIL,
  58021. + "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  58022. + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  58023. + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  58024. + dthrctl.b.rx_thr_len);
  58025. +
  58026. + }
  58027. +
  58028. + dwc_otg_enable_device_interrupts(core_if);
  58029. +
  58030. + {
  58031. + diepmsk_data_t msk = {.d32 = 0 };
  58032. + msk.b.txfifoundrn = 1;
  58033. + if (core_if->multiproc_int_enable) {
  58034. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->
  58035. + diepeachintmsk[0], msk.d32, msk.d32);
  58036. + } else {
  58037. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  58038. + msk.d32, msk.d32);
  58039. + }
  58040. + }
  58041. +
  58042. + if (core_if->multiproc_int_enable) {
  58043. + /* Set NAK on Babble */
  58044. + dctl_data_t dctl = {.d32 = 0 };
  58045. + dctl.b.nakonbble = 1;
  58046. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  58047. + }
  58048. +
  58049. + if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  58050. + dctl_data_t dctl = {.d32 = 0 };
  58051. + dctl.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  58052. + dctl.b.sftdiscon = 0;
  58053. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl, dctl.d32);
  58054. + }
  58055. +}
  58056. +
  58057. +/**
  58058. + * This function enables the Host mode interrupts.
  58059. + *
  58060. + * @param core_if Programming view of DWC_otg controller
  58061. + */
  58062. +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  58063. +{
  58064. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  58065. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58066. +
  58067. + DWC_DEBUGPL(DBG_CIL, "%s(%p)\n", __func__, core_if);
  58068. +
  58069. + /* Disable all interrupts. */
  58070. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  58071. +
  58072. + /* Clear any pending interrupts. */
  58073. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  58074. +
  58075. + /* Enable the common interrupts */
  58076. + dwc_otg_enable_common_interrupts(core_if);
  58077. +
  58078. + /*
  58079. + * Enable host mode interrupts without disturbing common
  58080. + * interrupts.
  58081. + */
  58082. +
  58083. + intr_mask.b.disconnect = 1;
  58084. + intr_mask.b.portintr = 1;
  58085. + intr_mask.b.hcintr = 1;
  58086. +
  58087. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  58088. +}
  58089. +
  58090. +/**
  58091. + * This function disables the Host Mode interrupts.
  58092. + *
  58093. + * @param core_if Programming view of DWC_otg controller
  58094. + */
  58095. +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  58096. +{
  58097. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  58098. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58099. +
  58100. + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  58101. +
  58102. + /*
  58103. + * Disable host mode interrupts without disturbing common
  58104. + * interrupts.
  58105. + */
  58106. + intr_mask.b.sofintr = 1;
  58107. + intr_mask.b.portintr = 1;
  58108. + intr_mask.b.hcintr = 1;
  58109. + intr_mask.b.ptxfempty = 1;
  58110. + intr_mask.b.nptxfempty = 1;
  58111. +
  58112. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  58113. +}
  58114. +
  58115. +/**
  58116. + * This function initializes the DWC_otg controller registers for
  58117. + * host mode.
  58118. + *
  58119. + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  58120. + * request queues. Host channels are reset to ensure that they are ready for
  58121. + * performing transfers.
  58122. + *
  58123. + * @param core_if Programming view of DWC_otg controller
  58124. + *
  58125. + */
  58126. +void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  58127. +{
  58128. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  58129. + dwc_otg_host_if_t *host_if = core_if->host_if;
  58130. + dwc_otg_core_params_t *params = core_if->core_params;
  58131. + hprt0_data_t hprt0 = {.d32 = 0 };
  58132. + fifosize_data_t nptxfifosize;
  58133. + fifosize_data_t ptxfifosize;
  58134. + uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  58135. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  58136. + int i;
  58137. + hcchar_data_t hcchar;
  58138. + hcfg_data_t hcfg;
  58139. + hfir_data_t hfir;
  58140. + dwc_otg_hc_regs_t *hc_regs;
  58141. + int num_channels;
  58142. + gotgctl_data_t gotgctl = {.d32 = 0 };
  58143. +
  58144. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  58145. +
  58146. + /* Restart the Phy Clock */
  58147. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  58148. +
  58149. + /* Initialize Host Configuration Register */
  58150. + init_fslspclksel(core_if);
  58151. + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  58152. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  58153. + hcfg.b.fslssupp = 1;
  58154. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  58155. +
  58156. + }
  58157. +
  58158. + /* This bit allows dynamic reloading of the HFIR register
  58159. + * during runtime. This bit needs to be programmed during
  58160. + * initial configuration and its value must not be changed
  58161. + * during runtime.*/
  58162. + if (core_if->core_params->reload_ctl == 1) {
  58163. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  58164. + hfir.b.hfirrldctrl = 1;
  58165. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  58166. + }
  58167. +
  58168. + if (core_if->core_params->dma_desc_enable) {
  58169. + uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  58170. + if (!
  58171. + (core_if->hwcfg4.b.desc_dma
  58172. + && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  58173. + && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  58174. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  58175. + || (op_mode ==
  58176. + DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  58177. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  58178. + || (op_mode ==
  58179. + DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  58180. +
  58181. + DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  58182. + "Either core version is below 2.90a or "
  58183. + "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  58184. + "To run the driver in Buffer DMA host mode set dma_desc_enable "
  58185. + "module parameter to 0.\n");
  58186. + return;
  58187. + }
  58188. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  58189. + hcfg.b.descdma = 1;
  58190. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  58191. + }
  58192. +
  58193. + /* Configure data FIFO sizes */
  58194. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  58195. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  58196. + core_if->total_fifo_size);
  58197. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  58198. + params->host_rx_fifo_size);
  58199. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  58200. + params->host_nperio_tx_fifo_size);
  58201. + DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  58202. + params->host_perio_tx_fifo_size);
  58203. +
  58204. + /* Rx FIFO */
  58205. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  58206. + DWC_READ_REG32(&global_regs->grxfsiz));
  58207. + DWC_WRITE_REG32(&global_regs->grxfsiz,
  58208. + params->host_rx_fifo_size);
  58209. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  58210. + DWC_READ_REG32(&global_regs->grxfsiz));
  58211. +
  58212. + /* Non-periodic Tx FIFO */
  58213. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  58214. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  58215. + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  58216. + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  58217. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  58218. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  58219. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  58220. +
  58221. + /* Periodic Tx FIFO */
  58222. + DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  58223. + DWC_READ_REG32(&global_regs->hptxfsiz));
  58224. + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  58225. + ptxfifosize.b.startaddr =
  58226. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  58227. + DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  58228. + DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  58229. + DWC_READ_REG32(&global_regs->hptxfsiz));
  58230. +
  58231. + if (core_if->en_multiple_tx_fifo
  58232. + && core_if->snpsid <= OTG_CORE_REV_2_94a) {
  58233. + /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  58234. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  58235. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  58236. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  58237. + hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  58238. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  58239. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  58240. + }
  58241. + }
  58242. +
  58243. + /* TODO - check this */
  58244. + /* Clear Host Set HNP Enable in the OTG Control Register */
  58245. + gotgctl.b.hstsethnpen = 1;
  58246. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  58247. + /* Make sure the FIFOs are flushed. */
  58248. + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  58249. + dwc_otg_flush_rx_fifo(core_if);
  58250. +
  58251. + /* Clear Host Set HNP Enable in the OTG Control Register */
  58252. + gotgctl.b.hstsethnpen = 1;
  58253. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  58254. +
  58255. + if (!core_if->core_params->dma_desc_enable) {
  58256. + /* Flush out any leftover queued requests. */
  58257. + num_channels = core_if->core_params->host_channels;
  58258. +
  58259. + for (i = 0; i < num_channels; i++) {
  58260. + hc_regs = core_if->host_if->hc_regs[i];
  58261. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58262. + hcchar.b.chen = 0;
  58263. + hcchar.b.chdis = 1;
  58264. + hcchar.b.epdir = 0;
  58265. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58266. + }
  58267. +
  58268. + /* Halt all channels to put them into a known state. */
  58269. + for (i = 0; i < num_channels; i++) {
  58270. + int count = 0;
  58271. + hc_regs = core_if->host_if->hc_regs[i];
  58272. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58273. + hcchar.b.chen = 1;
  58274. + hcchar.b.chdis = 1;
  58275. + hcchar.b.epdir = 0;
  58276. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58277. + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d regs %p\n", __func__, i, hc_regs);
  58278. + do {
  58279. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58280. + if (++count > 1000) {
  58281. + DWC_ERROR
  58282. + ("%s: Unable to clear halt on channel %d (timeout HCCHAR 0x%X @%p)\n",
  58283. + __func__, i, hcchar.d32, &hc_regs->hcchar);
  58284. + break;
  58285. + }
  58286. + dwc_udelay(1);
  58287. + } while (hcchar.b.chen);
  58288. + }
  58289. + }
  58290. +
  58291. + /* Turn on the vbus power. */
  58292. + DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  58293. + if (core_if->op_state == A_HOST) {
  58294. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  58295. + DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  58296. + if (hprt0.b.prtpwr == 0) {
  58297. + hprt0.b.prtpwr = 1;
  58298. + DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  58299. + }
  58300. + }
  58301. +
  58302. + dwc_otg_enable_host_interrupts(core_if);
  58303. +}
  58304. +
  58305. +/**
  58306. + * Prepares a host channel for transferring packets to/from a specific
  58307. + * endpoint. The HCCHARn register is set up with the characteristics specified
  58308. + * in _hc. Host channel interrupts that may need to be serviced while this
  58309. + * transfer is in progress are enabled.
  58310. + *
  58311. + * @param core_if Programming view of DWC_otg controller
  58312. + * @param hc Information needed to initialize the host channel
  58313. + */
  58314. +void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58315. +{
  58316. + uint32_t intr_enable;
  58317. + hcintmsk_data_t hc_intr_mask;
  58318. + gintmsk_data_t gintmsk = {.d32 = 0 };
  58319. + hcchar_data_t hcchar;
  58320. + hcsplt_data_t hcsplt;
  58321. +
  58322. + uint8_t hc_num = hc->hc_num;
  58323. + dwc_otg_host_if_t *host_if = core_if->host_if;
  58324. + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  58325. +
  58326. + /* Clear old interrupt conditions for this host channel. */
  58327. + hc_intr_mask.d32 = 0xFFFFFFFF;
  58328. + hc_intr_mask.b.reserved14_31 = 0;
  58329. + DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  58330. +
  58331. + /* Enable channel interrupts required for this transfer. */
  58332. + hc_intr_mask.d32 = 0;
  58333. + hc_intr_mask.b.chhltd = 1;
  58334. + if (core_if->dma_enable) {
  58335. + /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  58336. + if (!core_if->dma_desc_enable)
  58337. + hc_intr_mask.b.ahberr = 1;
  58338. + else {
  58339. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  58340. + hc_intr_mask.b.xfercompl = 1;
  58341. + }
  58342. +
  58343. + if (hc->error_state && !hc->do_split &&
  58344. + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  58345. + hc_intr_mask.b.ack = 1;
  58346. + if (hc->ep_is_in) {
  58347. + hc_intr_mask.b.datatglerr = 1;
  58348. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  58349. + hc_intr_mask.b.nak = 1;
  58350. + }
  58351. + }
  58352. + }
  58353. + } else {
  58354. + switch (hc->ep_type) {
  58355. + case DWC_OTG_EP_TYPE_CONTROL:
  58356. + case DWC_OTG_EP_TYPE_BULK:
  58357. + hc_intr_mask.b.xfercompl = 1;
  58358. + hc_intr_mask.b.stall = 1;
  58359. + hc_intr_mask.b.xacterr = 1;
  58360. + hc_intr_mask.b.datatglerr = 1;
  58361. + if (hc->ep_is_in) {
  58362. + hc_intr_mask.b.bblerr = 1;
  58363. + } else {
  58364. + hc_intr_mask.b.nak = 1;
  58365. + hc_intr_mask.b.nyet = 1;
  58366. + if (hc->do_ping) {
  58367. + hc_intr_mask.b.ack = 1;
  58368. + }
  58369. + }
  58370. +
  58371. + if (hc->do_split) {
  58372. + hc_intr_mask.b.nak = 1;
  58373. + if (hc->complete_split) {
  58374. + hc_intr_mask.b.nyet = 1;
  58375. + } else {
  58376. + hc_intr_mask.b.ack = 1;
  58377. + }
  58378. + }
  58379. +
  58380. + if (hc->error_state) {
  58381. + hc_intr_mask.b.ack = 1;
  58382. + }
  58383. + break;
  58384. + case DWC_OTG_EP_TYPE_INTR:
  58385. + hc_intr_mask.b.xfercompl = 1;
  58386. + hc_intr_mask.b.nak = 1;
  58387. + hc_intr_mask.b.stall = 1;
  58388. + hc_intr_mask.b.xacterr = 1;
  58389. + hc_intr_mask.b.datatglerr = 1;
  58390. + hc_intr_mask.b.frmovrun = 1;
  58391. +
  58392. + if (hc->ep_is_in) {
  58393. + hc_intr_mask.b.bblerr = 1;
  58394. + }
  58395. + if (hc->error_state) {
  58396. + hc_intr_mask.b.ack = 1;
  58397. + }
  58398. + if (hc->do_split) {
  58399. + if (hc->complete_split) {
  58400. + hc_intr_mask.b.nyet = 1;
  58401. + } else {
  58402. + hc_intr_mask.b.ack = 1;
  58403. + }
  58404. + }
  58405. + break;
  58406. + case DWC_OTG_EP_TYPE_ISOC:
  58407. + hc_intr_mask.b.xfercompl = 1;
  58408. + hc_intr_mask.b.frmovrun = 1;
  58409. + hc_intr_mask.b.ack = 1;
  58410. +
  58411. + if (hc->ep_is_in) {
  58412. + hc_intr_mask.b.xacterr = 1;
  58413. + hc_intr_mask.b.bblerr = 1;
  58414. + }
  58415. + break;
  58416. + }
  58417. + }
  58418. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  58419. +
  58420. + /* Enable the top level host channel interrupt. */
  58421. + intr_enable = (1 << hc_num);
  58422. + DWC_MODIFY_REG32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
  58423. +
  58424. + /* Make sure host channel interrupts are enabled. */
  58425. + gintmsk.b.hcintr = 1;
  58426. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  58427. +
  58428. + /*
  58429. + * Program the HCCHARn register with the endpoint characteristics for
  58430. + * the current transfer.
  58431. + */
  58432. + hcchar.d32 = 0;
  58433. + hcchar.b.devaddr = hc->dev_addr;
  58434. + hcchar.b.epnum = hc->ep_num;
  58435. + hcchar.b.epdir = hc->ep_is_in;
  58436. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  58437. + hcchar.b.eptype = hc->ep_type;
  58438. + hcchar.b.mps = hc->max_packet;
  58439. +
  58440. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  58441. +
  58442. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d, Dev Addr %d, EP #%d\n",
  58443. + __func__, hc->hc_num, hcchar.b.devaddr, hcchar.b.epnum);
  58444. + DWC_DEBUGPL(DBG_HCDV, " Is In %d, Is Low Speed %d, EP Type %d, "
  58445. + "Max Pkt %d, Multi Cnt %d\n",
  58446. + hcchar.b.epdir, hcchar.b.lspddev, hcchar.b.eptype,
  58447. + hcchar.b.mps, hcchar.b.multicnt);
  58448. +
  58449. + /*
  58450. + * Program the HCSPLIT register for SPLITs
  58451. + */
  58452. + hcsplt.d32 = 0;
  58453. + if (hc->do_split) {
  58454. + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  58455. + hc->hc_num,
  58456. + hc->complete_split ? "CSPLIT" : "SSPLIT");
  58457. + hcsplt.b.compsplt = hc->complete_split;
  58458. + hcsplt.b.xactpos = hc->xact_pos;
  58459. + hcsplt.b.hubaddr = hc->hub_addr;
  58460. + hcsplt.b.prtaddr = hc->port_addr;
  58461. + DWC_DEBUGPL(DBG_HCDV, "\t comp split %d\n", hc->complete_split);
  58462. + DWC_DEBUGPL(DBG_HCDV, "\t xact pos %d\n", hc->xact_pos);
  58463. + DWC_DEBUGPL(DBG_HCDV, "\t hub addr %d\n", hc->hub_addr);
  58464. + DWC_DEBUGPL(DBG_HCDV, "\t port addr %d\n", hc->port_addr);
  58465. + DWC_DEBUGPL(DBG_HCDV, "\t is_in %d\n", hc->ep_is_in);
  58466. + DWC_DEBUGPL(DBG_HCDV, "\t Max Pkt: %d\n", hcchar.b.mps);
  58467. + DWC_DEBUGPL(DBG_HCDV, "\t xferlen: %d\n", hc->xfer_len);
  58468. + }
  58469. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  58470. +
  58471. +}
  58472. +
  58473. +/**
  58474. + * Attempts to halt a host channel. This function should only be called in
  58475. + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  58476. + * normal circumstances in DMA mode, the controller halts the channel when the
  58477. + * transfer is complete or a condition occurs that requires application
  58478. + * intervention.
  58479. + *
  58480. + * In slave mode, checks for a free request queue entry, then sets the Channel
  58481. + * Enable and Channel Disable bits of the Host Channel Characteristics
  58482. + * register of the specified channel to intiate the halt. If there is no free
  58483. + * request queue entry, sets only the Channel Disable bit of the HCCHARn
  58484. + * register to flush requests for this channel. In the latter case, sets a
  58485. + * flag to indicate that the host channel needs to be halted when a request
  58486. + * queue slot is open.
  58487. + *
  58488. + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  58489. + * HCCHARn register. The controller ensures there is space in the request
  58490. + * queue before submitting the halt request.
  58491. + *
  58492. + * Some time may elapse before the core flushes any posted requests for this
  58493. + * host channel and halts. The Channel Halted interrupt handler completes the
  58494. + * deactivation of the host channel.
  58495. + *
  58496. + * @param core_if Controller register interface.
  58497. + * @param hc Host channel to halt.
  58498. + * @param halt_status Reason for halting the channel.
  58499. + */
  58500. +void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  58501. + dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  58502. +{
  58503. + gnptxsts_data_t nptxsts;
  58504. + hptxsts_data_t hptxsts;
  58505. + hcchar_data_t hcchar;
  58506. + dwc_otg_hc_regs_t *hc_regs;
  58507. + dwc_otg_core_global_regs_t *global_regs;
  58508. + dwc_otg_host_global_regs_t *host_global_regs;
  58509. +
  58510. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58511. + global_regs = core_if->core_global_regs;
  58512. + host_global_regs = core_if->host_if->host_global_regs;
  58513. +
  58514. + DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  58515. + "halt_status = %d\n", halt_status);
  58516. +
  58517. + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  58518. + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  58519. + /*
  58520. + * Disable all channel interrupts except Ch Halted. The QTD
  58521. + * and QH state associated with this transfer has been cleared
  58522. + * (in the case of URB_DEQUEUE), so the channel needs to be
  58523. + * shut down carefully to prevent crashes.
  58524. + */
  58525. + hcintmsk_data_t hcintmsk;
  58526. + hcintmsk.d32 = 0;
  58527. + hcintmsk.b.chhltd = 1;
  58528. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  58529. +
  58530. + /*
  58531. + * Make sure no other interrupts besides halt are currently
  58532. + * pending. Handling another interrupt could cause a crash due
  58533. + * to the QTD and QH state.
  58534. + */
  58535. + DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  58536. +
  58537. + /*
  58538. + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  58539. + * even if the channel was already halted for some other
  58540. + * reason.
  58541. + */
  58542. + hc->halt_status = halt_status;
  58543. +
  58544. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58545. + if (hcchar.b.chen == 0) {
  58546. + /*
  58547. + * The channel is either already halted or it hasn't
  58548. + * started yet. In DMA mode, the transfer may halt if
  58549. + * it finishes normally or a condition occurs that
  58550. + * requires driver intervention. Don't want to halt
  58551. + * the channel again. In either Slave or DMA mode,
  58552. + * it's possible that the transfer has been assigned
  58553. + * to a channel, but not started yet when an URB is
  58554. + * dequeued. Don't want to halt a channel that hasn't
  58555. + * started yet.
  58556. + */
  58557. + return;
  58558. + }
  58559. + }
  58560. + if (hc->halt_pending) {
  58561. + /*
  58562. + * A halt has already been issued for this channel. This might
  58563. + * happen when a transfer is aborted by a higher level in
  58564. + * the stack.
  58565. + */
  58566. +#ifdef DEBUG
  58567. + DWC_PRINTF
  58568. + ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  58569. + __func__, hc->hc_num);
  58570. +
  58571. +#endif
  58572. + return;
  58573. + }
  58574. +
  58575. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58576. +
  58577. + /* No need to set the bit in DDMA for disabling the channel */
  58578. + //TODO check it everywhere channel is disabled
  58579. + if (!core_if->core_params->dma_desc_enable)
  58580. + hcchar.b.chen = 1;
  58581. + hcchar.b.chdis = 1;
  58582. +
  58583. + if (!core_if->dma_enable) {
  58584. + /* Check for space in the request queue to issue the halt. */
  58585. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  58586. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  58587. + nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  58588. + if (nptxsts.b.nptxqspcavail == 0) {
  58589. + hcchar.b.chen = 0;
  58590. + }
  58591. + } else {
  58592. + hptxsts.d32 =
  58593. + DWC_READ_REG32(&host_global_regs->hptxsts);
  58594. + if ((hptxsts.b.ptxqspcavail == 0)
  58595. + || (core_if->queuing_high_bandwidth)) {
  58596. + hcchar.b.chen = 0;
  58597. + }
  58598. + }
  58599. + }
  58600. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58601. +
  58602. + hc->halt_status = halt_status;
  58603. +
  58604. + if (hcchar.b.chen) {
  58605. + hc->halt_pending = 1;
  58606. + hc->halt_on_queue = 0;
  58607. + } else {
  58608. + hc->halt_on_queue = 1;
  58609. + }
  58610. +
  58611. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58612. + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  58613. + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  58614. + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  58615. + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  58616. +
  58617. + return;
  58618. +}
  58619. +
  58620. +/**
  58621. + * Clears the transfer state for a host channel. This function is normally
  58622. + * called after a transfer is done and the host channel is being released.
  58623. + *
  58624. + * @param core_if Programming view of DWC_otg controller.
  58625. + * @param hc Identifies the host channel to clean up.
  58626. + */
  58627. +void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58628. +{
  58629. + dwc_otg_hc_regs_t *hc_regs;
  58630. +
  58631. + hc->xfer_started = 0;
  58632. +
  58633. + /*
  58634. + * Clear channel interrupt enables and any unhandled channel interrupt
  58635. + * conditions.
  58636. + */
  58637. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58638. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  58639. + DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  58640. +#ifdef DEBUG
  58641. + DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  58642. +#endif
  58643. +}
  58644. +
  58645. +/**
  58646. + * Sets the channel property that indicates in which frame a periodic transfer
  58647. + * should occur. This is always set to the _next_ frame. This function has no
  58648. + * effect on non-periodic transfers.
  58649. + *
  58650. + * @param core_if Programming view of DWC_otg controller.
  58651. + * @param hc Identifies the host channel to set up and its properties.
  58652. + * @param hcchar Current value of the HCCHAR register for the specified host
  58653. + * channel.
  58654. + */
  58655. +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  58656. + dwc_hc_t * hc, hcchar_data_t * hcchar)
  58657. +{
  58658. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58659. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58660. + hfnum_data_t hfnum;
  58661. + hfnum.d32 =
  58662. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  58663. +
  58664. + /* 1 if _next_ frame is odd, 0 if it's even */
  58665. + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  58666. +#ifdef DEBUG
  58667. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  58668. + && !hc->complete_split) {
  58669. + switch (hfnum.b.frnum & 0x7) {
  58670. + case 7:
  58671. + core_if->hfnum_7_samples++;
  58672. + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  58673. + break;
  58674. + case 0:
  58675. + core_if->hfnum_0_samples++;
  58676. + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  58677. + break;
  58678. + default:
  58679. + core_if->hfnum_other_samples++;
  58680. + core_if->hfnum_other_frrem_accum +=
  58681. + hfnum.b.frrem;
  58682. + break;
  58683. + }
  58684. + }
  58685. +#endif
  58686. + }
  58687. +}
  58688. +
  58689. +#ifdef DEBUG
  58690. +void hc_xfer_timeout(void *ptr)
  58691. +{
  58692. + hc_xfer_info_t *xfer_info = NULL;
  58693. + int hc_num = 0;
  58694. +
  58695. + if (ptr)
  58696. + xfer_info = (hc_xfer_info_t *) ptr;
  58697. +
  58698. + if (!xfer_info->hc) {
  58699. + DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  58700. + return;
  58701. + }
  58702. +
  58703. + hc_num = xfer_info->hc->hc_num;
  58704. + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  58705. + DWC_WARN(" start_hcchar_val 0x%08x\n",
  58706. + xfer_info->core_if->start_hcchar_val[hc_num]);
  58707. +}
  58708. +#endif
  58709. +
  58710. +void ep_xfer_timeout(void *ptr)
  58711. +{
  58712. + ep_xfer_info_t *xfer_info = NULL;
  58713. + int ep_num = 0;
  58714. + dctl_data_t dctl = {.d32 = 0 };
  58715. + gintsts_data_t gintsts = {.d32 = 0 };
  58716. + gintmsk_data_t gintmsk = {.d32 = 0 };
  58717. +
  58718. + if (ptr)
  58719. + xfer_info = (ep_xfer_info_t *) ptr;
  58720. +
  58721. + if (!xfer_info->ep) {
  58722. + DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  58723. + return;
  58724. + }
  58725. +
  58726. + ep_num = xfer_info->ep->num;
  58727. + DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  58728. + /* Put the sate to 2 as it was time outed */
  58729. + xfer_info->state = 2;
  58730. +
  58731. + dctl.d32 =
  58732. + DWC_READ_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl);
  58733. + gintsts.d32 =
  58734. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintsts);
  58735. + gintmsk.d32 =
  58736. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintmsk);
  58737. +
  58738. + if (!gintmsk.b.goutnakeff) {
  58739. + /* Unmask it */
  58740. + gintmsk.b.goutnakeff = 1;
  58741. + DWC_WRITE_REG32(&xfer_info->core_if->core_global_regs->gintmsk,
  58742. + gintmsk.d32);
  58743. +
  58744. + }
  58745. +
  58746. + if (!gintsts.b.goutnakeff) {
  58747. + dctl.b.sgoutnak = 1;
  58748. + }
  58749. + DWC_WRITE_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl,
  58750. + dctl.d32);
  58751. +
  58752. +}
  58753. +
  58754. +void set_pid_isoc(dwc_hc_t * hc)
  58755. +{
  58756. + /* Set up the initial PID for the transfer. */
  58757. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  58758. + if (hc->ep_is_in) {
  58759. + if (hc->multi_count == 1) {
  58760. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  58761. + } else if (hc->multi_count == 2) {
  58762. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  58763. + } else {
  58764. + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  58765. + }
  58766. + } else {
  58767. + if (hc->multi_count == 1) {
  58768. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  58769. + } else {
  58770. + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  58771. + }
  58772. + }
  58773. + } else {
  58774. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  58775. + }
  58776. +}
  58777. +
  58778. +/**
  58779. + * This function does the setup for a data transfer for a host channel and
  58780. + * starts the transfer. May be called in either Slave mode or DMA mode. In
  58781. + * Slave mode, the caller must ensure that there is sufficient space in the
  58782. + * request queue and Tx Data FIFO.
  58783. + *
  58784. + * For an OUT transfer in Slave mode, it loads a data packet into the
  58785. + * appropriate FIFO. If necessary, additional data packets will be loaded in
  58786. + * the Host ISR.
  58787. + *
  58788. + * For an IN transfer in Slave mode, a data packet is requested. The data
  58789. + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  58790. + * additional data packets are requested in the Host ISR.
  58791. + *
  58792. + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  58793. + * register along with a packet count of 1 and the channel is enabled. This
  58794. + * causes a single PING transaction to occur. Other fields in HCTSIZ are
  58795. + * simply set to 0 since no data transfer occurs in this case.
  58796. + *
  58797. + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  58798. + * all the information required to perform the subsequent data transfer. In
  58799. + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  58800. + * controller performs the entire PING protocol, then starts the data
  58801. + * transfer.
  58802. + *
  58803. + * @param core_if Programming view of DWC_otg controller.
  58804. + * @param hc Information needed to initialize the host channel. The xfer_len
  58805. + * value may be reduced to accommodate the max widths of the XferSize and
  58806. + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  58807. + * to reflect the final xfer_len value.
  58808. + */
  58809. +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58810. +{
  58811. + hcchar_data_t hcchar;
  58812. + hctsiz_data_t hctsiz;
  58813. + uint16_t num_packets;
  58814. + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  58815. + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  58816. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58817. +
  58818. + hctsiz.d32 = 0;
  58819. +
  58820. + if (hc->do_ping) {
  58821. + if (!core_if->dma_enable) {
  58822. + dwc_otg_hc_do_ping(core_if, hc);
  58823. + hc->xfer_started = 1;
  58824. + return;
  58825. + } else {
  58826. + hctsiz.b.dopng = 1;
  58827. + }
  58828. + }
  58829. +
  58830. + if (hc->do_split) {
  58831. + num_packets = 1;
  58832. +
  58833. + if (hc->complete_split && !hc->ep_is_in) {
  58834. + /* For CSPLIT OUT Transfer, set the size to 0 so the
  58835. + * core doesn't expect any data written to the FIFO */
  58836. + hc->xfer_len = 0;
  58837. + } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  58838. + hc->xfer_len = hc->max_packet;
  58839. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  58840. + hc->xfer_len = 188;
  58841. + }
  58842. +
  58843. + hctsiz.b.xfersize = hc->xfer_len;
  58844. + } else {
  58845. + /*
  58846. + * Ensure that the transfer length and packet count will fit
  58847. + * in the widths allocated for them in the HCTSIZn register.
  58848. + */
  58849. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58850. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58851. + /*
  58852. + * Make sure the transfer size is no larger than one
  58853. + * (micro)frame's worth of data. (A check was done
  58854. + * when the periodic transfer was accepted to ensure
  58855. + * that a (micro)frame's worth of data can be
  58856. + * programmed into a channel.)
  58857. + */
  58858. + uint32_t max_periodic_len =
  58859. + hc->multi_count * hc->max_packet;
  58860. + if (hc->xfer_len > max_periodic_len) {
  58861. + hc->xfer_len = max_periodic_len;
  58862. + } else {
  58863. + }
  58864. + } else if (hc->xfer_len > max_hc_xfer_size) {
  58865. + /* Make sure that xfer_len is a multiple of max packet size. */
  58866. + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  58867. + }
  58868. +
  58869. + if (hc->xfer_len > 0) {
  58870. + num_packets =
  58871. + (hc->xfer_len + hc->max_packet -
  58872. + 1) / hc->max_packet;
  58873. + if (num_packets > max_hc_pkt_count) {
  58874. + num_packets = max_hc_pkt_count;
  58875. + hc->xfer_len = num_packets * hc->max_packet;
  58876. + }
  58877. + } else {
  58878. + /* Need 1 packet for transfer length of 0. */
  58879. + num_packets = 1;
  58880. + }
  58881. +
  58882. + if (hc->ep_is_in) {
  58883. + /* Always program an integral # of max packets for IN transfers. */
  58884. + hc->xfer_len = num_packets * hc->max_packet;
  58885. + }
  58886. +
  58887. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58888. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58889. + /*
  58890. + * Make sure that the multi_count field matches the
  58891. + * actual transfer length.
  58892. + */
  58893. + hc->multi_count = num_packets;
  58894. + }
  58895. +
  58896. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  58897. + set_pid_isoc(hc);
  58898. +
  58899. + hctsiz.b.xfersize = hc->xfer_len;
  58900. + }
  58901. +
  58902. + hc->start_pkt_count = num_packets;
  58903. + hctsiz.b.pktcnt = num_packets;
  58904. + hctsiz.b.pid = hc->data_pid_start;
  58905. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58906. +
  58907. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58908. + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  58909. + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  58910. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  58911. +
  58912. + if (core_if->dma_enable) {
  58913. + dwc_dma_t dma_addr;
  58914. + if (hc->align_buff) {
  58915. + dma_addr = hc->align_buff;
  58916. + } else {
  58917. + dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  58918. + }
  58919. + DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  58920. + }
  58921. +
  58922. + /* Start the split */
  58923. + if (hc->do_split) {
  58924. + hcsplt_data_t hcsplt;
  58925. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  58926. + hcsplt.b.spltena = 1;
  58927. + DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  58928. + }
  58929. +
  58930. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58931. + hcchar.b.multicnt = hc->multi_count;
  58932. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58933. +#ifdef DEBUG
  58934. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  58935. + if (hcchar.b.chdis) {
  58936. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  58937. + __func__, hc->hc_num, hcchar.d32);
  58938. + }
  58939. +#endif
  58940. +
  58941. + /* Set host channel enable after all other setup is complete. */
  58942. + hcchar.b.chen = 1;
  58943. + hcchar.b.chdis = 0;
  58944. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58945. +
  58946. + hc->xfer_started = 1;
  58947. + hc->requests++;
  58948. +
  58949. + if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  58950. + /* Load OUT packet into the appropriate Tx FIFO. */
  58951. + dwc_otg_hc_write_packet(core_if, hc);
  58952. + }
  58953. +#ifdef DEBUG
  58954. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  58955. + DWC_DEBUGPL(DBG_HCDV, "transfer %d from core_if %p\n",
  58956. + hc->hc_num, core_if);//GRAYG
  58957. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  58958. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  58959. +
  58960. + /* Start a timer for this transfer. */
  58961. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  58962. + }
  58963. +#endif
  58964. +}
  58965. +
  58966. +/**
  58967. + * This function does the setup for a data transfer for a host channel
  58968. + * and starts the transfer in Descriptor DMA mode.
  58969. + *
  58970. + * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  58971. + * Sets PID and NTD values. For periodic transfers
  58972. + * initializes SCHED_INFO field with micro-frame bitmap.
  58973. + *
  58974. + * Initializes HCDMA register with descriptor list address and CTD value
  58975. + * then starts the transfer via enabling the channel.
  58976. + *
  58977. + * @param core_if Programming view of DWC_otg controller.
  58978. + * @param hc Information needed to initialize the host channel.
  58979. + */
  58980. +void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58981. +{
  58982. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58983. + hcchar_data_t hcchar;
  58984. + hctsiz_data_t hctsiz;
  58985. + hcdma_data_t hcdma;
  58986. +
  58987. + hctsiz.d32 = 0;
  58988. +
  58989. + if (hc->do_ping)
  58990. + hctsiz.b_ddma.dopng = 1;
  58991. +
  58992. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  58993. + set_pid_isoc(hc);
  58994. +
  58995. + /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  58996. + hctsiz.b_ddma.pid = hc->data_pid_start;
  58997. + hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  58998. + hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  58999. +
  59000. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  59001. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  59002. + DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  59003. +
  59004. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  59005. +
  59006. + hcdma.d32 = 0;
  59007. + hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  59008. +
  59009. + /* Always start from first descriptor. */
  59010. + hcdma.b.ctd = 0;
  59011. + DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  59012. +
  59013. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59014. + hcchar.b.multicnt = hc->multi_count;
  59015. +
  59016. +#ifdef DEBUG
  59017. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  59018. + if (hcchar.b.chdis) {
  59019. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  59020. + __func__, hc->hc_num, hcchar.d32);
  59021. + }
  59022. +#endif
  59023. +
  59024. + /* Set host channel enable after all other setup is complete. */
  59025. + hcchar.b.chen = 1;
  59026. + hcchar.b.chdis = 0;
  59027. +
  59028. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  59029. +
  59030. + hc->xfer_started = 1;
  59031. + hc->requests++;
  59032. +
  59033. +#ifdef DEBUG
  59034. + if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  59035. + && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  59036. + DWC_DEBUGPL(DBG_HCDV, "DMA transfer %d from core_if %p\n",
  59037. + hc->hc_num, core_if);//GRAYG
  59038. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  59039. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  59040. + /* Start a timer for this transfer. */
  59041. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  59042. + }
  59043. +#endif
  59044. +
  59045. +}
  59046. +
  59047. +/**
  59048. + * This function continues a data transfer that was started by previous call
  59049. + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  59050. + * sufficient space in the request queue and Tx Data FIFO. This function
  59051. + * should only be called in Slave mode. In DMA mode, the controller acts
  59052. + * autonomously to complete transfers programmed to a host channel.
  59053. + *
  59054. + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  59055. + * if there is any data remaining to be queued. For an IN transfer, another
  59056. + * data packet is always requested. For the SETUP phase of a control transfer,
  59057. + * this function does nothing.
  59058. + *
  59059. + * @return 1 if a new request is queued, 0 if no more requests are required
  59060. + * for this transfer.
  59061. + */
  59062. +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  59063. +{
  59064. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  59065. +
  59066. + if (hc->do_split) {
  59067. + /* SPLITs always queue just once per channel */
  59068. + return 0;
  59069. + } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  59070. + /* SETUPs are queued only once since they can't be NAKed. */
  59071. + return 0;
  59072. + } else if (hc->ep_is_in) {
  59073. + /*
  59074. + * Always queue another request for other IN transfers. If
  59075. + * back-to-back INs are issued and NAKs are received for both,
  59076. + * the driver may still be processing the first NAK when the
  59077. + * second NAK is received. When the interrupt handler clears
  59078. + * the NAK interrupt for the first NAK, the second NAK will
  59079. + * not be seen. So we can't depend on the NAK interrupt
  59080. + * handler to requeue a NAKed request. Instead, IN requests
  59081. + * are issued each time this function is called. When the
  59082. + * transfer completes, the extra requests for the channel will
  59083. + * be flushed.
  59084. + */
  59085. + hcchar_data_t hcchar;
  59086. + dwc_otg_hc_regs_t *hc_regs =
  59087. + core_if->host_if->hc_regs[hc->hc_num];
  59088. +
  59089. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59090. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  59091. + hcchar.b.chen = 1;
  59092. + hcchar.b.chdis = 0;
  59093. + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  59094. + hcchar.d32);
  59095. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  59096. + hc->requests++;
  59097. + return 1;
  59098. + } else {
  59099. + /* OUT transfers. */
  59100. + if (hc->xfer_count < hc->xfer_len) {
  59101. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  59102. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  59103. + hcchar_data_t hcchar;
  59104. + dwc_otg_hc_regs_t *hc_regs;
  59105. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  59106. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59107. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  59108. + }
  59109. +
  59110. + /* Load OUT packet into the appropriate Tx FIFO. */
  59111. + dwc_otg_hc_write_packet(core_if, hc);
  59112. + hc->requests++;
  59113. + return 1;
  59114. + } else {
  59115. + return 0;
  59116. + }
  59117. + }
  59118. +}
  59119. +
  59120. +/**
  59121. + * Starts a PING transfer. This function should only be called in Slave mode.
  59122. + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  59123. + */
  59124. +void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  59125. +{
  59126. + hcchar_data_t hcchar;
  59127. + hctsiz_data_t hctsiz;
  59128. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  59129. +
  59130. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  59131. +
  59132. + hctsiz.d32 = 0;
  59133. + hctsiz.b.dopng = 1;
  59134. + hctsiz.b.pktcnt = 1;
  59135. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  59136. +
  59137. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59138. + hcchar.b.chen = 1;
  59139. + hcchar.b.chdis = 0;
  59140. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  59141. +}
  59142. +
  59143. +/*
  59144. + * This function writes a packet into the Tx FIFO associated with the Host
  59145. + * Channel. For a channel associated with a non-periodic EP, the non-periodic
  59146. + * Tx FIFO is written. For a channel associated with a periodic EP, the
  59147. + * periodic Tx FIFO is written. This function should only be called in Slave
  59148. + * mode.
  59149. + *
  59150. + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  59151. + * then number of bytes written to the Tx FIFO.
  59152. + */
  59153. +void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  59154. +{
  59155. + uint32_t i;
  59156. + uint32_t remaining_count;
  59157. + uint32_t byte_count;
  59158. + uint32_t dword_count;
  59159. +
  59160. + uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  59161. + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  59162. +
  59163. + remaining_count = hc->xfer_len - hc->xfer_count;
  59164. + if (remaining_count > hc->max_packet) {
  59165. + byte_count = hc->max_packet;
  59166. + } else {
  59167. + byte_count = remaining_count;
  59168. + }
  59169. +
  59170. + dword_count = (byte_count + 3) / 4;
  59171. +
  59172. + if ((((unsigned long)data_buff) & 0x3) == 0) {
  59173. + /* xfer_buff is DWORD aligned. */
  59174. + for (i = 0; i < dword_count; i++, data_buff++) {
  59175. + DWC_WRITE_REG32(data_fifo, *data_buff);
  59176. + }
  59177. + } else {
  59178. + /* xfer_buff is not DWORD aligned. */
  59179. + for (i = 0; i < dword_count; i++, data_buff++) {
  59180. + uint32_t data;
  59181. + data =
  59182. + (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  59183. + 16 | data_buff[3] << 24);
  59184. + DWC_WRITE_REG32(data_fifo, data);
  59185. + }
  59186. + }
  59187. +
  59188. + hc->xfer_count += byte_count;
  59189. + hc->xfer_buff += byte_count;
  59190. +}
  59191. +
  59192. +/**
  59193. + * Gets the current USB frame number. This is the frame number from the last
  59194. + * SOF packet.
  59195. + */
  59196. +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  59197. +{
  59198. + dsts_data_t dsts;
  59199. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  59200. +
  59201. + /* read current frame/microframe number from DSTS register */
  59202. + return dsts.b.soffn;
  59203. +}
  59204. +
  59205. +/**
  59206. + * Calculates and gets the frame Interval value of HFIR register according PHY
  59207. + * type and speed.The application can modify a value of HFIR register only after
  59208. + * the Port Enable bit of the Host Port Control and Status register
  59209. + * (HPRT.PrtEnaPort) has been set.
  59210. +*/
  59211. +
  59212. +uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  59213. +{
  59214. + gusbcfg_data_t usbcfg;
  59215. + hwcfg2_data_t hwcfg2;
  59216. + hprt0_data_t hprt0;
  59217. + int clock = 60; // default value
  59218. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  59219. + hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  59220. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  59221. + if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  59222. + clock = 60;
  59223. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  59224. + clock = 48;
  59225. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  59226. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  59227. + clock = 30;
  59228. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  59229. + !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  59230. + clock = 60;
  59231. + if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  59232. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  59233. + clock = 48;
  59234. + if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  59235. + clock = 48;
  59236. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  59237. + clock = 48;
  59238. + if (hprt0.b.prtspd == 0)
  59239. + /* High speed case */
  59240. + return 125 * clock;
  59241. + else
  59242. + /* FS/LS case */
  59243. + return 1000 * clock;
  59244. +}
  59245. +
  59246. +/**
  59247. + * This function reads a setup packet from the Rx FIFO into the destination
  59248. + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  59249. + * Interrupt routine when a SETUP packet has been received in Slave mode.
  59250. + *
  59251. + * @param core_if Programming view of DWC_otg controller.
  59252. + * @param dest Destination buffer for packet data.
  59253. + */
  59254. +void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  59255. +{
  59256. + device_grxsts_data_t status;
  59257. + /* Get the 8 bytes of a setup transaction data */
  59258. +
  59259. + /* Pop 2 DWORDS off the receive data FIFO into memory */
  59260. + dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  59261. + dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  59262. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  59263. + status.d32 =
  59264. + DWC_READ_REG32(&core_if->core_global_regs->grxstsp);
  59265. + DWC_DEBUGPL(DBG_ANY,
  59266. + "EP:%d BCnt:%d " "pktsts:%x Frame:%d(0x%0x)\n",
  59267. + status.b.epnum, status.b.bcnt, status.b.pktsts,
  59268. + status.b.fn, status.b.fn);
  59269. + }
  59270. +}
  59271. +
  59272. +/**
  59273. + * This function enables EP0 OUT to receive SETUP packets and configures EP0
  59274. + * IN for transmitting packets. It is normally called when the
  59275. + * "Enumeration Done" interrupt occurs.
  59276. + *
  59277. + * @param core_if Programming view of DWC_otg controller.
  59278. + * @param ep The EP0 data.
  59279. + */
  59280. +void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59281. +{
  59282. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  59283. + dsts_data_t dsts;
  59284. + depctl_data_t diepctl;
  59285. + depctl_data_t doepctl;
  59286. + dctl_data_t dctl = {.d32 = 0 };
  59287. +
  59288. + ep->stp_rollover = 0;
  59289. + /* Read the Device Status and Endpoint 0 Control registers */
  59290. + dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  59291. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  59292. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  59293. +
  59294. + /* Set the MPS of the IN EP based on the enumeration speed */
  59295. + switch (dsts.b.enumspd) {
  59296. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  59297. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  59298. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  59299. + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  59300. + break;
  59301. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  59302. + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  59303. + break;
  59304. + }
  59305. +
  59306. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  59307. +
  59308. + /* Enable OUT EP for receive */
  59309. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  59310. + doepctl.b.epena = 1;
  59311. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  59312. + }
  59313. +#ifdef VERBOSE
  59314. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  59315. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  59316. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  59317. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  59318. +#endif
  59319. + dctl.b.cgnpinnak = 1;
  59320. +
  59321. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  59322. + DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  59323. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  59324. +
  59325. +}
  59326. +
  59327. +/**
  59328. + * This function activates an EP. The Device EP control register for
  59329. + * the EP is configured as defined in the ep structure. Note: This
  59330. + * function is not used for EP0.
  59331. + *
  59332. + * @param core_if Programming view of DWC_otg controller.
  59333. + * @param ep The EP to activate.
  59334. + */
  59335. +void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59336. +{
  59337. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  59338. + depctl_data_t depctl;
  59339. + volatile uint32_t *addr;
  59340. + daint_data_t daintmsk = {.d32 = 0 };
  59341. + dcfg_data_t dcfg;
  59342. + uint8_t i;
  59343. +
  59344. + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  59345. + (ep->is_in ? "IN" : "OUT"));
  59346. +
  59347. +#ifdef DWC_UTE_PER_IO
  59348. + ep->xiso_frame_num = 0xFFFFFFFF;
  59349. + ep->xiso_active_xfers = 0;
  59350. + ep->xiso_queued_xfers = 0;
  59351. +#endif
  59352. + /* Read DEPCTLn register */
  59353. + if (ep->is_in == 1) {
  59354. + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  59355. + daintmsk.ep.in = 1 << ep->num;
  59356. + } else {
  59357. + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  59358. + daintmsk.ep.out = 1 << ep->num;
  59359. + }
  59360. +
  59361. + /* If the EP is already active don't change the EP Control
  59362. + * register. */
  59363. + depctl.d32 = DWC_READ_REG32(addr);
  59364. + if (!depctl.b.usbactep) {
  59365. + depctl.b.mps = ep->maxpacket;
  59366. + depctl.b.eptype = ep->type;
  59367. + depctl.b.txfnum = ep->tx_fifo_num;
  59368. +
  59369. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59370. + depctl.b.setd0pid = 1; // ???
  59371. + } else {
  59372. + depctl.b.setd0pid = 1;
  59373. + }
  59374. + depctl.b.usbactep = 1;
  59375. +
  59376. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  59377. + if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  59378. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59379. + if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  59380. + break;
  59381. + }
  59382. + core_if->nextep_seq[i] = ep->num;
  59383. + core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  59384. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59385. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  59386. + dcfg.b.epmscnt++;
  59387. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  59388. +
  59389. + DWC_DEBUGPL(DBG_PCDV,
  59390. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  59391. + __func__, core_if->first_in_nextep_seq);
  59392. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  59393. + DWC_DEBUGPL(DBG_PCDV, "%2d\n",
  59394. + core_if->nextep_seq[i]);
  59395. + }
  59396. +
  59397. + }
  59398. +
  59399. +
  59400. + DWC_WRITE_REG32(addr, depctl.d32);
  59401. + DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  59402. + }
  59403. +
  59404. + /* Enable the Interrupt for this EP */
  59405. + if (core_if->multiproc_int_enable) {
  59406. + if (ep->is_in == 1) {
  59407. + diepmsk_data_t diepmsk = {.d32 = 0 };
  59408. + diepmsk.b.xfercompl = 1;
  59409. + diepmsk.b.timeout = 1;
  59410. + diepmsk.b.epdisabled = 1;
  59411. + diepmsk.b.ahberr = 1;
  59412. + diepmsk.b.intknepmis = 1;
  59413. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  59414. + diepmsk.b.intknepmis = 0;
  59415. + diepmsk.b.txfifoundrn = 1; //?????
  59416. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59417. + diepmsk.b.nak = 1;
  59418. + }
  59419. +
  59420. +
  59421. +
  59422. +/*
  59423. + if (core_if->dma_desc_enable) {
  59424. + diepmsk.b.bna = 1;
  59425. + }
  59426. +*/
  59427. +/*
  59428. + if (core_if->dma_enable) {
  59429. + doepmsk.b.nak = 1;
  59430. + }
  59431. +*/
  59432. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  59433. + diepeachintmsk[ep->num], diepmsk.d32);
  59434. +
  59435. + } else {
  59436. + doepmsk_data_t doepmsk = {.d32 = 0 };
  59437. + doepmsk.b.xfercompl = 1;
  59438. + doepmsk.b.ahberr = 1;
  59439. + doepmsk.b.epdisabled = 1;
  59440. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  59441. + doepmsk.b.outtknepdis = 1;
  59442. +
  59443. +/*
  59444. +
  59445. + if (core_if->dma_desc_enable) {
  59446. + doepmsk.b.bna = 1;
  59447. + }
  59448. +*/
  59449. +/*
  59450. + doepmsk.b.babble = 1;
  59451. + doepmsk.b.nyet = 1;
  59452. + doepmsk.b.nak = 1;
  59453. +*/
  59454. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  59455. + doepeachintmsk[ep->num], doepmsk.d32);
  59456. + }
  59457. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  59458. + 0, daintmsk.d32);
  59459. + } else {
  59460. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59461. + if (ep->is_in) {
  59462. + diepmsk_data_t diepmsk = {.d32 = 0 };
  59463. + diepmsk.b.nak = 1;
  59464. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  59465. + } else {
  59466. + doepmsk_data_t doepmsk = {.d32 = 0 };
  59467. + doepmsk.b.outtknepdis = 1;
  59468. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  59469. + }
  59470. + }
  59471. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  59472. + 0, daintmsk.d32);
  59473. + }
  59474. +
  59475. + DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  59476. + DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  59477. +
  59478. + ep->stall_clear_flag = 0;
  59479. +
  59480. + return;
  59481. +}
  59482. +
  59483. +/**
  59484. + * This function deactivates an EP. This is done by clearing the USB Active
  59485. + * EP bit in the Device EP control register. Note: This function is not used
  59486. + * for EP0. EP0 cannot be deactivated.
  59487. + *
  59488. + * @param core_if Programming view of DWC_otg controller.
  59489. + * @param ep The EP to deactivate.
  59490. + */
  59491. +void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59492. +{
  59493. + depctl_data_t depctl = {.d32 = 0 };
  59494. + volatile uint32_t *addr;
  59495. + daint_data_t daintmsk = {.d32 = 0 };
  59496. + dcfg_data_t dcfg;
  59497. + uint8_t i = 0;
  59498. +
  59499. +#ifdef DWC_UTE_PER_IO
  59500. + ep->xiso_frame_num = 0xFFFFFFFF;
  59501. + ep->xiso_active_xfers = 0;
  59502. + ep->xiso_queued_xfers = 0;
  59503. +#endif
  59504. +
  59505. + /* Read DEPCTLn register */
  59506. + if (ep->is_in == 1) {
  59507. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  59508. + daintmsk.ep.in = 1 << ep->num;
  59509. + } else {
  59510. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  59511. + daintmsk.ep.out = 1 << ep->num;
  59512. + }
  59513. +
  59514. + depctl.d32 = DWC_READ_REG32(addr);
  59515. +
  59516. + depctl.b.usbactep = 0;
  59517. +
  59518. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  59519. + if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  59520. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59521. + if (core_if->nextep_seq[i] == ep->num)
  59522. + break;
  59523. + }
  59524. + core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  59525. + if (core_if->first_in_nextep_seq == ep->num)
  59526. + core_if->first_in_nextep_seq = i;
  59527. + core_if->nextep_seq[ep->num] = 0xff;
  59528. + depctl.b.nextep = 0;
  59529. + dcfg.d32 =
  59530. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  59531. + dcfg.b.epmscnt--;
  59532. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  59533. + dcfg.d32);
  59534. +
  59535. + DWC_DEBUGPL(DBG_PCDV,
  59536. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  59537. + __func__, core_if->first_in_nextep_seq);
  59538. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  59539. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  59540. + }
  59541. + }
  59542. +
  59543. + if (ep->is_in == 1)
  59544. + depctl.b.txfnum = 0;
  59545. +
  59546. + if (core_if->dma_desc_enable)
  59547. + depctl.b.epdis = 1;
  59548. +
  59549. + DWC_WRITE_REG32(addr, depctl.d32);
  59550. + depctl.d32 = DWC_READ_REG32(addr);
  59551. + if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC
  59552. + && depctl.b.epena) {
  59553. + depctl_data_t depctl = {.d32 = 0};
  59554. + if (ep->is_in) {
  59555. + diepint_data_t diepint = {.d32 = 0};
  59556. +
  59557. + depctl.b.snak = 1;
  59558. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59559. + diepctl, depctl.d32);
  59560. + do {
  59561. + dwc_udelay(10);
  59562. + diepint.d32 =
  59563. + DWC_READ_REG32(&core_if->
  59564. + dev_if->in_ep_regs[ep->num]->
  59565. + diepint);
  59566. + } while (!diepint.b.inepnakeff);
  59567. + diepint.b.inepnakeff = 1;
  59568. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59569. + diepint, diepint.d32);
  59570. + depctl.d32 = 0;
  59571. + depctl.b.epdis = 1;
  59572. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59573. + diepctl, depctl.d32);
  59574. + do {
  59575. + dwc_udelay(10);
  59576. + diepint.d32 =
  59577. + DWC_READ_REG32(&core_if->
  59578. + dev_if->in_ep_regs[ep->num]->
  59579. + diepint);
  59580. + } while (!diepint.b.epdisabled);
  59581. + diepint.b.epdisabled = 1;
  59582. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59583. + diepint, diepint.d32);
  59584. + } else {
  59585. + dctl_data_t dctl = {.d32 = 0};
  59586. + gintmsk_data_t gintsts = {.d32 = 0};
  59587. + doepint_data_t doepint = {.d32 = 0};
  59588. + dctl.b.sgoutnak = 1;
  59589. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  59590. + dctl, 0, dctl.d32);
  59591. + do {
  59592. + dwc_udelay(10);
  59593. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  59594. + } while (!gintsts.b.goutnakeff);
  59595. + gintsts.d32 = 0;
  59596. + gintsts.b.goutnakeff = 1;
  59597. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  59598. +
  59599. + depctl.d32 = 0;
  59600. + depctl.b.epdis = 1;
  59601. + depctl.b.snak = 1;
  59602. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  59603. + do
  59604. + {
  59605. + dwc_udelay(10);
  59606. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  59607. + out_ep_regs[ep->num]->doepint);
  59608. + } while (!doepint.b.epdisabled);
  59609. +
  59610. + doepint.b.epdisabled = 1;
  59611. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  59612. +
  59613. + dctl.d32 = 0;
  59614. + dctl.b.cgoutnak = 1;
  59615. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  59616. + }
  59617. + }
  59618. +
  59619. + /* Disable the Interrupt for this EP */
  59620. + if (core_if->multiproc_int_enable) {
  59621. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  59622. + daintmsk.d32, 0);
  59623. +
  59624. + if (ep->is_in == 1) {
  59625. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  59626. + diepeachintmsk[ep->num], 0);
  59627. + } else {
  59628. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  59629. + doepeachintmsk[ep->num], 0);
  59630. + }
  59631. + } else {
  59632. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  59633. + daintmsk.d32, 0);
  59634. + }
  59635. +
  59636. +}
  59637. +
  59638. +/**
  59639. + * This function initializes dma descriptor chain.
  59640. + *
  59641. + * @param core_if Programming view of DWC_otg controller.
  59642. + * @param ep The EP to start the transfer on.
  59643. + */
  59644. +static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59645. +{
  59646. + dwc_otg_dev_dma_desc_t *dma_desc;
  59647. + uint32_t offset;
  59648. + uint32_t xfer_est;
  59649. + int i;
  59650. + unsigned maxxfer_local, total_len;
  59651. +
  59652. + if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  59653. + (ep->maxpacket%4)) {
  59654. + maxxfer_local = ep->maxpacket;
  59655. + total_len = ep->xfer_len;
  59656. + } else {
  59657. + maxxfer_local = ep->maxxfer;
  59658. + total_len = ep->total_len;
  59659. + }
  59660. +
  59661. + ep->desc_cnt = (total_len / maxxfer_local) +
  59662. + ((total_len % maxxfer_local) ? 1 : 0);
  59663. +
  59664. + if (!ep->desc_cnt)
  59665. + ep->desc_cnt = 1;
  59666. +
  59667. + if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  59668. + ep->desc_cnt = MAX_DMA_DESC_CNT;
  59669. +
  59670. + dma_desc = ep->desc_addr;
  59671. + if (maxxfer_local == ep->maxpacket) {
  59672. + if ((total_len % maxxfer_local) &&
  59673. + (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  59674. + xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  59675. + (total_len % maxxfer_local);
  59676. + } else
  59677. + xfer_est = ep->desc_cnt * maxxfer_local;
  59678. + } else
  59679. + xfer_est = total_len;
  59680. + offset = 0;
  59681. + for (i = 0; i < ep->desc_cnt; ++i) {
  59682. + /** DMA Descriptor Setup */
  59683. + if (xfer_est > maxxfer_local) {
  59684. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59685. + dma_desc->status.b.l = 0;
  59686. + dma_desc->status.b.ioc = 0;
  59687. + dma_desc->status.b.sp = 0;
  59688. + dma_desc->status.b.bytes = maxxfer_local;
  59689. + dma_desc->buf = ep->dma_addr + offset;
  59690. + dma_desc->status.b.sts = 0;
  59691. + dma_desc->status.b.bs = BS_HOST_READY;
  59692. +
  59693. + xfer_est -= maxxfer_local;
  59694. + offset += maxxfer_local;
  59695. + } else {
  59696. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59697. + dma_desc->status.b.l = 1;
  59698. + dma_desc->status.b.ioc = 1;
  59699. + if (ep->is_in) {
  59700. + dma_desc->status.b.sp =
  59701. + (xfer_est %
  59702. + ep->maxpacket) ? 1 : ((ep->
  59703. + sent_zlp) ? 1 : 0);
  59704. + dma_desc->status.b.bytes = xfer_est;
  59705. + } else {
  59706. + if (maxxfer_local == ep->maxpacket)
  59707. + dma_desc->status.b.bytes = xfer_est;
  59708. + else
  59709. + dma_desc->status.b.bytes =
  59710. + xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  59711. + }
  59712. +
  59713. + dma_desc->buf = ep->dma_addr + offset;
  59714. + dma_desc->status.b.sts = 0;
  59715. + dma_desc->status.b.bs = BS_HOST_READY;
  59716. + }
  59717. + dma_desc++;
  59718. + }
  59719. +}
  59720. +/**
  59721. + * This function is called when to write ISOC data into appropriate dedicated
  59722. + * periodic FIFO.
  59723. + */
  59724. +static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  59725. +{
  59726. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  59727. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  59728. + dtxfsts_data_t txstatus = {.d32 = 0 };
  59729. + uint32_t len = 0;
  59730. + int epnum = dwc_ep->num;
  59731. + int dwords;
  59732. +
  59733. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  59734. +
  59735. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  59736. +
  59737. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  59738. +
  59739. + if (len > dwc_ep->maxpacket) {
  59740. + len = dwc_ep->maxpacket;
  59741. + }
  59742. +
  59743. + dwords = (len + 3) / 4;
  59744. +
  59745. + /* While there is space in the queue and space in the FIFO and
  59746. + * More data to tranfer, Write packets to the Tx FIFO */
  59747. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  59748. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  59749. +
  59750. + while (txstatus.b.txfspcavail > dwords &&
  59751. + dwc_ep->xfer_count < dwc_ep->xfer_len && dwc_ep->xfer_len != 0) {
  59752. + /* Write the FIFO */
  59753. + dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  59754. +
  59755. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  59756. + if (len > dwc_ep->maxpacket) {
  59757. + len = dwc_ep->maxpacket;
  59758. + }
  59759. +
  59760. + dwords = (len + 3) / 4;
  59761. + txstatus.d32 =
  59762. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  59763. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  59764. + txstatus.d32);
  59765. + }
  59766. +
  59767. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  59768. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  59769. +
  59770. + return 1;
  59771. +}
  59772. +/**
  59773. + * This function does the setup for a data transfer for an EP and
  59774. + * starts the transfer. For an IN transfer, the packets will be
  59775. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  59776. + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  59777. + *
  59778. + * @param core_if Programming view of DWC_otg controller.
  59779. + * @param ep The EP to start the transfer on.
  59780. + */
  59781. +
  59782. +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59783. +{
  59784. + depctl_data_t depctl;
  59785. + deptsiz_data_t deptsiz;
  59786. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59787. +
  59788. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  59789. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  59790. + "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  59791. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  59792. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  59793. + ep->total_len);
  59794. + /* IN endpoint */
  59795. + if (ep->is_in == 1) {
  59796. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59797. + core_if->dev_if->in_ep_regs[ep->num];
  59798. +
  59799. + gnptxsts_data_t gtxstatus;
  59800. +
  59801. + gtxstatus.d32 =
  59802. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  59803. +
  59804. + if (core_if->en_multiple_tx_fifo == 0
  59805. + && gtxstatus.b.nptxqspcavail == 0 && !core_if->dma_enable) {
  59806. +#ifdef DEBUG
  59807. + DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  59808. +#endif
  59809. + return;
  59810. + }
  59811. +
  59812. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  59813. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  59814. +
  59815. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  59816. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  59817. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  59818. + else
  59819. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  59820. + MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  59821. +
  59822. +
  59823. + /* Zero Length Packet? */
  59824. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  59825. + deptsiz.b.xfersize = 0;
  59826. + deptsiz.b.pktcnt = 1;
  59827. + } else {
  59828. + /* Program the transfer size and packet count
  59829. + * as follows: xfersize = N * maxpacket +
  59830. + * short_packet pktcnt = N + (short_packet
  59831. + * exist ? 1 : 0)
  59832. + */
  59833. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  59834. + deptsiz.b.pktcnt =
  59835. + (ep->xfer_len - ep->xfer_count - 1 +
  59836. + ep->maxpacket) / ep->maxpacket;
  59837. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  59838. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  59839. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  59840. + }
  59841. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  59842. + deptsiz.b.mc = deptsiz.b.pktcnt;
  59843. + }
  59844. +
  59845. + /* Write the DMA register */
  59846. + if (core_if->dma_enable) {
  59847. + if (core_if->dma_desc_enable == 0) {
  59848. + if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  59849. + deptsiz.b.mc = 1;
  59850. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59851. + deptsiz.d32);
  59852. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59853. + (uint32_t) ep->dma_addr);
  59854. + } else {
  59855. +#ifdef DWC_UTE_CFI
  59856. + /* The descriptor chain should be already initialized by now */
  59857. + if (ep->buff_mode != BM_STANDARD) {
  59858. + DWC_WRITE_REG32(&in_regs->diepdma,
  59859. + ep->descs_dma_addr);
  59860. + } else {
  59861. +#endif
  59862. + init_dma_desc_chain(core_if, ep);
  59863. + /** DIEPDMAn Register write */
  59864. + DWC_WRITE_REG32(&in_regs->diepdma,
  59865. + ep->dma_desc_addr);
  59866. +#ifdef DWC_UTE_CFI
  59867. + }
  59868. +#endif
  59869. + }
  59870. + } else {
  59871. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59872. + if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  59873. + /**
  59874. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  59875. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  59876. + * the data will be written into the fifo by the ISR.
  59877. + */
  59878. + if (core_if->en_multiple_tx_fifo == 0) {
  59879. + intr_mask.b.nptxfempty = 1;
  59880. + DWC_MODIFY_REG32
  59881. + (&core_if->core_global_regs->gintmsk,
  59882. + intr_mask.d32, intr_mask.d32);
  59883. + } else {
  59884. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59885. + if (ep->xfer_len > 0) {
  59886. + uint32_t fifoemptymsk = 0;
  59887. + fifoemptymsk = 1 << ep->num;
  59888. + DWC_MODIFY_REG32
  59889. + (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59890. + 0, fifoemptymsk);
  59891. +
  59892. + }
  59893. + }
  59894. + } else {
  59895. + write_isoc_tx_fifo(core_if, ep);
  59896. + }
  59897. + }
  59898. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59899. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59900. +
  59901. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59902. + dsts_data_t dsts = {.d32 = 0};
  59903. + if (ep->bInterval == 1) {
  59904. + dsts.d32 =
  59905. + DWC_READ_REG32(&core_if->dev_if->
  59906. + dev_global_regs->dsts);
  59907. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  59908. + if (ep->frame_num > 0x3FFF) {
  59909. + ep->frm_overrun = 1;
  59910. + ep->frame_num &= 0x3FFF;
  59911. + } else
  59912. + ep->frm_overrun = 0;
  59913. + if (ep->frame_num & 0x1) {
  59914. + depctl.b.setd1pid = 1;
  59915. + } else {
  59916. + depctl.b.setd0pid = 1;
  59917. + }
  59918. + }
  59919. + }
  59920. + /* EP enable, IN data in FIFO */
  59921. + depctl.b.cnak = 1;
  59922. + depctl.b.epena = 1;
  59923. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59924. +
  59925. + } else {
  59926. + /* OUT endpoint */
  59927. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59928. + core_if->dev_if->out_ep_regs[ep->num];
  59929. +
  59930. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  59931. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  59932. +
  59933. + if (!core_if->dma_desc_enable) {
  59934. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  59935. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  59936. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  59937. + else
  59938. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  59939. + - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  59940. + }
  59941. +
  59942. + /* Program the transfer size and packet count as follows:
  59943. + *
  59944. + * pktcnt = N
  59945. + * xfersize = N * maxpacket
  59946. + */
  59947. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  59948. + /* Zero Length Packet */
  59949. + deptsiz.b.xfersize = ep->maxpacket;
  59950. + deptsiz.b.pktcnt = 1;
  59951. + } else {
  59952. + deptsiz.b.pktcnt =
  59953. + (ep->xfer_len - ep->xfer_count +
  59954. + (ep->maxpacket - 1)) / ep->maxpacket;
  59955. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  59956. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  59957. + }
  59958. + if (!core_if->dma_desc_enable) {
  59959. + ep->xfer_len =
  59960. + deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  59961. + }
  59962. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  59963. + }
  59964. +
  59965. + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  59966. + ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  59967. +
  59968. + if (core_if->dma_enable) {
  59969. + if (!core_if->dma_desc_enable) {
  59970. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59971. + deptsiz.d32);
  59972. +
  59973. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59974. + (uint32_t) ep->dma_addr);
  59975. + } else {
  59976. +#ifdef DWC_UTE_CFI
  59977. + /* The descriptor chain should be already initialized by now */
  59978. + if (ep->buff_mode != BM_STANDARD) {
  59979. + DWC_WRITE_REG32(&out_regs->doepdma,
  59980. + ep->descs_dma_addr);
  59981. + } else {
  59982. +#endif
  59983. + /** This is used for interrupt out transfers*/
  59984. + if (!ep->xfer_len)
  59985. + ep->xfer_len = ep->total_len;
  59986. + init_dma_desc_chain(core_if, ep);
  59987. +
  59988. + if (core_if->core_params->dev_out_nak) {
  59989. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  59990. + deptsiz.b.pktcnt = (ep->total_len +
  59991. + (ep->maxpacket - 1)) / ep->maxpacket;
  59992. + deptsiz.b.xfersize = ep->total_len;
  59993. + /* Remember initial value of doeptsiz */
  59994. + core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  59995. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59996. + deptsiz.d32);
  59997. + }
  59998. + }
  59999. + /** DOEPDMAn Register write */
  60000. + DWC_WRITE_REG32(&out_regs->doepdma,
  60001. + ep->dma_desc_addr);
  60002. +#ifdef DWC_UTE_CFI
  60003. + }
  60004. +#endif
  60005. + }
  60006. + } else {
  60007. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  60008. + }
  60009. +
  60010. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  60011. + dsts_data_t dsts = {.d32 = 0};
  60012. + if (ep->bInterval == 1) {
  60013. + dsts.d32 =
  60014. + DWC_READ_REG32(&core_if->dev_if->
  60015. + dev_global_regs->dsts);
  60016. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  60017. + if (ep->frame_num > 0x3FFF) {
  60018. + ep->frm_overrun = 1;
  60019. + ep->frame_num &= 0x3FFF;
  60020. + } else
  60021. + ep->frm_overrun = 0;
  60022. +
  60023. + if (ep->frame_num & 0x1) {
  60024. + depctl.b.setd1pid = 1;
  60025. + } else {
  60026. + depctl.b.setd0pid = 1;
  60027. + }
  60028. + }
  60029. + }
  60030. +
  60031. + /* EP enable */
  60032. + depctl.b.cnak = 1;
  60033. + depctl.b.epena = 1;
  60034. +
  60035. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  60036. +
  60037. + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  60038. + DWC_READ_REG32(&out_regs->doepctl),
  60039. + DWC_READ_REG32(&out_regs->doeptsiz));
  60040. + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  60041. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  60042. + daintmsk),
  60043. + DWC_READ_REG32(&core_if->core_global_regs->
  60044. + gintmsk));
  60045. +
  60046. + /* Timer is scheduling only for out bulk transfers for
  60047. + * "Device DDMA OUT NAK Enhancement" feature to inform user
  60048. + * about received data payload in case of timeout
  60049. + */
  60050. + if (core_if->core_params->dev_out_nak) {
  60051. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  60052. + core_if->ep_xfer_info[ep->num].core_if = core_if;
  60053. + core_if->ep_xfer_info[ep->num].ep = ep;
  60054. + core_if->ep_xfer_info[ep->num].state = 1;
  60055. +
  60056. + /* Start a timer for this transfer. */
  60057. + DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  60058. + }
  60059. + }
  60060. + }
  60061. +}
  60062. +
  60063. +/**
  60064. + * This function setup a zero length transfer in Buffer DMA and
  60065. + * Slave modes for usb requests with zero field set
  60066. + *
  60067. + * @param core_if Programming view of DWC_otg controller.
  60068. + * @param ep The EP to start the transfer on.
  60069. + *
  60070. + */
  60071. +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60072. +{
  60073. +
  60074. + depctl_data_t depctl;
  60075. + deptsiz_data_t deptsiz;
  60076. + gintmsk_data_t intr_mask = {.d32 = 0 };
  60077. +
  60078. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  60079. + DWC_PRINTF("zero length transfer is called\n");
  60080. +
  60081. + /* IN endpoint */
  60082. + if (ep->is_in == 1) {
  60083. + dwc_otg_dev_in_ep_regs_t *in_regs =
  60084. + core_if->dev_if->in_ep_regs[ep->num];
  60085. +
  60086. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  60087. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  60088. +
  60089. + deptsiz.b.xfersize = 0;
  60090. + deptsiz.b.pktcnt = 1;
  60091. +
  60092. + /* Write the DMA register */
  60093. + if (core_if->dma_enable) {
  60094. + if (core_if->dma_desc_enable == 0) {
  60095. + deptsiz.b.mc = 1;
  60096. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  60097. + deptsiz.d32);
  60098. + DWC_WRITE_REG32(&(in_regs->diepdma),
  60099. + (uint32_t) ep->dma_addr);
  60100. + }
  60101. + } else {
  60102. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  60103. + /**
  60104. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  60105. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  60106. + * the data will be written into the fifo by the ISR.
  60107. + */
  60108. + if (core_if->en_multiple_tx_fifo == 0) {
  60109. + intr_mask.b.nptxfempty = 1;
  60110. + DWC_MODIFY_REG32(&core_if->
  60111. + core_global_regs->gintmsk,
  60112. + intr_mask.d32, intr_mask.d32);
  60113. + } else {
  60114. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  60115. + if (ep->xfer_len > 0) {
  60116. + uint32_t fifoemptymsk = 0;
  60117. + fifoemptymsk = 1 << ep->num;
  60118. + DWC_MODIFY_REG32(&core_if->
  60119. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  60120. + 0, fifoemptymsk);
  60121. + }
  60122. + }
  60123. + }
  60124. +
  60125. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  60126. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  60127. + /* EP enable, IN data in FIFO */
  60128. + depctl.b.cnak = 1;
  60129. + depctl.b.epena = 1;
  60130. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  60131. +
  60132. + } else {
  60133. + /* OUT endpoint */
  60134. + dwc_otg_dev_out_ep_regs_t *out_regs =
  60135. + core_if->dev_if->out_ep_regs[ep->num];
  60136. +
  60137. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  60138. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  60139. +
  60140. + /* Zero Length Packet */
  60141. + deptsiz.b.xfersize = ep->maxpacket;
  60142. + deptsiz.b.pktcnt = 1;
  60143. +
  60144. + if (core_if->dma_enable) {
  60145. + if (!core_if->dma_desc_enable) {
  60146. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  60147. + deptsiz.d32);
  60148. +
  60149. + DWC_WRITE_REG32(&(out_regs->doepdma),
  60150. + (uint32_t) ep->dma_addr);
  60151. + }
  60152. + } else {
  60153. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  60154. + }
  60155. +
  60156. + /* EP enable */
  60157. + depctl.b.cnak = 1;
  60158. + depctl.b.epena = 1;
  60159. +
  60160. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  60161. +
  60162. + }
  60163. +}
  60164. +
  60165. +/**
  60166. + * This function does the setup for a data transfer for EP0 and starts
  60167. + * the transfer. For an IN transfer, the packets will be loaded into
  60168. + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  60169. + * unloaded from the Rx FIFO in the ISR.
  60170. + *
  60171. + * @param core_if Programming view of DWC_otg controller.
  60172. + * @param ep The EP0 data.
  60173. + */
  60174. +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60175. +{
  60176. + depctl_data_t depctl;
  60177. + deptsiz0_data_t deptsiz;
  60178. + gintmsk_data_t intr_mask = {.d32 = 0 };
  60179. + dwc_otg_dev_dma_desc_t *dma_desc;
  60180. +
  60181. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  60182. + "xfer_buff=%p start_xfer_buff=%p \n",
  60183. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  60184. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  60185. +
  60186. + ep->total_len = ep->xfer_len;
  60187. +
  60188. + /* IN endpoint */
  60189. + if (ep->is_in == 1) {
  60190. + dwc_otg_dev_in_ep_regs_t *in_regs =
  60191. + core_if->dev_if->in_ep_regs[0];
  60192. +
  60193. + gnptxsts_data_t gtxstatus;
  60194. +
  60195. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  60196. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  60197. + if (depctl.b.epena)
  60198. + return;
  60199. + }
  60200. +
  60201. + gtxstatus.d32 =
  60202. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  60203. +
  60204. + /* If dedicated FIFO every time flush fifo before enable ep*/
  60205. + if (core_if->en_multiple_tx_fifo && core_if->snpsid >= OTG_CORE_REV_3_00a)
  60206. + dwc_otg_flush_tx_fifo(core_if, ep->tx_fifo_num);
  60207. +
  60208. + if (core_if->en_multiple_tx_fifo == 0
  60209. + && gtxstatus.b.nptxqspcavail == 0
  60210. + && !core_if->dma_enable) {
  60211. +#ifdef DEBUG
  60212. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  60213. + DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  60214. + DWC_READ_REG32(&in_regs->diepctl));
  60215. + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  60216. + deptsiz.d32,
  60217. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  60218. + DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  60219. + gtxstatus.d32);
  60220. +#endif
  60221. + return;
  60222. + }
  60223. +
  60224. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  60225. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  60226. +
  60227. + /* Zero Length Packet? */
  60228. + if (ep->xfer_len == 0) {
  60229. + deptsiz.b.xfersize = 0;
  60230. + deptsiz.b.pktcnt = 1;
  60231. + } else {
  60232. + /* Program the transfer size and packet count
  60233. + * as follows: xfersize = N * maxpacket +
  60234. + * short_packet pktcnt = N + (short_packet
  60235. + * exist ? 1 : 0)
  60236. + */
  60237. + if (ep->xfer_len > ep->maxpacket) {
  60238. + ep->xfer_len = ep->maxpacket;
  60239. + deptsiz.b.xfersize = ep->maxpacket;
  60240. + } else {
  60241. + deptsiz.b.xfersize = ep->xfer_len;
  60242. + }
  60243. + deptsiz.b.pktcnt = 1;
  60244. +
  60245. + }
  60246. + DWC_DEBUGPL(DBG_PCDV,
  60247. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  60248. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  60249. + deptsiz.d32);
  60250. +
  60251. + /* Write the DMA register */
  60252. + if (core_if->dma_enable) {
  60253. + if (core_if->dma_desc_enable == 0) {
  60254. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  60255. + deptsiz.d32);
  60256. +
  60257. + DWC_WRITE_REG32(&(in_regs->diepdma),
  60258. + (uint32_t) ep->dma_addr);
  60259. + } else {
  60260. + dma_desc = core_if->dev_if->in_desc_addr;
  60261. +
  60262. + /** DMA Descriptor Setup */
  60263. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60264. + dma_desc->status.b.l = 1;
  60265. + dma_desc->status.b.ioc = 1;
  60266. + dma_desc->status.b.sp =
  60267. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  60268. + dma_desc->status.b.bytes = ep->xfer_len;
  60269. + dma_desc->buf = ep->dma_addr;
  60270. + dma_desc->status.b.sts = 0;
  60271. + dma_desc->status.b.bs = BS_HOST_READY;
  60272. +
  60273. + /** DIEPDMA0 Register write */
  60274. + DWC_WRITE_REG32(&in_regs->diepdma,
  60275. + core_if->
  60276. + dev_if->dma_in_desc_addr);
  60277. + }
  60278. + } else {
  60279. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  60280. + }
  60281. +
  60282. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  60283. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  60284. + /* EP enable, IN data in FIFO */
  60285. + depctl.b.cnak = 1;
  60286. + depctl.b.epena = 1;
  60287. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  60288. +
  60289. + /**
  60290. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  60291. + * data will be written into the fifo by the ISR.
  60292. + */
  60293. + if (!core_if->dma_enable) {
  60294. + if (core_if->en_multiple_tx_fifo == 0) {
  60295. + intr_mask.b.nptxfempty = 1;
  60296. + DWC_MODIFY_REG32(&core_if->
  60297. + core_global_regs->gintmsk,
  60298. + intr_mask.d32, intr_mask.d32);
  60299. + } else {
  60300. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  60301. + if (ep->xfer_len > 0) {
  60302. + uint32_t fifoemptymsk = 0;
  60303. + fifoemptymsk |= 1 << ep->num;
  60304. + DWC_MODIFY_REG32(&core_if->
  60305. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  60306. + 0, fifoemptymsk);
  60307. + }
  60308. + }
  60309. + }
  60310. + } else {
  60311. + /* OUT endpoint */
  60312. + dwc_otg_dev_out_ep_regs_t *out_regs =
  60313. + core_if->dev_if->out_ep_regs[0];
  60314. +
  60315. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  60316. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  60317. +
  60318. + /* Program the transfer size and packet count as follows:
  60319. + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  60320. + * pktcnt = N */
  60321. + /* Zero Length Packet */
  60322. + deptsiz.b.xfersize = ep->maxpacket;
  60323. + deptsiz.b.pktcnt = 1;
  60324. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  60325. + deptsiz.b.supcnt = 3;
  60326. +
  60327. + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  60328. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  60329. +
  60330. + if (core_if->dma_enable) {
  60331. + if (!core_if->dma_desc_enable) {
  60332. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  60333. + deptsiz.d32);
  60334. +
  60335. + DWC_WRITE_REG32(&(out_regs->doepdma),
  60336. + (uint32_t) ep->dma_addr);
  60337. + } else {
  60338. + dma_desc = core_if->dev_if->out_desc_addr;
  60339. +
  60340. + /** DMA Descriptor Setup */
  60341. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60342. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  60343. + dma_desc->status.b.mtrf = 0;
  60344. + dma_desc->status.b.sr = 0;
  60345. + }
  60346. + dma_desc->status.b.l = 1;
  60347. + dma_desc->status.b.ioc = 1;
  60348. + dma_desc->status.b.bytes = ep->maxpacket;
  60349. + dma_desc->buf = ep->dma_addr;
  60350. + dma_desc->status.b.sts = 0;
  60351. + dma_desc->status.b.bs = BS_HOST_READY;
  60352. +
  60353. + /** DOEPDMA0 Register write */
  60354. + DWC_WRITE_REG32(&out_regs->doepdma,
  60355. + core_if->dev_if->
  60356. + dma_out_desc_addr);
  60357. + }
  60358. + } else {
  60359. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  60360. + }
  60361. +
  60362. + /* EP enable */
  60363. + depctl.b.cnak = 1;
  60364. + depctl.b.epena = 1;
  60365. + DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  60366. + }
  60367. +}
  60368. +
  60369. +/**
  60370. + * This function continues control IN transfers started by
  60371. + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  60372. + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  60373. + * bit for the packet count.
  60374. + *
  60375. + * @param core_if Programming view of DWC_otg controller.
  60376. + * @param ep The EP0 data.
  60377. + */
  60378. +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60379. +{
  60380. + depctl_data_t depctl;
  60381. + deptsiz0_data_t deptsiz;
  60382. + gintmsk_data_t intr_mask = {.d32 = 0 };
  60383. + dwc_otg_dev_dma_desc_t *dma_desc;
  60384. +
  60385. + if (ep->is_in == 1) {
  60386. + dwc_otg_dev_in_ep_regs_t *in_regs =
  60387. + core_if->dev_if->in_ep_regs[0];
  60388. + gnptxsts_data_t tx_status = {.d32 = 0 };
  60389. +
  60390. + tx_status.d32 =
  60391. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  60392. + /** @todo Should there be check for room in the Tx
  60393. + * Status Queue. If not remove the code above this comment. */
  60394. +
  60395. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  60396. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  60397. +
  60398. + /* Program the transfer size and packet count
  60399. + * as follows: xfersize = N * maxpacket +
  60400. + * short_packet pktcnt = N + (short_packet
  60401. + * exist ? 1 : 0)
  60402. + */
  60403. +
  60404. + if (core_if->dma_desc_enable == 0) {
  60405. + deptsiz.b.xfersize =
  60406. + (ep->total_len - ep->xfer_count) >
  60407. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  60408. + ep->xfer_count);
  60409. + deptsiz.b.pktcnt = 1;
  60410. + if (core_if->dma_enable == 0) {
  60411. + ep->xfer_len += deptsiz.b.xfersize;
  60412. + } else {
  60413. + ep->xfer_len = deptsiz.b.xfersize;
  60414. + }
  60415. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  60416. + } else {
  60417. + ep->xfer_len =
  60418. + (ep->total_len - ep->xfer_count) >
  60419. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  60420. + ep->xfer_count);
  60421. +
  60422. + dma_desc = core_if->dev_if->in_desc_addr;
  60423. +
  60424. + /** DMA Descriptor Setup */
  60425. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60426. + dma_desc->status.b.l = 1;
  60427. + dma_desc->status.b.ioc = 1;
  60428. + dma_desc->status.b.sp =
  60429. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  60430. + dma_desc->status.b.bytes = ep->xfer_len;
  60431. + dma_desc->buf = ep->dma_addr;
  60432. + dma_desc->status.b.sts = 0;
  60433. + dma_desc->status.b.bs = BS_HOST_READY;
  60434. +
  60435. + /** DIEPDMA0 Register write */
  60436. + DWC_WRITE_REG32(&in_regs->diepdma,
  60437. + core_if->dev_if->dma_in_desc_addr);
  60438. + }
  60439. +
  60440. + DWC_DEBUGPL(DBG_PCDV,
  60441. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  60442. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  60443. + deptsiz.d32);
  60444. +
  60445. + /* Write the DMA register */
  60446. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  60447. + if (core_if->dma_desc_enable == 0)
  60448. + DWC_WRITE_REG32(&(in_regs->diepdma),
  60449. + (uint32_t) ep->dma_addr);
  60450. + }
  60451. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  60452. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  60453. + /* EP enable, IN data in FIFO */
  60454. + depctl.b.cnak = 1;
  60455. + depctl.b.epena = 1;
  60456. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  60457. +
  60458. + /**
  60459. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  60460. + * data will be written into the fifo by the ISR.
  60461. + */
  60462. + if (!core_if->dma_enable) {
  60463. + if (core_if->en_multiple_tx_fifo == 0) {
  60464. + /* First clear it from GINTSTS */
  60465. + intr_mask.b.nptxfempty = 1;
  60466. + DWC_MODIFY_REG32(&core_if->
  60467. + core_global_regs->gintmsk,
  60468. + intr_mask.d32, intr_mask.d32);
  60469. +
  60470. + } else {
  60471. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  60472. + if (ep->xfer_len > 0) {
  60473. + uint32_t fifoemptymsk = 0;
  60474. + fifoemptymsk |= 1 << ep->num;
  60475. + DWC_MODIFY_REG32(&core_if->
  60476. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  60477. + 0, fifoemptymsk);
  60478. + }
  60479. + }
  60480. + }
  60481. + } else {
  60482. + dwc_otg_dev_out_ep_regs_t *out_regs =
  60483. + core_if->dev_if->out_ep_regs[0];
  60484. +
  60485. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  60486. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  60487. +
  60488. + /* Program the transfer size and packet count
  60489. + * as follows: xfersize = N * maxpacket +
  60490. + * short_packet pktcnt = N + (short_packet
  60491. + * exist ? 1 : 0)
  60492. + */
  60493. + deptsiz.b.xfersize = ep->maxpacket;
  60494. + deptsiz.b.pktcnt = 1;
  60495. +
  60496. + if (core_if->dma_desc_enable == 0) {
  60497. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  60498. + } else {
  60499. + dma_desc = core_if->dev_if->out_desc_addr;
  60500. +
  60501. + /** DMA Descriptor Setup */
  60502. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60503. + dma_desc->status.b.l = 1;
  60504. + dma_desc->status.b.ioc = 1;
  60505. + dma_desc->status.b.bytes = ep->maxpacket;
  60506. + dma_desc->buf = ep->dma_addr;
  60507. + dma_desc->status.b.sts = 0;
  60508. + dma_desc->status.b.bs = BS_HOST_READY;
  60509. +
  60510. + /** DOEPDMA0 Register write */
  60511. + DWC_WRITE_REG32(&out_regs->doepdma,
  60512. + core_if->dev_if->dma_out_desc_addr);
  60513. + }
  60514. +
  60515. + DWC_DEBUGPL(DBG_PCDV,
  60516. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  60517. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  60518. + deptsiz.d32);
  60519. +
  60520. + /* Write the DMA register */
  60521. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  60522. + if (core_if->dma_desc_enable == 0)
  60523. + DWC_WRITE_REG32(&(out_regs->doepdma),
  60524. + (uint32_t) ep->dma_addr);
  60525. +
  60526. + }
  60527. +
  60528. + /* EP enable, IN data in FIFO */
  60529. + depctl.b.cnak = 1;
  60530. + depctl.b.epena = 1;
  60531. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  60532. +
  60533. + }
  60534. +}
  60535. +
  60536. +#ifdef DEBUG
  60537. +void dump_msg(const u8 * buf, unsigned int length)
  60538. +{
  60539. + unsigned int start, num, i;
  60540. + char line[52], *p;
  60541. +
  60542. + if (length >= 512)
  60543. + return;
  60544. + start = 0;
  60545. + while (length > 0) {
  60546. + num = length < 16u ? length : 16u;
  60547. + p = line;
  60548. + for (i = 0; i < num; ++i) {
  60549. + if (i == 8)
  60550. + *p++ = ' ';
  60551. + DWC_SPRINTF(p, " %02x", buf[i]);
  60552. + p += 3;
  60553. + }
  60554. + *p = 0;
  60555. + DWC_PRINTF("%6x: %s\n", start, line);
  60556. + buf += num;
  60557. + start += num;
  60558. + length -= num;
  60559. + }
  60560. +}
  60561. +#else
  60562. +static inline void dump_msg(const u8 * buf, unsigned int length)
  60563. +{
  60564. +}
  60565. +#endif
  60566. +
  60567. +/**
  60568. + * This function writes a packet into the Tx FIFO associated with the
  60569. + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  60570. + * periodic EPs the periodic Tx FIFO associated with the EP is written
  60571. + * with all packets for the next micro-frame.
  60572. + *
  60573. + * @param core_if Programming view of DWC_otg controller.
  60574. + * @param ep The EP to write packet for.
  60575. + * @param dma Indicates if DMA is being used.
  60576. + */
  60577. +void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  60578. + int dma)
  60579. +{
  60580. + /**
  60581. + * The buffer is padded to DWORD on a per packet basis in
  60582. + * slave/dma mode if the MPS is not DWORD aligned. The last
  60583. + * packet, if short, is also padded to a multiple of DWORD.
  60584. + *
  60585. + * ep->xfer_buff always starts DWORD aligned in memory and is a
  60586. + * multiple of DWORD in length
  60587. + *
  60588. + * ep->xfer_len can be any number of bytes
  60589. + *
  60590. + * ep->xfer_count is a multiple of ep->maxpacket until the last
  60591. + * packet
  60592. + *
  60593. + * FIFO access is DWORD */
  60594. +
  60595. + uint32_t i;
  60596. + uint32_t byte_count;
  60597. + uint32_t dword_count;
  60598. + uint32_t *fifo;
  60599. + uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  60600. +
  60601. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  60602. + ep);
  60603. + if (ep->xfer_count >= ep->xfer_len) {
  60604. + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  60605. + return;
  60606. + }
  60607. +
  60608. + /* Find the byte length of the packet either short packet or MPS */
  60609. + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  60610. + byte_count = ep->xfer_len - ep->xfer_count;
  60611. + } else {
  60612. + byte_count = ep->maxpacket;
  60613. + }
  60614. +
  60615. + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  60616. + * is not a multiple of DWORD */
  60617. + dword_count = (byte_count + 3) / 4;
  60618. +
  60619. +#ifdef VERBOSE
  60620. + dump_msg(ep->xfer_buff, byte_count);
  60621. +#endif
  60622. +
  60623. + /**@todo NGS Where are the Periodic Tx FIFO addresses
  60624. + * intialized? What should this be? */
  60625. +
  60626. + fifo = core_if->data_fifo[ep->num];
  60627. +
  60628. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  60629. + fifo, data_buff, *data_buff, byte_count);
  60630. +
  60631. + if (!dma) {
  60632. + for (i = 0; i < dword_count; i++, data_buff++) {
  60633. + DWC_WRITE_REG32(fifo, *data_buff);
  60634. + }
  60635. + }
  60636. +
  60637. + ep->xfer_count += byte_count;
  60638. + ep->xfer_buff += byte_count;
  60639. + ep->dma_addr += byte_count;
  60640. +}
  60641. +
  60642. +/**
  60643. + * Set the EP STALL.
  60644. + *
  60645. + * @param core_if Programming view of DWC_otg controller.
  60646. + * @param ep The EP to set the stall on.
  60647. + */
  60648. +void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60649. +{
  60650. + depctl_data_t depctl;
  60651. + volatile uint32_t *depctl_addr;
  60652. +
  60653. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  60654. + (ep->is_in ? "IN" : "OUT"));
  60655. +
  60656. + if (ep->is_in == 1) {
  60657. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  60658. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  60659. +
  60660. + /* set the disable and stall bits */
  60661. + if (depctl.b.epena) {
  60662. + depctl.b.epdis = 1;
  60663. + }
  60664. + depctl.b.stall = 1;
  60665. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  60666. + } else {
  60667. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  60668. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  60669. +
  60670. + /* set the stall bit */
  60671. + depctl.b.stall = 1;
  60672. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  60673. + }
  60674. +
  60675. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  60676. +
  60677. + return;
  60678. +}
  60679. +
  60680. +/**
  60681. + * Clear the EP STALL.
  60682. + *
  60683. + * @param core_if Programming view of DWC_otg controller.
  60684. + * @param ep The EP to clear stall from.
  60685. + */
  60686. +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60687. +{
  60688. + depctl_data_t depctl;
  60689. + volatile uint32_t *depctl_addr;
  60690. +
  60691. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  60692. + (ep->is_in ? "IN" : "OUT"));
  60693. +
  60694. + if (ep->is_in == 1) {
  60695. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  60696. + } else {
  60697. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  60698. + }
  60699. +
  60700. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  60701. +
  60702. + /* clear the stall bits */
  60703. + depctl.b.stall = 0;
  60704. +
  60705. + /*
  60706. + * USB Spec 9.4.5: For endpoints using data toggle, regardless
  60707. + * of whether an endpoint has the Halt feature set, a
  60708. + * ClearFeature(ENDPOINT_HALT) request always results in the
  60709. + * data toggle being reinitialized to DATA0.
  60710. + */
  60711. + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  60712. + ep->type == DWC_OTG_EP_TYPE_BULK) {
  60713. + depctl.b.setd0pid = 1; /* DATA0 */
  60714. + }
  60715. +
  60716. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  60717. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  60718. + return;
  60719. +}
  60720. +
  60721. +/**
  60722. + * This function reads a packet from the Rx FIFO into the destination
  60723. + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  60724. + *
  60725. + * @param core_if Programming view of DWC_otg controller.
  60726. + * @param dest Destination buffer for the packet.
  60727. + * @param bytes Number of bytes to copy to the destination.
  60728. + */
  60729. +void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  60730. + uint8_t * dest, uint16_t bytes)
  60731. +{
  60732. + int i;
  60733. + int word_count = (bytes + 3) / 4;
  60734. +
  60735. + volatile uint32_t *fifo = core_if->data_fifo[0];
  60736. + uint32_t *data_buff = (uint32_t *) dest;
  60737. +
  60738. + /**
  60739. + * @todo Account for the case where _dest is not dword aligned. This
  60740. + * requires reading data from the FIFO into a uint32_t temp buffer,
  60741. + * then moving it into the data buffer.
  60742. + */
  60743. +
  60744. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  60745. + core_if, dest, bytes);
  60746. +
  60747. + for (i = 0; i < word_count; i++, data_buff++) {
  60748. + *data_buff = DWC_READ_REG32(fifo);
  60749. + }
  60750. +
  60751. + return;
  60752. +}
  60753. +
  60754. +/**
  60755. + * This functions reads the device registers and prints them
  60756. + *
  60757. + * @param core_if Programming view of DWC_otg controller.
  60758. + */
  60759. +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  60760. +{
  60761. + int i;
  60762. + volatile uint32_t *addr;
  60763. +
  60764. + DWC_PRINTF("Device Global Registers\n");
  60765. + addr = &core_if->dev_if->dev_global_regs->dcfg;
  60766. + DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n",
  60767. + (unsigned long)addr, DWC_READ_REG32(addr));
  60768. + addr = &core_if->dev_if->dev_global_regs->dctl;
  60769. + DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n",
  60770. + (unsigned long)addr, DWC_READ_REG32(addr));
  60771. + addr = &core_if->dev_if->dev_global_regs->dsts;
  60772. + DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n",
  60773. + (unsigned long)addr, DWC_READ_REG32(addr));
  60774. + addr = &core_if->dev_if->dev_global_regs->diepmsk;
  60775. + DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60776. + DWC_READ_REG32(addr));
  60777. + addr = &core_if->dev_if->dev_global_regs->doepmsk;
  60778. + DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60779. + DWC_READ_REG32(addr));
  60780. + addr = &core_if->dev_if->dev_global_regs->daint;
  60781. + DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60782. + DWC_READ_REG32(addr));
  60783. + addr = &core_if->dev_if->dev_global_regs->daintmsk;
  60784. + DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60785. + DWC_READ_REG32(addr));
  60786. + addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  60787. + DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60788. + DWC_READ_REG32(addr));
  60789. + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  60790. + addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  60791. + DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  60792. + (unsigned long)addr, DWC_READ_REG32(addr));
  60793. + }
  60794. +
  60795. + addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  60796. + DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60797. + DWC_READ_REG32(addr));
  60798. +
  60799. + addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  60800. + DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  60801. + (unsigned long)addr, DWC_READ_REG32(addr));
  60802. +
  60803. + addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  60804. + DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  60805. + (unsigned long)addr, DWC_READ_REG32(addr));
  60806. +
  60807. + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  60808. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  60809. + DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  60810. + (unsigned long)addr, DWC_READ_REG32(addr));
  60811. + }
  60812. +
  60813. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  60814. + DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60815. + DWC_READ_REG32(addr));
  60816. +
  60817. + if (core_if->hwcfg2.b.multi_proc_int) {
  60818. +
  60819. + addr = &core_if->dev_if->dev_global_regs->deachint;
  60820. + DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  60821. + (unsigned long)addr, DWC_READ_REG32(addr));
  60822. + addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  60823. + DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  60824. + (unsigned long)addr, DWC_READ_REG32(addr));
  60825. +
  60826. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  60827. + addr =
  60828. + &core_if->dev_if->
  60829. + dev_global_regs->diepeachintmsk[i];
  60830. + DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  60831. + i, (unsigned long)addr,
  60832. + DWC_READ_REG32(addr));
  60833. + }
  60834. +
  60835. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  60836. + addr =
  60837. + &core_if->dev_if->
  60838. + dev_global_regs->doepeachintmsk[i];
  60839. + DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  60840. + i, (unsigned long)addr,
  60841. + DWC_READ_REG32(addr));
  60842. + }
  60843. + }
  60844. +
  60845. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  60846. + DWC_PRINTF("Device IN EP %d Registers\n", i);
  60847. + addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  60848. + DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  60849. + (unsigned long)addr, DWC_READ_REG32(addr));
  60850. + addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  60851. + DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  60852. + (unsigned long)addr, DWC_READ_REG32(addr));
  60853. + addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  60854. + DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  60855. + (unsigned long)addr, DWC_READ_REG32(addr));
  60856. + addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  60857. + DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  60858. + (unsigned long)addr, DWC_READ_REG32(addr));
  60859. + addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  60860. + DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  60861. + (unsigned long)addr, DWC_READ_REG32(addr));
  60862. + addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  60863. + DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  60864. + (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  60865. + }
  60866. +
  60867. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  60868. + DWC_PRINTF("Device OUT EP %d Registers\n", i);
  60869. + addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  60870. + DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  60871. + (unsigned long)addr, DWC_READ_REG32(addr));
  60872. + addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  60873. + DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  60874. + (unsigned long)addr, DWC_READ_REG32(addr));
  60875. + addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  60876. + DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  60877. + (unsigned long)addr, DWC_READ_REG32(addr));
  60878. + addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  60879. + DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  60880. + (unsigned long)addr, DWC_READ_REG32(addr));
  60881. + if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  60882. + addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  60883. + DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  60884. + (unsigned long)addr, DWC_READ_REG32(addr));
  60885. + }
  60886. +
  60887. + }
  60888. +}
  60889. +
  60890. +/**
  60891. + * This functions reads the SPRAM and prints its content
  60892. + *
  60893. + * @param core_if Programming view of DWC_otg controller.
  60894. + */
  60895. +void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  60896. +{
  60897. + volatile uint8_t *addr, *start_addr, *end_addr;
  60898. +
  60899. + DWC_PRINTF("SPRAM Data:\n");
  60900. + start_addr = (void *)core_if->core_global_regs;
  60901. + DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  60902. + start_addr += 0x00028000;
  60903. + end_addr = (void *)core_if->core_global_regs;
  60904. + end_addr += 0x000280e0;
  60905. +
  60906. + for (addr = start_addr; addr < end_addr; addr += 16) {
  60907. + DWC_PRINTF
  60908. + ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  60909. + (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  60910. + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  60911. + addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  60912. + );
  60913. + }
  60914. +
  60915. + return;
  60916. +}
  60917. +
  60918. +/**
  60919. + * This function reads the host registers and prints them
  60920. + *
  60921. + * @param core_if Programming view of DWC_otg controller.
  60922. + */
  60923. +void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  60924. +{
  60925. + int i;
  60926. + volatile uint32_t *addr;
  60927. +
  60928. + DWC_PRINTF("Host Global Registers\n");
  60929. + addr = &core_if->host_if->host_global_regs->hcfg;
  60930. + DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  60931. + (unsigned long)addr, DWC_READ_REG32(addr));
  60932. + addr = &core_if->host_if->host_global_regs->hfir;
  60933. + DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  60934. + (unsigned long)addr, DWC_READ_REG32(addr));
  60935. + addr = &core_if->host_if->host_global_regs->hfnum;
  60936. + DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60937. + DWC_READ_REG32(addr));
  60938. + addr = &core_if->host_if->host_global_regs->hptxsts;
  60939. + DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60940. + DWC_READ_REG32(addr));
  60941. + addr = &core_if->host_if->host_global_regs->haint;
  60942. + DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60943. + DWC_READ_REG32(addr));
  60944. + addr = &core_if->host_if->host_global_regs->haintmsk;
  60945. + DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60946. + DWC_READ_REG32(addr));
  60947. + if (core_if->dma_desc_enable) {
  60948. + addr = &core_if->host_if->host_global_regs->hflbaddr;
  60949. + DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  60950. + (unsigned long)addr, DWC_READ_REG32(addr));
  60951. + }
  60952. +
  60953. + addr = core_if->host_if->hprt0;
  60954. + DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60955. + DWC_READ_REG32(addr));
  60956. +
  60957. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  60958. + DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  60959. + addr = &core_if->host_if->hc_regs[i]->hcchar;
  60960. + DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  60961. + (unsigned long)addr, DWC_READ_REG32(addr));
  60962. + addr = &core_if->host_if->hc_regs[i]->hcsplt;
  60963. + DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  60964. + (unsigned long)addr, DWC_READ_REG32(addr));
  60965. + addr = &core_if->host_if->hc_regs[i]->hcint;
  60966. + DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  60967. + (unsigned long)addr, DWC_READ_REG32(addr));
  60968. + addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  60969. + DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  60970. + (unsigned long)addr, DWC_READ_REG32(addr));
  60971. + addr = &core_if->host_if->hc_regs[i]->hctsiz;
  60972. + DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  60973. + (unsigned long)addr, DWC_READ_REG32(addr));
  60974. + addr = &core_if->host_if->hc_regs[i]->hcdma;
  60975. + DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  60976. + (unsigned long)addr, DWC_READ_REG32(addr));
  60977. + if (core_if->dma_desc_enable) {
  60978. + addr = &core_if->host_if->hc_regs[i]->hcdmab;
  60979. + DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  60980. + (unsigned long)addr, DWC_READ_REG32(addr));
  60981. + }
  60982. +
  60983. + }
  60984. + return;
  60985. +}
  60986. +
  60987. +/**
  60988. + * This function reads the core global registers and prints them
  60989. + *
  60990. + * @param core_if Programming view of DWC_otg controller.
  60991. + */
  60992. +void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  60993. +{
  60994. + int i, ep_num;
  60995. + volatile uint32_t *addr;
  60996. + char *txfsiz;
  60997. +
  60998. + DWC_PRINTF("Core Global Registers\n");
  60999. + addr = &core_if->core_global_regs->gotgctl;
  61000. + DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61001. + DWC_READ_REG32(addr));
  61002. + addr = &core_if->core_global_regs->gotgint;
  61003. + DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61004. + DWC_READ_REG32(addr));
  61005. + addr = &core_if->core_global_regs->gahbcfg;
  61006. + DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61007. + DWC_READ_REG32(addr));
  61008. + addr = &core_if->core_global_regs->gusbcfg;
  61009. + DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61010. + DWC_READ_REG32(addr));
  61011. + addr = &core_if->core_global_regs->grstctl;
  61012. + DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61013. + DWC_READ_REG32(addr));
  61014. + addr = &core_if->core_global_regs->gintsts;
  61015. + DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61016. + DWC_READ_REG32(addr));
  61017. + addr = &core_if->core_global_regs->gintmsk;
  61018. + DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61019. + DWC_READ_REG32(addr));
  61020. + addr = &core_if->core_global_regs->grxstsr;
  61021. + DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61022. + DWC_READ_REG32(addr));
  61023. + addr = &core_if->core_global_regs->grxfsiz;
  61024. + DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61025. + DWC_READ_REG32(addr));
  61026. + addr = &core_if->core_global_regs->gnptxfsiz;
  61027. + DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61028. + DWC_READ_REG32(addr));
  61029. + addr = &core_if->core_global_regs->gnptxsts;
  61030. + DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61031. + DWC_READ_REG32(addr));
  61032. + addr = &core_if->core_global_regs->gi2cctl;
  61033. + DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61034. + DWC_READ_REG32(addr));
  61035. + addr = &core_if->core_global_regs->gpvndctl;
  61036. + DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61037. + DWC_READ_REG32(addr));
  61038. + addr = &core_if->core_global_regs->ggpio;
  61039. + DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61040. + DWC_READ_REG32(addr));
  61041. + addr = &core_if->core_global_regs->guid;
  61042. + DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  61043. + (unsigned long)addr, DWC_READ_REG32(addr));
  61044. + addr = &core_if->core_global_regs->gsnpsid;
  61045. + DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61046. + DWC_READ_REG32(addr));
  61047. + addr = &core_if->core_global_regs->ghwcfg1;
  61048. + DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61049. + DWC_READ_REG32(addr));
  61050. + addr = &core_if->core_global_regs->ghwcfg2;
  61051. + DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61052. + DWC_READ_REG32(addr));
  61053. + addr = &core_if->core_global_regs->ghwcfg3;
  61054. + DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61055. + DWC_READ_REG32(addr));
  61056. + addr = &core_if->core_global_regs->ghwcfg4;
  61057. + DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61058. + DWC_READ_REG32(addr));
  61059. + addr = &core_if->core_global_regs->glpmcfg;
  61060. + DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61061. + DWC_READ_REG32(addr));
  61062. + addr = &core_if->core_global_regs->gpwrdn;
  61063. + DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61064. + DWC_READ_REG32(addr));
  61065. + addr = &core_if->core_global_regs->gdfifocfg;
  61066. + DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61067. + DWC_READ_REG32(addr));
  61068. + addr = &core_if->core_global_regs->adpctl;
  61069. + DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61070. + dwc_otg_adp_read_reg(core_if));
  61071. + addr = &core_if->core_global_regs->hptxfsiz;
  61072. + DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61073. + DWC_READ_REG32(addr));
  61074. +
  61075. + if (core_if->en_multiple_tx_fifo == 0) {
  61076. + ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  61077. + txfsiz = "DPTXFSIZ";
  61078. + } else {
  61079. + ep_num = core_if->hwcfg4.b.num_in_eps;
  61080. + txfsiz = "DIENPTXF";
  61081. + }
  61082. + for (i = 0; i < ep_num; i++) {
  61083. + addr = &core_if->core_global_regs->dtxfsiz[i];
  61084. + DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  61085. + (unsigned long)addr, DWC_READ_REG32(addr));
  61086. + }
  61087. + addr = core_if->pcgcctl;
  61088. + DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61089. + DWC_READ_REG32(addr));
  61090. +}
  61091. +
  61092. +/**
  61093. + * Flush a Tx FIFO.
  61094. + *
  61095. + * @param core_if Programming view of DWC_otg controller.
  61096. + * @param num Tx FIFO to flush.
  61097. + */
  61098. +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  61099. +{
  61100. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  61101. + volatile grstctl_t greset = {.d32 = 0 };
  61102. + int count = 0;
  61103. +
  61104. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  61105. +
  61106. + greset.b.txfflsh = 1;
  61107. + greset.b.txfnum = num;
  61108. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  61109. +
  61110. + do {
  61111. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61112. + if (++count > 10000) {
  61113. + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  61114. + __func__, greset.d32,
  61115. + DWC_READ_REG32(&global_regs->gnptxsts));
  61116. + break;
  61117. + }
  61118. + dwc_udelay(1);
  61119. + } while (greset.b.txfflsh == 1);
  61120. +
  61121. + /* Wait for 3 PHY Clocks */
  61122. + dwc_udelay(1);
  61123. +}
  61124. +
  61125. +/**
  61126. + * Flush Rx FIFO.
  61127. + *
  61128. + * @param core_if Programming view of DWC_otg controller.
  61129. + */
  61130. +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  61131. +{
  61132. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  61133. + volatile grstctl_t greset = {.d32 = 0 };
  61134. + int count = 0;
  61135. +
  61136. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  61137. + /*
  61138. + *
  61139. + */
  61140. + greset.b.rxfflsh = 1;
  61141. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  61142. +
  61143. + do {
  61144. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61145. + if (++count > 10000) {
  61146. + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  61147. + greset.d32);
  61148. + break;
  61149. + }
  61150. + dwc_udelay(1);
  61151. + } while (greset.b.rxfflsh == 1);
  61152. +
  61153. + /* Wait for 3 PHY Clocks */
  61154. + dwc_udelay(1);
  61155. +}
  61156. +
  61157. +/**
  61158. + * Do core a soft reset of the core. Be careful with this because it
  61159. + * resets all the internal state machines of the core.
  61160. + */
  61161. +void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  61162. +{
  61163. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  61164. + volatile grstctl_t greset = {.d32 = 0 };
  61165. + int count = 0;
  61166. +
  61167. + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  61168. + /* Wait for AHB master IDLE state. */
  61169. + do {
  61170. + dwc_udelay(10);
  61171. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61172. + if (++count > 100000) {
  61173. + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  61174. + greset.d32);
  61175. + return;
  61176. + }
  61177. + }
  61178. + while (greset.b.ahbidle == 0);
  61179. +
  61180. + /* Core Soft Reset */
  61181. + count = 0;
  61182. + greset.b.csftrst = 1;
  61183. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  61184. + do {
  61185. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61186. + if (++count > 10000) {
  61187. + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  61188. + __func__, greset.d32);
  61189. + break;
  61190. + }
  61191. + dwc_udelay(1);
  61192. + }
  61193. + while (greset.b.csftrst == 1);
  61194. +
  61195. + /* Wait for 3 PHY Clocks */
  61196. + dwc_mdelay(100);
  61197. +}
  61198. +
  61199. +uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  61200. +{
  61201. + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  61202. +}
  61203. +
  61204. +uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  61205. +{
  61206. + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  61207. +}
  61208. +
  61209. +/**
  61210. + * Register HCD callbacks. The callbacks are used to start and stop
  61211. + * the HCD for interrupt processing.
  61212. + *
  61213. + * @param core_if Programming view of DWC_otg controller.
  61214. + * @param cb the HCD callback structure.
  61215. + * @param p pointer to be passed to callback function (usb_hcd*).
  61216. + */
  61217. +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  61218. + dwc_otg_cil_callbacks_t * cb, void *p)
  61219. +{
  61220. + core_if->hcd_cb = cb;
  61221. + cb->p = p;
  61222. +}
  61223. +
  61224. +/**
  61225. + * Register PCD callbacks. The callbacks are used to start and stop
  61226. + * the PCD for interrupt processing.
  61227. + *
  61228. + * @param core_if Programming view of DWC_otg controller.
  61229. + * @param cb the PCD callback structure.
  61230. + * @param p pointer to be passed to callback function (pcd*).
  61231. + */
  61232. +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  61233. + dwc_otg_cil_callbacks_t * cb, void *p)
  61234. +{
  61235. + core_if->pcd_cb = cb;
  61236. + cb->p = p;
  61237. +}
  61238. +
  61239. +#ifdef DWC_EN_ISOC
  61240. +
  61241. +/**
  61242. + * This function writes isoc data per 1 (micro)frame into tx fifo
  61243. + *
  61244. + * @param core_if Programming view of DWC_otg controller.
  61245. + * @param ep The EP to start the transfer on.
  61246. + *
  61247. + */
  61248. +void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  61249. +{
  61250. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  61251. + dtxfsts_data_t txstatus = {.d32 = 0 };
  61252. + uint32_t len = 0;
  61253. + uint32_t dwords;
  61254. +
  61255. + ep->xfer_len = ep->data_per_frame;
  61256. + ep->xfer_count = 0;
  61257. +
  61258. + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  61259. +
  61260. + len = ep->xfer_len - ep->xfer_count;
  61261. +
  61262. + if (len > ep->maxpacket) {
  61263. + len = ep->maxpacket;
  61264. + }
  61265. +
  61266. + dwords = (len + 3) / 4;
  61267. +
  61268. + /* While there is space in the queue and space in the FIFO and
  61269. + * More data to tranfer, Write packets to the Tx FIFO */
  61270. + txstatus.d32 =
  61271. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  61272. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  61273. +
  61274. + while (txstatus.b.txfspcavail > dwords &&
  61275. + ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  61276. + /* Write the FIFO */
  61277. + dwc_otg_ep_write_packet(core_if, ep, 0);
  61278. +
  61279. + len = ep->xfer_len - ep->xfer_count;
  61280. + if (len > ep->maxpacket) {
  61281. + len = ep->maxpacket;
  61282. + }
  61283. +
  61284. + dwords = (len + 3) / 4;
  61285. + txstatus.d32 =
  61286. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  61287. + dtxfsts);
  61288. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  61289. + txstatus.d32);
  61290. + }
  61291. +}
  61292. +
  61293. +/**
  61294. + * This function initializes a descriptor chain for Isochronous transfer
  61295. + *
  61296. + * @param core_if Programming view of DWC_otg controller.
  61297. + * @param ep The EP to start the transfer on.
  61298. + *
  61299. + */
  61300. +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  61301. + dwc_ep_t * ep)
  61302. +{
  61303. + deptsiz_data_t deptsiz = {.d32 = 0 };
  61304. + depctl_data_t depctl = {.d32 = 0 };
  61305. + dsts_data_t dsts = {.d32 = 0 };
  61306. + volatile uint32_t *addr;
  61307. +
  61308. + if (ep->is_in) {
  61309. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  61310. + } else {
  61311. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  61312. + }
  61313. +
  61314. + ep->xfer_len = ep->data_per_frame;
  61315. + ep->xfer_count = 0;
  61316. + ep->xfer_buff = ep->cur_pkt_addr;
  61317. + ep->dma_addr = ep->cur_pkt_dma_addr;
  61318. +
  61319. + if (ep->is_in) {
  61320. + /* Program the transfer size and packet count
  61321. + * as follows: xfersize = N * maxpacket +
  61322. + * short_packet pktcnt = N + (short_packet
  61323. + * exist ? 1 : 0)
  61324. + */
  61325. + deptsiz.b.xfersize = ep->xfer_len;
  61326. + deptsiz.b.pktcnt =
  61327. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  61328. + deptsiz.b.mc = deptsiz.b.pktcnt;
  61329. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  61330. + deptsiz.d32);
  61331. +
  61332. + /* Write the DMA register */
  61333. + if (core_if->dma_enable) {
  61334. + DWC_WRITE_REG32(&
  61335. + (core_if->dev_if->in_ep_regs[ep->num]->
  61336. + diepdma), (uint32_t) ep->dma_addr);
  61337. + }
  61338. + } else {
  61339. + deptsiz.b.pktcnt =
  61340. + (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  61341. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  61342. +
  61343. + DWC_WRITE_REG32(&core_if->dev_if->
  61344. + out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
  61345. +
  61346. + if (core_if->dma_enable) {
  61347. + DWC_WRITE_REG32(&
  61348. + (core_if->dev_if->
  61349. + out_ep_regs[ep->num]->doepdma),
  61350. + (uint32_t) ep->dma_addr);
  61351. + }
  61352. + }
  61353. +
  61354. + /** Enable endpoint, clear nak */
  61355. +
  61356. + depctl.d32 = 0;
  61357. + if (ep->bInterval == 1) {
  61358. + dsts.d32 =
  61359. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  61360. + ep->next_frame = dsts.b.soffn + ep->bInterval;
  61361. +
  61362. + if (ep->next_frame & 0x1) {
  61363. + depctl.b.setd1pid = 1;
  61364. + } else {
  61365. + depctl.b.setd0pid = 1;
  61366. + }
  61367. + } else {
  61368. + ep->next_frame += ep->bInterval;
  61369. +
  61370. + if (ep->next_frame & 0x1) {
  61371. + depctl.b.setd1pid = 1;
  61372. + } else {
  61373. + depctl.b.setd0pid = 1;
  61374. + }
  61375. + }
  61376. + depctl.b.epena = 1;
  61377. + depctl.b.cnak = 1;
  61378. +
  61379. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  61380. + depctl.d32 = DWC_READ_REG32(addr);
  61381. +
  61382. + if (ep->is_in && core_if->dma_enable == 0) {
  61383. + write_isoc_frame_data(core_if, ep);
  61384. + }
  61385. +
  61386. +}
  61387. +#endif /* DWC_EN_ISOC */
  61388. +
  61389. +static void dwc_otg_set_uninitialized(int32_t * p, int size)
  61390. +{
  61391. + int i;
  61392. + for (i = 0; i < size; i++) {
  61393. + p[i] = -1;
  61394. + }
  61395. +}
  61396. +
  61397. +static int dwc_otg_param_initialized(int32_t val)
  61398. +{
  61399. + return val != -1;
  61400. +}
  61401. +
  61402. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  61403. +{
  61404. + int i;
  61405. + core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  61406. + if (!core_if->core_params) {
  61407. + return -DWC_E_NO_MEMORY;
  61408. + }
  61409. + dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  61410. + sizeof(*core_if->core_params) /
  61411. + sizeof(int32_t));
  61412. + DWC_PRINTF("Setting default values for core params\n");
  61413. + dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  61414. + dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  61415. + dwc_otg_set_param_dma_desc_enable(core_if,
  61416. + dwc_param_dma_desc_enable_default);
  61417. + dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  61418. + dwc_otg_set_param_dma_burst_size(core_if,
  61419. + dwc_param_dma_burst_size_default);
  61420. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  61421. + dwc_param_host_support_fs_ls_low_power_default);
  61422. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  61423. + dwc_param_enable_dynamic_fifo_default);
  61424. + dwc_otg_set_param_data_fifo_size(core_if,
  61425. + dwc_param_data_fifo_size_default);
  61426. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  61427. + dwc_param_dev_rx_fifo_size_default);
  61428. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  61429. + dwc_param_dev_nperio_tx_fifo_size_default);
  61430. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  61431. + dwc_param_host_rx_fifo_size_default);
  61432. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  61433. + dwc_param_host_nperio_tx_fifo_size_default);
  61434. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  61435. + dwc_param_host_perio_tx_fifo_size_default);
  61436. + dwc_otg_set_param_max_transfer_size(core_if,
  61437. + dwc_param_max_transfer_size_default);
  61438. + dwc_otg_set_param_max_packet_count(core_if,
  61439. + dwc_param_max_packet_count_default);
  61440. + dwc_otg_set_param_host_channels(core_if,
  61441. + dwc_param_host_channels_default);
  61442. + dwc_otg_set_param_dev_endpoints(core_if,
  61443. + dwc_param_dev_endpoints_default);
  61444. + dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  61445. + dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  61446. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  61447. + dwc_param_host_ls_low_power_phy_clk_default);
  61448. + dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  61449. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  61450. + dwc_param_phy_ulpi_ext_vbus_default);
  61451. + dwc_otg_set_param_phy_utmi_width(core_if,
  61452. + dwc_param_phy_utmi_width_default);
  61453. + dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  61454. + dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  61455. + dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  61456. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  61457. + dwc_param_en_multiple_tx_fifo_default);
  61458. + for (i = 0; i < 15; i++) {
  61459. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  61460. + dwc_param_dev_perio_tx_fifo_size_default,
  61461. + i);
  61462. + }
  61463. +
  61464. + for (i = 0; i < 15; i++) {
  61465. + dwc_otg_set_param_dev_tx_fifo_size(core_if,
  61466. + dwc_param_dev_tx_fifo_size_default,
  61467. + i);
  61468. + }
  61469. + dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  61470. + dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  61471. + dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  61472. + dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  61473. + dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  61474. + dwc_otg_set_param_tx_thr_length(core_if,
  61475. + dwc_param_tx_thr_length_default);
  61476. + dwc_otg_set_param_rx_thr_length(core_if,
  61477. + dwc_param_rx_thr_length_default);
  61478. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  61479. + dwc_param_ahb_thr_ratio_default);
  61480. + dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  61481. + dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  61482. + dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  61483. + dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  61484. + dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  61485. + dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  61486. + dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  61487. + DWC_PRINTF("Finished setting default values for core params\n");
  61488. +
  61489. + return 0;
  61490. +}
  61491. +
  61492. +uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  61493. +{
  61494. + return core_if->dma_enable;
  61495. +}
  61496. +
  61497. +/* Checks if the parameter is outside of its valid range of values */
  61498. +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  61499. + (((_param_) < (_low_)) || \
  61500. + ((_param_) > (_high_)))
  61501. +
  61502. +/* Parameter access functions */
  61503. +int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  61504. +{
  61505. + int valid;
  61506. + int retval = 0;
  61507. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  61508. + DWC_WARN("Wrong value for otg_cap parameter\n");
  61509. + DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  61510. + retval = -DWC_E_INVALID;
  61511. + goto out;
  61512. + }
  61513. +
  61514. + valid = 1;
  61515. + switch (val) {
  61516. + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  61517. + if (core_if->hwcfg2.b.op_mode !=
  61518. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  61519. + valid = 0;
  61520. + break;
  61521. + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  61522. + if ((core_if->hwcfg2.b.op_mode !=
  61523. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  61524. + && (core_if->hwcfg2.b.op_mode !=
  61525. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  61526. + && (core_if->hwcfg2.b.op_mode !=
  61527. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  61528. + && (core_if->hwcfg2.b.op_mode !=
  61529. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  61530. + valid = 0;
  61531. + }
  61532. + break;
  61533. + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  61534. + /* always valid */
  61535. + break;
  61536. + }
  61537. + if (!valid) {
  61538. + if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  61539. + DWC_ERROR
  61540. + ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  61541. + val);
  61542. + }
  61543. + val =
  61544. + (((core_if->hwcfg2.b.op_mode ==
  61545. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  61546. + || (core_if->hwcfg2.b.op_mode ==
  61547. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  61548. + || (core_if->hwcfg2.b.op_mode ==
  61549. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  61550. + || (core_if->hwcfg2.b.op_mode ==
  61551. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  61552. + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  61553. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  61554. + retval = -DWC_E_INVALID;
  61555. + }
  61556. +
  61557. + core_if->core_params->otg_cap = val;
  61558. +out:
  61559. + return retval;
  61560. +}
  61561. +
  61562. +int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  61563. +{
  61564. + return core_if->core_params->otg_cap;
  61565. +}
  61566. +
  61567. +int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  61568. +{
  61569. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61570. + DWC_WARN("Wrong value for opt parameter\n");
  61571. + return -DWC_E_INVALID;
  61572. + }
  61573. + core_if->core_params->opt = val;
  61574. + return 0;
  61575. +}
  61576. +
  61577. +int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  61578. +{
  61579. + return core_if->core_params->opt;
  61580. +}
  61581. +
  61582. +int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61583. +{
  61584. + int retval = 0;
  61585. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61586. + DWC_WARN("Wrong value for dma enable\n");
  61587. + return -DWC_E_INVALID;
  61588. + }
  61589. +
  61590. + if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  61591. + if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  61592. + DWC_ERROR
  61593. + ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  61594. + val);
  61595. + }
  61596. + val = 0;
  61597. + retval = -DWC_E_INVALID;
  61598. + }
  61599. +
  61600. + core_if->core_params->dma_enable = val;
  61601. + if (val == 0) {
  61602. + dwc_otg_set_param_dma_desc_enable(core_if, 0);
  61603. + }
  61604. + return retval;
  61605. +}
  61606. +
  61607. +int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  61608. +{
  61609. + return core_if->core_params->dma_enable;
  61610. +}
  61611. +
  61612. +int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61613. +{
  61614. + int retval = 0;
  61615. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61616. + DWC_WARN("Wrong value for dma_enable\n");
  61617. + DWC_WARN("dma_desc_enable must be 0 or 1\n");
  61618. + return -DWC_E_INVALID;
  61619. + }
  61620. +
  61621. + if ((val == 1)
  61622. + && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  61623. + || (core_if->hwcfg4.b.desc_dma == 0))) {
  61624. + if (dwc_otg_param_initialized
  61625. + (core_if->core_params->dma_desc_enable)) {
  61626. + DWC_ERROR
  61627. + ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  61628. + val);
  61629. + }
  61630. + val = 0;
  61631. + retval = -DWC_E_INVALID;
  61632. + }
  61633. + core_if->core_params->dma_desc_enable = val;
  61634. + return retval;
  61635. +}
  61636. +
  61637. +int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  61638. +{
  61639. + return core_if->core_params->dma_desc_enable;
  61640. +}
  61641. +
  61642. +int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  61643. + int32_t val)
  61644. +{
  61645. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61646. + DWC_WARN("Wrong value for host_support_fs_low_power\n");
  61647. + DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  61648. + return -DWC_E_INVALID;
  61649. + }
  61650. + core_if->core_params->host_support_fs_ls_low_power = val;
  61651. + return 0;
  61652. +}
  61653. +
  61654. +int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  61655. + core_if)
  61656. +{
  61657. + return core_if->core_params->host_support_fs_ls_low_power;
  61658. +}
  61659. +
  61660. +int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  61661. + int32_t val)
  61662. +{
  61663. + int retval = 0;
  61664. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61665. + DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  61666. + DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  61667. + return -DWC_E_INVALID;
  61668. + }
  61669. +
  61670. + if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  61671. + if (dwc_otg_param_initialized
  61672. + (core_if->core_params->enable_dynamic_fifo)) {
  61673. + DWC_ERROR
  61674. + ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  61675. + val);
  61676. + }
  61677. + val = 0;
  61678. + retval = -DWC_E_INVALID;
  61679. + }
  61680. + core_if->core_params->enable_dynamic_fifo = val;
  61681. + return retval;
  61682. +}
  61683. +
  61684. +int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  61685. +{
  61686. + return core_if->core_params->enable_dynamic_fifo;
  61687. +}
  61688. +
  61689. +int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  61690. +{
  61691. + int retval = 0;
  61692. + if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  61693. + DWC_WARN("Wrong value for data_fifo_size\n");
  61694. + DWC_WARN("data_fifo_size must be 32-32768\n");
  61695. + return -DWC_E_INVALID;
  61696. + }
  61697. +
  61698. + if (val > core_if->hwcfg3.b.dfifo_depth) {
  61699. + if (dwc_otg_param_initialized
  61700. + (core_if->core_params->data_fifo_size)) {
  61701. + DWC_ERROR
  61702. + ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  61703. + val);
  61704. + }
  61705. + val = core_if->hwcfg3.b.dfifo_depth;
  61706. + retval = -DWC_E_INVALID;
  61707. + }
  61708. +
  61709. + core_if->core_params->data_fifo_size = val;
  61710. + return retval;
  61711. +}
  61712. +
  61713. +int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  61714. +{
  61715. + return core_if->core_params->data_fifo_size;
  61716. +}
  61717. +
  61718. +int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  61719. +{
  61720. + int retval = 0;
  61721. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61722. + DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  61723. + DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  61724. + return -DWC_E_INVALID;
  61725. + }
  61726. +
  61727. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  61728. + if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  61729. + DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  61730. + }
  61731. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  61732. + retval = -DWC_E_INVALID;
  61733. + }
  61734. +
  61735. + core_if->core_params->dev_rx_fifo_size = val;
  61736. + return retval;
  61737. +}
  61738. +
  61739. +int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  61740. +{
  61741. + return core_if->core_params->dev_rx_fifo_size;
  61742. +}
  61743. +
  61744. +int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61745. + int32_t val)
  61746. +{
  61747. + int retval = 0;
  61748. +
  61749. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61750. + DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  61751. + DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  61752. + return -DWC_E_INVALID;
  61753. + }
  61754. +
  61755. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  61756. + if (dwc_otg_param_initialized
  61757. + (core_if->core_params->dev_nperio_tx_fifo_size)) {
  61758. + DWC_ERROR
  61759. + ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  61760. + val);
  61761. + }
  61762. + val =
  61763. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  61764. + 16);
  61765. + retval = -DWC_E_INVALID;
  61766. + }
  61767. +
  61768. + core_if->core_params->dev_nperio_tx_fifo_size = val;
  61769. + return retval;
  61770. +}
  61771. +
  61772. +int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  61773. +{
  61774. + return core_if->core_params->dev_nperio_tx_fifo_size;
  61775. +}
  61776. +
  61777. +int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  61778. + int32_t val)
  61779. +{
  61780. + int retval = 0;
  61781. +
  61782. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61783. + DWC_WARN("Wrong value for host_rx_fifo_size\n");
  61784. + DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  61785. + return -DWC_E_INVALID;
  61786. + }
  61787. +
  61788. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  61789. + if (dwc_otg_param_initialized
  61790. + (core_if->core_params->host_rx_fifo_size)) {
  61791. + DWC_ERROR
  61792. + ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  61793. + val);
  61794. + }
  61795. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  61796. + retval = -DWC_E_INVALID;
  61797. + }
  61798. +
  61799. + core_if->core_params->host_rx_fifo_size = val;
  61800. + return retval;
  61801. +
  61802. +}
  61803. +
  61804. +int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  61805. +{
  61806. + return core_if->core_params->host_rx_fifo_size;
  61807. +}
  61808. +
  61809. +int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61810. + int32_t val)
  61811. +{
  61812. + int retval = 0;
  61813. +
  61814. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61815. + DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  61816. + DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  61817. + return -DWC_E_INVALID;
  61818. + }
  61819. +
  61820. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  61821. + if (dwc_otg_param_initialized
  61822. + (core_if->core_params->host_nperio_tx_fifo_size)) {
  61823. + DWC_ERROR
  61824. + ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  61825. + val);
  61826. + }
  61827. + val =
  61828. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  61829. + 16);
  61830. + retval = -DWC_E_INVALID;
  61831. + }
  61832. +
  61833. + core_if->core_params->host_nperio_tx_fifo_size = val;
  61834. + return retval;
  61835. +}
  61836. +
  61837. +int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  61838. +{
  61839. + return core_if->core_params->host_nperio_tx_fifo_size;
  61840. +}
  61841. +
  61842. +int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61843. + int32_t val)
  61844. +{
  61845. + int retval = 0;
  61846. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61847. + DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  61848. + DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  61849. + return -DWC_E_INVALID;
  61850. + }
  61851. +
  61852. + if (val > ((core_if->hptxfsiz.d32) >> 16)) {
  61853. + if (dwc_otg_param_initialized
  61854. + (core_if->core_params->host_perio_tx_fifo_size)) {
  61855. + DWC_ERROR
  61856. + ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  61857. + val);
  61858. + }
  61859. + val = (core_if->hptxfsiz.d32) >> 16;
  61860. + retval = -DWC_E_INVALID;
  61861. + }
  61862. +
  61863. + core_if->core_params->host_perio_tx_fifo_size = val;
  61864. + return retval;
  61865. +}
  61866. +
  61867. +int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  61868. +{
  61869. + return core_if->core_params->host_perio_tx_fifo_size;
  61870. +}
  61871. +
  61872. +int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  61873. + int32_t val)
  61874. +{
  61875. + int retval = 0;
  61876. +
  61877. + if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  61878. + DWC_WARN("Wrong value for max_transfer_size\n");
  61879. + DWC_WARN("max_transfer_size must be 2047-524288\n");
  61880. + return -DWC_E_INVALID;
  61881. + }
  61882. +
  61883. + if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  61884. + if (dwc_otg_param_initialized
  61885. + (core_if->core_params->max_transfer_size)) {
  61886. + DWC_ERROR
  61887. + ("%d invalid for max_transfer_size. Check HW configuration.\n",
  61888. + val);
  61889. + }
  61890. + val =
  61891. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  61892. + 1);
  61893. + retval = -DWC_E_INVALID;
  61894. + }
  61895. +
  61896. + core_if->core_params->max_transfer_size = val;
  61897. + return retval;
  61898. +}
  61899. +
  61900. +int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  61901. +{
  61902. + return core_if->core_params->max_transfer_size;
  61903. +}
  61904. +
  61905. +int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  61906. +{
  61907. + int retval = 0;
  61908. +
  61909. + if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  61910. + DWC_WARN("Wrong value for max_packet_count\n");
  61911. + DWC_WARN("max_packet_count must be 15-511\n");
  61912. + return -DWC_E_INVALID;
  61913. + }
  61914. +
  61915. + if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  61916. + if (dwc_otg_param_initialized
  61917. + (core_if->core_params->max_packet_count)) {
  61918. + DWC_ERROR
  61919. + ("%d invalid for max_packet_count. Check HW configuration.\n",
  61920. + val);
  61921. + }
  61922. + val =
  61923. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  61924. + retval = -DWC_E_INVALID;
  61925. + }
  61926. +
  61927. + core_if->core_params->max_packet_count = val;
  61928. + return retval;
  61929. +}
  61930. +
  61931. +int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  61932. +{
  61933. + return core_if->core_params->max_packet_count;
  61934. +}
  61935. +
  61936. +int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  61937. +{
  61938. + int retval = 0;
  61939. +
  61940. + if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  61941. + DWC_WARN("Wrong value for host_channels\n");
  61942. + DWC_WARN("host_channels must be 1-16\n");
  61943. + return -DWC_E_INVALID;
  61944. + }
  61945. +
  61946. + if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  61947. + if (dwc_otg_param_initialized
  61948. + (core_if->core_params->host_channels)) {
  61949. + DWC_ERROR
  61950. + ("%d invalid for host_channels. Check HW configurations.\n",
  61951. + val);
  61952. + }
  61953. + val = (core_if->hwcfg2.b.num_host_chan + 1);
  61954. + retval = -DWC_E_INVALID;
  61955. + }
  61956. +
  61957. + core_if->core_params->host_channels = val;
  61958. + return retval;
  61959. +}
  61960. +
  61961. +int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  61962. +{
  61963. + return core_if->core_params->host_channels;
  61964. +}
  61965. +
  61966. +int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  61967. +{
  61968. + int retval = 0;
  61969. +
  61970. + if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  61971. + DWC_WARN("Wrong value for dev_endpoints\n");
  61972. + DWC_WARN("dev_endpoints must be 1-15\n");
  61973. + return -DWC_E_INVALID;
  61974. + }
  61975. +
  61976. + if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  61977. + if (dwc_otg_param_initialized
  61978. + (core_if->core_params->dev_endpoints)) {
  61979. + DWC_ERROR
  61980. + ("%d invalid for dev_endpoints. Check HW configurations.\n",
  61981. + val);
  61982. + }
  61983. + val = core_if->hwcfg2.b.num_dev_ep;
  61984. + retval = -DWC_E_INVALID;
  61985. + }
  61986. +
  61987. + core_if->core_params->dev_endpoints = val;
  61988. + return retval;
  61989. +}
  61990. +
  61991. +int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  61992. +{
  61993. + return core_if->core_params->dev_endpoints;
  61994. +}
  61995. +
  61996. +int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  61997. +{
  61998. + int retval = 0;
  61999. + int valid = 0;
  62000. +
  62001. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  62002. + DWC_WARN("Wrong value for phy_type\n");
  62003. + DWC_WARN("phy_type must be 0,1 or 2\n");
  62004. + return -DWC_E_INVALID;
  62005. + }
  62006. +#ifndef NO_FS_PHY_HW_CHECKS
  62007. + if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  62008. + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  62009. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  62010. + valid = 1;
  62011. + } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  62012. + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  62013. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  62014. + valid = 1;
  62015. + } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  62016. + (core_if->hwcfg2.b.fs_phy_type == 1)) {
  62017. + valid = 1;
  62018. + }
  62019. + if (!valid) {
  62020. + if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  62021. + DWC_ERROR
  62022. + ("%d invalid for phy_type. Check HW configurations.\n",
  62023. + val);
  62024. + }
  62025. + if (core_if->hwcfg2.b.hs_phy_type) {
  62026. + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  62027. + (core_if->hwcfg2.b.hs_phy_type == 1)) {
  62028. + val = DWC_PHY_TYPE_PARAM_UTMI;
  62029. + } else {
  62030. + val = DWC_PHY_TYPE_PARAM_ULPI;
  62031. + }
  62032. + }
  62033. + retval = -DWC_E_INVALID;
  62034. + }
  62035. +#endif
  62036. + core_if->core_params->phy_type = val;
  62037. + return retval;
  62038. +}
  62039. +
  62040. +int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  62041. +{
  62042. + return core_if->core_params->phy_type;
  62043. +}
  62044. +
  62045. +int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  62046. +{
  62047. + int retval = 0;
  62048. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62049. + DWC_WARN("Wrong value for speed parameter\n");
  62050. + DWC_WARN("max_speed parameter must be 0 or 1\n");
  62051. + return -DWC_E_INVALID;
  62052. + }
  62053. + if ((val == 0)
  62054. + && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  62055. + if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  62056. + DWC_ERROR
  62057. + ("%d invalid for speed paremter. Check HW configuration.\n",
  62058. + val);
  62059. + }
  62060. + val =
  62061. + (dwc_otg_get_param_phy_type(core_if) ==
  62062. + DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  62063. + retval = -DWC_E_INVALID;
  62064. + }
  62065. + core_if->core_params->speed = val;
  62066. + return retval;
  62067. +}
  62068. +
  62069. +int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  62070. +{
  62071. + return core_if->core_params->speed;
  62072. +}
  62073. +
  62074. +int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  62075. + int32_t val)
  62076. +{
  62077. + int retval = 0;
  62078. +
  62079. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62080. + DWC_WARN
  62081. + ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  62082. + DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  62083. + return -DWC_E_INVALID;
  62084. + }
  62085. +
  62086. + if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  62087. + && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  62088. + if (dwc_otg_param_initialized
  62089. + (core_if->core_params->host_ls_low_power_phy_clk)) {
  62090. + DWC_ERROR
  62091. + ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  62092. + val);
  62093. + }
  62094. + val =
  62095. + (dwc_otg_get_param_phy_type(core_if) ==
  62096. + DWC_PHY_TYPE_PARAM_FS) ?
  62097. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  62098. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  62099. + retval = -DWC_E_INVALID;
  62100. + }
  62101. +
  62102. + core_if->core_params->host_ls_low_power_phy_clk = val;
  62103. + return retval;
  62104. +}
  62105. +
  62106. +int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  62107. +{
  62108. + return core_if->core_params->host_ls_low_power_phy_clk;
  62109. +}
  62110. +
  62111. +int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  62112. +{
  62113. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62114. + DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  62115. + DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  62116. + return -DWC_E_INVALID;
  62117. + }
  62118. +
  62119. + core_if->core_params->phy_ulpi_ddr = val;
  62120. + return 0;
  62121. +}
  62122. +
  62123. +int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  62124. +{
  62125. + return core_if->core_params->phy_ulpi_ddr;
  62126. +}
  62127. +
  62128. +int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  62129. + int32_t val)
  62130. +{
  62131. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62132. + DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  62133. + DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  62134. + return -DWC_E_INVALID;
  62135. + }
  62136. +
  62137. + core_if->core_params->phy_ulpi_ext_vbus = val;
  62138. + return 0;
  62139. +}
  62140. +
  62141. +int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  62142. +{
  62143. + return core_if->core_params->phy_ulpi_ext_vbus;
  62144. +}
  62145. +
  62146. +int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  62147. +{
  62148. + if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  62149. + DWC_WARN("Wrong valaue for phy_utmi_width\n");
  62150. + DWC_WARN("phy_utmi_width must be 8 or 16\n");
  62151. + return -DWC_E_INVALID;
  62152. + }
  62153. +
  62154. + core_if->core_params->phy_utmi_width = val;
  62155. + return 0;
  62156. +}
  62157. +
  62158. +int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  62159. +{
  62160. + return core_if->core_params->phy_utmi_width;
  62161. +}
  62162. +
  62163. +int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  62164. +{
  62165. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62166. + DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  62167. + DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  62168. + return -DWC_E_INVALID;
  62169. + }
  62170. +
  62171. + core_if->core_params->ulpi_fs_ls = val;
  62172. + return 0;
  62173. +}
  62174. +
  62175. +int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  62176. +{
  62177. + return core_if->core_params->ulpi_fs_ls;
  62178. +}
  62179. +
  62180. +int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  62181. +{
  62182. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62183. + DWC_WARN("Wrong valaue for ts_dline\n");
  62184. + DWC_WARN("ts_dline must be 0 or 1\n");
  62185. + return -DWC_E_INVALID;
  62186. + }
  62187. +
  62188. + core_if->core_params->ts_dline = val;
  62189. + return 0;
  62190. +}
  62191. +
  62192. +int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  62193. +{
  62194. + return core_if->core_params->ts_dline;
  62195. +}
  62196. +
  62197. +int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62198. +{
  62199. + int retval = 0;
  62200. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62201. + DWC_WARN("Wrong valaue for i2c_enable\n");
  62202. + DWC_WARN("i2c_enable must be 0 or 1\n");
  62203. + return -DWC_E_INVALID;
  62204. + }
  62205. +#ifndef NO_FS_PHY_HW_CHECK
  62206. + if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  62207. + if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  62208. + DWC_ERROR
  62209. + ("%d invalid for i2c_enable. Check HW configuration.\n",
  62210. + val);
  62211. + }
  62212. + val = 0;
  62213. + retval = -DWC_E_INVALID;
  62214. + }
  62215. +#endif
  62216. +
  62217. + core_if->core_params->i2c_enable = val;
  62218. + return retval;
  62219. +}
  62220. +
  62221. +int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  62222. +{
  62223. + return core_if->core_params->i2c_enable;
  62224. +}
  62225. +
  62226. +int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62227. + int32_t val, int fifo_num)
  62228. +{
  62229. + int retval = 0;
  62230. +
  62231. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  62232. + DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  62233. + DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  62234. + return -DWC_E_INVALID;
  62235. + }
  62236. +
  62237. + if (val >
  62238. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  62239. + if (dwc_otg_param_initialized
  62240. + (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  62241. + DWC_ERROR
  62242. + ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  62243. + val, fifo_num);
  62244. + }
  62245. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  62246. + retval = -DWC_E_INVALID;
  62247. + }
  62248. +
  62249. + core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  62250. + return retval;
  62251. +}
  62252. +
  62253. +int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62254. + int fifo_num)
  62255. +{
  62256. + return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  62257. +}
  62258. +
  62259. +int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  62260. + int32_t val)
  62261. +{
  62262. + int retval = 0;
  62263. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62264. + DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  62265. + DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  62266. + return -DWC_E_INVALID;
  62267. + }
  62268. +
  62269. + if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  62270. + if (dwc_otg_param_initialized
  62271. + (core_if->core_params->en_multiple_tx_fifo)) {
  62272. + DWC_ERROR
  62273. + ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  62274. + val);
  62275. + }
  62276. + val = 0;
  62277. + retval = -DWC_E_INVALID;
  62278. + }
  62279. +
  62280. + core_if->core_params->en_multiple_tx_fifo = val;
  62281. + return retval;
  62282. +}
  62283. +
  62284. +int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  62285. +{
  62286. + return core_if->core_params->en_multiple_tx_fifo;
  62287. +}
  62288. +
  62289. +int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  62290. + int fifo_num)
  62291. +{
  62292. + int retval = 0;
  62293. +
  62294. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  62295. + DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  62296. + DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  62297. + return -DWC_E_INVALID;
  62298. + }
  62299. +
  62300. + if (val >
  62301. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  62302. + if (dwc_otg_param_initialized
  62303. + (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  62304. + DWC_ERROR
  62305. + ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  62306. + val, fifo_num);
  62307. + }
  62308. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  62309. + retval = -DWC_E_INVALID;
  62310. + }
  62311. +
  62312. + core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  62313. + return retval;
  62314. +}
  62315. +
  62316. +int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62317. + int fifo_num)
  62318. +{
  62319. + return core_if->core_params->dev_tx_fifo_size[fifo_num];
  62320. +}
  62321. +
  62322. +int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  62323. +{
  62324. + int retval = 0;
  62325. +
  62326. + if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  62327. + DWC_WARN("Wrong value for thr_ctl\n");
  62328. + DWC_WARN("thr_ctl must be 0-7\n");
  62329. + return -DWC_E_INVALID;
  62330. + }
  62331. +
  62332. + if ((val != 0) &&
  62333. + (!dwc_otg_get_param_dma_enable(core_if) ||
  62334. + !core_if->hwcfg4.b.ded_fifo_en)) {
  62335. + if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  62336. + DWC_ERROR
  62337. + ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  62338. + val);
  62339. + }
  62340. + val = 0;
  62341. + retval = -DWC_E_INVALID;
  62342. + }
  62343. +
  62344. + core_if->core_params->thr_ctl = val;
  62345. + return retval;
  62346. +}
  62347. +
  62348. +int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  62349. +{
  62350. + return core_if->core_params->thr_ctl;
  62351. +}
  62352. +
  62353. +int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62354. +{
  62355. + int retval = 0;
  62356. +
  62357. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62358. + DWC_WARN("Wrong value for lpm_enable\n");
  62359. + DWC_WARN("lpm_enable must be 0 or 1\n");
  62360. + return -DWC_E_INVALID;
  62361. + }
  62362. +
  62363. + if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  62364. + if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  62365. + DWC_ERROR
  62366. + ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  62367. + val);
  62368. + }
  62369. + val = 0;
  62370. + retval = -DWC_E_INVALID;
  62371. + }
  62372. +
  62373. + core_if->core_params->lpm_enable = val;
  62374. + return retval;
  62375. +}
  62376. +
  62377. +int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  62378. +{
  62379. + return core_if->core_params->lpm_enable;
  62380. +}
  62381. +
  62382. +int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  62383. +{
  62384. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  62385. + DWC_WARN("Wrong valaue for tx_thr_length\n");
  62386. + DWC_WARN("tx_thr_length must be 8 - 128\n");
  62387. + return -DWC_E_INVALID;
  62388. + }
  62389. +
  62390. + core_if->core_params->tx_thr_length = val;
  62391. + return 0;
  62392. +}
  62393. +
  62394. +int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  62395. +{
  62396. + return core_if->core_params->tx_thr_length;
  62397. +}
  62398. +
  62399. +int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  62400. +{
  62401. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  62402. + DWC_WARN("Wrong valaue for rx_thr_length\n");
  62403. + DWC_WARN("rx_thr_length must be 8 - 128\n");
  62404. + return -DWC_E_INVALID;
  62405. + }
  62406. +
  62407. + core_if->core_params->rx_thr_length = val;
  62408. + return 0;
  62409. +}
  62410. +
  62411. +int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  62412. +{
  62413. + return core_if->core_params->rx_thr_length;
  62414. +}
  62415. +
  62416. +int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  62417. +{
  62418. + if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  62419. + DWC_OTG_PARAM_TEST(val, 4, 4) &&
  62420. + DWC_OTG_PARAM_TEST(val, 8, 8) &&
  62421. + DWC_OTG_PARAM_TEST(val, 16, 16) &&
  62422. + DWC_OTG_PARAM_TEST(val, 32, 32) &&
  62423. + DWC_OTG_PARAM_TEST(val, 64, 64) &&
  62424. + DWC_OTG_PARAM_TEST(val, 128, 128) &&
  62425. + DWC_OTG_PARAM_TEST(val, 256, 256)) {
  62426. + DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  62427. + return -DWC_E_INVALID;
  62428. + }
  62429. + core_if->core_params->dma_burst_size = val;
  62430. + return 0;
  62431. +}
  62432. +
  62433. +int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  62434. +{
  62435. + return core_if->core_params->dma_burst_size;
  62436. +}
  62437. +
  62438. +int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62439. +{
  62440. + int retval = 0;
  62441. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62442. + DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  62443. + return -DWC_E_INVALID;
  62444. + }
  62445. + if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  62446. + if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  62447. + DWC_ERROR
  62448. + ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  62449. + val);
  62450. + }
  62451. + retval = -DWC_E_INVALID;
  62452. + val = 0;
  62453. + }
  62454. + core_if->core_params->pti_enable = val;
  62455. + return retval;
  62456. +}
  62457. +
  62458. +int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  62459. +{
  62460. + return core_if->core_params->pti_enable;
  62461. +}
  62462. +
  62463. +int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62464. +{
  62465. + int retval = 0;
  62466. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62467. + DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  62468. + return -DWC_E_INVALID;
  62469. + }
  62470. + if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  62471. + if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  62472. + DWC_ERROR
  62473. + ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  62474. + val);
  62475. + }
  62476. + retval = -DWC_E_INVALID;
  62477. + val = 0;
  62478. + }
  62479. + core_if->core_params->mpi_enable = val;
  62480. + return retval;
  62481. +}
  62482. +
  62483. +int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  62484. +{
  62485. + return core_if->core_params->mpi_enable;
  62486. +}
  62487. +
  62488. +int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62489. +{
  62490. + int retval = 0;
  62491. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62492. + DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  62493. + return -DWC_E_INVALID;
  62494. + }
  62495. + if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  62496. + if (dwc_otg_param_initialized
  62497. + (core_if->core_params->adp_supp_enable)) {
  62498. + DWC_ERROR
  62499. + ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  62500. + val);
  62501. + }
  62502. + retval = -DWC_E_INVALID;
  62503. + val = 0;
  62504. + }
  62505. + core_if->core_params->adp_supp_enable = val;
  62506. + /*Set OTG version 2.0 in case of enabling ADP*/
  62507. + if (val)
  62508. + dwc_otg_set_param_otg_ver(core_if, 1);
  62509. +
  62510. + return retval;
  62511. +}
  62512. +
  62513. +int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  62514. +{
  62515. + return core_if->core_params->adp_supp_enable;
  62516. +}
  62517. +
  62518. +int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  62519. +{
  62520. + int retval = 0;
  62521. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62522. + DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  62523. + DWC_WARN("ic_usb_cap must be 0 or 1\n");
  62524. + return -DWC_E_INVALID;
  62525. + }
  62526. +
  62527. + if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  62528. + if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  62529. + DWC_ERROR
  62530. + ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  62531. + val);
  62532. + }
  62533. + retval = -DWC_E_INVALID;
  62534. + val = 0;
  62535. + }
  62536. + core_if->core_params->ic_usb_cap = val;
  62537. + return retval;
  62538. +}
  62539. +
  62540. +int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  62541. +{
  62542. + return core_if->core_params->ic_usb_cap;
  62543. +}
  62544. +
  62545. +int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  62546. +{
  62547. + int retval = 0;
  62548. + int valid = 1;
  62549. +
  62550. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  62551. + DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  62552. + DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  62553. + return -DWC_E_INVALID;
  62554. + }
  62555. +
  62556. + if (val
  62557. + && (core_if->snpsid < OTG_CORE_REV_2_81a
  62558. + || !dwc_otg_get_param_thr_ctl(core_if))) {
  62559. + valid = 0;
  62560. + } else if (val
  62561. + && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  62562. + 4)) {
  62563. + valid = 0;
  62564. + }
  62565. + if (valid == 0) {
  62566. + if (dwc_otg_param_initialized
  62567. + (core_if->core_params->ahb_thr_ratio)) {
  62568. + DWC_ERROR
  62569. + ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  62570. + val);
  62571. + }
  62572. + retval = -DWC_E_INVALID;
  62573. + val = 0;
  62574. + }
  62575. +
  62576. + core_if->core_params->ahb_thr_ratio = val;
  62577. + return retval;
  62578. +}
  62579. +
  62580. +int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  62581. +{
  62582. + return core_if->core_params->ahb_thr_ratio;
  62583. +}
  62584. +
  62585. +int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  62586. +{
  62587. + int retval = 0;
  62588. + int valid = 1;
  62589. + hwcfg4_data_t hwcfg4 = {.d32 = 0 };
  62590. + hwcfg4.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  62591. +
  62592. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  62593. + DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  62594. + DWC_WARN("power_down must be 0 - 2\n");
  62595. + return -DWC_E_INVALID;
  62596. + }
  62597. +
  62598. + if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  62599. + valid = 0;
  62600. + }
  62601. + if ((val == 3)
  62602. + && ((core_if->snpsid < OTG_CORE_REV_3_00a)
  62603. + || (hwcfg4.b.xhiber == 0))) {
  62604. + valid = 0;
  62605. + }
  62606. + if (valid == 0) {
  62607. + if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  62608. + DWC_ERROR
  62609. + ("%d invalid for parameter power_down. Check HW configuration.\n",
  62610. + val);
  62611. + }
  62612. + retval = -DWC_E_INVALID;
  62613. + val = 0;
  62614. + }
  62615. + core_if->core_params->power_down = val;
  62616. + return retval;
  62617. +}
  62618. +
  62619. +int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  62620. +{
  62621. + return core_if->core_params->power_down;
  62622. +}
  62623. +
  62624. +int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  62625. +{
  62626. + int retval = 0;
  62627. + int valid = 1;
  62628. +
  62629. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62630. + DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  62631. + DWC_WARN("reload_ctl must be 0 or 1\n");
  62632. + return -DWC_E_INVALID;
  62633. + }
  62634. +
  62635. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  62636. + valid = 0;
  62637. + }
  62638. + if (valid == 0) {
  62639. + if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  62640. + DWC_ERROR("%d invalid for parameter reload_ctl."
  62641. + "Check HW configuration.\n", val);
  62642. + }
  62643. + retval = -DWC_E_INVALID;
  62644. + val = 0;
  62645. + }
  62646. + core_if->core_params->reload_ctl = val;
  62647. + return retval;
  62648. +}
  62649. +
  62650. +int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  62651. +{
  62652. + return core_if->core_params->reload_ctl;
  62653. +}
  62654. +
  62655. +int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  62656. +{
  62657. + int retval = 0;
  62658. + int valid = 1;
  62659. +
  62660. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62661. + DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  62662. + DWC_WARN("dev_out_nak must be 0 or 1\n");
  62663. + return -DWC_E_INVALID;
  62664. + }
  62665. +
  62666. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  62667. + !(core_if->core_params->dma_desc_enable))) {
  62668. + valid = 0;
  62669. + }
  62670. + if (valid == 0) {
  62671. + if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  62672. + DWC_ERROR("%d invalid for parameter dev_out_nak."
  62673. + "Check HW configuration.\n", val);
  62674. + }
  62675. + retval = -DWC_E_INVALID;
  62676. + val = 0;
  62677. + }
  62678. + core_if->core_params->dev_out_nak = val;
  62679. + return retval;
  62680. +}
  62681. +
  62682. +int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  62683. +{
  62684. + return core_if->core_params->dev_out_nak;
  62685. +}
  62686. +
  62687. +int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  62688. +{
  62689. + int retval = 0;
  62690. + int valid = 1;
  62691. +
  62692. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62693. + DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  62694. + DWC_WARN("cont_on_bna must be 0 or 1\n");
  62695. + return -DWC_E_INVALID;
  62696. + }
  62697. +
  62698. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  62699. + !(core_if->core_params->dma_desc_enable))) {
  62700. + valid = 0;
  62701. + }
  62702. + if (valid == 0) {
  62703. + if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  62704. + DWC_ERROR("%d invalid for parameter cont_on_bna."
  62705. + "Check HW configuration.\n", val);
  62706. + }
  62707. + retval = -DWC_E_INVALID;
  62708. + val = 0;
  62709. + }
  62710. + core_if->core_params->cont_on_bna = val;
  62711. + return retval;
  62712. +}
  62713. +
  62714. +int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  62715. +{
  62716. + return core_if->core_params->cont_on_bna;
  62717. +}
  62718. +
  62719. +int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  62720. +{
  62721. + int retval = 0;
  62722. + int valid = 1;
  62723. +
  62724. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62725. + DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  62726. + DWC_WARN("ahb_single must be 0 or 1\n");
  62727. + return -DWC_E_INVALID;
  62728. + }
  62729. +
  62730. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  62731. + valid = 0;
  62732. + }
  62733. + if (valid == 0) {
  62734. + if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  62735. + DWC_ERROR("%d invalid for parameter ahb_single."
  62736. + "Check HW configuration.\n", val);
  62737. + }
  62738. + retval = -DWC_E_INVALID;
  62739. + val = 0;
  62740. + }
  62741. + core_if->core_params->ahb_single = val;
  62742. + return retval;
  62743. +}
  62744. +
  62745. +int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  62746. +{
  62747. + return core_if->core_params->ahb_single;
  62748. +}
  62749. +
  62750. +int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  62751. +{
  62752. + int retval = 0;
  62753. +
  62754. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62755. + DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  62756. + DWC_WARN
  62757. + ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  62758. + return -DWC_E_INVALID;
  62759. + }
  62760. +
  62761. + core_if->core_params->otg_ver = val;
  62762. + return retval;
  62763. +}
  62764. +
  62765. +int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  62766. +{
  62767. + return core_if->core_params->otg_ver;
  62768. +}
  62769. +
  62770. +uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  62771. +{
  62772. + gotgctl_data_t otgctl;
  62773. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62774. + return otgctl.b.hstnegscs;
  62775. +}
  62776. +
  62777. +uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  62778. +{
  62779. + gotgctl_data_t otgctl;
  62780. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62781. + return otgctl.b.sesreqscs;
  62782. +}
  62783. +
  62784. +void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  62785. +{
  62786. + if(core_if->otg_ver == 0) {
  62787. + gotgctl_data_t otgctl;
  62788. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62789. + otgctl.b.hnpreq = val;
  62790. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  62791. + } else {
  62792. + core_if->otg_sts = val;
  62793. + }
  62794. +}
  62795. +
  62796. +uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  62797. +{
  62798. + return core_if->snpsid;
  62799. +}
  62800. +
  62801. +uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  62802. +{
  62803. + gintsts_data_t gintsts;
  62804. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  62805. + return gintsts.b.curmode;
  62806. +}
  62807. +
  62808. +uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  62809. +{
  62810. + gusbcfg_data_t usbcfg;
  62811. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62812. + return usbcfg.b.hnpcap;
  62813. +}
  62814. +
  62815. +void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  62816. +{
  62817. + gusbcfg_data_t usbcfg;
  62818. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62819. + usbcfg.b.hnpcap = val;
  62820. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  62821. +}
  62822. +
  62823. +uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  62824. +{
  62825. + gusbcfg_data_t usbcfg;
  62826. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62827. + return usbcfg.b.srpcap;
  62828. +}
  62829. +
  62830. +void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  62831. +{
  62832. + gusbcfg_data_t usbcfg;
  62833. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62834. + usbcfg.b.srpcap = val;
  62835. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  62836. +}
  62837. +
  62838. +uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  62839. +{
  62840. + dcfg_data_t dcfg;
  62841. + /* originally: dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg); */
  62842. +
  62843. + dcfg.d32 = -1; //GRAYG
  62844. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)\n", __func__, core_if);
  62845. + if (NULL == core_if)
  62846. + DWC_ERROR("reg request with NULL core_if\n");
  62847. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)\n", __func__,
  62848. + core_if, core_if->dev_if);
  62849. + if (NULL == core_if->dev_if)
  62850. + DWC_ERROR("reg request with NULL dev_if\n");
  62851. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)->"
  62852. + "dev_global_regs(%p)\n", __func__,
  62853. + core_if, core_if->dev_if,
  62854. + core_if->dev_if->dev_global_regs);
  62855. + if (NULL == core_if->dev_if->dev_global_regs)
  62856. + DWC_ERROR("reg request with NULL dev_global_regs\n");
  62857. + else {
  62858. + DWC_DEBUGPL(DBG_CILV, "%s - &core_if(%p)->dev_if(%p)->"
  62859. + "dev_global_regs(%p)->dcfg = %p\n", __func__,
  62860. + core_if, core_if->dev_if,
  62861. + core_if->dev_if->dev_global_regs,
  62862. + &core_if->dev_if->dev_global_regs->dcfg);
  62863. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  62864. + }
  62865. + return dcfg.b.devspd;
  62866. +}
  62867. +
  62868. +void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  62869. +{
  62870. + dcfg_data_t dcfg;
  62871. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  62872. + dcfg.b.devspd = val;
  62873. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  62874. +}
  62875. +
  62876. +uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  62877. +{
  62878. + hprt0_data_t hprt0;
  62879. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  62880. + return hprt0.b.prtconnsts;
  62881. +}
  62882. +
  62883. +uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  62884. +{
  62885. + dsts_data_t dsts;
  62886. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  62887. + return dsts.b.enumspd;
  62888. +}
  62889. +
  62890. +uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  62891. +{
  62892. + hprt0_data_t hprt0;
  62893. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  62894. + return hprt0.b.prtpwr;
  62895. +
  62896. +}
  62897. +
  62898. +uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  62899. +{
  62900. + return core_if->hibernation_suspend;
  62901. +}
  62902. +
  62903. +void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  62904. +{
  62905. + hprt0_data_t hprt0;
  62906. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  62907. + hprt0.b.prtpwr = val;
  62908. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  62909. +}
  62910. +
  62911. +uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  62912. +{
  62913. + hprt0_data_t hprt0;
  62914. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  62915. + return hprt0.b.prtsusp;
  62916. +
  62917. +}
  62918. +
  62919. +void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  62920. +{
  62921. + hprt0_data_t hprt0;
  62922. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  62923. + hprt0.b.prtsusp = val;
  62924. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  62925. +}
  62926. +
  62927. +uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  62928. +{
  62929. + hfir_data_t hfir;
  62930. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  62931. + return hfir.b.frint;
  62932. +
  62933. +}
  62934. +
  62935. +void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  62936. +{
  62937. + hfir_data_t hfir;
  62938. + uint32_t fram_int;
  62939. + fram_int = calc_frame_interval(core_if);
  62940. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  62941. + if (!core_if->core_params->reload_ctl) {
  62942. + DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  62943. + "not set to 1.\nShould load driver with reload_ctl=1"
  62944. + " module parameter\n");
  62945. + return;
  62946. + }
  62947. + switch (fram_int) {
  62948. + case 3750:
  62949. + if ((val < 3350) || (val > 4150)) {
  62950. + DWC_WARN("HFIR interval for HS core and 30 MHz"
  62951. + "clock freq should be from 3350 to 4150\n");
  62952. + return;
  62953. + }
  62954. + break;
  62955. + case 30000:
  62956. + if ((val < 26820) || (val > 33180)) {
  62957. + DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  62958. + "clock freq should be from 26820 to 33180\n");
  62959. + return;
  62960. + }
  62961. + break;
  62962. + case 6000:
  62963. + if ((val < 5360) || (val > 6640)) {
  62964. + DWC_WARN("HFIR interval for HS core and 48 MHz"
  62965. + "clock freq should be from 5360 to 6640\n");
  62966. + return;
  62967. + }
  62968. + break;
  62969. + case 48000:
  62970. + if ((val < 42912) || (val > 53088)) {
  62971. + DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  62972. + "clock freq should be from 42912 to 53088\n");
  62973. + return;
  62974. + }
  62975. + break;
  62976. + case 7500:
  62977. + if ((val < 6700) || (val > 8300)) {
  62978. + DWC_WARN("HFIR interval for HS core and 60 MHz"
  62979. + "clock freq should be from 6700 to 8300\n");
  62980. + return;
  62981. + }
  62982. + break;
  62983. + case 60000:
  62984. + if ((val < 53640) || (val > 65536)) {
  62985. + DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  62986. + "clock freq should be from 53640 to 65536\n");
  62987. + return;
  62988. + }
  62989. + break;
  62990. + default:
  62991. + DWC_WARN("Unknown frame interval\n");
  62992. + return;
  62993. + break;
  62994. +
  62995. + }
  62996. + hfir.b.frint = val;
  62997. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  62998. +}
  62999. +
  63000. +uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  63001. +{
  63002. + hcfg_data_t hcfg;
  63003. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  63004. + return hcfg.b.modechtimen;
  63005. +
  63006. +}
  63007. +
  63008. +void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  63009. +{
  63010. + hcfg_data_t hcfg;
  63011. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  63012. + hcfg.b.modechtimen = val;
  63013. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  63014. +}
  63015. +
  63016. +void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  63017. +{
  63018. + hprt0_data_t hprt0;
  63019. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  63020. + hprt0.b.prtres = val;
  63021. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  63022. +}
  63023. +
  63024. +uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  63025. +{
  63026. + dctl_data_t dctl;
  63027. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  63028. + return dctl.b.rmtwkupsig;
  63029. +}
  63030. +
  63031. +uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  63032. +{
  63033. + glpmcfg_data_t lpmcfg;
  63034. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63035. +
  63036. + DWC_ASSERT(!
  63037. + ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  63038. + "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  63039. + core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  63040. +
  63041. + return lpmcfg.b.prt_sleep_sts;
  63042. +}
  63043. +
  63044. +uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  63045. +{
  63046. + glpmcfg_data_t lpmcfg;
  63047. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63048. + return lpmcfg.b.rem_wkup_en;
  63049. +}
  63050. +
  63051. +uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  63052. +{
  63053. + glpmcfg_data_t lpmcfg;
  63054. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63055. + return lpmcfg.b.appl_resp;
  63056. +}
  63057. +
  63058. +void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  63059. +{
  63060. + glpmcfg_data_t lpmcfg;
  63061. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63062. + lpmcfg.b.appl_resp = val;
  63063. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  63064. +}
  63065. +
  63066. +uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  63067. +{
  63068. + glpmcfg_data_t lpmcfg;
  63069. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63070. + return lpmcfg.b.hsic_connect;
  63071. +}
  63072. +
  63073. +void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  63074. +{
  63075. + glpmcfg_data_t lpmcfg;
  63076. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63077. + lpmcfg.b.hsic_connect = val;
  63078. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  63079. +}
  63080. +
  63081. +uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  63082. +{
  63083. + glpmcfg_data_t lpmcfg;
  63084. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63085. + return lpmcfg.b.inv_sel_hsic;
  63086. +
  63087. +}
  63088. +
  63089. +void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  63090. +{
  63091. + glpmcfg_data_t lpmcfg;
  63092. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63093. + lpmcfg.b.inv_sel_hsic = val;
  63094. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  63095. +}
  63096. +
  63097. +uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  63098. +{
  63099. + return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  63100. +}
  63101. +
  63102. +void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  63103. +{
  63104. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  63105. +}
  63106. +
  63107. +uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  63108. +{
  63109. + return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  63110. +}
  63111. +
  63112. +void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  63113. +{
  63114. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  63115. +}
  63116. +
  63117. +uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  63118. +{
  63119. + return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  63120. +}
  63121. +
  63122. +void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  63123. +{
  63124. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  63125. +}
  63126. +
  63127. +uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  63128. +{
  63129. + return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  63130. +}
  63131. +
  63132. +void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  63133. +{
  63134. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  63135. +}
  63136. +
  63137. +uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  63138. +{
  63139. + return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  63140. +}
  63141. +
  63142. +void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  63143. +{
  63144. + DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  63145. +}
  63146. +
  63147. +uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  63148. +{
  63149. + return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  63150. +}
  63151. +
  63152. +void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  63153. +{
  63154. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  63155. +}
  63156. +
  63157. +uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  63158. +{
  63159. + return DWC_READ_REG32(core_if->host_if->hprt0);
  63160. +
  63161. +}
  63162. +
  63163. +void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  63164. +{
  63165. + DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  63166. +}
  63167. +
  63168. +uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  63169. +{
  63170. + return DWC_READ_REG32(&core_if->core_global_regs->guid);
  63171. +}
  63172. +
  63173. +void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  63174. +{
  63175. + DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  63176. +}
  63177. +
  63178. +uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  63179. +{
  63180. + return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  63181. +}
  63182. +
  63183. +uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  63184. +{
  63185. + return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  63186. +}
  63187. +
  63188. +/**
  63189. + * Start the SRP timer to detect when the SRP does not complete within
  63190. + * 6 seconds.
  63191. + *
  63192. + * @param core_if the pointer to core_if strucure.
  63193. + */
  63194. +void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  63195. +{
  63196. + core_if->srp_timer_started = 1;
  63197. + DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  63198. +}
  63199. +
  63200. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  63201. +{
  63202. + uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  63203. + gotgctl_data_t mem;
  63204. + gotgctl_data_t val;
  63205. +
  63206. + val.d32 = DWC_READ_REG32(addr);
  63207. + if (val.b.sesreq) {
  63208. + DWC_ERROR("Session Request Already active!\n");
  63209. + return;
  63210. + }
  63211. +
  63212. + DWC_INFO("Session Request Initated\n"); //NOTICE
  63213. + mem.d32 = DWC_READ_REG32(addr);
  63214. + mem.b.sesreq = 1;
  63215. + DWC_WRITE_REG32(addr, mem.d32);
  63216. +
  63217. + /* Start the SRP timer */
  63218. + dwc_otg_pcd_start_srp_timer(core_if);
  63219. + return;
  63220. +}
  63221. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_cil.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h
  63222. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_cil.h 1970-01-01 01:00:00.000000000 +0100
  63223. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h 2014-04-24 16:04:39.815124215 +0200
  63224. @@ -0,0 +1,1464 @@
  63225. +/* ==========================================================================
  63226. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  63227. + * $Revision: #123 $
  63228. + * $Date: 2012/08/10 $
  63229. + * $Change: 2047372 $
  63230. + *
  63231. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  63232. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  63233. + * otherwise expressly agreed to in writing between Synopsys and you.
  63234. + *
  63235. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  63236. + * any End User Software License Agreement or Agreement for Licensed Product
  63237. + * with Synopsys or any supplement thereto. You are permitted to use and
  63238. + * redistribute this Software in source and binary forms, with or without
  63239. + * modification, provided that redistributions of source code must retain this
  63240. + * notice. You may not view, use, disclose, copy or distribute this file or
  63241. + * any information contained herein except pursuant to this license grant from
  63242. + * Synopsys. If you do not agree with this notice, including the disclaimer
  63243. + * below, then you are not authorized to use the Software.
  63244. + *
  63245. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  63246. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  63247. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63248. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  63249. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  63250. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  63251. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  63252. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  63253. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  63254. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  63255. + * DAMAGE.
  63256. + * ========================================================================== */
  63257. +
  63258. +#if !defined(__DWC_CIL_H__)
  63259. +#define __DWC_CIL_H__
  63260. +
  63261. +#include "dwc_list.h"
  63262. +#include "dwc_otg_dbg.h"
  63263. +#include "dwc_otg_regs.h"
  63264. +
  63265. +#include "dwc_otg_core_if.h"
  63266. +#include "dwc_otg_adp.h"
  63267. +
  63268. +/**
  63269. + * @file
  63270. + * This file contains the interface to the Core Interface Layer.
  63271. + */
  63272. +
  63273. +#ifdef DWC_UTE_CFI
  63274. +
  63275. +#define MAX_DMA_DESCS_PER_EP 256
  63276. +
  63277. +/**
  63278. + * Enumeration for the data buffer mode
  63279. + */
  63280. +typedef enum _data_buffer_mode {
  63281. + BM_STANDARD = 0, /* data buffer is in normal mode */
  63282. + BM_SG = 1, /* data buffer uses the scatter/gather mode */
  63283. + BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  63284. + BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  63285. + BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  63286. +} data_buffer_mode_e;
  63287. +#endif //DWC_UTE_CFI
  63288. +
  63289. +/** Macros defined for DWC OTG HW Release version */
  63290. +
  63291. +#define OTG_CORE_REV_2_60a 0x4F54260A
  63292. +#define OTG_CORE_REV_2_71a 0x4F54271A
  63293. +#define OTG_CORE_REV_2_72a 0x4F54272A
  63294. +#define OTG_CORE_REV_2_80a 0x4F54280A
  63295. +#define OTG_CORE_REV_2_81a 0x4F54281A
  63296. +#define OTG_CORE_REV_2_90a 0x4F54290A
  63297. +#define OTG_CORE_REV_2_91a 0x4F54291A
  63298. +#define OTG_CORE_REV_2_92a 0x4F54292A
  63299. +#define OTG_CORE_REV_2_93a 0x4F54293A
  63300. +#define OTG_CORE_REV_2_94a 0x4F54294A
  63301. +#define OTG_CORE_REV_3_00a 0x4F54300A
  63302. +
  63303. +/**
  63304. + * Information for each ISOC packet.
  63305. + */
  63306. +typedef struct iso_pkt_info {
  63307. + uint32_t offset;
  63308. + uint32_t length;
  63309. + int32_t status;
  63310. +} iso_pkt_info_t;
  63311. +
  63312. +/**
  63313. + * The <code>dwc_ep</code> structure represents the state of a single
  63314. + * endpoint when acting in device mode. It contains the data items
  63315. + * needed for an endpoint to be activated and transfer packets.
  63316. + */
  63317. +typedef struct dwc_ep {
  63318. + /** EP number used for register address lookup */
  63319. + uint8_t num;
  63320. + /** EP direction 0 = OUT */
  63321. + unsigned is_in:1;
  63322. + /** EP active. */
  63323. + unsigned active:1;
  63324. +
  63325. + /**
  63326. + * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  63327. + * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  63328. + unsigned tx_fifo_num:4;
  63329. + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  63330. + unsigned type:2;
  63331. +#define DWC_OTG_EP_TYPE_CONTROL 0
  63332. +#define DWC_OTG_EP_TYPE_ISOC 1
  63333. +#define DWC_OTG_EP_TYPE_BULK 2
  63334. +#define DWC_OTG_EP_TYPE_INTR 3
  63335. +
  63336. + /** DATA start PID for INTR and BULK EP */
  63337. + unsigned data_pid_start:1;
  63338. + /** Frame (even/odd) for ISOC EP */
  63339. + unsigned even_odd_frame:1;
  63340. + /** Max Packet bytes */
  63341. + unsigned maxpacket:11;
  63342. +
  63343. + /** Max Transfer size */
  63344. + uint32_t maxxfer;
  63345. +
  63346. + /** @name Transfer state */
  63347. + /** @{ */
  63348. +
  63349. + /**
  63350. + * Pointer to the beginning of the transfer buffer -- do not modify
  63351. + * during transfer.
  63352. + */
  63353. +
  63354. + dwc_dma_t dma_addr;
  63355. +
  63356. + dwc_dma_t dma_desc_addr;
  63357. + dwc_otg_dev_dma_desc_t *desc_addr;
  63358. +
  63359. + uint8_t *start_xfer_buff;
  63360. + /** pointer to the transfer buffer */
  63361. + uint8_t *xfer_buff;
  63362. + /** Number of bytes to transfer */
  63363. + unsigned xfer_len:19;
  63364. + /** Number of bytes transferred. */
  63365. + unsigned xfer_count:19;
  63366. + /** Sent ZLP */
  63367. + unsigned sent_zlp:1;
  63368. + /** Total len for control transfer */
  63369. + unsigned total_len:19;
  63370. +
  63371. + /** stall clear flag */
  63372. + unsigned stall_clear_flag:1;
  63373. +
  63374. + /** SETUP pkt cnt rollover flag for EP0 out*/
  63375. + unsigned stp_rollover;
  63376. +
  63377. +#ifdef DWC_UTE_CFI
  63378. + /* The buffer mode */
  63379. + data_buffer_mode_e buff_mode;
  63380. +
  63381. + /* The chain of DMA descriptors.
  63382. + * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  63383. + */
  63384. + dwc_otg_dma_desc_t *descs;
  63385. +
  63386. + /* The DMA address of the descriptors chain start */
  63387. + dma_addr_t descs_dma_addr;
  63388. + /** This variable stores the length of the last enqueued request */
  63389. + uint32_t cfi_req_len;
  63390. +#endif //DWC_UTE_CFI
  63391. +
  63392. +/** Max DMA Descriptor count for any EP */
  63393. +#define MAX_DMA_DESC_CNT 256
  63394. + /** Allocated DMA Desc count */
  63395. + uint32_t desc_cnt;
  63396. +
  63397. + /** bInterval */
  63398. + uint32_t bInterval;
  63399. + /** Next frame num to setup next ISOC transfer */
  63400. + uint32_t frame_num;
  63401. + /** Indicates SOF number overrun in DSTS */
  63402. + uint8_t frm_overrun;
  63403. +
  63404. +#ifdef DWC_UTE_PER_IO
  63405. + /** Next frame num for which will be setup DMA Desc */
  63406. + uint32_t xiso_frame_num;
  63407. + /** bInterval */
  63408. + uint32_t xiso_bInterval;
  63409. + /** Count of currently active transfers - shall be either 0 or 1 */
  63410. + int xiso_active_xfers;
  63411. + int xiso_queued_xfers;
  63412. +#endif
  63413. +#ifdef DWC_EN_ISOC
  63414. + /**
  63415. + * Variables specific for ISOC EPs
  63416. + *
  63417. + */
  63418. + /** DMA addresses of ISOC buffers */
  63419. + dwc_dma_t dma_addr0;
  63420. + dwc_dma_t dma_addr1;
  63421. +
  63422. + dwc_dma_t iso_dma_desc_addr;
  63423. + dwc_otg_dev_dma_desc_t *iso_desc_addr;
  63424. +
  63425. + /** pointer to the transfer buffers */
  63426. + uint8_t *xfer_buff0;
  63427. + uint8_t *xfer_buff1;
  63428. +
  63429. + /** number of ISOC Buffer is processing */
  63430. + uint32_t proc_buf_num;
  63431. + /** Interval of ISOC Buffer processing */
  63432. + uint32_t buf_proc_intrvl;
  63433. + /** Data size for regular frame */
  63434. + uint32_t data_per_frame;
  63435. +
  63436. + /* todo - pattern data support is to be implemented in the future */
  63437. + /** Data size for pattern frame */
  63438. + uint32_t data_pattern_frame;
  63439. + /** Frame number of pattern data */
  63440. + uint32_t sync_frame;
  63441. +
  63442. + /** bInterval */
  63443. + uint32_t bInterval;
  63444. + /** ISO Packet number per frame */
  63445. + uint32_t pkt_per_frm;
  63446. + /** Next frame num for which will be setup DMA Desc */
  63447. + uint32_t next_frame;
  63448. + /** Number of packets per buffer processing */
  63449. + uint32_t pkt_cnt;
  63450. + /** Info for all isoc packets */
  63451. + iso_pkt_info_t *pkt_info;
  63452. + /** current pkt number */
  63453. + uint32_t cur_pkt;
  63454. + /** current pkt number */
  63455. + uint8_t *cur_pkt_addr;
  63456. + /** current pkt number */
  63457. + uint32_t cur_pkt_dma_addr;
  63458. +#endif /* DWC_EN_ISOC */
  63459. +
  63460. +/** @} */
  63461. +} dwc_ep_t;
  63462. +
  63463. +/*
  63464. + * Reasons for halting a host channel.
  63465. + */
  63466. +typedef enum dwc_otg_halt_status {
  63467. + DWC_OTG_HC_XFER_NO_HALT_STATUS,
  63468. + DWC_OTG_HC_XFER_COMPLETE,
  63469. + DWC_OTG_HC_XFER_URB_COMPLETE,
  63470. + DWC_OTG_HC_XFER_ACK,
  63471. + DWC_OTG_HC_XFER_NAK,
  63472. + DWC_OTG_HC_XFER_NYET,
  63473. + DWC_OTG_HC_XFER_STALL,
  63474. + DWC_OTG_HC_XFER_XACT_ERR,
  63475. + DWC_OTG_HC_XFER_FRAME_OVERRUN,
  63476. + DWC_OTG_HC_XFER_BABBLE_ERR,
  63477. + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  63478. + DWC_OTG_HC_XFER_AHB_ERR,
  63479. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  63480. + DWC_OTG_HC_XFER_URB_DEQUEUE
  63481. +} dwc_otg_halt_status_e;
  63482. +
  63483. +/**
  63484. + * Host channel descriptor. This structure represents the state of a single
  63485. + * host channel when acting in host mode. It contains the data items needed to
  63486. + * transfer packets to an endpoint via a host channel.
  63487. + */
  63488. +typedef struct dwc_hc {
  63489. + /** Host channel number used for register address lookup */
  63490. + uint8_t hc_num;
  63491. +
  63492. + /** Device to access */
  63493. + unsigned dev_addr:7;
  63494. +
  63495. + /** EP to access */
  63496. + unsigned ep_num:4;
  63497. +
  63498. + /** EP direction. 0: OUT, 1: IN */
  63499. + unsigned ep_is_in:1;
  63500. +
  63501. + /**
  63502. + * EP speed.
  63503. + * One of the following values:
  63504. + * - DWC_OTG_EP_SPEED_LOW
  63505. + * - DWC_OTG_EP_SPEED_FULL
  63506. + * - DWC_OTG_EP_SPEED_HIGH
  63507. + */
  63508. + unsigned speed:2;
  63509. +#define DWC_OTG_EP_SPEED_LOW 0
  63510. +#define DWC_OTG_EP_SPEED_FULL 1
  63511. +#define DWC_OTG_EP_SPEED_HIGH 2
  63512. +
  63513. + /**
  63514. + * Endpoint type.
  63515. + * One of the following values:
  63516. + * - DWC_OTG_EP_TYPE_CONTROL: 0
  63517. + * - DWC_OTG_EP_TYPE_ISOC: 1
  63518. + * - DWC_OTG_EP_TYPE_BULK: 2
  63519. + * - DWC_OTG_EP_TYPE_INTR: 3
  63520. + */
  63521. + unsigned ep_type:2;
  63522. +
  63523. + /** Max packet size in bytes */
  63524. + unsigned max_packet:11;
  63525. +
  63526. + /**
  63527. + * PID for initial transaction.
  63528. + * 0: DATA0,<br>
  63529. + * 1: DATA2,<br>
  63530. + * 2: DATA1,<br>
  63531. + * 3: MDATA (non-Control EP),
  63532. + * SETUP (Control EP)
  63533. + */
  63534. + unsigned data_pid_start:2;
  63535. +#define DWC_OTG_HC_PID_DATA0 0
  63536. +#define DWC_OTG_HC_PID_DATA2 1
  63537. +#define DWC_OTG_HC_PID_DATA1 2
  63538. +#define DWC_OTG_HC_PID_MDATA 3
  63539. +#define DWC_OTG_HC_PID_SETUP 3
  63540. +
  63541. + /** Number of periodic transactions per (micro)frame */
  63542. + unsigned multi_count:2;
  63543. +
  63544. + /** @name Transfer State */
  63545. + /** @{ */
  63546. +
  63547. + /** Pointer to the current transfer buffer position. */
  63548. + uint8_t *xfer_buff;
  63549. + /**
  63550. + * In Buffer DMA mode this buffer will be used
  63551. + * if xfer_buff is not DWORD aligned.
  63552. + */
  63553. + dwc_dma_t align_buff;
  63554. + /** Total number of bytes to transfer. */
  63555. + uint32_t xfer_len;
  63556. + /** Number of bytes transferred so far. */
  63557. + uint32_t xfer_count;
  63558. + /** Packet count at start of transfer.*/
  63559. + uint16_t start_pkt_count;
  63560. +
  63561. + /**
  63562. + * Flag to indicate whether the transfer has been started. Set to 1 if
  63563. + * it has been started, 0 otherwise.
  63564. + */
  63565. + uint8_t xfer_started;
  63566. +
  63567. + /**
  63568. + * Set to 1 to indicate that a PING request should be issued on this
  63569. + * channel. If 0, process normally.
  63570. + */
  63571. + uint8_t do_ping;
  63572. +
  63573. + /**
  63574. + * Set to 1 to indicate that the error count for this transaction is
  63575. + * non-zero. Set to 0 if the error count is 0.
  63576. + */
  63577. + uint8_t error_state;
  63578. +
  63579. + /**
  63580. + * Set to 1 to indicate that this channel should be halted the next
  63581. + * time a request is queued for the channel. This is necessary in
  63582. + * slave mode if no request queue space is available when an attempt
  63583. + * is made to halt the channel.
  63584. + */
  63585. + uint8_t halt_on_queue;
  63586. +
  63587. + /**
  63588. + * Set to 1 if the host channel has been halted, but the core is not
  63589. + * finished flushing queued requests. Otherwise 0.
  63590. + */
  63591. + uint8_t halt_pending;
  63592. +
  63593. + /**
  63594. + * Reason for halting the host channel.
  63595. + */
  63596. + dwc_otg_halt_status_e halt_status;
  63597. +
  63598. + /*
  63599. + * Split settings for the host channel
  63600. + */
  63601. + uint8_t do_split; /**< Enable split for the channel */
  63602. + uint8_t complete_split; /**< Enable complete split */
  63603. + uint8_t hub_addr; /**< Address of high speed hub */
  63604. +
  63605. + uint8_t port_addr; /**< Port of the low/full speed device */
  63606. + /** Split transaction position
  63607. + * One of the following values:
  63608. + * - DWC_HCSPLIT_XACTPOS_MID
  63609. + * - DWC_HCSPLIT_XACTPOS_BEGIN
  63610. + * - DWC_HCSPLIT_XACTPOS_END
  63611. + * - DWC_HCSPLIT_XACTPOS_ALL */
  63612. + uint8_t xact_pos;
  63613. +
  63614. + /** Set when the host channel does a short read. */
  63615. + uint8_t short_read;
  63616. +
  63617. + /**
  63618. + * Number of requests issued for this channel since it was assigned to
  63619. + * the current transfer (not counting PINGs).
  63620. + */
  63621. + uint8_t requests;
  63622. +
  63623. + /**
  63624. + * Queue Head for the transfer being processed by this channel.
  63625. + */
  63626. + struct dwc_otg_qh *qh;
  63627. +
  63628. + /** @} */
  63629. +
  63630. + /** Entry in list of host channels. */
  63631. + DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  63632. +
  63633. + /** @name Descriptor DMA support */
  63634. + /** @{ */
  63635. +
  63636. + /** Number of Transfer Descriptors */
  63637. + uint16_t ntd;
  63638. +
  63639. + /** Descriptor List DMA address */
  63640. + dwc_dma_t desc_list_addr;
  63641. +
  63642. + /** Scheduling micro-frame bitmap. */
  63643. + uint8_t schinfo;
  63644. +
  63645. + /** @} */
  63646. +} dwc_hc_t;
  63647. +
  63648. +/**
  63649. + * The following parameters may be specified when starting the module. These
  63650. + * parameters define how the DWC_otg controller should be configured.
  63651. + */
  63652. +typedef struct dwc_otg_core_params {
  63653. + int32_t opt;
  63654. +
  63655. + /**
  63656. + * Specifies the OTG capabilities. The driver will automatically
  63657. + * detect the value for this parameter if none is specified.
  63658. + * 0 - HNP and SRP capable (default)
  63659. + * 1 - SRP Only capable
  63660. + * 2 - No HNP/SRP capable
  63661. + */
  63662. + int32_t otg_cap;
  63663. +
  63664. + /**
  63665. + * Specifies whether to use slave or DMA mode for accessing the data
  63666. + * FIFOs. The driver will automatically detect the value for this
  63667. + * parameter if none is specified.
  63668. + * 0 - Slave
  63669. + * 1 - DMA (default, if available)
  63670. + */
  63671. + int32_t dma_enable;
  63672. +
  63673. + /**
  63674. + * When DMA mode is enabled specifies whether to use address DMA or DMA
  63675. + * Descriptor mode for accessing the data FIFOs in device mode. The driver
  63676. + * will automatically detect the value for this if none is specified.
  63677. + * 0 - address DMA
  63678. + * 1 - DMA Descriptor(default, if available)
  63679. + */
  63680. + int32_t dma_desc_enable;
  63681. + /** The DMA Burst size (applicable only for External DMA
  63682. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  63683. + */
  63684. + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  63685. +
  63686. + /**
  63687. + * Specifies the maximum speed of operation in host and device mode.
  63688. + * The actual speed depends on the speed of the attached device and
  63689. + * the value of phy_type. The actual speed depends on the speed of the
  63690. + * attached device.
  63691. + * 0 - High Speed (default)
  63692. + * 1 - Full Speed
  63693. + */
  63694. + int32_t speed;
  63695. + /** Specifies whether low power mode is supported when attached
  63696. + * to a Full Speed or Low Speed device in host mode.
  63697. + * 0 - Don't support low power mode (default)
  63698. + * 1 - Support low power mode
  63699. + */
  63700. + int32_t host_support_fs_ls_low_power;
  63701. +
  63702. + /** Specifies the PHY clock rate in low power mode when connected to a
  63703. + * Low Speed device in host mode. This parameter is applicable only if
  63704. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  63705. + * then defaults to 6 MHZ otherwise 48 MHZ.
  63706. + *
  63707. + * 0 - 48 MHz
  63708. + * 1 - 6 MHz
  63709. + */
  63710. + int32_t host_ls_low_power_phy_clk;
  63711. +
  63712. + /**
  63713. + * 0 - Use cC FIFO size parameters
  63714. + * 1 - Allow dynamic FIFO sizing (default)
  63715. + */
  63716. + int32_t enable_dynamic_fifo;
  63717. +
  63718. + /** Total number of 4-byte words in the data FIFO memory. This
  63719. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  63720. + * Tx FIFOs.
  63721. + * 32 to 32768 (default 8192)
  63722. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  63723. + */
  63724. + int32_t data_fifo_size;
  63725. +
  63726. + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  63727. + * FIFO sizing is enabled.
  63728. + * 16 to 32768 (default 1064)
  63729. + */
  63730. + int32_t dev_rx_fifo_size;
  63731. +
  63732. + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  63733. + * when dynamic FIFO sizing is enabled.
  63734. + * 16 to 32768 (default 1024)
  63735. + */
  63736. + int32_t dev_nperio_tx_fifo_size;
  63737. +
  63738. + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  63739. + * mode when dynamic FIFO sizing is enabled.
  63740. + * 4 to 768 (default 256)
  63741. + */
  63742. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  63743. +
  63744. + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  63745. + * FIFO sizing is enabled.
  63746. + * 16 to 32768 (default 1024)
  63747. + */
  63748. + int32_t host_rx_fifo_size;
  63749. +
  63750. + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  63751. + * when Dynamic FIFO sizing is enabled in the core.
  63752. + * 16 to 32768 (default 1024)
  63753. + */
  63754. + int32_t host_nperio_tx_fifo_size;
  63755. +
  63756. + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  63757. + * FIFO sizing is enabled.
  63758. + * 16 to 32768 (default 1024)
  63759. + */
  63760. + int32_t host_perio_tx_fifo_size;
  63761. +
  63762. + /** The maximum transfer size supported in bytes.
  63763. + * 2047 to 65,535 (default 65,535)
  63764. + */
  63765. + int32_t max_transfer_size;
  63766. +
  63767. + /** The maximum number of packets in a transfer.
  63768. + * 15 to 511 (default 511)
  63769. + */
  63770. + int32_t max_packet_count;
  63771. +
  63772. + /** The number of host channel registers to use.
  63773. + * 1 to 16 (default 12)
  63774. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  63775. + */
  63776. + int32_t host_channels;
  63777. +
  63778. + /** The number of endpoints in addition to EP0 available for device
  63779. + * mode operations.
  63780. + * 1 to 15 (default 6 IN and OUT)
  63781. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  63782. + * endpoints in addition to EP0.
  63783. + */
  63784. + int32_t dev_endpoints;
  63785. +
  63786. + /**
  63787. + * Specifies the type of PHY interface to use. By default, the driver
  63788. + * will automatically detect the phy_type.
  63789. + *
  63790. + * 0 - Full Speed PHY
  63791. + * 1 - UTMI+ (default)
  63792. + * 2 - ULPI
  63793. + */
  63794. + int32_t phy_type;
  63795. +
  63796. + /**
  63797. + * Specifies the UTMI+ Data Width. This parameter is
  63798. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  63799. + * PHY_TYPE, this parameter indicates the data width between
  63800. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  63801. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  63802. + * to "8 and 16 bits", meaning that the core has been
  63803. + * configured to work at either data path width.
  63804. + *
  63805. + * 8 or 16 bits (default 16)
  63806. + */
  63807. + int32_t phy_utmi_width;
  63808. +
  63809. + /**
  63810. + * Specifies whether the ULPI operates at double or single
  63811. + * data rate. This parameter is only applicable if PHY_TYPE is
  63812. + * ULPI.
  63813. + *
  63814. + * 0 - single data rate ULPI interface with 8 bit wide data
  63815. + * bus (default)
  63816. + * 1 - double data rate ULPI interface with 4 bit wide data
  63817. + * bus
  63818. + */
  63819. + int32_t phy_ulpi_ddr;
  63820. +
  63821. + /**
  63822. + * Specifies whether to use the internal or external supply to
  63823. + * drive the vbus with a ULPI phy.
  63824. + */
  63825. + int32_t phy_ulpi_ext_vbus;
  63826. +
  63827. + /**
  63828. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  63829. + * parameter is only applicable if PHY_TYPE is FS.
  63830. + * 0 - No (default)
  63831. + * 1 - Yes
  63832. + */
  63833. + int32_t i2c_enable;
  63834. +
  63835. + int32_t ulpi_fs_ls;
  63836. +
  63837. + int32_t ts_dline;
  63838. +
  63839. + /**
  63840. + * Specifies whether dedicated transmit FIFOs are
  63841. + * enabled for non periodic IN endpoints in device mode
  63842. + * 0 - No
  63843. + * 1 - Yes
  63844. + */
  63845. + int32_t en_multiple_tx_fifo;
  63846. +
  63847. + /** Number of 4-byte words in each of the Tx FIFOs in device
  63848. + * mode when dynamic FIFO sizing is enabled.
  63849. + * 4 to 768 (default 256)
  63850. + */
  63851. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  63852. +
  63853. + /** Thresholding enable flag-
  63854. + * bit 0 - enable non-ISO Tx thresholding
  63855. + * bit 1 - enable ISO Tx thresholding
  63856. + * bit 2 - enable Rx thresholding
  63857. + */
  63858. + uint32_t thr_ctl;
  63859. +
  63860. + /** Thresholding length for Tx
  63861. + * FIFOs in 32 bit DWORDs
  63862. + */
  63863. + uint32_t tx_thr_length;
  63864. +
  63865. + /** Thresholding length for Rx
  63866. + * FIFOs in 32 bit DWORDs
  63867. + */
  63868. + uint32_t rx_thr_length;
  63869. +
  63870. + /**
  63871. + * Specifies whether LPM (Link Power Management) support is enabled
  63872. + */
  63873. + int32_t lpm_enable;
  63874. +
  63875. + /** Per Transfer Interrupt
  63876. + * mode enable flag
  63877. + * 1 - Enabled
  63878. + * 0 - Disabled
  63879. + */
  63880. + int32_t pti_enable;
  63881. +
  63882. + /** Multi Processor Interrupt
  63883. + * mode enable flag
  63884. + * 1 - Enabled
  63885. + * 0 - Disabled
  63886. + */
  63887. + int32_t mpi_enable;
  63888. +
  63889. + /** IS_USB Capability
  63890. + * 1 - Enabled
  63891. + * 0 - Disabled
  63892. + */
  63893. + int32_t ic_usb_cap;
  63894. +
  63895. + /** AHB Threshold Ratio
  63896. + * 2'b00 AHB Threshold = MAC Threshold
  63897. + * 2'b01 AHB Threshold = 1/2 MAC Threshold
  63898. + * 2'b10 AHB Threshold = 1/4 MAC Threshold
  63899. + * 2'b11 AHB Threshold = 1/8 MAC Threshold
  63900. + */
  63901. + int32_t ahb_thr_ratio;
  63902. +
  63903. + /** ADP Support
  63904. + * 1 - Enabled
  63905. + * 0 - Disabled
  63906. + */
  63907. + int32_t adp_supp_enable;
  63908. +
  63909. + /** HFIR Reload Control
  63910. + * 0 - The HFIR cannot be reloaded dynamically.
  63911. + * 1 - Allow dynamic reloading of the HFIR register during runtime.
  63912. + */
  63913. + int32_t reload_ctl;
  63914. +
  63915. + /** DCFG: Enable device Out NAK
  63916. + * 0 - The core does not set NAK after Bulk Out transfer complete.
  63917. + * 1 - The core sets NAK after Bulk OUT transfer complete.
  63918. + */
  63919. + int32_t dev_out_nak;
  63920. +
  63921. + /** DCFG: Enable Continue on BNA
  63922. + * After receiving BNA interrupt the core disables the endpoint,when the
  63923. + * endpoint is re-enabled by the application the core starts processing
  63924. + * 0 - from the DOEPDMA descriptor
  63925. + * 1 - from the descriptor which received the BNA.
  63926. + */
  63927. + int32_t cont_on_bna;
  63928. +
  63929. + /** GAHBCFG: AHB Single Support
  63930. + * This bit when programmed supports SINGLE transfers for remainder
  63931. + * data in a transfer for DMA mode of operation.
  63932. + * 0 - in this case the remainder data will be sent using INCR burst size.
  63933. + * 1 - in this case the remainder data will be sent using SINGLE burst size.
  63934. + */
  63935. + int32_t ahb_single;
  63936. +
  63937. + /** Core Power down mode
  63938. + * 0 - No Power Down is enabled
  63939. + * 1 - Reserved
  63940. + * 2 - Complete Power Down (Hibernation)
  63941. + */
  63942. + int32_t power_down;
  63943. +
  63944. + /** OTG revision supported
  63945. + * 0 - OTG 1.3 revision
  63946. + * 1 - OTG 2.0 revision
  63947. + */
  63948. + int32_t otg_ver;
  63949. +
  63950. +} dwc_otg_core_params_t;
  63951. +
  63952. +#ifdef DEBUG
  63953. +struct dwc_otg_core_if;
  63954. +typedef struct hc_xfer_info {
  63955. + struct dwc_otg_core_if *core_if;
  63956. + dwc_hc_t *hc;
  63957. +} hc_xfer_info_t;
  63958. +#endif
  63959. +
  63960. +typedef struct ep_xfer_info {
  63961. + struct dwc_otg_core_if *core_if;
  63962. + dwc_ep_t *ep;
  63963. + uint8_t state;
  63964. +} ep_xfer_info_t;
  63965. +/*
  63966. + * Device States
  63967. + */
  63968. +typedef enum dwc_otg_lx_state {
  63969. + /** On state */
  63970. + DWC_OTG_L0,
  63971. + /** LPM sleep state*/
  63972. + DWC_OTG_L1,
  63973. + /** USB suspend state*/
  63974. + DWC_OTG_L2,
  63975. + /** Off state*/
  63976. + DWC_OTG_L3
  63977. +} dwc_otg_lx_state_e;
  63978. +
  63979. +struct dwc_otg_global_regs_backup {
  63980. + uint32_t gotgctl_local;
  63981. + uint32_t gintmsk_local;
  63982. + uint32_t gahbcfg_local;
  63983. + uint32_t gusbcfg_local;
  63984. + uint32_t grxfsiz_local;
  63985. + uint32_t gnptxfsiz_local;
  63986. +#ifdef CONFIG_USB_DWC_OTG_LPM
  63987. + uint32_t glpmcfg_local;
  63988. +#endif
  63989. + uint32_t gi2cctl_local;
  63990. + uint32_t hptxfsiz_local;
  63991. + uint32_t pcgcctl_local;
  63992. + uint32_t gdfifocfg_local;
  63993. + uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  63994. + uint32_t gpwrdn_local;
  63995. + uint32_t xhib_pcgcctl;
  63996. + uint32_t xhib_gpwrdn;
  63997. +};
  63998. +
  63999. +struct dwc_otg_host_regs_backup {
  64000. + uint32_t hcfg_local;
  64001. + uint32_t haintmsk_local;
  64002. + uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  64003. + uint32_t hprt0_local;
  64004. + uint32_t hfir_local;
  64005. +};
  64006. +
  64007. +struct dwc_otg_dev_regs_backup {
  64008. + uint32_t dcfg;
  64009. + uint32_t dctl;
  64010. + uint32_t daintmsk;
  64011. + uint32_t diepmsk;
  64012. + uint32_t doepmsk;
  64013. + uint32_t diepctl[MAX_EPS_CHANNELS];
  64014. + uint32_t dieptsiz[MAX_EPS_CHANNELS];
  64015. + uint32_t diepdma[MAX_EPS_CHANNELS];
  64016. +};
  64017. +/**
  64018. + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  64019. + * the DWC_otg controller acting in either host or device mode. It
  64020. + * represents the programming view of the controller as a whole.
  64021. + */
  64022. +struct dwc_otg_core_if {
  64023. + /** Parameters that define how the core should be configured.*/
  64024. + dwc_otg_core_params_t *core_params;
  64025. +
  64026. + /** Core Global registers starting at offset 000h. */
  64027. + dwc_otg_core_global_regs_t *core_global_regs;
  64028. +
  64029. + /** Device-specific information */
  64030. + dwc_otg_dev_if_t *dev_if;
  64031. + /** Host-specific information */
  64032. + dwc_otg_host_if_t *host_if;
  64033. +
  64034. + /** Value from SNPSID register */
  64035. + uint32_t snpsid;
  64036. +
  64037. + /*
  64038. + * Set to 1 if the core PHY interface bits in USBCFG have been
  64039. + * initialized.
  64040. + */
  64041. + uint8_t phy_init_done;
  64042. +
  64043. + /*
  64044. + * SRP Success flag, set by srp success interrupt in FS I2C mode
  64045. + */
  64046. + uint8_t srp_success;
  64047. + uint8_t srp_timer_started;
  64048. + /** Timer for SRP. If it expires before SRP is successful
  64049. + * clear the SRP. */
  64050. + dwc_timer_t *srp_timer;
  64051. +
  64052. +#ifdef DWC_DEV_SRPCAP
  64053. + /* This timer is needed to power on the hibernated host core if SRP is not
  64054. + * initiated on connected SRP capable device for limited period of time
  64055. + */
  64056. + uint8_t pwron_timer_started;
  64057. + dwc_timer_t *pwron_timer;
  64058. +#endif
  64059. + /* Common configuration information */
  64060. + /** Power and Clock Gating Control Register */
  64061. + volatile uint32_t *pcgcctl;
  64062. +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
  64063. +
  64064. + /** Push/pop addresses for endpoints or host channels.*/
  64065. + uint32_t *data_fifo[MAX_EPS_CHANNELS];
  64066. +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  64067. +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
  64068. +
  64069. + /** Total RAM for FIFOs (Bytes) */
  64070. + uint16_t total_fifo_size;
  64071. + /** Size of Rx FIFO (Bytes) */
  64072. + uint16_t rx_fifo_size;
  64073. + /** Size of Non-periodic Tx FIFO (Bytes) */
  64074. + uint16_t nperio_tx_fifo_size;
  64075. +
  64076. + /** 1 if DMA is enabled, 0 otherwise. */
  64077. + uint8_t dma_enable;
  64078. +
  64079. + /** 1 if DMA descriptor is enabled, 0 otherwise. */
  64080. + uint8_t dma_desc_enable;
  64081. +
  64082. + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  64083. + uint8_t pti_enh_enable;
  64084. +
  64085. + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  64086. + uint8_t multiproc_int_enable;
  64087. +
  64088. + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  64089. + uint8_t en_multiple_tx_fifo;
  64090. +
  64091. + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  64092. + * process of being queued */
  64093. + uint8_t queuing_high_bandwidth;
  64094. +
  64095. + /** Hardware Configuration -- stored here for convenience.*/
  64096. + hwcfg1_data_t hwcfg1;
  64097. + hwcfg2_data_t hwcfg2;
  64098. + hwcfg3_data_t hwcfg3;
  64099. + hwcfg4_data_t hwcfg4;
  64100. + fifosize_data_t hptxfsiz;
  64101. +
  64102. + /** Host and Device Configuration -- stored here for convenience.*/
  64103. + hcfg_data_t hcfg;
  64104. + dcfg_data_t dcfg;
  64105. +
  64106. + /** The operational State, during transations
  64107. + * (a_host>>a_peripherial and b_device=>b_host) this may not
  64108. + * match the core but allows the software to determine
  64109. + * transitions.
  64110. + */
  64111. + uint8_t op_state;
  64112. +
  64113. + /**
  64114. + * Set to 1 if the HCD needs to be restarted on a session request
  64115. + * interrupt. This is required if no connector ID status change has
  64116. + * occurred since the HCD was last disconnected.
  64117. + */
  64118. + uint8_t restart_hcd_on_session_req;
  64119. +
  64120. + /** HCD callbacks */
  64121. + /** A-Device is a_host */
  64122. +#define A_HOST (1)
  64123. + /** A-Device is a_suspend */
  64124. +#define A_SUSPEND (2)
  64125. + /** A-Device is a_peripherial */
  64126. +#define A_PERIPHERAL (3)
  64127. + /** B-Device is operating as a Peripheral. */
  64128. +#define B_PERIPHERAL (4)
  64129. + /** B-Device is operating as a Host. */
  64130. +#define B_HOST (5)
  64131. +
  64132. + /** HCD callbacks */
  64133. + struct dwc_otg_cil_callbacks *hcd_cb;
  64134. + /** PCD callbacks */
  64135. + struct dwc_otg_cil_callbacks *pcd_cb;
  64136. +
  64137. + /** Device mode Periodic Tx FIFO Mask */
  64138. + uint32_t p_tx_msk;
  64139. + /** Device mode Periodic Tx FIFO Mask */
  64140. + uint32_t tx_msk;
  64141. +
  64142. + /** Workqueue object used for handling several interrupts */
  64143. + dwc_workq_t *wq_otg;
  64144. +
  64145. + /** Timer object used for handling "Wakeup Detected" Interrupt */
  64146. + dwc_timer_t *wkp_timer;
  64147. + /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  64148. + uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  64149. + ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  64150. + dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  64151. +#ifdef DEBUG
  64152. + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  64153. +
  64154. + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  64155. + dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  64156. +
  64157. + uint32_t hfnum_7_samples;
  64158. + uint64_t hfnum_7_frrem_accum;
  64159. + uint32_t hfnum_0_samples;
  64160. + uint64_t hfnum_0_frrem_accum;
  64161. + uint32_t hfnum_other_samples;
  64162. + uint64_t hfnum_other_frrem_accum;
  64163. +#endif
  64164. +
  64165. +#ifdef DWC_UTE_CFI
  64166. + uint16_t pwron_rxfsiz;
  64167. + uint16_t pwron_gnptxfsiz;
  64168. + uint16_t pwron_txfsiz[15];
  64169. +
  64170. + uint16_t init_rxfsiz;
  64171. + uint16_t init_gnptxfsiz;
  64172. + uint16_t init_txfsiz[15];
  64173. +#endif
  64174. +
  64175. + /** Lx state of device */
  64176. + dwc_otg_lx_state_e lx_state;
  64177. +
  64178. + /** Saved Core Global registers */
  64179. + struct dwc_otg_global_regs_backup *gr_backup;
  64180. + /** Saved Host registers */
  64181. + struct dwc_otg_host_regs_backup *hr_backup;
  64182. + /** Saved Device registers */
  64183. + struct dwc_otg_dev_regs_backup *dr_backup;
  64184. +
  64185. + /** Power Down Enable */
  64186. + uint32_t power_down;
  64187. +
  64188. + /** ADP support Enable */
  64189. + uint32_t adp_enable;
  64190. +
  64191. + /** ADP structure object */
  64192. + dwc_otg_adp_t adp;
  64193. +
  64194. + /** hibernation/suspend flag */
  64195. + int hibernation_suspend;
  64196. +
  64197. + /** Device mode extended hibernation flag */
  64198. + int xhib;
  64199. +
  64200. + /** OTG revision supported */
  64201. + uint32_t otg_ver;
  64202. +
  64203. + /** OTG status flag used for HNP polling */
  64204. + uint8_t otg_sts;
  64205. +
  64206. + /** Pointer to either hcd->lock or pcd->lock */
  64207. + dwc_spinlock_t *lock;
  64208. +
  64209. + /** Start predict NextEP based on Learning Queue if equal 1,
  64210. + * also used as counter of disabled NP IN EP's */
  64211. + uint8_t start_predict;
  64212. +
  64213. + /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  64214. + * active, 0xff otherwise */
  64215. + uint8_t nextep_seq[MAX_EPS_CHANNELS];
  64216. +
  64217. + /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  64218. + uint8_t first_in_nextep_seq;
  64219. +
  64220. + /** Frame number while entering to ISR - needed for ISOCs **/
  64221. + uint32_t frame_num;
  64222. +
  64223. +};
  64224. +
  64225. +#ifdef DEBUG
  64226. +/*
  64227. + * This function is called when transfer is timed out.
  64228. + */
  64229. +extern void hc_xfer_timeout(void *ptr);
  64230. +#endif
  64231. +
  64232. +/*
  64233. + * This function is called when transfer is timed out on endpoint.
  64234. + */
  64235. +extern void ep_xfer_timeout(void *ptr);
  64236. +
  64237. +/*
  64238. + * The following functions are functions for works
  64239. + * using during handling some interrupts
  64240. + */
  64241. +extern void w_conn_id_status_change(void *p);
  64242. +
  64243. +extern void w_wakeup_detected(void *p);
  64244. +
  64245. +/** Saves global register values into system memory. */
  64246. +extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  64247. +/** Saves device register values into system memory. */
  64248. +extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  64249. +/** Saves host register values into system memory. */
  64250. +extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  64251. +/** Restore global register values. */
  64252. +extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  64253. +/** Restore host register values. */
  64254. +extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  64255. +/** Restore device register values. */
  64256. +extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  64257. + int rem_wakeup);
  64258. +extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  64259. +extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  64260. + int is_host);
  64261. +
  64262. +extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  64263. + int restore_mode, int reset);
  64264. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  64265. + int rem_wakeup, int reset);
  64266. +
  64267. +/*
  64268. + * The following functions support initialization of the CIL driver component
  64269. + * and the DWC_otg controller.
  64270. + */
  64271. +extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  64272. +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  64273. +
  64274. +/** @name Device CIL Functions
  64275. + * The following functions support managing the DWC_otg controller in device
  64276. + * mode.
  64277. + */
  64278. +/**@{*/
  64279. +extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  64280. +extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  64281. + uint32_t * _dest);
  64282. +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  64283. +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64284. +extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64285. +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64286. +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  64287. + dwc_ep_t * _ep);
  64288. +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  64289. + dwc_ep_t * _ep);
  64290. +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  64291. + dwc_ep_t * _ep);
  64292. +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  64293. + dwc_ep_t * _ep);
  64294. +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  64295. + dwc_ep_t * _ep, int _dma);
  64296. +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64297. +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  64298. + dwc_ep_t * _ep);
  64299. +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  64300. +
  64301. +#ifdef DWC_EN_ISOC
  64302. +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  64303. + dwc_ep_t * ep);
  64304. +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  64305. + dwc_ep_t * ep);
  64306. +#endif /* DWC_EN_ISOC */
  64307. +/**@}*/
  64308. +
  64309. +/** @name Host CIL Functions
  64310. + * The following functions support managing the DWC_otg controller in host
  64311. + * mode.
  64312. + */
  64313. +/**@{*/
  64314. +extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  64315. +extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  64316. + dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  64317. +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  64318. +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  64319. + dwc_hc_t * _hc);
  64320. +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  64321. + dwc_hc_t * _hc);
  64322. +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  64323. +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  64324. + dwc_hc_t * _hc);
  64325. +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  64326. +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  64327. +
  64328. +extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  64329. + dwc_hc_t * hc);
  64330. +
  64331. +extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  64332. +
  64333. +/* Macro used to clear one channel interrupt */
  64334. +#define clear_hc_int(_hc_regs_, _intr_) \
  64335. +do { \
  64336. + hcint_data_t hcint_clear = {.d32 = 0}; \
  64337. + hcint_clear.b._intr_ = 1; \
  64338. + DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  64339. +} while (0)
  64340. +
  64341. +/*
  64342. + * Macro used to disable one channel interrupt. Channel interrupts are
  64343. + * disabled when the channel is halted or released by the interrupt handler.
  64344. + * There is no need to handle further interrupts of that type until the
  64345. + * channel is re-assigned. In fact, subsequent handling may cause crashes
  64346. + * because the channel structures are cleaned up when the channel is released.
  64347. + */
  64348. +#define disable_hc_int(_hc_regs_, _intr_) \
  64349. +do { \
  64350. + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  64351. + hcintmsk.b._intr_ = 1; \
  64352. + DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  64353. +} while (0)
  64354. +
  64355. +/**
  64356. + * This function Reads HPRT0 in preparation to modify. It keeps the
  64357. + * WC bits 0 so that if they are read as 1, they won't clear when you
  64358. + * write it back
  64359. + */
  64360. +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  64361. +{
  64362. + hprt0_data_t hprt0;
  64363. + hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  64364. + hprt0.b.prtena = 0;
  64365. + hprt0.b.prtconndet = 0;
  64366. + hprt0.b.prtenchng = 0;
  64367. + hprt0.b.prtovrcurrchng = 0;
  64368. + return hprt0.d32;
  64369. +}
  64370. +
  64371. +/**@}*/
  64372. +
  64373. +/** @name Common CIL Functions
  64374. + * The following functions support managing the DWC_otg controller in either
  64375. + * device or host mode.
  64376. + */
  64377. +/**@{*/
  64378. +
  64379. +extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  64380. + uint8_t * dest, uint16_t bytes);
  64381. +
  64382. +extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  64383. +extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  64384. +extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  64385. +
  64386. +/**
  64387. + * This function returns the Core Interrupt register.
  64388. + */
  64389. +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  64390. +{
  64391. + return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  64392. + DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  64393. +}
  64394. +
  64395. +/**
  64396. + * This function returns the OTG Interrupt register.
  64397. + */
  64398. +static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  64399. +{
  64400. + return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  64401. +}
  64402. +
  64403. +/**
  64404. + * This function reads the Device All Endpoints Interrupt register and
  64405. + * returns the IN endpoint interrupt bits.
  64406. + */
  64407. +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  64408. + core_if)
  64409. +{
  64410. +
  64411. + uint32_t v;
  64412. +
  64413. + if (core_if->multiproc_int_enable) {
  64414. + v = DWC_READ_REG32(&core_if->dev_if->
  64415. + dev_global_regs->deachint) &
  64416. + DWC_READ_REG32(&core_if->
  64417. + dev_if->dev_global_regs->deachintmsk);
  64418. + } else {
  64419. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  64420. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  64421. + }
  64422. + return (v & 0xffff);
  64423. +}
  64424. +
  64425. +/**
  64426. + * This function reads the Device All Endpoints Interrupt register and
  64427. + * returns the OUT endpoint interrupt bits.
  64428. + */
  64429. +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  64430. + core_if)
  64431. +{
  64432. + uint32_t v;
  64433. +
  64434. + if (core_if->multiproc_int_enable) {
  64435. + v = DWC_READ_REG32(&core_if->dev_if->
  64436. + dev_global_regs->deachint) &
  64437. + DWC_READ_REG32(&core_if->
  64438. + dev_if->dev_global_regs->deachintmsk);
  64439. + } else {
  64440. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  64441. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  64442. + }
  64443. +
  64444. + return ((v & 0xffff0000) >> 16);
  64445. +}
  64446. +
  64447. +/**
  64448. + * This function returns the Device IN EP Interrupt register
  64449. + */
  64450. +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  64451. + dwc_ep_t * ep)
  64452. +{
  64453. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  64454. + uint32_t v, msk, emp;
  64455. +
  64456. + if (core_if->multiproc_int_enable) {
  64457. + msk =
  64458. + DWC_READ_REG32(&dev_if->
  64459. + dev_global_regs->diepeachintmsk[ep->num]);
  64460. + emp =
  64461. + DWC_READ_REG32(&dev_if->
  64462. + dev_global_regs->dtknqr4_fifoemptymsk);
  64463. + msk |= ((emp >> ep->num) & 0x1) << 7;
  64464. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  64465. + } else {
  64466. + msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  64467. + emp =
  64468. + DWC_READ_REG32(&dev_if->
  64469. + dev_global_regs->dtknqr4_fifoemptymsk);
  64470. + msk |= ((emp >> ep->num) & 0x1) << 7;
  64471. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  64472. + }
  64473. +
  64474. + return v;
  64475. +}
  64476. +
  64477. +/**
  64478. + * This function returns the Device OUT EP Interrupt register
  64479. + */
  64480. +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  64481. + _core_if, dwc_ep_t * _ep)
  64482. +{
  64483. + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  64484. + uint32_t v;
  64485. + doepmsk_data_t msk = {.d32 = 0 };
  64486. +
  64487. + if (_core_if->multiproc_int_enable) {
  64488. + msk.d32 =
  64489. + DWC_READ_REG32(&dev_if->
  64490. + dev_global_regs->doepeachintmsk[_ep->num]);
  64491. + if (_core_if->pti_enh_enable) {
  64492. + msk.b.pktdrpsts = 1;
  64493. + }
  64494. + v = DWC_READ_REG32(&dev_if->
  64495. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  64496. + } else {
  64497. + msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  64498. + if (_core_if->pti_enh_enable) {
  64499. + msk.b.pktdrpsts = 1;
  64500. + }
  64501. + v = DWC_READ_REG32(&dev_if->
  64502. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  64503. + }
  64504. + return v;
  64505. +}
  64506. +
  64507. +/**
  64508. + * This function returns the Host All Channel Interrupt register
  64509. + */
  64510. +static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  64511. + _core_if)
  64512. +{
  64513. + return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  64514. +}
  64515. +
  64516. +static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  64517. + _core_if, dwc_hc_t * _hc)
  64518. +{
  64519. + return (DWC_READ_REG32
  64520. + (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  64521. +}
  64522. +
  64523. +/**
  64524. + * This function returns the mode of the operation, host or device.
  64525. + *
  64526. + * @return 0 - Device Mode, 1 - Host Mode
  64527. + */
  64528. +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  64529. +{
  64530. + return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  64531. +}
  64532. +
  64533. +/**@}*/
  64534. +
  64535. +/**
  64536. + * DWC_otg CIL callback structure. This structure allows the HCD and
  64537. + * PCD to register functions used for starting and stopping the PCD
  64538. + * and HCD for role change on for a DRD.
  64539. + */
  64540. +typedef struct dwc_otg_cil_callbacks {
  64541. + /** Start function for role change */
  64542. + int (*start) (void *_p);
  64543. + /** Stop Function for role change */
  64544. + int (*stop) (void *_p);
  64545. + /** Disconnect Function for role change */
  64546. + int (*disconnect) (void *_p);
  64547. + /** Resume/Remote wakeup Function */
  64548. + int (*resume_wakeup) (void *_p);
  64549. + /** Suspend function */
  64550. + int (*suspend) (void *_p);
  64551. + /** Session Start (SRP) */
  64552. + int (*session_start) (void *_p);
  64553. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64554. + /** Sleep (switch to L0 state) */
  64555. + int (*sleep) (void *_p);
  64556. +#endif
  64557. + /** Pointer passed to start() and stop() */
  64558. + void *p;
  64559. +} dwc_otg_cil_callbacks_t;
  64560. +
  64561. +extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  64562. + dwc_otg_cil_callbacks_t * _cb,
  64563. + void *_p);
  64564. +extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  64565. + dwc_otg_cil_callbacks_t * _cb,
  64566. + void *_p);
  64567. +
  64568. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  64569. +
  64570. +//////////////////////////////////////////////////////////////////////
  64571. +/** Start the HCD. Helper function for using the HCD callbacks.
  64572. + *
  64573. + * @param core_if Programming view of DWC_otg controller.
  64574. + */
  64575. +static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  64576. +{
  64577. + if (core_if->hcd_cb && core_if->hcd_cb->start) {
  64578. + core_if->hcd_cb->start(core_if->hcd_cb->p);
  64579. + }
  64580. +}
  64581. +
  64582. +/** Stop the HCD. Helper function for using the HCD callbacks.
  64583. + *
  64584. + * @param core_if Programming view of DWC_otg controller.
  64585. + */
  64586. +static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  64587. +{
  64588. + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  64589. + core_if->hcd_cb->stop(core_if->hcd_cb->p);
  64590. + }
  64591. +}
  64592. +
  64593. +/** Disconnect the HCD. Helper function for using the HCD callbacks.
  64594. + *
  64595. + * @param core_if Programming view of DWC_otg controller.
  64596. + */
  64597. +static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  64598. +{
  64599. + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  64600. + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
  64601. + }
  64602. +}
  64603. +
  64604. +/** Inform the HCD the a New Session has begun. Helper function for
  64605. + * using the HCD callbacks.
  64606. + *
  64607. + * @param core_if Programming view of DWC_otg controller.
  64608. + */
  64609. +static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  64610. +{
  64611. + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  64612. + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
  64613. + }
  64614. +}
  64615. +
  64616. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64617. +/**
  64618. + * Inform the HCD about LPM sleep.
  64619. + * Helper function for using the HCD callbacks.
  64620. + *
  64621. + * @param core_if Programming view of DWC_otg controller.
  64622. + */
  64623. +static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  64624. +{
  64625. + if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  64626. + core_if->hcd_cb->sleep(core_if->hcd_cb->p);
  64627. + }
  64628. +}
  64629. +#endif
  64630. +
  64631. +/** Resume the HCD. Helper function for using the HCD callbacks.
  64632. + *
  64633. + * @param core_if Programming view of DWC_otg controller.
  64634. + */
  64635. +static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  64636. +{
  64637. + if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  64638. + core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
  64639. + }
  64640. +}
  64641. +
  64642. +/** Start the PCD. Helper function for using the PCD callbacks.
  64643. + *
  64644. + * @param core_if Programming view of DWC_otg controller.
  64645. + */
  64646. +static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  64647. +{
  64648. + if (core_if->pcd_cb && core_if->pcd_cb->start) {
  64649. + core_if->pcd_cb->start(core_if->pcd_cb->p);
  64650. + }
  64651. +}
  64652. +
  64653. +/** Stop the PCD. Helper function for using the PCD callbacks.
  64654. + *
  64655. + * @param core_if Programming view of DWC_otg controller.
  64656. + */
  64657. +static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  64658. +{
  64659. + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  64660. + core_if->pcd_cb->stop(core_if->pcd_cb->p);
  64661. + }
  64662. +}
  64663. +
  64664. +/** Suspend the PCD. Helper function for using the PCD callbacks.
  64665. + *
  64666. + * @param core_if Programming view of DWC_otg controller.
  64667. + */
  64668. +static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  64669. +{
  64670. + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  64671. + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
  64672. + }
  64673. +}
  64674. +
  64675. +/** Resume the PCD. Helper function for using the PCD callbacks.
  64676. + *
  64677. + * @param core_if Programming view of DWC_otg controller.
  64678. + */
  64679. +static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  64680. +{
  64681. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  64682. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  64683. + }
  64684. +}
  64685. +
  64686. +//////////////////////////////////////////////////////////////////////
  64687. +
  64688. +#endif
  64689. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  64690. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 1970-01-01 01:00:00.000000000 +0100
  64691. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 2014-04-24 16:04:39.815124215 +0200
  64692. @@ -0,0 +1,1595 @@
  64693. +/* ==========================================================================
  64694. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
  64695. + * $Revision: #32 $
  64696. + * $Date: 2012/08/10 $
  64697. + * $Change: 2047372 $
  64698. + *
  64699. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  64700. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  64701. + * otherwise expressly agreed to in writing between Synopsys and you.
  64702. + *
  64703. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  64704. + * any End User Software License Agreement or Agreement for Licensed Product
  64705. + * with Synopsys or any supplement thereto. You are permitted to use and
  64706. + * redistribute this Software in source and binary forms, with or without
  64707. + * modification, provided that redistributions of source code must retain this
  64708. + * notice. You may not view, use, disclose, copy or distribute this file or
  64709. + * any information contained herein except pursuant to this license grant from
  64710. + * Synopsys. If you do not agree with this notice, including the disclaimer
  64711. + * below, then you are not authorized to use the Software.
  64712. + *
  64713. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  64714. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  64715. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  64716. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  64717. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  64718. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  64719. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  64720. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  64721. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  64722. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  64723. + * DAMAGE.
  64724. + * ========================================================================== */
  64725. +
  64726. +/** @file
  64727. + *
  64728. + * The Core Interface Layer provides basic services for accessing and
  64729. + * managing the DWC_otg hardware. These services are used by both the
  64730. + * Host Controller Driver and the Peripheral Controller Driver.
  64731. + *
  64732. + * This file contains the Common Interrupt handlers.
  64733. + */
  64734. +#include "dwc_os.h"
  64735. +#include "dwc_otg_regs.h"
  64736. +#include "dwc_otg_cil.h"
  64737. +#include "dwc_otg_driver.h"
  64738. +#include "dwc_otg_pcd.h"
  64739. +#include "dwc_otg_hcd.h"
  64740. +
  64741. +#ifdef DEBUG
  64742. +inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  64743. +{
  64744. + return (core_if->op_state == A_HOST ? "a_host" :
  64745. + (core_if->op_state == A_SUSPEND ? "a_suspend" :
  64746. + (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
  64747. + (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
  64748. + (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
  64749. +}
  64750. +#endif
  64751. +
  64752. +/** This function will log a debug message
  64753. + *
  64754. + * @param core_if Programming view of DWC_otg controller.
  64755. + */
  64756. +int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
  64757. +{
  64758. + gintsts_data_t gintsts;
  64759. + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
  64760. + dwc_otg_mode(core_if) ? "Host" : "Device");
  64761. +
  64762. + /* Clear interrupt */
  64763. + gintsts.d32 = 0;
  64764. + gintsts.b.modemismatch = 1;
  64765. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64766. + return 1;
  64767. +}
  64768. +
  64769. +/**
  64770. + * This function handles the OTG Interrupts. It reads the OTG
  64771. + * Interrupt Register (GOTGINT) to determine what interrupt has
  64772. + * occurred.
  64773. + *
  64774. + * @param core_if Programming view of DWC_otg controller.
  64775. + */
  64776. +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
  64777. +{
  64778. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  64779. + gotgint_data_t gotgint;
  64780. + gotgctl_data_t gotgctl;
  64781. + gintmsk_data_t gintmsk;
  64782. + gpwrdn_data_t gpwrdn;
  64783. +
  64784. + gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
  64785. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64786. + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
  64787. + op_state_str(core_if));
  64788. +
  64789. + if (gotgint.b.sesenddet) {
  64790. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64791. + "Session End Detected++ (%s)\n",
  64792. + op_state_str(core_if));
  64793. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64794. +
  64795. + if (core_if->op_state == B_HOST) {
  64796. + cil_pcd_start(core_if);
  64797. + core_if->op_state = B_PERIPHERAL;
  64798. + } else {
  64799. + /* If not B_HOST and Device HNP still set. HNP
  64800. + * Did not succeed!*/
  64801. + if (gotgctl.b.devhnpen) {
  64802. + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
  64803. + __DWC_ERROR("Device Not Connected/Responding!\n");
  64804. + }
  64805. +
  64806. + /* If Session End Detected the B-Cable has
  64807. + * been disconnected. */
  64808. + /* Reset PCD and Gadget driver to a
  64809. + * clean state. */
  64810. + core_if->lx_state = DWC_OTG_L0;
  64811. + DWC_SPINUNLOCK(core_if->lock);
  64812. + cil_pcd_stop(core_if);
  64813. + DWC_SPINLOCK(core_if->lock);
  64814. +
  64815. + if (core_if->adp_enable) {
  64816. + if (core_if->power_down == 2) {
  64817. + gpwrdn.d32 = 0;
  64818. + gpwrdn.b.pwrdnswtch = 1;
  64819. + DWC_MODIFY_REG32(&core_if->
  64820. + core_global_regs->
  64821. + gpwrdn, gpwrdn.d32, 0);
  64822. + }
  64823. +
  64824. + gpwrdn.d32 = 0;
  64825. + gpwrdn.b.pmuintsel = 1;
  64826. + gpwrdn.b.pmuactv = 1;
  64827. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64828. + gpwrdn, 0, gpwrdn.d32);
  64829. +
  64830. + dwc_otg_adp_sense_start(core_if);
  64831. + }
  64832. + }
  64833. +
  64834. + gotgctl.d32 = 0;
  64835. + gotgctl.b.devhnpen = 1;
  64836. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  64837. + }
  64838. + if (gotgint.b.sesreqsucstschng) {
  64839. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64840. + "Session Reqeust Success Status Change++\n");
  64841. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64842. + if (gotgctl.b.sesreqscs) {
  64843. +
  64844. + if ((core_if->core_params->phy_type ==
  64845. + DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
  64846. + core_if->srp_success = 1;
  64847. + } else {
  64848. + DWC_SPINUNLOCK(core_if->lock);
  64849. + cil_pcd_resume(core_if);
  64850. + DWC_SPINLOCK(core_if->lock);
  64851. + /* Clear Session Request */
  64852. + gotgctl.d32 = 0;
  64853. + gotgctl.b.sesreq = 1;
  64854. + DWC_MODIFY_REG32(&global_regs->gotgctl,
  64855. + gotgctl.d32, 0);
  64856. + }
  64857. + }
  64858. + }
  64859. + if (gotgint.b.hstnegsucstschng) {
  64860. + /* Print statements during the HNP interrupt handling
  64861. + * can cause it to fail.*/
  64862. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64863. + /* WA for 3.00a- HW is not setting cur_mode, even sometimes
  64864. + * this does not help*/
  64865. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  64866. + dwc_udelay(100);
  64867. + if (gotgctl.b.hstnegscs) {
  64868. + if (dwc_otg_is_host_mode(core_if)) {
  64869. + core_if->op_state = B_HOST;
  64870. + /*
  64871. + * Need to disable SOF interrupt immediately.
  64872. + * When switching from device to host, the PCD
  64873. + * interrupt handler won't handle the
  64874. + * interrupt if host mode is already set. The
  64875. + * HCD interrupt handler won't get called if
  64876. + * the HCD state is HALT. This means that the
  64877. + * interrupt does not get handled and Linux
  64878. + * complains loudly.
  64879. + */
  64880. + gintmsk.d32 = 0;
  64881. + gintmsk.b.sofintr = 1;
  64882. + DWC_MODIFY_REG32(&global_regs->gintmsk,
  64883. + gintmsk.d32, 0);
  64884. + /* Call callback function with spin lock released */
  64885. + DWC_SPINUNLOCK(core_if->lock);
  64886. + cil_pcd_stop(core_if);
  64887. + /*
  64888. + * Initialize the Core for Host mode.
  64889. + */
  64890. + cil_hcd_start(core_if);
  64891. + DWC_SPINLOCK(core_if->lock);
  64892. + core_if->op_state = B_HOST;
  64893. + }
  64894. + } else {
  64895. + gotgctl.d32 = 0;
  64896. + gotgctl.b.hnpreq = 1;
  64897. + gotgctl.b.devhnpen = 1;
  64898. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  64899. + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
  64900. + __DWC_ERROR("Device Not Connected/Responding\n");
  64901. + }
  64902. + }
  64903. + if (gotgint.b.hstnegdet) {
  64904. + /* The disconnect interrupt is set at the same time as
  64905. + * Host Negotiation Detected. During the mode
  64906. + * switch all interrupts are cleared so the disconnect
  64907. + * interrupt handler will not get executed.
  64908. + */
  64909. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64910. + "Host Negotiation Detected++ (%s)\n",
  64911. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  64912. + "Device"));
  64913. + if (dwc_otg_is_device_mode(core_if)) {
  64914. + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
  64915. + core_if->op_state);
  64916. + DWC_SPINUNLOCK(core_if->lock);
  64917. + cil_hcd_disconnect(core_if);
  64918. + cil_pcd_start(core_if);
  64919. + DWC_SPINLOCK(core_if->lock);
  64920. + core_if->op_state = A_PERIPHERAL;
  64921. + } else {
  64922. + /*
  64923. + * Need to disable SOF interrupt immediately. When
  64924. + * switching from device to host, the PCD interrupt
  64925. + * handler won't handle the interrupt if host mode is
  64926. + * already set. The HCD interrupt handler won't get
  64927. + * called if the HCD state is HALT. This means that
  64928. + * the interrupt does not get handled and Linux
  64929. + * complains loudly.
  64930. + */
  64931. + gintmsk.d32 = 0;
  64932. + gintmsk.b.sofintr = 1;
  64933. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
  64934. + DWC_SPINUNLOCK(core_if->lock);
  64935. + cil_pcd_stop(core_if);
  64936. + cil_hcd_start(core_if);
  64937. + DWC_SPINLOCK(core_if->lock);
  64938. + core_if->op_state = A_HOST;
  64939. + }
  64940. + }
  64941. + if (gotgint.b.adevtoutchng) {
  64942. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64943. + "A-Device Timeout Change++\n");
  64944. + }
  64945. + if (gotgint.b.debdone) {
  64946. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
  64947. + }
  64948. +
  64949. + /* Clear GOTGINT */
  64950. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
  64951. +
  64952. + return 1;
  64953. +}
  64954. +
  64955. +void w_conn_id_status_change(void *p)
  64956. +{
  64957. + dwc_otg_core_if_t *core_if = p;
  64958. + uint32_t count = 0;
  64959. + gotgctl_data_t gotgctl = {.d32 = 0 };
  64960. +
  64961. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  64962. + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
  64963. + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
  64964. +
  64965. + /* B-Device connector (Device Mode) */
  64966. + if (gotgctl.b.conidsts) {
  64967. + /* Wait for switch to device mode. */
  64968. + while (!dwc_otg_is_device_mode(core_if)) {
  64969. + DWC_PRINTF("Waiting for Peripheral Mode, Mode=%s\n",
  64970. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  64971. + "Peripheral"));
  64972. + dwc_mdelay(100);
  64973. + if (++count > 10000)
  64974. + break;
  64975. + }
  64976. + DWC_ASSERT(++count < 10000,
  64977. + "Connection id status change timed out");
  64978. + core_if->op_state = B_PERIPHERAL;
  64979. + dwc_otg_core_init(core_if);
  64980. + dwc_otg_enable_global_interrupts(core_if);
  64981. + cil_pcd_start(core_if);
  64982. + } else {
  64983. + /* A-Device connector (Host Mode) */
  64984. + while (!dwc_otg_is_host_mode(core_if)) {
  64985. + DWC_PRINTF("Waiting for Host Mode, Mode=%s\n",
  64986. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  64987. + "Peripheral"));
  64988. + dwc_mdelay(100);
  64989. + if (++count > 10000)
  64990. + break;
  64991. + }
  64992. + DWC_ASSERT(++count < 10000,
  64993. + "Connection id status change timed out");
  64994. + core_if->op_state = A_HOST;
  64995. + /*
  64996. + * Initialize the Core for Host mode.
  64997. + */
  64998. + dwc_otg_core_init(core_if);
  64999. + dwc_otg_enable_global_interrupts(core_if);
  65000. + cil_hcd_start(core_if);
  65001. + }
  65002. +}
  65003. +
  65004. +/**
  65005. + * This function handles the Connector ID Status Change Interrupt. It
  65006. + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
  65007. + * is a Device to Host Mode transition or a Host Mode to Device
  65008. + * Transition.
  65009. + *
  65010. + * This only occurs when the cable is connected/removed from the PHY
  65011. + * connector.
  65012. + *
  65013. + * @param core_if Programming view of DWC_otg controller.
  65014. + */
  65015. +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
  65016. +{
  65017. +
  65018. + /*
  65019. + * Need to disable SOF interrupt immediately. If switching from device
  65020. + * to host, the PCD interrupt handler won't handle the interrupt if
  65021. + * host mode is already set. The HCD interrupt handler won't get
  65022. + * called if the HCD state is HALT. This means that the interrupt does
  65023. + * not get handled and Linux complains loudly.
  65024. + */
  65025. + gintmsk_data_t gintmsk = {.d32 = 0 };
  65026. + gintsts_data_t gintsts = {.d32 = 0 };
  65027. +
  65028. + gintmsk.b.sofintr = 1;
  65029. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  65030. +
  65031. + DWC_DEBUGPL(DBG_CIL,
  65032. + " ++Connector ID Status Change Interrupt++ (%s)\n",
  65033. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
  65034. +
  65035. + DWC_SPINUNLOCK(core_if->lock);
  65036. +
  65037. + /*
  65038. + * Need to schedule a work, as there are possible DELAY function calls
  65039. + * Release lock before scheduling workq as it holds spinlock during scheduling
  65040. + */
  65041. +
  65042. + DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
  65043. + core_if, "connection id status change");
  65044. + DWC_SPINLOCK(core_if->lock);
  65045. +
  65046. + /* Set flag and clear interrupt */
  65047. + gintsts.b.conidstschng = 1;
  65048. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65049. +
  65050. + return 1;
  65051. +}
  65052. +
  65053. +/**
  65054. + * This interrupt indicates that a device is initiating the Session
  65055. + * Request Protocol to request the host to turn on bus power so a new
  65056. + * session can begin. The handler responds by turning on bus power. If
  65057. + * the DWC_otg controller is in low power mode, the handler brings the
  65058. + * controller out of low power mode before turning on bus power.
  65059. + *
  65060. + * @param core_if Programming view of DWC_otg controller.
  65061. + */
  65062. +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
  65063. +{
  65064. + gintsts_data_t gintsts;
  65065. +
  65066. +#ifndef DWC_HOST_ONLY
  65067. + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
  65068. +
  65069. + if (dwc_otg_is_device_mode(core_if)) {
  65070. + DWC_PRINTF("SRP: Device mode\n");
  65071. + } else {
  65072. + hprt0_data_t hprt0;
  65073. + DWC_PRINTF("SRP: Host mode\n");
  65074. +
  65075. + /* Turn on the port power bit. */
  65076. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  65077. + hprt0.b.prtpwr = 1;
  65078. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  65079. +
  65080. + /* Start the Connection timer. So a message can be displayed
  65081. + * if connect does not occur within 10 seconds. */
  65082. + cil_hcd_session_start(core_if);
  65083. + }
  65084. +#endif
  65085. +
  65086. + /* Clear interrupt */
  65087. + gintsts.d32 = 0;
  65088. + gintsts.b.sessreqintr = 1;
  65089. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65090. +
  65091. + return 1;
  65092. +}
  65093. +
  65094. +void w_wakeup_detected(void *p)
  65095. +{
  65096. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) p;
  65097. + /*
  65098. + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
  65099. + * so that OPT tests pass with all PHYs).
  65100. + */
  65101. + hprt0_data_t hprt0 = {.d32 = 0 };
  65102. +#if 0
  65103. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65104. + /* Restart the Phy Clock */
  65105. + pcgcctl.b.stoppclk = 1;
  65106. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65107. + dwc_udelay(10);
  65108. +#endif //0
  65109. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  65110. + DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
  65111. +// dwc_mdelay(70);
  65112. + hprt0.b.prtres = 0; /* Resume */
  65113. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  65114. + DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
  65115. + DWC_READ_REG32(core_if->host_if->hprt0));
  65116. +
  65117. + cil_hcd_resume(core_if);
  65118. +
  65119. + /** Change to L0 state*/
  65120. + core_if->lx_state = DWC_OTG_L0;
  65121. +}
  65122. +
  65123. +/**
  65124. + * This interrupt indicates that the DWC_otg controller has detected a
  65125. + * resume or remote wakeup sequence. If the DWC_otg controller is in
  65126. + * low power mode, the handler must brings the controller out of low
  65127. + * power mode. The controller automatically begins resume
  65128. + * signaling. The handler schedules a time to stop resume signaling.
  65129. + */
  65130. +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  65131. +{
  65132. + gintsts_data_t gintsts;
  65133. +
  65134. + DWC_DEBUGPL(DBG_ANY,
  65135. + "++Resume and Remote Wakeup Detected Interrupt++\n");
  65136. +
  65137. + DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
  65138. +
  65139. + if (dwc_otg_is_device_mode(core_if)) {
  65140. + dctl_data_t dctl = {.d32 = 0 };
  65141. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
  65142. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  65143. + dsts));
  65144. + if (core_if->lx_state == DWC_OTG_L2) {
  65145. +#ifdef PARTIAL_POWER_DOWN
  65146. + if (core_if->hwcfg4.b.power_optimiz) {
  65147. + pcgcctl_data_t power = {.d32 = 0 };
  65148. +
  65149. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  65150. + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
  65151. + power.d32);
  65152. +
  65153. + power.b.stoppclk = 0;
  65154. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65155. +
  65156. + power.b.pwrclmp = 0;
  65157. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65158. +
  65159. + power.b.rstpdwnmodule = 0;
  65160. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65161. + }
  65162. +#endif
  65163. + /* Clear the Remote Wakeup Signaling */
  65164. + dctl.b.rmtwkupsig = 1;
  65165. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  65166. + dctl, dctl.d32, 0);
  65167. +
  65168. + DWC_SPINUNLOCK(core_if->lock);
  65169. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  65170. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  65171. + }
  65172. + DWC_SPINLOCK(core_if->lock);
  65173. + } else {
  65174. + glpmcfg_data_t lpmcfg;
  65175. + lpmcfg.d32 =
  65176. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65177. + lpmcfg.b.hird_thres &= (~(1 << 4));
  65178. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  65179. + lpmcfg.d32);
  65180. + }
  65181. + /** Change to L0 state*/
  65182. + core_if->lx_state = DWC_OTG_L0;
  65183. + } else {
  65184. + if (core_if->lx_state != DWC_OTG_L1) {
  65185. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65186. +
  65187. + /* Restart the Phy Clock */
  65188. + pcgcctl.b.stoppclk = 1;
  65189. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65190. + DWC_TIMER_SCHEDULE(core_if->wkp_timer, 71);
  65191. + } else {
  65192. + /** Change to L0 state*/
  65193. + core_if->lx_state = DWC_OTG_L0;
  65194. + }
  65195. + }
  65196. +
  65197. + /* Clear interrupt */
  65198. + gintsts.d32 = 0;
  65199. + gintsts.b.wkupintr = 1;
  65200. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65201. +
  65202. + return 1;
  65203. +}
  65204. +
  65205. +/**
  65206. + * This interrupt indicates that the Wakeup Logic has detected a
  65207. + * Device disconnect.
  65208. + */
  65209. +static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t *core_if)
  65210. +{
  65211. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  65212. + gpwrdn_data_t gpwrdn_temp = { .d32 = 0 };
  65213. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65214. +
  65215. + DWC_PRINTF("%s called\n", __FUNCTION__);
  65216. +
  65217. + if (!core_if->hibernation_suspend) {
  65218. + DWC_PRINTF("Already exited from Hibernation\n");
  65219. + return 1;
  65220. + }
  65221. +
  65222. + /* Switch on the voltage to the core */
  65223. + gpwrdn.b.pwrdnswtch = 1;
  65224. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65225. + dwc_udelay(10);
  65226. +
  65227. + /* Reset the core */
  65228. + gpwrdn.d32 = 0;
  65229. + gpwrdn.b.pwrdnrstn = 1;
  65230. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65231. + dwc_udelay(10);
  65232. +
  65233. + /* Disable power clamps*/
  65234. + gpwrdn.d32 = 0;
  65235. + gpwrdn.b.pwrdnclmp = 1;
  65236. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65237. +
  65238. + /* Remove reset the core signal */
  65239. + gpwrdn.d32 = 0;
  65240. + gpwrdn.b.pwrdnrstn = 1;
  65241. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65242. + dwc_udelay(10);
  65243. +
  65244. + /* Disable PMU interrupt */
  65245. + gpwrdn.d32 = 0;
  65246. + gpwrdn.b.pmuintsel = 1;
  65247. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65248. +
  65249. + core_if->hibernation_suspend = 0;
  65250. +
  65251. + /* Disable PMU */
  65252. + gpwrdn.d32 = 0;
  65253. + gpwrdn.b.pmuactv = 1;
  65254. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65255. + dwc_udelay(10);
  65256. +
  65257. + if (gpwrdn_temp.b.idsts) {
  65258. + core_if->op_state = B_PERIPHERAL;
  65259. + dwc_otg_core_init(core_if);
  65260. + dwc_otg_enable_global_interrupts(core_if);
  65261. + cil_pcd_start(core_if);
  65262. + } else {
  65263. + core_if->op_state = A_HOST;
  65264. + dwc_otg_core_init(core_if);
  65265. + dwc_otg_enable_global_interrupts(core_if);
  65266. + cil_hcd_start(core_if);
  65267. + }
  65268. +
  65269. + return 1;
  65270. +}
  65271. +
  65272. +/**
  65273. + * This interrupt indicates that the Wakeup Logic has detected a
  65274. + * remote wakeup sequence.
  65275. + */
  65276. +static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  65277. +{
  65278. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65279. + DWC_DEBUGPL(DBG_ANY,
  65280. + "++Powerdown Remote Wakeup Detected Interrupt++\n");
  65281. +
  65282. + if (!core_if->hibernation_suspend) {
  65283. + DWC_PRINTF("Already exited from Hibernation\n");
  65284. + return 1;
  65285. + }
  65286. +
  65287. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65288. + if (gpwrdn.b.idsts) { // Device Mode
  65289. + if ((core_if->power_down == 2)
  65290. + && (core_if->hibernation_suspend == 1)) {
  65291. + dwc_otg_device_hibernation_restore(core_if, 0, 0);
  65292. + }
  65293. + } else {
  65294. + if ((core_if->power_down == 2)
  65295. + && (core_if->hibernation_suspend == 1)) {
  65296. + dwc_otg_host_hibernation_restore(core_if, 1, 0);
  65297. + }
  65298. + }
  65299. + return 1;
  65300. +}
  65301. +
  65302. +static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t *otg_dev)
  65303. +{
  65304. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65305. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  65306. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  65307. +
  65308. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  65309. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65310. + if (core_if->power_down == 2) {
  65311. + if (!core_if->hibernation_suspend) {
  65312. + DWC_PRINTF("Already exited from Hibernation\n");
  65313. + return 1;
  65314. + }
  65315. + DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
  65316. + /* Switch on the voltage to the core */
  65317. + gpwrdn.b.pwrdnswtch = 1;
  65318. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65319. + dwc_udelay(10);
  65320. +
  65321. + /* Reset the core */
  65322. + gpwrdn.d32 = 0;
  65323. + gpwrdn.b.pwrdnrstn = 1;
  65324. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65325. + dwc_udelay(10);
  65326. +
  65327. + /* Disable power clamps */
  65328. + gpwrdn.d32 = 0;
  65329. + gpwrdn.b.pwrdnclmp = 1;
  65330. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65331. +
  65332. + /* Remove reset the core signal */
  65333. + gpwrdn.d32 = 0;
  65334. + gpwrdn.b.pwrdnrstn = 1;
  65335. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65336. + dwc_udelay(10);
  65337. +
  65338. + /* Disable PMU interrupt */
  65339. + gpwrdn.d32 = 0;
  65340. + gpwrdn.b.pmuintsel = 1;
  65341. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65342. +
  65343. + /*Indicates that we are exiting from hibernation */
  65344. + core_if->hibernation_suspend = 0;
  65345. +
  65346. + /* Disable PMU */
  65347. + gpwrdn.d32 = 0;
  65348. + gpwrdn.b.pmuactv = 1;
  65349. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65350. + dwc_udelay(10);
  65351. +
  65352. + gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
  65353. + if (gpwrdn.b.dis_vbus == 1) {
  65354. + gpwrdn.d32 = 0;
  65355. + gpwrdn.b.dis_vbus = 1;
  65356. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65357. + }
  65358. +
  65359. + if (gpwrdn_temp.b.idsts) {
  65360. + core_if->op_state = B_PERIPHERAL;
  65361. + dwc_otg_core_init(core_if);
  65362. + dwc_otg_enable_global_interrupts(core_if);
  65363. + cil_pcd_start(core_if);
  65364. + } else {
  65365. + core_if->op_state = A_HOST;
  65366. + dwc_otg_core_init(core_if);
  65367. + dwc_otg_enable_global_interrupts(core_if);
  65368. + cil_hcd_start(core_if);
  65369. + }
  65370. + }
  65371. +
  65372. + if (core_if->adp_enable) {
  65373. + uint8_t is_host = 0;
  65374. + DWC_SPINUNLOCK(core_if->lock);
  65375. + /* Change the core_if's lock to hcd/pcd lock depend on mode? */
  65376. +#ifndef DWC_HOST_ONLY
  65377. + if (gpwrdn_temp.b.idsts)
  65378. + core_if->lock = otg_dev->pcd->lock;
  65379. +#endif
  65380. +#ifndef DWC_DEVICE_ONLY
  65381. + if (!gpwrdn_temp.b.idsts) {
  65382. + core_if->lock = otg_dev->hcd->lock;
  65383. + is_host = 1;
  65384. + }
  65385. +#endif
  65386. + DWC_PRINTF("RESTART ADP\n");
  65387. + if (core_if->adp.probe_enabled)
  65388. + dwc_otg_adp_probe_stop(core_if);
  65389. + if (core_if->adp.sense_enabled)
  65390. + dwc_otg_adp_sense_stop(core_if);
  65391. + if (core_if->adp.sense_timer_started)
  65392. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  65393. + if (core_if->adp.vbuson_timer_started)
  65394. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  65395. + core_if->adp.probe_timer_values[0] = -1;
  65396. + core_if->adp.probe_timer_values[1] = -1;
  65397. + core_if->adp.sense_timer_started = 0;
  65398. + core_if->adp.vbuson_timer_started = 0;
  65399. + core_if->adp.probe_counter = 0;
  65400. + core_if->adp.gpwrdn = 0;
  65401. +
  65402. + /* Disable PMU and restart ADP */
  65403. + gpwrdn_temp.d32 = 0;
  65404. + gpwrdn_temp.b.pmuactv = 1;
  65405. + gpwrdn_temp.b.pmuintsel = 1;
  65406. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65407. + DWC_PRINTF("Check point 1\n");
  65408. + dwc_mdelay(110);
  65409. + dwc_otg_adp_start(core_if, is_host);
  65410. + DWC_SPINLOCK(core_if->lock);
  65411. + }
  65412. +
  65413. +
  65414. + return 1;
  65415. +}
  65416. +
  65417. +static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
  65418. +{
  65419. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65420. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  65421. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  65422. +
  65423. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65424. + if (core_if->power_down == 2) {
  65425. + if (!core_if->hibernation_suspend) {
  65426. + DWC_PRINTF("Already exited from Hibernation\n");
  65427. + return 1;
  65428. + }
  65429. +
  65430. + if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  65431. + otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
  65432. + gpwrdn.b.bsessvld == 0) {
  65433. + /* Save gpwrdn register for further usage if stschng interrupt */
  65434. + core_if->gr_backup->gpwrdn_local =
  65435. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65436. + /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
  65437. + return 1;
  65438. + }
  65439. +
  65440. + /* Switch on the voltage to the core */
  65441. + gpwrdn.d32 = 0;
  65442. + gpwrdn.b.pwrdnswtch = 1;
  65443. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65444. + dwc_udelay(10);
  65445. +
  65446. + /* Reset the core */
  65447. + gpwrdn.d32 = 0;
  65448. + gpwrdn.b.pwrdnrstn = 1;
  65449. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65450. + dwc_udelay(10);
  65451. +
  65452. + /* Disable power clamps */
  65453. + gpwrdn.d32 = 0;
  65454. + gpwrdn.b.pwrdnclmp = 1;
  65455. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65456. +
  65457. + /* Remove reset the core signal */
  65458. + gpwrdn.d32 = 0;
  65459. + gpwrdn.b.pwrdnrstn = 1;
  65460. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65461. + dwc_udelay(10);
  65462. +
  65463. + /* Disable PMU interrupt */
  65464. + gpwrdn.d32 = 0;
  65465. + gpwrdn.b.pmuintsel = 1;
  65466. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65467. + dwc_udelay(10);
  65468. +
  65469. + /*Indicates that we are exiting from hibernation */
  65470. + core_if->hibernation_suspend = 0;
  65471. +
  65472. + /* Disable PMU */
  65473. + gpwrdn.d32 = 0;
  65474. + gpwrdn.b.pmuactv = 1;
  65475. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65476. + dwc_udelay(10);
  65477. +
  65478. + core_if->op_state = B_PERIPHERAL;
  65479. + dwc_otg_core_init(core_if);
  65480. + dwc_otg_enable_global_interrupts(core_if);
  65481. + cil_pcd_start(core_if);
  65482. +
  65483. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  65484. + otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
  65485. + /*
  65486. + * Initiate SRP after initial ADP probe.
  65487. + */
  65488. + dwc_otg_initiate_srp(core_if);
  65489. + }
  65490. + }
  65491. +
  65492. + return 1;
  65493. +}
  65494. +/**
  65495. + * This interrupt indicates that the Wakeup Logic has detected a
  65496. + * status change either on IDDIG or BSessVld.
  65497. + */
  65498. +static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t *otg_dev)
  65499. +{
  65500. + int retval;
  65501. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65502. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  65503. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  65504. +
  65505. + DWC_PRINTF("%s called\n", __FUNCTION__);
  65506. +
  65507. + if (core_if->power_down == 2) {
  65508. + if (core_if->hibernation_suspend <= 0) {
  65509. + DWC_PRINTF("Already exited from Hibernation\n");
  65510. + return 1;
  65511. + } else
  65512. + gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
  65513. +
  65514. + } else {
  65515. + gpwrdn_temp.d32 = core_if->adp.gpwrdn;
  65516. + }
  65517. +
  65518. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65519. +
  65520. + if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
  65521. + retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
  65522. + } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
  65523. + retval = dwc_otg_handle_pwrdn_session_change(core_if);
  65524. + }
  65525. +
  65526. + return retval;
  65527. +}
  65528. +
  65529. +/**
  65530. + * This interrupt indicates that the Wakeup Logic has detected a
  65531. + * SRP.
  65532. + */
  65533. +static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
  65534. +{
  65535. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65536. +
  65537. + DWC_PRINTF("%s called\n", __FUNCTION__);
  65538. +
  65539. + if (!core_if->hibernation_suspend) {
  65540. + DWC_PRINTF("Already exited from Hibernation\n");
  65541. + return 1;
  65542. + }
  65543. +#ifdef DWC_DEV_SRPCAP
  65544. + if (core_if->pwron_timer_started) {
  65545. + core_if->pwron_timer_started = 0;
  65546. + DWC_TIMER_CANCEL(core_if->pwron_timer);
  65547. + }
  65548. +#endif
  65549. +
  65550. + /* Switch on the voltage to the core */
  65551. + gpwrdn.b.pwrdnswtch = 1;
  65552. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65553. + dwc_udelay(10);
  65554. +
  65555. + /* Reset the core */
  65556. + gpwrdn.d32 = 0;
  65557. + gpwrdn.b.pwrdnrstn = 1;
  65558. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65559. + dwc_udelay(10);
  65560. +
  65561. + /* Disable power clamps */
  65562. + gpwrdn.d32 = 0;
  65563. + gpwrdn.b.pwrdnclmp = 1;
  65564. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65565. +
  65566. + /* Remove reset the core signal */
  65567. + gpwrdn.d32 = 0;
  65568. + gpwrdn.b.pwrdnrstn = 1;
  65569. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65570. + dwc_udelay(10);
  65571. +
  65572. + /* Disable PMU interrupt */
  65573. + gpwrdn.d32 = 0;
  65574. + gpwrdn.b.pmuintsel = 1;
  65575. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65576. +
  65577. + /* Indicates that we are exiting from hibernation */
  65578. + core_if->hibernation_suspend = 0;
  65579. +
  65580. + /* Disable PMU */
  65581. + gpwrdn.d32 = 0;
  65582. + gpwrdn.b.pmuactv = 1;
  65583. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65584. + dwc_udelay(10);
  65585. +
  65586. + /* Programm Disable VBUS to 0 */
  65587. + gpwrdn.d32 = 0;
  65588. + gpwrdn.b.dis_vbus = 1;
  65589. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65590. +
  65591. + /*Initialize the core as Host */
  65592. + core_if->op_state = A_HOST;
  65593. + dwc_otg_core_init(core_if);
  65594. + dwc_otg_enable_global_interrupts(core_if);
  65595. + cil_hcd_start(core_if);
  65596. +
  65597. + return 1;
  65598. +}
  65599. +
  65600. +/** This interrupt indicates that restore command after Hibernation
  65601. + * was completed by the core. */
  65602. +int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
  65603. +{
  65604. + pcgcctl_data_t pcgcctl;
  65605. + DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
  65606. +
  65607. + //TODO De-assert restore signal. 8.a
  65608. + pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
  65609. + if (pcgcctl.b.restoremode == 1) {
  65610. + gintmsk_data_t gintmsk = {.d32 = 0 };
  65611. + /*
  65612. + * If restore mode is Remote Wakeup,
  65613. + * unmask Remote Wakeup interrupt.
  65614. + */
  65615. + gintmsk.b.wkupintr = 1;
  65616. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  65617. + 0, gintmsk.d32);
  65618. + }
  65619. +
  65620. + return 1;
  65621. +}
  65622. +
  65623. +/**
  65624. + * This interrupt indicates that a device has been disconnected from
  65625. + * the root port.
  65626. + */
  65627. +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
  65628. +{
  65629. + gintsts_data_t gintsts;
  65630. +
  65631. + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
  65632. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
  65633. + op_state_str(core_if));
  65634. +
  65635. +/** @todo Consolidate this if statement. */
  65636. +#ifndef DWC_HOST_ONLY
  65637. + if (core_if->op_state == B_HOST) {
  65638. + /* If in device mode Disconnect and stop the HCD, then
  65639. + * start the PCD. */
  65640. + DWC_SPINUNLOCK(core_if->lock);
  65641. + cil_hcd_disconnect(core_if);
  65642. + cil_pcd_start(core_if);
  65643. + DWC_SPINLOCK(core_if->lock);
  65644. + core_if->op_state = B_PERIPHERAL;
  65645. + } else if (dwc_otg_is_device_mode(core_if)) {
  65646. + gotgctl_data_t gotgctl = {.d32 = 0 };
  65647. + gotgctl.d32 =
  65648. + DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  65649. + if (gotgctl.b.hstsethnpen == 1) {
  65650. + /* Do nothing, if HNP in process the OTG
  65651. + * interrupt "Host Negotiation Detected"
  65652. + * interrupt will do the mode switch.
  65653. + */
  65654. + } else if (gotgctl.b.devhnpen == 0) {
  65655. + /* If in device mode Disconnect and stop the HCD, then
  65656. + * start the PCD. */
  65657. + DWC_SPINUNLOCK(core_if->lock);
  65658. + cil_hcd_disconnect(core_if);
  65659. + cil_pcd_start(core_if);
  65660. + DWC_SPINLOCK(core_if->lock);
  65661. + core_if->op_state = B_PERIPHERAL;
  65662. + } else {
  65663. + DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
  65664. + }
  65665. + } else {
  65666. + if (core_if->op_state == A_HOST) {
  65667. + /* A-Cable still connected but device disconnected. */
  65668. + cil_hcd_disconnect(core_if);
  65669. + if (core_if->adp_enable) {
  65670. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  65671. + cil_hcd_stop(core_if);
  65672. + /* Enable Power Down Logic */
  65673. + gpwrdn.b.pmuintsel = 1;
  65674. + gpwrdn.b.pmuactv = 1;
  65675. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65676. + gpwrdn, 0, gpwrdn.d32);
  65677. + dwc_otg_adp_probe_start(core_if);
  65678. +
  65679. + /* Power off the core */
  65680. + if (core_if->power_down == 2) {
  65681. + gpwrdn.d32 = 0;
  65682. + gpwrdn.b.pwrdnswtch = 1;
  65683. + DWC_MODIFY_REG32
  65684. + (&core_if->core_global_regs->gpwrdn,
  65685. + gpwrdn.d32, 0);
  65686. + }
  65687. + }
  65688. + }
  65689. + }
  65690. +#endif
  65691. + /* Change to L3(OFF) state */
  65692. + core_if->lx_state = DWC_OTG_L3;
  65693. +
  65694. + gintsts.d32 = 0;
  65695. + gintsts.b.disconnect = 1;
  65696. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65697. + return 1;
  65698. +}
  65699. +
  65700. +/**
  65701. + * This interrupt indicates that SUSPEND state has been detected on
  65702. + * the USB.
  65703. + *
  65704. + * For HNP the USB Suspend interrupt signals the change from
  65705. + * "a_peripheral" to "a_host".
  65706. + *
  65707. + * When power management is enabled the core will be put in low power
  65708. + * mode.
  65709. + */
  65710. +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
  65711. +{
  65712. + dsts_data_t dsts;
  65713. + gintsts_data_t gintsts;
  65714. + dcfg_data_t dcfg;
  65715. +
  65716. + DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
  65717. +
  65718. + if (dwc_otg_is_device_mode(core_if)) {
  65719. + /* Check the Device status register to determine if the Suspend
  65720. + * state is active. */
  65721. + dsts.d32 =
  65722. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  65723. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
  65724. + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
  65725. + "HWCFG4.power Optimize=%d\n",
  65726. + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
  65727. +
  65728. +#ifdef PARTIAL_POWER_DOWN
  65729. +/** @todo Add a module parameter for power management. */
  65730. +
  65731. + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
  65732. + pcgcctl_data_t power = {.d32 = 0 };
  65733. + DWC_DEBUGPL(DBG_CIL, "suspend\n");
  65734. +
  65735. + power.b.pwrclmp = 1;
  65736. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65737. +
  65738. + power.b.rstpdwnmodule = 1;
  65739. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  65740. +
  65741. + power.b.stoppclk = 1;
  65742. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  65743. +
  65744. + } else {
  65745. + DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
  65746. + }
  65747. +#endif
  65748. + /* PCD callback for suspend. Release the lock inside of callback function */
  65749. + cil_pcd_suspend(core_if);
  65750. + if (core_if->power_down == 2)
  65751. + {
  65752. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  65753. + DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
  65754. + DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
  65755. +
  65756. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  65757. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65758. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65759. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  65760. +
  65761. + /* Change to L2(suspend) state */
  65762. + core_if->lx_state = DWC_OTG_L2;
  65763. +
  65764. + /* Clear interrupt in gintsts */
  65765. + gintsts.d32 = 0;
  65766. + gintsts.b.usbsuspend = 1;
  65767. + DWC_WRITE_REG32(&core_if->core_global_regs->
  65768. + gintsts, gintsts.d32);
  65769. + DWC_PRINTF("Start of hibernation completed\n");
  65770. + dwc_otg_save_global_regs(core_if);
  65771. + dwc_otg_save_dev_regs(core_if);
  65772. +
  65773. + gusbcfg.d32 =
  65774. + DWC_READ_REG32(&core_if->core_global_regs->
  65775. + gusbcfg);
  65776. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  65777. + /* ULPI interface */
  65778. + /* Suspend the Phy Clock */
  65779. + pcgcctl.d32 = 0;
  65780. + pcgcctl.b.stoppclk = 1;
  65781. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  65782. + pcgcctl.d32);
  65783. + dwc_udelay(10);
  65784. + gpwrdn.b.pmuactv = 1;
  65785. + DWC_MODIFY_REG32(&core_if->
  65786. + core_global_regs->
  65787. + gpwrdn, 0, gpwrdn.d32);
  65788. + } else {
  65789. + /* UTMI+ Interface */
  65790. + gpwrdn.b.pmuactv = 1;
  65791. + DWC_MODIFY_REG32(&core_if->
  65792. + core_global_regs->
  65793. + gpwrdn, 0, gpwrdn.d32);
  65794. + dwc_udelay(10);
  65795. + pcgcctl.b.stoppclk = 1;
  65796. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  65797. + pcgcctl.d32);
  65798. + dwc_udelay(10);
  65799. + }
  65800. +
  65801. + /* Set flag to indicate that we are in hibernation */
  65802. + core_if->hibernation_suspend = 1;
  65803. + /* Enable interrupts from wake up logic */
  65804. + gpwrdn.d32 = 0;
  65805. + gpwrdn.b.pmuintsel = 1;
  65806. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65807. + gpwrdn, 0, gpwrdn.d32);
  65808. + dwc_udelay(10);
  65809. +
  65810. + /* Unmask device mode interrupts in GPWRDN */
  65811. + gpwrdn.d32 = 0;
  65812. + gpwrdn.b.rst_det_msk = 1;
  65813. + gpwrdn.b.lnstchng_msk = 1;
  65814. + gpwrdn.b.sts_chngint_msk = 1;
  65815. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65816. + gpwrdn, 0, gpwrdn.d32);
  65817. + dwc_udelay(10);
  65818. +
  65819. + /* Enable Power Down Clamp */
  65820. + gpwrdn.d32 = 0;
  65821. + gpwrdn.b.pwrdnclmp = 1;
  65822. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65823. + gpwrdn, 0, gpwrdn.d32);
  65824. + dwc_udelay(10);
  65825. +
  65826. + /* Switch off VDD */
  65827. + gpwrdn.d32 = 0;
  65828. + gpwrdn.b.pwrdnswtch = 1;
  65829. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65830. + gpwrdn, 0, gpwrdn.d32);
  65831. +
  65832. + /* Save gpwrdn register for further usage if stschng interrupt */
  65833. + core_if->gr_backup->gpwrdn_local =
  65834. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65835. + DWC_PRINTF("Hibernation completed\n");
  65836. +
  65837. + return 1;
  65838. + }
  65839. + } else if (core_if->power_down == 3) {
  65840. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65841. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  65842. + DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
  65843. + DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
  65844. +
  65845. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  65846. + DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
  65847. + core_if->xhib = 1;
  65848. +
  65849. + /* Clear interrupt in gintsts */
  65850. + gintsts.d32 = 0;
  65851. + gintsts.b.usbsuspend = 1;
  65852. + DWC_WRITE_REG32(&core_if->core_global_regs->
  65853. + gintsts, gintsts.d32);
  65854. +
  65855. + dwc_otg_save_global_regs(core_if);
  65856. + dwc_otg_save_dev_regs(core_if);
  65857. +
  65858. + /* Wait for 10 PHY clocks */
  65859. + dwc_udelay(10);
  65860. +
  65861. + /* Program GPIO register while entering to xHib */
  65862. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
  65863. +
  65864. + pcgcctl.b.enbl_extnd_hiber = 1;
  65865. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65866. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65867. +
  65868. + pcgcctl.d32 = 0;
  65869. + pcgcctl.b.extnd_hiber_pwrclmp = 1;
  65870. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65871. +
  65872. + pcgcctl.d32 = 0;
  65873. + pcgcctl.b.extnd_hiber_switch = 1;
  65874. + core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65875. + core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
  65876. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65877. +
  65878. + DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
  65879. +
  65880. + return 1;
  65881. + }
  65882. + }
  65883. + } else {
  65884. + if (core_if->op_state == A_PERIPHERAL) {
  65885. + DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
  65886. + /* Clear the a_peripheral flag, back to a_host. */
  65887. + DWC_SPINUNLOCK(core_if->lock);
  65888. + cil_pcd_stop(core_if);
  65889. + cil_hcd_start(core_if);
  65890. + DWC_SPINLOCK(core_if->lock);
  65891. + core_if->op_state = A_HOST;
  65892. + }
  65893. + }
  65894. +
  65895. + /* Change to L2(suspend) state */
  65896. + core_if->lx_state = DWC_OTG_L2;
  65897. +
  65898. + /* Clear interrupt */
  65899. + gintsts.d32 = 0;
  65900. + gintsts.b.usbsuspend = 1;
  65901. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65902. +
  65903. + return 1;
  65904. +}
  65905. +
  65906. +static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
  65907. +{
  65908. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65909. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65910. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  65911. +
  65912. + dwc_udelay(10);
  65913. +
  65914. + /* Program GPIO register while entering to xHib */
  65915. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
  65916. +
  65917. + pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
  65918. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  65919. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65920. + dwc_udelay(10);
  65921. +
  65922. + gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
  65923. + gpwrdn.b.restore = 1;
  65924. + DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
  65925. + dwc_udelay(10);
  65926. +
  65927. + restore_lpm_i2c_regs(core_if);
  65928. +
  65929. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  65930. + pcgcctl.b.max_xcvrselect = 1;
  65931. + pcgcctl.b.ess_reg_restored = 0;
  65932. + pcgcctl.b.extnd_hiber_switch = 0;
  65933. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  65934. + pcgcctl.b.enbl_extnd_hiber = 1;
  65935. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65936. +
  65937. + gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
  65938. + gahbcfg.b.glblintrmsk = 1;
  65939. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  65940. +
  65941. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  65942. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
  65943. +
  65944. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  65945. + core_if->gr_backup->gusbcfg_local);
  65946. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  65947. + core_if->dr_backup->dcfg);
  65948. +
  65949. + pcgcctl.d32 = 0;
  65950. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  65951. + pcgcctl.b.max_xcvrselect = 1;
  65952. + pcgcctl.d32 |= 0x608;
  65953. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65954. + dwc_udelay(10);
  65955. +
  65956. + pcgcctl.d32 = 0;
  65957. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  65958. + pcgcctl.b.max_xcvrselect = 1;
  65959. + pcgcctl.b.ess_reg_restored = 1;
  65960. + pcgcctl.b.enbl_extnd_hiber = 1;
  65961. + pcgcctl.b.rstpdwnmodule = 1;
  65962. + pcgcctl.b.restoremode = 1;
  65963. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65964. +
  65965. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  65966. +
  65967. + return 1;
  65968. +}
  65969. +
  65970. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65971. +/**
  65972. + * This function hadles LPM transaction received interrupt.
  65973. + */
  65974. +static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
  65975. +{
  65976. + glpmcfg_data_t lpmcfg;
  65977. + gintsts_data_t gintsts;
  65978. +
  65979. + if (!core_if->core_params->lpm_enable) {
  65980. + DWC_PRINTF("Unexpected LPM interrupt\n");
  65981. + }
  65982. +
  65983. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65984. + DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
  65985. +
  65986. + if (dwc_otg_is_host_mode(core_if)) {
  65987. + cil_hcd_sleep(core_if);
  65988. + } else {
  65989. + lpmcfg.b.hird_thres |= (1 << 4);
  65990. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  65991. + lpmcfg.d32);
  65992. + }
  65993. +
  65994. + /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
  65995. + dwc_udelay(10);
  65996. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65997. + if (lpmcfg.b.prt_sleep_sts) {
  65998. + /* Save the current state */
  65999. + core_if->lx_state = DWC_OTG_L1;
  66000. + }
  66001. +
  66002. + /* Clear interrupt */
  66003. + gintsts.d32 = 0;
  66004. + gintsts.b.lpmtranrcvd = 1;
  66005. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  66006. + return 1;
  66007. +}
  66008. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  66009. +
  66010. +/**
  66011. + * This function returns the Core Interrupt register.
  66012. + */
  66013. +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)
  66014. +{
  66015. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  66016. + gintsts_data_t gintsts;
  66017. + gintmsk_data_t gintmsk;
  66018. + gintmsk_data_t gintmsk_common = {.d32 = 0 };
  66019. + gintmsk_common.b.wkupintr = 1;
  66020. + gintmsk_common.b.sessreqintr = 1;
  66021. + gintmsk_common.b.conidstschng = 1;
  66022. + gintmsk_common.b.otgintr = 1;
  66023. + gintmsk_common.b.modemismatch = 1;
  66024. + gintmsk_common.b.disconnect = 1;
  66025. + gintmsk_common.b.usbsuspend = 1;
  66026. +#ifdef CONFIG_USB_DWC_OTG_LPM
  66027. + gintmsk_common.b.lpmtranrcvd = 1;
  66028. +#endif
  66029. + gintmsk_common.b.restoredone = 1;
  66030. + if(dwc_otg_is_device_mode(core_if))
  66031. + {
  66032. + /** @todo: The port interrupt occurs while in device
  66033. + * mode. Added code to CIL to clear the interrupt for now!
  66034. + */
  66035. + gintmsk_common.b.portintr = 1;
  66036. + }
  66037. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  66038. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  66039. + if(fiq_enable) {
  66040. + local_fiq_disable();
  66041. + /* Pull in the interrupts that the FIQ has masked */
  66042. + gintmsk.d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  66043. + /* for the upstairs function to reenable - have to read it here in case FIQ triggers again */
  66044. + reenable_gintmsk->d32 |= gintmsk.d32;
  66045. + reenable_gintmsk->d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  66046. + reenable_gintmsk->d32 &= gintmsk_common.d32;
  66047. + local_fiq_enable();
  66048. + }
  66049. +
  66050. + gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  66051. +
  66052. +#ifdef DEBUG
  66053. + /* if any common interrupts set */
  66054. + if (gintsts.d32 & gintmsk_common.d32) {
  66055. + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
  66056. + gintsts.d32, gintmsk.d32);
  66057. + }
  66058. +#endif
  66059. + if (!fiq_enable){
  66060. + if (gahbcfg.b.glblintrmsk)
  66061. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  66062. + else
  66063. + return 0;
  66064. + } else {
  66065. + /* Our IRQ kicker is no longer the USB hardware, it's the MPHI interface.
  66066. + * Can't trust the global interrupt mask bit in this case.
  66067. + */
  66068. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  66069. + }
  66070. +
  66071. +}
  66072. +
  66073. +/* MACRO for clearing interupt bits in GPWRDN register */
  66074. +#define CLEAR_GPWRDN_INTR(__core_if,__intr) \
  66075. +do { \
  66076. + gpwrdn_data_t gpwrdn = {.d32=0}; \
  66077. + gpwrdn.b.__intr = 1; \
  66078. + DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
  66079. + 0, gpwrdn.d32); \
  66080. +} while (0)
  66081. +
  66082. +/**
  66083. + * Common interrupt handler.
  66084. + *
  66085. + * The common interrupts are those that occur in both Host and Device mode.
  66086. + * This handler handles the following interrupts:
  66087. + * - Mode Mismatch Interrupt
  66088. + * - Disconnect Interrupt
  66089. + * - OTG Interrupt
  66090. + * - Connector ID Status Change Interrupt
  66091. + * - Session Request Interrupt.
  66092. + * - Resume / Remote Wakeup Detected Interrupt.
  66093. + * - LPM Transaction Received Interrupt
  66094. + * - ADP Transaction Received Interrupt
  66095. + *
  66096. + */
  66097. +int32_t dwc_otg_handle_common_intr(void *dev)
  66098. +{
  66099. + int retval = 0;
  66100. + gintsts_data_t gintsts;
  66101. + gintmsk_data_t gintmsk_reenable = { .d32 = 0 };
  66102. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  66103. + dwc_otg_device_t *otg_dev = dev;
  66104. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  66105. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66106. + if (dwc_otg_is_device_mode(core_if))
  66107. + core_if->frame_num = dwc_otg_get_frame_number(core_if);
  66108. +
  66109. + if (core_if->lock)
  66110. + DWC_SPINLOCK(core_if->lock);
  66111. +
  66112. + if (core_if->power_down == 3 && core_if->xhib == 1) {
  66113. + DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
  66114. + retval |= dwc_otg_handle_xhib_exit_intr(core_if);
  66115. + core_if->xhib = 2;
  66116. + if (core_if->lock)
  66117. + DWC_SPINUNLOCK(core_if->lock);
  66118. +
  66119. + return retval;
  66120. + }
  66121. +
  66122. + if (core_if->hibernation_suspend <= 0) {
  66123. + /* read_common will have to poke the FIQ's saved mask. We must then clear this mask at the end
  66124. + * of this handler - god only knows why it's done like this
  66125. + */
  66126. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &gintmsk_reenable, otg_dev->hcd);
  66127. +
  66128. + if (gintsts.b.modemismatch) {
  66129. + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  66130. + }
  66131. + if (gintsts.b.otgintr) {
  66132. + retval |= dwc_otg_handle_otg_intr(core_if);
  66133. + }
  66134. + if (gintsts.b.conidstschng) {
  66135. + retval |=
  66136. + dwc_otg_handle_conn_id_status_change_intr(core_if);
  66137. + }
  66138. + if (gintsts.b.disconnect) {
  66139. + retval |= dwc_otg_handle_disconnect_intr(core_if);
  66140. + }
  66141. + if (gintsts.b.sessreqintr) {
  66142. + retval |= dwc_otg_handle_session_req_intr(core_if);
  66143. + }
  66144. + if (gintsts.b.wkupintr) {
  66145. + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
  66146. + }
  66147. + if (gintsts.b.usbsuspend) {
  66148. + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
  66149. + }
  66150. +#ifdef CONFIG_USB_DWC_OTG_LPM
  66151. + if (gintsts.b.lpmtranrcvd) {
  66152. + retval |= dwc_otg_handle_lpm_intr(core_if);
  66153. + }
  66154. +#endif
  66155. + if (gintsts.b.restoredone) {
  66156. + gintsts.d32 = 0;
  66157. + if (core_if->power_down == 2)
  66158. + core_if->hibernation_suspend = -1;
  66159. + else if (core_if->power_down == 3 && core_if->xhib == 2) {
  66160. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  66161. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  66162. + dctl_data_t dctl = {.d32 = 0 };
  66163. +
  66164. + DWC_WRITE_REG32(&core_if->core_global_regs->
  66165. + gintsts, 0xFFFFFFFF);
  66166. +
  66167. + DWC_DEBUGPL(DBG_ANY,
  66168. + "RESTORE DONE generated\n");
  66169. +
  66170. + gpwrdn.b.restore = 1;
  66171. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66172. + dwc_udelay(10);
  66173. +
  66174. + pcgcctl.b.rstpdwnmodule = 1;
  66175. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  66176. +
  66177. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
  66178. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
  66179. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
  66180. + dwc_udelay(50);
  66181. +
  66182. + dctl.b.pwronprgdone = 1;
  66183. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  66184. + dwc_udelay(10);
  66185. +
  66186. + dwc_otg_restore_global_regs(core_if);
  66187. + dwc_otg_restore_dev_regs(core_if, 0);
  66188. +
  66189. + dctl.d32 = 0;
  66190. + dctl.b.pwronprgdone = 1;
  66191. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  66192. + dwc_udelay(10);
  66193. +
  66194. + pcgcctl.d32 = 0;
  66195. + pcgcctl.b.enbl_extnd_hiber = 1;
  66196. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  66197. +
  66198. + /* The core will be in ON STATE */
  66199. + core_if->lx_state = DWC_OTG_L0;
  66200. + core_if->xhib = 0;
  66201. +
  66202. + DWC_SPINUNLOCK(core_if->lock);
  66203. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  66204. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  66205. + }
  66206. + DWC_SPINLOCK(core_if->lock);
  66207. +
  66208. + }
  66209. +
  66210. + gintsts.b.restoredone = 1;
  66211. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  66212. + DWC_PRINTF(" --Restore done interrupt received-- \n");
  66213. + retval |= 1;
  66214. + }
  66215. + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
  66216. + /* The port interrupt occurs while in device mode with HPRT0
  66217. + * Port Enable/Disable.
  66218. + */
  66219. + gintsts.d32 = 0;
  66220. + gintsts.b.portintr = 1;
  66221. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  66222. + retval |= 1;
  66223. + gintmsk_reenable.b.portintr = 1;
  66224. +
  66225. + }
  66226. + /* Did we actually handle anything? if so, unmask the interrupt */
  66227. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "CILOUT %1d", retval);
  66228. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintsts.d32);
  66229. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintmsk_reenable.d32);
  66230. + if (retval) {
  66231. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_reenable.d32);
  66232. + }
  66233. +
  66234. + } else {
  66235. + DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  66236. +
  66237. + if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
  66238. + CLEAR_GPWRDN_INTR(core_if, disconn_det);
  66239. + if (gpwrdn.b.linestate == 0) {
  66240. + dwc_otg_handle_pwrdn_disconnect_intr(core_if);
  66241. + } else {
  66242. + DWC_PRINTF("Disconnect detected while linestate is not 0\n");
  66243. + }
  66244. +
  66245. + retval |= 1;
  66246. + }
  66247. + if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
  66248. + CLEAR_GPWRDN_INTR(core_if, lnstschng);
  66249. + /* remote wakeup from hibernation */
  66250. + if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
  66251. + dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
  66252. + } else {
  66253. + DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
  66254. + }
  66255. + retval |= 1;
  66256. + }
  66257. + if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
  66258. + CLEAR_GPWRDN_INTR(core_if, rst_det);
  66259. + if (gpwrdn.b.linestate == 0) {
  66260. + DWC_PRINTF("Reset detected\n");
  66261. + retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
  66262. + }
  66263. + }
  66264. + if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
  66265. + CLEAR_GPWRDN_INTR(core_if, srp_det);
  66266. + dwc_otg_handle_pwrdn_srp_intr(core_if);
  66267. + retval |= 1;
  66268. + }
  66269. + }
  66270. + /* Handle ADP interrupt here */
  66271. + if (gpwrdn.b.adp_int) {
  66272. + DWC_PRINTF("ADP interrupt\n");
  66273. + CLEAR_GPWRDN_INTR(core_if, adp_int);
  66274. + dwc_otg_adp_handle_intr(core_if);
  66275. + retval |= 1;
  66276. + }
  66277. + if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
  66278. + DWC_PRINTF("STS CHNG interrupt asserted\n");
  66279. + CLEAR_GPWRDN_INTR(core_if, sts_chngint);
  66280. + dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
  66281. +
  66282. + retval |= 1;
  66283. + }
  66284. + if (core_if->lock)
  66285. + DWC_SPINUNLOCK(core_if->lock);
  66286. + return retval;
  66287. +}
  66288. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_core_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h
  66289. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 1970-01-01 01:00:00.000000000 +0100
  66290. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 2014-04-24 16:04:39.815124215 +0200
  66291. @@ -0,0 +1,705 @@
  66292. +/* ==========================================================================
  66293. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_core_if.h $
  66294. + * $Revision: #13 $
  66295. + * $Date: 2012/08/10 $
  66296. + * $Change: 2047372 $
  66297. + *
  66298. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66299. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66300. + * otherwise expressly agreed to in writing between Synopsys and you.
  66301. + *
  66302. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66303. + * any End User Software License Agreement or Agreement for Licensed Product
  66304. + * with Synopsys or any supplement thereto. You are permitted to use and
  66305. + * redistribute this Software in source and binary forms, with or without
  66306. + * modification, provided that redistributions of source code must retain this
  66307. + * notice. You may not view, use, disclose, copy or distribute this file or
  66308. + * any information contained herein except pursuant to this license grant from
  66309. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66310. + * below, then you are not authorized to use the Software.
  66311. + *
  66312. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66313. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66314. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66315. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66316. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66317. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66318. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66319. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66320. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66321. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66322. + * DAMAGE.
  66323. + * ========================================================================== */
  66324. +#if !defined(__DWC_CORE_IF_H__)
  66325. +#define __DWC_CORE_IF_H__
  66326. +
  66327. +#include "dwc_os.h"
  66328. +
  66329. +/** @file
  66330. + * This file defines DWC_OTG Core API
  66331. + */
  66332. +
  66333. +struct dwc_otg_core_if;
  66334. +typedef struct dwc_otg_core_if dwc_otg_core_if_t;
  66335. +
  66336. +/** Maximum number of Periodic FIFOs */
  66337. +#define MAX_PERIO_FIFOS 15
  66338. +/** Maximum number of Periodic FIFOs */
  66339. +#define MAX_TX_FIFOS 15
  66340. +
  66341. +/** Maximum number of Endpoints/HostChannels */
  66342. +#define MAX_EPS_CHANNELS 16
  66343. +
  66344. +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * _reg_base_addr);
  66345. +extern void dwc_otg_core_init(dwc_otg_core_if_t * _core_if);
  66346. +extern void dwc_otg_cil_remove(dwc_otg_core_if_t * _core_if);
  66347. +
  66348. +extern void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * _core_if);
  66349. +extern void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * _core_if);
  66350. +
  66351. +extern uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if);
  66352. +extern uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if);
  66353. +
  66354. +extern uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if);
  66355. +
  66356. +/** This function should be called on every hardware interrupt. */
  66357. +extern int32_t dwc_otg_handle_common_intr(void *otg_dev);
  66358. +
  66359. +/** @name OTG Core Parameters */
  66360. +/** @{ */
  66361. +
  66362. +/**
  66363. + * Specifies the OTG capabilities. The driver will automatically
  66364. + * detect the value for this parameter if none is specified.
  66365. + * 0 - HNP and SRP capable (default)
  66366. + * 1 - SRP Only capable
  66367. + * 2 - No HNP/SRP capable
  66368. + */
  66369. +extern int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val);
  66370. +extern int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if);
  66371. +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
  66372. +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
  66373. +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  66374. +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
  66375. +
  66376. +extern int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val);
  66377. +extern int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if);
  66378. +#define dwc_param_opt_default 1
  66379. +
  66380. +/**
  66381. + * Specifies whether to use slave or DMA mode for accessing the data
  66382. + * FIFOs. The driver will automatically detect the value for this
  66383. + * parameter if none is specified.
  66384. + * 0 - Slave
  66385. + * 1 - DMA (default, if available)
  66386. + */
  66387. +extern int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if,
  66388. + int32_t val);
  66389. +extern int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if);
  66390. +#define dwc_param_dma_enable_default 1
  66391. +
  66392. +/**
  66393. + * When DMA mode is enabled specifies whether to use
  66394. + * address DMA or DMA Descritor mode for accessing the data
  66395. + * FIFOs in device mode. The driver will automatically detect
  66396. + * the value for this parameter if none is specified.
  66397. + * 0 - address DMA
  66398. + * 1 - DMA Descriptor(default, if available)
  66399. + */
  66400. +extern int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if,
  66401. + int32_t val);
  66402. +extern int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if);
  66403. +//#define dwc_param_dma_desc_enable_default 1
  66404. +#define dwc_param_dma_desc_enable_default 0 // Broadcom BCM2708
  66405. +
  66406. +/** The DMA Burst size (applicable only for External DMA
  66407. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  66408. + */
  66409. +extern int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if,
  66410. + int32_t val);
  66411. +extern int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if);
  66412. +#define dwc_param_dma_burst_size_default 32
  66413. +
  66414. +/**
  66415. + * Specifies the maximum speed of operation in host and device mode.
  66416. + * The actual speed depends on the speed of the attached device and
  66417. + * the value of phy_type. The actual speed depends on the speed of the
  66418. + * attached device.
  66419. + * 0 - High Speed (default)
  66420. + * 1 - Full Speed
  66421. + */
  66422. +extern int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val);
  66423. +extern int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if);
  66424. +#define dwc_param_speed_default 0
  66425. +#define DWC_SPEED_PARAM_HIGH 0
  66426. +#define DWC_SPEED_PARAM_FULL 1
  66427. +
  66428. +/** Specifies whether low power mode is supported when attached
  66429. + * to a Full Speed or Low Speed device in host mode.
  66430. + * 0 - Don't support low power mode (default)
  66431. + * 1 - Support low power mode
  66432. + */
  66433. +extern int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  66434. + core_if, int32_t val);
  66435. +extern int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t
  66436. + * core_if);
  66437. +#define dwc_param_host_support_fs_ls_low_power_default 0
  66438. +
  66439. +/** Specifies the PHY clock rate in low power mode when connected to a
  66440. + * Low Speed device in host mode. This parameter is applicable only if
  66441. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  66442. + * then defaults to 6 MHZ otherwise 48 MHZ.
  66443. + *
  66444. + * 0 - 48 MHz
  66445. + * 1 - 6 MHz
  66446. + */
  66447. +extern int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  66448. + core_if, int32_t val);
  66449. +extern int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  66450. + core_if);
  66451. +#define dwc_param_host_ls_low_power_phy_clk_default 0
  66452. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  66453. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  66454. +
  66455. +/**
  66456. + * 0 - Use cC FIFO size parameters
  66457. + * 1 - Allow dynamic FIFO sizing (default)
  66458. + */
  66459. +extern int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  66460. + int32_t val);
  66461. +extern int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t *
  66462. + core_if);
  66463. +#define dwc_param_enable_dynamic_fifo_default 1
  66464. +
  66465. +/** Total number of 4-byte words in the data FIFO memory. This
  66466. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  66467. + * Tx FIFOs.
  66468. + * 32 to 32768 (default 8192)
  66469. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  66470. + */
  66471. +extern int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if,
  66472. + int32_t val);
  66473. +extern int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if);
  66474. +//#define dwc_param_data_fifo_size_default 8192
  66475. +#define dwc_param_data_fifo_size_default 0xFF0 // Broadcom BCM2708
  66476. +
  66477. +/** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  66478. + * FIFO sizing is enabled.
  66479. + * 16 to 32768 (default 1064)
  66480. + */
  66481. +extern int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if,
  66482. + int32_t val);
  66483. +extern int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if);
  66484. +#define dwc_param_dev_rx_fifo_size_default 1064
  66485. +
  66486. +/** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  66487. + * when dynamic FIFO sizing is enabled.
  66488. + * 16 to 32768 (default 1024)
  66489. + */
  66490. +extern int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  66491. + core_if, int32_t val);
  66492. +extern int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  66493. + core_if);
  66494. +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
  66495. +
  66496. +/** Number of 4-byte words in each of the periodic Tx FIFOs in device
  66497. + * mode when dynamic FIFO sizing is enabled.
  66498. + * 4 to 768 (default 256)
  66499. + */
  66500. +extern int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  66501. + int32_t val, int fifo_num);
  66502. +extern int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t *
  66503. + core_if, int fifo_num);
  66504. +#define dwc_param_dev_perio_tx_fifo_size_default 256
  66505. +
  66506. +/** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  66507. + * FIFO sizing is enabled.
  66508. + * 16 to 32768 (default 1024)
  66509. + */
  66510. +extern int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  66511. + int32_t val);
  66512. +extern int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if);
  66513. +//#define dwc_param_host_rx_fifo_size_default 1024
  66514. +#define dwc_param_host_rx_fifo_size_default 774 // Broadcom BCM2708
  66515. +
  66516. +/** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  66517. + * when Dynamic FIFO sizing is enabled in the core.
  66518. + * 16 to 32768 (default 1024)
  66519. + */
  66520. +extern int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  66521. + core_if, int32_t val);
  66522. +extern int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  66523. + core_if);
  66524. +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
  66525. +#define dwc_param_host_nperio_tx_fifo_size_default 0x100 // Broadcom BCM2708
  66526. +
  66527. +/** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  66528. + * FIFO sizing is enabled.
  66529. + * 16 to 32768 (default 1024)
  66530. + */
  66531. +extern int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  66532. + core_if, int32_t val);
  66533. +extern int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  66534. + core_if);
  66535. +//#define dwc_param_host_perio_tx_fifo_size_default 1024
  66536. +#define dwc_param_host_perio_tx_fifo_size_default 0x200 // Broadcom BCM2708
  66537. +
  66538. +/** The maximum transfer size supported in bytes.
  66539. + * 2047 to 65,535 (default 65,535)
  66540. + */
  66541. +extern int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  66542. + int32_t val);
  66543. +extern int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if);
  66544. +#define dwc_param_max_transfer_size_default 65535
  66545. +
  66546. +/** The maximum number of packets in a transfer.
  66547. + * 15 to 511 (default 511)
  66548. + */
  66549. +extern int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if,
  66550. + int32_t val);
  66551. +extern int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if);
  66552. +#define dwc_param_max_packet_count_default 511
  66553. +
  66554. +/** The number of host channel registers to use.
  66555. + * 1 to 16 (default 12)
  66556. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  66557. + */
  66558. +extern int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if,
  66559. + int32_t val);
  66560. +extern int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if);
  66561. +//#define dwc_param_host_channels_default 12
  66562. +#define dwc_param_host_channels_default 8 // Broadcom BCM2708
  66563. +
  66564. +/** The number of endpoints in addition to EP0 available for device
  66565. + * mode operations.
  66566. + * 1 to 15 (default 6 IN and OUT)
  66567. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  66568. + * endpoints in addition to EP0.
  66569. + */
  66570. +extern int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if,
  66571. + int32_t val);
  66572. +extern int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if);
  66573. +#define dwc_param_dev_endpoints_default 6
  66574. +
  66575. +/**
  66576. + * Specifies the type of PHY interface to use. By default, the driver
  66577. + * will automatically detect the phy_type.
  66578. + *
  66579. + * 0 - Full Speed PHY
  66580. + * 1 - UTMI+ (default)
  66581. + * 2 - ULPI
  66582. + */
  66583. +extern int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val);
  66584. +extern int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if);
  66585. +#define DWC_PHY_TYPE_PARAM_FS 0
  66586. +#define DWC_PHY_TYPE_PARAM_UTMI 1
  66587. +#define DWC_PHY_TYPE_PARAM_ULPI 2
  66588. +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
  66589. +
  66590. +/**
  66591. + * Specifies the UTMI+ Data Width. This parameter is
  66592. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  66593. + * PHY_TYPE, this parameter indicates the data width between
  66594. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  66595. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  66596. + * to "8 and 16 bits", meaning that the core has been
  66597. + * configured to work at either data path width.
  66598. + *
  66599. + * 8 or 16 bits (default 16)
  66600. + */
  66601. +extern int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if,
  66602. + int32_t val);
  66603. +extern int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if);
  66604. +//#define dwc_param_phy_utmi_width_default 16
  66605. +#define dwc_param_phy_utmi_width_default 8 // Broadcom BCM2708
  66606. +
  66607. +/**
  66608. + * Specifies whether the ULPI operates at double or single
  66609. + * data rate. This parameter is only applicable if PHY_TYPE is
  66610. + * ULPI.
  66611. + *
  66612. + * 0 - single data rate ULPI interface with 8 bit wide data
  66613. + * bus (default)
  66614. + * 1 - double data rate ULPI interface with 4 bit wide data
  66615. + * bus
  66616. + */
  66617. +extern int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if,
  66618. + int32_t val);
  66619. +extern int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if);
  66620. +#define dwc_param_phy_ulpi_ddr_default 0
  66621. +
  66622. +/**
  66623. + * Specifies whether to use the internal or external supply to
  66624. + * drive the vbus with a ULPI phy.
  66625. + */
  66626. +extern int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  66627. + int32_t val);
  66628. +extern int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if);
  66629. +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
  66630. +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
  66631. +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
  66632. +
  66633. +/**
  66634. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  66635. + * parameter is only applicable if PHY_TYPE is FS.
  66636. + * 0 - No (default)
  66637. + * 1 - Yes
  66638. + */
  66639. +extern int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if,
  66640. + int32_t val);
  66641. +extern int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if);
  66642. +#define dwc_param_i2c_enable_default 0
  66643. +
  66644. +extern int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if,
  66645. + int32_t val);
  66646. +extern int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if);
  66647. +#define dwc_param_ulpi_fs_ls_default 0
  66648. +
  66649. +extern int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val);
  66650. +extern int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if);
  66651. +#define dwc_param_ts_dline_default 0
  66652. +
  66653. +/**
  66654. + * Specifies whether dedicated transmit FIFOs are
  66655. + * enabled for non periodic IN endpoints in device mode
  66656. + * 0 - No
  66657. + * 1 - Yes
  66658. + */
  66659. +extern int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  66660. + int32_t val);
  66661. +extern int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t *
  66662. + core_if);
  66663. +#define dwc_param_en_multiple_tx_fifo_default 1
  66664. +
  66665. +/** Number of 4-byte words in each of the Tx FIFOs in device
  66666. + * mode when dynamic FIFO sizing is enabled.
  66667. + * 4 to 768 (default 256)
  66668. + */
  66669. +extern int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  66670. + int fifo_num, int32_t val);
  66671. +extern int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  66672. + int fifo_num);
  66673. +#define dwc_param_dev_tx_fifo_size_default 768
  66674. +
  66675. +/** Thresholding enable flag-
  66676. + * bit 0 - enable non-ISO Tx thresholding
  66677. + * bit 1 - enable ISO Tx thresholding
  66678. + * bit 2 - enable Rx thresholding
  66679. + */
  66680. +extern int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val);
  66681. +extern int32_t dwc_otg_get_thr_ctl(dwc_otg_core_if_t * core_if, int fifo_num);
  66682. +#define dwc_param_thr_ctl_default 0
  66683. +
  66684. +/** Thresholding length for Tx
  66685. + * FIFOs in 32 bit DWORDs
  66686. + */
  66687. +extern int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if,
  66688. + int32_t val);
  66689. +extern int32_t dwc_otg_get_tx_thr_length(dwc_otg_core_if_t * core_if);
  66690. +#define dwc_param_tx_thr_length_default 64
  66691. +
  66692. +/** Thresholding length for Rx
  66693. + * FIFOs in 32 bit DWORDs
  66694. + */
  66695. +extern int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if,
  66696. + int32_t val);
  66697. +extern int32_t dwc_otg_get_rx_thr_length(dwc_otg_core_if_t * core_if);
  66698. +#define dwc_param_rx_thr_length_default 64
  66699. +
  66700. +/**
  66701. + * Specifies whether LPM (Link Power Management) support is enabled
  66702. + */
  66703. +extern int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if,
  66704. + int32_t val);
  66705. +extern int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if);
  66706. +#define dwc_param_lpm_enable_default 1
  66707. +
  66708. +/**
  66709. + * Specifies whether PTI enhancement is enabled
  66710. + */
  66711. +extern int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if,
  66712. + int32_t val);
  66713. +extern int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if);
  66714. +#define dwc_param_pti_enable_default 0
  66715. +
  66716. +/**
  66717. + * Specifies whether MPI enhancement is enabled
  66718. + */
  66719. +extern int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if,
  66720. + int32_t val);
  66721. +extern int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if);
  66722. +#define dwc_param_mpi_enable_default 0
  66723. +
  66724. +/**
  66725. + * Specifies whether ADP capability is enabled
  66726. + */
  66727. +extern int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if,
  66728. + int32_t val);
  66729. +extern int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if);
  66730. +#define dwc_param_adp_enable_default 0
  66731. +
  66732. +/**
  66733. + * Specifies whether IC_USB capability is enabled
  66734. + */
  66735. +
  66736. +extern int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if,
  66737. + int32_t val);
  66738. +extern int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if);
  66739. +#define dwc_param_ic_usb_cap_default 0
  66740. +
  66741. +extern int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if,
  66742. + int32_t val);
  66743. +extern int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if);
  66744. +#define dwc_param_ahb_thr_ratio_default 0
  66745. +
  66746. +extern int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if,
  66747. + int32_t val);
  66748. +extern int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if);
  66749. +#define dwc_param_power_down_default 0
  66750. +
  66751. +extern int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if,
  66752. + int32_t val);
  66753. +extern int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if);
  66754. +#define dwc_param_reload_ctl_default 0
  66755. +
  66756. +extern int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if,
  66757. + int32_t val);
  66758. +extern int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if);
  66759. +#define dwc_param_dev_out_nak_default 0
  66760. +
  66761. +extern int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if,
  66762. + int32_t val);
  66763. +extern int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if);
  66764. +#define dwc_param_cont_on_bna_default 0
  66765. +
  66766. +extern int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if,
  66767. + int32_t val);
  66768. +extern int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if);
  66769. +#define dwc_param_ahb_single_default 0
  66770. +
  66771. +extern int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val);
  66772. +extern int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if);
  66773. +#define dwc_param_otg_ver_default 0
  66774. +
  66775. +/** @} */
  66776. +
  66777. +/** @name Access to registers and bit-fields */
  66778. +
  66779. +/**
  66780. + * Dump core registers and SPRAM
  66781. + */
  66782. +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * _core_if);
  66783. +extern void dwc_otg_dump_spram(dwc_otg_core_if_t * _core_if);
  66784. +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t * _core_if);
  66785. +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t * _core_if);
  66786. +
  66787. +/**
  66788. + * Get host negotiation status.
  66789. + */
  66790. +extern uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if);
  66791. +
  66792. +/**
  66793. + * Get srp status
  66794. + */
  66795. +extern uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if);
  66796. +
  66797. +/**
  66798. + * Set hnpreq bit in the GOTGCTL register.
  66799. + */
  66800. +extern void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val);
  66801. +
  66802. +/**
  66803. + * Get Content of SNPSID register.
  66804. + */
  66805. +extern uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if);
  66806. +
  66807. +/**
  66808. + * Get current mode.
  66809. + * Returns 0 if in device mode, and 1 if in host mode.
  66810. + */
  66811. +extern uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if);
  66812. +
  66813. +/**
  66814. + * Get value of hnpcapable field in the GUSBCFG register
  66815. + */
  66816. +extern uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if);
  66817. +/**
  66818. + * Set value of hnpcapable field in the GUSBCFG register
  66819. + */
  66820. +extern void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  66821. +
  66822. +/**
  66823. + * Get value of srpcapable field in the GUSBCFG register
  66824. + */
  66825. +extern uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if);
  66826. +/**
  66827. + * Set value of srpcapable field in the GUSBCFG register
  66828. + */
  66829. +extern void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  66830. +
  66831. +/**
  66832. + * Get value of devspeed field in the DCFG register
  66833. + */
  66834. +extern uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if);
  66835. +/**
  66836. + * Set value of devspeed field in the DCFG register
  66837. + */
  66838. +extern void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val);
  66839. +
  66840. +/**
  66841. + * Get the value of busconnected field from the HPRT0 register
  66842. + */
  66843. +extern uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if);
  66844. +
  66845. +/**
  66846. + * Gets the device enumeration Speed.
  66847. + */
  66848. +extern uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if);
  66849. +
  66850. +/**
  66851. + * Get value of prtpwr field from the HPRT0 register
  66852. + */
  66853. +extern uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if);
  66854. +
  66855. +/**
  66856. + * Get value of flag indicating core state - hibernated or not
  66857. + */
  66858. +extern uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if);
  66859. +
  66860. +/**
  66861. + * Set value of prtpwr field from the HPRT0 register
  66862. + */
  66863. +extern void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val);
  66864. +
  66865. +/**
  66866. + * Get value of prtsusp field from the HPRT0 regsiter
  66867. + */
  66868. +extern uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if);
  66869. +/**
  66870. + * Set value of prtpwr field from the HPRT0 register
  66871. + */
  66872. +extern void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val);
  66873. +
  66874. +/**
  66875. + * Get value of ModeChTimEn field from the HCFG regsiter
  66876. + */
  66877. +extern uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if);
  66878. +/**
  66879. + * Set value of ModeChTimEn field from the HCFG regsiter
  66880. + */
  66881. +extern void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val);
  66882. +
  66883. +/**
  66884. + * Get value of Fram Interval field from the HFIR regsiter
  66885. + */
  66886. +extern uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if);
  66887. +/**
  66888. + * Set value of Frame Interval field from the HFIR regsiter
  66889. + */
  66890. +extern void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val);
  66891. +
  66892. +/**
  66893. + * Set value of prtres field from the HPRT0 register
  66894. + *FIXME Remove?
  66895. + */
  66896. +extern void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val);
  66897. +
  66898. +/**
  66899. + * Get value of rmtwkupsig bit in DCTL register
  66900. + */
  66901. +extern uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if);
  66902. +
  66903. +/**
  66904. + * Get value of prt_sleep_sts field from the GLPMCFG register
  66905. + */
  66906. +extern uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if);
  66907. +
  66908. +/**
  66909. + * Get value of rem_wkup_en field from the GLPMCFG register
  66910. + */
  66911. +extern uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if);
  66912. +
  66913. +/**
  66914. + * Get value of appl_resp field from the GLPMCFG register
  66915. + */
  66916. +extern uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if);
  66917. +/**
  66918. + * Set value of appl_resp field from the GLPMCFG register
  66919. + */
  66920. +extern void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val);
  66921. +
  66922. +/**
  66923. + * Get value of hsic_connect field from the GLPMCFG register
  66924. + */
  66925. +extern uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if);
  66926. +/**
  66927. + * Set value of hsic_connect field from the GLPMCFG register
  66928. + */
  66929. +extern void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val);
  66930. +
  66931. +/**
  66932. + * Get value of inv_sel_hsic field from the GLPMCFG register.
  66933. + */
  66934. +extern uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if);
  66935. +/**
  66936. + * Set value of inv_sel_hsic field from the GLPMFG register.
  66937. + */
  66938. +extern void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val);
  66939. +
  66940. +/*
  66941. + * Some functions for accessing registers
  66942. + */
  66943. +
  66944. +/**
  66945. + * GOTGCTL register
  66946. + */
  66947. +extern uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if);
  66948. +extern void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val);
  66949. +
  66950. +/**
  66951. + * GUSBCFG register
  66952. + */
  66953. +extern uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if);
  66954. +extern void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val);
  66955. +
  66956. +/**
  66957. + * GRXFSIZ register
  66958. + */
  66959. +extern uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if);
  66960. +extern void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  66961. +
  66962. +/**
  66963. + * GNPTXFSIZ register
  66964. + */
  66965. +extern uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if);
  66966. +extern void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  66967. +
  66968. +extern uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if);
  66969. +extern void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val);
  66970. +
  66971. +/**
  66972. + * GGPIO register
  66973. + */
  66974. +extern uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if);
  66975. +extern void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val);
  66976. +
  66977. +/**
  66978. + * GUID register
  66979. + */
  66980. +extern uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if);
  66981. +extern void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val);
  66982. +
  66983. +/**
  66984. + * HPRT0 register
  66985. + */
  66986. +extern uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if);
  66987. +extern void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val);
  66988. +
  66989. +/**
  66990. + * GHPTXFSIZE
  66991. + */
  66992. +extern uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if);
  66993. +
  66994. +/** @} */
  66995. +
  66996. +#endif /* __DWC_CORE_IF_H__ */
  66997. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_dbg.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h
  66998. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 1970-01-01 01:00:00.000000000 +0100
  66999. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 2014-04-24 16:04:39.815124215 +0200
  67000. @@ -0,0 +1,117 @@
  67001. +/* ==========================================================================
  67002. + *
  67003. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67004. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67005. + * otherwise expressly agreed to in writing between Synopsys and you.
  67006. + *
  67007. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67008. + * any End User Software License Agreement or Agreement for Licensed Product
  67009. + * with Synopsys or any supplement thereto. You are permitted to use and
  67010. + * redistribute this Software in source and binary forms, with or without
  67011. + * modification, provided that redistributions of source code must retain this
  67012. + * notice. You may not view, use, disclose, copy or distribute this file or
  67013. + * any information contained herein except pursuant to this license grant from
  67014. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67015. + * below, then you are not authorized to use the Software.
  67016. + *
  67017. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67018. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67019. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67020. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67021. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67022. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67023. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67024. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67025. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67026. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67027. + * DAMAGE.
  67028. + * ========================================================================== */
  67029. +
  67030. +#ifndef __DWC_OTG_DBG_H__
  67031. +#define __DWC_OTG_DBG_H__
  67032. +
  67033. +/** @file
  67034. + * This file defines debug levels.
  67035. + * Debugging support vanishes in non-debug builds.
  67036. + */
  67037. +
  67038. +/**
  67039. + * The Debug Level bit-mask variable.
  67040. + */
  67041. +extern uint32_t g_dbg_lvl;
  67042. +/**
  67043. + * Set the Debug Level variable.
  67044. + */
  67045. +static inline uint32_t SET_DEBUG_LEVEL(const uint32_t new)
  67046. +{
  67047. + uint32_t old = g_dbg_lvl;
  67048. + g_dbg_lvl = new;
  67049. + return old;
  67050. +}
  67051. +
  67052. +#define DBG_USER (0x1)
  67053. +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
  67054. +#define DBG_CIL (0x2)
  67055. +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
  67056. + * messages */
  67057. +#define DBG_CILV (0x20)
  67058. +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
  67059. + * messages */
  67060. +#define DBG_PCD (0x4)
  67061. +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
  67062. + * messages */
  67063. +#define DBG_PCDV (0x40)
  67064. +/** When debug level has the DBG_HCD bit set, display Host debug messages */
  67065. +#define DBG_HCD (0x8)
  67066. +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
  67067. + * messages */
  67068. +#define DBG_HCDV (0x80)
  67069. +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
  67070. + * mode. */
  67071. +#define DBG_HCD_URB (0x800)
  67072. +/** When debug level has the DBG_HCDI bit set, display host interrupt
  67073. + * messages. */
  67074. +#define DBG_HCDI (0x1000)
  67075. +
  67076. +/** When debug level has any bit set, display debug messages */
  67077. +#define DBG_ANY (0xFF)
  67078. +
  67079. +/** All debug messages off */
  67080. +#define DBG_OFF 0
  67081. +
  67082. +/** Prefix string for DWC_DEBUG print macros. */
  67083. +#define USB_DWC "DWC_otg: "
  67084. +
  67085. +/**
  67086. + * Print a debug message when the Global debug level variable contains
  67087. + * the bit defined in <code>lvl</code>.
  67088. + *
  67089. + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
  67090. + * @param[in] x - like printf
  67091. + *
  67092. + * Example:<p>
  67093. + * <code>
  67094. + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
  67095. + * </code>
  67096. + * <br>
  67097. + * results in:<br>
  67098. + * <code>
  67099. + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
  67100. + * </code>
  67101. + */
  67102. +#ifdef DEBUG
  67103. +
  67104. +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)__DWC_DEBUG(USB_DWC x ); }while(0)
  67105. +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
  67106. +
  67107. +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
  67108. +
  67109. +#else
  67110. +
  67111. +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
  67112. +# define DWC_DEBUGP(x...)
  67113. +
  67114. +# define CHK_DEBUG_LEVEL(level) (0)
  67115. +
  67116. +#endif /*DEBUG*/
  67117. +#endif
  67118. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_driver.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  67119. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_driver.c 1970-01-01 01:00:00.000000000 +0100
  67120. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c 2014-04-24 16:04:39.815124215 +0200
  67121. @@ -0,0 +1,1749 @@
  67122. +/* ==========================================================================
  67123. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
  67124. + * $Revision: #92 $
  67125. + * $Date: 2012/08/10 $
  67126. + * $Change: 2047372 $
  67127. + *
  67128. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67129. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67130. + * otherwise expressly agreed to in writing between Synopsys and you.
  67131. + *
  67132. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67133. + * any End User Software License Agreement or Agreement for Licensed Product
  67134. + * with Synopsys or any supplement thereto. You are permitted to use and
  67135. + * redistribute this Software in source and binary forms, with or without
  67136. + * modification, provided that redistributions of source code must retain this
  67137. + * notice. You may not view, use, disclose, copy or distribute this file or
  67138. + * any information contained herein except pursuant to this license grant from
  67139. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67140. + * below, then you are not authorized to use the Software.
  67141. + *
  67142. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67143. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67144. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67145. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67146. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67147. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67148. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67149. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67150. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67151. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67152. + * DAMAGE.
  67153. + * ========================================================================== */
  67154. +
  67155. +/** @file
  67156. + * The dwc_otg_driver module provides the initialization and cleanup entry
  67157. + * points for the DWC_otg driver. This module will be dynamically installed
  67158. + * after Linux is booted using the insmod command. When the module is
  67159. + * installed, the dwc_otg_driver_init function is called. When the module is
  67160. + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
  67161. + *
  67162. + * This module also defines a data structure for the dwc_otg_driver, which is
  67163. + * used in conjunction with the standard ARM lm_device structure. These
  67164. + * structures allow the OTG driver to comply with the standard Linux driver
  67165. + * model in which devices and drivers are registered with a bus driver. This
  67166. + * has the benefit that Linux can expose attributes of the driver and device
  67167. + * in its special sysfs file system. Users can then read or write files in
  67168. + * this file system to perform diagnostics on the driver components or the
  67169. + * device.
  67170. + */
  67171. +
  67172. +#include "dwc_otg_os_dep.h"
  67173. +#include "dwc_os.h"
  67174. +#include "dwc_otg_dbg.h"
  67175. +#include "dwc_otg_driver.h"
  67176. +#include "dwc_otg_attr.h"
  67177. +#include "dwc_otg_core_if.h"
  67178. +#include "dwc_otg_pcd_if.h"
  67179. +#include "dwc_otg_hcd_if.h"
  67180. +#include "dwc_otg_fiq_fsm.h"
  67181. +
  67182. +#define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  67183. +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  67184. +
  67185. +bool microframe_schedule=true;
  67186. +
  67187. +static const char dwc_driver_name[] = "dwc_otg";
  67188. +
  67189. +
  67190. +extern int pcd_init(
  67191. +#ifdef LM_INTERFACE
  67192. + struct lm_device *_dev
  67193. +#elif defined(PCI_INTERFACE)
  67194. + struct pci_dev *_dev
  67195. +#elif defined(PLATFORM_INTERFACE)
  67196. + struct platform_device *dev
  67197. +#endif
  67198. + );
  67199. +extern int hcd_init(
  67200. +#ifdef LM_INTERFACE
  67201. + struct lm_device *_dev
  67202. +#elif defined(PCI_INTERFACE)
  67203. + struct pci_dev *_dev
  67204. +#elif defined(PLATFORM_INTERFACE)
  67205. + struct platform_device *dev
  67206. +#endif
  67207. + );
  67208. +
  67209. +extern int pcd_remove(
  67210. +#ifdef LM_INTERFACE
  67211. + struct lm_device *_dev
  67212. +#elif defined(PCI_INTERFACE)
  67213. + struct pci_dev *_dev
  67214. +#elif defined(PLATFORM_INTERFACE)
  67215. + struct platform_device *_dev
  67216. +#endif
  67217. + );
  67218. +
  67219. +extern void hcd_remove(
  67220. +#ifdef LM_INTERFACE
  67221. + struct lm_device *_dev
  67222. +#elif defined(PCI_INTERFACE)
  67223. + struct pci_dev *_dev
  67224. +#elif defined(PLATFORM_INTERFACE)
  67225. + struct platform_device *_dev
  67226. +#endif
  67227. + );
  67228. +
  67229. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  67230. +
  67231. +/*-------------------------------------------------------------------------*/
  67232. +/* Encapsulate the module parameter settings */
  67233. +
  67234. +struct dwc_otg_driver_module_params {
  67235. + int32_t opt;
  67236. + int32_t otg_cap;
  67237. + int32_t dma_enable;
  67238. + int32_t dma_desc_enable;
  67239. + int32_t dma_burst_size;
  67240. + int32_t speed;
  67241. + int32_t host_support_fs_ls_low_power;
  67242. + int32_t host_ls_low_power_phy_clk;
  67243. + int32_t enable_dynamic_fifo;
  67244. + int32_t data_fifo_size;
  67245. + int32_t dev_rx_fifo_size;
  67246. + int32_t dev_nperio_tx_fifo_size;
  67247. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  67248. + int32_t host_rx_fifo_size;
  67249. + int32_t host_nperio_tx_fifo_size;
  67250. + int32_t host_perio_tx_fifo_size;
  67251. + int32_t max_transfer_size;
  67252. + int32_t max_packet_count;
  67253. + int32_t host_channels;
  67254. + int32_t dev_endpoints;
  67255. + int32_t phy_type;
  67256. + int32_t phy_utmi_width;
  67257. + int32_t phy_ulpi_ddr;
  67258. + int32_t phy_ulpi_ext_vbus;
  67259. + int32_t i2c_enable;
  67260. + int32_t ulpi_fs_ls;
  67261. + int32_t ts_dline;
  67262. + int32_t en_multiple_tx_fifo;
  67263. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  67264. + uint32_t thr_ctl;
  67265. + uint32_t tx_thr_length;
  67266. + uint32_t rx_thr_length;
  67267. + int32_t pti_enable;
  67268. + int32_t mpi_enable;
  67269. + int32_t lpm_enable;
  67270. + int32_t ic_usb_cap;
  67271. + int32_t ahb_thr_ratio;
  67272. + int32_t power_down;
  67273. + int32_t reload_ctl;
  67274. + int32_t dev_out_nak;
  67275. + int32_t cont_on_bna;
  67276. + int32_t ahb_single;
  67277. + int32_t otg_ver;
  67278. + int32_t adp_enable;
  67279. +};
  67280. +
  67281. +static struct dwc_otg_driver_module_params dwc_otg_module_params = {
  67282. + .opt = -1,
  67283. + .otg_cap = -1,
  67284. + .dma_enable = -1,
  67285. + .dma_desc_enable = -1,
  67286. + .dma_burst_size = -1,
  67287. + .speed = -1,
  67288. + .host_support_fs_ls_low_power = -1,
  67289. + .host_ls_low_power_phy_clk = -1,
  67290. + .enable_dynamic_fifo = -1,
  67291. + .data_fifo_size = -1,
  67292. + .dev_rx_fifo_size = -1,
  67293. + .dev_nperio_tx_fifo_size = -1,
  67294. + .dev_perio_tx_fifo_size = {
  67295. + /* dev_perio_tx_fifo_size_1 */
  67296. + -1,
  67297. + -1,
  67298. + -1,
  67299. + -1,
  67300. + -1,
  67301. + -1,
  67302. + -1,
  67303. + -1,
  67304. + -1,
  67305. + -1,
  67306. + -1,
  67307. + -1,
  67308. + -1,
  67309. + -1,
  67310. + -1
  67311. + /* 15 */
  67312. + },
  67313. + .host_rx_fifo_size = -1,
  67314. + .host_nperio_tx_fifo_size = -1,
  67315. + .host_perio_tx_fifo_size = -1,
  67316. + .max_transfer_size = -1,
  67317. + .max_packet_count = -1,
  67318. + .host_channels = -1,
  67319. + .dev_endpoints = -1,
  67320. + .phy_type = -1,
  67321. + .phy_utmi_width = -1,
  67322. + .phy_ulpi_ddr = -1,
  67323. + .phy_ulpi_ext_vbus = -1,
  67324. + .i2c_enable = -1,
  67325. + .ulpi_fs_ls = -1,
  67326. + .ts_dline = -1,
  67327. + .en_multiple_tx_fifo = -1,
  67328. + .dev_tx_fifo_size = {
  67329. + /* dev_tx_fifo_size */
  67330. + -1,
  67331. + -1,
  67332. + -1,
  67333. + -1,
  67334. + -1,
  67335. + -1,
  67336. + -1,
  67337. + -1,
  67338. + -1,
  67339. + -1,
  67340. + -1,
  67341. + -1,
  67342. + -1,
  67343. + -1,
  67344. + -1
  67345. + /* 15 */
  67346. + },
  67347. + .thr_ctl = -1,
  67348. + .tx_thr_length = -1,
  67349. + .rx_thr_length = -1,
  67350. + .pti_enable = -1,
  67351. + .mpi_enable = -1,
  67352. + .lpm_enable = 0,
  67353. + .ic_usb_cap = -1,
  67354. + .ahb_thr_ratio = -1,
  67355. + .power_down = -1,
  67356. + .reload_ctl = -1,
  67357. + .dev_out_nak = -1,
  67358. + .cont_on_bna = -1,
  67359. + .ahb_single = -1,
  67360. + .otg_ver = -1,
  67361. + .adp_enable = -1,
  67362. +};
  67363. +
  67364. +//Global variable to switch the fiq fix on or off
  67365. +bool fiq_enable = 1;
  67366. +// Global variable to enable the split transaction fix
  67367. +bool fiq_fsm_enable = false;
  67368. +//Bulk split-transaction NAK holdoff in microframes
  67369. +uint16_t nak_holdoff = 8;
  67370. +
  67371. +unsigned short fiq_fsm_mask = 0x01;
  67372. +
  67373. +/**
  67374. + * This function shows the Driver Version.
  67375. + */
  67376. +static ssize_t version_show(struct device_driver *dev, char *buf)
  67377. +{
  67378. + return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
  67379. + DWC_DRIVER_VERSION);
  67380. +}
  67381. +
  67382. +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
  67383. +
  67384. +/**
  67385. + * Global Debug Level Mask.
  67386. + */
  67387. +uint32_t g_dbg_lvl = 0; /* OFF */
  67388. +
  67389. +/**
  67390. + * This function shows the driver Debug Level.
  67391. + */
  67392. +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
  67393. +{
  67394. + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
  67395. +}
  67396. +
  67397. +/**
  67398. + * This function stores the driver Debug Level.
  67399. + */
  67400. +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
  67401. + size_t count)
  67402. +{
  67403. + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
  67404. + return count;
  67405. +}
  67406. +
  67407. +static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
  67408. + dbg_level_store);
  67409. +
  67410. +/**
  67411. + * This function is called during module intialization
  67412. + * to pass module parameters to the DWC_OTG CORE.
  67413. + */
  67414. +static int set_parameters(dwc_otg_core_if_t * core_if)
  67415. +{
  67416. + int retval = 0;
  67417. + int i;
  67418. +
  67419. + if (dwc_otg_module_params.otg_cap != -1) {
  67420. + retval +=
  67421. + dwc_otg_set_param_otg_cap(core_if,
  67422. + dwc_otg_module_params.otg_cap);
  67423. + }
  67424. + if (dwc_otg_module_params.dma_enable != -1) {
  67425. + retval +=
  67426. + dwc_otg_set_param_dma_enable(core_if,
  67427. + dwc_otg_module_params.
  67428. + dma_enable);
  67429. + }
  67430. + if (dwc_otg_module_params.dma_desc_enable != -1) {
  67431. + retval +=
  67432. + dwc_otg_set_param_dma_desc_enable(core_if,
  67433. + dwc_otg_module_params.
  67434. + dma_desc_enable);
  67435. + }
  67436. + if (dwc_otg_module_params.opt != -1) {
  67437. + retval +=
  67438. + dwc_otg_set_param_opt(core_if, dwc_otg_module_params.opt);
  67439. + }
  67440. + if (dwc_otg_module_params.dma_burst_size != -1) {
  67441. + retval +=
  67442. + dwc_otg_set_param_dma_burst_size(core_if,
  67443. + dwc_otg_module_params.
  67444. + dma_burst_size);
  67445. + }
  67446. + if (dwc_otg_module_params.host_support_fs_ls_low_power != -1) {
  67447. + retval +=
  67448. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  67449. + dwc_otg_module_params.
  67450. + host_support_fs_ls_low_power);
  67451. + }
  67452. + if (dwc_otg_module_params.enable_dynamic_fifo != -1) {
  67453. + retval +=
  67454. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  67455. + dwc_otg_module_params.
  67456. + enable_dynamic_fifo);
  67457. + }
  67458. + if (dwc_otg_module_params.data_fifo_size != -1) {
  67459. + retval +=
  67460. + dwc_otg_set_param_data_fifo_size(core_if,
  67461. + dwc_otg_module_params.
  67462. + data_fifo_size);
  67463. + }
  67464. + if (dwc_otg_module_params.dev_rx_fifo_size != -1) {
  67465. + retval +=
  67466. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  67467. + dwc_otg_module_params.
  67468. + dev_rx_fifo_size);
  67469. + }
  67470. + if (dwc_otg_module_params.dev_nperio_tx_fifo_size != -1) {
  67471. + retval +=
  67472. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  67473. + dwc_otg_module_params.
  67474. + dev_nperio_tx_fifo_size);
  67475. + }
  67476. + if (dwc_otg_module_params.host_rx_fifo_size != -1) {
  67477. + retval +=
  67478. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  67479. + dwc_otg_module_params.host_rx_fifo_size);
  67480. + }
  67481. + if (dwc_otg_module_params.host_nperio_tx_fifo_size != -1) {
  67482. + retval +=
  67483. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  67484. + dwc_otg_module_params.
  67485. + host_nperio_tx_fifo_size);
  67486. + }
  67487. + if (dwc_otg_module_params.host_perio_tx_fifo_size != -1) {
  67488. + retval +=
  67489. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  67490. + dwc_otg_module_params.
  67491. + host_perio_tx_fifo_size);
  67492. + }
  67493. + if (dwc_otg_module_params.max_transfer_size != -1) {
  67494. + retval +=
  67495. + dwc_otg_set_param_max_transfer_size(core_if,
  67496. + dwc_otg_module_params.
  67497. + max_transfer_size);
  67498. + }
  67499. + if (dwc_otg_module_params.max_packet_count != -1) {
  67500. + retval +=
  67501. + dwc_otg_set_param_max_packet_count(core_if,
  67502. + dwc_otg_module_params.
  67503. + max_packet_count);
  67504. + }
  67505. + if (dwc_otg_module_params.host_channels != -1) {
  67506. + retval +=
  67507. + dwc_otg_set_param_host_channels(core_if,
  67508. + dwc_otg_module_params.
  67509. + host_channels);
  67510. + }
  67511. + if (dwc_otg_module_params.dev_endpoints != -1) {
  67512. + retval +=
  67513. + dwc_otg_set_param_dev_endpoints(core_if,
  67514. + dwc_otg_module_params.
  67515. + dev_endpoints);
  67516. + }
  67517. + if (dwc_otg_module_params.phy_type != -1) {
  67518. + retval +=
  67519. + dwc_otg_set_param_phy_type(core_if,
  67520. + dwc_otg_module_params.phy_type);
  67521. + }
  67522. + if (dwc_otg_module_params.speed != -1) {
  67523. + retval +=
  67524. + dwc_otg_set_param_speed(core_if,
  67525. + dwc_otg_module_params.speed);
  67526. + }
  67527. + if (dwc_otg_module_params.host_ls_low_power_phy_clk != -1) {
  67528. + retval +=
  67529. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  67530. + dwc_otg_module_params.
  67531. + host_ls_low_power_phy_clk);
  67532. + }
  67533. + if (dwc_otg_module_params.phy_ulpi_ddr != -1) {
  67534. + retval +=
  67535. + dwc_otg_set_param_phy_ulpi_ddr(core_if,
  67536. + dwc_otg_module_params.
  67537. + phy_ulpi_ddr);
  67538. + }
  67539. + if (dwc_otg_module_params.phy_ulpi_ext_vbus != -1) {
  67540. + retval +=
  67541. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  67542. + dwc_otg_module_params.
  67543. + phy_ulpi_ext_vbus);
  67544. + }
  67545. + if (dwc_otg_module_params.phy_utmi_width != -1) {
  67546. + retval +=
  67547. + dwc_otg_set_param_phy_utmi_width(core_if,
  67548. + dwc_otg_module_params.
  67549. + phy_utmi_width);
  67550. + }
  67551. + if (dwc_otg_module_params.ulpi_fs_ls != -1) {
  67552. + retval +=
  67553. + dwc_otg_set_param_ulpi_fs_ls(core_if,
  67554. + dwc_otg_module_params.ulpi_fs_ls);
  67555. + }
  67556. + if (dwc_otg_module_params.ts_dline != -1) {
  67557. + retval +=
  67558. + dwc_otg_set_param_ts_dline(core_if,
  67559. + dwc_otg_module_params.ts_dline);
  67560. + }
  67561. + if (dwc_otg_module_params.i2c_enable != -1) {
  67562. + retval +=
  67563. + dwc_otg_set_param_i2c_enable(core_if,
  67564. + dwc_otg_module_params.
  67565. + i2c_enable);
  67566. + }
  67567. + if (dwc_otg_module_params.en_multiple_tx_fifo != -1) {
  67568. + retval +=
  67569. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  67570. + dwc_otg_module_params.
  67571. + en_multiple_tx_fifo);
  67572. + }
  67573. + for (i = 0; i < 15; i++) {
  67574. + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
  67575. + retval +=
  67576. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  67577. + dwc_otg_module_params.
  67578. + dev_perio_tx_fifo_size
  67579. + [i], i);
  67580. + }
  67581. + }
  67582. +
  67583. + for (i = 0; i < 15; i++) {
  67584. + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
  67585. + retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
  67586. + dwc_otg_module_params.
  67587. + dev_tx_fifo_size
  67588. + [i], i);
  67589. + }
  67590. + }
  67591. + if (dwc_otg_module_params.thr_ctl != -1) {
  67592. + retval +=
  67593. + dwc_otg_set_param_thr_ctl(core_if,
  67594. + dwc_otg_module_params.thr_ctl);
  67595. + }
  67596. + if (dwc_otg_module_params.mpi_enable != -1) {
  67597. + retval +=
  67598. + dwc_otg_set_param_mpi_enable(core_if,
  67599. + dwc_otg_module_params.
  67600. + mpi_enable);
  67601. + }
  67602. + if (dwc_otg_module_params.pti_enable != -1) {
  67603. + retval +=
  67604. + dwc_otg_set_param_pti_enable(core_if,
  67605. + dwc_otg_module_params.
  67606. + pti_enable);
  67607. + }
  67608. + if (dwc_otg_module_params.lpm_enable != -1) {
  67609. + retval +=
  67610. + dwc_otg_set_param_lpm_enable(core_if,
  67611. + dwc_otg_module_params.
  67612. + lpm_enable);
  67613. + }
  67614. + if (dwc_otg_module_params.ic_usb_cap != -1) {
  67615. + retval +=
  67616. + dwc_otg_set_param_ic_usb_cap(core_if,
  67617. + dwc_otg_module_params.
  67618. + ic_usb_cap);
  67619. + }
  67620. + if (dwc_otg_module_params.tx_thr_length != -1) {
  67621. + retval +=
  67622. + dwc_otg_set_param_tx_thr_length(core_if,
  67623. + dwc_otg_module_params.tx_thr_length);
  67624. + }
  67625. + if (dwc_otg_module_params.rx_thr_length != -1) {
  67626. + retval +=
  67627. + dwc_otg_set_param_rx_thr_length(core_if,
  67628. + dwc_otg_module_params.
  67629. + rx_thr_length);
  67630. + }
  67631. + if (dwc_otg_module_params.ahb_thr_ratio != -1) {
  67632. + retval +=
  67633. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  67634. + dwc_otg_module_params.ahb_thr_ratio);
  67635. + }
  67636. + if (dwc_otg_module_params.power_down != -1) {
  67637. + retval +=
  67638. + dwc_otg_set_param_power_down(core_if,
  67639. + dwc_otg_module_params.power_down);
  67640. + }
  67641. + if (dwc_otg_module_params.reload_ctl != -1) {
  67642. + retval +=
  67643. + dwc_otg_set_param_reload_ctl(core_if,
  67644. + dwc_otg_module_params.reload_ctl);
  67645. + }
  67646. +
  67647. + if (dwc_otg_module_params.dev_out_nak != -1) {
  67648. + retval +=
  67649. + dwc_otg_set_param_dev_out_nak(core_if,
  67650. + dwc_otg_module_params.dev_out_nak);
  67651. + }
  67652. +
  67653. + if (dwc_otg_module_params.cont_on_bna != -1) {
  67654. + retval +=
  67655. + dwc_otg_set_param_cont_on_bna(core_if,
  67656. + dwc_otg_module_params.cont_on_bna);
  67657. + }
  67658. +
  67659. + if (dwc_otg_module_params.ahb_single != -1) {
  67660. + retval +=
  67661. + dwc_otg_set_param_ahb_single(core_if,
  67662. + dwc_otg_module_params.ahb_single);
  67663. + }
  67664. +
  67665. + if (dwc_otg_module_params.otg_ver != -1) {
  67666. + retval +=
  67667. + dwc_otg_set_param_otg_ver(core_if,
  67668. + dwc_otg_module_params.otg_ver);
  67669. + }
  67670. + if (dwc_otg_module_params.adp_enable != -1) {
  67671. + retval +=
  67672. + dwc_otg_set_param_adp_enable(core_if,
  67673. + dwc_otg_module_params.
  67674. + adp_enable);
  67675. + }
  67676. + return retval;
  67677. +}
  67678. +
  67679. +/**
  67680. + * This function is the top level interrupt handler for the Common
  67681. + * (Device and host modes) interrupts.
  67682. + */
  67683. +static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
  67684. +{
  67685. + int32_t retval = IRQ_NONE;
  67686. +
  67687. + retval = dwc_otg_handle_common_intr(dev);
  67688. + if (retval != 0) {
  67689. + S3C2410X_CLEAR_EINTPEND();
  67690. + }
  67691. + return IRQ_RETVAL(retval);
  67692. +}
  67693. +
  67694. +/**
  67695. + * This function is called when a lm_device is unregistered with the
  67696. + * dwc_otg_driver. This happens, for example, when the rmmod command is
  67697. + * executed. The device may or may not be electrically present. If it is
  67698. + * present, the driver stops device processing. Any resources used on behalf
  67699. + * of this device are freed.
  67700. + *
  67701. + * @param _dev
  67702. + */
  67703. +#ifdef LM_INTERFACE
  67704. +#define REM_RETVAL(n)
  67705. +static void dwc_otg_driver_remove( struct lm_device *_dev )
  67706. +{ dwc_otg_device_t *otg_dev = lm_get_drvdata(_dev);
  67707. +#elif defined(PCI_INTERFACE)
  67708. +#define REM_RETVAL(n)
  67709. +static void dwc_otg_driver_remove( struct pci_dev *_dev )
  67710. +{ dwc_otg_device_t *otg_dev = pci_get_drvdata(_dev);
  67711. +#elif defined(PLATFORM_INTERFACE)
  67712. +#define REM_RETVAL(n) n
  67713. +static int dwc_otg_driver_remove( struct platform_device *_dev )
  67714. +{ dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
  67715. +#endif
  67716. +
  67717. + DWC_DEBUGPL(DBG_ANY, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  67718. +
  67719. + if (!otg_dev) {
  67720. + /* Memory allocation for the dwc_otg_device failed. */
  67721. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  67722. + return REM_RETVAL(-ENOMEM);
  67723. + }
  67724. +#ifndef DWC_DEVICE_ONLY
  67725. + if (otg_dev->hcd) {
  67726. + hcd_remove(_dev);
  67727. + } else {
  67728. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  67729. + return REM_RETVAL(-EINVAL);
  67730. + }
  67731. +#endif
  67732. +
  67733. +#ifndef DWC_HOST_ONLY
  67734. + if (otg_dev->pcd) {
  67735. + pcd_remove(_dev);
  67736. + } else {
  67737. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
  67738. + return REM_RETVAL(-EINVAL);
  67739. + }
  67740. +#endif
  67741. + /*
  67742. + * Free the IRQ
  67743. + */
  67744. + if (otg_dev->common_irq_installed) {
  67745. +#ifdef PLATFORM_INTERFACE
  67746. + free_irq(platform_get_irq(_dev, 0), otg_dev);
  67747. +#else
  67748. + free_irq(_dev->irq, otg_dev);
  67749. +#endif
  67750. + } else {
  67751. + DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
  67752. + return REM_RETVAL(-ENXIO);
  67753. + }
  67754. +
  67755. + if (otg_dev->core_if) {
  67756. + dwc_otg_cil_remove(otg_dev->core_if);
  67757. + } else {
  67758. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
  67759. + return REM_RETVAL(-ENXIO);
  67760. + }
  67761. +
  67762. + /*
  67763. + * Remove the device attributes
  67764. + */
  67765. + dwc_otg_attr_remove(_dev);
  67766. +
  67767. + /*
  67768. + * Return the memory.
  67769. + */
  67770. + if (otg_dev->os_dep.base) {
  67771. + iounmap(otg_dev->os_dep.base);
  67772. + }
  67773. + DWC_FREE(otg_dev);
  67774. +
  67775. + /*
  67776. + * Clear the drvdata pointer.
  67777. + */
  67778. +#ifdef LM_INTERFACE
  67779. + lm_set_drvdata(_dev, 0);
  67780. +#elif defined(PCI_INTERFACE)
  67781. + release_mem_region(otg_dev->os_dep.rsrc_start,
  67782. + otg_dev->os_dep.rsrc_len);
  67783. + pci_set_drvdata(_dev, 0);
  67784. +#elif defined(PLATFORM_INTERFACE)
  67785. + platform_set_drvdata(_dev, 0);
  67786. +#endif
  67787. + return REM_RETVAL(0);
  67788. +}
  67789. +
  67790. +/**
  67791. + * This function is called when an lm_device is bound to a
  67792. + * dwc_otg_driver. It creates the driver components required to
  67793. + * control the device (CIL, HCD, and PCD) and it initializes the
  67794. + * device. The driver components are stored in a dwc_otg_device
  67795. + * structure. A reference to the dwc_otg_device is saved in the
  67796. + * lm_device. This allows the driver to access the dwc_otg_device
  67797. + * structure on subsequent calls to driver methods for this device.
  67798. + *
  67799. + * @param _dev Bus device
  67800. + */
  67801. +static int dwc_otg_driver_probe(
  67802. +#ifdef LM_INTERFACE
  67803. + struct lm_device *_dev
  67804. +#elif defined(PCI_INTERFACE)
  67805. + struct pci_dev *_dev,
  67806. + const struct pci_device_id *id
  67807. +#elif defined(PLATFORM_INTERFACE)
  67808. + struct platform_device *_dev
  67809. +#endif
  67810. + )
  67811. +{
  67812. + int retval = 0;
  67813. + dwc_otg_device_t *dwc_otg_device;
  67814. + int devirq;
  67815. +
  67816. + dev_dbg(&_dev->dev, "dwc_otg_driver_probe(%p)\n", _dev);
  67817. +#ifdef LM_INTERFACE
  67818. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)_dev->resource.start);
  67819. +#elif defined(PCI_INTERFACE)
  67820. + if (!id) {
  67821. + DWC_ERROR("Invalid pci_device_id %p", id);
  67822. + return -EINVAL;
  67823. + }
  67824. +
  67825. + if (!_dev || (pci_enable_device(_dev) < 0)) {
  67826. + DWC_ERROR("Invalid pci_device %p", _dev);
  67827. + return -ENODEV;
  67828. + }
  67829. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)pci_resource_start(_dev,0));
  67830. + /* other stuff needed as well? */
  67831. +
  67832. +#elif defined(PLATFORM_INTERFACE)
  67833. + dev_dbg(&_dev->dev, "start=0x%08x (len 0x%x)\n",
  67834. + (unsigned)_dev->resource->start,
  67835. + (unsigned)(_dev->resource->end - _dev->resource->start));
  67836. +#endif
  67837. +
  67838. + dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
  67839. +
  67840. + if (!dwc_otg_device) {
  67841. + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
  67842. + return -ENOMEM;
  67843. + }
  67844. +
  67845. + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
  67846. + dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
  67847. +
  67848. + /*
  67849. + * Map the DWC_otg Core memory into virtual address space.
  67850. + */
  67851. +#ifdef LM_INTERFACE
  67852. + dwc_otg_device->os_dep.base = ioremap(_dev->resource.start, SZ_256K);
  67853. +
  67854. + if (!dwc_otg_device->os_dep.base) {
  67855. + dev_err(&_dev->dev, "ioremap() failed\n");
  67856. + DWC_FREE(dwc_otg_device);
  67857. + return -ENOMEM;
  67858. + }
  67859. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  67860. + (unsigned)dwc_otg_device->os_dep.base);
  67861. +#elif defined(PCI_INTERFACE)
  67862. + _dev->current_state = PCI_D0;
  67863. + _dev->dev.power.power_state = PMSG_ON;
  67864. +
  67865. + if (!_dev->irq) {
  67866. + DWC_ERROR("Found HC with no IRQ. Check BIOS/PCI %s setup!",
  67867. + pci_name(_dev));
  67868. + iounmap(dwc_otg_device->os_dep.base);
  67869. + DWC_FREE(dwc_otg_device);
  67870. + return -ENODEV;
  67871. + }
  67872. +
  67873. + dwc_otg_device->os_dep.rsrc_start = pci_resource_start(_dev, 0);
  67874. + dwc_otg_device->os_dep.rsrc_len = pci_resource_len(_dev, 0);
  67875. + DWC_DEBUGPL(DBG_ANY, "PCI resource: start=%08x, len=%08x\n",
  67876. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  67877. + (unsigned)dwc_otg_device->os_dep.rsrc_len);
  67878. + if (!request_mem_region
  67879. + (dwc_otg_device->os_dep.rsrc_start, dwc_otg_device->os_dep.rsrc_len,
  67880. + "dwc_otg")) {
  67881. + dev_dbg(&_dev->dev, "error requesting memory\n");
  67882. + iounmap(dwc_otg_device->os_dep.base);
  67883. + DWC_FREE(dwc_otg_device);
  67884. + return -EFAULT;
  67885. + }
  67886. +
  67887. + dwc_otg_device->os_dep.base =
  67888. + ioremap_nocache(dwc_otg_device->os_dep.rsrc_start,
  67889. + dwc_otg_device->os_dep.rsrc_len);
  67890. + if (dwc_otg_device->os_dep.base == NULL) {
  67891. + dev_dbg(&_dev->dev, "error mapping memory\n");
  67892. + release_mem_region(dwc_otg_device->os_dep.rsrc_start,
  67893. + dwc_otg_device->os_dep.rsrc_len);
  67894. + iounmap(dwc_otg_device->os_dep.base);
  67895. + DWC_FREE(dwc_otg_device);
  67896. + return -EFAULT;
  67897. + }
  67898. + dev_dbg(&_dev->dev, "base=0x%p (before adjust) \n",
  67899. + dwc_otg_device->os_dep.base);
  67900. + dwc_otg_device->os_dep.base = (char *)dwc_otg_device->os_dep.base;
  67901. + dev_dbg(&_dev->dev, "base=0x%p (after adjust) \n",
  67902. + dwc_otg_device->os_dep.base);
  67903. + dev_dbg(&_dev->dev, "%s: mapped PA 0x%x to VA 0x%p\n", __func__,
  67904. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  67905. + dwc_otg_device->os_dep.base);
  67906. +
  67907. + pci_set_master(_dev);
  67908. + pci_set_drvdata(_dev, dwc_otg_device);
  67909. +#elif defined(PLATFORM_INTERFACE)
  67910. + DWC_DEBUGPL(DBG_ANY,"Platform resource: start=%08x, len=%08x\n",
  67911. + _dev->resource->start,
  67912. + _dev->resource->end - _dev->resource->start + 1);
  67913. +#if 1
  67914. + if (!request_mem_region(_dev->resource[0].start,
  67915. + _dev->resource[0].end - _dev->resource[0].start + 1,
  67916. + "dwc_otg")) {
  67917. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  67918. + retval = -EFAULT;
  67919. + goto fail;
  67920. + }
  67921. +
  67922. + dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  67923. + _dev->resource[0].end -
  67924. + _dev->resource[0].start+1);
  67925. + if (fiq_enable)
  67926. + {
  67927. + if (!request_mem_region(_dev->resource[1].start,
  67928. + _dev->resource[1].end - _dev->resource[1].start + 1,
  67929. + "dwc_otg")) {
  67930. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  67931. + retval = -EFAULT;
  67932. + goto fail;
  67933. + }
  67934. +
  67935. + dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  67936. + _dev->resource[1].end -
  67937. + _dev->resource[1].start + 1);
  67938. + }
  67939. +
  67940. +#else
  67941. + {
  67942. + struct map_desc desc = {
  67943. + .virtual = IO_ADDRESS((unsigned)_dev->resource->start),
  67944. + .pfn = __phys_to_pfn((unsigned)_dev->resource->start),
  67945. + .length = SZ_128K,
  67946. + .type = MT_DEVICE
  67947. + };
  67948. + iotable_init(&desc, 1);
  67949. + dwc_otg_device->os_dep.base = (void *)desc.virtual;
  67950. + }
  67951. +#endif
  67952. + if (!dwc_otg_device->os_dep.base) {
  67953. + dev_err(&_dev->dev, "ioremap() failed\n");
  67954. + retval = -ENOMEM;
  67955. + goto fail;
  67956. + }
  67957. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  67958. + (unsigned)dwc_otg_device->os_dep.base);
  67959. +#endif
  67960. +
  67961. + /*
  67962. + * Initialize driver data to point to the global DWC_otg
  67963. + * Device structure.
  67964. + */
  67965. +#ifdef LM_INTERFACE
  67966. + lm_set_drvdata(_dev, dwc_otg_device);
  67967. +#elif defined(PLATFORM_INTERFACE)
  67968. + platform_set_drvdata(_dev, dwc_otg_device);
  67969. +#endif
  67970. + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
  67971. +
  67972. + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
  67973. + DWC_DEBUGPL(DBG_HCDV, "probe of device %p given core_if %p\n",
  67974. + dwc_otg_device, dwc_otg_device->core_if);//GRAYG
  67975. +
  67976. + if (!dwc_otg_device->core_if) {
  67977. + dev_err(&_dev->dev, "CIL initialization failed!\n");
  67978. + retval = -ENOMEM;
  67979. + goto fail;
  67980. + }
  67981. +
  67982. + dev_dbg(&_dev->dev, "Calling get_gsnpsid\n");
  67983. + /*
  67984. + * Attempt to ensure this device is really a DWC_otg Controller.
  67985. + * Read and verify the SNPSID register contents. The value should be
  67986. + * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
  67987. + * as in "OTG version 2.XX" or "OTG version 3.XX".
  67988. + */
  67989. +
  67990. + if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) &&
  67991. + ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
  67992. + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
  67993. + dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
  67994. + retval = -EINVAL;
  67995. + goto fail;
  67996. + }
  67997. +
  67998. + /*
  67999. + * Validate parameter values.
  68000. + */
  68001. + dev_dbg(&_dev->dev, "Calling set_parameters\n");
  68002. + if (set_parameters(dwc_otg_device->core_if)) {
  68003. + retval = -EINVAL;
  68004. + goto fail;
  68005. + }
  68006. +
  68007. + /*
  68008. + * Create Device Attributes in sysfs
  68009. + */
  68010. + dev_dbg(&_dev->dev, "Calling attr_create\n");
  68011. + dwc_otg_attr_create(_dev);
  68012. +
  68013. + /*
  68014. + * Disable the global interrupt until all the interrupt
  68015. + * handlers are installed.
  68016. + */
  68017. + dev_dbg(&_dev->dev, "Calling disable_global_interrupts\n");
  68018. + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
  68019. +
  68020. + /*
  68021. + * Install the interrupt handler for the common interrupts before
  68022. + * enabling common interrupts in core_init below.
  68023. + */
  68024. +
  68025. +#if defined(PLATFORM_INTERFACE)
  68026. + devirq = platform_get_irq(_dev, 0);
  68027. +#else
  68028. + devirq = _dev->irq;
  68029. +#endif
  68030. + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  68031. + devirq);
  68032. + dev_dbg(&_dev->dev, "Calling request_irq(%d)\n", devirq);
  68033. + retval = request_irq(devirq, dwc_otg_common_irq,
  68034. + IRQF_SHARED,
  68035. + "dwc_otg", dwc_otg_device);
  68036. + if (retval) {
  68037. + DWC_ERROR("request of irq%d failed\n", devirq);
  68038. + retval = -EBUSY;
  68039. + goto fail;
  68040. + } else {
  68041. + dwc_otg_device->common_irq_installed = 1;
  68042. + }
  68043. +
  68044. +#ifndef IRQF_TRIGGER_LOW
  68045. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  68046. + dev_dbg(&_dev->dev, "Calling set_irq_type\n");
  68047. + set_irq_type(devirq,
  68048. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  68049. + IRQT_LOW
  68050. +#else
  68051. + IRQ_TYPE_LEVEL_LOW
  68052. +#endif
  68053. + );
  68054. +#endif
  68055. +#endif /*IRQF_TRIGGER_LOW*/
  68056. +
  68057. + /*
  68058. + * Initialize the DWC_otg core.
  68059. + */
  68060. + dev_dbg(&_dev->dev, "Calling dwc_otg_core_init\n");
  68061. + dwc_otg_core_init(dwc_otg_device->core_if);
  68062. +
  68063. +#ifndef DWC_HOST_ONLY
  68064. + /*
  68065. + * Initialize the PCD
  68066. + */
  68067. + dev_dbg(&_dev->dev, "Calling pcd_init\n");
  68068. + retval = pcd_init(_dev);
  68069. + if (retval != 0) {
  68070. + DWC_ERROR("pcd_init failed\n");
  68071. + dwc_otg_device->pcd = NULL;
  68072. + goto fail;
  68073. + }
  68074. +#endif
  68075. +#ifndef DWC_DEVICE_ONLY
  68076. + /*
  68077. + * Initialize the HCD
  68078. + */
  68079. + dev_dbg(&_dev->dev, "Calling hcd_init\n");
  68080. + retval = hcd_init(_dev);
  68081. + if (retval != 0) {
  68082. + DWC_ERROR("hcd_init failed\n");
  68083. + dwc_otg_device->hcd = NULL;
  68084. + goto fail;
  68085. + }
  68086. +#endif
  68087. + /* Recover from drvdata having been overwritten by hcd_init() */
  68088. +#ifdef LM_INTERFACE
  68089. + lm_set_drvdata(_dev, dwc_otg_device);
  68090. +#elif defined(PLATFORM_INTERFACE)
  68091. + platform_set_drvdata(_dev, dwc_otg_device);
  68092. +#elif defined(PCI_INTERFACE)
  68093. + pci_set_drvdata(_dev, dwc_otg_device);
  68094. + dwc_otg_device->os_dep.pcidev = _dev;
  68095. +#endif
  68096. +
  68097. + /*
  68098. + * Enable the global interrupt after all the interrupt
  68099. + * handlers are installed if there is no ADP support else
  68100. + * perform initial actions required for Internal ADP logic.
  68101. + */
  68102. + if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
  68103. + dev_dbg(&_dev->dev, "Calling enable_global_interrupts\n");
  68104. + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
  68105. + dev_dbg(&_dev->dev, "Done\n");
  68106. + } else
  68107. + dwc_otg_adp_start(dwc_otg_device->core_if,
  68108. + dwc_otg_is_host_mode(dwc_otg_device->core_if));
  68109. +
  68110. + return 0;
  68111. +
  68112. +fail:
  68113. + dwc_otg_driver_remove(_dev);
  68114. + return retval;
  68115. +}
  68116. +
  68117. +/**
  68118. + * This structure defines the methods to be called by a bus driver
  68119. + * during the lifecycle of a device on that bus. Both drivers and
  68120. + * devices are registered with a bus driver. The bus driver matches
  68121. + * devices to drivers based on information in the device and driver
  68122. + * structures.
  68123. + *
  68124. + * The probe function is called when the bus driver matches a device
  68125. + * to this driver. The remove function is called when a device is
  68126. + * unregistered with the bus driver.
  68127. + */
  68128. +#ifdef LM_INTERFACE
  68129. +static struct lm_driver dwc_otg_driver = {
  68130. + .drv = {.name = (char *)dwc_driver_name,},
  68131. + .probe = dwc_otg_driver_probe,
  68132. + .remove = dwc_otg_driver_remove,
  68133. + // 'suspend' and 'resume' absent
  68134. +};
  68135. +#elif defined(PCI_INTERFACE)
  68136. +static const struct pci_device_id pci_ids[] = { {
  68137. + PCI_DEVICE(0x16c3, 0xabcd),
  68138. + .driver_data =
  68139. + (unsigned long)0xdeadbeef,
  68140. + }, { /* end: all zeroes */ }
  68141. +};
  68142. +
  68143. +MODULE_DEVICE_TABLE(pci, pci_ids);
  68144. +
  68145. +/* pci driver glue; this is a "new style" PCI driver module */
  68146. +static struct pci_driver dwc_otg_driver = {
  68147. + .name = "dwc_otg",
  68148. + .id_table = pci_ids,
  68149. +
  68150. + .probe = dwc_otg_driver_probe,
  68151. + .remove = dwc_otg_driver_remove,
  68152. +
  68153. + .driver = {
  68154. + .name = (char *)dwc_driver_name,
  68155. + },
  68156. +};
  68157. +#elif defined(PLATFORM_INTERFACE)
  68158. +static struct platform_device_id platform_ids[] = {
  68159. + {
  68160. + .name = "bcm2708_usb",
  68161. + .driver_data = (kernel_ulong_t) 0xdeadbeef,
  68162. + },
  68163. + { /* end: all zeroes */ }
  68164. +};
  68165. +MODULE_DEVICE_TABLE(platform, platform_ids);
  68166. +
  68167. +static struct platform_driver dwc_otg_driver = {
  68168. + .driver = {
  68169. + .name = (char *)dwc_driver_name,
  68170. + },
  68171. + .id_table = platform_ids,
  68172. +
  68173. + .probe = dwc_otg_driver_probe,
  68174. + .remove = dwc_otg_driver_remove,
  68175. + // no 'shutdown', 'suspend', 'resume', 'suspend_late' or 'resume_early'
  68176. +};
  68177. +#endif
  68178. +
  68179. +/**
  68180. + * This function is called when the dwc_otg_driver is installed with the
  68181. + * insmod command. It registers the dwc_otg_driver structure with the
  68182. + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
  68183. + * to be called. In addition, the bus driver will automatically expose
  68184. + * attributes defined for the device and driver in the special sysfs file
  68185. + * system.
  68186. + *
  68187. + * @return
  68188. + */
  68189. +static int __init dwc_otg_driver_init(void)
  68190. +{
  68191. + int retval = 0;
  68192. + int error;
  68193. + struct device_driver *drv;
  68194. +
  68195. + if(fiq_fsm_enable && !fiq_enable) {
  68196. + printk(KERN_WARNING "dwc_otg: fiq_fsm_enable was set without fiq_enable! Correcting.\n");
  68197. + fiq_enable = 1;
  68198. + }
  68199. +
  68200. + printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  68201. + DWC_DRIVER_VERSION,
  68202. +#ifdef LM_INTERFACE
  68203. + "logicmodule");
  68204. + retval = lm_driver_register(&dwc_otg_driver);
  68205. + drv = &dwc_otg_driver.drv;
  68206. +#elif defined(PCI_INTERFACE)
  68207. + "pci");
  68208. + retval = pci_register_driver(&dwc_otg_driver);
  68209. + drv = &dwc_otg_driver.driver;
  68210. +#elif defined(PLATFORM_INTERFACE)
  68211. + "platform");
  68212. + retval = platform_driver_register(&dwc_otg_driver);
  68213. + drv = &dwc_otg_driver.driver;
  68214. +#endif
  68215. + if (retval < 0) {
  68216. + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  68217. + return retval;
  68218. + }
  68219. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_enable ? "enabled":"disabled");
  68220. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff ? "enabled":"disabled");
  68221. + printk(KERN_DEBUG "dwc_otg: FIQ split-transaction FSM %s\n", fiq_fsm_enable ? "enabled":"disabled");
  68222. +
  68223. + error = driver_create_file(drv, &driver_attr_version);
  68224. +#ifdef DEBUG
  68225. + error = driver_create_file(drv, &driver_attr_debuglevel);
  68226. +#endif
  68227. + return retval;
  68228. +}
  68229. +
  68230. +module_init(dwc_otg_driver_init);
  68231. +
  68232. +/**
  68233. + * This function is called when the driver is removed from the kernel
  68234. + * with the rmmod command. The driver unregisters itself with its bus
  68235. + * driver.
  68236. + *
  68237. + */
  68238. +static void __exit dwc_otg_driver_cleanup(void)
  68239. +{
  68240. + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
  68241. +
  68242. +#ifdef LM_INTERFACE
  68243. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
  68244. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
  68245. + lm_driver_unregister(&dwc_otg_driver);
  68246. +#elif defined(PCI_INTERFACE)
  68247. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  68248. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  68249. + pci_unregister_driver(&dwc_otg_driver);
  68250. +#elif defined(PLATFORM_INTERFACE)
  68251. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  68252. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  68253. + platform_driver_unregister(&dwc_otg_driver);
  68254. +#endif
  68255. +
  68256. + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
  68257. +}
  68258. +
  68259. +module_exit(dwc_otg_driver_cleanup);
  68260. +
  68261. +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
  68262. +MODULE_AUTHOR("Synopsys Inc.");
  68263. +MODULE_LICENSE("GPL");
  68264. +
  68265. +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
  68266. +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
  68267. +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
  68268. +MODULE_PARM_DESC(opt, "OPT Mode");
  68269. +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
  68270. +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
  68271. +
  68272. +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
  68273. + 0444);
  68274. +MODULE_PARM_DESC(dma_desc_enable,
  68275. + "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
  68276. +
  68277. +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
  68278. + 0444);
  68279. +MODULE_PARM_DESC(dma_burst_size,
  68280. + "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
  68281. +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
  68282. +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
  68283. +module_param_named(host_support_fs_ls_low_power,
  68284. + dwc_otg_module_params.host_support_fs_ls_low_power, int,
  68285. + 0444);
  68286. +MODULE_PARM_DESC(host_support_fs_ls_low_power,
  68287. + "Support Low Power w/FS or LS 0=Support 1=Don't Support");
  68288. +module_param_named(host_ls_low_power_phy_clk,
  68289. + dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
  68290. +MODULE_PARM_DESC(host_ls_low_power_phy_clk,
  68291. + "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
  68292. +module_param_named(enable_dynamic_fifo,
  68293. + dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
  68294. +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
  68295. +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
  68296. + 0444);
  68297. +MODULE_PARM_DESC(data_fifo_size,
  68298. + "Total number of words in the data FIFO memory 32-32768");
  68299. +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
  68300. + int, 0444);
  68301. +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  68302. +module_param_named(dev_nperio_tx_fifo_size,
  68303. + dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
  68304. +MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
  68305. + "Number of words in the non-periodic Tx FIFO 16-32768");
  68306. +module_param_named(dev_perio_tx_fifo_size_1,
  68307. + dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
  68308. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
  68309. + "Number of words in the periodic Tx FIFO 4-768");
  68310. +module_param_named(dev_perio_tx_fifo_size_2,
  68311. + dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
  68312. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
  68313. + "Number of words in the periodic Tx FIFO 4-768");
  68314. +module_param_named(dev_perio_tx_fifo_size_3,
  68315. + dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
  68316. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
  68317. + "Number of words in the periodic Tx FIFO 4-768");
  68318. +module_param_named(dev_perio_tx_fifo_size_4,
  68319. + dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
  68320. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
  68321. + "Number of words in the periodic Tx FIFO 4-768");
  68322. +module_param_named(dev_perio_tx_fifo_size_5,
  68323. + dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
  68324. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
  68325. + "Number of words in the periodic Tx FIFO 4-768");
  68326. +module_param_named(dev_perio_tx_fifo_size_6,
  68327. + dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
  68328. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
  68329. + "Number of words in the periodic Tx FIFO 4-768");
  68330. +module_param_named(dev_perio_tx_fifo_size_7,
  68331. + dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
  68332. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
  68333. + "Number of words in the periodic Tx FIFO 4-768");
  68334. +module_param_named(dev_perio_tx_fifo_size_8,
  68335. + dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
  68336. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
  68337. + "Number of words in the periodic Tx FIFO 4-768");
  68338. +module_param_named(dev_perio_tx_fifo_size_9,
  68339. + dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
  68340. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
  68341. + "Number of words in the periodic Tx FIFO 4-768");
  68342. +module_param_named(dev_perio_tx_fifo_size_10,
  68343. + dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
  68344. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
  68345. + "Number of words in the periodic Tx FIFO 4-768");
  68346. +module_param_named(dev_perio_tx_fifo_size_11,
  68347. + dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
  68348. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
  68349. + "Number of words in the periodic Tx FIFO 4-768");
  68350. +module_param_named(dev_perio_tx_fifo_size_12,
  68351. + dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
  68352. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
  68353. + "Number of words in the periodic Tx FIFO 4-768");
  68354. +module_param_named(dev_perio_tx_fifo_size_13,
  68355. + dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
  68356. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
  68357. + "Number of words in the periodic Tx FIFO 4-768");
  68358. +module_param_named(dev_perio_tx_fifo_size_14,
  68359. + dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
  68360. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
  68361. + "Number of words in the periodic Tx FIFO 4-768");
  68362. +module_param_named(dev_perio_tx_fifo_size_15,
  68363. + dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
  68364. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
  68365. + "Number of words in the periodic Tx FIFO 4-768");
  68366. +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
  68367. + int, 0444);
  68368. +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  68369. +module_param_named(host_nperio_tx_fifo_size,
  68370. + dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
  68371. +MODULE_PARM_DESC(host_nperio_tx_fifo_size,
  68372. + "Number of words in the non-periodic Tx FIFO 16-32768");
  68373. +module_param_named(host_perio_tx_fifo_size,
  68374. + dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
  68375. +MODULE_PARM_DESC(host_perio_tx_fifo_size,
  68376. + "Number of words in the host periodic Tx FIFO 16-32768");
  68377. +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
  68378. + int, 0444);
  68379. +/** @todo Set the max to 512K, modify checks */
  68380. +MODULE_PARM_DESC(max_transfer_size,
  68381. + "The maximum transfer size supported in bytes 2047-65535");
  68382. +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
  68383. + int, 0444);
  68384. +MODULE_PARM_DESC(max_packet_count,
  68385. + "The maximum number of packets in a transfer 15-511");
  68386. +module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
  68387. + 0444);
  68388. +MODULE_PARM_DESC(host_channels,
  68389. + "The number of host channel registers to use 1-16");
  68390. +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
  68391. + 0444);
  68392. +MODULE_PARM_DESC(dev_endpoints,
  68393. + "The number of endpoints in addition to EP0 available for device mode 1-15");
  68394. +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
  68395. +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
  68396. +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
  68397. + 0444);
  68398. +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
  68399. +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
  68400. +MODULE_PARM_DESC(phy_ulpi_ddr,
  68401. + "ULPI at double or single data rate 0=Single 1=Double");
  68402. +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
  68403. + int, 0444);
  68404. +MODULE_PARM_DESC(phy_ulpi_ext_vbus,
  68405. + "ULPI PHY using internal or external vbus 0=Internal");
  68406. +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
  68407. +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
  68408. +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
  68409. +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
  68410. +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
  68411. +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
  68412. +module_param_named(debug, g_dbg_lvl, int, 0444);
  68413. +MODULE_PARM_DESC(debug, "");
  68414. +
  68415. +module_param_named(en_multiple_tx_fifo,
  68416. + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
  68417. +MODULE_PARM_DESC(en_multiple_tx_fifo,
  68418. + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
  68419. +module_param_named(dev_tx_fifo_size_1,
  68420. + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
  68421. +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
  68422. +module_param_named(dev_tx_fifo_size_2,
  68423. + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
  68424. +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
  68425. +module_param_named(dev_tx_fifo_size_3,
  68426. + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
  68427. +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
  68428. +module_param_named(dev_tx_fifo_size_4,
  68429. + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
  68430. +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
  68431. +module_param_named(dev_tx_fifo_size_5,
  68432. + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
  68433. +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
  68434. +module_param_named(dev_tx_fifo_size_6,
  68435. + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
  68436. +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
  68437. +module_param_named(dev_tx_fifo_size_7,
  68438. + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
  68439. +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
  68440. +module_param_named(dev_tx_fifo_size_8,
  68441. + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
  68442. +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
  68443. +module_param_named(dev_tx_fifo_size_9,
  68444. + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
  68445. +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
  68446. +module_param_named(dev_tx_fifo_size_10,
  68447. + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
  68448. +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
  68449. +module_param_named(dev_tx_fifo_size_11,
  68450. + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
  68451. +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
  68452. +module_param_named(dev_tx_fifo_size_12,
  68453. + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
  68454. +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
  68455. +module_param_named(dev_tx_fifo_size_13,
  68456. + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
  68457. +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
  68458. +module_param_named(dev_tx_fifo_size_14,
  68459. + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
  68460. +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
  68461. +module_param_named(dev_tx_fifo_size_15,
  68462. + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
  68463. +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
  68464. +
  68465. +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
  68466. +MODULE_PARM_DESC(thr_ctl,
  68467. + "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
  68468. +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
  68469. + 0444);
  68470. +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
  68471. +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
  68472. + 0444);
  68473. +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
  68474. +
  68475. +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
  68476. +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
  68477. +module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
  68478. +MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
  68479. +module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
  68480. +MODULE_PARM_DESC(ic_usb_cap,
  68481. + "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
  68482. +module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
  68483. + 0444);
  68484. +MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
  68485. +module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
  68486. +MODULE_PARM_DESC(power_down, "Power Down Mode");
  68487. +module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
  68488. +MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
  68489. +module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
  68490. +MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
  68491. +module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
  68492. +MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
  68493. +module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
  68494. +MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
  68495. +module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
  68496. +MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
  68497. +module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
  68498. +MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
  68499. +module_param(microframe_schedule, bool, 0444);
  68500. +MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  68501. +
  68502. +module_param(fiq_enable, bool, 0444);
  68503. +MODULE_PARM_DESC(fiq_enable, "Enable the FIQ");
  68504. +module_param(nak_holdoff, ushort, 0644);
  68505. +MODULE_PARM_DESC(nak_holdoff, "Throttle duration for bulk split-transaction endpoints on a NAK. Default 8");
  68506. +module_param(fiq_fsm_enable, bool, 0444);
  68507. +MODULE_PARM_DESC(fiq_fsm_enable, "Enable the FIQ to perform split transactions as defined by fiq_fsm_mask");
  68508. +module_param(fiq_fsm_mask, ushort, 0444);
  68509. +MODULE_PARM_DESC(fiq_fsm_mask, "Bitmask of transactions to perform in the FIQ.\n"
  68510. + "Bit 0 : Non-periodic split transactions\n"
  68511. + "Bit 1 : Periodic split transactions\n"
  68512. + "Bit 2 : High-speed multi-transfer isochronous\n"
  68513. + "All other bits should be set 0.");
  68514. +
  68515. +
  68516. +/** @page "Module Parameters"
  68517. + *
  68518. + * The following parameters may be specified when starting the module.
  68519. + * These parameters define how the DWC_otg controller should be
  68520. + * configured. Parameter values are passed to the CIL initialization
  68521. + * function dwc_otg_cil_init
  68522. + *
  68523. + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
  68524. + *
  68525. +
  68526. + <table>
  68527. + <tr><td>Parameter Name</td><td>Meaning</td></tr>
  68528. +
  68529. + <tr>
  68530. + <td>otg_cap</td>
  68531. + <td>Specifies the OTG capabilities. The driver will automatically detect the
  68532. + value for this parameter if none is specified.
  68533. + - 0: HNP and SRP capable (default, if available)
  68534. + - 1: SRP Only capable
  68535. + - 2: No HNP/SRP capable
  68536. + </td></tr>
  68537. +
  68538. + <tr>
  68539. + <td>dma_enable</td>
  68540. + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
  68541. + The driver will automatically detect the value for this parameter if none is
  68542. + specified.
  68543. + - 0: Slave
  68544. + - 1: DMA (default, if available)
  68545. + </td></tr>
  68546. +
  68547. + <tr>
  68548. + <td>dma_burst_size</td>
  68549. + <td>The DMA Burst size (applicable only for External DMA Mode).
  68550. + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  68551. + </td></tr>
  68552. +
  68553. + <tr>
  68554. + <td>speed</td>
  68555. + <td>Specifies the maximum speed of operation in host and device mode. The
  68556. + actual speed depends on the speed of the attached device and the value of
  68557. + phy_type.
  68558. + - 0: High Speed (default)
  68559. + - 1: Full Speed
  68560. + </td></tr>
  68561. +
  68562. + <tr>
  68563. + <td>host_support_fs_ls_low_power</td>
  68564. + <td>Specifies whether low power mode is supported when attached to a Full
  68565. + Speed or Low Speed device in host mode.
  68566. + - 0: Don't support low power mode (default)
  68567. + - 1: Support low power mode
  68568. + </td></tr>
  68569. +
  68570. + <tr>
  68571. + <td>host_ls_low_power_phy_clk</td>
  68572. + <td>Specifies the PHY clock rate in low power mode when connected to a Low
  68573. + Speed device in host mode. This parameter is applicable only if
  68574. + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
  68575. + - 0: 48 MHz (default)
  68576. + - 1: 6 MHz
  68577. + </td></tr>
  68578. +
  68579. + <tr>
  68580. + <td>enable_dynamic_fifo</td>
  68581. + <td> Specifies whether FIFOs may be resized by the driver software.
  68582. + - 0: Use cC FIFO size parameters
  68583. + - 1: Allow dynamic FIFO sizing (default)
  68584. + </td></tr>
  68585. +
  68586. + <tr>
  68587. + <td>data_fifo_size</td>
  68588. + <td>Total number of 4-byte words in the data FIFO memory. This memory
  68589. + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
  68590. + - Values: 32 to 32768 (default 8192)
  68591. +
  68592. + Note: The total FIFO memory depth in the FPGA configuration is 8192.
  68593. + </td></tr>
  68594. +
  68595. + <tr>
  68596. + <td>dev_rx_fifo_size</td>
  68597. + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
  68598. + FIFO sizing is enabled.
  68599. + - Values: 16 to 32768 (default 1064)
  68600. + </td></tr>
  68601. +
  68602. + <tr>
  68603. + <td>dev_nperio_tx_fifo_size</td>
  68604. + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
  68605. + dynamic FIFO sizing is enabled.
  68606. + - Values: 16 to 32768 (default 1024)
  68607. + </td></tr>
  68608. +
  68609. + <tr>
  68610. + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
  68611. + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
  68612. + when dynamic FIFO sizing is enabled.
  68613. + - Values: 4 to 768 (default 256)
  68614. + </td></tr>
  68615. +
  68616. + <tr>
  68617. + <td>host_rx_fifo_size</td>
  68618. + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
  68619. + sizing is enabled.
  68620. + - Values: 16 to 32768 (default 1024)
  68621. + </td></tr>
  68622. +
  68623. + <tr>
  68624. + <td>host_nperio_tx_fifo_size</td>
  68625. + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
  68626. + dynamic FIFO sizing is enabled in the core.
  68627. + - Values: 16 to 32768 (default 1024)
  68628. + </td></tr>
  68629. +
  68630. + <tr>
  68631. + <td>host_perio_tx_fifo_size</td>
  68632. + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
  68633. + sizing is enabled.
  68634. + - Values: 16 to 32768 (default 1024)
  68635. + </td></tr>
  68636. +
  68637. + <tr>
  68638. + <td>max_transfer_size</td>
  68639. + <td>The maximum transfer size supported in bytes.
  68640. + - Values: 2047 to 65,535 (default 65,535)
  68641. + </td></tr>
  68642. +
  68643. + <tr>
  68644. + <td>max_packet_count</td>
  68645. + <td>The maximum number of packets in a transfer.
  68646. + - Values: 15 to 511 (default 511)
  68647. + </td></tr>
  68648. +
  68649. + <tr>
  68650. + <td>host_channels</td>
  68651. + <td>The number of host channel registers to use.
  68652. + - Values: 1 to 16 (default 12)
  68653. +
  68654. + Note: The FPGA configuration supports a maximum of 12 host channels.
  68655. + </td></tr>
  68656. +
  68657. + <tr>
  68658. + <td>dev_endpoints</td>
  68659. + <td>The number of endpoints in addition to EP0 available for device mode
  68660. + operations.
  68661. + - Values: 1 to 15 (default 6 IN and OUT)
  68662. +
  68663. + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
  68664. + addition to EP0.
  68665. + </td></tr>
  68666. +
  68667. + <tr>
  68668. + <td>phy_type</td>
  68669. + <td>Specifies the type of PHY interface to use. By default, the driver will
  68670. + automatically detect the phy_type.
  68671. + - 0: Full Speed
  68672. + - 1: UTMI+ (default, if available)
  68673. + - 2: ULPI
  68674. + </td></tr>
  68675. +
  68676. + <tr>
  68677. + <td>phy_utmi_width</td>
  68678. + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
  68679. + phy_type of UTMI+. Also, this parameter is applicable only if the
  68680. + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
  68681. + core has been configured to work at either data path width.
  68682. + - Values: 8 or 16 bits (default 16)
  68683. + </td></tr>
  68684. +
  68685. + <tr>
  68686. + <td>phy_ulpi_ddr</td>
  68687. + <td>Specifies whether the ULPI operates at double or single data rate. This
  68688. + parameter is only applicable if phy_type is ULPI.
  68689. + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
  68690. + - 1: double data rate ULPI interface with 4 bit wide data bus
  68691. + </td></tr>
  68692. +
  68693. + <tr>
  68694. + <td>i2c_enable</td>
  68695. + <td>Specifies whether to use the I2C interface for full speed PHY. This
  68696. + parameter is only applicable if PHY_TYPE is FS.
  68697. + - 0: Disabled (default)
  68698. + - 1: Enabled
  68699. + </td></tr>
  68700. +
  68701. + <tr>
  68702. + <td>ulpi_fs_ls</td>
  68703. + <td>Specifies whether to use ULPI FS/LS mode only.
  68704. + - 0: Disabled (default)
  68705. + - 1: Enabled
  68706. + </td></tr>
  68707. +
  68708. + <tr>
  68709. + <td>ts_dline</td>
  68710. + <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
  68711. + - 0: Disabled (default)
  68712. + - 1: Enabled
  68713. + </td></tr>
  68714. +
  68715. + <tr>
  68716. + <td>en_multiple_tx_fifo</td>
  68717. + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
  68718. + The driver will automatically detect the value for this parameter if none is
  68719. + specified.
  68720. + - 0: Disabled
  68721. + - 1: Enabled (default, if available)
  68722. + </td></tr>
  68723. +
  68724. + <tr>
  68725. + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
  68726. + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
  68727. + when dynamic FIFO sizing is enabled.
  68728. + - Values: 4 to 768 (default 256)
  68729. + </td></tr>
  68730. +
  68731. + <tr>
  68732. + <td>tx_thr_length</td>
  68733. + <td>Transmit Threshold length in 32 bit double words
  68734. + - Values: 8 to 128 (default 64)
  68735. + </td></tr>
  68736. +
  68737. + <tr>
  68738. + <td>rx_thr_length</td>
  68739. + <td>Receive Threshold length in 32 bit double words
  68740. + - Values: 8 to 128 (default 64)
  68741. + </td></tr>
  68742. +
  68743. +<tr>
  68744. + <td>thr_ctl</td>
  68745. + <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of
  68746. + this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
  68747. + Rx transfers accordingly.
  68748. + The driver will automatically detect the value for this parameter if none is
  68749. + specified.
  68750. + - Values: 0 to 7 (default 0)
  68751. + Bit values indicate:
  68752. + - 0: Thresholding disabled
  68753. + - 1: Thresholding enabled
  68754. + </td></tr>
  68755. +
  68756. +<tr>
  68757. + <td>dma_desc_enable</td>
  68758. + <td>Specifies whether to enable Descriptor DMA mode.
  68759. + The driver will automatically detect the value for this parameter if none is
  68760. + specified.
  68761. + - 0: Descriptor DMA disabled
  68762. + - 1: Descriptor DMA (default, if available)
  68763. + </td></tr>
  68764. +
  68765. +<tr>
  68766. + <td>mpi_enable</td>
  68767. + <td>Specifies whether to enable MPI enhancement mode.
  68768. + The driver will automatically detect the value for this parameter if none is
  68769. + specified.
  68770. + - 0: MPI disabled (default)
  68771. + - 1: MPI enable
  68772. + </td></tr>
  68773. +
  68774. +<tr>
  68775. + <td>pti_enable</td>
  68776. + <td>Specifies whether to enable PTI enhancement support.
  68777. + The driver will automatically detect the value for this parameter if none is
  68778. + specified.
  68779. + - 0: PTI disabled (default)
  68780. + - 1: PTI enable
  68781. + </td></tr>
  68782. +
  68783. +<tr>
  68784. + <td>lpm_enable</td>
  68785. + <td>Specifies whether to enable LPM support.
  68786. + The driver will automatically detect the value for this parameter if none is
  68787. + specified.
  68788. + - 0: LPM disabled
  68789. + - 1: LPM enable (default, if available)
  68790. + </td></tr>
  68791. +
  68792. +<tr>
  68793. + <td>ic_usb_cap</td>
  68794. + <td>Specifies whether to enable IC_USB capability.
  68795. + The driver will automatically detect the value for this parameter if none is
  68796. + specified.
  68797. + - 0: IC_USB disabled (default, if available)
  68798. + - 1: IC_USB enable
  68799. + </td></tr>
  68800. +
  68801. +<tr>
  68802. + <td>ahb_thr_ratio</td>
  68803. + <td>Specifies AHB Threshold ratio.
  68804. + - Values: 0 to 3 (default 0)
  68805. + </td></tr>
  68806. +
  68807. +<tr>
  68808. + <td>power_down</td>
  68809. + <td>Specifies Power Down(Hibernation) Mode.
  68810. + The driver will automatically detect the value for this parameter if none is
  68811. + specified.
  68812. + - 0: Power Down disabled (default)
  68813. + - 2: Power Down enabled
  68814. + </td></tr>
  68815. +
  68816. + <tr>
  68817. + <td>reload_ctl</td>
  68818. + <td>Specifies whether dynamic reloading of the HFIR register is allowed during
  68819. + run time. The driver will automatically detect the value for this parameter if
  68820. + none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
  68821. + the core might misbehave.
  68822. + - 0: Reload Control disabled (default)
  68823. + - 1: Reload Control enabled
  68824. + </td></tr>
  68825. +
  68826. + <tr>
  68827. + <td>dev_out_nak</td>
  68828. + <td>Specifies whether Device OUT NAK enhancement enabled or no.
  68829. + The driver will automatically detect the value for this parameter if
  68830. + none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  68831. + - 0: The core does not set NAK after Bulk OUT transfer complete (default)
  68832. + - 1: The core sets NAK after Bulk OUT transfer complete
  68833. + </td></tr>
  68834. +
  68835. + <tr>
  68836. + <td>cont_on_bna</td>
  68837. + <td>Specifies whether Enable Continue on BNA enabled or no.
  68838. + After receiving BNA interrupt the core disables the endpoint,when the
  68839. + endpoint is re-enabled by the application the
  68840. + - 0: Core starts processing from the DOEPDMA descriptor (default)
  68841. + - 1: Core starts processing from the descriptor which received the BNA.
  68842. + This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  68843. + </td></tr>
  68844. +
  68845. + <tr>
  68846. + <td>ahb_single</td>
  68847. + <td>This bit when programmed supports SINGLE transfers for remainder data
  68848. + in a transfer for DMA mode of operation.
  68849. + - 0: The remainder data will be sent using INCR burst size (default)
  68850. + - 1: The remainder data will be sent using SINGLE burst size.
  68851. + </td></tr>
  68852. +
  68853. +<tr>
  68854. + <td>adp_enable</td>
  68855. + <td>Specifies whether ADP feature is enabled.
  68856. + The driver will automatically detect the value for this parameter if none is
  68857. + specified.
  68858. + - 0: ADP feature disabled (default)
  68859. + - 1: ADP feature enabled
  68860. + </td></tr>
  68861. +
  68862. + <tr>
  68863. + <td>otg_ver</td>
  68864. + <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
  68865. + USB OTG device.
  68866. + - 0: OTG 2.0 support disabled (default)
  68867. + - 1: OTG 2.0 support enabled
  68868. + </td></tr>
  68869. +
  68870. +*/
  68871. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_driver.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h
  68872. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_driver.h 1970-01-01 01:00:00.000000000 +0100
  68873. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h 2014-04-24 16:04:39.819124254 +0200
  68874. @@ -0,0 +1,86 @@
  68875. +/* ==========================================================================
  68876. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
  68877. + * $Revision: #19 $
  68878. + * $Date: 2010/11/15 $
  68879. + * $Change: 1627671 $
  68880. + *
  68881. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  68882. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  68883. + * otherwise expressly agreed to in writing between Synopsys and you.
  68884. + *
  68885. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  68886. + * any End User Software License Agreement or Agreement for Licensed Product
  68887. + * with Synopsys or any supplement thereto. You are permitted to use and
  68888. + * redistribute this Software in source and binary forms, with or without
  68889. + * modification, provided that redistributions of source code must retain this
  68890. + * notice. You may not view, use, disclose, copy or distribute this file or
  68891. + * any information contained herein except pursuant to this license grant from
  68892. + * Synopsys. If you do not agree with this notice, including the disclaimer
  68893. + * below, then you are not authorized to use the Software.
  68894. + *
  68895. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  68896. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  68897. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  68898. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  68899. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68900. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  68901. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  68902. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68903. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68904. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  68905. + * DAMAGE.
  68906. + * ========================================================================== */
  68907. +
  68908. +#ifndef __DWC_OTG_DRIVER_H__
  68909. +#define __DWC_OTG_DRIVER_H__
  68910. +
  68911. +/** @file
  68912. + * This file contains the interface to the Linux driver.
  68913. + */
  68914. +#include "dwc_otg_os_dep.h"
  68915. +#include "dwc_otg_core_if.h"
  68916. +
  68917. +/* Type declarations */
  68918. +struct dwc_otg_pcd;
  68919. +struct dwc_otg_hcd;
  68920. +
  68921. +/**
  68922. + * This structure is a wrapper that encapsulates the driver components used to
  68923. + * manage a single DWC_otg controller.
  68924. + */
  68925. +typedef struct dwc_otg_device {
  68926. + /** Structure containing OS-dependent stuff. KEEP THIS STRUCT AT THE
  68927. + * VERY BEGINNING OF THE DEVICE STRUCT. OSes such as FreeBSD and NetBSD
  68928. + * require this. */
  68929. + struct os_dependent os_dep;
  68930. +
  68931. + /** Pointer to the core interface structure. */
  68932. + dwc_otg_core_if_t *core_if;
  68933. +
  68934. + /** Pointer to the PCD structure. */
  68935. + struct dwc_otg_pcd *pcd;
  68936. +
  68937. + /** Pointer to the HCD structure. */
  68938. + struct dwc_otg_hcd *hcd;
  68939. +
  68940. + /** Flag to indicate whether the common IRQ handler is installed. */
  68941. + uint8_t common_irq_installed;
  68942. +
  68943. +} dwc_otg_device_t;
  68944. +
  68945. +/*We must clear S3C24XX_EINTPEND external interrupt register
  68946. + * because after clearing in this register trigerred IRQ from
  68947. + * H/W core in kernel interrupt can be occured again before OTG
  68948. + * handlers clear all IRQ sources of Core registers because of
  68949. + * timing latencies and Low Level IRQ Type.
  68950. + */
  68951. +#ifdef CONFIG_MACH_IPMATE
  68952. +#define S3C2410X_CLEAR_EINTPEND() \
  68953. +do { \
  68954. + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
  68955. +} while (0)
  68956. +#else
  68957. +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
  68958. +#endif
  68959. +
  68960. +#endif
  68961. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
  68962. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 1970-01-01 01:00:00.000000000 +0100
  68963. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 2014-04-24 16:04:39.819124254 +0200
  68964. @@ -0,0 +1,1289 @@
  68965. +/*
  68966. + * dwc_otg_fiq_fsm.c - The finite state machine FIQ
  68967. + *
  68968. + * Copyright (c) 2013 Raspberry Pi Foundation
  68969. + *
  68970. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  68971. + * All rights reserved.
  68972. + *
  68973. + * Redistribution and use in source and binary forms, with or without
  68974. + * modification, are permitted provided that the following conditions are met:
  68975. + * * Redistributions of source code must retain the above copyright
  68976. + * notice, this list of conditions and the following disclaimer.
  68977. + * * Redistributions in binary form must reproduce the above copyright
  68978. + * notice, this list of conditions and the following disclaimer in the
  68979. + * documentation and/or other materials provided with the distribution.
  68980. + * * Neither the name of Raspberry Pi nor the
  68981. + * names of its contributors may be used to endorse or promote products
  68982. + * derived from this software without specific prior written permission.
  68983. + *
  68984. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  68985. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  68986. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  68987. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  68988. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68989. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  68990. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  68991. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  68992. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  68993. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  68994. + *
  68995. + * This FIQ implements functionality that performs split transactions on
  68996. + * the dwc_otg hardware without any outside intervention. A split transaction
  68997. + * is "queued" by nominating a specific host channel to perform the entirety
  68998. + * of a split transaction. This FIQ will then perform the microframe-precise
  68999. + * scheduling required in each phase of the transaction until completion.
  69000. + *
  69001. + * The FIQ functionality is glued into the Synopsys driver via the entry point
  69002. + * in the FSM enqueue function, and at the exit point in handling a HC interrupt
  69003. + * for a FSM-enabled channel.
  69004. + *
  69005. + * NB: Large parts of this implementation have architecture-specific code.
  69006. + * For porting this functionality to other ARM machines, the minimum is required:
  69007. + * - An interrupt controller allowing the top-level dwc USB interrupt to be routed
  69008. + * to the FIQ
  69009. + * - A method of forcing a software generated interrupt from FIQ mode that then
  69010. + * triggers an IRQ entry (with the dwc USB handler called by this IRQ number)
  69011. + * - Guaranteed interrupt routing such that both the FIQ and SGI occur on the same
  69012. + * processor core - there is no locking between the FIQ and IRQ (aside from
  69013. + * local_fiq_disable)
  69014. + *
  69015. + */
  69016. +
  69017. +#include "dwc_otg_fiq_fsm.h"
  69018. +
  69019. +
  69020. +char buffer[1000*16];
  69021. +int wptr;
  69022. +void notrace _fiq_print(enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...)
  69023. +{
  69024. + enum fiq_debug_level dbg_lvl_req = FIQDBG_ERR;
  69025. + va_list args;
  69026. + char text[17];
  69027. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + 0x408) };
  69028. +
  69029. + if((dbg_lvl & dbg_lvl_req) || dbg_lvl == FIQDBG_ERR)
  69030. + {
  69031. + snprintf(text, 9, " %4d:%1u ", hfnum.b.frnum/8, hfnum.b.frnum & 7);
  69032. + va_start(args, fmt);
  69033. + vsnprintf(text+8, 9, fmt, args);
  69034. + va_end(args);
  69035. +
  69036. + memcpy(buffer + wptr, text, 16);
  69037. + wptr = (wptr + 16) % sizeof(buffer);
  69038. + }
  69039. +}
  69040. +
  69041. +/**
  69042. + * fiq_fsm_restart_channel() - Poke channel enable bit for a split transaction
  69043. + * @channel: channel to re-enable
  69044. + */
  69045. +static void fiq_fsm_restart_channel(struct fiq_state *st, int n, int force)
  69046. +{
  69047. + hcchar_data_t hcchar = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR) };
  69048. +
  69049. + hcchar.b.chen = 0;
  69050. + if (st->channel[n].hcchar_copy.b.eptype & 0x1) {
  69051. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  69052. + /* Hardware bug workaround: update the ssplit index */
  69053. + if (st->channel[n].hcsplt_copy.b.spltena)
  69054. + st->channel[n].expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  69055. +
  69056. + hcchar.b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  69057. + }
  69058. +
  69059. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  69060. + hcchar.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  69061. + hcchar.b.chen = 1;
  69062. +
  69063. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  69064. + fiq_print(FIQDBG_INT, st, "HCGO %01d %01d", n, force);
  69065. +}
  69066. +
  69067. +/**
  69068. + * fiq_fsm_setup_csplit() - Prepare a host channel for a CSplit transaction stage
  69069. + * @st: Pointer to the channel's state
  69070. + * @n : channel number
  69071. + *
  69072. + * Change host channel registers to perform a complete-split transaction. Being mindful of the
  69073. + * endpoint direction, set control regs up correctly.
  69074. + */
  69075. +static void notrace fiq_fsm_setup_csplit(struct fiq_state *st, int n)
  69076. +{
  69077. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT) };
  69078. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  69079. +
  69080. + hcsplt.b.compsplt = 1;
  69081. + if (st->channel[n].hcchar_copy.b.epdir == 1) {
  69082. + // If IN, the CSPLIT result contains the data or a hub handshake. hctsiz = maxpacket.
  69083. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  69084. + } else {
  69085. + // If OUT, the CSPLIT result contains handshake only.
  69086. + hctsiz.b.xfersize = 0;
  69087. + }
  69088. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  69089. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  69090. + mb();
  69091. +}
  69092. +
  69093. +static inline int notrace fiq_get_xfer_len(struct fiq_state *st, int n)
  69094. +{
  69095. + /* The xfersize register is a bit wonky. For IN transfers, it decrements by the packet size. */
  69096. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  69097. +
  69098. + if (st->channel[n].hcchar_copy.b.epdir == 0) {
  69099. + return st->channel[n].hctsiz_copy.b.xfersize;
  69100. + } else {
  69101. + return st->channel[n].hctsiz_copy.b.xfersize - hctsiz.b.xfersize;
  69102. + }
  69103. +
  69104. +}
  69105. +
  69106. +
  69107. +/**
  69108. + * fiq_increment_dma_buf() - update DMA address for bounce buffers after a CSPLIT
  69109. + *
  69110. + * Of use only for IN periodic transfers.
  69111. + */
  69112. +static int notrace fiq_increment_dma_buf(struct fiq_state *st, int num_channels, int n)
  69113. +{
  69114. + hcdma_data_t hcdma;
  69115. + int i = st->channel[n].dma_info.index;
  69116. + int len;
  69117. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  69118. +
  69119. + len = fiq_get_xfer_len(st, n);
  69120. + fiq_print(FIQDBG_INT, st, "LEN: %03d", len);
  69121. + st->channel[n].dma_info.slot_len[i] = len;
  69122. + i++;
  69123. + if (i > 6)
  69124. + BUG();
  69125. +
  69126. + hcdma.d32 = (dma_addr_t) &blob->channel[n].index[i].buf[0];
  69127. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  69128. + st->channel[n].dma_info.index = i;
  69129. + return 0;
  69130. +}
  69131. +
  69132. +/**
  69133. + * fiq_reload_hctsiz() - for IN transactions, reset HCTSIZ
  69134. + */
  69135. +static void notrace fiq_fsm_reload_hctsiz(struct fiq_state *st, int n)
  69136. +{
  69137. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  69138. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  69139. + hctsiz.b.pktcnt = 1;
  69140. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  69141. +}
  69142. +
  69143. +/**
  69144. + * fiq_iso_out_advance() - update DMA address and split position bits
  69145. + * for isochronous OUT transactions.
  69146. + *
  69147. + * Returns 1 if this is the last packet queued, 0 otherwise. Split-ALL and
  69148. + * Split-BEGIN states are not handled - this is done when the transaction was queued.
  69149. + *
  69150. + * This function must only be called from the FIQ_ISO_OUT_ACTIVE state.
  69151. + */
  69152. +static int notrace fiq_iso_out_advance(struct fiq_state *st, int num_channels, int n)
  69153. +{
  69154. + hcsplt_data_t hcsplt;
  69155. + hctsiz_data_t hctsiz;
  69156. + hcdma_data_t hcdma;
  69157. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  69158. + int last = 0;
  69159. + int i = st->channel[n].dma_info.index;
  69160. +
  69161. + fiq_print(FIQDBG_INT, st, "ADV %01d %01d ", n, i);
  69162. + i++;
  69163. + if (i == 4)
  69164. + last = 1;
  69165. + if (st->channel[n].dma_info.slot_len[i+1] == 255)
  69166. + last = 1;
  69167. +
  69168. + /* New DMA address - address of bounce buffer referred to in index */
  69169. + hcdma.d32 = (uint32_t) &blob->channel[n].index[i].buf[0];
  69170. + //hcdma.d32 = FIQ_READ(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n));
  69171. + //hcdma.d32 += st->channel[n].dma_info.slot_len[i];
  69172. + fiq_print(FIQDBG_INT, st, "LAST: %01d ", last);
  69173. + fiq_print(FIQDBG_INT, st, "LEN: %03d", st->channel[n].dma_info.slot_len[i]);
  69174. + hcsplt.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT);
  69175. + hctsiz.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ);
  69176. + hcsplt.b.xactpos = (last) ? ISOC_XACTPOS_END : ISOC_XACTPOS_MID;
  69177. + /* Set up new packet length */
  69178. + hctsiz.b.pktcnt = 1;
  69179. + hctsiz.b.xfersize = st->channel[n].dma_info.slot_len[i];
  69180. + fiq_print(FIQDBG_INT, st, "%08x", hctsiz.d32);
  69181. +
  69182. + st->channel[n].dma_info.index++;
  69183. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  69184. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  69185. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  69186. + return last;
  69187. +}
  69188. +
  69189. +/**
  69190. + * fiq_fsm_tt_next_isoc() - queue next pending isochronous out start-split on a TT
  69191. + *
  69192. + * Despite the limitations of the DWC core, we can force a microframe pipeline of
  69193. + * isochronous OUT start-split transactions while waiting for a corresponding other-type
  69194. + * of endpoint to finish its CSPLITs. TTs have big periodic buffers therefore it
  69195. + * is very unlikely that filling the start-split FIFO will cause data loss.
  69196. + * This allows much better interleaving of transactions in an order-independent way-
  69197. + * there is no requirement to prioritise isochronous, just a state-space search has
  69198. + * to be performed on each periodic start-split complete interrupt.
  69199. + */
  69200. +static int notrace fiq_fsm_tt_next_isoc(struct fiq_state *st, int num_channels, int n)
  69201. +{
  69202. + int hub_addr = st->channel[n].hub_addr;
  69203. + int port_addr = st->channel[n].port_addr;
  69204. + int i, poked = 0;
  69205. + for (i = 0; i < num_channels; i++) {
  69206. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  69207. + continue;
  69208. + if (st->channel[i].hub_addr == hub_addr &&
  69209. + st->channel[i].port_addr == port_addr) {
  69210. + switch (st->channel[i].fsm) {
  69211. + case FIQ_PER_ISO_OUT_PENDING:
  69212. + if (st->channel[i].nrpackets == 1) {
  69213. + st->channel[i].fsm = FIQ_PER_ISO_OUT_LAST;
  69214. + } else {
  69215. + st->channel[i].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  69216. + }
  69217. + fiq_fsm_restart_channel(st, i, 0);
  69218. + poked = 1;
  69219. + break;
  69220. +
  69221. + default:
  69222. + break;
  69223. + }
  69224. + }
  69225. + if (poked)
  69226. + break;
  69227. + }
  69228. + return poked;
  69229. +}
  69230. +
  69231. +/**
  69232. + * fiq_fsm_tt_in_use() - search for host channels using this TT
  69233. + * @n: Channel to use as reference
  69234. + *
  69235. + */
  69236. +int notrace noinline fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n)
  69237. +{
  69238. + int hub_addr = st->channel[n].hub_addr;
  69239. + int port_addr = st->channel[n].port_addr;
  69240. + int i, in_use = 0;
  69241. + for (i = 0; i < num_channels; i++) {
  69242. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  69243. + continue;
  69244. + switch (st->channel[i].fsm) {
  69245. + /* TT is reserved for channels that are in the middle of a periodic
  69246. + * split transaction.
  69247. + */
  69248. + case FIQ_PER_SSPLIT_STARTED:
  69249. + case FIQ_PER_CSPLIT_WAIT:
  69250. + case FIQ_PER_CSPLIT_NYET1:
  69251. + //case FIQ_PER_CSPLIT_POLL:
  69252. + case FIQ_PER_ISO_OUT_ACTIVE:
  69253. + if (st->channel[i].hub_addr == hub_addr &&
  69254. + st->channel[i].port_addr == port_addr) {
  69255. + in_use = 1;
  69256. + }
  69257. + break;
  69258. + default:
  69259. + break;
  69260. + }
  69261. + if (in_use)
  69262. + break;
  69263. + }
  69264. + return in_use;
  69265. +}
  69266. +
  69267. +/**
  69268. + * fiq_fsm_more_csplits() - determine whether additional CSPLITs need
  69269. + * to be issued for this IN transaction.
  69270. + *
  69271. + * We cannot tell the inbound PID of a data packet due to hardware limitations.
  69272. + * we need to make an educated guess as to whether we need to queue another CSPLIT
  69273. + * or not. A no-brainer is when we have received enough data to fill the endpoint
  69274. + * size, but for endpoints that give variable-length data then we have to resort
  69275. + * to heuristics.
  69276. + *
  69277. + * We also return whether this is the last CSPLIT to be queued, again based on
  69278. + * heuristics. This is to allow a 1-uframe overlap of periodic split transactions.
  69279. + * Note: requires at least 1 CSPLIT to have been performed prior to being called.
  69280. + */
  69281. +
  69282. +/*
  69283. + * We need some way of guaranteeing if a returned periodic packet of size X
  69284. + * has a DATA0 PID.
  69285. + * The heuristic value of 144 bytes assumes that the received data has maximal
  69286. + * bit-stuffing and the clock frequency of the transmitting device is at the lowest
  69287. + * permissible limit. If the transfer length results in a final packet size
  69288. + * 144 < p <= 188, then an erroneous CSPLIT will be issued.
  69289. + * Also used to ensure that an endpoint will nominally only return a single
  69290. + * complete-split worth of data.
  69291. + */
  69292. +#define DATA0_PID_HEURISTIC 144
  69293. +
  69294. +static int notrace noinline fiq_fsm_more_csplits(struct fiq_state *state, int n, int *probably_last)
  69295. +{
  69296. +
  69297. + int i;
  69298. + int total_len = 0;
  69299. + int more_needed = 1;
  69300. + struct fiq_channel_state *st = &state->channel[n];
  69301. +
  69302. + for (i = 0; i < st->dma_info.index; i++) {
  69303. + total_len += st->dma_info.slot_len[i];
  69304. + }
  69305. +
  69306. + *probably_last = 0;
  69307. +
  69308. + if (st->hcchar_copy.b.eptype == 0x3) {
  69309. + /*
  69310. + * An interrupt endpoint will take max 2 CSPLITs. if we are receiving data
  69311. + * then this is definitely the last CSPLIT.
  69312. + */
  69313. + *probably_last = 1;
  69314. + } else {
  69315. + /* Isoc IN. This is a bit risky if we are the first transaction:
  69316. + * we may have been held off slightly. */
  69317. + if (i > 1 && st->dma_info.slot_len[st->dma_info.index-1] <= DATA0_PID_HEURISTIC) {
  69318. + more_needed = 0;
  69319. + }
  69320. + /* If in the next uframe we will receive enough data to fill the endpoint,
  69321. + * then only issue 1 more csplit.
  69322. + */
  69323. + if (st->hctsiz_copy.b.xfersize - total_len <= DATA0_PID_HEURISTIC)
  69324. + *probably_last = 1;
  69325. + }
  69326. +
  69327. + if (total_len >= st->hctsiz_copy.b.xfersize ||
  69328. + i == 6 || total_len == 0)
  69329. + /* Note: due to bit stuffing it is possible to have > 6 CSPLITs for
  69330. + * a single endpoint. Accepting more would completely break our scheduling mechanism though
  69331. + * - in these extreme cases we will pass through a truncated packet.
  69332. + */
  69333. + more_needed = 0;
  69334. +
  69335. + return more_needed;
  69336. +}
  69337. +
  69338. +/**
  69339. + * fiq_fsm_too_late() - Test transaction for lateness
  69340. + *
  69341. + * If a SSPLIT for a large IN transaction is issued too late in a frame,
  69342. + * the hub will disable the port to the device and respond with ERR handshakes.
  69343. + * The hub status endpoint will not reflect this change.
  69344. + * Returns 1 if we will issue a SSPLIT that will result in a device babble.
  69345. + */
  69346. +int notrace fiq_fsm_too_late(struct fiq_state *st, int n)
  69347. +{
  69348. + int uframe;
  69349. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  69350. + uframe = hfnum.b.frnum & 0x7;
  69351. + if ((uframe < 6) && (st->channel[n].nrpackets + 1 + uframe > 7)) {
  69352. + return 1;
  69353. + } else {
  69354. + return 0;
  69355. + }
  69356. +}
  69357. +
  69358. +
  69359. +/**
  69360. + * fiq_fsm_start_next_periodic() - A half-arsed attempt at a microframe pipeline
  69361. + *
  69362. + * Search pending transactions in the start-split pending state and queue them.
  69363. + * Don't queue packets in uframe .5 (comes out in .6) (USB2.0 11.18.4).
  69364. + * Note: we specifically don't do isochronous OUT transactions first because better
  69365. + * use of the TT's start-split fifo can be achieved by pipelining an IN before an OUT.
  69366. + */
  69367. +static void notrace noinline fiq_fsm_start_next_periodic(struct fiq_state *st, int num_channels)
  69368. +{
  69369. + int n;
  69370. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  69371. + if ((hfnum.b.frnum & 0x7) == 5)
  69372. + return;
  69373. + for (n = 0; n < num_channels; n++) {
  69374. + if (st->channel[n].fsm == FIQ_PER_SSPLIT_QUEUED) {
  69375. + /* Check to see if any other transactions are using this TT */
  69376. + if(!fiq_fsm_tt_in_use(st, num_channels, n)) {
  69377. + if (!fiq_fsm_too_late(st, n)) {
  69378. + st->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  69379. + fiq_print(FIQDBG_INT, st, "NEXTPER ");
  69380. + fiq_fsm_restart_channel(st, n, 0);
  69381. + } else {
  69382. + st->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  69383. + }
  69384. + break;
  69385. + }
  69386. + }
  69387. + }
  69388. + for (n = 0; n < num_channels; n++) {
  69389. + if (st->channel[n].fsm == FIQ_PER_ISO_OUT_PENDING) {
  69390. + if (!fiq_fsm_tt_in_use(st, num_channels, n)) {
  69391. + fiq_print(FIQDBG_INT, st, "NEXTISO ");
  69392. + st->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  69393. + fiq_fsm_restart_channel(st, n, 0);
  69394. + break;
  69395. + }
  69396. + }
  69397. + }
  69398. +}
  69399. +
  69400. +/**
  69401. + * fiq_fsm_update_hs_isoc() - update isochronous frame and transfer data
  69402. + * @state: Pointer to fiq_state
  69403. + * @n: Channel transaction is active on
  69404. + * @hcint: Copy of host channel interrupt register
  69405. + *
  69406. + * Returns 0 if there are no more transactions for this HC to do, 1
  69407. + * otherwise.
  69408. + */
  69409. +static int notrace noinline fiq_fsm_update_hs_isoc(struct fiq_state *state, int n, hcint_data_t hcint)
  69410. +{
  69411. + struct fiq_channel_state *st = &state->channel[n];
  69412. + int xfer_len = 0, nrpackets = 0;
  69413. + hcdma_data_t hcdma;
  69414. + fiq_print(FIQDBG_INT, state, "HSISO %02d", n);
  69415. +
  69416. + xfer_len = fiq_get_xfer_len(state, n);
  69417. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].actual_length = xfer_len;
  69418. +
  69419. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].status = hcint.d32;
  69420. +
  69421. + st->hs_isoc_info.index++;
  69422. + if (st->hs_isoc_info.index == st->hs_isoc_info.nrframes) {
  69423. + return 0;
  69424. + }
  69425. +
  69426. + /* grab the next DMA address offset from the array */
  69427. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].offset;
  69428. + FIQ_WRITE(state->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  69429. +
  69430. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  69431. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  69432. + * this is always set to the maximum size of the endpoint. */
  69433. + xfer_len = st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].length;
  69434. + /* Integer divide in a FIQ: fun. FIXME: make this not suck */
  69435. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  69436. + if (nrpackets == 0)
  69437. + nrpackets = 1;
  69438. + st->hcchar_copy.b.multicnt = nrpackets;
  69439. + st->hctsiz_copy.b.pktcnt = nrpackets;
  69440. +
  69441. + /* Initial PID also needs to be set */
  69442. + if (st->hcchar_copy.b.epdir == 0) {
  69443. + st->hctsiz_copy.b.xfersize = xfer_len;
  69444. + switch (st->hcchar_copy.b.multicnt) {
  69445. + case 1:
  69446. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  69447. + break;
  69448. + case 2:
  69449. + case 3:
  69450. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  69451. + break;
  69452. + }
  69453. +
  69454. + } else {
  69455. + switch (st->hcchar_copy.b.multicnt) {
  69456. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  69457. + case 1:
  69458. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  69459. + break;
  69460. + case 2:
  69461. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  69462. + break;
  69463. + case 3:
  69464. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  69465. + break;
  69466. + }
  69467. + }
  69468. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, st->hctsiz_copy.d32);
  69469. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, st->hcchar_copy.d32);
  69470. + /* Channel is enabled on hcint handler exit */
  69471. + fiq_print(FIQDBG_INT, state, "HSISOOUT");
  69472. + return 1;
  69473. +}
  69474. +
  69475. +
  69476. +/**
  69477. + * fiq_fsm_do_sof() - FSM start-of-frame interrupt handler
  69478. + * @state: Pointer to the state struct passed from banked FIQ mode registers.
  69479. + * @num_channels: set according to the DWC hardware configuration
  69480. + *
  69481. + * The SOF handler in FSM mode has two functions
  69482. + * 1. Hold off SOF from causing schedule advancement in IRQ context if there's
  69483. + * nothing to do
  69484. + * 2. Advance certain FSM states that require either a microframe delay, or a microframe
  69485. + * of holdoff.
  69486. + *
  69487. + * The second part is architecture-specific to mach-bcm2835 -
  69488. + * a sane interrupt controller would have a mask register for ARM interrupt sources
  69489. + * to be promoted to the nFIQ line, but it doesn't. Instead a single interrupt
  69490. + * number (USB) can be enabled. This means that certain parts of the USB specification
  69491. + * that require "wait a little while, then issue another packet" cannot be fulfilled with
  69492. + * the timing granularity required to achieve optimal throughout. The workaround is to use
  69493. + * the SOF "timer" (125uS) to perform this task.
  69494. + */
  69495. +static int notrace noinline fiq_fsm_do_sof(struct fiq_state *state, int num_channels)
  69496. +{
  69497. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + HFNUM) };
  69498. + int n;
  69499. + int kick_irq = 0;
  69500. +
  69501. + if ((hfnum.b.frnum & 0x7) == 1) {
  69502. + /* We cannot issue csplits for transactions in the last frame past (n+1).1
  69503. + * Check to see if there are any transactions that are stale.
  69504. + * Boot them out.
  69505. + */
  69506. + for (n = 0; n < num_channels; n++) {
  69507. + switch (state->channel[n].fsm) {
  69508. + case FIQ_PER_CSPLIT_WAIT:
  69509. + case FIQ_PER_CSPLIT_NYET1:
  69510. + case FIQ_PER_CSPLIT_POLL:
  69511. + case FIQ_PER_CSPLIT_LAST:
  69512. + /* Check if we are no longer in the same full-speed frame. */
  69513. + if (((state->channel[n].expected_uframe & 0x3FFF) & ~0x7) <
  69514. + (hfnum.b.frnum & ~0x7))
  69515. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  69516. + break;
  69517. + default:
  69518. + break;
  69519. + }
  69520. + }
  69521. + }
  69522. +
  69523. + for (n = 0; n < num_channels; n++) {
  69524. + switch (state->channel[n].fsm) {
  69525. +
  69526. + case FIQ_NP_SSPLIT_RETRY:
  69527. + case FIQ_NP_IN_CSPLIT_RETRY:
  69528. + case FIQ_NP_OUT_CSPLIT_RETRY:
  69529. + fiq_fsm_restart_channel(state, n, 0);
  69530. + break;
  69531. +
  69532. + case FIQ_HS_ISOC_SLEEPING:
  69533. + state->channel[n].fsm = FIQ_HS_ISOC_TURBO;
  69534. + fiq_fsm_restart_channel(state, n, 0);
  69535. + break;
  69536. +
  69537. + case FIQ_PER_SSPLIT_QUEUED:
  69538. + if ((hfnum.b.frnum & 0x7) == 5)
  69539. + break;
  69540. + if(!fiq_fsm_tt_in_use(state, num_channels, n)) {
  69541. + if (!fiq_fsm_too_late(state, n)) {
  69542. + fiq_print(FIQDBG_INT, st, "SOF GO %01d", n);
  69543. + fiq_fsm_restart_channel(state, n, 0);
  69544. + state->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  69545. + } else {
  69546. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  69547. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  69548. + kick_irq |= 1;
  69549. + }
  69550. + }
  69551. + break;
  69552. +
  69553. + case FIQ_PER_ISO_OUT_PENDING:
  69554. + /* Ordinarily, this should be poked after the SSPLIT
  69555. + * complete interrupt for a competing transfer on the same
  69556. + * TT. Doesn't happen for aborted transactions though.
  69557. + */
  69558. + if ((hfnum.b.frnum & 0x7) >= 5)
  69559. + break;
  69560. + if (!fiq_fsm_tt_in_use(state, num_channels, n)) {
  69561. + /* Hardware bug. SOF can sometimes occur after the channel halt interrupt
  69562. + * that caused this.
  69563. + */
  69564. + fiq_fsm_restart_channel(state, n, 0);
  69565. + fiq_print(FIQDBG_INT, state, "SOF ISOC");
  69566. + if (state->channel[n].nrpackets == 1) {
  69567. + state->channel[n].fsm = FIQ_PER_ISO_OUT_LAST;
  69568. + } else {
  69569. + state->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  69570. + }
  69571. + }
  69572. + break;
  69573. +
  69574. + case FIQ_PER_CSPLIT_WAIT:
  69575. + /* we are guaranteed to be in this state if and only if the SSPLIT interrupt
  69576. + * occurred when the bus transaction occurred. The SOF interrupt reversal bug
  69577. + * will utterly bugger this up though.
  69578. + */
  69579. + if (hfnum.b.frnum != state->channel[n].expected_uframe) {
  69580. + fiq_print(FIQDBG_INT, state, "SOFCS %d ", n);
  69581. + state->channel[n].fsm = FIQ_PER_CSPLIT_POLL;
  69582. + fiq_fsm_restart_channel(state, n, 0);
  69583. + fiq_fsm_start_next_periodic(state, num_channels);
  69584. +
  69585. + }
  69586. + break;
  69587. +
  69588. + case FIQ_PER_SPLIT_TIMEOUT:
  69589. + /* Ugly: we have to force a HCD interrupt.
  69590. + * Poke the mask for the channel in question.
  69591. + * We will take a fake SOF because of this, but
  69592. + * that's OK.
  69593. + */
  69594. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  69595. + kick_irq |= 1;
  69596. + break;
  69597. +
  69598. + default:
  69599. + break;
  69600. + }
  69601. + }
  69602. +
  69603. + if (state->kick_np_queues ||
  69604. + dwc_frame_num_le(state->next_sched_frame, hfnum.b.frnum))
  69605. + kick_irq |= 1;
  69606. +
  69607. + return !kick_irq;
  69608. +}
  69609. +
  69610. +
  69611. +/**
  69612. + * fiq_fsm_do_hcintr() - FSM host channel interrupt handler
  69613. + * @state: Pointer to the FIQ state struct
  69614. + * @num_channels: Number of channels as per hardware config
  69615. + * @n: channel for which HAINT(i) was raised
  69616. + *
  69617. + * An important property is that only the CHHLT interrupt is unmasked. Unfortunately, AHBerr is as well.
  69618. + */
  69619. +static int notrace noinline fiq_fsm_do_hcintr(struct fiq_state *state, int num_channels, int n)
  69620. +{
  69621. + hcint_data_t hcint;
  69622. + hcintmsk_data_t hcintmsk;
  69623. + hcint_data_t hcint_probe;
  69624. + hcchar_data_t hcchar;
  69625. + int handled = 0;
  69626. + int restart = 0;
  69627. + int last_csplit = 0;
  69628. + int start_next_periodic = 0;
  69629. + struct fiq_channel_state *st = &state->channel[n];
  69630. + hfnum_data_t hfnum;
  69631. +
  69632. + hcint.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT);
  69633. + hcintmsk.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK);
  69634. + hcint_probe.d32 = hcint.d32 & hcintmsk.d32;
  69635. +
  69636. + if (st->fsm != FIQ_PASSTHROUGH) {
  69637. + fiq_print(FIQDBG_INT, state, "HC%01d ST%02d", n, st->fsm);
  69638. + fiq_print(FIQDBG_INT, state, "%08x", hcint.d32);
  69639. + }
  69640. +
  69641. + switch (st->fsm) {
  69642. +
  69643. + case FIQ_PASSTHROUGH:
  69644. + case FIQ_DEQUEUE_ISSUED:
  69645. + /* doesn't belong to us, kick it upstairs */
  69646. + break;
  69647. +
  69648. + case FIQ_PASSTHROUGH_ERRORSTATE:
  69649. + /* We are here to emulate the error recovery mechanism of the dwc HCD.
  69650. + * Several interrupts are unmasked if a previous transaction failed - it's
  69651. + * death for the FIQ to attempt to handle them as the channel isn't halted.
  69652. + * Emulate what the HCD does in this situation: mask and continue.
  69653. + * The FSM has no other state setup so this has to be handled out-of-band.
  69654. + */
  69655. + fiq_print(FIQDBG_ERR, state, "ERRST %02d", n);
  69656. + if (hcint_probe.b.nak || hcint_probe.b.ack || hcint_probe.b.datatglerr) {
  69657. + fiq_print(FIQDBG_ERR, state, "RESET %02d", n);
  69658. + st->nr_errors = 0;
  69659. + hcintmsk.b.nak = 0;
  69660. + hcintmsk.b.ack = 0;
  69661. + hcintmsk.b.datatglerr = 0;
  69662. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, hcintmsk.d32);
  69663. + return 1;
  69664. + }
  69665. + if (hcint_probe.b.chhltd) {
  69666. + fiq_print(FIQDBG_ERR, state, "CHHLT %02d", n);
  69667. + fiq_print(FIQDBG_ERR, state, "%08x", hcint.d32);
  69668. + return 0;
  69669. + }
  69670. + break;
  69671. +
  69672. + /* Non-periodic state groups */
  69673. + case FIQ_NP_SSPLIT_STARTED:
  69674. + case FIQ_NP_SSPLIT_RETRY:
  69675. + /* Got a HCINT for a NP SSPLIT. Expected ACK / NAK / fail */
  69676. + if (hcint.b.ack) {
  69677. + /* SSPLIT complete. For OUT, the data has been sent. For IN, the LS transaction
  69678. + * will start shortly. SOF needs to kick the transaction to prevent a NYET flood.
  69679. + */
  69680. + if(st->hcchar_copy.b.epdir == 1)
  69681. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  69682. + else
  69683. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  69684. + st->nr_errors = 0;
  69685. + handled = 1;
  69686. + fiq_fsm_setup_csplit(state, n);
  69687. + } else if (hcint.b.nak) {
  69688. + // No buffer space in TT. Retry on a uframe boundary.
  69689. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  69690. + handled = 1;
  69691. + } else if (hcint.b.xacterr) {
  69692. + // The only other one we care about is xacterr. This implies HS bus error - retry.
  69693. + st->nr_errors++;
  69694. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  69695. + if (st->nr_errors >= 3) {
  69696. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69697. + } else {
  69698. + handled = 1;
  69699. + restart = 1;
  69700. + }
  69701. + } else {
  69702. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  69703. + handled = 0;
  69704. + restart = 0;
  69705. + }
  69706. + break;
  69707. +
  69708. + case FIQ_NP_IN_CSPLIT_RETRY:
  69709. + /* Received a CSPLIT done interrupt.
  69710. + * Expected Data/NAK/STALL/NYET for IN.
  69711. + */
  69712. + if (hcint.b.xfercomp) {
  69713. + /* For IN, data is present. */
  69714. + st->fsm = FIQ_NP_SPLIT_DONE;
  69715. + } else if (hcint.b.nak) {
  69716. + /* no endpoint data. Punt it upstairs */
  69717. + st->fsm = FIQ_NP_SPLIT_DONE;
  69718. + } else if (hcint.b.nyet) {
  69719. + /* CSPLIT NYET - retry on a uframe boundary. */
  69720. + handled = 1;
  69721. + st->nr_errors = 0;
  69722. + } else if (hcint.b.datatglerr) {
  69723. + /* data toggle errors do not set the xfercomp bit. */
  69724. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  69725. + } else if (hcint.b.xacterr) {
  69726. + /* HS error. Retry immediate */
  69727. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  69728. + st->nr_errors++;
  69729. + if (st->nr_errors >= 3) {
  69730. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69731. + } else {
  69732. + handled = 1;
  69733. + restart = 1;
  69734. + }
  69735. + } else if (hcint.b.stall) {
  69736. + /* A STALL implies either a LS bus error or a genuine STALL. */
  69737. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  69738. + } else {
  69739. + /* Hardware bug. It's possible in some cases to
  69740. + * get a channel halt with nothing else set when
  69741. + * the response was a NYET. Treat as local 3-strikes retry.
  69742. + */
  69743. + hcint_data_t hcint_test = hcint;
  69744. + hcint_test.b.chhltd = 0;
  69745. + if (!hcint_test.d32) {
  69746. + st->nr_errors++;
  69747. + if (st->nr_errors >= 3) {
  69748. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69749. + } else {
  69750. + handled = 1;
  69751. + }
  69752. + } else {
  69753. + /* Bail out if something unexpected happened */
  69754. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69755. + }
  69756. + }
  69757. + break;
  69758. +
  69759. + case FIQ_NP_OUT_CSPLIT_RETRY:
  69760. + /* Received a CSPLIT done interrupt.
  69761. + * Expected ACK/NAK/STALL/NYET/XFERCOMP for OUT.*/
  69762. + if (hcint.b.xfercomp) {
  69763. + st->fsm = FIQ_NP_SPLIT_DONE;
  69764. + } else if (hcint.b.nak) {
  69765. + // The HCD will implement the holdoff on frame boundaries.
  69766. + st->fsm = FIQ_NP_SPLIT_DONE;
  69767. + } else if (hcint.b.nyet) {
  69768. + // Hub still processing.
  69769. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  69770. + handled = 1;
  69771. + st->nr_errors = 0;
  69772. + //restart = 1;
  69773. + } else if (hcint.b.xacterr) {
  69774. + /* HS error. retry immediate */
  69775. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  69776. + st->nr_errors++;
  69777. + if (st->nr_errors >= 3) {
  69778. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69779. + } else {
  69780. + handled = 1;
  69781. + restart = 1;
  69782. + }
  69783. + } else if (hcint.b.stall) {
  69784. + /* LS bus error or genuine stall */
  69785. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  69786. + } else {
  69787. + /*
  69788. + * Hardware bug. It's possible in some cases to get a
  69789. + * channel halt with nothing else set when the response was a NYET.
  69790. + * Treat as local 3-strikes retry.
  69791. + */
  69792. + hcint_data_t hcint_test = hcint;
  69793. + hcint_test.b.chhltd = 0;
  69794. + if (!hcint_test.d32) {
  69795. + st->nr_errors++;
  69796. + if (st->nr_errors >= 3) {
  69797. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69798. + } else {
  69799. + handled = 1;
  69800. + }
  69801. + } else {
  69802. + // Something unexpected happened. AHBerror or babble perhaps. Let the IRQ deal with it.
  69803. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69804. + }
  69805. + }
  69806. + break;
  69807. +
  69808. + /* Periodic split states (except isoc out) */
  69809. + case FIQ_PER_SSPLIT_STARTED:
  69810. + /* Expect an ACK or failure for SSPLIT */
  69811. + if (hcint.b.ack) {
  69812. + /*
  69813. + * SSPLIT transfer complete interrupt - the generation of this interrupt is fraught with bugs.
  69814. + * For a packet queued in microframe n-3 to appear in n-2, if the channel is enabled near the EOF1
  69815. + * point for microframe n-3, the packet will not appear on the bus until microframe n.
  69816. + * Additionally, the generation of the actual interrupt is dodgy. For a packet appearing on the bus
  69817. + * in microframe n, sometimes the interrupt is generated immediately. Sometimes, it appears in n+1
  69818. + * coincident with SOF for n+1.
  69819. + * SOF is also buggy. It can sometimes be raised AFTER the first bus transaction has taken place.
  69820. + * These appear to be caused by timing/clock crossing bugs within the core itself.
  69821. + * State machine workaround.
  69822. + */
  69823. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  69824. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  69825. + fiq_fsm_setup_csplit(state, n);
  69826. + /* Poke the oddfrm bit. If we are equivalent, we received the interrupt at the correct
  69827. + * time. If not, then we're in the next SOF.
  69828. + */
  69829. + if ((hfnum.b.frnum & 0x1) == hcchar.b.oddfrm) {
  69830. + fiq_print(FIQDBG_INT, state, "CSWAIT %01d", n);
  69831. + st->expected_uframe = hfnum.b.frnum;
  69832. + st->fsm = FIQ_PER_CSPLIT_WAIT;
  69833. + } else {
  69834. + fiq_print(FIQDBG_INT, state, "CSPOL %01d", n);
  69835. + /* For isochronous IN endpoints,
  69836. + * we need to hold off if we are expecting a lot of data */
  69837. + if (st->hcchar_copy.b.mps < DATA0_PID_HEURISTIC) {
  69838. + start_next_periodic = 1;
  69839. + }
  69840. + /* Danger will robinson: we are in a broken state. If our first interrupt after
  69841. + * this is a NYET, it will be delayed by 1 uframe and result in an unrecoverable
  69842. + * lag. Unmask the NYET interrupt.
  69843. + */
  69844. + st->expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  69845. + st->fsm = FIQ_PER_CSPLIT_BROKEN_NYET1;
  69846. + restart = 1;
  69847. + }
  69848. + handled = 1;
  69849. + } else if (hcint.b.xacterr) {
  69850. + /* 3-strikes retry is enabled, we have hit our max nr_errors */
  69851. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  69852. + start_next_periodic = 1;
  69853. + } else {
  69854. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  69855. + start_next_periodic = 1;
  69856. + }
  69857. + /* We can now queue the next isochronous OUT transaction, if one is pending. */
  69858. + if(fiq_fsm_tt_next_isoc(state, num_channels, n)) {
  69859. + fiq_print(FIQDBG_INT, state, "NEXTISO ");
  69860. + }
  69861. + break;
  69862. +
  69863. + case FIQ_PER_CSPLIT_NYET1:
  69864. + /* First CSPLIT attempt was a NYET. If we get a subsequent NYET,
  69865. + * we are too late and the TT has dropped its CSPLIT fifo.
  69866. + */
  69867. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  69868. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  69869. + start_next_periodic = 1;
  69870. + if (hcint.b.nak) {
  69871. + st->fsm = FIQ_PER_SPLIT_DONE;
  69872. + } else if (hcint.b.xfercomp) {
  69873. + fiq_increment_dma_buf(state, num_channels, n);
  69874. + st->fsm = FIQ_PER_CSPLIT_POLL;
  69875. + st->nr_errors = 0;
  69876. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  69877. + handled = 1;
  69878. + restart = 1;
  69879. + if (!last_csplit)
  69880. + start_next_periodic = 0;
  69881. + } else {
  69882. + st->fsm = FIQ_PER_SPLIT_DONE;
  69883. + }
  69884. + } else if (hcint.b.nyet) {
  69885. + /* Doh. Data lost. */
  69886. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  69887. + } else if (hcint.b.xacterr || hcint.b.stall) {
  69888. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  69889. + } else {
  69890. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  69891. + }
  69892. + break;
  69893. +
  69894. + case FIQ_PER_CSPLIT_BROKEN_NYET1:
  69895. + /*
  69896. + * we got here because our host channel is in the delayed-interrupt
  69897. + * state and we cannot take a NYET interrupt any later than when it
  69898. + * occurred. Disable then re-enable the channel if this happens to force
  69899. + * CSPLITs to occur at the right time.
  69900. + */
  69901. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  69902. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  69903. + fiq_print(FIQDBG_INT, state, "BROK: %01d ", n);
  69904. + if (hcint.b.nak) {
  69905. + st->fsm = FIQ_PER_SPLIT_DONE;
  69906. + start_next_periodic = 1;
  69907. + } else if (hcint.b.xfercomp) {
  69908. + fiq_increment_dma_buf(state, num_channels, n);
  69909. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  69910. + st->fsm = FIQ_PER_CSPLIT_POLL;
  69911. + handled = 1;
  69912. + restart = 1;
  69913. + start_next_periodic = 1;
  69914. + /* Reload HCTSIZ for the next transfer */
  69915. + fiq_fsm_reload_hctsiz(state, n);
  69916. + if (!last_csplit)
  69917. + start_next_periodic = 0;
  69918. + } else {
  69919. + st->fsm = FIQ_PER_SPLIT_DONE;
  69920. + }
  69921. + } else if (hcint.b.nyet) {
  69922. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  69923. + start_next_periodic = 1;
  69924. + } else if (hcint.b.xacterr) {
  69925. + /* Local 3-strikes retry is handled by the core. This is a ERR response.*/
  69926. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  69927. + } else {
  69928. + fiq_print(FIQDBG_INT, state, "TOGGLES");
  69929. + BUG();
  69930. + }
  69931. + break;
  69932. +
  69933. + case FIQ_PER_CSPLIT_POLL:
  69934. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  69935. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  69936. + start_next_periodic = 1;
  69937. + if (hcint.b.nak) {
  69938. + st->fsm = FIQ_PER_SPLIT_DONE;
  69939. + } else if (hcint.b.xfercomp) {
  69940. + fiq_increment_dma_buf(state, num_channels, n);
  69941. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  69942. + handled = 1;
  69943. + restart = 1;
  69944. + /* Reload HCTSIZ for the next transfer */
  69945. + fiq_fsm_reload_hctsiz(state, n);
  69946. + if (!last_csplit)
  69947. + start_next_periodic = 0;
  69948. + } else {
  69949. + st->fsm = FIQ_PER_SPLIT_DONE;
  69950. + }
  69951. + } else if (hcint.b.nyet) {
  69952. + /* Are we a NYET after the first data packet? */
  69953. + if (st->nrpackets == 0) {
  69954. + st->fsm = FIQ_PER_CSPLIT_NYET1;
  69955. + handled = 1;
  69956. + restart = 1;
  69957. + } else {
  69958. + /* We got a NYET when polling CSPLITs. Can happen
  69959. + * if our heuristic fails, or if someone disables us
  69960. + * for any significant length of time.
  69961. + */
  69962. + if (st->nr_errors >= 3) {
  69963. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  69964. + } else {
  69965. + st->fsm = FIQ_PER_SPLIT_DONE;
  69966. + }
  69967. + }
  69968. + } else if (hcint.b.xacterr || hcint.b.stall) {
  69969. + /* For xacterr, Local 3-strikes retry is handled by the core. This is a ERR response.*/
  69970. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  69971. + } else if (hcint.b.datatglerr) {
  69972. + fiq_print(FIQDBG_INT, state, "TOGGLES");
  69973. + BUG();
  69974. + } else {
  69975. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  69976. + }
  69977. + break;
  69978. +
  69979. + case FIQ_HS_ISOC_TURBO:
  69980. + if (fiq_fsm_update_hs_isoc(state, n, hcint)) {
  69981. + /* more transactions to come */
  69982. + handled = 1;
  69983. + restart = 1;
  69984. + fiq_print(FIQDBG_INT, state, "HSISO M ");
  69985. + } else {
  69986. + st->fsm = FIQ_HS_ISOC_DONE;
  69987. + fiq_print(FIQDBG_INT, state, "HSISO F ");
  69988. + }
  69989. + break;
  69990. +
  69991. + case FIQ_HS_ISOC_ABORTED:
  69992. + /* This abort is called by the driver rewriting the state mid-transaction
  69993. + * which allows the dequeue mechanism to work more effectively.
  69994. + */
  69995. + break;
  69996. +
  69997. + case FIQ_PER_ISO_OUT_ACTIVE:
  69998. + if (hcint.b.ack) {
  69999. + if(fiq_iso_out_advance(state, num_channels, n)) {
  70000. + /* last OUT transfer */
  70001. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  70002. + /*
  70003. + * Assuming the periodic FIFO in the dwc core
  70004. + * actually does its job properly, we can queue
  70005. + * the next ssplit now and in theory, the wire
  70006. + * transactions will be in-order.
  70007. + */
  70008. + // No it doesn't. It appears to process requests in host channel order.
  70009. + //start_next_periodic = 1;
  70010. + }
  70011. + handled = 1;
  70012. + restart = 1;
  70013. + } else {
  70014. + /*
  70015. + * Isochronous transactions carry on regardless. Log the error
  70016. + * and continue.
  70017. + */
  70018. + //explode += 1;
  70019. + st->nr_errors++;
  70020. + if(fiq_iso_out_advance(state, num_channels, n)) {
  70021. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  70022. + //start_next_periodic = 1;
  70023. + }
  70024. + handled = 1;
  70025. + restart = 1;
  70026. + }
  70027. + break;
  70028. +
  70029. + case FIQ_PER_ISO_OUT_LAST:
  70030. + if (hcint.b.ack) {
  70031. + /* All done here */
  70032. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  70033. + } else {
  70034. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  70035. + st->nr_errors++;
  70036. + }
  70037. + start_next_periodic = 1;
  70038. + break;
  70039. +
  70040. + case FIQ_PER_SPLIT_TIMEOUT:
  70041. + /* SOF kicked us because we overran. */
  70042. + start_next_periodic = 1;
  70043. + break;
  70044. +
  70045. + default:
  70046. + break;
  70047. + }
  70048. +
  70049. + if (handled) {
  70050. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT, hcint.d32);
  70051. + } else {
  70052. + /* Copy the regs into the state so the IRQ knows what to do */
  70053. + st->hcint_copy.d32 = hcint.d32;
  70054. + }
  70055. +
  70056. + if (restart) {
  70057. + /* Restart always implies handled. */
  70058. + if (restart == 2) {
  70059. + /* For complete-split INs, the show must go on.
  70060. + * Force a channel restart */
  70061. + fiq_fsm_restart_channel(state, n, 1);
  70062. + } else {
  70063. + fiq_fsm_restart_channel(state, n, 0);
  70064. + }
  70065. + }
  70066. + if (start_next_periodic) {
  70067. + fiq_fsm_start_next_periodic(state, num_channels);
  70068. + }
  70069. + if (st->fsm != FIQ_PASSTHROUGH)
  70070. + fiq_print(FIQDBG_INT, state, "FSMOUT%02d", st->fsm);
  70071. +
  70072. + return handled;
  70073. +}
  70074. +
  70075. +
  70076. +/**
  70077. + * dwc_otg_fiq_fsm() - Flying State Machine (monster) FIQ
  70078. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  70079. + * @num_channels: set according to the DWC hardware configuration
  70080. + * @dma: pointer to DMA bounce buffers for split transaction slots
  70081. + *
  70082. + * The FSM FIQ performs the low-level tasks that normally would be performed by the microcode
  70083. + * inside an EHCI or similar host controller regarding split transactions. The DWC core
  70084. + * interrupts each and every time a split transaction packet is received or sent successfully.
  70085. + * This results in either an interrupt storm when everything is working "properly", or
  70086. + * the interrupt latency of the system in general breaks time-sensitive periodic split
  70087. + * transactions. Pushing the low-level, but relatively easy state machine work into the FIQ
  70088. + * solves these problems.
  70089. + *
  70090. + * Return: void
  70091. + */
  70092. +void notrace dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels)
  70093. +{
  70094. + gintsts_data_t gintsts, gintsts_handled;
  70095. + gintmsk_data_t gintmsk;
  70096. + //hfnum_data_t hfnum;
  70097. + haint_data_t haint, haint_handled;
  70098. + haintmsk_data_t haintmsk;
  70099. + int kick_irq = 0;
  70100. +
  70101. + gintsts_handled.d32 = 0;
  70102. + haint_handled.d32 = 0;
  70103. +
  70104. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  70105. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  70106. + gintsts.d32 &= gintmsk.d32;
  70107. +
  70108. + if (gintsts.b.sofintr) {
  70109. + /* For FSM mode, SOF is required to keep the state machine advance for
  70110. + * certain stages of the periodic pipeline. It's death to mask this
  70111. + * interrupt in that case.
  70112. + */
  70113. +
  70114. + if (!fiq_fsm_do_sof(state, num_channels)) {
  70115. + /* Kick IRQ once. Queue advancement means that all pending transactions
  70116. + * will get serviced when the IRQ finally executes.
  70117. + */
  70118. + if (state->gintmsk_saved.b.sofintr == 1)
  70119. + kick_irq |= 1;
  70120. + state->gintmsk_saved.b.sofintr = 0;
  70121. + }
  70122. + gintsts_handled.b.sofintr = 1;
  70123. + }
  70124. +
  70125. + if (gintsts.b.hcintr) {
  70126. + int i;
  70127. + haint.d32 = FIQ_READ(state->dwc_regs_base + HAINT);
  70128. + haintmsk.d32 = FIQ_READ(state->dwc_regs_base + HAINTMSK);
  70129. + haint.d32 &= haintmsk.d32;
  70130. + haint_handled.d32 = 0;
  70131. + for (i=0; i<num_channels; i++) {
  70132. + if (haint.b2.chint & (1 << i)) {
  70133. + if(!fiq_fsm_do_hcintr(state, num_channels, i)) {
  70134. + /* HCINT was not handled in FIQ
  70135. + * HAINT is level-sensitive, leading to level-sensitive ginststs.b.hcint bit.
  70136. + * Mask HAINT(i) but keep top-level hcint unmasked.
  70137. + */
  70138. + state->haintmsk_saved.b2.chint &= ~(1 << i);
  70139. + } else {
  70140. + /* do_hcintr cleaned up after itself, but clear haint */
  70141. + haint_handled.b2.chint |= (1 << i);
  70142. + }
  70143. + }
  70144. + }
  70145. +
  70146. + if (haint_handled.b2.chint) {
  70147. + FIQ_WRITE(state->dwc_regs_base + HAINT, haint_handled.d32);
  70148. + }
  70149. +
  70150. + if (haintmsk.d32 != (haintmsk.d32 & state->haintmsk_saved.d32)) {
  70151. + /*
  70152. + * This is necessary to avoid multiple retriggers of the MPHI in the case
  70153. + * where interrupts are held off and HCINTs start to pile up.
  70154. + * Only wake up the IRQ if a new interrupt came in, was not handled and was
  70155. + * masked.
  70156. + */
  70157. + haintmsk.d32 &= state->haintmsk_saved.d32;
  70158. + FIQ_WRITE(state->dwc_regs_base + HAINTMSK, haintmsk.d32);
  70159. + kick_irq |= 1;
  70160. + }
  70161. + /* Top-Level interrupt - always handled because it's level-sensitive */
  70162. + gintsts_handled.b.hcintr = 1;
  70163. + }
  70164. +
  70165. +
  70166. + /* Clear the bits in the saved register that were not handled but were triggered. */
  70167. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  70168. +
  70169. + /* FIQ didn't handle something - mask has changed - write new mask */
  70170. + if (gintmsk.d32 != (gintmsk.d32 & state->gintmsk_saved.d32)) {
  70171. + gintmsk.d32 &= state->gintmsk_saved.d32;
  70172. + gintmsk.b.sofintr = 1;
  70173. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  70174. +// fiq_print(FIQDBG_INT, state, "KICKGINT");
  70175. +// fiq_print(FIQDBG_INT, state, "%08x", gintmsk.d32);
  70176. +// fiq_print(FIQDBG_INT, state, "%08x", state->gintmsk_saved.d32);
  70177. + kick_irq |= 1;
  70178. + }
  70179. +
  70180. + if (gintsts_handled.d32) {
  70181. + /* Only applies to edge-sensitive bits in GINTSTS */
  70182. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  70183. + }
  70184. +
  70185. + /* We got an interrupt, didn't handle it. */
  70186. + if (kick_irq) {
  70187. + state->mphi_int_count++;
  70188. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  70189. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  70190. +
  70191. + }
  70192. + state->fiq_done++;
  70193. + mb();
  70194. +}
  70195. +
  70196. +
  70197. +/**
  70198. + * dwc_otg_fiq_nop() - FIQ "lite"
  70199. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  70200. + *
  70201. + * The "nop" handler does not intervene on any interrupts other than SOF.
  70202. + * It is limited in scope to deciding at each SOF if the IRQ SOF handler (which deals
  70203. + * with non-periodic/periodic queues) needs to be kicked.
  70204. + *
  70205. + * This is done to hold off the SOF interrupt, which occurs at a rate of 8000 per second.
  70206. + *
  70207. + * Return: void
  70208. + */
  70209. +void notrace dwc_otg_fiq_nop(struct fiq_state *state)
  70210. +{
  70211. + gintsts_data_t gintsts, gintsts_handled;
  70212. + gintmsk_data_t gintmsk;
  70213. + hfnum_data_t hfnum;
  70214. +
  70215. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  70216. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  70217. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  70218. + gintsts.d32 &= gintmsk.d32;
  70219. + gintsts_handled.d32 = 0;
  70220. +
  70221. + if (gintsts.b.sofintr) {
  70222. + if (!state->kick_np_queues &&
  70223. + dwc_frame_num_gt(state->next_sched_frame, hfnum.b.frnum)) {
  70224. + /* SOF handled, no work to do, just ACK interrupt */
  70225. + gintsts_handled.b.sofintr = 1;
  70226. + } else {
  70227. + /* Kick IRQ */
  70228. + state->gintmsk_saved.b.sofintr = 0;
  70229. + }
  70230. + }
  70231. +
  70232. + /* Reset handled interrupts */
  70233. + if(gintsts_handled.d32) {
  70234. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  70235. + }
  70236. +
  70237. + /* Clear the bits in the saved register that were not handled but were triggered. */
  70238. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  70239. +
  70240. + /* We got an interrupt, didn't handle it and want to mask it */
  70241. + if (~(state->gintmsk_saved.d32)) {
  70242. + state->mphi_int_count++;
  70243. + gintmsk.d32 &= state->gintmsk_saved.d32;
  70244. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  70245. + /* Force a clear before another dummy send */
  70246. + FIQ_WRITE(state->mphi_regs.intstat, (1<<29));
  70247. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  70248. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  70249. +
  70250. + }
  70251. + state->fiq_done++;
  70252. + mb();
  70253. +}
  70254. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
  70255. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 1970-01-01 01:00:00.000000000 +0100
  70256. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 2014-04-24 16:04:39.819124254 +0200
  70257. @@ -0,0 +1,353 @@
  70258. +/*
  70259. + * dwc_otg_fiq_fsm.h - Finite state machine FIQ header definitions
  70260. + *
  70261. + * Copyright (c) 2013 Raspberry Pi Foundation
  70262. + *
  70263. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  70264. + * All rights reserved.
  70265. + *
  70266. + * Redistribution and use in source and binary forms, with or without
  70267. + * modification, are permitted provided that the following conditions are met:
  70268. + * * Redistributions of source code must retain the above copyright
  70269. + * notice, this list of conditions and the following disclaimer.
  70270. + * * Redistributions in binary form must reproduce the above copyright
  70271. + * notice, this list of conditions and the following disclaimer in the
  70272. + * documentation and/or other materials provided with the distribution.
  70273. + * * Neither the name of Raspberry Pi nor the
  70274. + * names of its contributors may be used to endorse or promote products
  70275. + * derived from this software without specific prior written permission.
  70276. + *
  70277. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  70278. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  70279. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  70280. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  70281. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  70282. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  70283. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  70284. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  70285. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  70286. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  70287. + *
  70288. + * This FIQ implements functionality that performs split transactions on
  70289. + * the dwc_otg hardware without any outside intervention. A split transaction
  70290. + * is "queued" by nominating a specific host channel to perform the entirety
  70291. + * of a split transaction. This FIQ will then perform the microframe-precise
  70292. + * scheduling required in each phase of the transaction until completion.
  70293. + *
  70294. + * The FIQ functionality has been surgically implanted into the Synopsys
  70295. + * vendor-provided driver.
  70296. + *
  70297. + */
  70298. +
  70299. +#ifndef DWC_OTG_FIQ_FSM_H_
  70300. +#define DWC_OTG_FIQ_FSM_H_
  70301. +
  70302. +#include "dwc_otg_regs.h"
  70303. +#include "dwc_otg_cil.h"
  70304. +#include "dwc_otg_hcd.h"
  70305. +#include <linux/kernel.h>
  70306. +#include <linux/irqflags.h>
  70307. +#include <linux/string.h>
  70308. +#include <asm/barrier.h>
  70309. +
  70310. +#if 0
  70311. +#define FLAME_ON(x) \
  70312. +do { \
  70313. + int gpioreg; \
  70314. + \
  70315. + gpioreg = readl(__io_address(0x20200000+0x8)); \
  70316. + gpioreg &= ~(7 << (x-20)*3); \
  70317. + gpioreg |= 0x1 << (x-20)*3; \
  70318. + writel(gpioreg, __io_address(0x20200000+0x8)); \
  70319. + \
  70320. + writel(1<<x, __io_address(0x20200000+(0x1C))); \
  70321. +} while (0)
  70322. +
  70323. +#define FLAME_OFF(x) \
  70324. +do { \
  70325. + writel(1<<x, __io_address(0x20200000+(0x28))); \
  70326. +} while (0)
  70327. +#else
  70328. +#define FLAME_ON(x) do { } while (0)
  70329. +#define FLAME_OFF(X) do { } while (0)
  70330. +#endif
  70331. +
  70332. +/* This is a quick-and-dirty arch-specific register read/write. We know that
  70333. + * writes to a peripheral on BCM2835 will always arrive in-order, also that
  70334. + * reads and writes are executed in-order therefore the need for memory barriers
  70335. + * is obviated if we're only talking to USB.
  70336. + */
  70337. +#define FIQ_WRITE(_addr_,_data_) (*(volatile unsigned int *) (_addr_) = (_data_))
  70338. +#define FIQ_READ(_addr_) (*(volatile unsigned int *) (_addr_))
  70339. +
  70340. +/* FIQ-ified register definitions. Offsets are from dwc_regs_base. */
  70341. +#define GINTSTS 0x014
  70342. +#define GINTMSK 0x018
  70343. +/* Debug register. Poll the top of the received packets FIFO. */
  70344. +#define GRXSTSR 0x01C
  70345. +#define HFNUM 0x408
  70346. +#define HAINT 0x414
  70347. +#define HAINTMSK 0x418
  70348. +#define HPRT0 0x440
  70349. +
  70350. +/* HC_regs start from an offset of 0x500 */
  70351. +#define HC_START 0x500
  70352. +#define HC_OFFSET 0x020
  70353. +
  70354. +#define HC_DMA 0x514
  70355. +
  70356. +#define HCCHAR 0x00
  70357. +#define HCSPLT 0x04
  70358. +#define HCINT 0x08
  70359. +#define HCINTMSK 0x0C
  70360. +#define HCTSIZ 0x10
  70361. +
  70362. +#define ISOC_XACTPOS_ALL 0b11
  70363. +#define ISOC_XACTPOS_BEGIN 0b10
  70364. +#define ISOC_XACTPOS_MID 0b00
  70365. +#define ISOC_XACTPOS_END 0b01
  70366. +
  70367. +#define DWC_PID_DATA2 0b01
  70368. +#define DWC_PID_MDATA 0b11
  70369. +#define DWC_PID_DATA1 0b10
  70370. +#define DWC_PID_DATA0 0b00
  70371. +
  70372. +typedef struct {
  70373. + volatile void* base;
  70374. + volatile void* ctrl;
  70375. + volatile void* outdda;
  70376. + volatile void* outddb;
  70377. + volatile void* intstat;
  70378. +} mphi_regs_t;
  70379. +
  70380. +
  70381. +enum fiq_debug_level {
  70382. + FIQDBG_SCHED = (1 << 0),
  70383. + FIQDBG_INT = (1 << 1),
  70384. + FIQDBG_ERR = (1 << 2),
  70385. + FIQDBG_PORTHUB = (1 << 3),
  70386. +};
  70387. +
  70388. +struct fiq_state;
  70389. +
  70390. +extern void _fiq_print (enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...);
  70391. +#if 0
  70392. +#define fiq_print _fiq_print
  70393. +#else
  70394. +#define fiq_print(x, y, ...)
  70395. +#endif
  70396. +
  70397. +extern bool fiq_enable, fiq_fsm_enable;
  70398. +extern ushort nak_holdoff;
  70399. +
  70400. +/**
  70401. + * enum fiq_fsm_state - The FIQ FSM states.
  70402. + *
  70403. + * This is the "core" of the FIQ FSM. Broadly, the FSM states follow the
  70404. + * USB2.0 specification for host responses to various transaction states.
  70405. + * There are modifications to this host state machine because of a variety of
  70406. + * quirks and limitations in the dwc_otg hardware.
  70407. + *
  70408. + * The fsm state is also used to communicate back to the driver on completion of
  70409. + * a split transaction. The end states are used in conjunction with the interrupts
  70410. + * raised by the final transaction.
  70411. + */
  70412. +enum fiq_fsm_state {
  70413. + /* FIQ isn't enabled for this host channel */
  70414. + FIQ_PASSTHROUGH = 0,
  70415. + /* For the first interrupt received for this channel,
  70416. + * the FIQ has to ack any interrupts indicating success. */
  70417. + FIQ_PASSTHROUGH_ERRORSTATE = 31,
  70418. + /* Nonperiodic state groups */
  70419. + FIQ_NP_SSPLIT_STARTED = 1,
  70420. + FIQ_NP_SSPLIT_RETRY = 2,
  70421. + FIQ_NP_OUT_CSPLIT_RETRY = 3,
  70422. + FIQ_NP_IN_CSPLIT_RETRY = 4,
  70423. + FIQ_NP_SPLIT_DONE = 5,
  70424. + FIQ_NP_SPLIT_LS_ABORTED = 6,
  70425. + /* This differentiates a HS transaction error from a LS one
  70426. + * (handling the hub state is different) */
  70427. + FIQ_NP_SPLIT_HS_ABORTED = 7,
  70428. +
  70429. + /* Periodic state groups */
  70430. + /* Periodic transactions are either started directly by the IRQ handler
  70431. + * or deferred if the TT is already in use.
  70432. + */
  70433. + FIQ_PER_SSPLIT_QUEUED = 8,
  70434. + FIQ_PER_SSPLIT_STARTED = 9,
  70435. + FIQ_PER_SSPLIT_LAST = 10,
  70436. +
  70437. +
  70438. + FIQ_PER_ISO_OUT_PENDING = 11,
  70439. + FIQ_PER_ISO_OUT_ACTIVE = 12,
  70440. + FIQ_PER_ISO_OUT_LAST = 13,
  70441. + FIQ_PER_ISO_OUT_DONE = 27,
  70442. +
  70443. + FIQ_PER_CSPLIT_WAIT = 14,
  70444. + FIQ_PER_CSPLIT_NYET1 = 15,
  70445. + FIQ_PER_CSPLIT_BROKEN_NYET1 = 28,
  70446. + FIQ_PER_CSPLIT_NYET_FAFF = 29,
  70447. + /* For multiple CSPLITs (large isoc IN, or delayed interrupt) */
  70448. + FIQ_PER_CSPLIT_POLL = 16,
  70449. + /* The last CSPLIT for a transaction has been issued, differentiates
  70450. + * for the state machine to queue the next packet.
  70451. + */
  70452. + FIQ_PER_CSPLIT_LAST = 17,
  70453. +
  70454. + FIQ_PER_SPLIT_DONE = 18,
  70455. + FIQ_PER_SPLIT_LS_ABORTED = 19,
  70456. + FIQ_PER_SPLIT_HS_ABORTED = 20,
  70457. + FIQ_PER_SPLIT_NYET_ABORTED = 21,
  70458. + /* Frame rollover has occurred without the transaction finishing. */
  70459. + FIQ_PER_SPLIT_TIMEOUT = 22,
  70460. +
  70461. + /* FIQ-accelerated HS Isochronous state groups */
  70462. + FIQ_HS_ISOC_TURBO = 23,
  70463. + /* For interval > 1, SOF wakes up the isochronous FSM */
  70464. + FIQ_HS_ISOC_SLEEPING = 24,
  70465. + FIQ_HS_ISOC_DONE = 25,
  70466. + FIQ_HS_ISOC_ABORTED = 26,
  70467. + FIQ_DEQUEUE_ISSUED = 30,
  70468. + FIQ_TEST = 32,
  70469. +};
  70470. +
  70471. +struct fiq_stack {
  70472. + int magic1;
  70473. + uint8_t stack[2048];
  70474. + int magic2;
  70475. +};
  70476. +
  70477. +
  70478. +/**
  70479. + * struct fiq_dma_info - DMA bounce buffer utilisation information (per-channel)
  70480. + * @index: Number of slots reported used for IN transactions / number of slots
  70481. + * transmitted for an OUT transaction
  70482. + * @slot_len[6]: Number of actual transfer bytes in each slot (255 if unused)
  70483. + *
  70484. + * Split transaction transfers can have variable length depending on other bus
  70485. + * traffic. The OTG core DMA engine requires 4-byte aligned addresses therefore
  70486. + * each transaction needs a guaranteed aligned address. A maximum of 6 split transfers
  70487. + * can happen per-frame.
  70488. + */
  70489. +struct fiq_dma_info {
  70490. + u8 index;
  70491. + u8 slot_len[6];
  70492. +};
  70493. +
  70494. +struct __attribute__((packed)) fiq_split_dma_slot {
  70495. + u8 buf[188];
  70496. +};
  70497. +
  70498. +struct fiq_dma_channel {
  70499. + struct __attribute__((packed)) fiq_split_dma_slot index[6];
  70500. +};
  70501. +
  70502. +struct fiq_dma_blob {
  70503. + struct __attribute__((packed)) fiq_dma_channel channel[0];
  70504. +};
  70505. +
  70506. +/**
  70507. + * struct fiq_hs_isoc_info - USB2.0 isochronous data
  70508. + * @iso_frame: Pointer to the array of OTG URB iso_frame_descs.
  70509. + * @nrframes: Total length of iso_frame_desc array
  70510. + * @index: Current index (FIQ-maintained)
  70511. + *
  70512. + */
  70513. +struct fiq_hs_isoc_info {
  70514. + struct dwc_otg_hcd_iso_packet_desc *iso_desc;
  70515. + unsigned int nrframes;
  70516. + unsigned int index;
  70517. +};
  70518. +
  70519. +/**
  70520. + * struct fiq_channel_state - FIQ state machine storage
  70521. + * @fsm: Current state of the channel as understood by the FIQ
  70522. + * @nr_errors: Number of transaction errors on this split-transaction
  70523. + * @hub_addr: SSPLIT/CSPLIT destination hub
  70524. + * @port_addr: SSPLIT/CSPLIT destination port - always 1 if single TT hub
  70525. + * @nrpackets: For isoc OUT, the number of split-OUT packets to transmit. For
  70526. + * split-IN, number of CSPLIT data packets that were received.
  70527. + * @hcchar_copy:
  70528. + * @hcsplt_copy:
  70529. + * @hcintmsk_copy:
  70530. + * @hctsiz_copy: Copies of the host channel registers.
  70531. + * For use as scratch, or for returning state.
  70532. + *
  70533. + * The fiq_channel_state is state storage between interrupts for a host channel. The
  70534. + * FSM state is stored here. Members of this structure must only be set up by the
  70535. + * driver prior to enabling the FIQ for this host channel, and not touched until the FIQ
  70536. + * has updated the state to either a COMPLETE state group or ABORT state group.
  70537. + */
  70538. +
  70539. +struct fiq_channel_state {
  70540. + enum fiq_fsm_state fsm;
  70541. + unsigned int nr_errors;
  70542. + unsigned int hub_addr;
  70543. + unsigned int port_addr;
  70544. + /* Hardware bug workaround: sometimes channel halt interrupts are
  70545. + * delayed until the next SOF. Keep track of when we expected to get interrupted. */
  70546. + unsigned int expected_uframe;
  70547. + /* in/out for communicating number of dma buffers used, or number of ISOC to do */
  70548. + unsigned int nrpackets;
  70549. + struct fiq_dma_info dma_info;
  70550. + struct fiq_hs_isoc_info hs_isoc_info;
  70551. + /* Copies of HC registers - in/out communication from/to IRQ handler
  70552. + * and for ease of channel setup. A bit of mungeing is performed - for
  70553. + * example the hctsiz.b.maxp is _always_ the max packet size of the endpoint.
  70554. + */
  70555. + hcchar_data_t hcchar_copy;
  70556. + hcsplt_data_t hcsplt_copy;
  70557. + hcint_data_t hcint_copy;
  70558. + hcintmsk_data_t hcintmsk_copy;
  70559. + hctsiz_data_t hctsiz_copy;
  70560. + hcdma_data_t hcdma_copy;
  70561. +};
  70562. +
  70563. +/**
  70564. + * struct fiq_state - top-level FIQ state machine storage
  70565. + * @mphi_regs: virtual address of the MPHI peripheral register file
  70566. + * @dwc_regs_base: virtual address of the base of the DWC core register file
  70567. + * @dma_base: physical address for the base of the DMA bounce buffers
  70568. + * @dummy_send: Scratch area for sending a fake message to the MPHI peripheral
  70569. + * @gintmsk_saved: Top-level mask of interrupts that the FIQ has not handled.
  70570. + * Used for determining which interrupts fired to set off the IRQ handler.
  70571. + * @haintmsk_saved: Mask of interrupts from host channels that the FIQ did not handle internally.
  70572. + * @np_count: Non-periodic transactions in the active queue
  70573. + * @np_sent: Count of non-periodic transactions that have completed
  70574. + * @next_sched_frame: For periodic transactions handled by the driver's SOF-driven queuing mechanism,
  70575. + * this is the next frame on which a SOF interrupt is required. Used to hold off
  70576. + * passing SOF through to the driver until necessary.
  70577. + * @channel[n]: Per-channel FIQ state. Allocated during init depending on the number of host
  70578. + * channels configured into the core logic.
  70579. + *
  70580. + * This is passed as the first argument to the dwc_otg_fiq_fsm top-level FIQ handler from the asm stub.
  70581. + * It contains top-level state information.
  70582. + */
  70583. +struct fiq_state {
  70584. + mphi_regs_t mphi_regs;
  70585. + void *dwc_regs_base;
  70586. + dma_addr_t dma_base;
  70587. + struct fiq_dma_blob *fiq_dmab;
  70588. + void *dummy_send;
  70589. + gintmsk_data_t gintmsk_saved;
  70590. + haintmsk_data_t haintmsk_saved;
  70591. + int mphi_int_count;
  70592. + unsigned int fiq_done;
  70593. + unsigned int kick_np_queues;
  70594. + unsigned int next_sched_frame;
  70595. +#ifdef FIQ_DEBUG
  70596. + char * buffer;
  70597. + unsigned int bufsiz;
  70598. +#endif
  70599. + struct fiq_channel_state channel[0];
  70600. +};
  70601. +
  70602. +extern int fiq_fsm_too_late(struct fiq_state *st, int n);
  70603. +
  70604. +extern int fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n);
  70605. +
  70606. +extern void dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels);
  70607. +
  70608. +extern void dwc_otg_fiq_nop(struct fiq_state *state);
  70609. +
  70610. +#endif /* DWC_OTG_FIQ_FSM_H_ */
  70611. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S
  70612. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 1970-01-01 01:00:00.000000000 +0100
  70613. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 2014-04-24 16:04:39.819124254 +0200
  70614. @@ -0,0 +1,81 @@
  70615. +/*
  70616. + * dwc_otg_fiq_fsm.S - assembly stub for the FSM FIQ
  70617. + *
  70618. + * Copyright (c) 2013 Raspberry Pi Foundation
  70619. + *
  70620. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  70621. + * All rights reserved.
  70622. + *
  70623. + * Redistribution and use in source and binary forms, with or without
  70624. + * modification, are permitted provided that the following conditions are met:
  70625. + * * Redistributions of source code must retain the above copyright
  70626. + * notice, this list of conditions and the following disclaimer.
  70627. + * * Redistributions in binary form must reproduce the above copyright
  70628. + * notice, this list of conditions and the following disclaimer in the
  70629. + * documentation and/or other materials provided with the distribution.
  70630. + * * Neither the name of Raspberry Pi nor the
  70631. + * names of its contributors may be used to endorse or promote products
  70632. + * derived from this software without specific prior written permission.
  70633. + *
  70634. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  70635. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  70636. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  70637. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  70638. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  70639. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  70640. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  70641. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  70642. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  70643. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  70644. + */
  70645. +
  70646. +
  70647. +#include <asm/assembler.h>
  70648. +#include <linux/linkage.h>
  70649. +
  70650. +
  70651. +.text
  70652. +
  70653. +.global _dwc_otg_fiq_stub_end;
  70654. +
  70655. +/**
  70656. + * _dwc_otg_fiq_stub() - entry copied to the FIQ vector page to allow
  70657. + * a C-style function call with arguments from the FIQ banked registers.
  70658. + * r0 = &hcd->fiq_state
  70659. + * r1 = &hcd->num_channels
  70660. + * r2 = &hcd->dma_buffers
  70661. + * Tramples: r0, r1, r2, r4, fp, ip
  70662. + */
  70663. +
  70664. +ENTRY(_dwc_otg_fiq_stub)
  70665. + /* Stash unbanked regs - SP will have been set up for us */
  70666. + mov ip, sp;
  70667. + stmdb sp!, {r0-r12, lr};
  70668. +#ifdef FIQ_DEBUG
  70669. + // Cycle profiling - read cycle counter at start
  70670. + mrc p15, 0, r5, c15, c12, 1;
  70671. +#endif
  70672. + /* r11 = fp, don't trample it */
  70673. + mov r4, fp;
  70674. + /* set EABI frame size */
  70675. + sub fp, ip, #512;
  70676. +
  70677. + /* for fiq NOP mode - just need state */
  70678. + mov r0, r8;
  70679. + /* r9 = num_channels */
  70680. + mov r1, r9;
  70681. + /* r10 = struct *dma_bufs */
  70682. +// mov r2, r10;
  70683. +
  70684. + /* r4 = &fiq_c_function */
  70685. + blx r4;
  70686. +#ifdef FIQ_DEBUG
  70687. + mrc p15, 0, r4, c15, c12, 1;
  70688. + subs r5, r5, r4;
  70689. + // r5 is now the cycle count time for executing the FIQ. Store it somewhere?
  70690. +#endif
  70691. + ldmia sp!, {r0-r12, lr};
  70692. + subs pc, lr, #4;
  70693. +_dwc_otg_fiq_stub_end:
  70694. +END(_dwc_otg_fiq_stub)
  70695. +
  70696. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  70697. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 1970-01-01 01:00:00.000000000 +0100
  70698. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 2014-04-24 16:04:39.819124254 +0200
  70699. @@ -0,0 +1,4188 @@
  70700. +
  70701. +/* ==========================================================================
  70702. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
  70703. + * $Revision: #104 $
  70704. + * $Date: 2011/10/24 $
  70705. + * $Change: 1871159 $
  70706. + *
  70707. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  70708. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  70709. + * otherwise expressly agreed to in writing between Synopsys and you.
  70710. + *
  70711. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  70712. + * any End User Software License Agreement or Agreement for Licensed Product
  70713. + * with Synopsys or any supplement thereto. You are permitted to use and
  70714. + * redistribute this Software in source and binary forms, with or without
  70715. + * modification, provided that redistributions of source code must retain this
  70716. + * notice. You may not view, use, disclose, copy or distribute this file or
  70717. + * any information contained herein except pursuant to this license grant from
  70718. + * Synopsys. If you do not agree with this notice, including the disclaimer
  70719. + * below, then you are not authorized to use the Software.
  70720. + *
  70721. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  70722. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  70723. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  70724. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  70725. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  70726. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  70727. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  70728. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  70729. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  70730. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  70731. + * DAMAGE.
  70732. + * ========================================================================== */
  70733. +#ifndef DWC_DEVICE_ONLY
  70734. +
  70735. +/** @file
  70736. + * This file implements HCD Core. All code in this file is portable and doesn't
  70737. + * use any OS specific functions.
  70738. + * Interface provided by HCD Core is defined in <code><hcd_if.h></code>
  70739. + * header file.
  70740. + */
  70741. +
  70742. +#include <linux/usb.h>
  70743. +#include <linux/usb/hcd.h>
  70744. +
  70745. +#include "dwc_otg_hcd.h"
  70746. +#include "dwc_otg_regs.h"
  70747. +#include "dwc_otg_fiq_fsm.h"
  70748. +
  70749. +extern bool microframe_schedule;
  70750. +extern uint16_t fiq_fsm_mask, nak_holdoff;
  70751. +
  70752. +//#define DEBUG_HOST_CHANNELS
  70753. +#ifdef DEBUG_HOST_CHANNELS
  70754. +static int last_sel_trans_num_per_scheduled = 0;
  70755. +static int last_sel_trans_num_nonper_scheduled = 0;
  70756. +static int last_sel_trans_num_avail_hc_at_start = 0;
  70757. +static int last_sel_trans_num_avail_hc_at_end = 0;
  70758. +#endif /* DEBUG_HOST_CHANNELS */
  70759. +
  70760. +
  70761. +dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  70762. +{
  70763. + return DWC_ALLOC(sizeof(dwc_otg_hcd_t));
  70764. +}
  70765. +
  70766. +/**
  70767. + * Connection timeout function. An OTG host is required to display a
  70768. + * message if the device does not connect within 10 seconds.
  70769. + */
  70770. +void dwc_otg_hcd_connect_timeout(void *ptr)
  70771. +{
  70772. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, ptr);
  70773. + DWC_PRINTF("Connect Timeout\n");
  70774. + __DWC_ERROR("Device Not Connected/Responding\n");
  70775. +}
  70776. +
  70777. +#if defined(DEBUG)
  70778. +static void dump_channel_info(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  70779. +{
  70780. + if (qh->channel != NULL) {
  70781. + dwc_hc_t *hc = qh->channel;
  70782. + dwc_list_link_t *item;
  70783. + dwc_otg_qh_t *qh_item;
  70784. + int num_channels = hcd->core_if->core_params->host_channels;
  70785. + int i;
  70786. +
  70787. + dwc_otg_hc_regs_t *hc_regs;
  70788. + hcchar_data_t hcchar;
  70789. + hcsplt_data_t hcsplt;
  70790. + hctsiz_data_t hctsiz;
  70791. + uint32_t hcdma;
  70792. +
  70793. + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  70794. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70795. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  70796. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  70797. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  70798. +
  70799. + DWC_PRINTF(" Assigned to channel %p:\n", hc);
  70800. + DWC_PRINTF(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32,
  70801. + hcsplt.d32);
  70802. + DWC_PRINTF(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32,
  70803. + hcdma);
  70804. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  70805. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  70806. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  70807. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  70808. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  70809. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  70810. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  70811. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  70812. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  70813. + DWC_PRINTF(" qh: %p\n", hc->qh);
  70814. + DWC_PRINTF(" NP inactive sched:\n");
  70815. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_inactive) {
  70816. + qh_item =
  70817. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  70818. + DWC_PRINTF(" %p\n", qh_item);
  70819. + }
  70820. + DWC_PRINTF(" NP active sched:\n");
  70821. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_active) {
  70822. + qh_item =
  70823. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  70824. + DWC_PRINTF(" %p\n", qh_item);
  70825. + }
  70826. + DWC_PRINTF(" Channels: \n");
  70827. + for (i = 0; i < num_channels; i++) {
  70828. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  70829. + DWC_PRINTF(" %2d: %p\n", i, hc);
  70830. + }
  70831. + }
  70832. +}
  70833. +#else
  70834. +#define dump_channel_info(hcd, qh)
  70835. +#endif /* DEBUG */
  70836. +
  70837. +/**
  70838. + * Work queue function for starting the HCD when A-Cable is connected.
  70839. + * The hcd_start() must be called in a process context.
  70840. + */
  70841. +static void hcd_start_func(void *_vp)
  70842. +{
  70843. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) _vp;
  70844. +
  70845. + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, hcd);
  70846. + if (hcd) {
  70847. + hcd->fops->start(hcd);
  70848. + }
  70849. +}
  70850. +
  70851. +static void del_xfer_timers(dwc_otg_hcd_t * hcd)
  70852. +{
  70853. +#ifdef DEBUG
  70854. + int i;
  70855. + int num_channels = hcd->core_if->core_params->host_channels;
  70856. + for (i = 0; i < num_channels; i++) {
  70857. + DWC_TIMER_CANCEL(hcd->core_if->hc_xfer_timer[i]);
  70858. + }
  70859. +#endif
  70860. +}
  70861. +
  70862. +static void del_timers(dwc_otg_hcd_t * hcd)
  70863. +{
  70864. + del_xfer_timers(hcd);
  70865. + DWC_TIMER_CANCEL(hcd->conn_timer);
  70866. +}
  70867. +
  70868. +/**
  70869. + * Processes all the URBs in a single list of QHs. Completes them with
  70870. + * -ESHUTDOWN and frees the QTD.
  70871. + */
  70872. +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  70873. +{
  70874. + dwc_list_link_t *qh_item, *qh_tmp;
  70875. + dwc_otg_qh_t *qh;
  70876. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  70877. +
  70878. + DWC_LIST_FOREACH_SAFE(qh_item, qh_tmp, qh_list) {
  70879. + qh = DWC_LIST_ENTRY(qh_item, dwc_otg_qh_t, qh_list_entry);
  70880. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp,
  70881. + &qh->qtd_list, qtd_list_entry) {
  70882. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  70883. + if (qtd->urb != NULL) {
  70884. + hcd->fops->complete(hcd, qtd->urb->priv,
  70885. + qtd->urb, -DWC_E_SHUTDOWN);
  70886. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  70887. + }
  70888. +
  70889. + }
  70890. + if(qh->channel) {
  70891. + /* Using hcchar.chen == 1 is not a reliable test.
  70892. + * It is possible that the channel has already halted
  70893. + * but not yet been through the IRQ handler.
  70894. + */
  70895. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  70896. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  70897. + if(microframe_schedule)
  70898. + hcd->available_host_channels++;
  70899. + qh->channel = NULL;
  70900. + }
  70901. + dwc_otg_hcd_qh_remove(hcd, qh);
  70902. + }
  70903. +}
  70904. +
  70905. +/**
  70906. + * Responds with an error status of ESHUTDOWN to all URBs in the non-periodic
  70907. + * and periodic schedules. The QTD associated with each URB is removed from
  70908. + * the schedule and freed. This function may be called when a disconnect is
  70909. + * detected or when the HCD is being stopped.
  70910. + */
  70911. +static void kill_all_urbs(dwc_otg_hcd_t * hcd)
  70912. +{
  70913. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
  70914. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
  70915. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
  70916. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
  70917. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
  70918. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
  70919. +}
  70920. +
  70921. +/**
  70922. + * Start the connection timer. An OTG host is required to display a
  70923. + * message if the device does not connect within 10 seconds. The
  70924. + * timer is deleted if a port connect interrupt occurs before the
  70925. + * timer expires.
  70926. + */
  70927. +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t * hcd)
  70928. +{
  70929. + DWC_TIMER_SCHEDULE(hcd->conn_timer, 10000 /* 10 secs */ );
  70930. +}
  70931. +
  70932. +/**
  70933. + * HCD Callback function for disconnect of the HCD.
  70934. + *
  70935. + * @param p void pointer to the <code>struct usb_hcd</code>
  70936. + */
  70937. +static int32_t dwc_otg_hcd_session_start_cb(void *p)
  70938. +{
  70939. + dwc_otg_hcd_t *dwc_otg_hcd;
  70940. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  70941. + dwc_otg_hcd = p;
  70942. + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
  70943. + return 1;
  70944. +}
  70945. +
  70946. +/**
  70947. + * HCD Callback function for starting the HCD when A-Cable is
  70948. + * connected.
  70949. + *
  70950. + * @param p void pointer to the <code>struct usb_hcd</code>
  70951. + */
  70952. +static int32_t dwc_otg_hcd_start_cb(void *p)
  70953. +{
  70954. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  70955. + dwc_otg_core_if_t *core_if;
  70956. + hprt0_data_t hprt0;
  70957. +
  70958. + core_if = dwc_otg_hcd->core_if;
  70959. +
  70960. + if (core_if->op_state == B_HOST) {
  70961. + /*
  70962. + * Reset the port. During a HNP mode switch the reset
  70963. + * needs to occur within 1ms and have a duration of at
  70964. + * least 50ms.
  70965. + */
  70966. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70967. + hprt0.b.prtrst = 1;
  70968. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70969. + }
  70970. + DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg,
  70971. + hcd_start_func, dwc_otg_hcd, 50,
  70972. + "start hcd");
  70973. +
  70974. + return 1;
  70975. +}
  70976. +
  70977. +/**
  70978. + * HCD Callback function for disconnect of the HCD.
  70979. + *
  70980. + * @param p void pointer to the <code>struct usb_hcd</code>
  70981. + */
  70982. +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
  70983. +{
  70984. + gintsts_data_t intr;
  70985. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  70986. +
  70987. + /*
  70988. + * Set status flags for the hub driver.
  70989. + */
  70990. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  70991. + dwc_otg_hcd->flags.b.port_connect_status = 0;
  70992. + if(fiq_enable)
  70993. + local_fiq_disable();
  70994. + /*
  70995. + * Shutdown any transfers in process by clearing the Tx FIFO Empty
  70996. + * interrupt mask and status bits and disabling subsequent host
  70997. + * channel interrupts.
  70998. + */
  70999. + intr.d32 = 0;
  71000. + intr.b.nptxfempty = 1;
  71001. + intr.b.ptxfempty = 1;
  71002. + intr.b.hcintr = 1;
  71003. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk,
  71004. + intr.d32, 0);
  71005. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintsts,
  71006. + intr.d32, 0);
  71007. +
  71008. + del_timers(dwc_otg_hcd);
  71009. +
  71010. + /*
  71011. + * Turn off the vbus power only if the core has transitioned to device
  71012. + * mode. If still in host mode, need to keep power on to detect a
  71013. + * reconnection.
  71014. + */
  71015. + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
  71016. + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
  71017. + hprt0_data_t hprt0 = {.d32 = 0 };
  71018. + DWC_PRINTF("Disconnect: PortPower off\n");
  71019. + hprt0.b.prtpwr = 0;
  71020. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0,
  71021. + hprt0.d32);
  71022. + }
  71023. +
  71024. + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
  71025. + }
  71026. +
  71027. + /* Respond with an error status to all URBs in the schedule. */
  71028. + kill_all_urbs(dwc_otg_hcd);
  71029. +
  71030. + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
  71031. + /* Clean up any host channels that were in use. */
  71032. + int num_channels;
  71033. + int i;
  71034. + dwc_hc_t *channel;
  71035. + dwc_otg_hc_regs_t *hc_regs;
  71036. + hcchar_data_t hcchar;
  71037. +
  71038. + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
  71039. +
  71040. + if (!dwc_otg_hcd->core_if->dma_enable) {
  71041. + /* Flush out any channel requests in slave mode. */
  71042. + for (i = 0; i < num_channels; i++) {
  71043. + channel = dwc_otg_hcd->hc_ptr_array[i];
  71044. + if (DWC_CIRCLEQ_EMPTY_ENTRY
  71045. + (channel, hc_list_entry)) {
  71046. + hc_regs =
  71047. + dwc_otg_hcd->core_if->
  71048. + host_if->hc_regs[i];
  71049. + hcchar.d32 =
  71050. + DWC_READ_REG32(&hc_regs->hcchar);
  71051. + if (hcchar.b.chen) {
  71052. + hcchar.b.chen = 0;
  71053. + hcchar.b.chdis = 1;
  71054. + hcchar.b.epdir = 0;
  71055. + DWC_WRITE_REG32
  71056. + (&hc_regs->hcchar,
  71057. + hcchar.d32);
  71058. + }
  71059. + }
  71060. + }
  71061. + }
  71062. +
  71063. + for (i = 0; i < num_channels; i++) {
  71064. + channel = dwc_otg_hcd->hc_ptr_array[i];
  71065. + if (DWC_CIRCLEQ_EMPTY_ENTRY(channel, hc_list_entry)) {
  71066. + hc_regs =
  71067. + dwc_otg_hcd->core_if->host_if->hc_regs[i];
  71068. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  71069. + if (hcchar.b.chen) {
  71070. + /* Halt the channel. */
  71071. + hcchar.b.chdis = 1;
  71072. + DWC_WRITE_REG32(&hc_regs->hcchar,
  71073. + hcchar.d32);
  71074. + }
  71075. +
  71076. + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if,
  71077. + channel);
  71078. + DWC_CIRCLEQ_INSERT_TAIL
  71079. + (&dwc_otg_hcd->free_hc_list, channel,
  71080. + hc_list_entry);
  71081. + /*
  71082. + * Added for Descriptor DMA to prevent channel double cleanup
  71083. + * in release_channel_ddma(). Which called from ep_disable
  71084. + * when device disconnect.
  71085. + */
  71086. + channel->qh = NULL;
  71087. + }
  71088. + }
  71089. + if(fiq_fsm_enable) {
  71090. + for(i=0; i < 128; i++) {
  71091. + dwc_otg_hcd->hub_port[i] = 0;
  71092. + }
  71093. + }
  71094. +
  71095. + }
  71096. +
  71097. + if(fiq_enable)
  71098. + local_fiq_enable();
  71099. +
  71100. + if (dwc_otg_hcd->fops->disconnect) {
  71101. + dwc_otg_hcd->fops->disconnect(dwc_otg_hcd);
  71102. + }
  71103. +
  71104. + return 1;
  71105. +}
  71106. +
  71107. +/**
  71108. + * HCD Callback function for stopping the HCD.
  71109. + *
  71110. + * @param p void pointer to the <code>struct usb_hcd</code>
  71111. + */
  71112. +static int32_t dwc_otg_hcd_stop_cb(void *p)
  71113. +{
  71114. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  71115. +
  71116. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  71117. + dwc_otg_hcd_stop(dwc_otg_hcd);
  71118. + return 1;
  71119. +}
  71120. +
  71121. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71122. +/**
  71123. + * HCD Callback function for sleep of HCD.
  71124. + *
  71125. + * @param p void pointer to the <code>struct usb_hcd</code>
  71126. + */
  71127. +static int dwc_otg_hcd_sleep_cb(void *p)
  71128. +{
  71129. + dwc_otg_hcd_t *hcd = p;
  71130. +
  71131. + dwc_otg_hcd_free_hc_from_lpm(hcd);
  71132. +
  71133. + return 0;
  71134. +}
  71135. +#endif
  71136. +
  71137. +
  71138. +/**
  71139. + * HCD Callback function for Remote Wakeup.
  71140. + *
  71141. + * @param p void pointer to the <code>struct usb_hcd</code>
  71142. + */
  71143. +static int dwc_otg_hcd_rem_wakeup_cb(void *p)
  71144. +{
  71145. + dwc_otg_hcd_t *hcd = p;
  71146. +
  71147. + if (hcd->core_if->lx_state == DWC_OTG_L2) {
  71148. + hcd->flags.b.port_suspend_change = 1;
  71149. + }
  71150. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71151. + else {
  71152. + hcd->flags.b.port_l1_change = 1;
  71153. + }
  71154. +#endif
  71155. + return 0;
  71156. +}
  71157. +
  71158. +/**
  71159. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  71160. + * stopped.
  71161. + */
  71162. +void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd)
  71163. +{
  71164. + hprt0_data_t hprt0 = {.d32 = 0 };
  71165. +
  71166. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
  71167. +
  71168. + /*
  71169. + * The root hub should be disconnected before this function is called.
  71170. + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
  71171. + * and the QH lists (via ..._hcd_endpoint_disable).
  71172. + */
  71173. +
  71174. + /* Turn off all host-specific interrupts. */
  71175. + dwc_otg_disable_host_interrupts(hcd->core_if);
  71176. +
  71177. + /* Turn off the vbus power */
  71178. + DWC_PRINTF("PortPower off\n");
  71179. + hprt0.b.prtpwr = 0;
  71180. + DWC_WRITE_REG32(hcd->core_if->host_if->hprt0, hprt0.d32);
  71181. + dwc_mdelay(1);
  71182. +}
  71183. +
  71184. +int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
  71185. + dwc_otg_hcd_urb_t * dwc_otg_urb, void **ep_handle,
  71186. + int atomic_alloc)
  71187. +{
  71188. + int retval = 0;
  71189. + uint8_t needs_scheduling = 0;
  71190. + dwc_otg_transaction_type_e tr_type;
  71191. + dwc_otg_qtd_t *qtd;
  71192. + gintmsk_data_t intr_mask = {.d32 = 0 };
  71193. + hprt0_data_t hprt0 = { .d32 = 0 };
  71194. +
  71195. +#ifdef DEBUG /* integrity checks (Broadcom) */
  71196. + if (NULL == hcd->core_if) {
  71197. + DWC_ERROR("**** DWC OTG HCD URB Enqueue - HCD has NULL core_if\n");
  71198. + /* No longer connected. */
  71199. + return -DWC_E_INVALID;
  71200. + }
  71201. +#endif
  71202. + if (!hcd->flags.b.port_connect_status) {
  71203. + /* No longer connected. */
  71204. + DWC_ERROR("Not connected\n");
  71205. + return -DWC_E_NO_DEVICE;
  71206. + }
  71207. +
  71208. + /* Some core configurations cannot support LS traffic on a FS root port */
  71209. + if ((hcd->fops->speed(hcd, dwc_otg_urb->priv) == USB_SPEED_LOW) &&
  71210. + (hcd->core_if->hwcfg2.b.fs_phy_type == 1) &&
  71211. + (hcd->core_if->hwcfg2.b.hs_phy_type == 1)) {
  71212. + hprt0.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  71213. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
  71214. + return -DWC_E_NO_DEVICE;
  71215. + }
  71216. + }
  71217. +
  71218. + qtd = dwc_otg_hcd_qtd_create(dwc_otg_urb, atomic_alloc);
  71219. + if (qtd == NULL) {
  71220. + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
  71221. + return -DWC_E_NO_MEMORY;
  71222. + }
  71223. +#ifdef DEBUG /* integrity checks (Broadcom) */
  71224. + if (qtd->urb == NULL) {
  71225. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD with no URBs\n");
  71226. + return -DWC_E_NO_MEMORY;
  71227. + }
  71228. + if (qtd->urb->priv == NULL) {
  71229. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD URB with no URB handle\n");
  71230. + return -DWC_E_NO_MEMORY;
  71231. + }
  71232. +#endif
  71233. + intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  71234. + if(!intr_mask.b.sofintr || fiq_enable) needs_scheduling = 1;
  71235. + if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  71236. + /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  71237. + needs_scheduling = 0;
  71238. +
  71239. + retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
  71240. + // creates a new queue in ep_handle if it doesn't exist already
  71241. + if (retval < 0) {
  71242. + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
  71243. + "Error status %d\n", retval);
  71244. + dwc_otg_hcd_qtd_free(qtd);
  71245. + return retval;
  71246. + }
  71247. +
  71248. + if(needs_scheduling) {
  71249. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  71250. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  71251. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  71252. + }
  71253. + }
  71254. + return retval;
  71255. +}
  71256. +
  71257. +int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
  71258. + dwc_otg_hcd_urb_t * dwc_otg_urb)
  71259. +{
  71260. + dwc_otg_qh_t *qh;
  71261. + dwc_otg_qtd_t *urb_qtd;
  71262. + BUG_ON(!hcd);
  71263. + BUG_ON(!dwc_otg_urb);
  71264. +
  71265. +#ifdef DEBUG /* integrity checks (Broadcom) */
  71266. +
  71267. + if (hcd == NULL) {
  71268. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL HCD\n");
  71269. + return -DWC_E_INVALID;
  71270. + }
  71271. + if (dwc_otg_urb == NULL) {
  71272. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL URB\n");
  71273. + return -DWC_E_INVALID;
  71274. + }
  71275. + if (dwc_otg_urb->qtd == NULL) {
  71276. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with NULL QTD\n");
  71277. + return -DWC_E_INVALID;
  71278. + }
  71279. + urb_qtd = dwc_otg_urb->qtd;
  71280. + BUG_ON(!urb_qtd);
  71281. + if (urb_qtd->qh == NULL) {
  71282. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with QTD with NULL Q handler\n");
  71283. + return -DWC_E_INVALID;
  71284. + }
  71285. +#else
  71286. + urb_qtd = dwc_otg_urb->qtd;
  71287. + BUG_ON(!urb_qtd);
  71288. +#endif
  71289. + qh = urb_qtd->qh;
  71290. + BUG_ON(!qh);
  71291. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  71292. + if (urb_qtd->in_process) {
  71293. + dump_channel_info(hcd, qh);
  71294. + }
  71295. + }
  71296. +#ifdef DEBUG /* integrity checks (Broadcom) */
  71297. + if (hcd->core_if == NULL) {
  71298. + DWC_ERROR("**** DWC OTG HCD URB Dequeue HCD has NULL core_if\n");
  71299. + return -DWC_E_INVALID;
  71300. + }
  71301. +#endif
  71302. + if (urb_qtd->in_process && qh->channel) {
  71303. + /* The QTD is in process (it has been assigned to a channel). */
  71304. + if (hcd->flags.b.port_connect_status) {
  71305. + int n = qh->channel->hc_num;
  71306. + /*
  71307. + * If still connected (i.e. in host mode), halt the
  71308. + * channel so it can be used for other transfers. If
  71309. + * no longer connected, the host registers can't be
  71310. + * written to halt the channel since the core is in
  71311. + * device mode.
  71312. + */
  71313. + /* In FIQ FSM mode, we need to shut down carefully.
  71314. + * The FIQ may attempt to restart a disabled channel */
  71315. + if (fiq_fsm_enable && (hcd->fiq_state->channel[n].fsm != FIQ_PASSTHROUGH)) {
  71316. + hcd->fiq_state->channel[n].fsm = FIQ_DEQUEUE_ISSUED;
  71317. + }
  71318. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  71319. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  71320. +
  71321. + }
  71322. + }
  71323. +
  71324. + /*
  71325. + * Free the QTD and clean up the associated QH. Leave the QH in the
  71326. + * schedule if it has any remaining QTDs.
  71327. + */
  71328. +
  71329. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue - "
  71330. + "delete %sQueue handler\n",
  71331. + hcd->core_if->dma_desc_enable?"DMA ":"");
  71332. + if (!hcd->core_if->dma_desc_enable) {
  71333. + uint8_t b = urb_qtd->in_process;
  71334. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  71335. + if (b) {
  71336. + dwc_otg_hcd_qh_deactivate(hcd, qh, 0);
  71337. + qh->channel = NULL;
  71338. + } else if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  71339. + dwc_otg_hcd_qh_remove(hcd, qh);
  71340. + }
  71341. + } else {
  71342. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  71343. + }
  71344. + return 0;
  71345. +}
  71346. +
  71347. +int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  71348. + int retry)
  71349. +{
  71350. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  71351. + int retval = 0;
  71352. + dwc_irqflags_t flags;
  71353. +
  71354. + if (retry < 0) {
  71355. + retval = -DWC_E_INVALID;
  71356. + goto done;
  71357. + }
  71358. +
  71359. + if (!qh) {
  71360. + retval = -DWC_E_INVALID;
  71361. + goto done;
  71362. + }
  71363. +
  71364. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  71365. +
  71366. + while (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list) && retry) {
  71367. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  71368. + retry--;
  71369. + dwc_msleep(5);
  71370. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  71371. + }
  71372. +
  71373. + dwc_otg_hcd_qh_remove(hcd, qh);
  71374. +
  71375. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  71376. + /*
  71377. + * Split dwc_otg_hcd_qh_remove_and_free() into qh_remove
  71378. + * and qh_free to prevent stack dump on DWC_DMA_FREE() with
  71379. + * irq_disabled (spinlock_irqsave) in dwc_otg_hcd_desc_list_free()
  71380. + * and dwc_otg_hcd_frame_list_alloc().
  71381. + */
  71382. + dwc_otg_hcd_qh_free(hcd, qh);
  71383. +
  71384. +done:
  71385. + return retval;
  71386. +}
  71387. +
  71388. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  71389. +int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle)
  71390. +{
  71391. + int retval = 0;
  71392. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  71393. + if (!qh)
  71394. + return -DWC_E_INVALID;
  71395. +
  71396. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  71397. + return retval;
  71398. +}
  71399. +#endif
  71400. +
  71401. +/**
  71402. + * HCD Callback structure for handling mode switching.
  71403. + */
  71404. +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
  71405. + .start = dwc_otg_hcd_start_cb,
  71406. + .stop = dwc_otg_hcd_stop_cb,
  71407. + .disconnect = dwc_otg_hcd_disconnect_cb,
  71408. + .session_start = dwc_otg_hcd_session_start_cb,
  71409. + .resume_wakeup = dwc_otg_hcd_rem_wakeup_cb,
  71410. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71411. + .sleep = dwc_otg_hcd_sleep_cb,
  71412. +#endif
  71413. + .p = 0,
  71414. +};
  71415. +
  71416. +/**
  71417. + * Reset tasklet function
  71418. + */
  71419. +static void reset_tasklet_func(void *data)
  71420. +{
  71421. + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *) data;
  71422. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  71423. + hprt0_data_t hprt0;
  71424. +
  71425. + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
  71426. +
  71427. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71428. + hprt0.b.prtrst = 1;
  71429. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71430. + dwc_mdelay(60);
  71431. +
  71432. + hprt0.b.prtrst = 0;
  71433. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71434. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  71435. +}
  71436. +
  71437. +static void completion_tasklet_func(void *ptr)
  71438. +{
  71439. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) ptr;
  71440. + struct urb *urb;
  71441. + urb_tq_entry_t *item;
  71442. + dwc_irqflags_t flags;
  71443. +
  71444. + /* This could just be spin_lock_irq */
  71445. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  71446. + while (!DWC_TAILQ_EMPTY(&hcd->completed_urb_list)) {
  71447. + item = DWC_TAILQ_FIRST(&hcd->completed_urb_list);
  71448. + urb = item->urb;
  71449. + DWC_TAILQ_REMOVE(&hcd->completed_urb_list, item,
  71450. + urb_tq_entries);
  71451. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  71452. + DWC_FREE(item);
  71453. +
  71454. + usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  71455. +
  71456. +
  71457. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  71458. + }
  71459. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  71460. + return;
  71461. +}
  71462. +
  71463. +static void qh_list_free(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  71464. +{
  71465. + dwc_list_link_t *item;
  71466. + dwc_otg_qh_t *qh;
  71467. + dwc_irqflags_t flags;
  71468. +
  71469. + if (!qh_list->next) {
  71470. + /* The list hasn't been initialized yet. */
  71471. + return;
  71472. + }
  71473. + /*
  71474. + * Hold spinlock here. Not needed in that case if bellow
  71475. + * function is being called from ISR
  71476. + */
  71477. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  71478. + /* Ensure there are no QTDs or URBs left. */
  71479. + kill_urbs_in_qh_list(hcd, qh_list);
  71480. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  71481. +
  71482. + DWC_LIST_FOREACH(item, qh_list) {
  71483. + qh = DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  71484. + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
  71485. + }
  71486. +}
  71487. +
  71488. +/**
  71489. + * Exit from Hibernation if Host did not detect SRP from connected SRP capable
  71490. + * Device during SRP time by host power up.
  71491. + */
  71492. +void dwc_otg_hcd_power_up(void *ptr)
  71493. +{
  71494. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  71495. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  71496. +
  71497. + DWC_PRINTF("%s called\n", __FUNCTION__);
  71498. +
  71499. + if (!core_if->hibernation_suspend) {
  71500. + DWC_PRINTF("Already exited from Hibernation\n");
  71501. + return;
  71502. + }
  71503. +
  71504. + /* Switch on the voltage to the core */
  71505. + gpwrdn.b.pwrdnswtch = 1;
  71506. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71507. + dwc_udelay(10);
  71508. +
  71509. + /* Reset the core */
  71510. + gpwrdn.d32 = 0;
  71511. + gpwrdn.b.pwrdnrstn = 1;
  71512. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71513. + dwc_udelay(10);
  71514. +
  71515. + /* Disable power clamps */
  71516. + gpwrdn.d32 = 0;
  71517. + gpwrdn.b.pwrdnclmp = 1;
  71518. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71519. +
  71520. + /* Remove reset the core signal */
  71521. + gpwrdn.d32 = 0;
  71522. + gpwrdn.b.pwrdnrstn = 1;
  71523. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  71524. + dwc_udelay(10);
  71525. +
  71526. + /* Disable PMU interrupt */
  71527. + gpwrdn.d32 = 0;
  71528. + gpwrdn.b.pmuintsel = 1;
  71529. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71530. +
  71531. + core_if->hibernation_suspend = 0;
  71532. +
  71533. + /* Disable PMU */
  71534. + gpwrdn.d32 = 0;
  71535. + gpwrdn.b.pmuactv = 1;
  71536. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71537. + dwc_udelay(10);
  71538. +
  71539. + /* Enable VBUS */
  71540. + gpwrdn.d32 = 0;
  71541. + gpwrdn.b.dis_vbus = 1;
  71542. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71543. +
  71544. + core_if->op_state = A_HOST;
  71545. + dwc_otg_core_init(core_if);
  71546. + dwc_otg_enable_global_interrupts(core_if);
  71547. + cil_hcd_start(core_if);
  71548. +}
  71549. +
  71550. +void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num)
  71551. +{
  71552. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  71553. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  71554. + int i;
  71555. +
  71556. + st->fsm = FIQ_PASSTHROUGH;
  71557. + st->hcchar_copy.d32 = 0;
  71558. + st->hcsplt_copy.d32 = 0;
  71559. + st->hcint_copy.d32 = 0;
  71560. + st->hcintmsk_copy.d32 = 0;
  71561. + st->hctsiz_copy.d32 = 0;
  71562. + st->hcdma_copy.d32 = 0;
  71563. + st->nr_errors = 0;
  71564. + st->hub_addr = 0;
  71565. + st->port_addr = 0;
  71566. + st->expected_uframe = 0;
  71567. + st->nrpackets = 0;
  71568. + st->dma_info.index = 0;
  71569. + for (i = 0; i < 6; i++)
  71570. + st->dma_info.slot_len[i] = 255;
  71571. + st->hs_isoc_info.index = 0;
  71572. + st->hs_isoc_info.iso_desc = NULL;
  71573. + st->hs_isoc_info.nrframes = 0;
  71574. +
  71575. + DWC_MEMSET(&blob->channel[num].index[0], 0x6b, 1128);
  71576. +}
  71577. +
  71578. +/**
  71579. + * Frees secondary storage associated with the dwc_otg_hcd structure contained
  71580. + * in the struct usb_hcd field.
  71581. + */
  71582. +static void dwc_otg_hcd_free(dwc_otg_hcd_t * dwc_otg_hcd)
  71583. +{
  71584. + int i;
  71585. +
  71586. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
  71587. +
  71588. + del_timers(dwc_otg_hcd);
  71589. +
  71590. + /* Free memory for QH/QTD lists */
  71591. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
  71592. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
  71593. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
  71594. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
  71595. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
  71596. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
  71597. +
  71598. + /* Free memory for the host channels. */
  71599. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  71600. + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
  71601. +
  71602. +#ifdef DEBUG
  71603. + if (dwc_otg_hcd->core_if->hc_xfer_timer[i]) {
  71604. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->hc_xfer_timer[i]);
  71605. + }
  71606. +#endif
  71607. + if (hc != NULL) {
  71608. + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n",
  71609. + i, hc);
  71610. + DWC_FREE(hc);
  71611. + }
  71612. + }
  71613. +
  71614. + if (dwc_otg_hcd->core_if->dma_enable) {
  71615. + if (dwc_otg_hcd->status_buf_dma) {
  71616. + DWC_DMA_FREE(DWC_OTG_HCD_STATUS_BUF_SIZE,
  71617. + dwc_otg_hcd->status_buf,
  71618. + dwc_otg_hcd->status_buf_dma);
  71619. + }
  71620. + } else if (dwc_otg_hcd->status_buf != NULL) {
  71621. + DWC_FREE(dwc_otg_hcd->status_buf);
  71622. + }
  71623. + DWC_SPINLOCK_FREE(dwc_otg_hcd->channel_lock);
  71624. + DWC_SPINLOCK_FREE(dwc_otg_hcd->lock);
  71625. + /* Set core_if's lock pointer to NULL */
  71626. + dwc_otg_hcd->core_if->lock = NULL;
  71627. +
  71628. + DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  71629. + DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  71630. + DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  71631. + DWC_FREE(dwc_otg_hcd->fiq_state);
  71632. +
  71633. +#ifdef DWC_DEV_SRPCAP
  71634. + if (dwc_otg_hcd->core_if->power_down == 2 &&
  71635. + dwc_otg_hcd->core_if->pwron_timer) {
  71636. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->pwron_timer);
  71637. + }
  71638. +#endif
  71639. + DWC_FREE(dwc_otg_hcd);
  71640. +}
  71641. +
  71642. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
  71643. +
  71644. +int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
  71645. +{
  71646. + int retval = 0;
  71647. + int num_channels;
  71648. + int i;
  71649. + dwc_hc_t *channel;
  71650. +
  71651. + hcd->lock = DWC_SPINLOCK_ALLOC();
  71652. + hcd->channel_lock = DWC_SPINLOCK_ALLOC();
  71653. + DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
  71654. + hcd, core_if);
  71655. + if (!hcd->lock) {
  71656. + DWC_ERROR("Could not allocate lock for pcd");
  71657. + DWC_FREE(hcd);
  71658. + retval = -DWC_E_NO_MEMORY;
  71659. + goto out;
  71660. + }
  71661. + hcd->core_if = core_if;
  71662. +
  71663. + /* Register the HCD CIL Callbacks */
  71664. + dwc_otg_cil_register_hcd_callbacks(hcd->core_if,
  71665. + &hcd_cil_callbacks, hcd);
  71666. +
  71667. + /* Initialize the non-periodic schedule. */
  71668. + DWC_LIST_INIT(&hcd->non_periodic_sched_inactive);
  71669. + DWC_LIST_INIT(&hcd->non_periodic_sched_active);
  71670. +
  71671. + /* Initialize the periodic schedule. */
  71672. + DWC_LIST_INIT(&hcd->periodic_sched_inactive);
  71673. + DWC_LIST_INIT(&hcd->periodic_sched_ready);
  71674. + DWC_LIST_INIT(&hcd->periodic_sched_assigned);
  71675. + DWC_LIST_INIT(&hcd->periodic_sched_queued);
  71676. + DWC_TAILQ_INIT(&hcd->completed_urb_list);
  71677. + /*
  71678. + * Create a host channel descriptor for each host channel implemented
  71679. + * in the controller. Initialize the channel descriptor array.
  71680. + */
  71681. + DWC_CIRCLEQ_INIT(&hcd->free_hc_list);
  71682. + num_channels = hcd->core_if->core_params->host_channels;
  71683. + DWC_MEMSET(hcd->hc_ptr_array, 0, sizeof(hcd->hc_ptr_array));
  71684. + for (i = 0; i < num_channels; i++) {
  71685. + channel = DWC_ALLOC(sizeof(dwc_hc_t));
  71686. + if (channel == NULL) {
  71687. + retval = -DWC_E_NO_MEMORY;
  71688. + DWC_ERROR("%s: host channel allocation failed\n",
  71689. + __func__);
  71690. + dwc_otg_hcd_free(hcd);
  71691. + goto out;
  71692. + }
  71693. + channel->hc_num = i;
  71694. + hcd->hc_ptr_array[i] = channel;
  71695. +#ifdef DEBUG
  71696. + hcd->core_if->hc_xfer_timer[i] =
  71697. + DWC_TIMER_ALLOC("hc timer", hc_xfer_timeout,
  71698. + &hcd->core_if->hc_xfer_info[i]);
  71699. +#endif
  71700. + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i,
  71701. + channel);
  71702. + }
  71703. +
  71704. + if (fiq_enable) {
  71705. + hcd->fiq_state = DWC_ALLOC(sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels));
  71706. + if (!hcd->fiq_state) {
  71707. + retval = -DWC_E_NO_MEMORY;
  71708. + DWC_ERROR("%s: cannot allocate fiq_state structure\n", __func__);
  71709. + dwc_otg_hcd_free(hcd);
  71710. + goto out;
  71711. + }
  71712. + DWC_MEMSET(hcd->fiq_state, 0, (sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels)));
  71713. +
  71714. + for (i = 0; i < num_channels; i++) {
  71715. + hcd->fiq_state->channel[i].fsm = FIQ_PASSTHROUGH;
  71716. + }
  71717. + hcd->fiq_state->dummy_send = DWC_ALLOC_ATOMIC(16);
  71718. +
  71719. + hcd->fiq_stack = DWC_ALLOC(sizeof(struct fiq_stack));
  71720. + if (!hcd->fiq_stack) {
  71721. + retval = -DWC_E_NO_MEMORY;
  71722. + DWC_ERROR("%s: cannot allocate fiq_stack structure\n", __func__);
  71723. + dwc_otg_hcd_free(hcd);
  71724. + goto out;
  71725. + }
  71726. + hcd->fiq_stack->magic1 = 0xDEADBEEF;
  71727. + hcd->fiq_stack->magic2 = 0xD00DFEED;
  71728. + hcd->fiq_state->gintmsk_saved.d32 = ~0;
  71729. + hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  71730. +
  71731. + /* This bit is terrible and uses no API, but necessary. The FIQ has no concept of DMA pools
  71732. + * (and if it did, would be a lot slower). This allocates a chunk of memory (~9kiB for 8 host channels)
  71733. + * for use as transaction bounce buffers in a 2-D array. Our access into this chunk is done by some
  71734. + * moderately readable array casts.
  71735. + */
  71736. + hcd->fiq_dmab = DWC_DMA_ALLOC((sizeof(struct fiq_dma_channel) * num_channels), &hcd->fiq_state->dma_base);
  71737. + DWC_WARN("FIQ DMA bounce buffers: virt = 0x%08x dma = 0x%08x len=%d",
  71738. + (unsigned int)hcd->fiq_dmab, (unsigned int)hcd->fiq_state->dma_base,
  71739. + sizeof(struct fiq_dma_channel) * num_channels);
  71740. +
  71741. + DWC_MEMSET(hcd->fiq_dmab, 0x6b, 9024);
  71742. +
  71743. + /* pointer for debug in fiq_print */
  71744. + hcd->fiq_state->fiq_dmab = hcd->fiq_dmab;
  71745. + if (fiq_fsm_enable) {
  71746. + int i;
  71747. + for (i=0; i < hcd->core_if->core_params->host_channels; i++) {
  71748. + dwc_otg_cleanup_fiq_channel(hcd, i);
  71749. + }
  71750. + DWC_PRINTF("FIQ FSM acceleration enabled for :\n%s%s%s",
  71751. + (fiq_fsm_mask & 0x1) ? "Non-periodic Split Transactions\n" : "",
  71752. + (fiq_fsm_mask & 0x2) ? "Periodic Split Transactions\n" : "",
  71753. + (fiq_fsm_mask & 0x4) ? "High-Speed Isochronous Endpoints\n" : "");
  71754. + }
  71755. + }
  71756. +
  71757. + /* Initialize the Connection timeout timer. */
  71758. + hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  71759. + dwc_otg_hcd_connect_timeout, 0);
  71760. +
  71761. + printk(KERN_DEBUG "dwc_otg: Microframe scheduler %s\n", microframe_schedule ? "enabled":"disabled");
  71762. + if (microframe_schedule)
  71763. + init_hcd_usecs(hcd);
  71764. +
  71765. + /* Initialize reset tasklet. */
  71766. + hcd->reset_tasklet = DWC_TASK_ALLOC("reset_tasklet", reset_tasklet_func, hcd);
  71767. +
  71768. + hcd->completion_tasklet = DWC_TASK_ALLOC("completion_tasklet",
  71769. + completion_tasklet_func, hcd);
  71770. +#ifdef DWC_DEV_SRPCAP
  71771. + if (hcd->core_if->power_down == 2) {
  71772. + /* Initialize Power on timer for Host power up in case hibernation */
  71773. + hcd->core_if->pwron_timer = DWC_TIMER_ALLOC("PWRON TIMER",
  71774. + dwc_otg_hcd_power_up, core_if);
  71775. + }
  71776. +#endif
  71777. +
  71778. + /*
  71779. + * Allocate space for storing data on status transactions. Normally no
  71780. + * data is sent, but this space acts as a bit bucket. This must be
  71781. + * done after usb_add_hcd since that function allocates the DMA buffer
  71782. + * pool.
  71783. + */
  71784. + if (hcd->core_if->dma_enable) {
  71785. + hcd->status_buf =
  71786. + DWC_DMA_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE,
  71787. + &hcd->status_buf_dma);
  71788. + } else {
  71789. + hcd->status_buf = DWC_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE);
  71790. + }
  71791. + if (!hcd->status_buf) {
  71792. + retval = -DWC_E_NO_MEMORY;
  71793. + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
  71794. + dwc_otg_hcd_free(hcd);
  71795. + goto out;
  71796. + }
  71797. +
  71798. + hcd->otg_port = 1;
  71799. + hcd->frame_list = NULL;
  71800. + hcd->frame_list_dma = 0;
  71801. + hcd->periodic_qh_count = 0;
  71802. +
  71803. + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
  71804. +#ifdef FIQ_DEBUG
  71805. + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
  71806. +#endif
  71807. +
  71808. +out:
  71809. + return retval;
  71810. +}
  71811. +
  71812. +void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd)
  71813. +{
  71814. + /* Turn off all host-specific interrupts. */
  71815. + dwc_otg_disable_host_interrupts(hcd->core_if);
  71816. +
  71817. + dwc_otg_hcd_free(hcd);
  71818. +}
  71819. +
  71820. +/**
  71821. + * Initializes dynamic portions of the DWC_otg HCD state.
  71822. + */
  71823. +static void dwc_otg_hcd_reinit(dwc_otg_hcd_t * hcd)
  71824. +{
  71825. + int num_channels;
  71826. + int i;
  71827. + dwc_hc_t *channel;
  71828. + dwc_hc_t *channel_tmp;
  71829. +
  71830. + hcd->flags.d32 = 0;
  71831. +
  71832. + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
  71833. + if (!microframe_schedule) {
  71834. + hcd->non_periodic_channels = 0;
  71835. + hcd->periodic_channels = 0;
  71836. + } else {
  71837. + hcd->available_host_channels = hcd->core_if->core_params->host_channels;
  71838. + }
  71839. + /*
  71840. + * Put all channels in the free channel list and clean up channel
  71841. + * states.
  71842. + */
  71843. + DWC_CIRCLEQ_FOREACH_SAFE(channel, channel_tmp,
  71844. + &hcd->free_hc_list, hc_list_entry) {
  71845. + DWC_CIRCLEQ_REMOVE(&hcd->free_hc_list, channel, hc_list_entry);
  71846. + }
  71847. +
  71848. + num_channels = hcd->core_if->core_params->host_channels;
  71849. + for (i = 0; i < num_channels; i++) {
  71850. + channel = hcd->hc_ptr_array[i];
  71851. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, channel,
  71852. + hc_list_entry);
  71853. + dwc_otg_hc_cleanup(hcd->core_if, channel);
  71854. + }
  71855. +
  71856. + /* Initialize the DWC core for host mode operation. */
  71857. + dwc_otg_core_host_init(hcd->core_if);
  71858. +
  71859. + /* Set core_if's lock pointer to the hcd->lock */
  71860. + hcd->core_if->lock = hcd->lock;
  71861. +}
  71862. +
  71863. +/**
  71864. + * Assigns transactions from a QTD to a free host channel and initializes the
  71865. + * host channel to perform the transactions. The host channel is removed from
  71866. + * the free list.
  71867. + *
  71868. + * @param hcd The HCD state structure.
  71869. + * @param qh Transactions from the first QTD for this QH are selected and
  71870. + * assigned to a free host channel.
  71871. + */
  71872. +static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  71873. +{
  71874. + dwc_hc_t *hc;
  71875. + dwc_otg_qtd_t *qtd;
  71876. + dwc_otg_hcd_urb_t *urb;
  71877. + void* ptr = NULL;
  71878. +
  71879. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  71880. +
  71881. + urb = qtd->urb;
  71882. +
  71883. + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p) - urb %x, actual_length %d\n", __func__, hcd, qh, (unsigned int)urb, urb->actual_length);
  71884. +
  71885. + if (((urb->actual_length < 0) || (urb->actual_length > urb->length)) && !dwc_otg_hcd_is_pipe_in(&urb->pipe_info))
  71886. + urb->actual_length = urb->length;
  71887. +
  71888. +
  71889. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  71890. +
  71891. + /* Remove the host channel from the free list. */
  71892. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  71893. +
  71894. + qh->channel = hc;
  71895. +
  71896. + qtd->in_process = 1;
  71897. +
  71898. + /*
  71899. + * Use usb_pipedevice to determine device address. This address is
  71900. + * 0 before the SET_ADDRESS command and the correct address afterward.
  71901. + */
  71902. + hc->dev_addr = dwc_otg_hcd_get_dev_addr(&urb->pipe_info);
  71903. + hc->ep_num = dwc_otg_hcd_get_ep_num(&urb->pipe_info);
  71904. + hc->speed = qh->dev_speed;
  71905. + hc->max_packet = dwc_max_packet(qh->maxp);
  71906. +
  71907. + hc->xfer_started = 0;
  71908. + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
  71909. + hc->error_state = (qtd->error_count > 0);
  71910. + hc->halt_on_queue = 0;
  71911. + hc->halt_pending = 0;
  71912. + hc->requests = 0;
  71913. +
  71914. + /*
  71915. + * The following values may be modified in the transfer type section
  71916. + * below. The xfer_len value may be reduced when the transfer is
  71917. + * started to accommodate the max widths of the XferSize and PktCnt
  71918. + * fields in the HCTSIZn register.
  71919. + */
  71920. +
  71921. + hc->ep_is_in = (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) != 0);
  71922. + if (hc->ep_is_in) {
  71923. + hc->do_ping = 0;
  71924. + } else {
  71925. + hc->do_ping = qh->ping_state;
  71926. + }
  71927. +
  71928. + hc->data_pid_start = qh->data_toggle;
  71929. + hc->multi_count = 1;
  71930. +
  71931. + if (hcd->core_if->dma_enable) {
  71932. + hc->xfer_buff = (uint8_t *) urb->dma + urb->actual_length;
  71933. +
  71934. + /* For non-dword aligned case */
  71935. + if (((unsigned long)hc->xfer_buff & 0x3)
  71936. + && !hcd->core_if->dma_desc_enable) {
  71937. + ptr = (uint8_t *) urb->buf + urb->actual_length;
  71938. + }
  71939. + } else {
  71940. + hc->xfer_buff = (uint8_t *) urb->buf + urb->actual_length;
  71941. + }
  71942. + hc->xfer_len = urb->length - urb->actual_length;
  71943. + hc->xfer_count = 0;
  71944. +
  71945. + /*
  71946. + * Set the split attributes
  71947. + */
  71948. + hc->do_split = 0;
  71949. + if (qh->do_split) {
  71950. + uint32_t hub_addr, port_addr;
  71951. + hc->do_split = 1;
  71952. + hc->xact_pos = qtd->isoc_split_pos;
  71953. + /* We don't need to do complete splits anymore */
  71954. +// if(fiq_fsm_enable)
  71955. + if (0)
  71956. + hc->complete_split = qtd->complete_split = 0;
  71957. + else
  71958. + hc->complete_split = qtd->complete_split;
  71959. +
  71960. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
  71961. + hc->hub_addr = (uint8_t) hub_addr;
  71962. + hc->port_addr = (uint8_t) port_addr;
  71963. + }
  71964. +
  71965. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  71966. + case UE_CONTROL:
  71967. + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
  71968. + switch (qtd->control_phase) {
  71969. + case DWC_OTG_CONTROL_SETUP:
  71970. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
  71971. + hc->do_ping = 0;
  71972. + hc->ep_is_in = 0;
  71973. + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
  71974. + if (hcd->core_if->dma_enable) {
  71975. + hc->xfer_buff = (uint8_t *) urb->setup_dma;
  71976. + } else {
  71977. + hc->xfer_buff = (uint8_t *) urb->setup_packet;
  71978. + }
  71979. + hc->xfer_len = 8;
  71980. + ptr = NULL;
  71981. + break;
  71982. + case DWC_OTG_CONTROL_DATA:
  71983. + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
  71984. + hc->data_pid_start = qtd->data_toggle;
  71985. + break;
  71986. + case DWC_OTG_CONTROL_STATUS:
  71987. + /*
  71988. + * Direction is opposite of data direction or IN if no
  71989. + * data.
  71990. + */
  71991. + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
  71992. + if (urb->length == 0) {
  71993. + hc->ep_is_in = 1;
  71994. + } else {
  71995. + hc->ep_is_in =
  71996. + dwc_otg_hcd_is_pipe_out(&urb->pipe_info);
  71997. + }
  71998. + if (hc->ep_is_in) {
  71999. + hc->do_ping = 0;
  72000. + }
  72001. +
  72002. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  72003. +
  72004. + hc->xfer_len = 0;
  72005. + if (hcd->core_if->dma_enable) {
  72006. + hc->xfer_buff = (uint8_t *) hcd->status_buf_dma;
  72007. + } else {
  72008. + hc->xfer_buff = (uint8_t *) hcd->status_buf;
  72009. + }
  72010. + ptr = NULL;
  72011. + break;
  72012. + }
  72013. + break;
  72014. + case UE_BULK:
  72015. + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
  72016. + break;
  72017. + case UE_INTERRUPT:
  72018. + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
  72019. + break;
  72020. + case UE_ISOCHRONOUS:
  72021. + {
  72022. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  72023. +
  72024. + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
  72025. +
  72026. + if (hcd->core_if->dma_desc_enable)
  72027. + break;
  72028. +
  72029. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  72030. +
  72031. + frame_desc->status = 0;
  72032. +
  72033. + if (hcd->core_if->dma_enable) {
  72034. + hc->xfer_buff = (uint8_t *) urb->dma;
  72035. + } else {
  72036. + hc->xfer_buff = (uint8_t *) urb->buf;
  72037. + }
  72038. + hc->xfer_buff +=
  72039. + frame_desc->offset + qtd->isoc_split_offset;
  72040. + hc->xfer_len =
  72041. + frame_desc->length - qtd->isoc_split_offset;
  72042. +
  72043. + /* For non-dword aligned buffers */
  72044. + if (((unsigned long)hc->xfer_buff & 0x3)
  72045. + && hcd->core_if->dma_enable) {
  72046. + ptr =
  72047. + (uint8_t *) urb->buf + frame_desc->offset +
  72048. + qtd->isoc_split_offset;
  72049. + } else
  72050. + ptr = NULL;
  72051. +
  72052. + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  72053. + if (hc->xfer_len <= 188) {
  72054. + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
  72055. + } else {
  72056. + hc->xact_pos =
  72057. + DWC_HCSPLIT_XACTPOS_BEGIN;
  72058. + }
  72059. + }
  72060. + }
  72061. + break;
  72062. + }
  72063. + /* non DWORD-aligned buffer case */
  72064. + if (ptr) {
  72065. + uint32_t buf_size;
  72066. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  72067. + buf_size = hcd->core_if->core_params->max_transfer_size;
  72068. + } else {
  72069. + buf_size = 4096;
  72070. + }
  72071. + if (!qh->dw_align_buf) {
  72072. + qh->dw_align_buf = DWC_DMA_ALLOC_ATOMIC(buf_size,
  72073. + &qh->dw_align_buf_dma);
  72074. + if (!qh->dw_align_buf) {
  72075. + DWC_ERROR
  72076. + ("%s: Failed to allocate memory to handle "
  72077. + "non-dword aligned buffer case\n",
  72078. + __func__);
  72079. + return;
  72080. + }
  72081. + }
  72082. + if (!hc->ep_is_in) {
  72083. + dwc_memcpy(qh->dw_align_buf, ptr, hc->xfer_len);
  72084. + }
  72085. + hc->align_buff = qh->dw_align_buf_dma;
  72086. + } else {
  72087. + hc->align_buff = 0;
  72088. + }
  72089. +
  72090. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  72091. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  72092. + /*
  72093. + * This value may be modified when the transfer is started to
  72094. + * reflect the actual transfer length.
  72095. + */
  72096. + hc->multi_count = dwc_hb_mult(qh->maxp);
  72097. + }
  72098. +
  72099. + if (hcd->core_if->dma_desc_enable)
  72100. + hc->desc_list_addr = qh->desc_list_dma;
  72101. +
  72102. + dwc_otg_hc_init(hcd->core_if, hc);
  72103. + hc->qh = qh;
  72104. +}
  72105. +
  72106. +
  72107. +/**
  72108. + * fiq_fsm_transaction_suitable() - Test a QH for compatibility with the FIQ
  72109. + * @qh: pointer to the endpoint's queue head
  72110. + *
  72111. + * Transaction start/end control flow is grafted onto the existing dwc_otg
  72112. + * mechanisms, to avoid spaghettifying the functions more than they already are.
  72113. + * This function's eligibility check is altered by debug parameter.
  72114. + *
  72115. + * Returns: 0 for unsuitable, 1 implies the FIQ can be enabled for this transaction.
  72116. + */
  72117. +
  72118. +int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh)
  72119. +{
  72120. + if (qh->do_split) {
  72121. + switch (qh->ep_type) {
  72122. + case UE_CONTROL:
  72123. + case UE_BULK:
  72124. + if (fiq_fsm_mask & (1 << 0))
  72125. + return 1;
  72126. + break;
  72127. + case UE_INTERRUPT:
  72128. + case UE_ISOCHRONOUS:
  72129. + if (fiq_fsm_mask & (1 << 1))
  72130. + return 1;
  72131. + break;
  72132. + default:
  72133. + break;
  72134. + }
  72135. + } else if (qh->ep_type == UE_ISOCHRONOUS) {
  72136. + if (fiq_fsm_mask & (1 << 2)) {
  72137. + /* HS ISOCH support. We test for compatibility:
  72138. + * - DWORD aligned buffers
  72139. + * - Must be at least 2 transfers (otherwise pointless to use the FIQ)
  72140. + * If yes, then the fsm enqueue function will handle the state machine setup.
  72141. + */
  72142. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  72143. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  72144. + struct dwc_otg_hcd_iso_packet_desc (*iso_descs)[0] = &urb->iso_descs;
  72145. + int nr_iso_frames = urb->packet_count;
  72146. + int i;
  72147. + uint32_t ptr;
  72148. +
  72149. + if (nr_iso_frames < 2)
  72150. + return 0;
  72151. + for (i = 0; i < nr_iso_frames; i++) {
  72152. + ptr = urb->dma + iso_descs[i]->offset;
  72153. + if (ptr & 0x3) {
  72154. + printk_ratelimited("%s: Non-Dword aligned isochronous frame offset."
  72155. + " Cannot queue FIQ-accelerated transfer to device %d endpoint %d\n",
  72156. + __FUNCTION__, qh->channel->dev_addr, qh->channel->ep_num);
  72157. + return 0;
  72158. + }
  72159. + }
  72160. + return 1;
  72161. + }
  72162. + }
  72163. + return 0;
  72164. +}
  72165. +
  72166. +/**
  72167. + * fiq_fsm_setup_periodic_dma() - Set up DMA bounce buffers
  72168. + * @hcd: Pointer to the dwc_otg_hcd struct
  72169. + * @qh: Pointer to the endpoint's queue head
  72170. + *
  72171. + * Periodic split transactions are transmitted modulo 188 bytes.
  72172. + * This necessitates slicing data up into buckets for isochronous out
  72173. + * and fixing up the DMA address for all IN transfers.
  72174. + *
  72175. + * Returns 1 if the DMA bounce buffers have been used, 0 if the default
  72176. + * HC buffer has been used.
  72177. + */
  72178. +int fiq_fsm_setup_periodic_dma(dwc_otg_hcd_t *hcd, struct fiq_channel_state *st, dwc_otg_qh_t *qh)
  72179. + {
  72180. + int frame_length, i = 0;
  72181. + uint8_t *ptr = NULL;
  72182. + dwc_hc_t *hc = qh->channel;
  72183. + struct fiq_dma_blob *blob;
  72184. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  72185. +
  72186. + for (i = 0; i < 6; i++) {
  72187. + st->dma_info.slot_len[i] = 255;
  72188. + }
  72189. + st->dma_info.index = 0;
  72190. + i = 0;
  72191. + if (hc->ep_is_in) {
  72192. + /*
  72193. + * Set dma_regs to bounce buffer. FIQ will update the
  72194. + * state depending on transaction progress.
  72195. + */
  72196. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  72197. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  72198. + /* Calculate the max number of CSPLITS such that the FIQ can time out
  72199. + * a transaction if it fails.
  72200. + */
  72201. + frame_length = st->hcchar_copy.b.mps;
  72202. + do {
  72203. + i++;
  72204. + frame_length -= 188;
  72205. + } while (frame_length >= 0);
  72206. + st->nrpackets = i;
  72207. + return 1;
  72208. + } else {
  72209. + if (qh->ep_type == UE_ISOCHRONOUS) {
  72210. +
  72211. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  72212. +
  72213. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  72214. + frame_length = frame_desc->length;
  72215. +
  72216. + /* Virtual address for bounce buffers */
  72217. + blob = hcd->fiq_dmab;
  72218. +
  72219. + ptr = qtd->urb->buf + frame_desc->offset;
  72220. + if (frame_length == 0) {
  72221. + /*
  72222. + * for isochronous transactions, we must still transmit a packet
  72223. + * even if the length is zero.
  72224. + */
  72225. + st->dma_info.slot_len[0] = 0;
  72226. + st->nrpackets = 1;
  72227. + } else {
  72228. + do {
  72229. + if (frame_length <= 188) {
  72230. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, frame_length);
  72231. + st->dma_info.slot_len[i] = frame_length;
  72232. + ptr += frame_length;
  72233. + } else {
  72234. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, 188);
  72235. + st->dma_info.slot_len[i] = 188;
  72236. + ptr += 188;
  72237. + }
  72238. + i++;
  72239. + frame_length -= 188;
  72240. + } while (frame_length > 0);
  72241. + st->nrpackets = i;
  72242. + }
  72243. + ptr = qtd->urb->buf + frame_desc->offset;
  72244. + /* Point the HC at the DMA address of the bounce buffers */
  72245. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  72246. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  72247. +
  72248. + /* fixup xfersize to the actual packet size */
  72249. + st->hctsiz_copy.b.pid = 0;
  72250. + st->hctsiz_copy.b.xfersize = st->dma_info.slot_len[0];
  72251. + return 1;
  72252. + } else {
  72253. + /* For interrupt, single OUT packet required, goes in the SSPLIT from hc_buff. */
  72254. + return 0;
  72255. + }
  72256. + }
  72257. +}
  72258. +
  72259. +/*
  72260. + * Pushing a periodic request into the queue near the EOF1 point
  72261. + * in a microframe causes erroneous behaviour (frmovrun) interrupt.
  72262. + * Usually, the request goes out on the bus causing a transfer but
  72263. + * the core does not transfer the data to memory.
  72264. + * This guard interval (in number of 60MHz clocks) is required which
  72265. + * must cater for CPU latency between reading the value and enabling
  72266. + * the channel.
  72267. + */
  72268. +#define PERIODIC_FRREM_BACKOFF 1000
  72269. +
  72270. +int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  72271. +{
  72272. + dwc_hc_t *hc = qh->channel;
  72273. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  72274. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  72275. + int frame;
  72276. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  72277. + int xfer_len, nrpackets;
  72278. + hcdma_data_t hcdma;
  72279. + hfnum_data_t hfnum;
  72280. +
  72281. + if (st->fsm != FIQ_PASSTHROUGH)
  72282. + return 0;
  72283. +
  72284. + st->nr_errors = 0;
  72285. +
  72286. + st->hcchar_copy.d32 = 0;
  72287. + st->hcchar_copy.b.mps = hc->max_packet;
  72288. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  72289. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  72290. + st->hcchar_copy.b.epnum = hc->ep_num;
  72291. + st->hcchar_copy.b.eptype = hc->ep_type;
  72292. +
  72293. + st->hcintmsk_copy.b.chhltd = 1;
  72294. +
  72295. + frame = dwc_otg_hcd_get_frame_number(hcd);
  72296. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  72297. +
  72298. + st->hcchar_copy.b.lspddev = 0;
  72299. + /* Enable the channel later as a final register write. */
  72300. +
  72301. + st->hcsplt_copy.d32 = 0;
  72302. +
  72303. + st->hs_isoc_info.iso_desc = (struct dwc_otg_hcd_iso_packet_desc *) &qtd->urb->iso_descs;
  72304. + st->hs_isoc_info.nrframes = qtd->urb->packet_count;
  72305. + /* grab the next DMA address offset from the array */
  72306. + st->hcdma_copy.d32 = qtd->urb->dma;
  72307. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[0].offset;
  72308. +
  72309. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  72310. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  72311. + * this is always set to the maximum size of the endpoint. */
  72312. + xfer_len = st->hs_isoc_info.iso_desc[0].length;
  72313. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  72314. + if (nrpackets == 0)
  72315. + nrpackets = 1;
  72316. + st->hcchar_copy.b.multicnt = nrpackets;
  72317. + st->hctsiz_copy.b.pktcnt = nrpackets;
  72318. +
  72319. + /* Initial PID also needs to be set */
  72320. + if (st->hcchar_copy.b.epdir == 0) {
  72321. + st->hctsiz_copy.b.xfersize = xfer_len;
  72322. + switch (st->hcchar_copy.b.multicnt) {
  72323. + case 1:
  72324. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  72325. + break;
  72326. + case 2:
  72327. + case 3:
  72328. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  72329. + break;
  72330. + }
  72331. +
  72332. + } else {
  72333. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  72334. + switch (st->hcchar_copy.b.multicnt) {
  72335. + case 1:
  72336. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  72337. + break;
  72338. + case 2:
  72339. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  72340. + break;
  72341. + case 3:
  72342. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  72343. + break;
  72344. + }
  72345. + }
  72346. +
  72347. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d ", hc->hc_num);
  72348. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcchar_copy.d32);
  72349. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  72350. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  72351. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  72352. + local_fiq_disable();
  72353. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  72354. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  72355. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  72356. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  72357. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  72358. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  72359. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  72360. + * split transaction is queued very close to EOF.
  72361. + */
  72362. + st->fsm = FIQ_HS_ISOC_SLEEPING;
  72363. + } else {
  72364. + st->fsm = FIQ_HS_ISOC_TURBO;
  72365. + st->hcchar_copy.b.chen = 1;
  72366. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  72367. + }
  72368. + mb();
  72369. + st->hcchar_copy.b.chen = 0;
  72370. + local_fiq_enable();
  72371. + return 0;
  72372. +}
  72373. +
  72374. +
  72375. +/**
  72376. + * fiq_fsm_queue_split_transaction() - Set up a host channel and FIQ state
  72377. + * @hcd: Pointer to the dwc_otg_hcd struct
  72378. + * @qh: Pointer to the endpoint's queue head
  72379. + *
  72380. + * This overrides the dwc_otg driver's normal method of queueing a transaction.
  72381. + * Called from dwc_otg_hcd_queue_transactions(), this performs specific setup
  72382. + * for the nominated host channel.
  72383. + *
  72384. + * For periodic transfers, it also peeks at the FIQ state to see if an immediate
  72385. + * start is possible. If not, then the FIQ is left to start the transfer.
  72386. + */
  72387. +int fiq_fsm_queue_split_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  72388. +{
  72389. + int start_immediate = 1, i;
  72390. + hfnum_data_t hfnum;
  72391. + dwc_hc_t *hc = qh->channel;
  72392. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  72393. + /* Program HC registers, setup FIQ_state, examine FIQ if periodic, start transfer (not if uframe 5) */
  72394. + int hub_addr, port_addr, frame, uframe;
  72395. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  72396. +
  72397. + if (st->fsm != FIQ_PASSTHROUGH)
  72398. + return 0;
  72399. + st->nr_errors = 0;
  72400. +
  72401. + st->hcchar_copy.d32 = 0;
  72402. + st->hcchar_copy.b.mps = hc->max_packet;
  72403. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  72404. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  72405. + st->hcchar_copy.b.epnum = hc->ep_num;
  72406. + st->hcchar_copy.b.eptype = hc->ep_type;
  72407. + if (hc->ep_type & 0x1) {
  72408. + if (hc->ep_is_in)
  72409. + st->hcchar_copy.b.multicnt = 3;
  72410. + else
  72411. + /* Docs say set this to 1, but driver sets to 0! */
  72412. + st->hcchar_copy.b.multicnt = 0;
  72413. + } else {
  72414. + st->hcchar_copy.b.multicnt = 1;
  72415. + st->hcchar_copy.b.oddfrm = 0;
  72416. + }
  72417. + st->hcchar_copy.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW) ? 1 : 0;
  72418. + /* Enable the channel later as a final register write. */
  72419. +
  72420. + st->hcsplt_copy.d32 = 0;
  72421. + if(qh->do_split) {
  72422. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  72423. + st->hcsplt_copy.b.compsplt = 0;
  72424. + st->hcsplt_copy.b.spltena = 1;
  72425. + // XACTPOS is for isoc-out only but needs initialising anyway.
  72426. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_ALL;
  72427. + if((qh->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!qh->ep_is_in)) {
  72428. + /* For packetsize 0 < L < 188, ISOC_XACTPOS_ALL.
  72429. + * for longer than this, ISOC_XACTPOS_BEGIN and the FIQ
  72430. + * will update as necessary.
  72431. + */
  72432. + if (hc->xfer_len > 188) {
  72433. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_BEGIN;
  72434. + }
  72435. + }
  72436. + st->hcsplt_copy.b.hubaddr = (uint8_t) hub_addr;
  72437. + st->hcsplt_copy.b.prtaddr = (uint8_t) port_addr;
  72438. + st->hub_addr = hub_addr;
  72439. + st->port_addr = port_addr;
  72440. + }
  72441. +
  72442. + st->hctsiz_copy.d32 = 0;
  72443. + st->hctsiz_copy.b.dopng = 0;
  72444. + st->hctsiz_copy.b.pid = hc->data_pid_start;
  72445. +
  72446. + if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  72447. + hc->xfer_len = hc->max_packet;
  72448. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  72449. + hc->xfer_len = 188;
  72450. + }
  72451. + st->hctsiz_copy.b.xfersize = hc->xfer_len;
  72452. +
  72453. + st->hctsiz_copy.b.pktcnt = 1;
  72454. +
  72455. + if (hc->ep_type & 0x1) {
  72456. + /*
  72457. + * For potentially multi-packet transfers, must use the DMA bounce buffers. For IN transfers,
  72458. + * the DMA address is the address of the first 188byte slot buffer in the bounce buffer array.
  72459. + * For multi-packet OUT transfers, we need to copy the data into the bounce buffer array so the FIQ can punt
  72460. + * the right address out as necessary. hc->xfer_buff and hc->xfer_len have already been set
  72461. + * in assign_and_init_hc(), but this is for the eventual transaction completion only. The FIQ
  72462. + * must not touch internal driver state.
  72463. + */
  72464. + if(!fiq_fsm_setup_periodic_dma(hcd, st, qh)) {
  72465. + if (hc->align_buff) {
  72466. + st->hcdma_copy.d32 = hc->align_buff;
  72467. + } else {
  72468. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  72469. + }
  72470. + }
  72471. + } else {
  72472. + if (hc->align_buff) {
  72473. + st->hcdma_copy.d32 = hc->align_buff;
  72474. + } else {
  72475. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  72476. + }
  72477. + }
  72478. + /* The FIQ depends upon no other interrupts being enabled except channel halt.
  72479. + * Fixup channel interrupt mask. */
  72480. + st->hcintmsk_copy.d32 = 0;
  72481. + st->hcintmsk_copy.b.chhltd = 1;
  72482. + st->hcintmsk_copy.b.ahberr = 1;
  72483. +
  72484. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  72485. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  72486. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  72487. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  72488. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  72489. +
  72490. + local_fiq_disable();
  72491. + mb();
  72492. +
  72493. + if (hc->ep_type & 0x1) {
  72494. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  72495. + frame = (hfnum.b.frnum & ~0x7) >> 3;
  72496. + uframe = hfnum.b.frnum & 0x7;
  72497. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  72498. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  72499. + * split transaction is queued very close to EOF.
  72500. + */
  72501. + start_immediate = 0;
  72502. + } else if (uframe == 5) {
  72503. + start_immediate = 0;
  72504. + } else if (hc->ep_type == UE_ISOCHRONOUS && !hc->ep_is_in) {
  72505. + start_immediate = 0;
  72506. + } else if (hc->ep_is_in && fiq_fsm_too_late(hcd->fiq_state, hc->hc_num)) {
  72507. + start_immediate = 0;
  72508. + } else {
  72509. + /* Search through all host channels to determine if a transaction
  72510. + * is currently in progress */
  72511. + for (i = 0; i < hcd->core_if->core_params->host_channels; i++) {
  72512. + if (i == hc->hc_num || hcd->fiq_state->channel[i].fsm == FIQ_PASSTHROUGH)
  72513. + continue;
  72514. + switch (hcd->fiq_state->channel[i].fsm) {
  72515. + /* TT is reserved for channels that are in the middle of a periodic
  72516. + * split transaction.
  72517. + */
  72518. + case FIQ_PER_SSPLIT_STARTED:
  72519. + case FIQ_PER_CSPLIT_WAIT:
  72520. + case FIQ_PER_CSPLIT_NYET1:
  72521. + case FIQ_PER_CSPLIT_POLL:
  72522. + case FIQ_PER_ISO_OUT_ACTIVE:
  72523. + case FIQ_PER_ISO_OUT_LAST:
  72524. + if (hcd->fiq_state->channel[i].hub_addr == hub_addr &&
  72525. + hcd->fiq_state->channel[i].port_addr == port_addr) {
  72526. + start_immediate = 0;
  72527. + }
  72528. + break;
  72529. + default:
  72530. + break;
  72531. + }
  72532. + if (!start_immediate)
  72533. + break;
  72534. + }
  72535. + }
  72536. + }
  72537. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d %01d", hc->hc_num, start_immediate);
  72538. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08d", hfnum.b.frrem);
  72539. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "H:%02dP:%02d", hub_addr, port_addr);
  72540. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  72541. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  72542. + switch (hc->ep_type) {
  72543. + case UE_CONTROL:
  72544. + case UE_BULK:
  72545. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  72546. + break;
  72547. + case UE_ISOCHRONOUS:
  72548. + if (hc->ep_is_in) {
  72549. + if (start_immediate) {
  72550. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  72551. + } else {
  72552. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  72553. + }
  72554. + } else {
  72555. + if (start_immediate) {
  72556. + /* Single-isoc OUT packets don't require FIQ involvement */
  72557. + if (st->nrpackets == 1) {
  72558. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  72559. + } else {
  72560. + st->fsm = FIQ_PER_ISO_OUT_ACTIVE;
  72561. + }
  72562. + } else {
  72563. + st->fsm = FIQ_PER_ISO_OUT_PENDING;
  72564. + }
  72565. + }
  72566. + break;
  72567. + case UE_INTERRUPT:
  72568. + if (start_immediate) {
  72569. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  72570. + } else {
  72571. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  72572. + }
  72573. + default:
  72574. + break;
  72575. + }
  72576. + if (start_immediate) {
  72577. + /* Set the oddfrm bit as close as possible to actual queueing */
  72578. + frame = dwc_otg_hcd_get_frame_number(hcd);
  72579. + st->expected_uframe = (frame + 1) & 0x3FFF;
  72580. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  72581. + st->hcchar_copy.b.chen = 1;
  72582. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  72583. + }
  72584. + mb();
  72585. + local_fiq_enable();
  72586. + return 0;
  72587. +}
  72588. +
  72589. +
  72590. +/**
  72591. + * This function selects transactions from the HCD transfer schedule and
  72592. + * assigns them to available host channels. It is called from HCD interrupt
  72593. + * handler functions.
  72594. + *
  72595. + * @param hcd The HCD state structure.
  72596. + *
  72597. + * @return The types of new transactions that were assigned to host channels.
  72598. + */
  72599. +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
  72600. +{
  72601. + dwc_list_link_t *qh_ptr;
  72602. + dwc_otg_qh_t *qh;
  72603. + int num_channels;
  72604. + dwc_irqflags_t flags;
  72605. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  72606. + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  72607. +
  72608. +#ifdef DEBUG_HOST_CHANNELS
  72609. + last_sel_trans_num_per_scheduled = 0;
  72610. + last_sel_trans_num_nonper_scheduled = 0;
  72611. + last_sel_trans_num_avail_hc_at_start = hcd->available_host_channels;
  72612. +#endif /* DEBUG_HOST_CHANNELS */
  72613. +
  72614. + /* Process entries in the periodic ready list. */
  72615. + qh_ptr = DWC_LIST_FIRST(&hcd->periodic_sched_ready);
  72616. +
  72617. + while (qh_ptr != &hcd->periodic_sched_ready &&
  72618. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  72619. +
  72620. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  72621. +
  72622. + if (microframe_schedule) {
  72623. + // Make sure we leave one channel for non periodic transactions.
  72624. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  72625. + if (hcd->available_host_channels <= 1) {
  72626. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72627. + break;
  72628. + }
  72629. + hcd->available_host_channels--;
  72630. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72631. +#ifdef DEBUG_HOST_CHANNELS
  72632. + last_sel_trans_num_per_scheduled++;
  72633. +#endif /* DEBUG_HOST_CHANNELS */
  72634. + }
  72635. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  72636. + assign_and_init_hc(hcd, qh);
  72637. +
  72638. + /*
  72639. + * Move the QH from the periodic ready schedule to the
  72640. + * periodic assigned schedule.
  72641. + */
  72642. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  72643. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  72644. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  72645. + &qh->qh_list_entry);
  72646. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72647. + }
  72648. +
  72649. + /*
  72650. + * Process entries in the inactive portion of the non-periodic
  72651. + * schedule. Some free host channels may not be used if they are
  72652. + * reserved for periodic transfers.
  72653. + */
  72654. + qh_ptr = hcd->non_periodic_sched_inactive.next;
  72655. + num_channels = hcd->core_if->core_params->host_channels;
  72656. + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
  72657. + (microframe_schedule || hcd->non_periodic_channels <
  72658. + num_channels - hcd->periodic_channels) &&
  72659. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  72660. +
  72661. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  72662. + /*
  72663. + * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  72664. + * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  72665. + * cheeky devices that just hold off using NAKs
  72666. + */
  72667. + if (nak_holdoff && qh->do_split) {
  72668. + if (qh->nak_frame != 0xffff) {
  72669. + uint16_t next_frame = dwc_frame_num_inc(qh->nak_frame, (qh->ep_type == UE_BULK) ? nak_holdoff : 8);
  72670. + uint16_t frame = dwc_otg_hcd_get_frame_number(hcd);
  72671. + if (dwc_frame_num_le(frame, next_frame)) {
  72672. + if(dwc_frame_num_le(next_frame, hcd->fiq_state->next_sched_frame)) {
  72673. + hcd->fiq_state->next_sched_frame = next_frame;
  72674. + }
  72675. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  72676. + continue;
  72677. + } else {
  72678. + qh->nak_frame = 0xFFFF;
  72679. + }
  72680. + }
  72681. + }
  72682. +
  72683. + if (microframe_schedule) {
  72684. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  72685. + if (hcd->available_host_channels < 1) {
  72686. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72687. + break;
  72688. + }
  72689. + hcd->available_host_channels--;
  72690. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72691. +#ifdef DEBUG_HOST_CHANNELS
  72692. + last_sel_trans_num_nonper_scheduled++;
  72693. +#endif /* DEBUG_HOST_CHANNELS */
  72694. + }
  72695. +
  72696. + assign_and_init_hc(hcd, qh);
  72697. +
  72698. + /*
  72699. + * Move the QH from the non-periodic inactive schedule to the
  72700. + * non-periodic active schedule.
  72701. + */
  72702. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  72703. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  72704. + DWC_LIST_MOVE_HEAD(&hcd->non_periodic_sched_active,
  72705. + &qh->qh_list_entry);
  72706. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72707. +
  72708. +
  72709. + if (!microframe_schedule)
  72710. + hcd->non_periodic_channels++;
  72711. + }
  72712. + /* we moved a non-periodic QH to the active schedule. If the inactive queue is empty,
  72713. + * stop the FIQ from kicking us. We could potentially still have elements here if we
  72714. + * ran out of host channels.
  72715. + */
  72716. + if (DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive)) {
  72717. + hcd->fiq_state->kick_np_queues = 0;
  72718. + } else {
  72719. + /* For each entry remaining in the NP inactive queue,
  72720. + * if this a NAK'd retransmit then don't set the kick flag.
  72721. + */
  72722. + if(nak_holdoff) {
  72723. + DWC_LIST_FOREACH(qh_ptr, &hcd->non_periodic_sched_inactive) {
  72724. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  72725. + if (qh->nak_frame == 0xFFFF) {
  72726. + hcd->fiq_state->kick_np_queues = 1;
  72727. + }
  72728. + }
  72729. + }
  72730. + }
  72731. + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  72732. + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  72733. +
  72734. + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
  72735. + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
  72736. +
  72737. +
  72738. +#ifdef DEBUG_HOST_CHANNELS
  72739. + last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
  72740. +#endif /* DEBUG_HOST_CHANNELS */
  72741. + return ret_val;
  72742. +}
  72743. +
  72744. +/**
  72745. + * Attempts to queue a single transaction request for a host channel
  72746. + * associated with either a periodic or non-periodic transfer. This function
  72747. + * assumes that there is space available in the appropriate request queue. For
  72748. + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
  72749. + * is available in the appropriate Tx FIFO.
  72750. + *
  72751. + * @param hcd The HCD state structure.
  72752. + * @param hc Host channel descriptor associated with either a periodic or
  72753. + * non-periodic transfer.
  72754. + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
  72755. + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
  72756. + * transfers.
  72757. + *
  72758. + * @return 1 if a request is queued and more requests may be needed to
  72759. + * complete the transfer, 0 if no more requests are required for this
  72760. + * transfer, -1 if there is insufficient space in the Tx FIFO.
  72761. + */
  72762. +static int queue_transaction(dwc_otg_hcd_t * hcd,
  72763. + dwc_hc_t * hc, uint16_t fifo_dwords_avail)
  72764. +{
  72765. + int retval;
  72766. +
  72767. + if (hcd->core_if->dma_enable) {
  72768. + if (hcd->core_if->dma_desc_enable) {
  72769. + if (!hc->xfer_started
  72770. + || (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
  72771. + dwc_otg_hcd_start_xfer_ddma(hcd, hc->qh);
  72772. + hc->qh->ping_state = 0;
  72773. + }
  72774. + } else if (!hc->xfer_started) {
  72775. + if (fiq_fsm_enable && hc->error_state) {
  72776. + hcd->fiq_state->channel[hc->hc_num].nr_errors =
  72777. + DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list)->error_count;
  72778. + hcd->fiq_state->channel[hc->hc_num].fsm =
  72779. + FIQ_PASSTHROUGH_ERRORSTATE;
  72780. + }
  72781. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  72782. + hc->qh->ping_state = 0;
  72783. + }
  72784. + retval = 0;
  72785. + } else if (hc->halt_pending) {
  72786. + /* Don't queue a request if the channel has been halted. */
  72787. + retval = 0;
  72788. + } else if (hc->halt_on_queue) {
  72789. + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
  72790. + retval = 0;
  72791. + } else if (hc->do_ping) {
  72792. + if (!hc->xfer_started) {
  72793. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  72794. + }
  72795. + retval = 0;
  72796. + } else if (!hc->ep_is_in || hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  72797. + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
  72798. + if (!hc->xfer_started) {
  72799. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  72800. + retval = 1;
  72801. + } else {
  72802. + retval =
  72803. + dwc_otg_hc_continue_transfer(hcd->core_if,
  72804. + hc);
  72805. + }
  72806. + } else {
  72807. + retval = -1;
  72808. + }
  72809. + } else {
  72810. + if (!hc->xfer_started) {
  72811. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  72812. + retval = 1;
  72813. + } else {
  72814. + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
  72815. + }
  72816. + }
  72817. +
  72818. + return retval;
  72819. +}
  72820. +
  72821. +/**
  72822. + * Processes periodic channels for the next frame and queues transactions for
  72823. + * these channels to the DWC_otg controller. After queueing transactions, the
  72824. + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
  72825. + * to queue as Periodic Tx FIFO or request queue space becomes available.
  72826. + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
  72827. + */
  72828. +static void process_periodic_channels(dwc_otg_hcd_t * hcd)
  72829. +{
  72830. + hptxsts_data_t tx_status;
  72831. + dwc_list_link_t *qh_ptr;
  72832. + dwc_otg_qh_t *qh;
  72833. + int status = 0;
  72834. + int no_queue_space = 0;
  72835. + int no_fifo_space = 0;
  72836. +
  72837. + dwc_otg_host_global_regs_t *host_regs;
  72838. + host_regs = hcd->core_if->host_if->host_global_regs;
  72839. +
  72840. + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
  72841. +#ifdef DEBUG
  72842. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  72843. + DWC_DEBUGPL(DBG_HCDV,
  72844. + " P Tx Req Queue Space Avail (before queue): %d\n",
  72845. + tx_status.b.ptxqspcavail);
  72846. + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
  72847. + tx_status.b.ptxfspcavail);
  72848. +#endif
  72849. +
  72850. + qh_ptr = hcd->periodic_sched_assigned.next;
  72851. + while (qh_ptr != &hcd->periodic_sched_assigned) {
  72852. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  72853. + if (tx_status.b.ptxqspcavail == 0) {
  72854. + no_queue_space = 1;
  72855. + break;
  72856. + }
  72857. +
  72858. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  72859. +
  72860. + // Do not send a split start transaction any later than frame .6
  72861. + // Note, we have to schedule a periodic in .5 to make it go in .6
  72862. + if(fiq_fsm_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  72863. + {
  72864. + qh_ptr = qh_ptr->next;
  72865. + hcd->fiq_state->next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  72866. + continue;
  72867. + }
  72868. +
  72869. + if (fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  72870. + if (qh->do_split)
  72871. + fiq_fsm_queue_split_transaction(hcd, qh);
  72872. + else
  72873. + fiq_fsm_queue_isoc_transaction(hcd, qh);
  72874. + } else {
  72875. +
  72876. + /*
  72877. + * Set a flag if we're queueing high-bandwidth in slave mode.
  72878. + * The flag prevents any halts to get into the request queue in
  72879. + * the middle of multiple high-bandwidth packets getting queued.
  72880. + */
  72881. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  72882. + hcd->core_if->queuing_high_bandwidth = 1;
  72883. + }
  72884. + status = queue_transaction(hcd, qh->channel,
  72885. + tx_status.b.ptxfspcavail);
  72886. + if (status < 0) {
  72887. + no_fifo_space = 1;
  72888. + break;
  72889. + }
  72890. + }
  72891. +
  72892. + /*
  72893. + * In Slave mode, stay on the current transfer until there is
  72894. + * nothing more to do or the high-bandwidth request count is
  72895. + * reached. In DMA mode, only need to queue one request. The
  72896. + * controller automatically handles multiple packets for
  72897. + * high-bandwidth transfers.
  72898. + */
  72899. + if (hcd->core_if->dma_enable || status == 0 ||
  72900. + qh->channel->requests == qh->channel->multi_count) {
  72901. + qh_ptr = qh_ptr->next;
  72902. + /*
  72903. + * Move the QH from the periodic assigned schedule to
  72904. + * the periodic queued schedule.
  72905. + */
  72906. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_queued,
  72907. + &qh->qh_list_entry);
  72908. +
  72909. + /* done queuing high bandwidth */
  72910. + hcd->core_if->queuing_high_bandwidth = 0;
  72911. + }
  72912. + }
  72913. +
  72914. + if (!hcd->core_if->dma_enable) {
  72915. + dwc_otg_core_global_regs_t *global_regs;
  72916. + gintmsk_data_t intr_mask = {.d32 = 0 };
  72917. +
  72918. + global_regs = hcd->core_if->core_global_regs;
  72919. + intr_mask.b.ptxfempty = 1;
  72920. +#ifdef DEBUG
  72921. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  72922. + DWC_DEBUGPL(DBG_HCDV,
  72923. + " P Tx Req Queue Space Avail (after queue): %d\n",
  72924. + tx_status.b.ptxqspcavail);
  72925. + DWC_DEBUGPL(DBG_HCDV,
  72926. + " P Tx FIFO Space Avail (after queue): %d\n",
  72927. + tx_status.b.ptxfspcavail);
  72928. +#endif
  72929. + if (!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned) ||
  72930. + no_queue_space || no_fifo_space) {
  72931. + /*
  72932. + * May need to queue more transactions as the request
  72933. + * queue or Tx FIFO empties. Enable the periodic Tx
  72934. + * FIFO empty interrupt. (Always use the half-empty
  72935. + * level to ensure that new requests are loaded as
  72936. + * soon as possible.)
  72937. + */
  72938. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  72939. + intr_mask.d32);
  72940. + } else {
  72941. + /*
  72942. + * Disable the Tx FIFO empty interrupt since there are
  72943. + * no more transactions that need to be queued right
  72944. + * now. This function is called from interrupt
  72945. + * handlers to queue more transactions as transfer
  72946. + * states change.
  72947. + */
  72948. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  72949. + 0);
  72950. + }
  72951. + }
  72952. +}
  72953. +
  72954. +/**
  72955. + * Processes active non-periodic channels and queues transactions for these
  72956. + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
  72957. + * FIFO Empty interrupt is enabled if there are more transactions to queue as
  72958. + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
  72959. + * FIFO Empty interrupt is disabled.
  72960. + */
  72961. +static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
  72962. +{
  72963. + gnptxsts_data_t tx_status;
  72964. + dwc_list_link_t *orig_qh_ptr;
  72965. + dwc_otg_qh_t *qh;
  72966. + int status;
  72967. + int no_queue_space = 0;
  72968. + int no_fifo_space = 0;
  72969. + int more_to_do = 0;
  72970. +
  72971. + dwc_otg_core_global_regs_t *global_regs =
  72972. + hcd->core_if->core_global_regs;
  72973. +
  72974. + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
  72975. +#ifdef DEBUG
  72976. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  72977. + DWC_DEBUGPL(DBG_HCDV,
  72978. + " NP Tx Req Queue Space Avail (before queue): %d\n",
  72979. + tx_status.b.nptxqspcavail);
  72980. + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
  72981. + tx_status.b.nptxfspcavail);
  72982. +#endif
  72983. + /*
  72984. + * Keep track of the starting point. Skip over the start-of-list
  72985. + * entry.
  72986. + */
  72987. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  72988. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  72989. + }
  72990. + orig_qh_ptr = hcd->non_periodic_qh_ptr;
  72991. +
  72992. + /*
  72993. + * Process once through the active list or until no more space is
  72994. + * available in the request queue or the Tx FIFO.
  72995. + */
  72996. + do {
  72997. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  72998. + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
  72999. + no_queue_space = 1;
  73000. + break;
  73001. + }
  73002. +
  73003. + qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  73004. + qh_list_entry);
  73005. +
  73006. + if(fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  73007. + fiq_fsm_queue_split_transaction(hcd, qh);
  73008. + } else {
  73009. + status = queue_transaction(hcd, qh->channel,
  73010. + tx_status.b.nptxfspcavail);
  73011. +
  73012. + if (status > 0) {
  73013. + more_to_do = 1;
  73014. + } else if (status < 0) {
  73015. + no_fifo_space = 1;
  73016. + break;
  73017. + }
  73018. + }
  73019. + /* Advance to next QH, skipping start-of-list entry. */
  73020. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  73021. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  73022. + hcd->non_periodic_qh_ptr =
  73023. + hcd->non_periodic_qh_ptr->next;
  73024. + }
  73025. +
  73026. + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
  73027. +
  73028. + if (!hcd->core_if->dma_enable) {
  73029. + gintmsk_data_t intr_mask = {.d32 = 0 };
  73030. + intr_mask.b.nptxfempty = 1;
  73031. +
  73032. +#ifdef DEBUG
  73033. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  73034. + DWC_DEBUGPL(DBG_HCDV,
  73035. + " NP Tx Req Queue Space Avail (after queue): %d\n",
  73036. + tx_status.b.nptxqspcavail);
  73037. + DWC_DEBUGPL(DBG_HCDV,
  73038. + " NP Tx FIFO Space Avail (after queue): %d\n",
  73039. + tx_status.b.nptxfspcavail);
  73040. +#endif
  73041. + if (more_to_do || no_queue_space || no_fifo_space) {
  73042. + /*
  73043. + * May need to queue more transactions as the request
  73044. + * queue or Tx FIFO empties. Enable the non-periodic
  73045. + * Tx FIFO empty interrupt. (Always use the half-empty
  73046. + * level to ensure that new requests are loaded as
  73047. + * soon as possible.)
  73048. + */
  73049. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  73050. + intr_mask.d32);
  73051. + } else {
  73052. + /*
  73053. + * Disable the Tx FIFO empty interrupt since there are
  73054. + * no more transactions that need to be queued right
  73055. + * now. This function is called from interrupt
  73056. + * handlers to queue more transactions as transfer
  73057. + * states change.
  73058. + */
  73059. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  73060. + 0);
  73061. + }
  73062. + }
  73063. +}
  73064. +
  73065. +/**
  73066. + * This function processes the currently active host channels and queues
  73067. + * transactions for these channels to the DWC_otg controller. It is called
  73068. + * from HCD interrupt handler functions.
  73069. + *
  73070. + * @param hcd The HCD state structure.
  73071. + * @param tr_type The type(s) of transactions to queue (non-periodic,
  73072. + * periodic, or both).
  73073. + */
  73074. +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  73075. + dwc_otg_transaction_type_e tr_type)
  73076. +{
  73077. +#ifdef DEBUG_SOF
  73078. + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
  73079. +#endif
  73080. + /* Process host channels associated with periodic transfers. */
  73081. + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
  73082. + tr_type == DWC_OTG_TRANSACTION_ALL) &&
  73083. + !DWC_LIST_EMPTY(&hcd->periodic_sched_assigned)) {
  73084. +
  73085. + process_periodic_channels(hcd);
  73086. + }
  73087. +
  73088. + /* Process host channels associated with non-periodic transfers. */
  73089. + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
  73090. + tr_type == DWC_OTG_TRANSACTION_ALL) {
  73091. + if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active)) {
  73092. + process_non_periodic_channels(hcd);
  73093. + } else {
  73094. + /*
  73095. + * Ensure NP Tx FIFO empty interrupt is disabled when
  73096. + * there are no non-periodic transfers to process.
  73097. + */
  73098. + gintmsk_data_t gintmsk = {.d32 = 0 };
  73099. + gintmsk.b.nptxfempty = 1;
  73100. + DWC_MODIFY_REG32(&hcd->core_if->
  73101. + core_global_regs->gintmsk, gintmsk.d32,
  73102. + 0);
  73103. + }
  73104. + }
  73105. +}
  73106. +
  73107. +#ifdef DWC_HS_ELECT_TST
  73108. +/*
  73109. + * Quick and dirty hack to implement the HS Electrical Test
  73110. + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
  73111. + *
  73112. + * This code was copied from our userspace app "hset". It sends a
  73113. + * Get Device Descriptor control sequence in two parts, first the
  73114. + * Setup packet by itself, followed some time later by the In and
  73115. + * Ack packets. Rather than trying to figure out how to add this
  73116. + * functionality to the normal driver code, we just hijack the
  73117. + * hardware, using these two function to drive the hardware
  73118. + * directly.
  73119. + */
  73120. +
  73121. +static dwc_otg_core_global_regs_t *global_regs;
  73122. +static dwc_otg_host_global_regs_t *hc_global_regs;
  73123. +static dwc_otg_hc_regs_t *hc_regs;
  73124. +static uint32_t *data_fifo;
  73125. +
  73126. +static void do_setup(void)
  73127. +{
  73128. + gintsts_data_t gintsts;
  73129. + hctsiz_data_t hctsiz;
  73130. + hcchar_data_t hcchar;
  73131. + haint_data_t haint;
  73132. + hcint_data_t hcint;
  73133. +
  73134. + /* Enable HAINTs */
  73135. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  73136. +
  73137. + /* Enable HCINTs */
  73138. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  73139. +
  73140. + /* Read GINTSTS */
  73141. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73142. +
  73143. + /* Read HAINT */
  73144. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73145. +
  73146. + /* Read HCINT */
  73147. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73148. +
  73149. + /* Read HCCHAR */
  73150. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73151. +
  73152. + /* Clear HCINT */
  73153. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73154. +
  73155. + /* Clear HAINT */
  73156. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73157. +
  73158. + /* Clear GINTSTS */
  73159. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73160. +
  73161. + /* Read GINTSTS */
  73162. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73163. +
  73164. + /*
  73165. + * Send Setup packet (Get Device Descriptor)
  73166. + */
  73167. +
  73168. + /* Make sure channel is disabled */
  73169. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73170. + if (hcchar.b.chen) {
  73171. + hcchar.b.chdis = 1;
  73172. +// hcchar.b.chen = 1;
  73173. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73174. + //sleep(1);
  73175. + dwc_mdelay(1000);
  73176. +
  73177. + /* Read GINTSTS */
  73178. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73179. +
  73180. + /* Read HAINT */
  73181. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73182. +
  73183. + /* Read HCINT */
  73184. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73185. +
  73186. + /* Read HCCHAR */
  73187. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73188. +
  73189. + /* Clear HCINT */
  73190. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73191. +
  73192. + /* Clear HAINT */
  73193. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73194. +
  73195. + /* Clear GINTSTS */
  73196. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73197. +
  73198. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73199. + }
  73200. +
  73201. + /* Set HCTSIZ */
  73202. + hctsiz.d32 = 0;
  73203. + hctsiz.b.xfersize = 8;
  73204. + hctsiz.b.pktcnt = 1;
  73205. + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
  73206. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  73207. +
  73208. + /* Set HCCHAR */
  73209. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73210. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  73211. + hcchar.b.epdir = 0;
  73212. + hcchar.b.epnum = 0;
  73213. + hcchar.b.mps = 8;
  73214. + hcchar.b.chen = 1;
  73215. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73216. +
  73217. + /* Fill FIFO with Setup data for Get Device Descriptor */
  73218. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  73219. + DWC_WRITE_REG32(data_fifo++, 0x01000680);
  73220. + DWC_WRITE_REG32(data_fifo++, 0x00080000);
  73221. +
  73222. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73223. +
  73224. + /* Wait for host channel interrupt */
  73225. + do {
  73226. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73227. + } while (gintsts.b.hcintr == 0);
  73228. +
  73229. + /* Disable HCINTs */
  73230. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  73231. +
  73232. + /* Disable HAINTs */
  73233. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  73234. +
  73235. + /* Read HAINT */
  73236. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73237. +
  73238. + /* Read HCINT */
  73239. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73240. +
  73241. + /* Read HCCHAR */
  73242. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73243. +
  73244. + /* Clear HCINT */
  73245. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73246. +
  73247. + /* Clear HAINT */
  73248. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73249. +
  73250. + /* Clear GINTSTS */
  73251. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73252. +
  73253. + /* Read GINTSTS */
  73254. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73255. +}
  73256. +
  73257. +static void do_in_ack(void)
  73258. +{
  73259. + gintsts_data_t gintsts;
  73260. + hctsiz_data_t hctsiz;
  73261. + hcchar_data_t hcchar;
  73262. + haint_data_t haint;
  73263. + hcint_data_t hcint;
  73264. + host_grxsts_data_t grxsts;
  73265. +
  73266. + /* Enable HAINTs */
  73267. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  73268. +
  73269. + /* Enable HCINTs */
  73270. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  73271. +
  73272. + /* Read GINTSTS */
  73273. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73274. +
  73275. + /* Read HAINT */
  73276. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73277. +
  73278. + /* Read HCINT */
  73279. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73280. +
  73281. + /* Read HCCHAR */
  73282. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73283. +
  73284. + /* Clear HCINT */
  73285. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73286. +
  73287. + /* Clear HAINT */
  73288. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73289. +
  73290. + /* Clear GINTSTS */
  73291. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73292. +
  73293. + /* Read GINTSTS */
  73294. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73295. +
  73296. + /*
  73297. + * Receive Control In packet
  73298. + */
  73299. +
  73300. + /* Make sure channel is disabled */
  73301. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73302. + if (hcchar.b.chen) {
  73303. + hcchar.b.chdis = 1;
  73304. + hcchar.b.chen = 1;
  73305. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73306. + //sleep(1);
  73307. + dwc_mdelay(1000);
  73308. +
  73309. + /* Read GINTSTS */
  73310. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73311. +
  73312. + /* Read HAINT */
  73313. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73314. +
  73315. + /* Read HCINT */
  73316. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73317. +
  73318. + /* Read HCCHAR */
  73319. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73320. +
  73321. + /* Clear HCINT */
  73322. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73323. +
  73324. + /* Clear HAINT */
  73325. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73326. +
  73327. + /* Clear GINTSTS */
  73328. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73329. +
  73330. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73331. + }
  73332. +
  73333. + /* Set HCTSIZ */
  73334. + hctsiz.d32 = 0;
  73335. + hctsiz.b.xfersize = 8;
  73336. + hctsiz.b.pktcnt = 1;
  73337. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  73338. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  73339. +
  73340. + /* Set HCCHAR */
  73341. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73342. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  73343. + hcchar.b.epdir = 1;
  73344. + hcchar.b.epnum = 0;
  73345. + hcchar.b.mps = 8;
  73346. + hcchar.b.chen = 1;
  73347. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73348. +
  73349. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73350. +
  73351. + /* Wait for receive status queue interrupt */
  73352. + do {
  73353. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73354. + } while (gintsts.b.rxstsqlvl == 0);
  73355. +
  73356. + /* Read RXSTS */
  73357. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  73358. +
  73359. + /* Clear RXSTSQLVL in GINTSTS */
  73360. + gintsts.d32 = 0;
  73361. + gintsts.b.rxstsqlvl = 1;
  73362. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73363. +
  73364. + switch (grxsts.b.pktsts) {
  73365. + case DWC_GRXSTS_PKTSTS_IN:
  73366. + /* Read the data into the host buffer */
  73367. + if (grxsts.b.bcnt > 0) {
  73368. + int i;
  73369. + int word_count = (grxsts.b.bcnt + 3) / 4;
  73370. +
  73371. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  73372. +
  73373. + for (i = 0; i < word_count; i++) {
  73374. + (void)DWC_READ_REG32(data_fifo++);
  73375. + }
  73376. + }
  73377. + break;
  73378. +
  73379. + default:
  73380. + break;
  73381. + }
  73382. +
  73383. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73384. +
  73385. + /* Wait for receive status queue interrupt */
  73386. + do {
  73387. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73388. + } while (gintsts.b.rxstsqlvl == 0);
  73389. +
  73390. + /* Read RXSTS */
  73391. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  73392. +
  73393. + /* Clear RXSTSQLVL in GINTSTS */
  73394. + gintsts.d32 = 0;
  73395. + gintsts.b.rxstsqlvl = 1;
  73396. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73397. +
  73398. + switch (grxsts.b.pktsts) {
  73399. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  73400. + break;
  73401. +
  73402. + default:
  73403. + break;
  73404. + }
  73405. +
  73406. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73407. +
  73408. + /* Wait for host channel interrupt */
  73409. + do {
  73410. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73411. + } while (gintsts.b.hcintr == 0);
  73412. +
  73413. + /* Read HAINT */
  73414. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73415. +
  73416. + /* Read HCINT */
  73417. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73418. +
  73419. + /* Read HCCHAR */
  73420. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73421. +
  73422. + /* Clear HCINT */
  73423. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73424. +
  73425. + /* Clear HAINT */
  73426. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73427. +
  73428. + /* Clear GINTSTS */
  73429. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73430. +
  73431. + /* Read GINTSTS */
  73432. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73433. +
  73434. +// usleep(100000);
  73435. +// mdelay(100);
  73436. + dwc_mdelay(1);
  73437. +
  73438. + /*
  73439. + * Send handshake packet
  73440. + */
  73441. +
  73442. + /* Read HAINT */
  73443. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73444. +
  73445. + /* Read HCINT */
  73446. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73447. +
  73448. + /* Read HCCHAR */
  73449. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73450. +
  73451. + /* Clear HCINT */
  73452. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73453. +
  73454. + /* Clear HAINT */
  73455. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73456. +
  73457. + /* Clear GINTSTS */
  73458. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73459. +
  73460. + /* Read GINTSTS */
  73461. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73462. +
  73463. + /* Make sure channel is disabled */
  73464. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73465. + if (hcchar.b.chen) {
  73466. + hcchar.b.chdis = 1;
  73467. + hcchar.b.chen = 1;
  73468. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73469. + //sleep(1);
  73470. + dwc_mdelay(1000);
  73471. +
  73472. + /* Read GINTSTS */
  73473. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73474. +
  73475. + /* Read HAINT */
  73476. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73477. +
  73478. + /* Read HCINT */
  73479. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73480. +
  73481. + /* Read HCCHAR */
  73482. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73483. +
  73484. + /* Clear HCINT */
  73485. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73486. +
  73487. + /* Clear HAINT */
  73488. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73489. +
  73490. + /* Clear GINTSTS */
  73491. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73492. +
  73493. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73494. + }
  73495. +
  73496. + /* Set HCTSIZ */
  73497. + hctsiz.d32 = 0;
  73498. + hctsiz.b.xfersize = 0;
  73499. + hctsiz.b.pktcnt = 1;
  73500. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  73501. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  73502. +
  73503. + /* Set HCCHAR */
  73504. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73505. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  73506. + hcchar.b.epdir = 0;
  73507. + hcchar.b.epnum = 0;
  73508. + hcchar.b.mps = 8;
  73509. + hcchar.b.chen = 1;
  73510. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73511. +
  73512. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73513. +
  73514. + /* Wait for host channel interrupt */
  73515. + do {
  73516. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73517. + } while (gintsts.b.hcintr == 0);
  73518. +
  73519. + /* Disable HCINTs */
  73520. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  73521. +
  73522. + /* Disable HAINTs */
  73523. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  73524. +
  73525. + /* Read HAINT */
  73526. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73527. +
  73528. + /* Read HCINT */
  73529. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73530. +
  73531. + /* Read HCCHAR */
  73532. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73533. +
  73534. + /* Clear HCINT */
  73535. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73536. +
  73537. + /* Clear HAINT */
  73538. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73539. +
  73540. + /* Clear GINTSTS */
  73541. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73542. +
  73543. + /* Read GINTSTS */
  73544. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73545. +}
  73546. +#endif
  73547. +
  73548. +/** Handles hub class-specific requests. */
  73549. +int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  73550. + uint16_t typeReq,
  73551. + uint16_t wValue,
  73552. + uint16_t wIndex, uint8_t * buf, uint16_t wLength)
  73553. +{
  73554. + int retval = 0;
  73555. +
  73556. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  73557. + usb_hub_descriptor_t *hub_desc;
  73558. + hprt0_data_t hprt0 = {.d32 = 0 };
  73559. +
  73560. + uint32_t port_status;
  73561. +
  73562. + switch (typeReq) {
  73563. + case UCR_CLEAR_HUB_FEATURE:
  73564. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73565. + "ClearHubFeature 0x%x\n", wValue);
  73566. + switch (wValue) {
  73567. + case UHF_C_HUB_LOCAL_POWER:
  73568. + case UHF_C_HUB_OVER_CURRENT:
  73569. + /* Nothing required here */
  73570. + break;
  73571. + default:
  73572. + retval = -DWC_E_INVALID;
  73573. + DWC_ERROR("DWC OTG HCD - "
  73574. + "ClearHubFeature request %xh unknown\n",
  73575. + wValue);
  73576. + }
  73577. + break;
  73578. + case UCR_CLEAR_PORT_FEATURE:
  73579. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73580. + if (wValue != UHF_PORT_L1)
  73581. +#endif
  73582. + if (!wIndex || wIndex > 1)
  73583. + goto error;
  73584. +
  73585. + switch (wValue) {
  73586. + case UHF_PORT_ENABLE:
  73587. + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
  73588. + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
  73589. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73590. + hprt0.b.prtena = 1;
  73591. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73592. + break;
  73593. + case UHF_PORT_SUSPEND:
  73594. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73595. + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
  73596. +
  73597. + if (core_if->power_down == 2) {
  73598. + dwc_otg_host_hibernation_restore(core_if, 0, 0);
  73599. + } else {
  73600. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  73601. + dwc_mdelay(5);
  73602. +
  73603. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73604. + hprt0.b.prtres = 1;
  73605. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73606. + hprt0.b.prtsusp = 0;
  73607. + /* Clear Resume bit */
  73608. + dwc_mdelay(100);
  73609. + hprt0.b.prtres = 0;
  73610. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73611. + }
  73612. + break;
  73613. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73614. + case UHF_PORT_L1:
  73615. + {
  73616. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  73617. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  73618. +
  73619. + lpmcfg.d32 =
  73620. + DWC_READ_REG32(&core_if->
  73621. + core_global_regs->glpmcfg);
  73622. + lpmcfg.b.en_utmi_sleep = 0;
  73623. + lpmcfg.b.hird_thres &= (~(1 << 4));
  73624. + lpmcfg.b.prt_sleep_sts = 1;
  73625. + DWC_WRITE_REG32(&core_if->
  73626. + core_global_regs->glpmcfg,
  73627. + lpmcfg.d32);
  73628. +
  73629. + /* Clear Enbl_L1Gating bit. */
  73630. + pcgcctl.b.enbl_sleep_gating = 1;
  73631. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,
  73632. + 0);
  73633. +
  73634. + dwc_mdelay(5);
  73635. +
  73636. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73637. + hprt0.b.prtres = 1;
  73638. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  73639. + hprt0.d32);
  73640. + /* This bit will be cleared in wakeup interrupt handle */
  73641. + break;
  73642. + }
  73643. +#endif
  73644. + case UHF_PORT_POWER:
  73645. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73646. + "ClearPortFeature USB_PORT_FEAT_POWER\n");
  73647. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73648. + hprt0.b.prtpwr = 0;
  73649. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73650. + break;
  73651. + case UHF_PORT_INDICATOR:
  73652. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73653. + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
  73654. + /* Port inidicator not supported */
  73655. + break;
  73656. + case UHF_C_PORT_CONNECTION:
  73657. + /* Clears drivers internal connect status change
  73658. + * flag */
  73659. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73660. + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
  73661. + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
  73662. + break;
  73663. + case UHF_C_PORT_RESET:
  73664. + /* Clears the driver's internal Port Reset Change
  73665. + * flag */
  73666. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73667. + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
  73668. + dwc_otg_hcd->flags.b.port_reset_change = 0;
  73669. + break;
  73670. + case UHF_C_PORT_ENABLE:
  73671. + /* Clears the driver's internal Port
  73672. + * Enable/Disable Change flag */
  73673. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73674. + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
  73675. + dwc_otg_hcd->flags.b.port_enable_change = 0;
  73676. + break;
  73677. + case UHF_C_PORT_SUSPEND:
  73678. + /* Clears the driver's internal Port Suspend
  73679. + * Change flag, which is set when resume signaling on
  73680. + * the host port is complete */
  73681. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73682. + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
  73683. + dwc_otg_hcd->flags.b.port_suspend_change = 0;
  73684. + break;
  73685. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73686. + case UHF_C_PORT_L1:
  73687. + dwc_otg_hcd->flags.b.port_l1_change = 0;
  73688. + break;
  73689. +#endif
  73690. + case UHF_C_PORT_OVER_CURRENT:
  73691. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73692. + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
  73693. + dwc_otg_hcd->flags.b.port_over_current_change = 0;
  73694. + break;
  73695. + default:
  73696. + retval = -DWC_E_INVALID;
  73697. + DWC_ERROR("DWC OTG HCD - "
  73698. + "ClearPortFeature request %xh "
  73699. + "unknown or unsupported\n", wValue);
  73700. + }
  73701. + break;
  73702. + case UCR_GET_HUB_DESCRIPTOR:
  73703. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73704. + "GetHubDescriptor\n");
  73705. + hub_desc = (usb_hub_descriptor_t *) buf;
  73706. + hub_desc->bDescLength = 9;
  73707. + hub_desc->bDescriptorType = 0x29;
  73708. + hub_desc->bNbrPorts = 1;
  73709. + USETW(hub_desc->wHubCharacteristics, 0x08);
  73710. + hub_desc->bPwrOn2PwrGood = 1;
  73711. + hub_desc->bHubContrCurrent = 0;
  73712. + hub_desc->DeviceRemovable[0] = 0;
  73713. + hub_desc->DeviceRemovable[1] = 0xff;
  73714. + break;
  73715. + case UCR_GET_HUB_STATUS:
  73716. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73717. + "GetHubStatus\n");
  73718. + DWC_MEMSET(buf, 0, 4);
  73719. + break;
  73720. + case UCR_GET_PORT_STATUS:
  73721. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73722. + "GetPortStatus wIndex = 0x%04x FLAGS=0x%08x\n",
  73723. + wIndex, dwc_otg_hcd->flags.d32);
  73724. + if (!wIndex || wIndex > 1)
  73725. + goto error;
  73726. +
  73727. + port_status = 0;
  73728. +
  73729. + if (dwc_otg_hcd->flags.b.port_connect_status_change)
  73730. + port_status |= (1 << UHF_C_PORT_CONNECTION);
  73731. +
  73732. + if (dwc_otg_hcd->flags.b.port_enable_change)
  73733. + port_status |= (1 << UHF_C_PORT_ENABLE);
  73734. +
  73735. + if (dwc_otg_hcd->flags.b.port_suspend_change)
  73736. + port_status |= (1 << UHF_C_PORT_SUSPEND);
  73737. +
  73738. + if (dwc_otg_hcd->flags.b.port_l1_change)
  73739. + port_status |= (1 << UHF_C_PORT_L1);
  73740. +
  73741. + if (dwc_otg_hcd->flags.b.port_reset_change) {
  73742. + port_status |= (1 << UHF_C_PORT_RESET);
  73743. + }
  73744. +
  73745. + if (dwc_otg_hcd->flags.b.port_over_current_change) {
  73746. + DWC_WARN("Overcurrent change detected\n");
  73747. + port_status |= (1 << UHF_C_PORT_OVER_CURRENT);
  73748. + }
  73749. +
  73750. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  73751. + /*
  73752. + * The port is disconnected, which means the core is
  73753. + * either in device mode or it soon will be. Just
  73754. + * return 0's for the remainder of the port status
  73755. + * since the port register can't be read if the core
  73756. + * is in device mode.
  73757. + */
  73758. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  73759. + break;
  73760. + }
  73761. +
  73762. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  73763. + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
  73764. +
  73765. + if (hprt0.b.prtconnsts)
  73766. + port_status |= (1 << UHF_PORT_CONNECTION);
  73767. +
  73768. + if (hprt0.b.prtena)
  73769. + port_status |= (1 << UHF_PORT_ENABLE);
  73770. +
  73771. + if (hprt0.b.prtsusp)
  73772. + port_status |= (1 << UHF_PORT_SUSPEND);
  73773. +
  73774. + if (hprt0.b.prtovrcurract)
  73775. + port_status |= (1 << UHF_PORT_OVER_CURRENT);
  73776. +
  73777. + if (hprt0.b.prtrst)
  73778. + port_status |= (1 << UHF_PORT_RESET);
  73779. +
  73780. + if (hprt0.b.prtpwr)
  73781. + port_status |= (1 << UHF_PORT_POWER);
  73782. +
  73783. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  73784. + port_status |= (1 << UHF_PORT_HIGH_SPEED);
  73785. + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
  73786. + port_status |= (1 << UHF_PORT_LOW_SPEED);
  73787. +
  73788. + if (hprt0.b.prttstctl)
  73789. + port_status |= (1 << UHF_PORT_TEST);
  73790. + if (dwc_otg_get_lpm_portsleepstatus(dwc_otg_hcd->core_if)) {
  73791. + port_status |= (1 << UHF_PORT_L1);
  73792. + }
  73793. + /*
  73794. + For Synopsys HW emulation of Power down wkup_control asserts the
  73795. + hreset_n and prst_n on suspned. This causes the HPRT0 to be zero.
  73796. + We intentionally tell the software that port is in L2Suspend state.
  73797. + Only for STE.
  73798. + */
  73799. + if ((core_if->power_down == 2)
  73800. + && (core_if->hibernation_suspend == 1)) {
  73801. + port_status |= (1 << UHF_PORT_SUSPEND);
  73802. + }
  73803. + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
  73804. +
  73805. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  73806. +
  73807. + break;
  73808. + case UCR_SET_HUB_FEATURE:
  73809. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73810. + "SetHubFeature\n");
  73811. + /* No HUB features supported */
  73812. + break;
  73813. + case UCR_SET_PORT_FEATURE:
  73814. + if (wValue != UHF_PORT_TEST && (!wIndex || wIndex > 1))
  73815. + goto error;
  73816. +
  73817. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  73818. + /*
  73819. + * The port is disconnected, which means the core is
  73820. + * either in device mode or it soon will be. Just
  73821. + * return without doing anything since the port
  73822. + * register can't be written if the core is in device
  73823. + * mode.
  73824. + */
  73825. + break;
  73826. + }
  73827. +
  73828. + switch (wValue) {
  73829. + case UHF_PORT_SUSPEND:
  73830. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73831. + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
  73832. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) != wIndex) {
  73833. + goto error;
  73834. + }
  73835. + if (core_if->power_down == 2) {
  73836. + int timeout = 300;
  73837. + dwc_irqflags_t flags;
  73838. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  73839. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  73840. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  73841. +#ifdef DWC_DEV_SRPCAP
  73842. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  73843. +#endif
  73844. + DWC_PRINTF("Preparing for complete power-off\n");
  73845. +
  73846. + /* Save registers before hibernation */
  73847. + dwc_otg_save_global_regs(core_if);
  73848. + dwc_otg_save_host_regs(core_if);
  73849. +
  73850. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73851. + hprt0.b.prtsusp = 1;
  73852. + hprt0.b.prtena = 0;
  73853. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73854. + /* Spin hprt0.b.prtsusp to became 1 */
  73855. + do {
  73856. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73857. + if (hprt0.b.prtsusp) {
  73858. + break;
  73859. + }
  73860. + dwc_mdelay(1);
  73861. + } while (--timeout);
  73862. + if (!timeout) {
  73863. + DWC_WARN("Suspend wasn't genereted\n");
  73864. + }
  73865. + dwc_udelay(10);
  73866. +
  73867. + /*
  73868. + * We need to disable interrupts to prevent servicing of any IRQ
  73869. + * during going to hibernation
  73870. + */
  73871. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  73872. + core_if->lx_state = DWC_OTG_L2;
  73873. +#ifdef DWC_DEV_SRPCAP
  73874. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73875. + hprt0.b.prtpwr = 0;
  73876. + hprt0.b.prtena = 0;
  73877. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  73878. + hprt0.d32);
  73879. +#endif
  73880. + gusbcfg.d32 =
  73881. + DWC_READ_REG32(&core_if->core_global_regs->
  73882. + gusbcfg);
  73883. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  73884. + /* ULPI interface */
  73885. + /* Suspend the Phy Clock */
  73886. + pcgcctl.d32 = 0;
  73887. + pcgcctl.b.stoppclk = 1;
  73888. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  73889. + pcgcctl.d32);
  73890. + dwc_udelay(10);
  73891. + gpwrdn.b.pmuactv = 1;
  73892. + DWC_MODIFY_REG32(&core_if->
  73893. + core_global_regs->
  73894. + gpwrdn, 0, gpwrdn.d32);
  73895. + } else {
  73896. + /* UTMI+ Interface */
  73897. + gpwrdn.b.pmuactv = 1;
  73898. + DWC_MODIFY_REG32(&core_if->
  73899. + core_global_regs->
  73900. + gpwrdn, 0, gpwrdn.d32);
  73901. + dwc_udelay(10);
  73902. + pcgcctl.b.stoppclk = 1;
  73903. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  73904. + dwc_udelay(10);
  73905. + }
  73906. +#ifdef DWC_DEV_SRPCAP
  73907. + gpwrdn.d32 = 0;
  73908. + gpwrdn.b.dis_vbus = 1;
  73909. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73910. + gpwrdn, 0, gpwrdn.d32);
  73911. +#endif
  73912. + gpwrdn.d32 = 0;
  73913. + gpwrdn.b.pmuintsel = 1;
  73914. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73915. + gpwrdn, 0, gpwrdn.d32);
  73916. + dwc_udelay(10);
  73917. +
  73918. + gpwrdn.d32 = 0;
  73919. +#ifdef DWC_DEV_SRPCAP
  73920. + gpwrdn.b.srp_det_msk = 1;
  73921. +#endif
  73922. + gpwrdn.b.disconn_det_msk = 1;
  73923. + gpwrdn.b.lnstchng_msk = 1;
  73924. + gpwrdn.b.sts_chngint_msk = 1;
  73925. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73926. + gpwrdn, 0, gpwrdn.d32);
  73927. + dwc_udelay(10);
  73928. +
  73929. + /* Enable Power Down Clamp and all interrupts in GPWRDN */
  73930. + gpwrdn.d32 = 0;
  73931. + gpwrdn.b.pwrdnclmp = 1;
  73932. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73933. + gpwrdn, 0, gpwrdn.d32);
  73934. + dwc_udelay(10);
  73935. +
  73936. + /* Switch off VDD */
  73937. + gpwrdn.d32 = 0;
  73938. + gpwrdn.b.pwrdnswtch = 1;
  73939. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73940. + gpwrdn, 0, gpwrdn.d32);
  73941. +
  73942. +#ifdef DWC_DEV_SRPCAP
  73943. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)
  73944. + {
  73945. + core_if->pwron_timer_started = 1;
  73946. + DWC_TIMER_SCHEDULE(core_if->pwron_timer, 6000 /* 6 secs */ );
  73947. + }
  73948. +#endif
  73949. + /* Save gpwrdn register for further usage if stschng interrupt */
  73950. + core_if->gr_backup->gpwrdn_local =
  73951. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  73952. +
  73953. + /* Set flag to indicate that we are in hibernation */
  73954. + core_if->hibernation_suspend = 1;
  73955. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock,flags);
  73956. +
  73957. + DWC_PRINTF("Host hibernation completed\n");
  73958. + // Exit from case statement
  73959. + break;
  73960. +
  73961. + }
  73962. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) == wIndex &&
  73963. + dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  73964. + gotgctl_data_t gotgctl = {.d32 = 0 };
  73965. + gotgctl.b.hstsethnpen = 1;
  73966. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73967. + gotgctl, 0, gotgctl.d32);
  73968. + core_if->op_state = A_SUSPEND;
  73969. + }
  73970. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73971. + hprt0.b.prtsusp = 1;
  73972. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73973. + {
  73974. + dwc_irqflags_t flags;
  73975. + /* Update lx_state */
  73976. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  73977. + core_if->lx_state = DWC_OTG_L2;
  73978. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  73979. + }
  73980. + /* Suspend the Phy Clock */
  73981. + {
  73982. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  73983. + pcgcctl.b.stoppclk = 1;
  73984. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  73985. + pcgcctl.d32);
  73986. + dwc_udelay(10);
  73987. + }
  73988. +
  73989. + /* For HNP the bus must be suspended for at least 200ms. */
  73990. + if (dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  73991. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  73992. + pcgcctl.b.stoppclk = 1;
  73993. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  73994. + dwc_mdelay(200);
  73995. + }
  73996. +
  73997. + /** @todo - check how sw can wait for 1 sec to check asesvld??? */
  73998. +#if 0 //vahrama !!!!!!!!!!!!!!!!!!
  73999. + if (core_if->adp_enable) {
  74000. + gotgctl_data_t gotgctl = {.d32 = 0 };
  74001. + gpwrdn_data_t gpwrdn;
  74002. +
  74003. + while (gotgctl.b.asesvld == 1) {
  74004. + gotgctl.d32 =
  74005. + DWC_READ_REG32(&core_if->
  74006. + core_global_regs->
  74007. + gotgctl);
  74008. + dwc_mdelay(100);
  74009. + }
  74010. +
  74011. + /* Enable Power Down Logic */
  74012. + gpwrdn.d32 = 0;
  74013. + gpwrdn.b.pmuactv = 1;
  74014. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  74015. + gpwrdn, 0, gpwrdn.d32);
  74016. +
  74017. + /* Unmask SRP detected interrupt from Power Down Logic */
  74018. + gpwrdn.d32 = 0;
  74019. + gpwrdn.b.srp_det_msk = 1;
  74020. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  74021. + gpwrdn, 0, gpwrdn.d32);
  74022. +
  74023. + dwc_otg_adp_probe_start(core_if);
  74024. + }
  74025. +#endif
  74026. + break;
  74027. + case UHF_PORT_POWER:
  74028. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74029. + "SetPortFeature - USB_PORT_FEAT_POWER\n");
  74030. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74031. + hprt0.b.prtpwr = 1;
  74032. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74033. + break;
  74034. + case UHF_PORT_RESET:
  74035. + if ((core_if->power_down == 2)
  74036. + && (core_if->hibernation_suspend == 1)) {
  74037. + /* If we are going to exit from Hibernated
  74038. + * state via USB RESET.
  74039. + */
  74040. + dwc_otg_host_hibernation_restore(core_if, 0, 1);
  74041. + } else {
  74042. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74043. +
  74044. + DWC_DEBUGPL(DBG_HCD,
  74045. + "DWC OTG HCD HUB CONTROL - "
  74046. + "SetPortFeature - USB_PORT_FEAT_RESET\n");
  74047. + {
  74048. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  74049. + pcgcctl.b.enbl_sleep_gating = 1;
  74050. + pcgcctl.b.stoppclk = 1;
  74051. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  74052. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  74053. + }
  74054. +#ifdef CONFIG_USB_DWC_OTG_LPM
  74055. + {
  74056. + glpmcfg_data_t lpmcfg;
  74057. + lpmcfg.d32 =
  74058. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  74059. + if (lpmcfg.b.prt_sleep_sts) {
  74060. + lpmcfg.b.en_utmi_sleep = 0;
  74061. + lpmcfg.b.hird_thres &= (~(1 << 4));
  74062. + DWC_WRITE_REG32
  74063. + (&core_if->core_global_regs->glpmcfg,
  74064. + lpmcfg.d32);
  74065. + dwc_mdelay(1);
  74066. + }
  74067. + }
  74068. +#endif
  74069. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74070. + /* Clear suspend bit if resetting from suspended state. */
  74071. + hprt0.b.prtsusp = 0;
  74072. + /* When B-Host the Port reset bit is set in
  74073. + * the Start HCD Callback function, so that
  74074. + * the reset is started within 1ms of the HNP
  74075. + * success interrupt. */
  74076. + if (!dwc_otg_hcd_is_b_host(dwc_otg_hcd)) {
  74077. + hprt0.b.prtpwr = 1;
  74078. + hprt0.b.prtrst = 1;
  74079. + DWC_PRINTF("Indeed it is in host mode hprt0 = %08x\n",hprt0.d32);
  74080. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  74081. + hprt0.d32);
  74082. + }
  74083. + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
  74084. + dwc_mdelay(60);
  74085. + hprt0.b.prtrst = 0;
  74086. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74087. + core_if->lx_state = DWC_OTG_L0; /* Now back to the on state */
  74088. + }
  74089. + break;
  74090. +#ifdef DWC_HS_ELECT_TST
  74091. + case UHF_PORT_TEST:
  74092. + {
  74093. + uint32_t t;
  74094. + gintmsk_data_t gintmsk;
  74095. +
  74096. + t = (wIndex >> 8); /* MSB wIndex USB */
  74097. + DWC_DEBUGPL(DBG_HCD,
  74098. + "DWC OTG HCD HUB CONTROL - "
  74099. + "SetPortFeature - USB_PORT_FEAT_TEST %d\n",
  74100. + t);
  74101. + DWC_WARN("USB_PORT_FEAT_TEST %d\n", t);
  74102. + if (t < 6) {
  74103. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74104. + hprt0.b.prttstctl = t;
  74105. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  74106. + hprt0.d32);
  74107. + } else {
  74108. + /* Setup global vars with reg addresses (quick and
  74109. + * dirty hack, should be cleaned up)
  74110. + */
  74111. + global_regs = core_if->core_global_regs;
  74112. + hc_global_regs =
  74113. + core_if->host_if->host_global_regs;
  74114. + hc_regs =
  74115. + (dwc_otg_hc_regs_t *) ((char *)
  74116. + global_regs +
  74117. + 0x500);
  74118. + data_fifo =
  74119. + (uint32_t *) ((char *)global_regs +
  74120. + 0x1000);
  74121. +
  74122. + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
  74123. + /* Save current interrupt mask */
  74124. + gintmsk.d32 =
  74125. + DWC_READ_REG32
  74126. + (&global_regs->gintmsk);
  74127. +
  74128. + /* Disable all interrupts while we muck with
  74129. + * the hardware directly
  74130. + */
  74131. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  74132. +
  74133. + /* 15 second delay per the test spec */
  74134. + dwc_mdelay(15000);
  74135. +
  74136. + /* Drive suspend on the root port */
  74137. + hprt0.d32 =
  74138. + dwc_otg_read_hprt0(core_if);
  74139. + hprt0.b.prtsusp = 1;
  74140. + hprt0.b.prtres = 0;
  74141. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74142. +
  74143. + /* 15 second delay per the test spec */
  74144. + dwc_mdelay(15000);
  74145. +
  74146. + /* Drive resume on the root port */
  74147. + hprt0.d32 =
  74148. + dwc_otg_read_hprt0(core_if);
  74149. + hprt0.b.prtsusp = 0;
  74150. + hprt0.b.prtres = 1;
  74151. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74152. + dwc_mdelay(100);
  74153. +
  74154. + /* Clear the resume bit */
  74155. + hprt0.b.prtres = 0;
  74156. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74157. +
  74158. + /* Restore interrupts */
  74159. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  74160. + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  74161. + /* Save current interrupt mask */
  74162. + gintmsk.d32 =
  74163. + DWC_READ_REG32
  74164. + (&global_regs->gintmsk);
  74165. +
  74166. + /* Disable all interrupts while we muck with
  74167. + * the hardware directly
  74168. + */
  74169. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  74170. +
  74171. + /* 15 second delay per the test spec */
  74172. + dwc_mdelay(15000);
  74173. +
  74174. + /* Send the Setup packet */
  74175. + do_setup();
  74176. +
  74177. + /* 15 second delay so nothing else happens for awhile */
  74178. + dwc_mdelay(15000);
  74179. +
  74180. + /* Restore interrupts */
  74181. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  74182. + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  74183. + /* Save current interrupt mask */
  74184. + gintmsk.d32 =
  74185. + DWC_READ_REG32
  74186. + (&global_regs->gintmsk);
  74187. +
  74188. + /* Disable all interrupts while we muck with
  74189. + * the hardware directly
  74190. + */
  74191. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  74192. +
  74193. + /* Send the Setup packet */
  74194. + do_setup();
  74195. +
  74196. + /* 15 second delay so nothing else happens for awhile */
  74197. + dwc_mdelay(15000);
  74198. +
  74199. + /* Send the In and Ack packets */
  74200. + do_in_ack();
  74201. +
  74202. + /* 15 second delay so nothing else happens for awhile */
  74203. + dwc_mdelay(15000);
  74204. +
  74205. + /* Restore interrupts */
  74206. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  74207. + }
  74208. + }
  74209. + break;
  74210. + }
  74211. +#endif /* DWC_HS_ELECT_TST */
  74212. +
  74213. + case UHF_PORT_INDICATOR:
  74214. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74215. + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
  74216. + /* Not supported */
  74217. + break;
  74218. + default:
  74219. + retval = -DWC_E_INVALID;
  74220. + DWC_ERROR("DWC OTG HCD - "
  74221. + "SetPortFeature request %xh "
  74222. + "unknown or unsupported\n", wValue);
  74223. + break;
  74224. + }
  74225. + break;
  74226. +#ifdef CONFIG_USB_DWC_OTG_LPM
  74227. + case UCR_SET_AND_TEST_PORT_FEATURE:
  74228. + if (wValue != UHF_PORT_L1) {
  74229. + goto error;
  74230. + }
  74231. + {
  74232. + int portnum, hird, devaddr, remwake;
  74233. + glpmcfg_data_t lpmcfg;
  74234. + uint32_t time_usecs;
  74235. + gintsts_data_t gintsts;
  74236. + gintmsk_data_t gintmsk;
  74237. +
  74238. + if (!dwc_otg_get_param_lpm_enable(core_if)) {
  74239. + goto error;
  74240. + }
  74241. + if (wValue != UHF_PORT_L1 || wLength != 1) {
  74242. + goto error;
  74243. + }
  74244. + /* Check if the port currently is in SLEEP state */
  74245. + lpmcfg.d32 =
  74246. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  74247. + if (lpmcfg.b.prt_sleep_sts) {
  74248. + DWC_INFO("Port is already in sleep mode\n");
  74249. + buf[0] = 0; /* Return success */
  74250. + break;
  74251. + }
  74252. +
  74253. + portnum = wIndex & 0xf;
  74254. + hird = (wIndex >> 4) & 0xf;
  74255. + devaddr = (wIndex >> 8) & 0x7f;
  74256. + remwake = (wIndex >> 15);
  74257. +
  74258. + if (portnum != 1) {
  74259. + retval = -DWC_E_INVALID;
  74260. + DWC_WARN
  74261. + ("Wrong port number(%d) in SetandTestPortFeature request\n",
  74262. + portnum);
  74263. + break;
  74264. + }
  74265. +
  74266. + DWC_PRINTF
  74267. + ("SetandTestPortFeature request: portnum = %d, hird = %d, devaddr = %d, rewake = %d\n",
  74268. + portnum, hird, devaddr, remwake);
  74269. + /* Disable LPM interrupt */
  74270. + gintmsk.d32 = 0;
  74271. + gintmsk.b.lpmtranrcvd = 1;
  74272. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  74273. + gintmsk.d32, 0);
  74274. +
  74275. + if (dwc_otg_hcd_send_lpm
  74276. + (dwc_otg_hcd, devaddr, hird, remwake)) {
  74277. + retval = -DWC_E_INVALID;
  74278. + break;
  74279. + }
  74280. +
  74281. + time_usecs = 10 * (lpmcfg.b.retry_count + 1);
  74282. + /* We will consider timeout if time_usecs microseconds pass,
  74283. + * and we don't receive LPM transaction status.
  74284. + * After receiving non-error responce(ACK/NYET/STALL) from device,
  74285. + * core will set lpmtranrcvd bit.
  74286. + */
  74287. + do {
  74288. + gintsts.d32 =
  74289. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  74290. + if (gintsts.b.lpmtranrcvd) {
  74291. + break;
  74292. + }
  74293. + dwc_udelay(1);
  74294. + } while (--time_usecs);
  74295. + /* lpm_int bit will be cleared in LPM interrupt handler */
  74296. +
  74297. + /* Now fill status
  74298. + * 0x00 - Success
  74299. + * 0x10 - NYET
  74300. + * 0x11 - Timeout
  74301. + */
  74302. + if (!gintsts.b.lpmtranrcvd) {
  74303. + buf[0] = 0x3; /* Completion code is Timeout */
  74304. + dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd);
  74305. + } else {
  74306. + lpmcfg.d32 =
  74307. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  74308. + if (lpmcfg.b.lpm_resp == 0x3) {
  74309. + /* ACK responce from the device */
  74310. + buf[0] = 0x00; /* Success */
  74311. + } else if (lpmcfg.b.lpm_resp == 0x2) {
  74312. + /* NYET responce from the device */
  74313. + buf[0] = 0x2;
  74314. + } else {
  74315. + /* Otherwise responce with Timeout */
  74316. + buf[0] = 0x3;
  74317. + }
  74318. + }
  74319. + DWC_PRINTF("Device responce to LPM trans is %x\n",
  74320. + lpmcfg.b.lpm_resp);
  74321. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0,
  74322. + gintmsk.d32);
  74323. +
  74324. + break;
  74325. + }
  74326. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  74327. + default:
  74328. +error:
  74329. + retval = -DWC_E_INVALID;
  74330. + DWC_WARN("DWC OTG HCD - "
  74331. + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
  74332. + typeReq, wIndex, wValue);
  74333. + break;
  74334. + }
  74335. +
  74336. + return retval;
  74337. +}
  74338. +
  74339. +#ifdef CONFIG_USB_DWC_OTG_LPM
  74340. +/** Returns index of host channel to perform LPM transaction. */
  74341. +int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd, uint8_t devaddr)
  74342. +{
  74343. + dwc_otg_core_if_t *core_if = hcd->core_if;
  74344. + dwc_hc_t *hc;
  74345. + hcchar_data_t hcchar;
  74346. + gintmsk_data_t gintmsk = {.d32 = 0 };
  74347. +
  74348. + if (DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  74349. + DWC_PRINTF("No free channel to select for LPM transaction\n");
  74350. + return -1;
  74351. + }
  74352. +
  74353. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  74354. +
  74355. + /* Mask host channel interrupts. */
  74356. + gintmsk.b.hcintr = 1;
  74357. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  74358. +
  74359. + /* Fill fields that core needs for LPM transaction */
  74360. + hcchar.b.devaddr = devaddr;
  74361. + hcchar.b.epnum = 0;
  74362. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  74363. + hcchar.b.mps = 64;
  74364. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  74365. + hcchar.b.epdir = 0; /* OUT */
  74366. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[hc->hc_num]->hcchar,
  74367. + hcchar.d32);
  74368. +
  74369. + /* Remove the host channel from the free list. */
  74370. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  74371. +
  74372. + DWC_PRINTF("hcnum = %d devaddr = %d\n", hc->hc_num, devaddr);
  74373. +
  74374. + return hc->hc_num;
  74375. +}
  74376. +
  74377. +/** Release hc after performing LPM transaction */
  74378. +void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd)
  74379. +{
  74380. + dwc_hc_t *hc;
  74381. + glpmcfg_data_t lpmcfg;
  74382. + uint8_t hc_num;
  74383. +
  74384. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  74385. + hc_num = lpmcfg.b.lpm_chan_index;
  74386. +
  74387. + hc = hcd->hc_ptr_array[hc_num];
  74388. +
  74389. + DWC_PRINTF("Freeing channel %d after LPM\n", hc_num);
  74390. + /* Return host channel to free list */
  74391. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  74392. +}
  74393. +
  74394. +int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr, uint8_t hird,
  74395. + uint8_t bRemoteWake)
  74396. +{
  74397. + glpmcfg_data_t lpmcfg;
  74398. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  74399. + int channel;
  74400. +
  74401. + channel = dwc_otg_hcd_get_hc_for_lpm_tran(hcd, devaddr);
  74402. + if (channel < 0) {
  74403. + return channel;
  74404. + }
  74405. +
  74406. + pcgcctl.b.enbl_sleep_gating = 1;
  74407. + DWC_MODIFY_REG32(hcd->core_if->pcgcctl, 0, pcgcctl.d32);
  74408. +
  74409. + /* Read LPM config register */
  74410. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  74411. +
  74412. + /* Program LPM transaction fields */
  74413. + lpmcfg.b.rem_wkup_en = bRemoteWake;
  74414. + lpmcfg.b.hird = hird;
  74415. + lpmcfg.b.hird_thres = 0x1c;
  74416. + lpmcfg.b.lpm_chan_index = channel;
  74417. + lpmcfg.b.en_utmi_sleep = 1;
  74418. + /* Program LPM config register */
  74419. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  74420. +
  74421. + /* Send LPM transaction */
  74422. + lpmcfg.b.send_lpm = 1;
  74423. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  74424. +
  74425. + return 0;
  74426. +}
  74427. +
  74428. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  74429. +
  74430. +int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port)
  74431. +{
  74432. + int retval;
  74433. +
  74434. + if (port != 1) {
  74435. + return -DWC_E_INVALID;
  74436. + }
  74437. +
  74438. + retval = (hcd->flags.b.port_connect_status_change ||
  74439. + hcd->flags.b.port_reset_change ||
  74440. + hcd->flags.b.port_enable_change ||
  74441. + hcd->flags.b.port_suspend_change ||
  74442. + hcd->flags.b.port_over_current_change);
  74443. +#ifdef DEBUG
  74444. + if (retval) {
  74445. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
  74446. + " Root port status changed\n");
  74447. + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
  74448. + hcd->flags.b.port_connect_status_change);
  74449. + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
  74450. + hcd->flags.b.port_reset_change);
  74451. + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
  74452. + hcd->flags.b.port_enable_change);
  74453. + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
  74454. + hcd->flags.b.port_suspend_change);
  74455. + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
  74456. + hcd->flags.b.port_over_current_change);
  74457. + }
  74458. +#endif
  74459. + return retval;
  74460. +}
  74461. +
  74462. +int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * dwc_otg_hcd)
  74463. +{
  74464. + hfnum_data_t hfnum;
  74465. + hfnum.d32 =
  74466. + DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->
  74467. + hfnum);
  74468. +
  74469. +#ifdef DEBUG_SOF
  74470. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n",
  74471. + hfnum.b.frnum);
  74472. +#endif
  74473. + return hfnum.b.frnum;
  74474. +}
  74475. +
  74476. +int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  74477. + struct dwc_otg_hcd_function_ops *fops)
  74478. +{
  74479. + int retval = 0;
  74480. +
  74481. + hcd->fops = fops;
  74482. + if (!dwc_otg_is_device_mode(hcd->core_if) &&
  74483. + (!hcd->core_if->adp_enable || hcd->core_if->adp.adp_started)) {
  74484. + dwc_otg_hcd_reinit(hcd);
  74485. + } else {
  74486. + retval = -DWC_E_NO_DEVICE;
  74487. + }
  74488. +
  74489. + return retval;
  74490. +}
  74491. +
  74492. +void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd)
  74493. +{
  74494. + return hcd->priv;
  74495. +}
  74496. +
  74497. +void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data)
  74498. +{
  74499. + hcd->priv = priv_data;
  74500. +}
  74501. +
  74502. +uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd)
  74503. +{
  74504. + return hcd->otg_port;
  74505. +}
  74506. +
  74507. +uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd)
  74508. +{
  74509. + uint32_t is_b_host;
  74510. + if (hcd->core_if->op_state == B_HOST) {
  74511. + is_b_host = 1;
  74512. + } else {
  74513. + is_b_host = 0;
  74514. + }
  74515. +
  74516. + return is_b_host;
  74517. +}
  74518. +
  74519. +dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  74520. + int iso_desc_count, int atomic_alloc)
  74521. +{
  74522. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  74523. + uint32_t size;
  74524. +
  74525. + size =
  74526. + sizeof(*dwc_otg_urb) +
  74527. + iso_desc_count * sizeof(struct dwc_otg_hcd_iso_packet_desc);
  74528. + if (atomic_alloc)
  74529. + dwc_otg_urb = DWC_ALLOC_ATOMIC(size);
  74530. + else
  74531. + dwc_otg_urb = DWC_ALLOC(size);
  74532. +
  74533. + if (dwc_otg_urb)
  74534. + dwc_otg_urb->packet_count = iso_desc_count;
  74535. + else {
  74536. + DWC_ERROR("**** DWC OTG HCD URB alloc - "
  74537. + "%salloc of %db failed\n",
  74538. + atomic_alloc?"atomic ":"", size);
  74539. + }
  74540. + return dwc_otg_urb;
  74541. +}
  74542. +
  74543. +void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * dwc_otg_urb,
  74544. + uint8_t dev_addr, uint8_t ep_num,
  74545. + uint8_t ep_type, uint8_t ep_dir, uint16_t mps)
  74546. +{
  74547. + dwc_otg_hcd_fill_pipe(&dwc_otg_urb->pipe_info, dev_addr, ep_num,
  74548. + ep_type, ep_dir, mps);
  74549. +#if 0
  74550. + DWC_PRINTF
  74551. + ("addr = %d, ep_num = %d, ep_dir = 0x%x, ep_type = 0x%x, mps = %d\n",
  74552. + dev_addr, ep_num, ep_dir, ep_type, mps);
  74553. +#endif
  74554. +}
  74555. +
  74556. +void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  74557. + void *urb_handle, void *buf, dwc_dma_t dma,
  74558. + uint32_t buflen, void *setup_packet,
  74559. + dwc_dma_t setup_dma, uint32_t flags,
  74560. + uint16_t interval)
  74561. +{
  74562. + dwc_otg_urb->priv = urb_handle;
  74563. + dwc_otg_urb->buf = buf;
  74564. + dwc_otg_urb->dma = dma;
  74565. + dwc_otg_urb->length = buflen;
  74566. + dwc_otg_urb->setup_packet = setup_packet;
  74567. + dwc_otg_urb->setup_dma = setup_dma;
  74568. + dwc_otg_urb->flags = flags;
  74569. + dwc_otg_urb->interval = interval;
  74570. + dwc_otg_urb->status = -DWC_E_IN_PROGRESS;
  74571. +}
  74572. +
  74573. +uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb)
  74574. +{
  74575. + return dwc_otg_urb->status;
  74576. +}
  74577. +
  74578. +uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t * dwc_otg_urb)
  74579. +{
  74580. + return dwc_otg_urb->actual_length;
  74581. +}
  74582. +
  74583. +uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t * dwc_otg_urb)
  74584. +{
  74585. + return dwc_otg_urb->error_count;
  74586. +}
  74587. +
  74588. +void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  74589. + int desc_num, uint32_t offset,
  74590. + uint32_t length)
  74591. +{
  74592. + dwc_otg_urb->iso_descs[desc_num].offset = offset;
  74593. + dwc_otg_urb->iso_descs[desc_num].length = length;
  74594. +}
  74595. +
  74596. +uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t * dwc_otg_urb,
  74597. + int desc_num)
  74598. +{
  74599. + return dwc_otg_urb->iso_descs[desc_num].status;
  74600. +}
  74601. +
  74602. +uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  74603. + dwc_otg_urb, int desc_num)
  74604. +{
  74605. + return dwc_otg_urb->iso_descs[desc_num].actual_length;
  74606. +}
  74607. +
  74608. +int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd, void *ep_handle)
  74609. +{
  74610. + int allocated = 0;
  74611. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  74612. +
  74613. + if (qh) {
  74614. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  74615. + allocated = 1;
  74616. + }
  74617. + }
  74618. + return allocated;
  74619. +}
  74620. +
  74621. +int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle)
  74622. +{
  74623. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  74624. + int freed = 0;
  74625. + DWC_ASSERT(qh, "qh is not allocated\n");
  74626. +
  74627. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  74628. + freed = 1;
  74629. + }
  74630. +
  74631. + return freed;
  74632. +}
  74633. +
  74634. +uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd, void *ep_handle)
  74635. +{
  74636. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  74637. + DWC_ASSERT(qh, "qh is not allocated\n");
  74638. + return qh->usecs;
  74639. +}
  74640. +
  74641. +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd)
  74642. +{
  74643. +#ifdef DEBUG
  74644. + int num_channels;
  74645. + int i;
  74646. + gnptxsts_data_t np_tx_status;
  74647. + hptxsts_data_t p_tx_status;
  74648. +
  74649. + num_channels = hcd->core_if->core_params->host_channels;
  74650. + DWC_PRINTF("\n");
  74651. + DWC_PRINTF
  74652. + ("************************************************************\n");
  74653. + DWC_PRINTF("HCD State:\n");
  74654. + DWC_PRINTF(" Num channels: %d\n", num_channels);
  74655. + for (i = 0; i < num_channels; i++) {
  74656. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  74657. + DWC_PRINTF(" Channel %d:\n", i);
  74658. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  74659. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  74660. + DWC_PRINTF(" speed: %d\n", hc->speed);
  74661. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  74662. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  74663. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  74664. + DWC_PRINTF(" multi_count: %d\n", hc->multi_count);
  74665. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  74666. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  74667. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  74668. + DWC_PRINTF(" xfer_count: %d\n", hc->xfer_count);
  74669. + DWC_PRINTF(" halt_on_queue: %d\n", hc->halt_on_queue);
  74670. + DWC_PRINTF(" halt_pending: %d\n", hc->halt_pending);
  74671. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  74672. + DWC_PRINTF(" do_split: %d\n", hc->do_split);
  74673. + DWC_PRINTF(" complete_split: %d\n", hc->complete_split);
  74674. + DWC_PRINTF(" hub_addr: %d\n", hc->hub_addr);
  74675. + DWC_PRINTF(" port_addr: %d\n", hc->port_addr);
  74676. + DWC_PRINTF(" xact_pos: %d\n", hc->xact_pos);
  74677. + DWC_PRINTF(" requests: %d\n", hc->requests);
  74678. + DWC_PRINTF(" qh: %p\n", hc->qh);
  74679. + if (hc->xfer_started) {
  74680. + hfnum_data_t hfnum;
  74681. + hcchar_data_t hcchar;
  74682. + hctsiz_data_t hctsiz;
  74683. + hcint_data_t hcint;
  74684. + hcintmsk_data_t hcintmsk;
  74685. + hfnum.d32 =
  74686. + DWC_READ_REG32(&hcd->core_if->
  74687. + host_if->host_global_regs->hfnum);
  74688. + hcchar.d32 =
  74689. + DWC_READ_REG32(&hcd->core_if->host_if->
  74690. + hc_regs[i]->hcchar);
  74691. + hctsiz.d32 =
  74692. + DWC_READ_REG32(&hcd->core_if->host_if->
  74693. + hc_regs[i]->hctsiz);
  74694. + hcint.d32 =
  74695. + DWC_READ_REG32(&hcd->core_if->host_if->
  74696. + hc_regs[i]->hcint);
  74697. + hcintmsk.d32 =
  74698. + DWC_READ_REG32(&hcd->core_if->host_if->
  74699. + hc_regs[i]->hcintmsk);
  74700. + DWC_PRINTF(" hfnum: 0x%08x\n", hfnum.d32);
  74701. + DWC_PRINTF(" hcchar: 0x%08x\n", hcchar.d32);
  74702. + DWC_PRINTF(" hctsiz: 0x%08x\n", hctsiz.d32);
  74703. + DWC_PRINTF(" hcint: 0x%08x\n", hcint.d32);
  74704. + DWC_PRINTF(" hcintmsk: 0x%08x\n", hcintmsk.d32);
  74705. + }
  74706. + if (hc->xfer_started && hc->qh) {
  74707. + dwc_otg_qtd_t *qtd;
  74708. + dwc_otg_hcd_urb_t *urb;
  74709. +
  74710. + DWC_CIRCLEQ_FOREACH(qtd, &hc->qh->qtd_list, qtd_list_entry) {
  74711. + if (!qtd->in_process)
  74712. + break;
  74713. +
  74714. + urb = qtd->urb;
  74715. + DWC_PRINTF(" URB Info:\n");
  74716. + DWC_PRINTF(" qtd: %p, urb: %p\n", qtd, urb);
  74717. + if (urb) {
  74718. + DWC_PRINTF(" Dev: %d, EP: %d %s\n",
  74719. + dwc_otg_hcd_get_dev_addr(&urb->
  74720. + pipe_info),
  74721. + dwc_otg_hcd_get_ep_num(&urb->
  74722. + pipe_info),
  74723. + dwc_otg_hcd_is_pipe_in(&urb->
  74724. + pipe_info) ?
  74725. + "IN" : "OUT");
  74726. + DWC_PRINTF(" Max packet size: %d\n",
  74727. + dwc_otg_hcd_get_mps(&urb->
  74728. + pipe_info));
  74729. + DWC_PRINTF(" transfer_buffer: %p\n",
  74730. + urb->buf);
  74731. + DWC_PRINTF(" transfer_dma: %p\n",
  74732. + (void *)urb->dma);
  74733. + DWC_PRINTF(" transfer_buffer_length: %d\n",
  74734. + urb->length);
  74735. + DWC_PRINTF(" actual_length: %d\n",
  74736. + urb->actual_length);
  74737. + }
  74738. + }
  74739. + }
  74740. + }
  74741. + DWC_PRINTF(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
  74742. + DWC_PRINTF(" periodic_channels: %d\n", hcd->periodic_channels);
  74743. + DWC_PRINTF(" periodic_usecs: %d\n", hcd->periodic_usecs);
  74744. + np_tx_status.d32 =
  74745. + DWC_READ_REG32(&hcd->core_if->core_global_regs->gnptxsts);
  74746. + DWC_PRINTF(" NP Tx Req Queue Space Avail: %d\n",
  74747. + np_tx_status.b.nptxqspcavail);
  74748. + DWC_PRINTF(" NP Tx FIFO Space Avail: %d\n",
  74749. + np_tx_status.b.nptxfspcavail);
  74750. + p_tx_status.d32 =
  74751. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hptxsts);
  74752. + DWC_PRINTF(" P Tx Req Queue Space Avail: %d\n",
  74753. + p_tx_status.b.ptxqspcavail);
  74754. + DWC_PRINTF(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
  74755. + dwc_otg_hcd_dump_frrem(hcd);
  74756. + dwc_otg_dump_global_registers(hcd->core_if);
  74757. + dwc_otg_dump_host_registers(hcd->core_if);
  74758. + DWC_PRINTF
  74759. + ("************************************************************\n");
  74760. + DWC_PRINTF("\n");
  74761. +#endif
  74762. +}
  74763. +
  74764. +#ifdef DEBUG
  74765. +void dwc_print_setup_data(uint8_t * setup)
  74766. +{
  74767. + int i;
  74768. + if (CHK_DEBUG_LEVEL(DBG_HCD)) {
  74769. + DWC_PRINTF("Setup Data = MSB ");
  74770. + for (i = 7; i >= 0; i--)
  74771. + DWC_PRINTF("%02x ", setup[i]);
  74772. + DWC_PRINTF("\n");
  74773. + DWC_PRINTF(" bmRequestType Tranfer = %s\n",
  74774. + (setup[0] & 0x80) ? "Device-to-Host" :
  74775. + "Host-to-Device");
  74776. + DWC_PRINTF(" bmRequestType Type = ");
  74777. + switch ((setup[0] & 0x60) >> 5) {
  74778. + case 0:
  74779. + DWC_PRINTF("Standard\n");
  74780. + break;
  74781. + case 1:
  74782. + DWC_PRINTF("Class\n");
  74783. + break;
  74784. + case 2:
  74785. + DWC_PRINTF("Vendor\n");
  74786. + break;
  74787. + case 3:
  74788. + DWC_PRINTF("Reserved\n");
  74789. + break;
  74790. + }
  74791. + DWC_PRINTF(" bmRequestType Recipient = ");
  74792. + switch (setup[0] & 0x1f) {
  74793. + case 0:
  74794. + DWC_PRINTF("Device\n");
  74795. + break;
  74796. + case 1:
  74797. + DWC_PRINTF("Interface\n");
  74798. + break;
  74799. + case 2:
  74800. + DWC_PRINTF("Endpoint\n");
  74801. + break;
  74802. + case 3:
  74803. + DWC_PRINTF("Other\n");
  74804. + break;
  74805. + default:
  74806. + DWC_PRINTF("Reserved\n");
  74807. + break;
  74808. + }
  74809. + DWC_PRINTF(" bRequest = 0x%0x\n", setup[1]);
  74810. + DWC_PRINTF(" wValue = 0x%0x\n", *((uint16_t *) & setup[2]));
  74811. + DWC_PRINTF(" wIndex = 0x%0x\n", *((uint16_t *) & setup[4]));
  74812. + DWC_PRINTF(" wLength = 0x%0x\n\n", *((uint16_t *) & setup[6]));
  74813. + }
  74814. +}
  74815. +#endif
  74816. +
  74817. +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd)
  74818. +{
  74819. +#if 0
  74820. + DWC_PRINTF("Frame remaining at SOF:\n");
  74821. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74822. + hcd->frrem_samples, hcd->frrem_accum,
  74823. + (hcd->frrem_samples > 0) ?
  74824. + hcd->frrem_accum / hcd->frrem_samples : 0);
  74825. +
  74826. + DWC_PRINTF("\n");
  74827. + DWC_PRINTF("Frame remaining at start_transfer (uframe 7):\n");
  74828. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74829. + hcd->core_if->hfnum_7_samples,
  74830. + hcd->core_if->hfnum_7_frrem_accum,
  74831. + (hcd->core_if->hfnum_7_samples >
  74832. + 0) ? hcd->core_if->hfnum_7_frrem_accum /
  74833. + hcd->core_if->hfnum_7_samples : 0);
  74834. + DWC_PRINTF("Frame remaining at start_transfer (uframe 0):\n");
  74835. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74836. + hcd->core_if->hfnum_0_samples,
  74837. + hcd->core_if->hfnum_0_frrem_accum,
  74838. + (hcd->core_if->hfnum_0_samples >
  74839. + 0) ? hcd->core_if->hfnum_0_frrem_accum /
  74840. + hcd->core_if->hfnum_0_samples : 0);
  74841. + DWC_PRINTF("Frame remaining at start_transfer (uframe 1-6):\n");
  74842. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74843. + hcd->core_if->hfnum_other_samples,
  74844. + hcd->core_if->hfnum_other_frrem_accum,
  74845. + (hcd->core_if->hfnum_other_samples >
  74846. + 0) ? hcd->core_if->hfnum_other_frrem_accum /
  74847. + hcd->core_if->hfnum_other_samples : 0);
  74848. +
  74849. + DWC_PRINTF("\n");
  74850. + DWC_PRINTF("Frame remaining at sample point A (uframe 7):\n");
  74851. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74852. + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
  74853. + (hcd->hfnum_7_samples_a > 0) ?
  74854. + hcd->hfnum_7_frrem_accum_a / hcd->hfnum_7_samples_a : 0);
  74855. + DWC_PRINTF("Frame remaining at sample point A (uframe 0):\n");
  74856. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74857. + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
  74858. + (hcd->hfnum_0_samples_a > 0) ?
  74859. + hcd->hfnum_0_frrem_accum_a / hcd->hfnum_0_samples_a : 0);
  74860. + DWC_PRINTF("Frame remaining at sample point A (uframe 1-6):\n");
  74861. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74862. + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
  74863. + (hcd->hfnum_other_samples_a > 0) ?
  74864. + hcd->hfnum_other_frrem_accum_a /
  74865. + hcd->hfnum_other_samples_a : 0);
  74866. +
  74867. + DWC_PRINTF("\n");
  74868. + DWC_PRINTF("Frame remaining at sample point B (uframe 7):\n");
  74869. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74870. + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
  74871. + (hcd->hfnum_7_samples_b > 0) ?
  74872. + hcd->hfnum_7_frrem_accum_b / hcd->hfnum_7_samples_b : 0);
  74873. + DWC_PRINTF("Frame remaining at sample point B (uframe 0):\n");
  74874. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74875. + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
  74876. + (hcd->hfnum_0_samples_b > 0) ?
  74877. + hcd->hfnum_0_frrem_accum_b / hcd->hfnum_0_samples_b : 0);
  74878. + DWC_PRINTF("Frame remaining at sample point B (uframe 1-6):\n");
  74879. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74880. + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
  74881. + (hcd->hfnum_other_samples_b > 0) ?
  74882. + hcd->hfnum_other_frrem_accum_b /
  74883. + hcd->hfnum_other_samples_b : 0);
  74884. +#endif
  74885. +}
  74886. +
  74887. +#endif /* DWC_DEVICE_ONLY */
  74888. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c
  74889. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 1970-01-01 01:00:00.000000000 +0100
  74890. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 2014-04-24 16:04:39.819124254 +0200
  74891. @@ -0,0 +1,1132 @@
  74892. +/*==========================================================================
  74893. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_ddma.c $
  74894. + * $Revision: #10 $
  74895. + * $Date: 2011/10/20 $
  74896. + * $Change: 1869464 $
  74897. + *
  74898. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  74899. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  74900. + * otherwise expressly agreed to in writing between Synopsys and you.
  74901. + *
  74902. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  74903. + * any End User Software License Agreement or Agreement for Licensed Product
  74904. + * with Synopsys or any supplement thereto. You are permitted to use and
  74905. + * redistribute this Software in source and binary forms, with or without
  74906. + * modification, provided that redistributions of source code must retain this
  74907. + * notice. You may not view, use, disclose, copy or distribute this file or
  74908. + * any information contained herein except pursuant to this license grant from
  74909. + * Synopsys. If you do not agree with this notice, including the disclaimer
  74910. + * below, then you are not authorized to use the Software.
  74911. + *
  74912. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  74913. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  74914. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  74915. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  74916. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  74917. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  74918. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  74919. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  74920. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  74921. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  74922. + * DAMAGE.
  74923. + * ========================================================================== */
  74924. +#ifndef DWC_DEVICE_ONLY
  74925. +
  74926. +/** @file
  74927. + * This file contains Descriptor DMA support implementation for host mode.
  74928. + */
  74929. +
  74930. +#include "dwc_otg_hcd.h"
  74931. +#include "dwc_otg_regs.h"
  74932. +
  74933. +extern bool microframe_schedule;
  74934. +
  74935. +static inline uint8_t frame_list_idx(uint16_t frame)
  74936. +{
  74937. + return (frame & (MAX_FRLIST_EN_NUM - 1));
  74938. +}
  74939. +
  74940. +static inline uint16_t desclist_idx_inc(uint16_t idx, uint16_t inc, uint8_t speed)
  74941. +{
  74942. + return (idx + inc) &
  74943. + (((speed ==
  74944. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  74945. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  74946. +}
  74947. +
  74948. +static inline uint16_t desclist_idx_dec(uint16_t idx, uint16_t inc, uint8_t speed)
  74949. +{
  74950. + return (idx - inc) &
  74951. + (((speed ==
  74952. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  74953. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  74954. +}
  74955. +
  74956. +static inline uint16_t max_desc_num(dwc_otg_qh_t * qh)
  74957. +{
  74958. + return (((qh->ep_type == UE_ISOCHRONOUS)
  74959. + && (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH))
  74960. + ? MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC);
  74961. +}
  74962. +static inline uint16_t frame_incr_val(dwc_otg_qh_t * qh)
  74963. +{
  74964. + return ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH)
  74965. + ? ((qh->interval + 8 - 1) / 8)
  74966. + : qh->interval);
  74967. +}
  74968. +
  74969. +static int desc_list_alloc(dwc_otg_qh_t * qh)
  74970. +{
  74971. + int retval = 0;
  74972. +
  74973. + qh->desc_list = (dwc_otg_host_dma_desc_t *)
  74974. + DWC_DMA_ALLOC(sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh),
  74975. + &qh->desc_list_dma);
  74976. +
  74977. + if (!qh->desc_list) {
  74978. + retval = -DWC_E_NO_MEMORY;
  74979. + DWC_ERROR("%s: DMA descriptor list allocation failed\n", __func__);
  74980. +
  74981. + }
  74982. +
  74983. + dwc_memset(qh->desc_list, 0x00,
  74984. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  74985. +
  74986. + qh->n_bytes =
  74987. + (uint32_t *) DWC_ALLOC(sizeof(uint32_t) * max_desc_num(qh));
  74988. +
  74989. + if (!qh->n_bytes) {
  74990. + retval = -DWC_E_NO_MEMORY;
  74991. + DWC_ERROR
  74992. + ("%s: Failed to allocate array for descriptors' size actual values\n",
  74993. + __func__);
  74994. +
  74995. + }
  74996. + return retval;
  74997. +
  74998. +}
  74999. +
  75000. +static void desc_list_free(dwc_otg_qh_t * qh)
  75001. +{
  75002. + if (qh->desc_list) {
  75003. + DWC_DMA_FREE(max_desc_num(qh), qh->desc_list,
  75004. + qh->desc_list_dma);
  75005. + qh->desc_list = NULL;
  75006. + }
  75007. +
  75008. + if (qh->n_bytes) {
  75009. + DWC_FREE(qh->n_bytes);
  75010. + qh->n_bytes = NULL;
  75011. + }
  75012. +}
  75013. +
  75014. +static int frame_list_alloc(dwc_otg_hcd_t * hcd)
  75015. +{
  75016. + int retval = 0;
  75017. + if (hcd->frame_list)
  75018. + return 0;
  75019. +
  75020. + hcd->frame_list = DWC_DMA_ALLOC(4 * MAX_FRLIST_EN_NUM,
  75021. + &hcd->frame_list_dma);
  75022. + if (!hcd->frame_list) {
  75023. + retval = -DWC_E_NO_MEMORY;
  75024. + DWC_ERROR("%s: Frame List allocation failed\n", __func__);
  75025. + }
  75026. +
  75027. + dwc_memset(hcd->frame_list, 0x00, 4 * MAX_FRLIST_EN_NUM);
  75028. +
  75029. + return retval;
  75030. +}
  75031. +
  75032. +static void frame_list_free(dwc_otg_hcd_t * hcd)
  75033. +{
  75034. + if (!hcd->frame_list)
  75035. + return;
  75036. +
  75037. + DWC_DMA_FREE(4 * MAX_FRLIST_EN_NUM, hcd->frame_list, hcd->frame_list_dma);
  75038. + hcd->frame_list = NULL;
  75039. +}
  75040. +
  75041. +static void per_sched_enable(dwc_otg_hcd_t * hcd, uint16_t fr_list_en)
  75042. +{
  75043. +
  75044. + hcfg_data_t hcfg;
  75045. +
  75046. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  75047. +
  75048. + if (hcfg.b.perschedena) {
  75049. + /* already enabled */
  75050. + return;
  75051. + }
  75052. +
  75053. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hflbaddr,
  75054. + hcd->frame_list_dma);
  75055. +
  75056. + switch (fr_list_en) {
  75057. + case 64:
  75058. + hcfg.b.frlisten = 3;
  75059. + break;
  75060. + case 32:
  75061. + hcfg.b.frlisten = 2;
  75062. + break;
  75063. + case 16:
  75064. + hcfg.b.frlisten = 1;
  75065. + break;
  75066. + case 8:
  75067. + hcfg.b.frlisten = 0;
  75068. + break;
  75069. + default:
  75070. + break;
  75071. + }
  75072. +
  75073. + hcfg.b.perschedena = 1;
  75074. +
  75075. + DWC_DEBUGPL(DBG_HCD, "Enabling Periodic schedule\n");
  75076. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  75077. +
  75078. +}
  75079. +
  75080. +static void per_sched_disable(dwc_otg_hcd_t * hcd)
  75081. +{
  75082. + hcfg_data_t hcfg;
  75083. +
  75084. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  75085. +
  75086. + if (!hcfg.b.perschedena) {
  75087. + /* already disabled */
  75088. + return;
  75089. + }
  75090. + hcfg.b.perschedena = 0;
  75091. +
  75092. + DWC_DEBUGPL(DBG_HCD, "Disabling Periodic schedule\n");
  75093. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  75094. +}
  75095. +
  75096. +/*
  75097. + * Activates/Deactivates FrameList entries for the channel
  75098. + * based on endpoint servicing period.
  75099. + */
  75100. +void update_frame_list(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, uint8_t enable)
  75101. +{
  75102. + uint16_t i, j, inc;
  75103. + dwc_hc_t *hc = NULL;
  75104. +
  75105. + if (!qh->channel) {
  75106. + DWC_ERROR("qh->channel = %p", qh->channel);
  75107. + return;
  75108. + }
  75109. +
  75110. + if (!hcd) {
  75111. + DWC_ERROR("------hcd = %p", hcd);
  75112. + return;
  75113. + }
  75114. +
  75115. + if (!hcd->frame_list) {
  75116. + DWC_ERROR("-------hcd->frame_list = %p", hcd->frame_list);
  75117. + return;
  75118. + }
  75119. +
  75120. + hc = qh->channel;
  75121. + inc = frame_incr_val(qh);
  75122. + if (qh->ep_type == UE_ISOCHRONOUS)
  75123. + i = frame_list_idx(qh->sched_frame);
  75124. + else
  75125. + i = 0;
  75126. +
  75127. + j = i;
  75128. + do {
  75129. + if (enable)
  75130. + hcd->frame_list[j] |= (1 << hc->hc_num);
  75131. + else
  75132. + hcd->frame_list[j] &= ~(1 << hc->hc_num);
  75133. + j = (j + inc) & (MAX_FRLIST_EN_NUM - 1);
  75134. + }
  75135. + while (j != i);
  75136. + if (!enable)
  75137. + return;
  75138. + hc->schinfo = 0;
  75139. + if (qh->channel->speed == DWC_OTG_EP_SPEED_HIGH) {
  75140. + j = 1;
  75141. + /* TODO - check this */
  75142. + inc = (8 + qh->interval - 1) / qh->interval;
  75143. + for (i = 0; i < inc; i++) {
  75144. + hc->schinfo |= j;
  75145. + j = j << qh->interval;
  75146. + }
  75147. + } else {
  75148. + hc->schinfo = 0xff;
  75149. + }
  75150. +}
  75151. +
  75152. +#if 1
  75153. +void dump_frame_list(dwc_otg_hcd_t * hcd)
  75154. +{
  75155. + int i = 0;
  75156. + DWC_PRINTF("--FRAME LIST (hex) --\n");
  75157. + for (i = 0; i < MAX_FRLIST_EN_NUM; i++) {
  75158. + DWC_PRINTF("%x\t", hcd->frame_list[i]);
  75159. + if (!(i % 8) && i)
  75160. + DWC_PRINTF("\n");
  75161. + }
  75162. + DWC_PRINTF("\n----\n");
  75163. +
  75164. +}
  75165. +#endif
  75166. +
  75167. +static void release_channel_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75168. +{
  75169. + dwc_irqflags_t flags;
  75170. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  75171. +
  75172. + dwc_hc_t *hc = qh->channel;
  75173. + if (dwc_qh_is_non_per(qh)) {
  75174. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  75175. + if (!microframe_schedule)
  75176. + hcd->non_periodic_channels--;
  75177. + else
  75178. + hcd->available_host_channels++;
  75179. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  75180. + } else
  75181. + update_frame_list(hcd, qh, 0);
  75182. +
  75183. + /*
  75184. + * The condition is added to prevent double cleanup try in case of device
  75185. + * disconnect. See channel cleanup in dwc_otg_hcd_disconnect_cb().
  75186. + */
  75187. + if (hc->qh) {
  75188. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  75189. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  75190. + hc->qh = NULL;
  75191. + }
  75192. +
  75193. + qh->channel = NULL;
  75194. + qh->ntd = 0;
  75195. +
  75196. + if (qh->desc_list) {
  75197. + dwc_memset(qh->desc_list, 0x00,
  75198. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  75199. + }
  75200. +}
  75201. +
  75202. +/**
  75203. + * Initializes a QH structure's Descriptor DMA related members.
  75204. + * Allocates memory for descriptor list.
  75205. + * On first periodic QH, allocates memory for FrameList
  75206. + * and enables periodic scheduling.
  75207. + *
  75208. + * @param hcd The HCD state structure for the DWC OTG controller.
  75209. + * @param qh The QH to init.
  75210. + *
  75211. + * @return 0 if successful, negative error code otherwise.
  75212. + */
  75213. +int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75214. +{
  75215. + int retval = 0;
  75216. +
  75217. + if (qh->do_split) {
  75218. + DWC_ERROR("SPLIT Transfers are not supported in Descriptor DMA.\n");
  75219. + return -1;
  75220. + }
  75221. +
  75222. + retval = desc_list_alloc(qh);
  75223. +
  75224. + if ((retval == 0)
  75225. + && (qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)) {
  75226. + if (!hcd->frame_list) {
  75227. + retval = frame_list_alloc(hcd);
  75228. + /* Enable periodic schedule on first periodic QH */
  75229. + if (retval == 0)
  75230. + per_sched_enable(hcd, MAX_FRLIST_EN_NUM);
  75231. + }
  75232. + }
  75233. +
  75234. + qh->ntd = 0;
  75235. +
  75236. + return retval;
  75237. +}
  75238. +
  75239. +/**
  75240. + * Frees descriptor list memory associated with the QH.
  75241. + * If QH is periodic and the last, frees FrameList memory
  75242. + * and disables periodic scheduling.
  75243. + *
  75244. + * @param hcd The HCD state structure for the DWC OTG controller.
  75245. + * @param qh The QH to init.
  75246. + */
  75247. +void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75248. +{
  75249. + desc_list_free(qh);
  75250. +
  75251. + /*
  75252. + * Channel still assigned due to some reasons.
  75253. + * Seen on Isoc URB dequeue. Channel halted but no subsequent
  75254. + * ChHalted interrupt to release the channel. Afterwards
  75255. + * when it comes here from endpoint disable routine
  75256. + * channel remains assigned.
  75257. + */
  75258. + if (qh->channel)
  75259. + release_channel_ddma(hcd, qh);
  75260. +
  75261. + if ((qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)
  75262. + && (microframe_schedule || !hcd->periodic_channels) && hcd->frame_list) {
  75263. +
  75264. + per_sched_disable(hcd);
  75265. + frame_list_free(hcd);
  75266. + }
  75267. +}
  75268. +
  75269. +static uint8_t frame_to_desc_idx(dwc_otg_qh_t * qh, uint16_t frame_idx)
  75270. +{
  75271. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  75272. + /*
  75273. + * Descriptor set(8 descriptors) index
  75274. + * which is 8-aligned.
  75275. + */
  75276. + return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
  75277. + } else {
  75278. + return (frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1));
  75279. + }
  75280. +}
  75281. +
  75282. +/*
  75283. + * Determine starting frame for Isochronous transfer.
  75284. + * Few frames skipped to prevent race condition with HC.
  75285. + */
  75286. +static uint8_t calc_starting_frame(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  75287. + uint8_t * skip_frames)
  75288. +{
  75289. + uint16_t frame = 0;
  75290. + hcd->frame_number = dwc_otg_hcd_get_frame_number(hcd);
  75291. +
  75292. + /* sched_frame is always frame number(not uFrame) both in FS and HS !! */
  75293. +
  75294. + /*
  75295. + * skip_frames is used to limit activated descriptors number
  75296. + * to avoid the situation when HC services the last activated
  75297. + * descriptor firstly.
  75298. + * Example for FS:
  75299. + * Current frame is 1, scheduled frame is 3. Since HC always fetches the descriptor
  75300. + * corresponding to curr_frame+1, the descriptor corresponding to frame 2
  75301. + * will be fetched. If the number of descriptors is max=64 (or greather) the
  75302. + * list will be fully programmed with Active descriptors and it is possible
  75303. + * case(rare) that the latest descriptor(considering rollback) corresponding
  75304. + * to frame 2 will be serviced first. HS case is more probable because, in fact,
  75305. + * up to 11 uframes(16 in the code) may be skipped.
  75306. + */
  75307. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  75308. + /*
  75309. + * Consider uframe counter also, to start xfer asap.
  75310. + * If half of the frame elapsed skip 2 frames otherwise
  75311. + * just 1 frame.
  75312. + * Starting descriptor index must be 8-aligned, so
  75313. + * if the current frame is near to complete the next one
  75314. + * is skipped as well.
  75315. + */
  75316. +
  75317. + if (dwc_micro_frame_num(hcd->frame_number) >= 5) {
  75318. + *skip_frames = 2 * 8;
  75319. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  75320. + } else {
  75321. + *skip_frames = 1 * 8;
  75322. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  75323. + }
  75324. +
  75325. + frame = dwc_full_frame_num(frame);
  75326. + } else {
  75327. + /*
  75328. + * Two frames are skipped for FS - the current and the next.
  75329. + * But for descriptor programming, 1 frame(descriptor) is enough,
  75330. + * see example above.
  75331. + */
  75332. + *skip_frames = 1;
  75333. + frame = dwc_frame_num_inc(hcd->frame_number, 2);
  75334. + }
  75335. +
  75336. + return frame;
  75337. +}
  75338. +
  75339. +/*
  75340. + * Calculate initial descriptor index for isochronous transfer
  75341. + * based on scheduled frame.
  75342. + */
  75343. +static uint8_t recalc_initial_desc_idx(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75344. +{
  75345. + uint16_t frame = 0, fr_idx, fr_idx_tmp;
  75346. + uint8_t skip_frames = 0;
  75347. + /*
  75348. + * With current ISOC processing algorithm the channel is being
  75349. + * released when no more QTDs in the list(qh->ntd == 0).
  75350. + * Thus this function is called only when qh->ntd == 0 and qh->channel == 0.
  75351. + *
  75352. + * So qh->channel != NULL branch is not used and just not removed from the
  75353. + * source file. It is required for another possible approach which is,
  75354. + * do not disable and release the channel when ISOC session completed,
  75355. + * just move QH to inactive schedule until new QTD arrives.
  75356. + * On new QTD, the QH moved back to 'ready' schedule,
  75357. + * starting frame and therefore starting desc_index are recalculated.
  75358. + * In this case channel is released only on ep_disable.
  75359. + */
  75360. +
  75361. + /* Calculate starting descriptor index. For INTERRUPT endpoint it is always 0. */
  75362. + if (qh->channel) {
  75363. + frame = calc_starting_frame(hcd, qh, &skip_frames);
  75364. + /*
  75365. + * Calculate initial descriptor index based on FrameList current bitmap
  75366. + * and servicing period.
  75367. + */
  75368. + fr_idx_tmp = frame_list_idx(frame);
  75369. + fr_idx =
  75370. + (MAX_FRLIST_EN_NUM + frame_list_idx(qh->sched_frame) -
  75371. + fr_idx_tmp)
  75372. + % frame_incr_val(qh);
  75373. + fr_idx = (fr_idx + fr_idx_tmp) % MAX_FRLIST_EN_NUM;
  75374. + } else {
  75375. + qh->sched_frame = calc_starting_frame(hcd, qh, &skip_frames);
  75376. + fr_idx = frame_list_idx(qh->sched_frame);
  75377. + }
  75378. +
  75379. + qh->td_first = qh->td_last = frame_to_desc_idx(qh, fr_idx);
  75380. +
  75381. + return skip_frames;
  75382. +}
  75383. +
  75384. +#define ISOC_URB_GIVEBACK_ASAP
  75385. +
  75386. +#define MAX_ISOC_XFER_SIZE_FS 1023
  75387. +#define MAX_ISOC_XFER_SIZE_HS 3072
  75388. +#define DESCNUM_THRESHOLD 4
  75389. +
  75390. +static void init_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  75391. + uint8_t skip_frames)
  75392. +{
  75393. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  75394. + dwc_otg_qtd_t *qtd;
  75395. + dwc_otg_host_dma_desc_t *dma_desc;
  75396. + uint16_t idx, inc, n_desc, ntd_max, max_xfer_size;
  75397. +
  75398. + idx = qh->td_last;
  75399. + inc = qh->interval;
  75400. + n_desc = 0;
  75401. +
  75402. + ntd_max = (max_desc_num(qh) + qh->interval - 1) / qh->interval;
  75403. + if (skip_frames && !qh->channel)
  75404. + ntd_max = ntd_max - skip_frames / qh->interval;
  75405. +
  75406. + max_xfer_size =
  75407. + (qh->dev_speed ==
  75408. + DWC_OTG_EP_SPEED_HIGH) ? MAX_ISOC_XFER_SIZE_HS :
  75409. + MAX_ISOC_XFER_SIZE_FS;
  75410. +
  75411. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  75412. + while ((qh->ntd < ntd_max)
  75413. + && (qtd->isoc_frame_index_last <
  75414. + qtd->urb->packet_count)) {
  75415. +
  75416. + dma_desc = &qh->desc_list[idx];
  75417. + dwc_memset(dma_desc, 0x00, sizeof(dwc_otg_host_dma_desc_t));
  75418. +
  75419. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
  75420. +
  75421. + if (frame_desc->length > max_xfer_size)
  75422. + qh->n_bytes[idx] = max_xfer_size;
  75423. + else
  75424. + qh->n_bytes[idx] = frame_desc->length;
  75425. + dma_desc->status.b_isoc.n_bytes = qh->n_bytes[idx];
  75426. + dma_desc->status.b_isoc.a = 1;
  75427. + dma_desc->status.b_isoc.sts = 0;
  75428. +
  75429. + dma_desc->buf = qtd->urb->dma + frame_desc->offset;
  75430. +
  75431. + qh->ntd++;
  75432. +
  75433. + qtd->isoc_frame_index_last++;
  75434. +
  75435. +#ifdef ISOC_URB_GIVEBACK_ASAP
  75436. + /*
  75437. + * Set IOC for each descriptor corresponding to the
  75438. + * last frame of the URB.
  75439. + */
  75440. + if (qtd->isoc_frame_index_last ==
  75441. + qtd->urb->packet_count)
  75442. + dma_desc->status.b_isoc.ioc = 1;
  75443. +
  75444. +#endif
  75445. + idx = desclist_idx_inc(idx, inc, qh->dev_speed);
  75446. + n_desc++;
  75447. +
  75448. + }
  75449. + qtd->in_process = 1;
  75450. + }
  75451. +
  75452. + qh->td_last = idx;
  75453. +
  75454. +#ifdef ISOC_URB_GIVEBACK_ASAP
  75455. + /* Set IOC for the last descriptor if descriptor list is full */
  75456. + if (qh->ntd == ntd_max) {
  75457. + idx = desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  75458. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  75459. + }
  75460. +#else
  75461. + /*
  75462. + * Set IOC bit only for one descriptor.
  75463. + * Always try to be ahead of HW processing,
  75464. + * i.e. on IOC generation driver activates next descriptors but
  75465. + * core continues to process descriptors followed the one with IOC set.
  75466. + */
  75467. +
  75468. + if (n_desc > DESCNUM_THRESHOLD) {
  75469. + /*
  75470. + * Move IOC "up". Required even if there is only one QTD
  75471. + * in the list, cause QTDs migth continue to be queued,
  75472. + * but during the activation it was only one queued.
  75473. + * Actually more than one QTD might be in the list if this function called
  75474. + * from XferCompletion - QTDs was queued during HW processing of the previous
  75475. + * descriptor chunk.
  75476. + */
  75477. + idx = dwc_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), qh->dev_speed);
  75478. + } else {
  75479. + /*
  75480. + * Set the IOC for the latest descriptor
  75481. + * if either number of descriptor is not greather than threshold
  75482. + * or no more new descriptors activated.
  75483. + */
  75484. + idx = dwc_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  75485. + }
  75486. +
  75487. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  75488. +#endif
  75489. +}
  75490. +
  75491. +static void init_non_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75492. +{
  75493. +
  75494. + dwc_hc_t *hc;
  75495. + dwc_otg_host_dma_desc_t *dma_desc;
  75496. + dwc_otg_qtd_t *qtd;
  75497. + int num_packets, len, n_desc = 0;
  75498. +
  75499. + hc = qh->channel;
  75500. +
  75501. + /*
  75502. + * Start with hc->xfer_buff initialized in
  75503. + * assign_and_init_hc(), then if SG transfer consists of multiple URBs,
  75504. + * this pointer re-assigned to the buffer of the currently processed QTD.
  75505. + * For non-SG request there is always one QTD active.
  75506. + */
  75507. +
  75508. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  75509. +
  75510. + if (n_desc) {
  75511. + /* SG request - more than 1 QTDs */
  75512. + hc->xfer_buff = (uint8_t *)qtd->urb->dma + qtd->urb->actual_length;
  75513. + hc->xfer_len = qtd->urb->length - qtd->urb->actual_length;
  75514. + }
  75515. +
  75516. + qtd->n_desc = 0;
  75517. +
  75518. + do {
  75519. + dma_desc = &qh->desc_list[n_desc];
  75520. + len = hc->xfer_len;
  75521. +
  75522. + if (len > MAX_DMA_DESC_SIZE)
  75523. + len = MAX_DMA_DESC_SIZE - hc->max_packet + 1;
  75524. +
  75525. + if (hc->ep_is_in) {
  75526. + if (len > 0) {
  75527. + num_packets = (len + hc->max_packet - 1) / hc->max_packet;
  75528. + } else {
  75529. + /* Need 1 packet for transfer length of 0. */
  75530. + num_packets = 1;
  75531. + }
  75532. + /* Always program an integral # of max packets for IN transfers. */
  75533. + len = num_packets * hc->max_packet;
  75534. + }
  75535. +
  75536. + dma_desc->status.b.n_bytes = len;
  75537. +
  75538. + qh->n_bytes[n_desc] = len;
  75539. +
  75540. + if ((qh->ep_type == UE_CONTROL)
  75541. + && (qtd->control_phase == DWC_OTG_CONTROL_SETUP))
  75542. + dma_desc->status.b.sup = 1; /* Setup Packet */
  75543. +
  75544. + dma_desc->status.b.a = 1; /* Active descriptor */
  75545. + dma_desc->status.b.sts = 0;
  75546. +
  75547. + dma_desc->buf =
  75548. + ((unsigned long)hc->xfer_buff & 0xffffffff);
  75549. +
  75550. + /*
  75551. + * Last descriptor(or single) of IN transfer
  75552. + * with actual size less than MaxPacket.
  75553. + */
  75554. + if (len > hc->xfer_len) {
  75555. + hc->xfer_len = 0;
  75556. + } else {
  75557. + hc->xfer_buff += len;
  75558. + hc->xfer_len -= len;
  75559. + }
  75560. +
  75561. + qtd->n_desc++;
  75562. + n_desc++;
  75563. + }
  75564. + while ((hc->xfer_len > 0) && (n_desc != MAX_DMA_DESC_NUM_GENERIC));
  75565. +
  75566. +
  75567. + qtd->in_process = 1;
  75568. +
  75569. + if (qh->ep_type == UE_CONTROL)
  75570. + break;
  75571. +
  75572. + if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
  75573. + break;
  75574. + }
  75575. +
  75576. + if (n_desc) {
  75577. + /* Request Transfer Complete interrupt for the last descriptor */
  75578. + qh->desc_list[n_desc - 1].status.b.ioc = 1;
  75579. + /* End of List indicator */
  75580. + qh->desc_list[n_desc - 1].status.b.eol = 1;
  75581. +
  75582. + hc->ntd = n_desc;
  75583. + }
  75584. +}
  75585. +
  75586. +/**
  75587. + * For Control and Bulk endpoints initializes descriptor list
  75588. + * and starts the transfer.
  75589. + *
  75590. + * For Interrupt and Isochronous endpoints initializes descriptor list
  75591. + * then updates FrameList, marking appropriate entries as active.
  75592. + * In case of Isochronous, the starting descriptor index is calculated based
  75593. + * on the scheduled frame, but only on the first transfer descriptor within a session.
  75594. + * Then starts the transfer via enabling the channel.
  75595. + * For Isochronous endpoint the channel is not halted on XferComplete
  75596. + * interrupt so remains assigned to the endpoint(QH) until session is done.
  75597. + *
  75598. + * @param hcd The HCD state structure for the DWC OTG controller.
  75599. + * @param qh The QH to init.
  75600. + *
  75601. + * @return 0 if successful, negative error code otherwise.
  75602. + */
  75603. +void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75604. +{
  75605. + /* Channel is already assigned */
  75606. + dwc_hc_t *hc = qh->channel;
  75607. + uint8_t skip_frames = 0;
  75608. +
  75609. + switch (hc->ep_type) {
  75610. + case DWC_OTG_EP_TYPE_CONTROL:
  75611. + case DWC_OTG_EP_TYPE_BULK:
  75612. + init_non_isoc_dma_desc(hcd, qh);
  75613. +
  75614. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  75615. + break;
  75616. + case DWC_OTG_EP_TYPE_INTR:
  75617. + init_non_isoc_dma_desc(hcd, qh);
  75618. +
  75619. + update_frame_list(hcd, qh, 1);
  75620. +
  75621. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  75622. + break;
  75623. + case DWC_OTG_EP_TYPE_ISOC:
  75624. +
  75625. + if (!qh->ntd)
  75626. + skip_frames = recalc_initial_desc_idx(hcd, qh);
  75627. +
  75628. + init_isoc_dma_desc(hcd, qh, skip_frames);
  75629. +
  75630. + if (!hc->xfer_started) {
  75631. +
  75632. + update_frame_list(hcd, qh, 1);
  75633. +
  75634. + /*
  75635. + * Always set to max, instead of actual size.
  75636. + * Otherwise ntd will be changed with
  75637. + * channel being enabled. Not recommended.
  75638. + *
  75639. + */
  75640. + hc->ntd = max_desc_num(qh);
  75641. + /* Enable channel only once for ISOC */
  75642. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  75643. + }
  75644. +
  75645. + break;
  75646. + default:
  75647. +
  75648. + break;
  75649. + }
  75650. +}
  75651. +
  75652. +static void complete_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  75653. + dwc_hc_t * hc,
  75654. + dwc_otg_hc_regs_t * hc_regs,
  75655. + dwc_otg_halt_status_e halt_status)
  75656. +{
  75657. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  75658. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  75659. + dwc_otg_qh_t *qh;
  75660. + dwc_otg_host_dma_desc_t *dma_desc;
  75661. + uint16_t idx, remain;
  75662. + uint8_t urb_compl;
  75663. +
  75664. + qh = hc->qh;
  75665. + idx = qh->td_first;
  75666. +
  75667. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  75668. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry)
  75669. + qtd->in_process = 0;
  75670. + return;
  75671. + } else if ((halt_status == DWC_OTG_HC_XFER_AHB_ERR) ||
  75672. + (halt_status == DWC_OTG_HC_XFER_BABBLE_ERR)) {
  75673. + /*
  75674. + * Channel is halted in these error cases.
  75675. + * Considered as serious issues.
  75676. + * Complete all URBs marking all frames as failed,
  75677. + * irrespective whether some of the descriptors(frames) succeeded or no.
  75678. + * Pass error code to completion routine as well, to
  75679. + * update urb->status, some of class drivers might use it to stop
  75680. + * queing transfer requests.
  75681. + */
  75682. + int err = (halt_status == DWC_OTG_HC_XFER_AHB_ERR)
  75683. + ? (-DWC_E_IO)
  75684. + : (-DWC_E_OVERFLOW);
  75685. +
  75686. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  75687. + for (idx = 0; idx < qtd->urb->packet_count; idx++) {
  75688. + frame_desc = &qtd->urb->iso_descs[idx];
  75689. + frame_desc->status = err;
  75690. + }
  75691. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, err);
  75692. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  75693. + }
  75694. + return;
  75695. + }
  75696. +
  75697. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  75698. +
  75699. + if (!qtd->in_process)
  75700. + break;
  75701. +
  75702. + urb_compl = 0;
  75703. +
  75704. + do {
  75705. +
  75706. + dma_desc = &qh->desc_list[idx];
  75707. +
  75708. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  75709. + remain = hc->ep_is_in ? dma_desc->status.b_isoc.n_bytes : 0;
  75710. +
  75711. + if (dma_desc->status.b_isoc.sts == DMA_DESC_STS_PKTERR) {
  75712. + /*
  75713. + * XactError or, unable to complete all the transactions
  75714. + * in the scheduled micro-frame/frame,
  75715. + * both indicated by DMA_DESC_STS_PKTERR.
  75716. + */
  75717. + qtd->urb->error_count++;
  75718. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  75719. + frame_desc->status = -DWC_E_PROTOCOL;
  75720. + } else {
  75721. + /* Success */
  75722. +
  75723. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  75724. + frame_desc->status = 0;
  75725. + }
  75726. +
  75727. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  75728. + /*
  75729. + * urb->status is not used for isoc transfers here.
  75730. + * The individual frame_desc status are used instead.
  75731. + */
  75732. +
  75733. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  75734. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  75735. +
  75736. + /*
  75737. + * This check is necessary because urb_dequeue can be called
  75738. + * from urb complete callback(sound driver example).
  75739. + * All pending URBs are dequeued there, so no need for
  75740. + * further processing.
  75741. + */
  75742. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  75743. + return;
  75744. + }
  75745. +
  75746. + urb_compl = 1;
  75747. +
  75748. + }
  75749. +
  75750. + qh->ntd--;
  75751. +
  75752. + /* Stop if IOC requested descriptor reached */
  75753. + if (dma_desc->status.b_isoc.ioc) {
  75754. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  75755. + goto stop_scan;
  75756. + }
  75757. +
  75758. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  75759. +
  75760. + if (urb_compl)
  75761. + break;
  75762. + }
  75763. + while (idx != qh->td_first);
  75764. + }
  75765. +stop_scan:
  75766. + qh->td_first = idx;
  75767. +}
  75768. +
  75769. +uint8_t update_non_isoc_urb_state_ddma(dwc_otg_hcd_t * hcd,
  75770. + dwc_hc_t * hc,
  75771. + dwc_otg_qtd_t * qtd,
  75772. + dwc_otg_host_dma_desc_t * dma_desc,
  75773. + dwc_otg_halt_status_e halt_status,
  75774. + uint32_t n_bytes, uint8_t * xfer_done)
  75775. +{
  75776. +
  75777. + uint16_t remain = hc->ep_is_in ? dma_desc->status.b.n_bytes : 0;
  75778. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  75779. +
  75780. + if (halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  75781. + urb->status = -DWC_E_IO;
  75782. + return 1;
  75783. + }
  75784. + if (dma_desc->status.b.sts == DMA_DESC_STS_PKTERR) {
  75785. + switch (halt_status) {
  75786. + case DWC_OTG_HC_XFER_STALL:
  75787. + urb->status = -DWC_E_PIPE;
  75788. + break;
  75789. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  75790. + urb->status = -DWC_E_OVERFLOW;
  75791. + break;
  75792. + case DWC_OTG_HC_XFER_XACT_ERR:
  75793. + urb->status = -DWC_E_PROTOCOL;
  75794. + break;
  75795. + default:
  75796. + DWC_ERROR("%s: Unhandled descriptor error status (%d)\n", __func__,
  75797. + halt_status);
  75798. + break;
  75799. + }
  75800. + return 1;
  75801. + }
  75802. +
  75803. + if (dma_desc->status.b.a == 1) {
  75804. + DWC_DEBUGPL(DBG_HCDV,
  75805. + "Active descriptor encountered on channel %d\n",
  75806. + hc->hc_num);
  75807. + return 0;
  75808. + }
  75809. +
  75810. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL) {
  75811. + if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  75812. + urb->actual_length += n_bytes - remain;
  75813. + if (remain || urb->actual_length == urb->length) {
  75814. + /*
  75815. + * For Control Data stage do not set urb->status=0 to prevent
  75816. + * URB callback. Set it when Status phase done. See below.
  75817. + */
  75818. + *xfer_done = 1;
  75819. + }
  75820. +
  75821. + } else if (qtd->control_phase == DWC_OTG_CONTROL_STATUS) {
  75822. + urb->status = 0;
  75823. + *xfer_done = 1;
  75824. + }
  75825. + /* No handling for SETUP stage */
  75826. + } else {
  75827. + /* BULK and INTR */
  75828. + urb->actual_length += n_bytes - remain;
  75829. + if (remain || urb->actual_length == urb->length) {
  75830. + urb->status = 0;
  75831. + *xfer_done = 1;
  75832. + }
  75833. + }
  75834. +
  75835. + return 0;
  75836. +}
  75837. +
  75838. +static void complete_non_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  75839. + dwc_hc_t * hc,
  75840. + dwc_otg_hc_regs_t * hc_regs,
  75841. + dwc_otg_halt_status_e halt_status)
  75842. +{
  75843. + dwc_otg_hcd_urb_t *urb = NULL;
  75844. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  75845. + dwc_otg_qh_t *qh;
  75846. + dwc_otg_host_dma_desc_t *dma_desc;
  75847. + uint32_t n_bytes, n_desc, i;
  75848. + uint8_t failed = 0, xfer_done;
  75849. +
  75850. + n_desc = 0;
  75851. +
  75852. + qh = hc->qh;
  75853. +
  75854. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  75855. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  75856. + qtd->in_process = 0;
  75857. + }
  75858. + return;
  75859. + }
  75860. +
  75861. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  75862. +
  75863. + urb = qtd->urb;
  75864. +
  75865. + n_bytes = 0;
  75866. + xfer_done = 0;
  75867. +
  75868. + for (i = 0; i < qtd->n_desc; i++) {
  75869. + dma_desc = &qh->desc_list[n_desc];
  75870. +
  75871. + n_bytes = qh->n_bytes[n_desc];
  75872. +
  75873. + failed =
  75874. + update_non_isoc_urb_state_ddma(hcd, hc, qtd,
  75875. + dma_desc,
  75876. + halt_status, n_bytes,
  75877. + &xfer_done);
  75878. +
  75879. + if (failed
  75880. + || (xfer_done
  75881. + && (urb->status != -DWC_E_IN_PROGRESS))) {
  75882. +
  75883. + hcd->fops->complete(hcd, urb->priv, urb,
  75884. + urb->status);
  75885. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  75886. +
  75887. + if (failed)
  75888. + goto stop_scan;
  75889. + } else if (qh->ep_type == UE_CONTROL) {
  75890. + if (qtd->control_phase == DWC_OTG_CONTROL_SETUP) {
  75891. + if (urb->length > 0) {
  75892. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  75893. + } else {
  75894. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  75895. + }
  75896. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
  75897. + } else if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  75898. + if (xfer_done) {
  75899. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  75900. + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
  75901. + } else if (i + 1 == qtd->n_desc) {
  75902. + /*
  75903. + * Last descriptor for Control data stage which is
  75904. + * not completed yet.
  75905. + */
  75906. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75907. + }
  75908. + }
  75909. + }
  75910. +
  75911. + n_desc++;
  75912. + }
  75913. +
  75914. + }
  75915. +
  75916. +stop_scan:
  75917. +
  75918. + if (qh->ep_type != UE_CONTROL) {
  75919. + /*
  75920. + * Resetting the data toggle for bulk
  75921. + * and interrupt endpoints in case of stall. See handle_hc_stall_intr()
  75922. + */
  75923. + if (halt_status == DWC_OTG_HC_XFER_STALL)
  75924. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  75925. + else
  75926. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75927. + }
  75928. +
  75929. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  75930. + hcint_data_t hcint;
  75931. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  75932. + if (hcint.b.nyet) {
  75933. + /*
  75934. + * Got a NYET on the last transaction of the transfer. It
  75935. + * means that the endpoint should be in the PING state at the
  75936. + * beginning of the next transfer.
  75937. + */
  75938. + qh->ping_state = 1;
  75939. + clear_hc_int(hc_regs, nyet);
  75940. + }
  75941. +
  75942. + }
  75943. +
  75944. +}
  75945. +
  75946. +/**
  75947. + * This function is called from interrupt handlers.
  75948. + * Scans the descriptor list, updates URB's status and
  75949. + * calls completion routine for the URB if it's done.
  75950. + * Releases the channel to be used by other transfers.
  75951. + * In case of Isochronous endpoint the channel is not halted until
  75952. + * the end of the session, i.e. QTD list is empty.
  75953. + * If periodic channel released the FrameList is updated accordingly.
  75954. + *
  75955. + * Calls transaction selection routines to activate pending transfers.
  75956. + *
  75957. + * @param hcd The HCD state structure for the DWC OTG controller.
  75958. + * @param hc Host channel, the transfer is completed on.
  75959. + * @param hc_regs Host channel registers.
  75960. + * @param halt_status Reason the channel is being halted,
  75961. + * or just XferComplete for isochronous transfer
  75962. + */
  75963. +void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  75964. + dwc_hc_t * hc,
  75965. + dwc_otg_hc_regs_t * hc_regs,
  75966. + dwc_otg_halt_status_e halt_status)
  75967. +{
  75968. + uint8_t continue_isoc_xfer = 0;
  75969. + dwc_otg_transaction_type_e tr_type;
  75970. + dwc_otg_qh_t *qh = hc->qh;
  75971. +
  75972. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  75973. +
  75974. + complete_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  75975. +
  75976. + /* Release the channel if halted or session completed */
  75977. + if (halt_status != DWC_OTG_HC_XFER_COMPLETE ||
  75978. + DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  75979. +
  75980. + /* Halt the channel if session completed */
  75981. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  75982. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  75983. + }
  75984. +
  75985. + release_channel_ddma(hcd, qh);
  75986. + dwc_otg_hcd_qh_remove(hcd, qh);
  75987. + } else {
  75988. + /* Keep in assigned schedule to continue transfer */
  75989. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  75990. + &qh->qh_list_entry);
  75991. + continue_isoc_xfer = 1;
  75992. +
  75993. + }
  75994. + /** @todo Consider the case when period exceeds FrameList size.
  75995. + * Frame Rollover interrupt should be used.
  75996. + */
  75997. + } else {
  75998. + /* Scan descriptor list to complete the URB(s), then release the channel */
  75999. + complete_non_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  76000. +
  76001. + release_channel_ddma(hcd, qh);
  76002. + dwc_otg_hcd_qh_remove(hcd, qh);
  76003. +
  76004. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  76005. + /* Add back to inactive non-periodic schedule on normal completion */
  76006. + dwc_otg_hcd_qh_add(hcd, qh);
  76007. + }
  76008. +
  76009. + }
  76010. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  76011. + if (tr_type != DWC_OTG_TRANSACTION_NONE || continue_isoc_xfer) {
  76012. + if (continue_isoc_xfer) {
  76013. + if (tr_type == DWC_OTG_TRANSACTION_NONE) {
  76014. + tr_type = DWC_OTG_TRANSACTION_PERIODIC;
  76015. + } else if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC) {
  76016. + tr_type = DWC_OTG_TRANSACTION_ALL;
  76017. + }
  76018. + }
  76019. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  76020. + }
  76021. +}
  76022. +
  76023. +#endif /* DWC_DEVICE_ONLY */
  76024. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  76025. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 1970-01-01 01:00:00.000000000 +0100
  76026. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 2014-04-24 16:04:39.819124254 +0200
  76027. @@ -0,0 +1,862 @@
  76028. +/* ==========================================================================
  76029. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
  76030. + * $Revision: #58 $
  76031. + * $Date: 2011/09/15 $
  76032. + * $Change: 1846647 $
  76033. + *
  76034. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  76035. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  76036. + * otherwise expressly agreed to in writing between Synopsys and you.
  76037. + *
  76038. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  76039. + * any End User Software License Agreement or Agreement for Licensed Product
  76040. + * with Synopsys or any supplement thereto. You are permitted to use and
  76041. + * redistribute this Software in source and binary forms, with or without
  76042. + * modification, provided that redistributions of source code must retain this
  76043. + * notice. You may not view, use, disclose, copy or distribute this file or
  76044. + * any information contained herein except pursuant to this license grant from
  76045. + * Synopsys. If you do not agree with this notice, including the disclaimer
  76046. + * below, then you are not authorized to use the Software.
  76047. + *
  76048. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  76049. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  76050. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76051. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  76052. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  76053. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  76054. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  76055. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  76056. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  76057. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  76058. + * DAMAGE.
  76059. + * ========================================================================== */
  76060. +#ifndef DWC_DEVICE_ONLY
  76061. +#ifndef __DWC_HCD_H__
  76062. +#define __DWC_HCD_H__
  76063. +
  76064. +#include "dwc_otg_os_dep.h"
  76065. +#include "usb.h"
  76066. +#include "dwc_otg_hcd_if.h"
  76067. +#include "dwc_otg_core_if.h"
  76068. +#include "dwc_list.h"
  76069. +#include "dwc_otg_cil.h"
  76070. +#include "dwc_otg_fiq_fsm.h"
  76071. +
  76072. +
  76073. +/**
  76074. + * @file
  76075. + *
  76076. + * This file contains the structures, constants, and interfaces for
  76077. + * the Host Contoller Driver (HCD).
  76078. + *
  76079. + * The Host Controller Driver (HCD) is responsible for translating requests
  76080. + * from the USB Driver into the appropriate actions on the DWC_otg controller.
  76081. + * It isolates the USBD from the specifics of the controller by providing an
  76082. + * API to the USBD.
  76083. + */
  76084. +
  76085. +struct dwc_otg_hcd_pipe_info {
  76086. + uint8_t dev_addr;
  76087. + uint8_t ep_num;
  76088. + uint8_t pipe_type;
  76089. + uint8_t pipe_dir;
  76090. + uint16_t mps;
  76091. +};
  76092. +
  76093. +struct dwc_otg_hcd_iso_packet_desc {
  76094. + uint32_t offset;
  76095. + uint32_t length;
  76096. + uint32_t actual_length;
  76097. + uint32_t status;
  76098. +};
  76099. +
  76100. +struct dwc_otg_qtd;
  76101. +
  76102. +struct dwc_otg_hcd_urb {
  76103. + void *priv;
  76104. + struct dwc_otg_qtd *qtd;
  76105. + void *buf;
  76106. + dwc_dma_t dma;
  76107. + void *setup_packet;
  76108. + dwc_dma_t setup_dma;
  76109. + uint32_t length;
  76110. + uint32_t actual_length;
  76111. + uint32_t status;
  76112. + uint32_t error_count;
  76113. + uint32_t packet_count;
  76114. + uint32_t flags;
  76115. + uint16_t interval;
  76116. + struct dwc_otg_hcd_pipe_info pipe_info;
  76117. + struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
  76118. +};
  76119. +
  76120. +static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
  76121. +{
  76122. + return pipe->ep_num;
  76123. +}
  76124. +
  76125. +static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
  76126. + *pipe)
  76127. +{
  76128. + return pipe->pipe_type;
  76129. +}
  76130. +
  76131. +static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
  76132. +{
  76133. + return pipe->mps;
  76134. +}
  76135. +
  76136. +static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
  76137. + *pipe)
  76138. +{
  76139. + return pipe->dev_addr;
  76140. +}
  76141. +
  76142. +static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
  76143. + *pipe)
  76144. +{
  76145. + return (pipe->pipe_type == UE_ISOCHRONOUS);
  76146. +}
  76147. +
  76148. +static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
  76149. + *pipe)
  76150. +{
  76151. + return (pipe->pipe_type == UE_INTERRUPT);
  76152. +}
  76153. +
  76154. +static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
  76155. + *pipe)
  76156. +{
  76157. + return (pipe->pipe_type == UE_BULK);
  76158. +}
  76159. +
  76160. +static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
  76161. + *pipe)
  76162. +{
  76163. + return (pipe->pipe_type == UE_CONTROL);
  76164. +}
  76165. +
  76166. +static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
  76167. +{
  76168. + return (pipe->pipe_dir == UE_DIR_IN);
  76169. +}
  76170. +
  76171. +static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
  76172. + *pipe)
  76173. +{
  76174. + return (!dwc_otg_hcd_is_pipe_in(pipe));
  76175. +}
  76176. +
  76177. +static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
  76178. + uint8_t devaddr, uint8_t ep_num,
  76179. + uint8_t pipe_type, uint8_t pipe_dir,
  76180. + uint16_t mps)
  76181. +{
  76182. + pipe->dev_addr = devaddr;
  76183. + pipe->ep_num = ep_num;
  76184. + pipe->pipe_type = pipe_type;
  76185. + pipe->pipe_dir = pipe_dir;
  76186. + pipe->mps = mps;
  76187. +}
  76188. +
  76189. +/**
  76190. + * Phases for control transfers.
  76191. + */
  76192. +typedef enum dwc_otg_control_phase {
  76193. + DWC_OTG_CONTROL_SETUP,
  76194. + DWC_OTG_CONTROL_DATA,
  76195. + DWC_OTG_CONTROL_STATUS
  76196. +} dwc_otg_control_phase_e;
  76197. +
  76198. +/** Transaction types. */
  76199. +typedef enum dwc_otg_transaction_type {
  76200. + DWC_OTG_TRANSACTION_NONE = 0,
  76201. + DWC_OTG_TRANSACTION_PERIODIC = 1,
  76202. + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
  76203. + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
  76204. +} dwc_otg_transaction_type_e;
  76205. +
  76206. +struct dwc_otg_qh;
  76207. +
  76208. +/**
  76209. + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
  76210. + * interrupt, or isochronous transfer. A single QTD is created for each URB
  76211. + * (of one of these types) submitted to the HCD. The transfer associated with
  76212. + * a QTD may require one or multiple transactions.
  76213. + *
  76214. + * A QTD is linked to a Queue Head, which is entered in either the
  76215. + * non-periodic or periodic schedule for execution. When a QTD is chosen for
  76216. + * execution, some or all of its transactions may be executed. After
  76217. + * execution, the state of the QTD is updated. The QTD may be retired if all
  76218. + * its transactions are complete or if an error occurred. Otherwise, it
  76219. + * remains in the schedule so more transactions can be executed later.
  76220. + */
  76221. +typedef struct dwc_otg_qtd {
  76222. + /**
  76223. + * Determines the PID of the next data packet for the data phase of
  76224. + * control transfers. Ignored for other transfer types.<br>
  76225. + * One of the following values:
  76226. + * - DWC_OTG_HC_PID_DATA0
  76227. + * - DWC_OTG_HC_PID_DATA1
  76228. + */
  76229. + uint8_t data_toggle;
  76230. +
  76231. + /** Current phase for control transfers (Setup, Data, or Status). */
  76232. + dwc_otg_control_phase_e control_phase;
  76233. +
  76234. + /** Keep track of the current split type
  76235. + * for FS/LS endpoints on a HS Hub */
  76236. + uint8_t complete_split;
  76237. +
  76238. + /** How many bytes transferred during SSPLIT OUT */
  76239. + uint32_t ssplit_out_xfer_count;
  76240. +
  76241. + /**
  76242. + * Holds the number of bus errors that have occurred for a transaction
  76243. + * within this transfer.
  76244. + */
  76245. + uint8_t error_count;
  76246. +
  76247. + /**
  76248. + * Index of the next frame descriptor for an isochronous transfer. A
  76249. + * frame descriptor describes the buffer position and length of the
  76250. + * data to be transferred in the next scheduled (micro)frame of an
  76251. + * isochronous transfer. It also holds status for that transaction.
  76252. + * The frame index starts at 0.
  76253. + */
  76254. + uint16_t isoc_frame_index;
  76255. +
  76256. + /** Position of the ISOC split on full/low speed */
  76257. + uint8_t isoc_split_pos;
  76258. +
  76259. + /** Position of the ISOC split in the buffer for the current frame */
  76260. + uint16_t isoc_split_offset;
  76261. +
  76262. + /** URB for this transfer */
  76263. + struct dwc_otg_hcd_urb *urb;
  76264. +
  76265. + struct dwc_otg_qh *qh;
  76266. +
  76267. + /** This list of QTDs */
  76268. + DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
  76269. +
  76270. + /** Indicates if this QTD is currently processed by HW. */
  76271. + uint8_t in_process;
  76272. +
  76273. + /** Number of DMA descriptors for this QTD */
  76274. + uint8_t n_desc;
  76275. +
  76276. + /**
  76277. + * Last activated frame(packet) index.
  76278. + * Used in Descriptor DMA mode only.
  76279. + */
  76280. + uint16_t isoc_frame_index_last;
  76281. +
  76282. +} dwc_otg_qtd_t;
  76283. +
  76284. +DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
  76285. +
  76286. +/**
  76287. + * A Queue Head (QH) holds the static characteristics of an endpoint and
  76288. + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
  76289. + * be entered in either the non-periodic or periodic schedule.
  76290. + */
  76291. +typedef struct dwc_otg_qh {
  76292. + /**
  76293. + * Endpoint type.
  76294. + * One of the following values:
  76295. + * - UE_CONTROL
  76296. + * - UE_BULK
  76297. + * - UE_INTERRUPT
  76298. + * - UE_ISOCHRONOUS
  76299. + */
  76300. + uint8_t ep_type;
  76301. + uint8_t ep_is_in;
  76302. +
  76303. + /** wMaxPacketSize Field of Endpoint Descriptor. */
  76304. + uint16_t maxp;
  76305. +
  76306. + /**
  76307. + * Device speed.
  76308. + * One of the following values:
  76309. + * - DWC_OTG_EP_SPEED_LOW
  76310. + * - DWC_OTG_EP_SPEED_FULL
  76311. + * - DWC_OTG_EP_SPEED_HIGH
  76312. + */
  76313. + uint8_t dev_speed;
  76314. +
  76315. + /**
  76316. + * Determines the PID of the next data packet for non-control
  76317. + * transfers. Ignored for control transfers.<br>
  76318. + * One of the following values:
  76319. + * - DWC_OTG_HC_PID_DATA0
  76320. + * - DWC_OTG_HC_PID_DATA1
  76321. + */
  76322. + uint8_t data_toggle;
  76323. +
  76324. + /** Ping state if 1. */
  76325. + uint8_t ping_state;
  76326. +
  76327. + /**
  76328. + * List of QTDs for this QH.
  76329. + */
  76330. + struct dwc_otg_qtd_list qtd_list;
  76331. +
  76332. + /** Host channel currently processing transfers for this QH. */
  76333. + struct dwc_hc *channel;
  76334. +
  76335. + /** Full/low speed endpoint on high-speed hub requires split. */
  76336. + uint8_t do_split;
  76337. +
  76338. + /** @name Periodic schedule information */
  76339. + /** @{ */
  76340. +
  76341. + /** Bandwidth in microseconds per (micro)frame. */
  76342. + uint16_t usecs;
  76343. +
  76344. + /** Interval between transfers in (micro)frames. */
  76345. + uint16_t interval;
  76346. +
  76347. + /**
  76348. + * (micro)frame to initialize a periodic transfer. The transfer
  76349. + * executes in the following (micro)frame.
  76350. + */
  76351. + uint16_t sched_frame;
  76352. +
  76353. + /*
  76354. + ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
  76355. + */
  76356. + uint16_t nak_frame;
  76357. +
  76358. + /** (micro)frame at which last start split was initialized. */
  76359. + uint16_t start_split_frame;
  76360. +
  76361. + /** @} */
  76362. +
  76363. + /**
  76364. + * Used instead of original buffer if
  76365. + * it(physical address) is not dword-aligned.
  76366. + */
  76367. + uint8_t *dw_align_buf;
  76368. + dwc_dma_t dw_align_buf_dma;
  76369. +
  76370. + /** Entry for QH in either the periodic or non-periodic schedule. */
  76371. + dwc_list_link_t qh_list_entry;
  76372. +
  76373. + /** @name Descriptor DMA support */
  76374. + /** @{ */
  76375. +
  76376. + /** Descriptor List. */
  76377. + dwc_otg_host_dma_desc_t *desc_list;
  76378. +
  76379. + /** Descriptor List physical address. */
  76380. + dwc_dma_t desc_list_dma;
  76381. +
  76382. + /**
  76383. + * Xfer Bytes array.
  76384. + * Each element corresponds to a descriptor and indicates
  76385. + * original XferSize size value for the descriptor.
  76386. + */
  76387. + uint32_t *n_bytes;
  76388. +
  76389. + /** Actual number of transfer descriptors in a list. */
  76390. + uint16_t ntd;
  76391. +
  76392. + /** First activated isochronous transfer descriptor index. */
  76393. + uint8_t td_first;
  76394. + /** Last activated isochronous transfer descriptor index. */
  76395. + uint8_t td_last;
  76396. +
  76397. + /** @} */
  76398. +
  76399. +
  76400. + uint16_t speed;
  76401. + uint16_t frame_usecs[8];
  76402. +
  76403. + uint32_t skip_count;
  76404. +} dwc_otg_qh_t;
  76405. +
  76406. +DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
  76407. +
  76408. +typedef struct urb_tq_entry {
  76409. + struct urb *urb;
  76410. + DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
  76411. +} urb_tq_entry_t;
  76412. +
  76413. +DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
  76414. +
  76415. +/**
  76416. + * This structure holds the state of the HCD, including the non-periodic and
  76417. + * periodic schedules.
  76418. + */
  76419. +struct dwc_otg_hcd {
  76420. + /** The DWC otg device pointer */
  76421. + struct dwc_otg_device *otg_dev;
  76422. + /** DWC OTG Core Interface Layer */
  76423. + dwc_otg_core_if_t *core_if;
  76424. +
  76425. + /** Function HCD driver callbacks */
  76426. + struct dwc_otg_hcd_function_ops *fops;
  76427. +
  76428. + /** Internal DWC HCD Flags */
  76429. + volatile union dwc_otg_hcd_internal_flags {
  76430. + uint32_t d32;
  76431. + struct {
  76432. + unsigned port_connect_status_change:1;
  76433. + unsigned port_connect_status:1;
  76434. + unsigned port_reset_change:1;
  76435. + unsigned port_enable_change:1;
  76436. + unsigned port_suspend_change:1;
  76437. + unsigned port_over_current_change:1;
  76438. + unsigned port_l1_change:1;
  76439. + unsigned reserved:26;
  76440. + } b;
  76441. + } flags;
  76442. +
  76443. + /**
  76444. + * Inactive items in the non-periodic schedule. This is a list of
  76445. + * Queue Heads. Transfers associated with these Queue Heads are not
  76446. + * currently assigned to a host channel.
  76447. + */
  76448. + dwc_list_link_t non_periodic_sched_inactive;
  76449. +
  76450. + /**
  76451. + * Active items in the non-periodic schedule. This is a list of
  76452. + * Queue Heads. Transfers associated with these Queue Heads are
  76453. + * currently assigned to a host channel.
  76454. + */
  76455. + dwc_list_link_t non_periodic_sched_active;
  76456. +
  76457. + /**
  76458. + * Pointer to the next Queue Head to process in the active
  76459. + * non-periodic schedule.
  76460. + */
  76461. + dwc_list_link_t *non_periodic_qh_ptr;
  76462. +
  76463. + /**
  76464. + * Inactive items in the periodic schedule. This is a list of QHs for
  76465. + * periodic transfers that are _not_ scheduled for the next frame.
  76466. + * Each QH in the list has an interval counter that determines when it
  76467. + * needs to be scheduled for execution. This scheduling mechanism
  76468. + * allows only a simple calculation for periodic bandwidth used (i.e.
  76469. + * must assume that all periodic transfers may need to execute in the
  76470. + * same frame). However, it greatly simplifies scheduling and should
  76471. + * be sufficient for the vast majority of OTG hosts, which need to
  76472. + * connect to a small number of peripherals at one time.
  76473. + *
  76474. + * Items move from this list to periodic_sched_ready when the QH
  76475. + * interval counter is 0 at SOF.
  76476. + */
  76477. + dwc_list_link_t periodic_sched_inactive;
  76478. +
  76479. + /**
  76480. + * List of periodic QHs that are ready for execution in the next
  76481. + * frame, but have not yet been assigned to host channels.
  76482. + *
  76483. + * Items move from this list to periodic_sched_assigned as host
  76484. + * channels become available during the current frame.
  76485. + */
  76486. + dwc_list_link_t periodic_sched_ready;
  76487. +
  76488. + /**
  76489. + * List of periodic QHs to be executed in the next frame that are
  76490. + * assigned to host channels.
  76491. + *
  76492. + * Items move from this list to periodic_sched_queued as the
  76493. + * transactions for the QH are queued to the DWC_otg controller.
  76494. + */
  76495. + dwc_list_link_t periodic_sched_assigned;
  76496. +
  76497. + /**
  76498. + * List of periodic QHs that have been queued for execution.
  76499. + *
  76500. + * Items move from this list to either periodic_sched_inactive or
  76501. + * periodic_sched_ready when the channel associated with the transfer
  76502. + * is released. If the interval for the QH is 1, the item moves to
  76503. + * periodic_sched_ready because it must be rescheduled for the next
  76504. + * frame. Otherwise, the item moves to periodic_sched_inactive.
  76505. + */
  76506. + dwc_list_link_t periodic_sched_queued;
  76507. +
  76508. + /**
  76509. + * Total bandwidth claimed so far for periodic transfers. This value
  76510. + * is in microseconds per (micro)frame. The assumption is that all
  76511. + * periodic transfers may occur in the same (micro)frame.
  76512. + */
  76513. + uint16_t periodic_usecs;
  76514. +
  76515. + /**
  76516. + * Total bandwidth claimed so far for all periodic transfers
  76517. + * in a frame.
  76518. + * This will include a mixture of HS and FS transfers.
  76519. + * Units are microseconds per (micro)frame.
  76520. + * We have a budget per frame and have to schedule
  76521. + * transactions accordingly.
  76522. + * Watch out for the fact that things are actually scheduled for the
  76523. + * "next frame".
  76524. + */
  76525. + uint16_t frame_usecs[8];
  76526. +
  76527. +
  76528. + /**
  76529. + * Frame number read from the core at SOF. The value ranges from 0 to
  76530. + * DWC_HFNUM_MAX_FRNUM.
  76531. + */
  76532. + uint16_t frame_number;
  76533. +
  76534. + /**
  76535. + * Count of periodic QHs, if using several eps. For SOF enable/disable.
  76536. + */
  76537. + uint16_t periodic_qh_count;
  76538. +
  76539. + /**
  76540. + * Free host channels in the controller. This is a list of
  76541. + * dwc_hc_t items.
  76542. + */
  76543. + struct hc_list free_hc_list;
  76544. + /**
  76545. + * Number of host channels assigned to periodic transfers. Currently
  76546. + * assuming that there is a dedicated host channel for each periodic
  76547. + * transaction and at least one host channel available for
  76548. + * non-periodic transactions.
  76549. + */
  76550. + int periodic_channels; /* microframe_schedule==0 */
  76551. +
  76552. + /**
  76553. + * Number of host channels assigned to non-periodic transfers.
  76554. + */
  76555. + int non_periodic_channels; /* microframe_schedule==0 */
  76556. +
  76557. + /**
  76558. + * Number of host channels assigned to non-periodic transfers.
  76559. + */
  76560. + int available_host_channels;
  76561. +
  76562. + /**
  76563. + * Array of pointers to the host channel descriptors. Allows accessing
  76564. + * a host channel descriptor given the host channel number. This is
  76565. + * useful in interrupt handlers.
  76566. + */
  76567. + struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
  76568. +
  76569. + /**
  76570. + * Buffer to use for any data received during the status phase of a
  76571. + * control transfer. Normally no data is transferred during the status
  76572. + * phase. This buffer is used as a bit bucket.
  76573. + */
  76574. + uint8_t *status_buf;
  76575. +
  76576. + /**
  76577. + * DMA address for status_buf.
  76578. + */
  76579. + dma_addr_t status_buf_dma;
  76580. +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
  76581. +
  76582. + /**
  76583. + * Connection timer. An OTG host must display a message if the device
  76584. + * does not connect. Started when the VBus power is turned on via
  76585. + * sysfs attribute "buspower".
  76586. + */
  76587. + dwc_timer_t *conn_timer;
  76588. +
  76589. + /* Tasket to do a reset */
  76590. + dwc_tasklet_t *reset_tasklet;
  76591. +
  76592. + dwc_tasklet_t *completion_tasklet;
  76593. + struct urb_list completed_urb_list;
  76594. +
  76595. + /* */
  76596. + dwc_spinlock_t *lock;
  76597. + dwc_spinlock_t *channel_lock;
  76598. + /**
  76599. + * Private data that could be used by OS wrapper.
  76600. + */
  76601. + void *priv;
  76602. +
  76603. + uint8_t otg_port;
  76604. +
  76605. + /** Frame List */
  76606. + uint32_t *frame_list;
  76607. +
  76608. + /** Hub - Port assignment */
  76609. + int hub_port[128];
  76610. +#ifdef FIQ_DEBUG
  76611. + int hub_port_alloc[2048];
  76612. +#endif
  76613. +
  76614. + /** Frame List DMA address */
  76615. + dma_addr_t frame_list_dma;
  76616. +
  76617. + struct fiq_stack *fiq_stack;
  76618. + struct fiq_state *fiq_state;
  76619. +
  76620. + /** Virtual address for split transaction DMA bounce buffers */
  76621. + struct fiq_dma_blob *fiq_dmab;
  76622. +
  76623. +#ifdef DEBUG
  76624. + uint32_t frrem_samples;
  76625. + uint64_t frrem_accum;
  76626. +
  76627. + uint32_t hfnum_7_samples_a;
  76628. + uint64_t hfnum_7_frrem_accum_a;
  76629. + uint32_t hfnum_0_samples_a;
  76630. + uint64_t hfnum_0_frrem_accum_a;
  76631. + uint32_t hfnum_other_samples_a;
  76632. + uint64_t hfnum_other_frrem_accum_a;
  76633. +
  76634. + uint32_t hfnum_7_samples_b;
  76635. + uint64_t hfnum_7_frrem_accum_b;
  76636. + uint32_t hfnum_0_samples_b;
  76637. + uint64_t hfnum_0_frrem_accum_b;
  76638. + uint32_t hfnum_other_samples_b;
  76639. + uint64_t hfnum_other_frrem_accum_b;
  76640. +#endif
  76641. +};
  76642. +
  76643. +/** @name Transaction Execution Functions */
  76644. +/** @{ */
  76645. +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
  76646. + * hcd);
  76647. +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  76648. + dwc_otg_transaction_type_e tr_type);
  76649. +
  76650. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  76651. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  76652. +
  76653. +extern int fiq_fsm_queue_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
  76654. +extern int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh);
  76655. +extern void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num);
  76656. +
  76657. +/** @} */
  76658. +
  76659. +/** @name Interrupt Handler Functions */
  76660. +/** @{ */
  76661. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76662. +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76663. +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
  76664. + dwc_otg_hcd);
  76665. +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
  76666. + dwc_otg_hcd);
  76667. +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
  76668. + dwc_otg_hcd);
  76669. +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
  76670. + dwc_otg_hcd);
  76671. +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76672. +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
  76673. + dwc_otg_hcd);
  76674. +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76675. +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76676. +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
  76677. + uint32_t num);
  76678. +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76679. +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
  76680. + dwc_otg_hcd);
  76681. +/** @} */
  76682. +
  76683. +/** @name Schedule Queue Functions */
  76684. +/** @{ */
  76685. +
  76686. +/* Implemented in dwc_otg_hcd_queue.c */
  76687. +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  76688. + dwc_otg_hcd_urb_t * urb, int atomic_alloc);
  76689. +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  76690. +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  76691. +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  76692. +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  76693. + int sched_csplit);
  76694. +
  76695. +/** Remove and free a QH */
  76696. +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
  76697. + dwc_otg_qh_t * qh)
  76698. +{
  76699. + dwc_irqflags_t flags;
  76700. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  76701. + dwc_otg_hcd_qh_remove(hcd, qh);
  76702. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  76703. + dwc_otg_hcd_qh_free(hcd, qh);
  76704. +}
  76705. +
  76706. +/** Allocates memory for a QH structure.
  76707. + * @return Returns the memory allocate or NULL on error. */
  76708. +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
  76709. +{
  76710. + if (atomic_alloc)
  76711. + return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
  76712. + else
  76713. + return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
  76714. +}
  76715. +
  76716. +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
  76717. + int atomic_alloc);
  76718. +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
  76719. +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
  76720. + dwc_otg_qh_t ** qh, int atomic_alloc);
  76721. +
  76722. +/** Allocates memory for a QTD structure.
  76723. + * @return Returns the memory allocate or NULL on error. */
  76724. +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
  76725. +{
  76726. + if (atomic_alloc)
  76727. + return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
  76728. + else
  76729. + return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
  76730. +}
  76731. +
  76732. +/** Frees the memory for a QTD structure. QTD should already be removed from
  76733. + * list.
  76734. + * @param qtd QTD to free.*/
  76735. +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
  76736. +{
  76737. + DWC_FREE(qtd);
  76738. +}
  76739. +
  76740. +/** Removes a QTD from list.
  76741. + * @param hcd HCD instance.
  76742. + * @param qtd QTD to remove from list.
  76743. + * @param qh QTD belongs to.
  76744. + */
  76745. +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
  76746. + dwc_otg_qtd_t * qtd,
  76747. + dwc_otg_qh_t * qh)
  76748. +{
  76749. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  76750. +}
  76751. +
  76752. +/** Remove and free a QTD
  76753. + * Need to disable IRQ and hold hcd lock while calling this function out of
  76754. + * interrupt servicing chain */
  76755. +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
  76756. + dwc_otg_qtd_t * qtd,
  76757. + dwc_otg_qh_t * qh)
  76758. +{
  76759. + dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
  76760. + dwc_otg_hcd_qtd_free(qtd);
  76761. +}
  76762. +
  76763. +/** @} */
  76764. +
  76765. +/** @name Descriptor DMA Supporting Functions */
  76766. +/** @{ */
  76767. +
  76768. +extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  76769. +extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  76770. + dwc_hc_t * hc,
  76771. + dwc_otg_hc_regs_t * hc_regs,
  76772. + dwc_otg_halt_status_e halt_status);
  76773. +
  76774. +extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  76775. +extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  76776. +
  76777. +/** @} */
  76778. +
  76779. +/** @name Internal Functions */
  76780. +/** @{ */
  76781. +dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
  76782. +/** @} */
  76783. +
  76784. +#ifdef CONFIG_USB_DWC_OTG_LPM
  76785. +extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
  76786. + uint8_t devaddr);
  76787. +extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
  76788. +#endif
  76789. +
  76790. +/** Gets the QH that contains the list_head */
  76791. +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
  76792. +
  76793. +/** Gets the QTD that contains the list_head */
  76794. +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
  76795. +
  76796. +/** Check if QH is non-periodic */
  76797. +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
  76798. + (_qh_ptr_->ep_type == UE_CONTROL))
  76799. +
  76800. +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
  76801. +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
  76802. +
  76803. +/** Packet size for any kind of endpoint descriptor */
  76804. +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
  76805. +
  76806. +/**
  76807. + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
  76808. + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
  76809. + * frame number when the max frame number is reached.
  76810. + */
  76811. +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
  76812. +{
  76813. + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
  76814. + (DWC_HFNUM_MAX_FRNUM >> 1);
  76815. +}
  76816. +
  76817. +/**
  76818. + * Returns true if _frame1 is greater than _frame2. The comparison is done
  76819. + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
  76820. + * number when the max frame number is reached.
  76821. + */
  76822. +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
  76823. +{
  76824. + return (frame1 != frame2) &&
  76825. + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
  76826. + (DWC_HFNUM_MAX_FRNUM >> 1));
  76827. +}
  76828. +
  76829. +/**
  76830. + * Increments _frame by the amount specified by _inc. The addition is done
  76831. + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
  76832. + */
  76833. +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
  76834. +{
  76835. + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
  76836. +}
  76837. +
  76838. +static inline uint16_t dwc_full_frame_num(uint16_t frame)
  76839. +{
  76840. + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
  76841. +}
  76842. +
  76843. +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
  76844. +{
  76845. + return frame & 0x7;
  76846. +}
  76847. +
  76848. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  76849. + dwc_otg_hc_regs_t * hc_regs,
  76850. + dwc_otg_qtd_t * qtd);
  76851. +
  76852. +#ifdef DEBUG
  76853. +/**
  76854. + * Macro to sample the remaining PHY clocks left in the current frame. This
  76855. + * may be used during debugging to determine the average time it takes to
  76856. + * execute sections of code. There are two possible sample points, "a" and
  76857. + * "b", so the _letter argument must be one of these values.
  76858. + *
  76859. + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
  76860. + * example, "cat /sys/devices/lm0/hcd_frrem".
  76861. + */
  76862. +#define dwc_sample_frrem(_hcd, _qh, _letter) \
  76863. +{ \
  76864. + hfnum_data_t hfnum; \
  76865. + dwc_otg_qtd_t *qtd; \
  76866. + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
  76867. + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
  76868. + hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
  76869. + switch (hfnum.b.frnum & 0x7) { \
  76870. + case 7: \
  76871. + _hcd->hfnum_7_samples_##_letter++; \
  76872. + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
  76873. + break; \
  76874. + case 0: \
  76875. + _hcd->hfnum_0_samples_##_letter++; \
  76876. + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
  76877. + break; \
  76878. + default: \
  76879. + _hcd->hfnum_other_samples_##_letter++; \
  76880. + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
  76881. + break; \
  76882. + } \
  76883. + } \
  76884. +}
  76885. +#else
  76886. +#define dwc_sample_frrem(_hcd, _qh, _letter)
  76887. +#endif
  76888. +#endif
  76889. +#endif /* DWC_DEVICE_ONLY */
  76890. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
  76891. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 1970-01-01 01:00:00.000000000 +0100
  76892. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 2014-04-24 16:04:39.819124254 +0200
  76893. @@ -0,0 +1,417 @@
  76894. +/* ==========================================================================
  76895. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  76896. + * $Revision: #12 $
  76897. + * $Date: 2011/10/26 $
  76898. + * $Change: 1873028 $
  76899. + *
  76900. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  76901. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  76902. + * otherwise expressly agreed to in writing between Synopsys and you.
  76903. + *
  76904. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  76905. + * any End User Software License Agreement or Agreement for Licensed Product
  76906. + * with Synopsys or any supplement thereto. You are permitted to use and
  76907. + * redistribute this Software in source and binary forms, with or without
  76908. + * modification, provided that redistributions of source code must retain this
  76909. + * notice. You may not view, use, disclose, copy or distribute this file or
  76910. + * any information contained herein except pursuant to this license grant from
  76911. + * Synopsys. If you do not agree with this notice, including the disclaimer
  76912. + * below, then you are not authorized to use the Software.
  76913. + *
  76914. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  76915. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  76916. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76917. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  76918. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  76919. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  76920. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  76921. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  76922. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  76923. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  76924. + * DAMAGE.
  76925. + * ========================================================================== */
  76926. +#ifndef DWC_DEVICE_ONLY
  76927. +#ifndef __DWC_HCD_IF_H__
  76928. +#define __DWC_HCD_IF_H__
  76929. +
  76930. +#include "dwc_otg_core_if.h"
  76931. +
  76932. +/** @file
  76933. + * This file defines DWC_OTG HCD Core API.
  76934. + */
  76935. +
  76936. +struct dwc_otg_hcd;
  76937. +typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  76938. +
  76939. +struct dwc_otg_hcd_urb;
  76940. +typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  76941. +
  76942. +/** @name HCD Function Driver Callbacks */
  76943. +/** @{ */
  76944. +
  76945. +/** This function is called whenever core switches to host mode. */
  76946. +typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  76947. +
  76948. +/** This function is called when device has been disconnected */
  76949. +typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  76950. +
  76951. +/** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  76952. +typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  76953. + void *urb_handle,
  76954. + uint32_t * hub_addr,
  76955. + uint32_t * port_addr);
  76956. +/** Via this function HCD core gets device speed */
  76957. +typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  76958. + void *urb_handle);
  76959. +
  76960. +/** This function is called when urb is completed */
  76961. +typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  76962. + void *urb_handle,
  76963. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  76964. + int32_t status);
  76965. +
  76966. +/** Via this function HCD core gets b_hnp_enable parameter */
  76967. +typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  76968. +
  76969. +struct dwc_otg_hcd_function_ops {
  76970. + dwc_otg_hcd_start_cb_t start;
  76971. + dwc_otg_hcd_disconnect_cb_t disconnect;
  76972. + dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  76973. + dwc_otg_hcd_speed_from_urb_cb_t speed;
  76974. + dwc_otg_hcd_complete_urb_cb_t complete;
  76975. + dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  76976. +};
  76977. +/** @} */
  76978. +
  76979. +/** @name HCD Core API */
  76980. +/** @{ */
  76981. +/** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  76982. +extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  76983. +
  76984. +/** This function should be called to initiate HCD Core.
  76985. + *
  76986. + * @param hcd The HCD
  76987. + * @param core_if The DWC_OTG Core
  76988. + *
  76989. + * Returns -DWC_E_NO_MEMORY if no enough memory.
  76990. + * Returns 0 on success
  76991. + */
  76992. +extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  76993. +
  76994. +/** Frees HCD
  76995. + *
  76996. + * @param hcd The HCD
  76997. + */
  76998. +extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  76999. +
  77000. +/** This function should be called on every hardware interrupt.
  77001. + *
  77002. + * @param dwc_otg_hcd The HCD
  77003. + *
  77004. + * Returns non zero if interrupt is handled
  77005. + * Return 0 if interrupt is not handled
  77006. + */
  77007. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  77008. +
  77009. +/** This function is used to handle the fast interrupt
  77010. + *
  77011. + */
  77012. +extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
  77013. +
  77014. +/**
  77015. + * Returns private data set by
  77016. + * dwc_otg_hcd_set_priv_data function.
  77017. + *
  77018. + * @param hcd The HCD
  77019. + */
  77020. +extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  77021. +
  77022. +/**
  77023. + * Set private data.
  77024. + *
  77025. + * @param hcd The HCD
  77026. + * @param priv_data pointer to be stored in private data
  77027. + */
  77028. +extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  77029. +
  77030. +/**
  77031. + * This function initializes the HCD Core.
  77032. + *
  77033. + * @param hcd The HCD
  77034. + * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  77035. + *
  77036. + * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  77037. + * Returns 0 on success
  77038. + */
  77039. +extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  77040. + struct dwc_otg_hcd_function_ops *fops);
  77041. +
  77042. +/**
  77043. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  77044. + * stopped.
  77045. + *
  77046. + * @param hcd The HCD
  77047. + */
  77048. +extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  77049. +
  77050. +/**
  77051. + * Handles hub class-specific requests.
  77052. + *
  77053. + * @param dwc_otg_hcd The HCD
  77054. + * @param typeReq Request Type
  77055. + * @param wValue wValue from control request
  77056. + * @param wIndex wIndex from control request
  77057. + * @param buf data buffer
  77058. + * @param wLength data buffer length
  77059. + *
  77060. + * Returns -DWC_E_INVALID if invalid argument is passed
  77061. + * Returns 0 on success
  77062. + */
  77063. +extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  77064. + uint16_t typeReq, uint16_t wValue,
  77065. + uint16_t wIndex, uint8_t * buf,
  77066. + uint16_t wLength);
  77067. +
  77068. +/**
  77069. + * Returns otg port number.
  77070. + *
  77071. + * @param hcd The HCD
  77072. + */
  77073. +extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  77074. +
  77075. +/**
  77076. + * Returns OTG version - either 1.3 or 2.0.
  77077. + *
  77078. + * @param core_if The core_if structure pointer
  77079. + */
  77080. +extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  77081. +
  77082. +/**
  77083. + * Returns 1 if currently core is acting as B host, and 0 otherwise.
  77084. + *
  77085. + * @param hcd The HCD
  77086. + */
  77087. +extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  77088. +
  77089. +/**
  77090. + * Returns current frame number.
  77091. + *
  77092. + * @param hcd The HCD
  77093. + */
  77094. +extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  77095. +
  77096. +/**
  77097. + * Dumps hcd state.
  77098. + *
  77099. + * @param hcd The HCD
  77100. + */
  77101. +extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  77102. +
  77103. +/**
  77104. + * Dump the average frame remaining at SOF. This can be used to
  77105. + * determine average interrupt latency. Frame remaining is also shown for
  77106. + * start transfer and two additional sample points.
  77107. + * Currently this function is not implemented.
  77108. + *
  77109. + * @param hcd The HCD
  77110. + */
  77111. +extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  77112. +
  77113. +/**
  77114. + * Sends LPM transaction to the local device.
  77115. + *
  77116. + * @param hcd The HCD
  77117. + * @param devaddr Device Address
  77118. + * @param hird Host initiated resume duration
  77119. + * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  77120. + *
  77121. + * Returns negative value if sending LPM transaction was not succeeded.
  77122. + * Returns 0 on success.
  77123. + */
  77124. +extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  77125. + uint8_t hird, uint8_t bRemoteWake);
  77126. +
  77127. +/* URB interface */
  77128. +
  77129. +/**
  77130. + * Allocates memory for dwc_otg_hcd_urb structure.
  77131. + * Allocated memory should be freed by call of DWC_FREE.
  77132. + *
  77133. + * @param hcd The HCD
  77134. + * @param iso_desc_count Count of ISOC descriptors
  77135. + * @param atomic_alloc Specefies whether to perform atomic allocation.
  77136. + */
  77137. +extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  77138. + int iso_desc_count,
  77139. + int atomic_alloc);
  77140. +
  77141. +/**
  77142. + * Set pipe information in URB.
  77143. + *
  77144. + * @param hcd_urb DWC_OTG URB
  77145. + * @param devaddr Device Address
  77146. + * @param ep_num Endpoint Number
  77147. + * @param ep_type Endpoint Type
  77148. + * @param ep_dir Endpoint Direction
  77149. + * @param mps Max Packet Size
  77150. + */
  77151. +extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  77152. + uint8_t devaddr, uint8_t ep_num,
  77153. + uint8_t ep_type, uint8_t ep_dir,
  77154. + uint16_t mps);
  77155. +
  77156. +/* Transfer flags */
  77157. +#define URB_GIVEBACK_ASAP 0x1
  77158. +#define URB_SEND_ZERO_PACKET 0x2
  77159. +
  77160. +/**
  77161. + * Sets dwc_otg_hcd_urb parameters.
  77162. + *
  77163. + * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  77164. + * @param urb_handle Unique handle for request, this will be passed back
  77165. + * to function driver in completion callback.
  77166. + * @param buf The buffer for the data
  77167. + * @param dma The DMA buffer for the data
  77168. + * @param buflen Transfer length
  77169. + * @param sp Buffer for setup data
  77170. + * @param sp_dma DMA address of setup data buffer
  77171. + * @param flags Transfer flags
  77172. + * @param interval Polling interval for interrupt or isochronous transfers.
  77173. + */
  77174. +extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  77175. + void *urb_handle, void *buf,
  77176. + dwc_dma_t dma, uint32_t buflen, void *sp,
  77177. + dwc_dma_t sp_dma, uint32_t flags,
  77178. + uint16_t interval);
  77179. +
  77180. +/** Gets status from dwc_otg_hcd_urb
  77181. + *
  77182. + * @param dwc_otg_urb DWC_OTG URB
  77183. + */
  77184. +extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  77185. +
  77186. +/** Gets actual length from dwc_otg_hcd_urb
  77187. + *
  77188. + * @param dwc_otg_urb DWC_OTG URB
  77189. + */
  77190. +extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  77191. + dwc_otg_urb);
  77192. +
  77193. +/** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  77194. + *
  77195. + * @param dwc_otg_urb DWC_OTG URB
  77196. + */
  77197. +extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  77198. + dwc_otg_urb);
  77199. +
  77200. +/** Set ISOC descriptor offset and length
  77201. + *
  77202. + * @param dwc_otg_urb DWC_OTG URB
  77203. + * @param desc_num ISOC descriptor number
  77204. + * @param offset Offset from beginig of buffer.
  77205. + * @param length Transaction length
  77206. + */
  77207. +extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  77208. + int desc_num, uint32_t offset,
  77209. + uint32_t length);
  77210. +
  77211. +/** Get status of ISOC descriptor, specified by desc_num
  77212. + *
  77213. + * @param dwc_otg_urb DWC_OTG URB
  77214. + * @param desc_num ISOC descriptor number
  77215. + */
  77216. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  77217. + dwc_otg_urb, int desc_num);
  77218. +
  77219. +/** Get actual length of ISOC descriptor, specified by desc_num
  77220. + *
  77221. + * @param dwc_otg_urb DWC_OTG URB
  77222. + * @param desc_num ISOC descriptor number
  77223. + */
  77224. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  77225. + dwc_otg_urb,
  77226. + int desc_num);
  77227. +
  77228. +/** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  77229. + *
  77230. + * @param dwc_otg_hcd The HCD
  77231. + * @param dwc_otg_urb DWC_OTG URB
  77232. + * @param ep_handle Out parameter for returning endpoint handle
  77233. + * @param atomic_alloc Flag to do atomic allocation if needed
  77234. + *
  77235. + * Returns -DWC_E_NO_DEVICE if no device is connected.
  77236. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  77237. + * Returns 0 on success.
  77238. + */
  77239. +extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  77240. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  77241. + void **ep_handle, int atomic_alloc);
  77242. +
  77243. +/** De-queue the specified URB
  77244. + *
  77245. + * @param dwc_otg_hcd The HCD
  77246. + * @param dwc_otg_urb DWC_OTG URB
  77247. + */
  77248. +extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  77249. + dwc_otg_hcd_urb_t * dwc_otg_urb);
  77250. +
  77251. +/** Frees resources in the DWC_otg controller related to a given endpoint.
  77252. + * Any URBs for the endpoint must already be dequeued.
  77253. + *
  77254. + * @param hcd The HCD
  77255. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  77256. + * @param retry Number of retries if there are queued transfers.
  77257. + *
  77258. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  77259. + * Returns 0 on success
  77260. + */
  77261. +extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  77262. + int retry);
  77263. +
  77264. +/* Resets the data toggle in qh structure. This function can be called from
  77265. + * usb_clear_halt routine.
  77266. + *
  77267. + * @param hcd The HCD
  77268. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  77269. + *
  77270. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  77271. + * Returns 0 on success
  77272. + */
  77273. +extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  77274. +
  77275. +/** Returns 1 if status of specified port is changed and 0 otherwise.
  77276. + *
  77277. + * @param hcd The HCD
  77278. + * @param port Port number
  77279. + */
  77280. +extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  77281. +
  77282. +/** Call this function to check if bandwidth was allocated for specified endpoint.
  77283. + * Only for ISOC and INTERRUPT endpoints.
  77284. + *
  77285. + * @param hcd The HCD
  77286. + * @param ep_handle Endpoint handle
  77287. + */
  77288. +extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  77289. + void *ep_handle);
  77290. +
  77291. +/** Call this function to check if bandwidth was freed for specified endpoint.
  77292. + *
  77293. + * @param hcd The HCD
  77294. + * @param ep_handle Endpoint handle
  77295. + */
  77296. +extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  77297. +
  77298. +/** Returns bandwidth allocated for specified endpoint in microseconds.
  77299. + * Only for ISOC and INTERRUPT endpoints.
  77300. + *
  77301. + * @param hcd The HCD
  77302. + * @param ep_handle Endpoint handle
  77303. + */
  77304. +extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  77305. + void *ep_handle);
  77306. +
  77307. +/** @} */
  77308. +
  77309. +#endif /* __DWC_HCD_IF_H__ */
  77310. +#endif /* DWC_DEVICE_ONLY */
  77311. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  77312. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  77313. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 2014-04-24 16:04:39.819124254 +0200
  77314. @@ -0,0 +1,2681 @@
  77315. +/* ==========================================================================
  77316. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
  77317. + * $Revision: #89 $
  77318. + * $Date: 2011/10/20 $
  77319. + * $Change: 1869487 $
  77320. + *
  77321. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  77322. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  77323. + * otherwise expressly agreed to in writing between Synopsys and you.
  77324. + *
  77325. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  77326. + * any End User Software License Agreement or Agreement for Licensed Product
  77327. + * with Synopsys or any supplement thereto. You are permitted to use and
  77328. + * redistribute this Software in source and binary forms, with or without
  77329. + * modification, provided that redistributions of source code must retain this
  77330. + * notice. You may not view, use, disclose, copy or distribute this file or
  77331. + * any information contained herein except pursuant to this license grant from
  77332. + * Synopsys. If you do not agree with this notice, including the disclaimer
  77333. + * below, then you are not authorized to use the Software.
  77334. + *
  77335. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  77336. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  77337. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  77338. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  77339. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  77340. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  77341. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  77342. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  77343. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  77344. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  77345. + * DAMAGE.
  77346. + * ========================================================================== */
  77347. +#ifndef DWC_DEVICE_ONLY
  77348. +
  77349. +#include "dwc_otg_hcd.h"
  77350. +#include "dwc_otg_regs.h"
  77351. +
  77352. +#include <linux/jiffies.h>
  77353. +#include <mach/hardware.h>
  77354. +#include <asm/fiq.h>
  77355. +
  77356. +
  77357. +extern bool microframe_schedule;
  77358. +
  77359. +/** @file
  77360. + * This file contains the implementation of the HCD Interrupt handlers.
  77361. + */
  77362. +
  77363. +int fiq_done, int_done;
  77364. +
  77365. +#ifdef FIQ_DEBUG
  77366. +char buffer[1000*16];
  77367. +int wptr;
  77368. +void notrace _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
  77369. +{
  77370. + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
  77371. + va_list args;
  77372. + char text[17];
  77373. + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  77374. +
  77375. + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  77376. + {
  77377. + local_fiq_disable();
  77378. + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  77379. + va_start(args, fmt);
  77380. + vsnprintf(text+8, 9, fmt, args);
  77381. + va_end(args);
  77382. +
  77383. + memcpy(buffer + wptr, text, 16);
  77384. + wptr = (wptr + 16) % sizeof(buffer);
  77385. + local_fiq_enable();
  77386. + }
  77387. +}
  77388. +#endif
  77389. +
  77390. +/** This function handles interrupts for the HCD. */
  77391. +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  77392. +{
  77393. + int retval = 0;
  77394. + static int last_time;
  77395. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  77396. + gintsts_data_t gintsts;
  77397. + gintmsk_data_t gintmsk;
  77398. + hfnum_data_t hfnum;
  77399. + haintmsk_data_t haintmsk;
  77400. +
  77401. +#ifdef DEBUG
  77402. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  77403. +
  77404. +#endif
  77405. +
  77406. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  77407. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  77408. +
  77409. + /* Exit from ISR if core is hibernated */
  77410. + if (core_if->hibernation_suspend == 1) {
  77411. + goto exit_handler_routine;
  77412. + }
  77413. + DWC_SPINLOCK(dwc_otg_hcd->lock);
  77414. + /* Check if HOST Mode */
  77415. + if (dwc_otg_is_host_mode(core_if)) {
  77416. + local_fiq_disable();
  77417. + /* Pull in from the FIQ's disabled mask */
  77418. + gintmsk.d32 = gintmsk.d32 | ~(dwc_otg_hcd->fiq_state->gintmsk_saved.d32);
  77419. + dwc_otg_hcd->fiq_state->gintmsk_saved.d32 = ~0;
  77420. +
  77421. +
  77422. + if (fiq_fsm_enable && ( 0x0000FFFF & ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint))) {
  77423. + gintsts.b.hcintr = 1;
  77424. + }
  77425. +
  77426. + /* Danger will robinson: fake a SOF if necessary */
  77427. + if (fiq_fsm_enable && (dwc_otg_hcd->fiq_state->gintmsk_saved.b.sofintr == 1)) {
  77428. + gintsts.b.sofintr = 1;
  77429. + }
  77430. + gintsts.d32 &= gintmsk.d32;
  77431. +
  77432. + local_fiq_enable();
  77433. + if (!gintsts.d32) {
  77434. + goto exit_handler_routine;
  77435. + }
  77436. +
  77437. +#ifdef DEBUG
  77438. + // We should be OK doing this because the common interrupts should already have been serviced
  77439. + /* Don't print debug message in the interrupt handler on SOF */
  77440. +#ifndef DEBUG_SOF
  77441. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  77442. +#endif
  77443. + DWC_DEBUGPL(DBG_HCDI, "\n");
  77444. +#endif
  77445. +
  77446. +#ifdef DEBUG
  77447. +#ifndef DEBUG_SOF
  77448. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  77449. +#endif
  77450. + DWC_DEBUGPL(DBG_HCDI,
  77451. + "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x core_if=%p\n",
  77452. + gintsts.d32, core_if);
  77453. +#endif
  77454. + hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  77455. + if (gintsts.b.sofintr) {
  77456. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  77457. + }
  77458. +
  77459. + if (gintsts.b.rxstsqlvl) {
  77460. + retval |=
  77461. + dwc_otg_hcd_handle_rx_status_q_level_intr
  77462. + (dwc_otg_hcd);
  77463. + }
  77464. + if (gintsts.b.nptxfempty) {
  77465. + retval |=
  77466. + dwc_otg_hcd_handle_np_tx_fifo_empty_intr
  77467. + (dwc_otg_hcd);
  77468. + }
  77469. + if (gintsts.b.i2cintr) {
  77470. + /** @todo Implement i2cintr handler. */
  77471. + }
  77472. + if (gintsts.b.portintr) {
  77473. +
  77474. + gintmsk_data_t gintmsk = { .b.portintr = 1};
  77475. + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
  77476. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  77477. + }
  77478. + if (gintsts.b.hcintr) {
  77479. + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
  77480. + }
  77481. + if (gintsts.b.ptxfempty) {
  77482. + retval |=
  77483. + dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
  77484. + (dwc_otg_hcd);
  77485. + }
  77486. +#ifdef DEBUG
  77487. +#ifndef DEBUG_SOF
  77488. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  77489. +#endif
  77490. + {
  77491. + DWC_DEBUGPL(DBG_HCDI,
  77492. + "DWC OTG HCD Finished Servicing Interrupts\n");
  77493. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
  77494. + DWC_READ_REG32(&global_regs->gintsts));
  77495. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
  77496. + DWC_READ_REG32(&global_regs->gintmsk));
  77497. + }
  77498. +#endif
  77499. +
  77500. +#ifdef DEBUG
  77501. +#ifndef DEBUG_SOF
  77502. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  77503. +#endif
  77504. + DWC_DEBUGPL(DBG_HCDI, "\n");
  77505. +#endif
  77506. +
  77507. + }
  77508. +
  77509. +exit_handler_routine:
  77510. + if (fiq_enable) {
  77511. + gintmsk_data_t gintmsk_new;
  77512. + haintmsk_data_t haintmsk_new;
  77513. + local_fiq_disable();
  77514. + gintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->gintmsk_saved.d32;
  77515. + if(fiq_fsm_enable)
  77516. + haintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->haintmsk_saved.d32;
  77517. + else
  77518. + haintmsk_new.d32 = 0x0000FFFF;
  77519. +
  77520. + /* The FIQ could have sneaked another interrupt in. If so, don't clear MPHI */
  77521. + if ((gintmsk_new.d32 == ~0) && (haintmsk_new.d32 == 0x0000FFFF)) {
  77522. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.intstat, (1<<16));
  77523. + if (dwc_otg_hcd->fiq_state->mphi_int_count >= 50) {
  77524. + fiq_print(FIQDBG_INT, dwc_otg_hcd->fiq_state, "MPHI CLR");
  77525. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, ((1<<31) + (1<<16)));
  77526. + while (!(DWC_READ_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & (1 << 17)))
  77527. + ;
  77528. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, (1<<31));
  77529. + dwc_otg_hcd->fiq_state->mphi_int_count = 0;
  77530. + }
  77531. + int_done++;
  77532. + }
  77533. + haintmsk.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  77534. + /* Re-enable interrupts that the FIQ masked (first time round) */
  77535. + FIQ_WRITE(dwc_otg_hcd->fiq_state->dwc_regs_base + GINTMSK, gintmsk.d32);
  77536. + local_fiq_enable();
  77537. +
  77538. + if ((jiffies / HZ) > last_time) {
  77539. + //dwc_otg_qh_t *qh;
  77540. + //dwc_list_link_t *cur;
  77541. + /* Once a second output the fiq and irq numbers, useful for debug */
  77542. + last_time = jiffies / HZ;
  77543. + // DWC_WARN("np_kick=%d AHC=%d sched_frame=%d cur_frame=%d int_done=%d fiq_done=%d",
  77544. + // dwc_otg_hcd->fiq_state->kick_np_queues, dwc_otg_hcd->available_host_channels,
  77545. + // dwc_otg_hcd->fiq_state->next_sched_frame, hfnum.b.frnum, int_done, dwc_otg_hcd->fiq_state->fiq_done);
  77546. + //printk(KERN_WARNING "Periodic queues:\n");
  77547. + }
  77548. + }
  77549. +
  77550. + DWC_SPINUNLOCK(dwc_otg_hcd->lock);
  77551. + return retval;
  77552. +}
  77553. +
  77554. +#ifdef DWC_TRACK_MISSED_SOFS
  77555. +
  77556. +#warning Compiling code to track missed SOFs
  77557. +#define FRAME_NUM_ARRAY_SIZE 1000
  77558. +/**
  77559. + * This function is for debug only.
  77560. + */
  77561. +static inline void track_missed_sofs(uint16_t curr_frame_number)
  77562. +{
  77563. + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
  77564. + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
  77565. + static int frame_num_idx = 0;
  77566. + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
  77567. + static int dumped_frame_num_array = 0;
  77568. +
  77569. + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  77570. + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
  77571. + curr_frame_number) {
  77572. + frame_num_array[frame_num_idx] = curr_frame_number;
  77573. + last_frame_num_array[frame_num_idx++] = last_frame_num;
  77574. + }
  77575. + } else if (!dumped_frame_num_array) {
  77576. + int i;
  77577. + DWC_PRINTF("Frame Last Frame\n");
  77578. + DWC_PRINTF("----- ----------\n");
  77579. + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  77580. + DWC_PRINTF("0x%04x 0x%04x\n",
  77581. + frame_num_array[i], last_frame_num_array[i]);
  77582. + }
  77583. + dumped_frame_num_array = 1;
  77584. + }
  77585. + last_frame_num = curr_frame_number;
  77586. +}
  77587. +#endif
  77588. +
  77589. +/**
  77590. + * Handles the start-of-frame interrupt in host mode. Non-periodic
  77591. + * transactions may be queued to the DWC_otg controller for the current
  77592. + * (micro)frame. Periodic transactions may be queued to the controller for the
  77593. + * next (micro)frame.
  77594. + */
  77595. +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  77596. +{
  77597. + hfnum_data_t hfnum;
  77598. + gintsts_data_t gintsts = { .d32 = 0 };
  77599. + dwc_list_link_t *qh_entry;
  77600. + dwc_otg_qh_t *qh;
  77601. + dwc_otg_transaction_type_e tr_type;
  77602. + int did_something = 0;
  77603. + int32_t next_sched_frame = -1;
  77604. +
  77605. + hfnum.d32 =
  77606. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  77607. +
  77608. +#ifdef DEBUG_SOF
  77609. + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
  77610. +#endif
  77611. + hcd->frame_number = hfnum.b.frnum;
  77612. +
  77613. +#ifdef DEBUG
  77614. + hcd->frrem_accum += hfnum.b.frrem;
  77615. + hcd->frrem_samples++;
  77616. +#endif
  77617. +
  77618. +#ifdef DWC_TRACK_MISSED_SOFS
  77619. + track_missed_sofs(hcd->frame_number);
  77620. +#endif
  77621. + /* Determine whether any periodic QHs should be executed. */
  77622. + qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
  77623. + while (qh_entry != &hcd->periodic_sched_inactive) {
  77624. + qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
  77625. + qh_entry = qh_entry->next;
  77626. + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
  77627. +
  77628. + /*
  77629. + * Move QH to the ready list to be executed next
  77630. + * (micro)frame.
  77631. + */
  77632. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  77633. + &qh->qh_list_entry);
  77634. +
  77635. + did_something = 1;
  77636. + }
  77637. + else
  77638. + {
  77639. + if(next_sched_frame < 0 || dwc_frame_num_le(qh->sched_frame, next_sched_frame))
  77640. + {
  77641. + next_sched_frame = qh->sched_frame;
  77642. + }
  77643. + }
  77644. + }
  77645. +
  77646. + hcd->fiq_state->next_sched_frame = next_sched_frame;
  77647. +
  77648. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  77649. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  77650. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  77651. + did_something = 1;
  77652. + }
  77653. +
  77654. + /* Clear interrupt - but do not trample on the FIQ sof */
  77655. + if (!fiq_fsm_enable) {
  77656. + gintsts.b.sofintr = 1;
  77657. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  77658. + }
  77659. + return 1;
  77660. +}
  77661. +
  77662. +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
  77663. + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
  77664. + * memory if the DWC_otg controller is operating in Slave mode. */
  77665. +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  77666. +{
  77667. + host_grxsts_data_t grxsts;
  77668. + dwc_hc_t *hc = NULL;
  77669. +
  77670. + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
  77671. +
  77672. + grxsts.d32 =
  77673. + DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
  77674. +
  77675. + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
  77676. + if (!hc) {
  77677. + DWC_ERROR("Unable to get corresponding channel\n");
  77678. + return 0;
  77679. + }
  77680. +
  77681. + /* Packet Status */
  77682. + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
  77683. + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
  77684. + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
  77685. + hc->data_pid_start);
  77686. + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
  77687. +
  77688. + switch (grxsts.b.pktsts) {
  77689. + case DWC_GRXSTS_PKTSTS_IN:
  77690. + /* Read the data into the host buffer. */
  77691. + if (grxsts.b.bcnt > 0) {
  77692. + dwc_otg_read_packet(dwc_otg_hcd->core_if,
  77693. + hc->xfer_buff, grxsts.b.bcnt);
  77694. +
  77695. + /* Update the HC fields for the next packet received. */
  77696. + hc->xfer_count += grxsts.b.bcnt;
  77697. + hc->xfer_buff += grxsts.b.bcnt;
  77698. + }
  77699. +
  77700. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  77701. + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  77702. + case DWC_GRXSTS_PKTSTS_CH_HALTED:
  77703. + /* Handled in interrupt, just ignore data */
  77704. + break;
  77705. + default:
  77706. + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
  77707. + grxsts.b.pktsts);
  77708. + break;
  77709. + }
  77710. +
  77711. + return 1;
  77712. +}
  77713. +
  77714. +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  77715. + * data packets may be written to the FIFO for OUT transfers. More requests
  77716. + * may be written to the non-periodic request queue for IN transfers. This
  77717. + * interrupt is enabled only in Slave mode. */
  77718. +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  77719. +{
  77720. + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  77721. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  77722. + DWC_OTG_TRANSACTION_NON_PERIODIC);
  77723. + return 1;
  77724. +}
  77725. +
  77726. +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  77727. + * packets may be written to the FIFO for OUT transfers. More requests may be
  77728. + * written to the periodic request queue for IN transfers. This interrupt is
  77729. + * enabled only in Slave mode. */
  77730. +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  77731. +{
  77732. + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
  77733. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  77734. + DWC_OTG_TRANSACTION_PERIODIC);
  77735. + return 1;
  77736. +}
  77737. +
  77738. +/** There are multiple conditions that can cause a port interrupt. This function
  77739. + * determines which interrupt conditions have occurred and handles them
  77740. + * appropriately. */
  77741. +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  77742. +{
  77743. + int retval = 0;
  77744. + hprt0_data_t hprt0;
  77745. + hprt0_data_t hprt0_modify;
  77746. +
  77747. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  77748. + hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  77749. +
  77750. + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
  77751. + * GINTSTS */
  77752. +
  77753. + hprt0_modify.b.prtena = 0;
  77754. + hprt0_modify.b.prtconndet = 0;
  77755. + hprt0_modify.b.prtenchng = 0;
  77756. + hprt0_modify.b.prtovrcurrchng = 0;
  77757. +
  77758. + /* Port Connect Detected
  77759. + * Set flag and clear if detected */
  77760. + if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
  77761. + // Dont modify port status if we are in hibernation state
  77762. + hprt0_modify.b.prtconndet = 1;
  77763. + hprt0_modify.b.prtenchng = 1;
  77764. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  77765. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  77766. + return retval;
  77767. + }
  77768. +
  77769. + if (hprt0.b.prtconndet) {
  77770. + /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
  77771. + if (dwc_otg_hcd->core_if->adp_enable &&
  77772. + dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
  77773. + DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
  77774. + DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
  77775. + dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  77776. + /* TODO - check if this is required, as
  77777. + * host initialization was already performed
  77778. + * after initial ADP probing
  77779. + */
  77780. + /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  77781. + dwc_otg_core_init(dwc_otg_hcd->core_if);
  77782. + dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
  77783. + cil_hcd_start(dwc_otg_hcd->core_if);*/
  77784. + } else {
  77785. +
  77786. + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
  77787. + "Port Connect Detected--\n", hprt0.d32);
  77788. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  77789. + dwc_otg_hcd->flags.b.port_connect_status = 1;
  77790. + hprt0_modify.b.prtconndet = 1;
  77791. +
  77792. + /* B-Device has connected, Delete the connection timer. */
  77793. + DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
  77794. + }
  77795. + /* The Hub driver asserts a reset when it sees port connect
  77796. + * status change flag */
  77797. + retval |= 1;
  77798. + }
  77799. +
  77800. + /* Port Enable Changed
  77801. + * Clear if detected - Set internal flag if disabled */
  77802. + if (hprt0.b.prtenchng) {
  77803. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  77804. + "Port Enable Changed--\n", hprt0.d32);
  77805. + hprt0_modify.b.prtenchng = 1;
  77806. + if (hprt0.b.prtena == 1) {
  77807. + hfir_data_t hfir;
  77808. + int do_reset = 0;
  77809. + dwc_otg_core_params_t *params =
  77810. + dwc_otg_hcd->core_if->core_params;
  77811. + dwc_otg_core_global_regs_t *global_regs =
  77812. + dwc_otg_hcd->core_if->core_global_regs;
  77813. + dwc_otg_host_if_t *host_if =
  77814. + dwc_otg_hcd->core_if->host_if;
  77815. +
  77816. + /* Every time when port enables calculate
  77817. + * HFIR.FrInterval
  77818. + */
  77819. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  77820. + hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
  77821. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  77822. +
  77823. + /* Check if we need to adjust the PHY clock speed for
  77824. + * low power and adjust it */
  77825. + if (params->host_support_fs_ls_low_power) {
  77826. + gusbcfg_data_t usbcfg;
  77827. +
  77828. + usbcfg.d32 =
  77829. + DWC_READ_REG32(&global_regs->gusbcfg);
  77830. +
  77831. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
  77832. + || hprt0.b.prtspd ==
  77833. + DWC_HPRT0_PRTSPD_FULL_SPEED) {
  77834. + /*
  77835. + * Low power
  77836. + */
  77837. + hcfg_data_t hcfg;
  77838. + if (usbcfg.b.phylpwrclksel == 0) {
  77839. + /* Set PHY low power clock select for FS/LS devices */
  77840. + usbcfg.b.phylpwrclksel = 1;
  77841. + DWC_WRITE_REG32
  77842. + (&global_regs->gusbcfg,
  77843. + usbcfg.d32);
  77844. + do_reset = 1;
  77845. + }
  77846. +
  77847. + hcfg.d32 =
  77848. + DWC_READ_REG32
  77849. + (&host_if->host_global_regs->hcfg);
  77850. +
  77851. + if (hprt0.b.prtspd ==
  77852. + DWC_HPRT0_PRTSPD_LOW_SPEED
  77853. + && params->host_ls_low_power_phy_clk
  77854. + ==
  77855. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
  77856. + {
  77857. + /* 6 MHZ */
  77858. + DWC_DEBUGPL(DBG_CIL,
  77859. + "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
  77860. + if (hcfg.b.fslspclksel !=
  77861. + DWC_HCFG_6_MHZ) {
  77862. + hcfg.b.fslspclksel =
  77863. + DWC_HCFG_6_MHZ;
  77864. + DWC_WRITE_REG32
  77865. + (&host_if->host_global_regs->hcfg,
  77866. + hcfg.d32);
  77867. + do_reset = 1;
  77868. + }
  77869. + } else {
  77870. + /* 48 MHZ */
  77871. + DWC_DEBUGPL(DBG_CIL,
  77872. + "FS_PHY programming HCFG to 48 MHz ()\n");
  77873. + if (hcfg.b.fslspclksel !=
  77874. + DWC_HCFG_48_MHZ) {
  77875. + hcfg.b.fslspclksel =
  77876. + DWC_HCFG_48_MHZ;
  77877. + DWC_WRITE_REG32
  77878. + (&host_if->host_global_regs->hcfg,
  77879. + hcfg.d32);
  77880. + do_reset = 1;
  77881. + }
  77882. + }
  77883. + } else {
  77884. + /*
  77885. + * Not low power
  77886. + */
  77887. + if (usbcfg.b.phylpwrclksel == 1) {
  77888. + usbcfg.b.phylpwrclksel = 0;
  77889. + DWC_WRITE_REG32
  77890. + (&global_regs->gusbcfg,
  77891. + usbcfg.d32);
  77892. + do_reset = 1;
  77893. + }
  77894. + }
  77895. +
  77896. + if (do_reset) {
  77897. + DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
  77898. + }
  77899. + }
  77900. +
  77901. + if (!do_reset) {
  77902. + /* Port has been enabled set the reset change flag */
  77903. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  77904. + }
  77905. + } else {
  77906. + dwc_otg_hcd->flags.b.port_enable_change = 1;
  77907. + }
  77908. + retval |= 1;
  77909. + }
  77910. +
  77911. + /** Overcurrent Change Interrupt */
  77912. + if (hprt0.b.prtovrcurrchng) {
  77913. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  77914. + "Port Overcurrent Changed--\n", hprt0.d32);
  77915. + dwc_otg_hcd->flags.b.port_over_current_change = 1;
  77916. + hprt0_modify.b.prtovrcurrchng = 1;
  77917. + retval |= 1;
  77918. + }
  77919. +
  77920. + /* Clear Port Interrupts */
  77921. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  77922. +
  77923. + return retval;
  77924. +}
  77925. +
  77926. +/** This interrupt indicates that one or more host channels has a pending
  77927. + * interrupt. There are multiple conditions that can cause each host channel
  77928. + * interrupt. This function determines which conditions have occurred for each
  77929. + * host channel interrupt and handles them appropriately. */
  77930. +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  77931. +{
  77932. + int i;
  77933. + int retval = 0;
  77934. + haint_data_t haint = { .d32 = 0 } ;
  77935. +
  77936. + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  77937. + * GINTSTS */
  77938. +
  77939. + if (!fiq_fsm_enable)
  77940. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  77941. +
  77942. + // Overwrite with saved interrupts from fiq handler
  77943. + if(fiq_fsm_enable)
  77944. + {
  77945. + /* check the mask? */
  77946. + local_fiq_disable();
  77947. + haint.b2.chint |= ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint);
  77948. + dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  77949. + local_fiq_enable();
  77950. + }
  77951. +
  77952. + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
  77953. + if (haint.b2.chint & (1 << i)) {
  77954. + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
  77955. + }
  77956. + }
  77957. +
  77958. + return retval;
  77959. +}
  77960. +
  77961. +/**
  77962. + * Gets the actual length of a transfer after the transfer halts. _halt_status
  77963. + * holds the reason for the halt.
  77964. + *
  77965. + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
  77966. + * *short_read is set to 1 upon return if less than the requested
  77967. + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
  77968. + * return. short_read may also be NULL on entry, in which case it remains
  77969. + * unchanged.
  77970. + */
  77971. +static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
  77972. + dwc_otg_hc_regs_t * hc_regs,
  77973. + dwc_otg_qtd_t * qtd,
  77974. + dwc_otg_halt_status_e halt_status,
  77975. + int *short_read)
  77976. +{
  77977. + hctsiz_data_t hctsiz;
  77978. + uint32_t length;
  77979. +
  77980. + if (short_read != NULL) {
  77981. + *short_read = 0;
  77982. + }
  77983. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  77984. +
  77985. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  77986. + if (hc->ep_is_in) {
  77987. + length = hc->xfer_len - hctsiz.b.xfersize;
  77988. + if (short_read != NULL) {
  77989. + *short_read = (hctsiz.b.xfersize != 0);
  77990. + }
  77991. + } else if (hc->qh->do_split) {
  77992. + //length = split_out_xfersize[hc->hc_num];
  77993. + length = qtd->ssplit_out_xfer_count;
  77994. + } else {
  77995. + length = hc->xfer_len;
  77996. + }
  77997. + } else {
  77998. + /*
  77999. + * Must use the hctsiz.pktcnt field to determine how much data
  78000. + * has been transferred. This field reflects the number of
  78001. + * packets that have been transferred via the USB. This is
  78002. + * always an integral number of packets if the transfer was
  78003. + * halted before its normal completion. (Can't use the
  78004. + * hctsiz.xfersize field because that reflects the number of
  78005. + * bytes transferred via the AHB, not the USB).
  78006. + */
  78007. + length =
  78008. + (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
  78009. + }
  78010. +
  78011. + return length;
  78012. +}
  78013. +
  78014. +/**
  78015. + * Updates the state of the URB after a Transfer Complete interrupt on the
  78016. + * host channel. Updates the actual_length field of the URB based on the
  78017. + * number of bytes transferred via the host channel. Sets the URB status
  78018. + * if the data transfer is finished.
  78019. + *
  78020. + * @return 1 if the data transfer specified by the URB is completely finished,
  78021. + * 0 otherwise.
  78022. + */
  78023. +static int update_urb_state_xfer_comp(dwc_hc_t * hc,
  78024. + dwc_otg_hc_regs_t * hc_regs,
  78025. + dwc_otg_hcd_urb_t * urb,
  78026. + dwc_otg_qtd_t * qtd)
  78027. +{
  78028. + int xfer_done = 0;
  78029. + int short_read = 0;
  78030. +
  78031. + int xfer_length;
  78032. +
  78033. + xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
  78034. + DWC_OTG_HC_XFER_COMPLETE,
  78035. + &short_read);
  78036. +
  78037. + /* non DWORD-aligned buffer case handling. */
  78038. + if (hc->align_buff && xfer_length && hc->ep_is_in) {
  78039. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  78040. + xfer_length);
  78041. + }
  78042. +
  78043. + urb->actual_length += xfer_length;
  78044. +
  78045. + if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
  78046. + (urb->flags & URB_SEND_ZERO_PACKET)
  78047. + && (urb->actual_length == urb->length)
  78048. + && !(urb->length % hc->max_packet)) {
  78049. + xfer_done = 0;
  78050. + } else if (short_read || urb->actual_length >= urb->length) {
  78051. + xfer_done = 1;
  78052. + urb->status = 0;
  78053. + }
  78054. +
  78055. +#ifdef DEBUG
  78056. + {
  78057. + hctsiz_data_t hctsiz;
  78058. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78059. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  78060. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  78061. + hc->hc_num);
  78062. + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
  78063. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
  78064. + hctsiz.b.xfersize);
  78065. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  78066. + urb->length);
  78067. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  78068. + urb->actual_length);
  78069. + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
  78070. + short_read, xfer_done);
  78071. + }
  78072. +#endif
  78073. +
  78074. + return xfer_done;
  78075. +}
  78076. +
  78077. +/*
  78078. + * Save the starting data toggle for the next transfer. The data toggle is
  78079. + * saved in the QH for non-control transfers and it's saved in the QTD for
  78080. + * control transfers.
  78081. + */
  78082. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  78083. + dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
  78084. +{
  78085. + hctsiz_data_t hctsiz;
  78086. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78087. +
  78088. + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
  78089. + dwc_otg_qh_t *qh = hc->qh;
  78090. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  78091. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  78092. + } else {
  78093. + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
  78094. + }
  78095. + } else {
  78096. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  78097. + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
  78098. + } else {
  78099. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  78100. + }
  78101. + }
  78102. +}
  78103. +
  78104. +/**
  78105. + * Updates the state of an Isochronous URB when the transfer is stopped for
  78106. + * any reason. The fields of the current entry in the frame descriptor array
  78107. + * are set based on the transfer state and the input _halt_status. Completes
  78108. + * the Isochronous URB if all the URB frames have been completed.
  78109. + *
  78110. + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
  78111. + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
  78112. + */
  78113. +static dwc_otg_halt_status_e
  78114. +update_isoc_urb_state(dwc_otg_hcd_t * hcd,
  78115. + dwc_hc_t * hc,
  78116. + dwc_otg_hc_regs_t * hc_regs,
  78117. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  78118. +{
  78119. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  78120. + dwc_otg_halt_status_e ret_val = halt_status;
  78121. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  78122. +
  78123. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  78124. + switch (halt_status) {
  78125. + case DWC_OTG_HC_XFER_COMPLETE:
  78126. + frame_desc->status = 0;
  78127. + frame_desc->actual_length =
  78128. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  78129. +
  78130. + /* non DWORD-aligned buffer case handling. */
  78131. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  78132. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  78133. + hc->qh->dw_align_buf, frame_desc->actual_length);
  78134. + }
  78135. +
  78136. + break;
  78137. + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
  78138. + urb->error_count++;
  78139. + if (hc->ep_is_in) {
  78140. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  78141. + } else {
  78142. + frame_desc->status = -DWC_E_COMMUNICATION;
  78143. + }
  78144. + frame_desc->actual_length = 0;
  78145. + break;
  78146. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  78147. + urb->error_count++;
  78148. + frame_desc->status = -DWC_E_OVERFLOW;
  78149. + /* Don't need to update actual_length in this case. */
  78150. + break;
  78151. + case DWC_OTG_HC_XFER_XACT_ERR:
  78152. + urb->error_count++;
  78153. + frame_desc->status = -DWC_E_PROTOCOL;
  78154. + frame_desc->actual_length =
  78155. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  78156. +
  78157. + /* non DWORD-aligned buffer case handling. */
  78158. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  78159. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  78160. + hc->qh->dw_align_buf, frame_desc->actual_length);
  78161. + }
  78162. + /* Skip whole frame */
  78163. + if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
  78164. + hc->ep_is_in && hcd->core_if->dma_enable) {
  78165. + qtd->complete_split = 0;
  78166. + qtd->isoc_split_offset = 0;
  78167. + }
  78168. +
  78169. + break;
  78170. + default:
  78171. + DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
  78172. + break;
  78173. + }
  78174. + if (++qtd->isoc_frame_index == urb->packet_count) {
  78175. + /*
  78176. + * urb->status is not used for isoc transfers.
  78177. + * The individual frame_desc statuses are used instead.
  78178. + */
  78179. + hcd->fops->complete(hcd, urb->priv, urb, 0);
  78180. + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
  78181. + } else {
  78182. + ret_val = DWC_OTG_HC_XFER_COMPLETE;
  78183. + }
  78184. + return ret_val;
  78185. +}
  78186. +
  78187. +/**
  78188. + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  78189. + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  78190. + * still linked to the QH, the QH is added to the end of the inactive
  78191. + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  78192. + * schedule if no more QTDs are linked to the QH.
  78193. + */
  78194. +static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
  78195. +{
  78196. + int continue_split = 0;
  78197. + dwc_otg_qtd_t *qtd;
  78198. +
  78199. + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
  78200. +
  78201. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  78202. +
  78203. + if (qtd->complete_split) {
  78204. + continue_split = 1;
  78205. + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  78206. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
  78207. + continue_split = 1;
  78208. + }
  78209. +
  78210. + if (free_qtd) {
  78211. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  78212. + continue_split = 0;
  78213. + }
  78214. +
  78215. + qh->channel = NULL;
  78216. + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
  78217. +}
  78218. +
  78219. +/**
  78220. + * Releases a host channel for use by other transfers. Attempts to select and
  78221. + * queue more transactions since at least one host channel is available.
  78222. + *
  78223. + * @param hcd The HCD state structure.
  78224. + * @param hc The host channel to release.
  78225. + * @param qtd The QTD associated with the host channel. This QTD may be freed
  78226. + * if the transfer is complete or an error has occurred.
  78227. + * @param halt_status Reason the channel is being released. This status
  78228. + * determines the actions taken by this function.
  78229. + */
  78230. +static void release_channel(dwc_otg_hcd_t * hcd,
  78231. + dwc_hc_t * hc,
  78232. + dwc_otg_qtd_t * qtd,
  78233. + dwc_otg_halt_status_e halt_status)
  78234. +{
  78235. + dwc_otg_transaction_type_e tr_type;
  78236. + int free_qtd;
  78237. + dwc_irqflags_t flags;
  78238. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  78239. +
  78240. + int hog_port = 0;
  78241. +
  78242. + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  78243. + __func__, hc->hc_num, halt_status, hc->xfer_len);
  78244. +
  78245. + if(fiq_fsm_enable && hc->do_split) {
  78246. + if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  78247. + if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  78248. + hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  78249. + hog_port = 0;
  78250. + }
  78251. + }
  78252. + }
  78253. +
  78254. + switch (halt_status) {
  78255. + case DWC_OTG_HC_XFER_URB_COMPLETE:
  78256. + free_qtd = 1;
  78257. + break;
  78258. + case DWC_OTG_HC_XFER_AHB_ERR:
  78259. + case DWC_OTG_HC_XFER_STALL:
  78260. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  78261. + free_qtd = 1;
  78262. + break;
  78263. + case DWC_OTG_HC_XFER_XACT_ERR:
  78264. + if (qtd->error_count >= 3) {
  78265. + DWC_DEBUGPL(DBG_HCDV,
  78266. + " Complete URB with transaction error\n");
  78267. + free_qtd = 1;
  78268. + qtd->urb->status = -DWC_E_PROTOCOL;
  78269. + hcd->fops->complete(hcd, qtd->urb->priv,
  78270. + qtd->urb, -DWC_E_PROTOCOL);
  78271. + } else {
  78272. + free_qtd = 0;
  78273. + }
  78274. + break;
  78275. + case DWC_OTG_HC_XFER_URB_DEQUEUE:
  78276. + /*
  78277. + * The QTD has already been removed and the QH has been
  78278. + * deactivated. Don't want to do anything except release the
  78279. + * host channel and try to queue more transfers.
  78280. + */
  78281. + goto cleanup;
  78282. + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
  78283. + free_qtd = 0;
  78284. + break;
  78285. + case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
  78286. + DWC_DEBUGPL(DBG_HCDV,
  78287. + " Complete URB with I/O error\n");
  78288. + free_qtd = 1;
  78289. + qtd->urb->status = -DWC_E_IO;
  78290. + hcd->fops->complete(hcd, qtd->urb->priv,
  78291. + qtd->urb, -DWC_E_IO);
  78292. + break;
  78293. + default:
  78294. + free_qtd = 0;
  78295. + break;
  78296. + }
  78297. +
  78298. + deactivate_qh(hcd, hc->qh, free_qtd);
  78299. +
  78300. +cleanup:
  78301. + /*
  78302. + * Release the host channel for use by other transfers. The cleanup
  78303. + * function clears the channel interrupt enables and conditions, so
  78304. + * there's no need to clear the Channel Halted interrupt separately.
  78305. + */
  78306. + if (fiq_fsm_enable && hcd->fiq_state->channel[hc->hc_num].fsm != FIQ_PASSTHROUGH)
  78307. + dwc_otg_cleanup_fiq_channel(hcd, hc->hc_num);
  78308. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  78309. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  78310. +
  78311. + if (!microframe_schedule) {
  78312. + switch (hc->ep_type) {
  78313. + case DWC_OTG_EP_TYPE_CONTROL:
  78314. + case DWC_OTG_EP_TYPE_BULK:
  78315. + hcd->non_periodic_channels--;
  78316. + break;
  78317. +
  78318. + default:
  78319. + /*
  78320. + * Don't release reservations for periodic channels here.
  78321. + * That's done when a periodic transfer is descheduled (i.e.
  78322. + * when the QH is removed from the periodic schedule).
  78323. + */
  78324. + break;
  78325. + }
  78326. + } else {
  78327. +
  78328. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  78329. + hcd->available_host_channels++;
  78330. + fiq_print(FIQDBG_INT, hcd->fiq_state, "AHC = %d ", hcd->available_host_channels);
  78331. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  78332. + }
  78333. +
  78334. + /* Try to queue more transfers now that there's a free channel. */
  78335. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  78336. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  78337. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  78338. + }
  78339. +}
  78340. +
  78341. +/**
  78342. + * Halts a host channel. If the channel cannot be halted immediately because
  78343. + * the request queue is full, this function ensures that the FIFO empty
  78344. + * interrupt for the appropriate queue is enabled so that the halt request can
  78345. + * be queued when there is space in the request queue.
  78346. + *
  78347. + * This function may also be called in DMA mode. In that case, the channel is
  78348. + * simply released since the core always halts the channel automatically in
  78349. + * DMA mode.
  78350. + */
  78351. +static void halt_channel(dwc_otg_hcd_t * hcd,
  78352. + dwc_hc_t * hc,
  78353. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  78354. +{
  78355. + if (hcd->core_if->dma_enable) {
  78356. + release_channel(hcd, hc, qtd, halt_status);
  78357. + return;
  78358. + }
  78359. +
  78360. + /* Slave mode processing... */
  78361. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  78362. +
  78363. + if (hc->halt_on_queue) {
  78364. + gintmsk_data_t gintmsk = {.d32 = 0 };
  78365. + dwc_otg_core_global_regs_t *global_regs;
  78366. + global_regs = hcd->core_if->core_global_regs;
  78367. +
  78368. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  78369. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  78370. + /*
  78371. + * Make sure the Non-periodic Tx FIFO empty interrupt
  78372. + * is enabled so that the non-periodic schedule will
  78373. + * be processed.
  78374. + */
  78375. + gintmsk.b.nptxfempty = 1;
  78376. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  78377. + } else {
  78378. + /*
  78379. + * Move the QH from the periodic queued schedule to
  78380. + * the periodic assigned schedule. This allows the
  78381. + * halt to be queued when the periodic schedule is
  78382. + * processed.
  78383. + */
  78384. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  78385. + &hc->qh->qh_list_entry);
  78386. +
  78387. + /*
  78388. + * Make sure the Periodic Tx FIFO Empty interrupt is
  78389. + * enabled so that the periodic schedule will be
  78390. + * processed.
  78391. + */
  78392. + gintmsk.b.ptxfempty = 1;
  78393. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  78394. + }
  78395. + }
  78396. +}
  78397. +
  78398. +/**
  78399. + * Performs common cleanup for non-periodic transfers after a Transfer
  78400. + * Complete interrupt. This function should be called after any endpoint type
  78401. + * specific handling is finished to release the host channel.
  78402. + */
  78403. +static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
  78404. + dwc_hc_t * hc,
  78405. + dwc_otg_hc_regs_t * hc_regs,
  78406. + dwc_otg_qtd_t * qtd,
  78407. + dwc_otg_halt_status_e halt_status)
  78408. +{
  78409. + hcint_data_t hcint;
  78410. +
  78411. + qtd->error_count = 0;
  78412. +
  78413. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  78414. + if (hcint.b.nyet) {
  78415. + /*
  78416. + * Got a NYET on the last transaction of the transfer. This
  78417. + * means that the endpoint should be in the PING state at the
  78418. + * beginning of the next transfer.
  78419. + */
  78420. + hc->qh->ping_state = 1;
  78421. + clear_hc_int(hc_regs, nyet);
  78422. + }
  78423. +
  78424. + /*
  78425. + * Always halt and release the host channel to make it available for
  78426. + * more transfers. There may still be more phases for a control
  78427. + * transfer or more data packets for a bulk transfer at this point,
  78428. + * but the host channel is still halted. A channel will be reassigned
  78429. + * to the transfer when the non-periodic schedule is processed after
  78430. + * the channel is released. This allows transactions to be queued
  78431. + * properly via dwc_otg_hcd_queue_transactions, which also enables the
  78432. + * Tx FIFO Empty interrupt if necessary.
  78433. + */
  78434. + if (hc->ep_is_in) {
  78435. + /*
  78436. + * IN transfers in Slave mode require an explicit disable to
  78437. + * halt the channel. (In DMA mode, this call simply releases
  78438. + * the channel.)
  78439. + */
  78440. + halt_channel(hcd, hc, qtd, halt_status);
  78441. + } else {
  78442. + /*
  78443. + * The channel is automatically disabled by the core for OUT
  78444. + * transfers in Slave mode.
  78445. + */
  78446. + release_channel(hcd, hc, qtd, halt_status);
  78447. + }
  78448. +}
  78449. +
  78450. +/**
  78451. + * Performs common cleanup for periodic transfers after a Transfer Complete
  78452. + * interrupt. This function should be called after any endpoint type specific
  78453. + * handling is finished to release the host channel.
  78454. + */
  78455. +static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
  78456. + dwc_hc_t * hc,
  78457. + dwc_otg_hc_regs_t * hc_regs,
  78458. + dwc_otg_qtd_t * qtd,
  78459. + dwc_otg_halt_status_e halt_status)
  78460. +{
  78461. + hctsiz_data_t hctsiz;
  78462. + qtd->error_count = 0;
  78463. +
  78464. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78465. + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
  78466. + /* Core halts channel in these cases. */
  78467. + release_channel(hcd, hc, qtd, halt_status);
  78468. + } else {
  78469. + /* Flush any outstanding requests from the Tx queue. */
  78470. + halt_channel(hcd, hc, qtd, halt_status);
  78471. + }
  78472. +}
  78473. +
  78474. +static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
  78475. + dwc_hc_t * hc,
  78476. + dwc_otg_hc_regs_t * hc_regs,
  78477. + dwc_otg_qtd_t * qtd)
  78478. +{
  78479. + uint32_t len;
  78480. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  78481. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  78482. +
  78483. + len = get_actual_xfer_length(hc, hc_regs, qtd,
  78484. + DWC_OTG_HC_XFER_COMPLETE, NULL);
  78485. +
  78486. + if (!len) {
  78487. + qtd->complete_split = 0;
  78488. + qtd->isoc_split_offset = 0;
  78489. + return 0;
  78490. + }
  78491. + frame_desc->actual_length += len;
  78492. +
  78493. + if (hc->align_buff && len)
  78494. + dwc_memcpy(qtd->urb->buf + frame_desc->offset +
  78495. + qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
  78496. + qtd->isoc_split_offset += len;
  78497. +
  78498. + if (frame_desc->length == frame_desc->actual_length) {
  78499. + frame_desc->status = 0;
  78500. + qtd->isoc_frame_index++;
  78501. + qtd->complete_split = 0;
  78502. + qtd->isoc_split_offset = 0;
  78503. + }
  78504. +
  78505. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  78506. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  78507. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78508. + } else {
  78509. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  78510. + }
  78511. +
  78512. + return 1; /* Indicates that channel released */
  78513. +}
  78514. +
  78515. +/**
  78516. + * Handles a host channel Transfer Complete interrupt. This handler may be
  78517. + * called in either DMA mode or Slave mode.
  78518. + */
  78519. +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
  78520. + dwc_hc_t * hc,
  78521. + dwc_otg_hc_regs_t * hc_regs,
  78522. + dwc_otg_qtd_t * qtd)
  78523. +{
  78524. + int urb_xfer_done;
  78525. + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
  78526. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  78527. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  78528. +
  78529. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78530. + "Transfer Complete--\n", hc->hc_num);
  78531. +
  78532. + if (hcd->core_if->dma_desc_enable) {
  78533. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
  78534. + if (pipe_type == UE_ISOCHRONOUS) {
  78535. + /* Do not disable the interrupt, just clear it */
  78536. + clear_hc_int(hc_regs, xfercomp);
  78537. + return 1;
  78538. + }
  78539. + goto handle_xfercomp_done;
  78540. + }
  78541. +
  78542. + /*
  78543. + * Handle xfer complete on CSPLIT.
  78544. + */
  78545. +
  78546. + if (hc->qh->do_split) {
  78547. + if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
  78548. + && hcd->core_if->dma_enable) {
  78549. + if (qtd->complete_split
  78550. + && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
  78551. + qtd))
  78552. + goto handle_xfercomp_done;
  78553. + } else {
  78554. + qtd->complete_split = 0;
  78555. + }
  78556. + }
  78557. +
  78558. + /* Update the QTD and URB states. */
  78559. + switch (pipe_type) {
  78560. + case UE_CONTROL:
  78561. + switch (qtd->control_phase) {
  78562. + case DWC_OTG_CONTROL_SETUP:
  78563. + if (urb->length > 0) {
  78564. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  78565. + } else {
  78566. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  78567. + }
  78568. + DWC_DEBUGPL(DBG_HCDV,
  78569. + " Control setup transaction done\n");
  78570. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  78571. + break;
  78572. + case DWC_OTG_CONTROL_DATA:{
  78573. + urb_xfer_done =
  78574. + update_urb_state_xfer_comp(hc, hc_regs, urb,
  78575. + qtd);
  78576. + if (urb_xfer_done) {
  78577. + qtd->control_phase =
  78578. + DWC_OTG_CONTROL_STATUS;
  78579. + DWC_DEBUGPL(DBG_HCDV,
  78580. + " Control data transfer done\n");
  78581. + } else {
  78582. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78583. + }
  78584. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  78585. + break;
  78586. + }
  78587. + case DWC_OTG_CONTROL_STATUS:
  78588. + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
  78589. + if (urb->status == -DWC_E_IN_PROGRESS) {
  78590. + urb->status = 0;
  78591. + }
  78592. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  78593. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  78594. + break;
  78595. + }
  78596. +
  78597. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  78598. + break;
  78599. + case UE_BULK:
  78600. + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
  78601. + urb_xfer_done =
  78602. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  78603. + if (urb_xfer_done) {
  78604. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  78605. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  78606. + } else {
  78607. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  78608. + }
  78609. +
  78610. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78611. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  78612. + break;
  78613. + case UE_INTERRUPT:
  78614. + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
  78615. + urb_xfer_done =
  78616. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  78617. +
  78618. + /*
  78619. + * Interrupt URB is done on the first transfer complete
  78620. + * interrupt.
  78621. + */
  78622. + if (urb_xfer_done) {
  78623. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  78624. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  78625. + } else {
  78626. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  78627. + }
  78628. +
  78629. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78630. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  78631. + break;
  78632. + case UE_ISOCHRONOUS:
  78633. + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
  78634. + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  78635. + halt_status =
  78636. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  78637. + DWC_OTG_HC_XFER_COMPLETE);
  78638. + }
  78639. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  78640. + break;
  78641. + }
  78642. +
  78643. +handle_xfercomp_done:
  78644. + disable_hc_int(hc_regs, xfercompl);
  78645. +
  78646. + return 1;
  78647. +}
  78648. +
  78649. +/**
  78650. + * Handles a host channel STALL interrupt. This handler may be called in
  78651. + * either DMA mode or Slave mode.
  78652. + */
  78653. +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
  78654. + dwc_hc_t * hc,
  78655. + dwc_otg_hc_regs_t * hc_regs,
  78656. + dwc_otg_qtd_t * qtd)
  78657. +{
  78658. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  78659. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  78660. +
  78661. + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
  78662. + "STALL Received--\n", hc->hc_num);
  78663. +
  78664. + if (hcd->core_if->dma_desc_enable) {
  78665. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
  78666. + goto handle_stall_done;
  78667. + }
  78668. +
  78669. + if (pipe_type == UE_CONTROL) {
  78670. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  78671. + }
  78672. +
  78673. + if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
  78674. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  78675. + /*
  78676. + * USB protocol requires resetting the data toggle for bulk
  78677. + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  78678. + * setup command is issued to the endpoint. Anticipate the
  78679. + * CLEAR_FEATURE command since a STALL has occurred and reset
  78680. + * the data toggle now.
  78681. + */
  78682. + hc->qh->data_toggle = 0;
  78683. + }
  78684. +
  78685. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
  78686. +
  78687. +handle_stall_done:
  78688. + disable_hc_int(hc_regs, stall);
  78689. +
  78690. + return 1;
  78691. +}
  78692. +
  78693. +/*
  78694. + * Updates the state of the URB when a transfer has been stopped due to an
  78695. + * abnormal condition before the transfer completes. Modifies the
  78696. + * actual_length field of the URB to reflect the number of bytes that have
  78697. + * actually been transferred via the host channel.
  78698. + */
  78699. +static void update_urb_state_xfer_intr(dwc_hc_t * hc,
  78700. + dwc_otg_hc_regs_t * hc_regs,
  78701. + dwc_otg_hcd_urb_t * urb,
  78702. + dwc_otg_qtd_t * qtd,
  78703. + dwc_otg_halt_status_e halt_status)
  78704. +{
  78705. + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
  78706. + halt_status, NULL);
  78707. + /* non DWORD-aligned buffer case handling. */
  78708. + if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
  78709. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  78710. + bytes_transferred);
  78711. + }
  78712. +
  78713. + urb->actual_length += bytes_transferred;
  78714. +
  78715. +#ifdef DEBUG
  78716. + {
  78717. + hctsiz_data_t hctsiz;
  78718. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78719. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  78720. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  78721. + hc->hc_num);
  78722. + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
  78723. + hc->start_pkt_count);
  78724. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
  78725. + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
  78726. + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
  78727. + bytes_transferred);
  78728. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  78729. + urb->actual_length);
  78730. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  78731. + urb->length);
  78732. + }
  78733. +#endif
  78734. +}
  78735. +
  78736. +/**
  78737. + * Handles a host channel NAK interrupt. This handler may be called in either
  78738. + * DMA mode or Slave mode.
  78739. + */
  78740. +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
  78741. + dwc_hc_t * hc,
  78742. + dwc_otg_hc_regs_t * hc_regs,
  78743. + dwc_otg_qtd_t * qtd)
  78744. +{
  78745. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78746. + "NAK Received--\n", hc->hc_num);
  78747. +
  78748. + /*
  78749. + * When we get bulk NAKs then remember this so we holdoff on this qh until
  78750. + * the beginning of the next frame
  78751. + */
  78752. + switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  78753. + case UE_BULK:
  78754. + case UE_CONTROL:
  78755. + if (nak_holdoff && qtd->qh->do_split)
  78756. + hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  78757. + }
  78758. +
  78759. + /*
  78760. + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  78761. + * interrupt. Re-start the SSPLIT transfer.
  78762. + */
  78763. + if (hc->do_split) {
  78764. + if (hc->complete_split) {
  78765. + qtd->error_count = 0;
  78766. + }
  78767. + qtd->complete_split = 0;
  78768. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  78769. + goto handle_nak_done;
  78770. + }
  78771. +
  78772. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  78773. + case UE_CONTROL:
  78774. + case UE_BULK:
  78775. + if (hcd->core_if->dma_enable && hc->ep_is_in) {
  78776. + /*
  78777. + * NAK interrupts are enabled on bulk/control IN
  78778. + * transfers in DMA mode for the sole purpose of
  78779. + * resetting the error count after a transaction error
  78780. + * occurs. The core will continue transferring data.
  78781. + * Disable other interrupts unmasked for the same
  78782. + * reason.
  78783. + */
  78784. + disable_hc_int(hc_regs, datatglerr);
  78785. + disable_hc_int(hc_regs, ack);
  78786. + qtd->error_count = 0;
  78787. + goto handle_nak_done;
  78788. + }
  78789. +
  78790. + /*
  78791. + * NAK interrupts normally occur during OUT transfers in DMA
  78792. + * or Slave mode. For IN transfers, more requests will be
  78793. + * queued as request queue space is available.
  78794. + */
  78795. + qtd->error_count = 0;
  78796. +
  78797. + if (!hc->qh->ping_state) {
  78798. + update_urb_state_xfer_intr(hc, hc_regs,
  78799. + qtd->urb, qtd,
  78800. + DWC_OTG_HC_XFER_NAK);
  78801. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78802. +
  78803. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
  78804. + hc->qh->ping_state = 1;
  78805. + }
  78806. +
  78807. + /*
  78808. + * Halt the channel so the transfer can be re-started from
  78809. + * the appropriate point or the PING protocol will
  78810. + * start/continue.
  78811. + */
  78812. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  78813. + break;
  78814. + case UE_INTERRUPT:
  78815. + qtd->error_count = 0;
  78816. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  78817. + break;
  78818. + case UE_ISOCHRONOUS:
  78819. + /* Should never get called for isochronous transfers. */
  78820. + DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
  78821. + break;
  78822. + }
  78823. +
  78824. +handle_nak_done:
  78825. + disable_hc_int(hc_regs, nak);
  78826. +
  78827. + return 1;
  78828. +}
  78829. +
  78830. +/**
  78831. + * Handles a host channel ACK interrupt. This interrupt is enabled when
  78832. + * performing the PING protocol in Slave mode, when errors occur during
  78833. + * either Slave mode or DMA mode, and during Start Split transactions.
  78834. + */
  78835. +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
  78836. + dwc_hc_t * hc,
  78837. + dwc_otg_hc_regs_t * hc_regs,
  78838. + dwc_otg_qtd_t * qtd)
  78839. +{
  78840. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78841. + "ACK Received--\n", hc->hc_num);
  78842. +
  78843. + if (hc->do_split) {
  78844. + /*
  78845. + * Handle ACK on SSPLIT.
  78846. + * ACK should not occur in CSPLIT.
  78847. + */
  78848. + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
  78849. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  78850. + }
  78851. + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
  78852. + /* Don't need complete for isochronous out transfers. */
  78853. + qtd->complete_split = 1;
  78854. + }
  78855. +
  78856. + /* ISOC OUT */
  78857. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  78858. + switch (hc->xact_pos) {
  78859. + case DWC_HCSPLIT_XACTPOS_ALL:
  78860. + break;
  78861. + case DWC_HCSPLIT_XACTPOS_END:
  78862. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  78863. + qtd->isoc_split_offset = 0;
  78864. + break;
  78865. + case DWC_HCSPLIT_XACTPOS_BEGIN:
  78866. + case DWC_HCSPLIT_XACTPOS_MID:
  78867. + /*
  78868. + * For BEGIN or MID, calculate the length for
  78869. + * the next microframe to determine the correct
  78870. + * SSPLIT token, either MID or END.
  78871. + */
  78872. + {
  78873. + struct dwc_otg_hcd_iso_packet_desc
  78874. + *frame_desc;
  78875. +
  78876. + frame_desc =
  78877. + &qtd->urb->
  78878. + iso_descs[qtd->isoc_frame_index];
  78879. + qtd->isoc_split_offset += 188;
  78880. +
  78881. + if ((frame_desc->length -
  78882. + qtd->isoc_split_offset) <= 188) {
  78883. + qtd->isoc_split_pos =
  78884. + DWC_HCSPLIT_XACTPOS_END;
  78885. + } else {
  78886. + qtd->isoc_split_pos =
  78887. + DWC_HCSPLIT_XACTPOS_MID;
  78888. + }
  78889. +
  78890. + }
  78891. + break;
  78892. + }
  78893. + } else {
  78894. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  78895. + }
  78896. + } else {
  78897. + /*
  78898. + * An unmasked ACK on a non-split DMA transaction is
  78899. + * for the sole purpose of resetting error counts. Disable other
  78900. + * interrupts unmasked for the same reason.
  78901. + */
  78902. + if(hcd->core_if->dma_enable) {
  78903. + disable_hc_int(hc_regs, datatglerr);
  78904. + disable_hc_int(hc_regs, nak);
  78905. + }
  78906. + qtd->error_count = 0;
  78907. +
  78908. + if (hc->qh->ping_state) {
  78909. + hc->qh->ping_state = 0;
  78910. + /*
  78911. + * Halt the channel so the transfer can be re-started
  78912. + * from the appropriate point. This only happens in
  78913. + * Slave mode. In DMA mode, the ping_state is cleared
  78914. + * when the transfer is started because the core
  78915. + * automatically executes the PING, then the transfer.
  78916. + */
  78917. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  78918. + }
  78919. + }
  78920. +
  78921. + /*
  78922. + * If the ACK occurred when _not_ in the PING state, let the channel
  78923. + * continue transferring data after clearing the error count.
  78924. + */
  78925. +
  78926. + disable_hc_int(hc_regs, ack);
  78927. +
  78928. + return 1;
  78929. +}
  78930. +
  78931. +/**
  78932. + * Handles a host channel NYET interrupt. This interrupt should only occur on
  78933. + * Bulk and Control OUT endpoints and for complete split transactions. If a
  78934. + * NYET occurs at the same time as a Transfer Complete interrupt, it is
  78935. + * handled in the xfercomp interrupt handler, not here. This handler may be
  78936. + * called in either DMA mode or Slave mode.
  78937. + */
  78938. +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
  78939. + dwc_hc_t * hc,
  78940. + dwc_otg_hc_regs_t * hc_regs,
  78941. + dwc_otg_qtd_t * qtd)
  78942. +{
  78943. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78944. + "NYET Received--\n", hc->hc_num);
  78945. +
  78946. + /*
  78947. + * NYET on CSPLIT
  78948. + * re-do the CSPLIT immediately on non-periodic
  78949. + */
  78950. + if (hc->do_split && hc->complete_split) {
  78951. + if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  78952. + && hcd->core_if->dma_enable) {
  78953. + qtd->complete_split = 0;
  78954. + qtd->isoc_split_offset = 0;
  78955. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  78956. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  78957. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78958. + }
  78959. + else
  78960. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  78961. + goto handle_nyet_done;
  78962. + }
  78963. +
  78964. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  78965. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  78966. + int frnum = dwc_otg_hcd_get_frame_number(hcd);
  78967. +
  78968. + // With the FIQ running we only ever see the failed NYET
  78969. + if (dwc_full_frame_num(frnum) !=
  78970. + dwc_full_frame_num(hc->qh->sched_frame) ||
  78971. + fiq_fsm_enable) {
  78972. + /*
  78973. + * No longer in the same full speed frame.
  78974. + * Treat this as a transaction error.
  78975. + */
  78976. +#if 0
  78977. + /** @todo Fix system performance so this can
  78978. + * be treated as an error. Right now complete
  78979. + * splits cannot be scheduled precisely enough
  78980. + * due to other system activity, so this error
  78981. + * occurs regularly in Slave mode.
  78982. + */
  78983. + qtd->error_count++;
  78984. +#endif
  78985. + qtd->complete_split = 0;
  78986. + halt_channel(hcd, hc, qtd,
  78987. + DWC_OTG_HC_XFER_XACT_ERR);
  78988. + /** @todo add support for isoc release */
  78989. + goto handle_nyet_done;
  78990. + }
  78991. + }
  78992. +
  78993. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  78994. + goto handle_nyet_done;
  78995. + }
  78996. +
  78997. + hc->qh->ping_state = 1;
  78998. + qtd->error_count = 0;
  78999. +
  79000. + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
  79001. + DWC_OTG_HC_XFER_NYET);
  79002. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79003. +
  79004. + /*
  79005. + * Halt the channel and re-start the transfer so the PING
  79006. + * protocol will start.
  79007. + */
  79008. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  79009. +
  79010. +handle_nyet_done:
  79011. + disable_hc_int(hc_regs, nyet);
  79012. + return 1;
  79013. +}
  79014. +
  79015. +/**
  79016. + * Handles a host channel babble interrupt. This handler may be called in
  79017. + * either DMA mode or Slave mode.
  79018. + */
  79019. +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
  79020. + dwc_hc_t * hc,
  79021. + dwc_otg_hc_regs_t * hc_regs,
  79022. + dwc_otg_qtd_t * qtd)
  79023. +{
  79024. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79025. + "Babble Error--\n", hc->hc_num);
  79026. +
  79027. + if (hcd->core_if->dma_desc_enable) {
  79028. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  79029. + DWC_OTG_HC_XFER_BABBLE_ERR);
  79030. + goto handle_babble_done;
  79031. + }
  79032. +
  79033. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  79034. + hcd->fops->complete(hcd, qtd->urb->priv,
  79035. + qtd->urb, -DWC_E_OVERFLOW);
  79036. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
  79037. + } else {
  79038. + dwc_otg_halt_status_e halt_status;
  79039. + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  79040. + DWC_OTG_HC_XFER_BABBLE_ERR);
  79041. + halt_channel(hcd, hc, qtd, halt_status);
  79042. + }
  79043. +
  79044. +handle_babble_done:
  79045. + disable_hc_int(hc_regs, bblerr);
  79046. + return 1;
  79047. +}
  79048. +
  79049. +/**
  79050. + * Handles a host channel AHB error interrupt. This handler is only called in
  79051. + * DMA mode.
  79052. + */
  79053. +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
  79054. + dwc_hc_t * hc,
  79055. + dwc_otg_hc_regs_t * hc_regs,
  79056. + dwc_otg_qtd_t * qtd)
  79057. +{
  79058. + hcchar_data_t hcchar;
  79059. + hcsplt_data_t hcsplt;
  79060. + hctsiz_data_t hctsiz;
  79061. + uint32_t hcdma;
  79062. + char *pipetype, *speed;
  79063. +
  79064. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  79065. +
  79066. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79067. + "AHB Error--\n", hc->hc_num);
  79068. +
  79069. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  79070. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  79071. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  79072. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  79073. +
  79074. + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
  79075. + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
  79076. + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
  79077. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
  79078. + DWC_ERROR(" Device address: %d\n",
  79079. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  79080. + DWC_ERROR(" Endpoint: %d, %s\n",
  79081. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  79082. + (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
  79083. +
  79084. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  79085. + case UE_CONTROL:
  79086. + pipetype = "CONTROL";
  79087. + break;
  79088. + case UE_BULK:
  79089. + pipetype = "BULK";
  79090. + break;
  79091. + case UE_INTERRUPT:
  79092. + pipetype = "INTERRUPT";
  79093. + break;
  79094. + case UE_ISOCHRONOUS:
  79095. + pipetype = "ISOCHRONOUS";
  79096. + break;
  79097. + default:
  79098. + pipetype = "UNKNOWN";
  79099. + break;
  79100. + }
  79101. +
  79102. + DWC_ERROR(" Endpoint type: %s\n", pipetype);
  79103. +
  79104. + switch (hc->speed) {
  79105. + case DWC_OTG_EP_SPEED_HIGH:
  79106. + speed = "HIGH";
  79107. + break;
  79108. + case DWC_OTG_EP_SPEED_FULL:
  79109. + speed = "FULL";
  79110. + break;
  79111. + case DWC_OTG_EP_SPEED_LOW:
  79112. + speed = "LOW";
  79113. + break;
  79114. + default:
  79115. + speed = "UNKNOWN";
  79116. + break;
  79117. + };
  79118. +
  79119. + DWC_ERROR(" Speed: %s\n", speed);
  79120. +
  79121. + DWC_ERROR(" Max packet size: %d\n",
  79122. + dwc_otg_hcd_get_mps(&urb->pipe_info));
  79123. + DWC_ERROR(" Data buffer length: %d\n", urb->length);
  79124. + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
  79125. + urb->buf, (void *)urb->dma);
  79126. + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
  79127. + urb->setup_packet, (void *)urb->setup_dma);
  79128. + DWC_ERROR(" Interval: %d\n", urb->interval);
  79129. +
  79130. + /* Core haltes the channel for Descriptor DMA mode */
  79131. + if (hcd->core_if->dma_desc_enable) {
  79132. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  79133. + DWC_OTG_HC_XFER_AHB_ERR);
  79134. + goto handle_ahberr_done;
  79135. + }
  79136. +
  79137. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
  79138. +
  79139. + /*
  79140. + * Force a channel halt. Don't call halt_channel because that won't
  79141. + * write to the HCCHARn register in DMA mode to force the halt.
  79142. + */
  79143. + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
  79144. +handle_ahberr_done:
  79145. + disable_hc_int(hc_regs, ahberr);
  79146. + return 1;
  79147. +}
  79148. +
  79149. +/**
  79150. + * Handles a host channel transaction error interrupt. This handler may be
  79151. + * called in either DMA mode or Slave mode.
  79152. + */
  79153. +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
  79154. + dwc_hc_t * hc,
  79155. + dwc_otg_hc_regs_t * hc_regs,
  79156. + dwc_otg_qtd_t * qtd)
  79157. +{
  79158. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79159. + "Transaction Error--\n", hc->hc_num);
  79160. +
  79161. + if (hcd->core_if->dma_desc_enable) {
  79162. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  79163. + DWC_OTG_HC_XFER_XACT_ERR);
  79164. + goto handle_xacterr_done;
  79165. + }
  79166. +
  79167. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  79168. + case UE_CONTROL:
  79169. + case UE_BULK:
  79170. + qtd->error_count++;
  79171. + if (!hc->qh->ping_state) {
  79172. +
  79173. + update_urb_state_xfer_intr(hc, hc_regs,
  79174. + qtd->urb, qtd,
  79175. + DWC_OTG_HC_XFER_XACT_ERR);
  79176. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79177. + if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  79178. + hc->qh->ping_state = 1;
  79179. + }
  79180. + }
  79181. +
  79182. + /*
  79183. + * Halt the channel so the transfer can be re-started from
  79184. + * the appropriate point or the PING protocol will start.
  79185. + */
  79186. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79187. + break;
  79188. + case UE_INTERRUPT:
  79189. + qtd->error_count++;
  79190. + if (hc->do_split && hc->complete_split) {
  79191. + qtd->complete_split = 0;
  79192. + }
  79193. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79194. + break;
  79195. + case UE_ISOCHRONOUS:
  79196. + {
  79197. + dwc_otg_halt_status_e halt_status;
  79198. + halt_status =
  79199. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  79200. + DWC_OTG_HC_XFER_XACT_ERR);
  79201. +
  79202. + halt_channel(hcd, hc, qtd, halt_status);
  79203. + }
  79204. + break;
  79205. + }
  79206. +handle_xacterr_done:
  79207. + disable_hc_int(hc_regs, xacterr);
  79208. +
  79209. + return 1;
  79210. +}
  79211. +
  79212. +/**
  79213. + * Handles a host channel frame overrun interrupt. This handler may be called
  79214. + * in either DMA mode or Slave mode.
  79215. + */
  79216. +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
  79217. + dwc_hc_t * hc,
  79218. + dwc_otg_hc_regs_t * hc_regs,
  79219. + dwc_otg_qtd_t * qtd)
  79220. +{
  79221. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79222. + "Frame Overrun--\n", hc->hc_num);
  79223. +
  79224. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  79225. + case UE_CONTROL:
  79226. + case UE_BULK:
  79227. + break;
  79228. + case UE_INTERRUPT:
  79229. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
  79230. + break;
  79231. + case UE_ISOCHRONOUS:
  79232. + {
  79233. + dwc_otg_halt_status_e halt_status;
  79234. + halt_status =
  79235. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  79236. + DWC_OTG_HC_XFER_FRAME_OVERRUN);
  79237. +
  79238. + halt_channel(hcd, hc, qtd, halt_status);
  79239. + }
  79240. + break;
  79241. + }
  79242. +
  79243. + disable_hc_int(hc_regs, frmovrun);
  79244. +
  79245. + return 1;
  79246. +}
  79247. +
  79248. +/**
  79249. + * Handles a host channel data toggle error interrupt. This handler may be
  79250. + * called in either DMA mode or Slave mode.
  79251. + */
  79252. +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
  79253. + dwc_hc_t * hc,
  79254. + dwc_otg_hc_regs_t * hc_regs,
  79255. + dwc_otg_qtd_t * qtd)
  79256. +{
  79257. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79258. + "Data Toggle Error on %s transfer--\n",
  79259. + hc->hc_num, (hc->ep_is_in ? "IN" : "OUT"));
  79260. +
  79261. + /* Data toggles on split transactions cause the hc to halt.
  79262. + * restart transfer */
  79263. + if(hc->qh->do_split)
  79264. + {
  79265. + qtd->error_count++;
  79266. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79267. + update_urb_state_xfer_intr(hc, hc_regs,
  79268. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79269. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79270. + } else if (hc->ep_is_in) {
  79271. + /* An unmasked data toggle error on a non-split DMA transaction is
  79272. + * for the sole purpose of resetting error counts. Disable other
  79273. + * interrupts unmasked for the same reason.
  79274. + */
  79275. + if(hcd->core_if->dma_enable) {
  79276. + disable_hc_int(hc_regs, ack);
  79277. + disable_hc_int(hc_regs, nak);
  79278. + }
  79279. + qtd->error_count = 0;
  79280. + }
  79281. +
  79282. + disable_hc_int(hc_regs, datatglerr);
  79283. +
  79284. + return 1;
  79285. +}
  79286. +
  79287. +#ifdef DEBUG
  79288. +/**
  79289. + * This function is for debug only. It checks that a valid halt status is set
  79290. + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
  79291. + * taken and a warning is issued.
  79292. + * @return 1 if halt status is ok, 0 otherwise.
  79293. + */
  79294. +static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
  79295. + dwc_hc_t * hc,
  79296. + dwc_otg_hc_regs_t * hc_regs,
  79297. + dwc_otg_qtd_t * qtd)
  79298. +{
  79299. + hcchar_data_t hcchar;
  79300. + hctsiz_data_t hctsiz;
  79301. + hcint_data_t hcint;
  79302. + hcintmsk_data_t hcintmsk;
  79303. + hcsplt_data_t hcsplt;
  79304. +
  79305. + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
  79306. + /*
  79307. + * This code is here only as a check. This condition should
  79308. + * never happen. Ignore the halt if it does occur.
  79309. + */
  79310. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  79311. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  79312. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  79313. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  79314. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  79315. + DWC_WARN
  79316. + ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
  79317. + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
  79318. + "hcint 0x%08x, hcintmsk 0x%08x, "
  79319. + "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
  79320. + hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
  79321. + hcintmsk.d32, hcsplt.d32, qtd->complete_split);
  79322. +
  79323. + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
  79324. + __func__, hc->hc_num);
  79325. + DWC_WARN("\n");
  79326. + clear_hc_int(hc_regs, chhltd);
  79327. + return 0;
  79328. + }
  79329. +
  79330. + /*
  79331. + * This code is here only as a check. hcchar.chdis should
  79332. + * never be set when the halt interrupt occurs. Halt the
  79333. + * channel again if it does occur.
  79334. + */
  79335. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  79336. + if (hcchar.b.chdis) {
  79337. + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
  79338. + "hcchar 0x%08x, trying to halt again\n",
  79339. + __func__, hcchar.d32);
  79340. + clear_hc_int(hc_regs, chhltd);
  79341. + hc->halt_pending = 0;
  79342. + halt_channel(hcd, hc, qtd, hc->halt_status);
  79343. + return 0;
  79344. + }
  79345. +
  79346. + return 1;
  79347. +}
  79348. +#endif
  79349. +
  79350. +/**
  79351. + * Handles a host Channel Halted interrupt in DMA mode. This handler
  79352. + * determines the reason the channel halted and proceeds accordingly.
  79353. + */
  79354. +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
  79355. + dwc_hc_t * hc,
  79356. + dwc_otg_hc_regs_t * hc_regs,
  79357. + dwc_otg_qtd_t * qtd)
  79358. +{
  79359. + int out_nak_enh = 0;
  79360. + hcint_data_t hcint;
  79361. + hcintmsk_data_t hcintmsk;
  79362. + /* For core with OUT NAK enhancement, the flow for high-
  79363. + * speed CONTROL/BULK OUT is handled a little differently.
  79364. + */
  79365. + if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
  79366. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
  79367. + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  79368. + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
  79369. + out_nak_enh = 1;
  79370. + }
  79371. + }
  79372. +
  79373. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  79374. + (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
  79375. + && !hcd->core_if->dma_desc_enable)) {
  79376. + /*
  79377. + * Just release the channel. A dequeue can happen on a
  79378. + * transfer timeout. In the case of an AHB Error, the channel
  79379. + * was forced to halt because there's no way to gracefully
  79380. + * recover.
  79381. + */
  79382. + if (hcd->core_if->dma_desc_enable)
  79383. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  79384. + hc->halt_status);
  79385. + else
  79386. + release_channel(hcd, hc, qtd, hc->halt_status);
  79387. + return;
  79388. + }
  79389. +
  79390. + /* Read the HCINTn register to determine the cause for the halt. */
  79391. +
  79392. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  79393. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  79394. +
  79395. + if (hcint.b.xfercomp) {
  79396. + /** @todo This is here because of a possible hardware bug. Spec
  79397. + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  79398. + * interrupt w/ACK bit set should occur, but I only see the
  79399. + * XFERCOMP bit, even with it masked out. This is a workaround
  79400. + * for that behavior. Should fix this when hardware is fixed.
  79401. + */
  79402. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  79403. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  79404. + }
  79405. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  79406. + } else if (hcint.b.stall) {
  79407. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  79408. + } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
  79409. + if (out_nak_enh) {
  79410. + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
  79411. + DWC_DEBUGPL(DBG_HCD, "XactErr with NYET/NAK/ACK\n");
  79412. + qtd->error_count = 0;
  79413. + } else {
  79414. + DWC_DEBUGPL(DBG_HCD, "XactErr without NYET/NAK/ACK\n");
  79415. + }
  79416. + }
  79417. +
  79418. + /*
  79419. + * Must handle xacterr before nak or ack. Could get a xacterr
  79420. + * at the same time as either of these on a BULK/CONTROL OUT
  79421. + * that started with a PING. The xacterr takes precedence.
  79422. + */
  79423. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  79424. + } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
  79425. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  79426. + } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
  79427. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  79428. + } else if (hcint.b.bblerr) {
  79429. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  79430. + } else if (hcint.b.frmovrun) {
  79431. + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
  79432. + } else if (hcint.b.datatglerr) {
  79433. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  79434. + } else if (!out_nak_enh) {
  79435. + if (hcint.b.nyet) {
  79436. + /*
  79437. + * Must handle nyet before nak or ack. Could get a nyet at the
  79438. + * same time as either of those on a BULK/CONTROL OUT that
  79439. + * started with a PING. The nyet takes precedence.
  79440. + */
  79441. + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
  79442. + } else if (hcint.b.nak && !hcintmsk.b.nak) {
  79443. + /*
  79444. + * If nak is not masked, it's because a non-split IN transfer
  79445. + * is in an error state. In that case, the nak is handled by
  79446. + * the nak interrupt handler, not here. Handle nak here for
  79447. + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
  79448. + * rewinding the buffer pointer.
  79449. + */
  79450. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  79451. + } else if (hcint.b.ack && !hcintmsk.b.ack) {
  79452. + /*
  79453. + * If ack is not masked, it's because a non-split IN transfer
  79454. + * is in an error state. In that case, the ack is handled by
  79455. + * the ack interrupt handler, not here. Handle ack here for
  79456. + * split transfers. Start splits halt on ACK.
  79457. + */
  79458. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  79459. + } else {
  79460. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  79461. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  79462. + /*
  79463. + * A periodic transfer halted with no other channel
  79464. + * interrupts set. Assume it was halted by the core
  79465. + * because it could not be completed in its scheduled
  79466. + * (micro)frame.
  79467. + */
  79468. +#ifdef DEBUG
  79469. + DWC_PRINTF
  79470. + ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
  79471. + __func__, hc->hc_num);
  79472. +#endif
  79473. + halt_channel(hcd, hc, qtd,
  79474. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
  79475. + } else {
  79476. + DWC_ERROR
  79477. + ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
  79478. + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
  79479. + __func__, hc->hc_num, hcint.d32,
  79480. + DWC_READ_REG32(&hcd->
  79481. + core_if->core_global_regs->
  79482. + gintsts));
  79483. + /* Failthrough: use 3-strikes rule */
  79484. + qtd->error_count++;
  79485. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79486. + update_urb_state_xfer_intr(hc, hc_regs,
  79487. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79488. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79489. + }
  79490. +
  79491. + }
  79492. + } else {
  79493. + DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  79494. + hcint.d32);
  79495. + /* Failthrough: use 3-strikes rule */
  79496. + qtd->error_count++;
  79497. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79498. + update_urb_state_xfer_intr(hc, hc_regs,
  79499. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79500. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79501. + }
  79502. +}
  79503. +
  79504. +/**
  79505. + * Handles a host channel Channel Halted interrupt.
  79506. + *
  79507. + * In slave mode, this handler is called only when the driver specifically
  79508. + * requests a halt. This occurs during handling other host channel interrupts
  79509. + * (e.g. nak, xacterr, stall, nyet, etc.).
  79510. + *
  79511. + * In DMA mode, this is the interrupt that occurs when the core has finished
  79512. + * processing a transfer on a channel. Other host channel interrupts (except
  79513. + * ahberr) are disabled in DMA mode.
  79514. + */
  79515. +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  79516. + dwc_hc_t * hc,
  79517. + dwc_otg_hc_regs_t * hc_regs,
  79518. + dwc_otg_qtd_t * qtd)
  79519. +{
  79520. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79521. + "Channel Halted--\n", hc->hc_num);
  79522. +
  79523. + if (hcd->core_if->dma_enable) {
  79524. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
  79525. + } else {
  79526. +#ifdef DEBUG
  79527. + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  79528. + return 1;
  79529. + }
  79530. +#endif
  79531. + release_channel(hcd, hc, qtd, hc->halt_status);
  79532. + }
  79533. +
  79534. + return 1;
  79535. +}
  79536. +
  79537. +
  79538. +/**
  79539. + * dwc_otg_fiq_unmangle_isoc() - Update the iso_frame_desc structure on
  79540. + * FIQ transfer completion
  79541. + * @hcd: Pointer to dwc_otg_hcd struct
  79542. + * @num: Host channel number
  79543. + *
  79544. + * 1. Un-mangle the status as recorded in each iso_frame_desc status
  79545. + * 2. Copy it from the dwc_otg_urb into the real URB
  79546. + */
  79547. +void dwc_otg_fiq_unmangle_isoc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  79548. +{
  79549. + struct dwc_otg_hcd_urb *dwc_urb = qtd->urb;
  79550. + int nr_frames = dwc_urb->packet_count;
  79551. + int i;
  79552. + hcint_data_t frame_hcint;
  79553. +
  79554. + for (i = 0; i < nr_frames; i++) {
  79555. + frame_hcint.d32 = dwc_urb->iso_descs[i].status;
  79556. + if (frame_hcint.b.xfercomp) {
  79557. + dwc_urb->iso_descs[i].status = 0;
  79558. + dwc_urb->actual_length += dwc_urb->iso_descs[i].actual_length;
  79559. + } else if (frame_hcint.b.frmovrun) {
  79560. + if (qh->ep_is_in)
  79561. + dwc_urb->iso_descs[i].status = -DWC_E_NO_STREAM_RES;
  79562. + else
  79563. + dwc_urb->iso_descs[i].status = -DWC_E_COMMUNICATION;
  79564. + dwc_urb->error_count++;
  79565. + dwc_urb->iso_descs[i].actual_length = 0;
  79566. + } else if (frame_hcint.b.xacterr) {
  79567. + dwc_urb->iso_descs[i].status = -DWC_E_PROTOCOL;
  79568. + dwc_urb->error_count++;
  79569. + dwc_urb->iso_descs[i].actual_length = 0;
  79570. + } else if (frame_hcint.b.bblerr) {
  79571. + dwc_urb->iso_descs[i].status = -DWC_E_OVERFLOW;
  79572. + dwc_urb->error_count++;
  79573. + dwc_urb->iso_descs[i].actual_length = 0;
  79574. + } else {
  79575. + /* Something went wrong */
  79576. + dwc_urb->iso_descs[i].status = -1;
  79577. + dwc_urb->iso_descs[i].actual_length = 0;
  79578. + dwc_urb->error_count++;
  79579. + }
  79580. + }
  79581. + //printk_ratelimited(KERN_INFO "%s: HS isochronous of %d/%d frames with %d errors complete\n",
  79582. + // __FUNCTION__, i, dwc_urb->packet_count, dwc_urb->error_count);
  79583. + hcd->fops->complete(hcd, dwc_urb->priv, dwc_urb, 0);
  79584. + release_channel(hcd, qh->channel, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79585. +}
  79586. +
  79587. +/**
  79588. + * dwc_otg_fiq_unsetup_per_dma() - Remove data from bounce buffers for split transactions
  79589. + * @hcd: Pointer to dwc_otg_hcd struct
  79590. + * @num: Host channel number
  79591. + *
  79592. + * Copies data from the FIQ bounce buffers into the URB's transfer buffer. Does not modify URB state.
  79593. + * Returns total length of data or -1 if the buffers were not used.
  79594. + *
  79595. + */
  79596. +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)
  79597. +{
  79598. + dwc_hc_t *hc = qh->channel;
  79599. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  79600. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  79601. + uint8_t *ptr = NULL;
  79602. + int index = 0, len = 0;
  79603. + int i = 0;
  79604. + if (hc->ep_is_in) {
  79605. + /* Copy data out of the DMA bounce buffers to the URB's buffer.
  79606. + * The align_buf is ignored as this is ignored on FSM enqueue. */
  79607. + ptr = qtd->urb->buf;
  79608. + if (qh->ep_type == UE_ISOCHRONOUS) {
  79609. + /* Isoc IN transactions - grab the offset of the iso_frame_desc into the URB transfer buffer */
  79610. + index = qtd->isoc_frame_index;
  79611. + ptr += qtd->urb->iso_descs[index].offset;
  79612. + } else {
  79613. + /* Need to increment by actual_length for interrupt IN */
  79614. + ptr += qtd->urb->actual_length;
  79615. + }
  79616. +
  79617. + for (i = 0; i < st->dma_info.index; i++) {
  79618. + len += st->dma_info.slot_len[i];
  79619. + dwc_memcpy(ptr, &blob->channel[num].index[i].buf[0], st->dma_info.slot_len[i]);
  79620. + ptr += st->dma_info.slot_len[i];
  79621. + }
  79622. + return len;
  79623. + } else {
  79624. + /* OUT endpoints - nothing to do. */
  79625. + return -1;
  79626. + }
  79627. +
  79628. +}
  79629. +/**
  79630. + * dwc_otg_hcd_handle_hc_fsm() - handle an unmasked channel interrupt
  79631. + * from a channel handled in the FIQ
  79632. + * @hcd: Pointer to dwc_otg_hcd struct
  79633. + * @num: Host channel number
  79634. + *
  79635. + * If a host channel interrupt was received by the IRQ and this was a channel
  79636. + * used by the FIQ, the execution flow for transfer completion is substantially
  79637. + * different from the normal (messy) path. This function and its friends handles
  79638. + * channel cleanup and transaction completion from a FIQ transaction.
  79639. + */
  79640. +int32_t dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd_t *hcd, uint32_t num)
  79641. +{
  79642. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  79643. + dwc_hc_t *hc = hcd->hc_ptr_array[num];
  79644. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  79645. + dwc_otg_qh_t *qh = hc->qh;
  79646. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[num];
  79647. + hcint_data_t hcint = hcd->fiq_state->channel[num].hcint_copy;
  79648. + int hostchannels = 0;
  79649. + int ret = 0;
  79650. + fiq_print(FIQDBG_INT, hcd->fiq_state, "OUT %01d %01d ", num , st->fsm);
  79651. +
  79652. + hostchannels = hcd->available_host_channels;
  79653. + switch (st->fsm) {
  79654. + case FIQ_TEST:
  79655. + break;
  79656. +
  79657. + case FIQ_DEQUEUE_ISSUED:
  79658. + /* hc_halt was called. QTD no longer exists. */
  79659. + /* TODO: for a nonperiodic split transaction, need to issue a
  79660. + * CLEAR_TT_BUFFER hub command if we were in the start-split phase.
  79661. + */
  79662. + release_channel(hcd, hc, NULL, hc->halt_status);
  79663. + ret = 1;
  79664. + break;
  79665. +
  79666. + case FIQ_NP_SPLIT_DONE:
  79667. + /* Nonperiodic transaction complete. */
  79668. + if (!hc->ep_is_in) {
  79669. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  79670. + }
  79671. + if (hcint.b.xfercomp) {
  79672. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  79673. + } else if (hcint.b.nak) {
  79674. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  79675. + }
  79676. + ret = 1;
  79677. + break;
  79678. +
  79679. + case FIQ_NP_SPLIT_HS_ABORTED:
  79680. + /* A HS abort is a 3-strikes on the HS bus at any point in the transaction.
  79681. + * Normally a CLEAR_TT_BUFFER hub command would be required: we can't do that
  79682. + * because there's no guarantee which order a non-periodic split happened in.
  79683. + * We could end up clearing a perfectly good transaction out of the buffer.
  79684. + */
  79685. + if (hcint.b.xacterr) {
  79686. + qtd->error_count += st->nr_errors;
  79687. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  79688. + } else if (hcint.b.ahberr) {
  79689. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  79690. + } else {
  79691. + local_fiq_disable();
  79692. + BUG();
  79693. + }
  79694. + break;
  79695. +
  79696. + case FIQ_NP_SPLIT_LS_ABORTED:
  79697. + /* A few cases can cause this - either an unknown state on a SSPLIT or
  79698. + * STALL/data toggle error response on a CSPLIT */
  79699. + if (hcint.b.stall) {
  79700. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  79701. + } else if (hcint.b.datatglerr) {
  79702. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  79703. + } else if (hcint.b.ahberr) {
  79704. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  79705. + } else {
  79706. + local_fiq_disable();
  79707. + BUG();
  79708. + }
  79709. + break;
  79710. +
  79711. + case FIQ_PER_SPLIT_DONE:
  79712. + /* Isoc IN or Interrupt IN/OUT */
  79713. +
  79714. + /* Flow control here is different from the normal execution by the driver.
  79715. + * We need to completely ignore most of the driver's method of handling
  79716. + * split transactions and do it ourselves.
  79717. + */
  79718. + if (hc->ep_type == UE_INTERRUPT) {
  79719. + if (hcint.b.nak) {
  79720. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  79721. + } else if (hc->ep_is_in) {
  79722. + int len;
  79723. + len = dwc_otg_fiq_unsetup_per_dma(hcd, hc->qh, qtd, num);
  79724. + //printk(KERN_NOTICE "FIQ Transaction: hc=%d len=%d urb_len = %d\n", num, len, qtd->urb->length);
  79725. + qtd->urb->actual_length += len;
  79726. + if (qtd->urb->actual_length >= qtd->urb->length) {
  79727. + qtd->urb->status = 0;
  79728. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  79729. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79730. + } else {
  79731. + /* Interrupt transfer not complete yet - is it a short read? */
  79732. + if (len < hc->max_packet) {
  79733. + /* Interrupt transaction complete */
  79734. + qtd->urb->status = 0;
  79735. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  79736. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79737. + } else {
  79738. + /* Further transactions required */
  79739. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  79740. + }
  79741. + }
  79742. + } else {
  79743. + /* Interrupt OUT complete. */
  79744. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79745. + qtd->urb->actual_length += hc->xfer_len;
  79746. + if (qtd->urb->actual_length >= qtd->urb->length) {
  79747. + qtd->urb->status = 0;
  79748. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  79749. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79750. + } else {
  79751. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  79752. + }
  79753. + }
  79754. + } else {
  79755. + /* ISOC IN complete. */
  79756. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  79757. + int len = 0;
  79758. + /* Record errors, update qtd. */
  79759. + if (st->nr_errors) {
  79760. + frame_desc->actual_length = 0;
  79761. + frame_desc->status = -DWC_E_PROTOCOL;
  79762. + } else {
  79763. + frame_desc->status = 0;
  79764. + /* Unswizzle dma */
  79765. + len = dwc_otg_fiq_unsetup_per_dma(hcd, qh, qtd, num);
  79766. + frame_desc->actual_length = len;
  79767. + }
  79768. + qtd->isoc_frame_index++;
  79769. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  79770. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  79771. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79772. + } else {
  79773. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  79774. + }
  79775. + }
  79776. + break;
  79777. +
  79778. + case FIQ_PER_ISO_OUT_DONE: {
  79779. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  79780. + /* Record errors, update qtd. */
  79781. + if (st->nr_errors) {
  79782. + frame_desc->actual_length = 0;
  79783. + frame_desc->status = -DWC_E_PROTOCOL;
  79784. + } else {
  79785. + frame_desc->status = 0;
  79786. + frame_desc->actual_length = frame_desc->length;
  79787. + }
  79788. + qtd->isoc_frame_index++;
  79789. + qtd->isoc_split_offset = 0;
  79790. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  79791. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  79792. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79793. + } else {
  79794. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  79795. + }
  79796. + }
  79797. + break;
  79798. +
  79799. + case FIQ_PER_SPLIT_NYET_ABORTED:
  79800. + /* Doh. lost the data. */
  79801. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  79802. + "- FIQ reported NYET. Data may have been lost.\n",
  79803. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  79804. + if (hc->ep_type == UE_ISOCHRONOUS) {
  79805. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  79806. + /* Record errors, update qtd. */
  79807. + frame_desc->actual_length = 0;
  79808. + frame_desc->status = -DWC_E_PROTOCOL;
  79809. + qtd->isoc_frame_index++;
  79810. + qtd->isoc_split_offset = 0;
  79811. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  79812. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  79813. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79814. + } else {
  79815. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  79816. + }
  79817. + } else {
  79818. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  79819. + }
  79820. + break;
  79821. +
  79822. + case FIQ_HS_ISOC_DONE:
  79823. + /* The FIQ has performed a whole pile of isochronous transactions.
  79824. + * The status is recorded as the interrupt state should the transaction
  79825. + * fail.
  79826. + */
  79827. + dwc_otg_fiq_unmangle_isoc(hcd, qh, qtd, num);
  79828. + break;
  79829. +
  79830. + case FIQ_PER_SPLIT_LS_ABORTED:
  79831. + if (hcint.b.xacterr) {
  79832. + /* Hub has responded with an ERR packet. Device
  79833. + * has been unplugged or the port has been disabled.
  79834. + * TODO: need to issue a reset to the hub port. */
  79835. + qtd->error_count += 3;
  79836. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  79837. + } else if (hcint.b.stall) {
  79838. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  79839. + } else {
  79840. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
  79841. + "- FIQ reported FSM=%d. Data may have been lost.\n",
  79842. + st->fsm, hc->dev_addr, hc->ep_num);
  79843. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  79844. + }
  79845. + break;
  79846. +
  79847. + case FIQ_PER_SPLIT_HS_ABORTED:
  79848. + /* Either the SSPLIT phase suffered transaction errors or something
  79849. + * unexpected happened.
  79850. + */
  79851. + qtd->error_count += 3;
  79852. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  79853. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  79854. + break;
  79855. +
  79856. + case FIQ_PER_SPLIT_TIMEOUT:
  79857. + /* Couldn't complete in the nominated frame */
  79858. + printk(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  79859. + "- FIQ timed out. Data may have been lost.\n",
  79860. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  79861. + if (hc->ep_type == UE_ISOCHRONOUS) {
  79862. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  79863. + /* Record errors, update qtd. */
  79864. + frame_desc->actual_length = 0;
  79865. + if (hc->ep_is_in) {
  79866. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  79867. + } else {
  79868. + frame_desc->status = -DWC_E_COMMUNICATION;
  79869. + }
  79870. + qtd->isoc_frame_index++;
  79871. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  79872. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  79873. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79874. + } else {
  79875. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  79876. + }
  79877. + } else {
  79878. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  79879. + }
  79880. + break;
  79881. +
  79882. + default:
  79883. + local_fiq_disable();
  79884. + DWC_WARN("unexpected state received on hc=%d fsm=%d", hc->hc_num, st->fsm);
  79885. + BUG();
  79886. + }
  79887. + //if (hostchannels != hcd->available_host_channels) {
  79888. + /* should have incremented by now! */
  79889. + // BUG();
  79890. +// }
  79891. + return ret;
  79892. +}
  79893. +
  79894. +/** Handles interrupt for a specific Host Channel */
  79895. +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  79896. +{
  79897. + int retval = 0;
  79898. + hcint_data_t hcint;
  79899. + hcintmsk_data_t hcintmsk;
  79900. + dwc_hc_t *hc;
  79901. + dwc_otg_hc_regs_t *hc_regs;
  79902. + dwc_otg_qtd_t *qtd;
  79903. +
  79904. + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
  79905. +
  79906. + hc = dwc_otg_hcd->hc_ptr_array[num];
  79907. + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
  79908. + if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  79909. + /* We are responding to a channel disable. Driver
  79910. + * state is cleared - our qtd has gone away.
  79911. + */
  79912. + release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
  79913. + return 1;
  79914. + }
  79915. + qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  79916. +
  79917. + /*
  79918. + * FSM mode: Check to see if this is a HC interrupt from a channel handled by the FIQ.
  79919. + * Execution path is fundamentally different for the channels after a FIQ has completed
  79920. + * a split transaction.
  79921. + */
  79922. + if (fiq_fsm_enable) {
  79923. + switch (dwc_otg_hcd->fiq_state->channel[num].fsm) {
  79924. + case FIQ_PASSTHROUGH:
  79925. + break;
  79926. + case FIQ_PASSTHROUGH_ERRORSTATE:
  79927. + /* Hook into the error count */
  79928. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "HCDERR%02d", num);
  79929. + if (dwc_otg_hcd->fiq_state->channel[num].nr_errors) {
  79930. + qtd->error_count = 0;
  79931. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "RESET ");
  79932. + }
  79933. + break;
  79934. + default:
  79935. + dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd, num);
  79936. + return 1;
  79937. + }
  79938. + }
  79939. +
  79940. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  79941. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  79942. + hcint.d32 = hcint.d32 & hcintmsk.d32;
  79943. + if (!dwc_otg_hcd->core_if->dma_enable) {
  79944. + if (hcint.b.chhltd && hcint.d32 != 0x2) {
  79945. + hcint.b.chhltd = 0;
  79946. + }
  79947. + }
  79948. +
  79949. + if (hcint.b.xfercomp) {
  79950. + retval |=
  79951. + handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79952. + /*
  79953. + * If NYET occurred at same time as Xfer Complete, the NYET is
  79954. + * handled by the Xfer Complete interrupt handler. Don't want
  79955. + * to call the NYET interrupt handler in this case.
  79956. + */
  79957. + hcint.b.nyet = 0;
  79958. + }
  79959. + if (hcint.b.chhltd) {
  79960. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79961. + }
  79962. + if (hcint.b.ahberr) {
  79963. + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79964. + }
  79965. + if (hcint.b.stall) {
  79966. + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79967. + }
  79968. + if (hcint.b.nak) {
  79969. + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79970. + }
  79971. + if (hcint.b.ack) {
  79972. + if(!hcint.b.chhltd)
  79973. + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79974. + }
  79975. + if (hcint.b.nyet) {
  79976. + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79977. + }
  79978. + if (hcint.b.xacterr) {
  79979. + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79980. + }
  79981. + if (hcint.b.bblerr) {
  79982. + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79983. + }
  79984. + if (hcint.b.frmovrun) {
  79985. + retval |=
  79986. + handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79987. + }
  79988. + if (hcint.b.datatglerr) {
  79989. + retval |=
  79990. + handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79991. + }
  79992. +
  79993. + return retval;
  79994. +}
  79995. +#endif /* DWC_DEVICE_ONLY */
  79996. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  79997. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  79998. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 2014-04-24 16:04:39.819124254 +0200
  79999. @@ -0,0 +1,985 @@
  80000. +
  80001. +/* ==========================================================================
  80002. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_linux.c $
  80003. + * $Revision: #20 $
  80004. + * $Date: 2011/10/26 $
  80005. + * $Change: 1872981 $
  80006. + *
  80007. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  80008. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  80009. + * otherwise expressly agreed to in writing between Synopsys and you.
  80010. + *
  80011. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  80012. + * any End User Software License Agreement or Agreement for Licensed Product
  80013. + * with Synopsys or any supplement thereto. You are permitted to use and
  80014. + * redistribute this Software in source and binary forms, with or without
  80015. + * modification, provided that redistributions of source code must retain this
  80016. + * notice. You may not view, use, disclose, copy or distribute this file or
  80017. + * any information contained herein except pursuant to this license grant from
  80018. + * Synopsys. If you do not agree with this notice, including the disclaimer
  80019. + * below, then you are not authorized to use the Software.
  80020. + *
  80021. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  80022. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  80023. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  80024. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  80025. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  80026. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  80027. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  80028. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  80029. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  80030. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  80031. + * DAMAGE.
  80032. + * ========================================================================== */
  80033. +#ifndef DWC_DEVICE_ONLY
  80034. +
  80035. +/**
  80036. + * @file
  80037. + *
  80038. + * This file contains the implementation of the HCD. In Linux, the HCD
  80039. + * implements the hc_driver API.
  80040. + */
  80041. +#include <linux/kernel.h>
  80042. +#include <linux/module.h>
  80043. +#include <linux/moduleparam.h>
  80044. +#include <linux/init.h>
  80045. +#include <linux/device.h>
  80046. +#include <linux/errno.h>
  80047. +#include <linux/list.h>
  80048. +#include <linux/interrupt.h>
  80049. +#include <linux/string.h>
  80050. +#include <linux/dma-mapping.h>
  80051. +#include <linux/version.h>
  80052. +#include <asm/io.h>
  80053. +#include <asm/fiq.h>
  80054. +#include <linux/usb.h>
  80055. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
  80056. +#include <../drivers/usb/core/hcd.h>
  80057. +#else
  80058. +#include <linux/usb/hcd.h>
  80059. +#endif
  80060. +#include <asm/bug.h>
  80061. +
  80062. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  80063. +#define USB_URB_EP_LINKING 1
  80064. +#else
  80065. +#define USB_URB_EP_LINKING 0
  80066. +#endif
  80067. +
  80068. +#include "dwc_otg_hcd_if.h"
  80069. +#include "dwc_otg_dbg.h"
  80070. +#include "dwc_otg_driver.h"
  80071. +#include "dwc_otg_hcd.h"
  80072. +
  80073. +extern unsigned char _dwc_otg_fiq_stub, _dwc_otg_fiq_stub_end;
  80074. +
  80075. +/**
  80076. + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  80077. + * qualified with its direction (possible 32 endpoints per device).
  80078. + */
  80079. +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
  80080. + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
  80081. +
  80082. +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  80083. +
  80084. +extern bool fiq_enable;
  80085. +
  80086. +/** @name Linux HC Driver API Functions */
  80087. +/** @{ */
  80088. +/* manage i/o requests, device state */
  80089. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  80090. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80091. + struct usb_host_endpoint *ep,
  80092. +#endif
  80093. + struct urb *urb, gfp_t mem_flags);
  80094. +
  80095. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  80096. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80097. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
  80098. +#endif
  80099. +#else /* kernels at or post 2.6.30 */
  80100. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd,
  80101. + struct urb *urb, int status);
  80102. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
  80103. +
  80104. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  80105. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  80106. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  80107. +#endif
  80108. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
  80109. +extern int hcd_start(struct usb_hcd *hcd);
  80110. +extern void hcd_stop(struct usb_hcd *hcd);
  80111. +static int get_frame_number(struct usb_hcd *hcd);
  80112. +extern int hub_status_data(struct usb_hcd *hcd, char *buf);
  80113. +extern int hub_control(struct usb_hcd *hcd,
  80114. + u16 typeReq,
  80115. + u16 wValue, u16 wIndex, char *buf, u16 wLength);
  80116. +
  80117. +struct wrapper_priv_data {
  80118. + dwc_otg_hcd_t *dwc_otg_hcd;
  80119. +};
  80120. +
  80121. +/** @} */
  80122. +
  80123. +static struct hc_driver dwc_otg_hc_driver = {
  80124. +
  80125. + .description = dwc_otg_hcd_name,
  80126. + .product_desc = "DWC OTG Controller",
  80127. + .hcd_priv_size = sizeof(struct wrapper_priv_data),
  80128. +
  80129. + .irq = dwc_otg_hcd_irq,
  80130. +
  80131. + .flags = HCD_MEMORY | HCD_USB2,
  80132. +
  80133. + //.reset =
  80134. + .start = hcd_start,
  80135. + //.suspend =
  80136. + //.resume =
  80137. + .stop = hcd_stop,
  80138. +
  80139. + .urb_enqueue = dwc_otg_urb_enqueue,
  80140. + .urb_dequeue = dwc_otg_urb_dequeue,
  80141. + .endpoint_disable = endpoint_disable,
  80142. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  80143. + .endpoint_reset = endpoint_reset,
  80144. +#endif
  80145. + .get_frame_number = get_frame_number,
  80146. +
  80147. + .hub_status_data = hub_status_data,
  80148. + .hub_control = hub_control,
  80149. + //.bus_suspend =
  80150. + //.bus_resume =
  80151. +};
  80152. +
  80153. +/** Gets the dwc_otg_hcd from a struct usb_hcd */
  80154. +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
  80155. +{
  80156. + struct wrapper_priv_data *p;
  80157. + p = (struct wrapper_priv_data *)(hcd->hcd_priv);
  80158. + return p->dwc_otg_hcd;
  80159. +}
  80160. +
  80161. +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
  80162. +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t * dwc_otg_hcd)
  80163. +{
  80164. + return dwc_otg_hcd_get_priv_data(dwc_otg_hcd);
  80165. +}
  80166. +
  80167. +/** Gets the usb_host_endpoint associated with an URB. */
  80168. +inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
  80169. +{
  80170. + struct usb_device *dev = urb->dev;
  80171. + int ep_num = usb_pipeendpoint(urb->pipe);
  80172. +
  80173. + if (usb_pipein(urb->pipe))
  80174. + return dev->ep_in[ep_num];
  80175. + else
  80176. + return dev->ep_out[ep_num];
  80177. +}
  80178. +
  80179. +static int _disconnect(dwc_otg_hcd_t * hcd)
  80180. +{
  80181. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  80182. +
  80183. + usb_hcd->self.is_b_host = 0;
  80184. + return 0;
  80185. +}
  80186. +
  80187. +static int _start(dwc_otg_hcd_t * hcd)
  80188. +{
  80189. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  80190. +
  80191. + usb_hcd->self.is_b_host = dwc_otg_hcd_is_b_host(hcd);
  80192. + hcd_start(usb_hcd);
  80193. +
  80194. + return 0;
  80195. +}
  80196. +
  80197. +static int _hub_info(dwc_otg_hcd_t * hcd, void *urb_handle, uint32_t * hub_addr,
  80198. + uint32_t * port_addr)
  80199. +{
  80200. + struct urb *urb = (struct urb *)urb_handle;
  80201. + struct usb_bus *bus;
  80202. +#if 1 //GRAYG - temporary
  80203. + if (NULL == urb_handle)
  80204. + DWC_ERROR("**** %s - NULL URB handle\n", __func__);//GRAYG
  80205. + if (NULL == urb->dev)
  80206. + DWC_ERROR("**** %s - URB has no device\n", __func__);//GRAYG
  80207. + if (NULL == port_addr)
  80208. + DWC_ERROR("**** %s - NULL port_address\n", __func__);//GRAYG
  80209. +#endif
  80210. + if (urb->dev->tt) {
  80211. + if (NULL == urb->dev->tt->hub) {
  80212. + DWC_ERROR("**** %s - (URB's transactor has no TT - giving no hub)\n",
  80213. + __func__); //GRAYG
  80214. + //*hub_addr = (u8)usb_pipedevice(urb->pipe); //GRAYG
  80215. + *hub_addr = 0; //GRAYG
  80216. + // we probably shouldn't have a transaction translator if
  80217. + // there's no associated hub?
  80218. + } else {
  80219. + bus = hcd_to_bus(dwc_otg_hcd_to_hcd(hcd));
  80220. + if (urb->dev->tt->hub == bus->root_hub)
  80221. + *hub_addr = 0;
  80222. + else
  80223. + *hub_addr = urb->dev->tt->hub->devnum;
  80224. + }
  80225. + *port_addr = urb->dev->tt->multi ? urb->dev->ttport : 1;
  80226. + } else {
  80227. + *hub_addr = 0;
  80228. + *port_addr = urb->dev->ttport;
  80229. + }
  80230. + return 0;
  80231. +}
  80232. +
  80233. +static int _speed(dwc_otg_hcd_t * hcd, void *urb_handle)
  80234. +{
  80235. + struct urb *urb = (struct urb *)urb_handle;
  80236. + return urb->dev->speed;
  80237. +}
  80238. +
  80239. +static int _get_b_hnp_enable(dwc_otg_hcd_t * hcd)
  80240. +{
  80241. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  80242. + return usb_hcd->self.b_hnp_enable;
  80243. +}
  80244. +
  80245. +static void allocate_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  80246. + struct urb *urb)
  80247. +{
  80248. + hcd_to_bus(hcd)->bandwidth_allocated += bw / urb->interval;
  80249. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80250. + hcd_to_bus(hcd)->bandwidth_isoc_reqs++;
  80251. + } else {
  80252. + hcd_to_bus(hcd)->bandwidth_int_reqs++;
  80253. + }
  80254. +}
  80255. +
  80256. +static void free_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  80257. + struct urb *urb)
  80258. +{
  80259. + hcd_to_bus(hcd)->bandwidth_allocated -= bw / urb->interval;
  80260. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80261. + hcd_to_bus(hcd)->bandwidth_isoc_reqs--;
  80262. + } else {
  80263. + hcd_to_bus(hcd)->bandwidth_int_reqs--;
  80264. + }
  80265. +}
  80266. +
  80267. +/**
  80268. + * Sets the final status of an URB and returns it to the device driver. Any
  80269. + * required cleanup of the URB is performed. The HCD lock should be held on
  80270. + * entry.
  80271. + */
  80272. +static int _complete(dwc_otg_hcd_t * hcd, void *urb_handle,
  80273. + dwc_otg_hcd_urb_t * dwc_otg_urb, int32_t status)
  80274. +{
  80275. + struct urb *urb = (struct urb *)urb_handle;
  80276. + urb_tq_entry_t *new_entry;
  80277. + int rc = 0;
  80278. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  80279. + DWC_PRINTF("%s: urb %p, device %d, ep %d %s, status=%d\n",
  80280. + __func__, urb, usb_pipedevice(urb->pipe),
  80281. + usb_pipeendpoint(urb->pipe),
  80282. + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
  80283. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80284. + int i;
  80285. + for (i = 0; i < urb->number_of_packets; i++) {
  80286. + DWC_PRINTF(" ISO Desc %d status: %d\n",
  80287. + i, urb->iso_frame_desc[i].status);
  80288. + }
  80289. + }
  80290. + }
  80291. + new_entry = DWC_ALLOC_ATOMIC(sizeof(urb_tq_entry_t));
  80292. + urb->actual_length = dwc_otg_hcd_urb_get_actual_length(dwc_otg_urb);
  80293. + /* Convert status value. */
  80294. + switch (status) {
  80295. + case -DWC_E_PROTOCOL:
  80296. + status = -EPROTO;
  80297. + break;
  80298. + case -DWC_E_IN_PROGRESS:
  80299. + status = -EINPROGRESS;
  80300. + break;
  80301. + case -DWC_E_PIPE:
  80302. + status = -EPIPE;
  80303. + break;
  80304. + case -DWC_E_IO:
  80305. + status = -EIO;
  80306. + break;
  80307. + case -DWC_E_TIMEOUT:
  80308. + status = -ETIMEDOUT;
  80309. + break;
  80310. + case -DWC_E_OVERFLOW:
  80311. + status = -EOVERFLOW;
  80312. + break;
  80313. + case -DWC_E_SHUTDOWN:
  80314. + status = -ESHUTDOWN;
  80315. + break;
  80316. + default:
  80317. + if (status) {
  80318. + DWC_PRINTF("Uknown urb status %d\n", status);
  80319. +
  80320. + }
  80321. + }
  80322. +
  80323. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80324. + int i;
  80325. +
  80326. + urb->error_count = dwc_otg_hcd_urb_get_error_count(dwc_otg_urb);
  80327. + for (i = 0; i < urb->number_of_packets; ++i) {
  80328. + urb->iso_frame_desc[i].actual_length =
  80329. + dwc_otg_hcd_urb_get_iso_desc_actual_length
  80330. + (dwc_otg_urb, i);
  80331. + urb->iso_frame_desc[i].status =
  80332. + dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_urb, i);
  80333. + }
  80334. + }
  80335. +
  80336. + urb->status = status;
  80337. + urb->hcpriv = NULL;
  80338. + if (!status) {
  80339. + if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
  80340. + (urb->actual_length < urb->transfer_buffer_length)) {
  80341. + urb->status = -EREMOTEIO;
  80342. + }
  80343. + }
  80344. +
  80345. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) ||
  80346. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  80347. + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
  80348. + if (ep) {
  80349. + free_bus_bandwidth(dwc_otg_hcd_to_hcd(hcd),
  80350. + dwc_otg_hcd_get_ep_bandwidth(hcd,
  80351. + ep->hcpriv),
  80352. + urb);
  80353. + }
  80354. + }
  80355. + DWC_FREE(dwc_otg_urb);
  80356. + if (!new_entry) {
  80357. + DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  80358. + urb->status = -EPROTO;
  80359. + /* don't schedule the tasklet -
  80360. + * directly return the packet here with error. */
  80361. +#if USB_URB_EP_LINKING
  80362. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  80363. +#endif
  80364. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80365. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb);
  80366. +#else
  80367. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  80368. +#endif
  80369. + } else {
  80370. + new_entry->urb = urb;
  80371. +#if USB_URB_EP_LINKING
  80372. + rc = usb_hcd_check_unlink_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  80373. + if(0 == rc) {
  80374. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  80375. + }
  80376. +#endif
  80377. + if(0 == rc) {
  80378. + DWC_TAILQ_INSERT_TAIL(&hcd->completed_urb_list, new_entry,
  80379. + urb_tq_entries);
  80380. + DWC_TASK_HI_SCHEDULE(hcd->completion_tasklet);
  80381. + }
  80382. + }
  80383. + return 0;
  80384. +}
  80385. +
  80386. +static struct dwc_otg_hcd_function_ops hcd_fops = {
  80387. + .start = _start,
  80388. + .disconnect = _disconnect,
  80389. + .hub_info = _hub_info,
  80390. + .speed = _speed,
  80391. + .complete = _complete,
  80392. + .get_b_hnp_enable = _get_b_hnp_enable,
  80393. +};
  80394. +
  80395. +static struct fiq_handler fh = {
  80396. + .name = "usb_fiq",
  80397. +};
  80398. +
  80399. +
  80400. +
  80401. +/**
  80402. + * Initializes the HCD. This function allocates memory for and initializes the
  80403. + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  80404. + * USB bus with the core and calls the hc_driver->start() function. It returns
  80405. + * a negative error on failure.
  80406. + */
  80407. +int hcd_init(dwc_bus_dev_t *_dev)
  80408. +{
  80409. + struct usb_hcd *hcd = NULL;
  80410. + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
  80411. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  80412. + int retval = 0;
  80413. + u64 dmamask;
  80414. + struct pt_regs regs;
  80415. +
  80416. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT otg_dev=%p\n", otg_dev);
  80417. +
  80418. + /* Set device flags indicating whether the HCD supports DMA. */
  80419. + if (dwc_otg_is_dma_enable(otg_dev->core_if))
  80420. + dmamask = DMA_BIT_MASK(32);
  80421. + else
  80422. + dmamask = 0;
  80423. +
  80424. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  80425. + dma_set_mask(&_dev->dev, dmamask);
  80426. + dma_set_coherent_mask(&_dev->dev, dmamask);
  80427. +#elif defined(PCI_INTERFACE)
  80428. + pci_set_dma_mask(_dev, dmamask);
  80429. + pci_set_consistent_dma_mask(_dev, dmamask);
  80430. +#endif
  80431. +
  80432. + /*
  80433. + * Allocate memory for the base HCD plus the DWC OTG HCD.
  80434. + * Initialize the base HCD.
  80435. + */
  80436. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  80437. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, _dev->dev.bus_id);
  80438. +#else
  80439. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, dev_name(&_dev->dev));
  80440. + hcd->has_tt = 1;
  80441. +// hcd->uses_new_polling = 1;
  80442. +// hcd->poll_rh = 0;
  80443. +#endif
  80444. + if (!hcd) {
  80445. + retval = -ENOMEM;
  80446. + goto error1;
  80447. + }
  80448. +
  80449. + hcd->regs = otg_dev->os_dep.base;
  80450. +
  80451. +
  80452. + /* Initialize the DWC OTG HCD. */
  80453. + dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  80454. + if (!dwc_otg_hcd) {
  80455. + goto error2;
  80456. + }
  80457. + ((struct wrapper_priv_data *)(hcd->hcd_priv))->dwc_otg_hcd =
  80458. + dwc_otg_hcd;
  80459. + otg_dev->hcd = dwc_otg_hcd;
  80460. +
  80461. + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
  80462. + goto error2;
  80463. + }
  80464. +
  80465. + if (fiq_enable)
  80466. + {
  80467. + if (claim_fiq(&fh)) {
  80468. + DWC_ERROR("Can't claim FIQ");
  80469. + goto error2;
  80470. + }
  80471. +
  80472. + DWC_WARN("FIQ at 0x%08x", (fiq_fsm_enable ? (int)&dwc_otg_fiq_fsm : (int)&dwc_otg_fiq_nop));
  80473. + DWC_WARN("FIQ ASM at 0x%08x length %d", (int)&_dwc_otg_fiq_stub, (int)(&_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub));
  80474. +
  80475. + set_fiq_handler((void *) &_dwc_otg_fiq_stub, &_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub);
  80476. + memset(&regs,0,sizeof(regs));
  80477. +
  80478. + regs.ARM_r8 = (long) dwc_otg_hcd->fiq_state;
  80479. + if (fiq_fsm_enable) {
  80480. + regs.ARM_r9 = dwc_otg_hcd->core_if->core_params->host_channels;
  80481. + //regs.ARM_r10 = dwc_otg_hcd->dma;
  80482. + regs.ARM_fp = (long) dwc_otg_fiq_fsm;
  80483. + } else {
  80484. + regs.ARM_fp = (long) dwc_otg_fiq_nop;
  80485. + }
  80486. +
  80487. + regs.ARM_sp = (long) dwc_otg_hcd->fiq_stack + (sizeof(struct fiq_stack) - 4);
  80488. +
  80489. +// __show_regs(&regs);
  80490. + set_fiq_regs(&regs);
  80491. +
  80492. + //Set the mphi periph to the required registers
  80493. + dwc_otg_hcd->fiq_state->mphi_regs.base = otg_dev->os_dep.mphi_base;
  80494. + dwc_otg_hcd->fiq_state->mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  80495. + dwc_otg_hcd->fiq_state->mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  80496. + dwc_otg_hcd->fiq_state->mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  80497. + dwc_otg_hcd->fiq_state->mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  80498. + dwc_otg_hcd->fiq_state->dwc_regs_base = otg_dev->os_dep.base;
  80499. + DWC_WARN("MPHI regs_base at 0x%08x", (int)dwc_otg_hcd->fiq_state->mphi_regs.base);
  80500. + //Enable mphi peripheral
  80501. + writel((1<<31),dwc_otg_hcd->fiq_state->mphi_regs.ctrl);
  80502. +#ifdef DEBUG
  80503. + if (readl(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & 0x80000000)
  80504. + DWC_WARN("MPHI periph has been enabled");
  80505. + else
  80506. + DWC_WARN("MPHI periph has NOT been enabled");
  80507. +#endif
  80508. + // Enable FIQ interrupt from USB peripheral
  80509. + enable_fiq(INTERRUPT_VC_USB);
  80510. + local_fiq_enable();
  80511. + }
  80512. +
  80513. +
  80514. + otg_dev->hcd->otg_dev = otg_dev;
  80515. + hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  80516. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  80517. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) //version field absent later
  80518. + hcd->self.otg_version = dwc_otg_get_otg_version(otg_dev->core_if);
  80519. +#endif
  80520. + /* Don't support SG list at this point */
  80521. + hcd->self.sg_tablesize = 0;
  80522. +#endif
  80523. + /*
  80524. + * Finish generic HCD initialization and start the HCD. This function
  80525. + * allocates the DMA buffer pool, registers the USB bus, requests the
  80526. + * IRQ line, and calls hcd_start method.
  80527. + */
  80528. +#ifdef PLATFORM_INTERFACE
  80529. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, 0), IRQF_SHARED | IRQF_DISABLED);
  80530. +#else
  80531. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  80532. +#endif
  80533. + if (retval < 0) {
  80534. + goto error2;
  80535. + }
  80536. +
  80537. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
  80538. + return 0;
  80539. +
  80540. +error2:
  80541. + usb_put_hcd(hcd);
  80542. +error1:
  80543. + return retval;
  80544. +}
  80545. +
  80546. +/**
  80547. + * Removes the HCD.
  80548. + * Frees memory and resources associated with the HCD and deregisters the bus.
  80549. + */
  80550. +void hcd_remove(dwc_bus_dev_t *_dev)
  80551. +{
  80552. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  80553. + dwc_otg_hcd_t *dwc_otg_hcd;
  80554. + struct usb_hcd *hcd;
  80555. +
  80556. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE otg_dev=%p\n", otg_dev);
  80557. +
  80558. + if (!otg_dev) {
  80559. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  80560. + return;
  80561. + }
  80562. +
  80563. + dwc_otg_hcd = otg_dev->hcd;
  80564. +
  80565. + if (!dwc_otg_hcd) {
  80566. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  80567. + return;
  80568. + }
  80569. +
  80570. + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
  80571. +
  80572. + if (!hcd) {
  80573. + DWC_DEBUGPL(DBG_ANY,
  80574. + "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n",
  80575. + __func__);
  80576. + return;
  80577. + }
  80578. + usb_remove_hcd(hcd);
  80579. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, NULL);
  80580. + dwc_otg_hcd_remove(dwc_otg_hcd);
  80581. + usb_put_hcd(hcd);
  80582. +}
  80583. +
  80584. +/* =========================================================================
  80585. + * Linux HC Driver Functions
  80586. + * ========================================================================= */
  80587. +
  80588. +/** Initializes the DWC_otg controller and its root hub and prepares it for host
  80589. + * mode operation. Activates the root port. Returns 0 on success and a negative
  80590. + * error code on failure. */
  80591. +int hcd_start(struct usb_hcd *hcd)
  80592. +{
  80593. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80594. + struct usb_bus *bus;
  80595. +
  80596. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
  80597. + bus = hcd_to_bus(hcd);
  80598. +
  80599. + hcd->state = HC_STATE_RUNNING;
  80600. + if (dwc_otg_hcd_start(dwc_otg_hcd, &hcd_fops)) {
  80601. + return 0;
  80602. + }
  80603. +
  80604. + /* Initialize and connect root hub if one is not already attached */
  80605. + if (bus->root_hub) {
  80606. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
  80607. + /* Inform the HUB driver to resume. */
  80608. + usb_hcd_resume_root_hub(hcd);
  80609. + }
  80610. +
  80611. + return 0;
  80612. +}
  80613. +
  80614. +/**
  80615. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  80616. + * stopped.
  80617. + */
  80618. +void hcd_stop(struct usb_hcd *hcd)
  80619. +{
  80620. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80621. +
  80622. + dwc_otg_hcd_stop(dwc_otg_hcd);
  80623. +}
  80624. +
  80625. +/** Returns the current frame number. */
  80626. +static int get_frame_number(struct usb_hcd *hcd)
  80627. +{
  80628. + hprt0_data_t hprt0;
  80629. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80630. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  80631. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  80632. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd) >> 3;
  80633. + else
  80634. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  80635. +}
  80636. +
  80637. +#ifdef DEBUG
  80638. +static void dump_urb_info(struct urb *urb, char *fn_name)
  80639. +{
  80640. + DWC_PRINTF("%s, urb %p\n", fn_name, urb);
  80641. + DWC_PRINTF(" Device address: %d\n", usb_pipedevice(urb->pipe));
  80642. + DWC_PRINTF(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
  80643. + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
  80644. + DWC_PRINTF(" Endpoint type: %s\n", ( {
  80645. + char *pipetype;
  80646. + switch (usb_pipetype(urb->pipe)) {
  80647. +case PIPE_CONTROL:
  80648. +pipetype = "CONTROL"; break; case PIPE_BULK:
  80649. +pipetype = "BULK"; break; case PIPE_INTERRUPT:
  80650. +pipetype = "INTERRUPT"; break; case PIPE_ISOCHRONOUS:
  80651. +pipetype = "ISOCHRONOUS"; break; default:
  80652. + pipetype = "UNKNOWN"; break;};
  80653. + pipetype;}
  80654. + )) ;
  80655. + DWC_PRINTF(" Speed: %s\n", ( {
  80656. + char *speed; switch (urb->dev->speed) {
  80657. +case USB_SPEED_HIGH:
  80658. +speed = "HIGH"; break; case USB_SPEED_FULL:
  80659. +speed = "FULL"; break; case USB_SPEED_LOW:
  80660. +speed = "LOW"; break; default:
  80661. + speed = "UNKNOWN"; break;};
  80662. + speed;}
  80663. + )) ;
  80664. + DWC_PRINTF(" Max packet size: %d\n",
  80665. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
  80666. + DWC_PRINTF(" Data buffer length: %d\n", urb->transfer_buffer_length);
  80667. + DWC_PRINTF(" Transfer buffer: %p, Transfer DMA: %p\n",
  80668. + urb->transfer_buffer, (void *)urb->transfer_dma);
  80669. + DWC_PRINTF(" Setup buffer: %p, Setup DMA: %p\n",
  80670. + urb->setup_packet, (void *)urb->setup_dma);
  80671. + DWC_PRINTF(" Interval: %d\n", urb->interval);
  80672. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80673. + int i;
  80674. + for (i = 0; i < urb->number_of_packets; i++) {
  80675. + DWC_PRINTF(" ISO Desc %d:\n", i);
  80676. + DWC_PRINTF(" offset: %d, length %d\n",
  80677. + urb->iso_frame_desc[i].offset,
  80678. + urb->iso_frame_desc[i].length);
  80679. + }
  80680. + }
  80681. +}
  80682. +#endif
  80683. +
  80684. +/** Starts processing a USB transfer request specified by a USB Request Block
  80685. + * (URB). mem_flags indicates the type of memory allocation to use while
  80686. + * processing this URB. */
  80687. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  80688. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80689. + struct usb_host_endpoint *ep,
  80690. +#endif
  80691. + struct urb *urb, gfp_t mem_flags)
  80692. +{
  80693. + int retval = 0;
  80694. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
  80695. + struct usb_host_endpoint *ep = urb->ep;
  80696. +#endif
  80697. + dwc_irqflags_t irqflags;
  80698. + void **ref_ep_hcpriv = &ep->hcpriv;
  80699. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80700. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  80701. + int i;
  80702. + int alloc_bandwidth = 0;
  80703. + uint8_t ep_type = 0;
  80704. + uint32_t flags = 0;
  80705. + void *buf;
  80706. +
  80707. +#ifdef DEBUG
  80708. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  80709. + dump_urb_info(urb, "dwc_otg_urb_enqueue");
  80710. + }
  80711. +#endif
  80712. +
  80713. + if (!urb->transfer_buffer && urb->transfer_buffer_length)
  80714. + return -EINVAL;
  80715. +
  80716. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
  80717. + || (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  80718. + if (!dwc_otg_hcd_is_bandwidth_allocated
  80719. + (dwc_otg_hcd, ref_ep_hcpriv)) {
  80720. + alloc_bandwidth = 1;
  80721. + }
  80722. + }
  80723. +
  80724. + switch (usb_pipetype(urb->pipe)) {
  80725. + case PIPE_CONTROL:
  80726. + ep_type = USB_ENDPOINT_XFER_CONTROL;
  80727. + break;
  80728. + case PIPE_ISOCHRONOUS:
  80729. + ep_type = USB_ENDPOINT_XFER_ISOC;
  80730. + break;
  80731. + case PIPE_BULK:
  80732. + ep_type = USB_ENDPOINT_XFER_BULK;
  80733. + break;
  80734. + case PIPE_INTERRUPT:
  80735. + ep_type = USB_ENDPOINT_XFER_INT;
  80736. + break;
  80737. + default:
  80738. + DWC_WARN("Wrong EP type - %d\n", usb_pipetype(urb->pipe));
  80739. + }
  80740. +
  80741. + /* # of packets is often 0 - do we really need to call this then? */
  80742. + dwc_otg_urb = dwc_otg_hcd_urb_alloc(dwc_otg_hcd,
  80743. + urb->number_of_packets,
  80744. + mem_flags == GFP_ATOMIC ? 1 : 0);
  80745. +
  80746. + if(dwc_otg_urb == NULL)
  80747. + return -ENOMEM;
  80748. +
  80749. + if (!dwc_otg_urb && urb->number_of_packets)
  80750. + return -ENOMEM;
  80751. +
  80752. + dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_urb, usb_pipedevice(urb->pipe),
  80753. + usb_pipeendpoint(urb->pipe), ep_type,
  80754. + usb_pipein(urb->pipe),
  80755. + usb_maxpacket(urb->dev, urb->pipe,
  80756. + !(usb_pipein(urb->pipe))));
  80757. +
  80758. + buf = urb->transfer_buffer;
  80759. + if (hcd->self.uses_dma) {
  80760. + /*
  80761. + * Calculate virtual address from physical address,
  80762. + * because some class driver may not fill transfer_buffer.
  80763. + * In Buffer DMA mode virual address is used,
  80764. + * when handling non DWORD aligned buffers.
  80765. + */
  80766. + //buf = phys_to_virt(urb->transfer_dma);
  80767. + // DMA addresses are bus addresses not physical addresses!
  80768. + buf = dma_to_virt(&urb->dev->dev, urb->transfer_dma);
  80769. + }
  80770. +
  80771. + if (!(urb->transfer_flags & URB_NO_INTERRUPT))
  80772. + flags |= URB_GIVEBACK_ASAP;
  80773. + if (urb->transfer_flags & URB_ZERO_PACKET)
  80774. + flags |= URB_SEND_ZERO_PACKET;
  80775. +
  80776. + dwc_otg_hcd_urb_set_params(dwc_otg_urb, urb, buf,
  80777. + urb->transfer_dma,
  80778. + urb->transfer_buffer_length,
  80779. + urb->setup_packet,
  80780. + urb->setup_dma, flags, urb->interval);
  80781. +
  80782. + for (i = 0; i < urb->number_of_packets; ++i) {
  80783. + dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_urb, i,
  80784. + urb->
  80785. + iso_frame_desc[i].offset,
  80786. + urb->
  80787. + iso_frame_desc[i].length);
  80788. + }
  80789. +
  80790. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &irqflags);
  80791. + urb->hcpriv = dwc_otg_urb;
  80792. +#if USB_URB_EP_LINKING
  80793. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  80794. + if (0 == retval)
  80795. +#endif
  80796. + {
  80797. + retval = dwc_otg_hcd_urb_enqueue(dwc_otg_hcd, dwc_otg_urb,
  80798. + /*(dwc_otg_qh_t **)*/
  80799. + ref_ep_hcpriv, 1);
  80800. + if (0 == retval) {
  80801. + if (alloc_bandwidth) {
  80802. + allocate_bus_bandwidth(hcd,
  80803. + dwc_otg_hcd_get_ep_bandwidth(
  80804. + dwc_otg_hcd, *ref_ep_hcpriv),
  80805. + urb);
  80806. + }
  80807. + } else {
  80808. + DWC_DEBUGPL(DBG_HCD, "DWC OTG dwc_otg_hcd_urb_enqueue failed rc %d\n", retval);
  80809. +#if USB_URB_EP_LINKING
  80810. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  80811. +#endif
  80812. + DWC_FREE(dwc_otg_urb);
  80813. + urb->hcpriv = NULL;
  80814. + if (retval == -DWC_E_NO_DEVICE)
  80815. + retval = -ENODEV;
  80816. + }
  80817. + }
  80818. +#if USB_URB_EP_LINKING
  80819. + else
  80820. + {
  80821. + DWC_FREE(dwc_otg_urb);
  80822. + urb->hcpriv = NULL;
  80823. + }
  80824. +#endif
  80825. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, irqflags);
  80826. + return retval;
  80827. +}
  80828. +
  80829. +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
  80830. + * success. */
  80831. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80832. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  80833. +#else
  80834. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  80835. +#endif
  80836. +{
  80837. + dwc_irqflags_t flags;
  80838. + dwc_otg_hcd_t *dwc_otg_hcd;
  80839. + int rc;
  80840. +
  80841. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
  80842. +
  80843. + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80844. +
  80845. +#ifdef DEBUG
  80846. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  80847. + dump_urb_info(urb, "dwc_otg_urb_dequeue");
  80848. + }
  80849. +#endif
  80850. +
  80851. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  80852. + rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  80853. + if (0 == rc) {
  80854. + if(urb->hcpriv != NULL) {
  80855. + dwc_otg_hcd_urb_dequeue(dwc_otg_hcd,
  80856. + (dwc_otg_hcd_urb_t *)urb->hcpriv);
  80857. +
  80858. + DWC_FREE(urb->hcpriv);
  80859. + urb->hcpriv = NULL;
  80860. + }
  80861. + }
  80862. +
  80863. + if (0 == rc) {
  80864. + /* Higher layer software sets URB status. */
  80865. +#if USB_URB_EP_LINKING
  80866. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  80867. +#endif
  80868. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  80869. +
  80870. +
  80871. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80872. + usb_hcd_giveback_urb(hcd, urb);
  80873. +#else
  80874. + usb_hcd_giveback_urb(hcd, urb, status);
  80875. +#endif
  80876. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  80877. + DWC_PRINTF("Called usb_hcd_giveback_urb() \n");
  80878. + DWC_PRINTF(" 1urb->status = %d\n", urb->status);
  80879. + }
  80880. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue OK\n");
  80881. + } else {
  80882. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  80883. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue failed - rc %d\n",
  80884. + rc);
  80885. + }
  80886. +
  80887. + return rc;
  80888. +}
  80889. +
  80890. +/* Frees resources in the DWC_otg controller related to a given endpoint. Also
  80891. + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
  80892. + * must already be dequeued. */
  80893. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  80894. +{
  80895. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80896. +
  80897. + DWC_DEBUGPL(DBG_HCD,
  80898. + "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
  80899. + "endpoint=%d\n", ep->desc.bEndpointAddress,
  80900. + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
  80901. + dwc_otg_hcd_endpoint_disable(dwc_otg_hcd, ep->hcpriv, 250);
  80902. + ep->hcpriv = NULL;
  80903. +}
  80904. +
  80905. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  80906. +/* Resets endpoint specific parameter values, in current version used to reset
  80907. + * the data toggle(as a WA). This function can be called from usb_clear_halt routine */
  80908. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  80909. +{
  80910. + dwc_irqflags_t flags;
  80911. + struct usb_device *udev = NULL;
  80912. + int epnum = usb_endpoint_num(&ep->desc);
  80913. + int is_out = usb_endpoint_dir_out(&ep->desc);
  80914. + int is_control = usb_endpoint_xfer_control(&ep->desc);
  80915. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80916. + struct device *dev = DWC_OTG_OS_GETDEV(dwc_otg_hcd->otg_dev->os_dep);
  80917. +
  80918. + if (dev)
  80919. + udev = to_usb_device(dev);
  80920. + else
  80921. + return;
  80922. +
  80923. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP RESET: Endpoint Num=0x%02d\n", epnum);
  80924. +
  80925. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  80926. + usb_settoggle(udev, epnum, is_out, 0);
  80927. + if (is_control)
  80928. + usb_settoggle(udev, epnum, !is_out, 0);
  80929. +
  80930. + if (ep->hcpriv) {
  80931. + dwc_otg_hcd_endpoint_reset(dwc_otg_hcd, ep->hcpriv);
  80932. + }
  80933. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  80934. +}
  80935. +#endif
  80936. +
  80937. +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
  80938. + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
  80939. + * interrupt.
  80940. + *
  80941. + * This function is called by the USB core when an interrupt occurs */
  80942. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd)
  80943. +{
  80944. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80945. + int32_t retval = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
  80946. + if (retval != 0) {
  80947. + S3C2410X_CLEAR_EINTPEND();
  80948. + }
  80949. + return IRQ_RETVAL(retval);
  80950. +}
  80951. +
  80952. +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
  80953. + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  80954. + * is the status change indicator for the single root port. Returns 1 if either
  80955. + * change indicator is 1, otherwise returns 0. */
  80956. +int hub_status_data(struct usb_hcd *hcd, char *buf)
  80957. +{
  80958. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80959. +
  80960. + buf[0] = 0;
  80961. + buf[0] |= (dwc_otg_hcd_is_status_changed(dwc_otg_hcd, 1)) << 1;
  80962. +
  80963. + return (buf[0] != 0);
  80964. +}
  80965. +
  80966. +/** Handles hub class-specific requests. */
  80967. +int hub_control(struct usb_hcd *hcd,
  80968. + u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength)
  80969. +{
  80970. + int retval;
  80971. +
  80972. + retval = dwc_otg_hcd_hub_control(hcd_to_dwc_otg_hcd(hcd),
  80973. + typeReq, wValue, wIndex, buf, wLength);
  80974. +
  80975. + switch (retval) {
  80976. + case -DWC_E_INVALID:
  80977. + retval = -EINVAL;
  80978. + break;
  80979. + }
  80980. +
  80981. + return retval;
  80982. +}
  80983. +
  80984. +#endif /* DWC_DEVICE_ONLY */
  80985. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  80986. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 1970-01-01 01:00:00.000000000 +0100
  80987. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 2014-04-24 16:04:39.819124254 +0200
  80988. @@ -0,0 +1,942 @@
  80989. +/* ==========================================================================
  80990. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
  80991. + * $Revision: #44 $
  80992. + * $Date: 2011/10/26 $
  80993. + * $Change: 1873028 $
  80994. + *
  80995. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  80996. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  80997. + * otherwise expressly agreed to in writing between Synopsys and you.
  80998. + *
  80999. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81000. + * any End User Software License Agreement or Agreement for Licensed Product
  81001. + * with Synopsys or any supplement thereto. You are permitted to use and
  81002. + * redistribute this Software in source and binary forms, with or without
  81003. + * modification, provided that redistributions of source code must retain this
  81004. + * notice. You may not view, use, disclose, copy or distribute this file or
  81005. + * any information contained herein except pursuant to this license grant from
  81006. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81007. + * below, then you are not authorized to use the Software.
  81008. + *
  81009. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81010. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81011. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81012. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81013. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81014. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81015. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81016. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81017. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81018. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81019. + * DAMAGE.
  81020. + * ========================================================================== */
  81021. +#ifndef DWC_DEVICE_ONLY
  81022. +
  81023. +/**
  81024. + * @file
  81025. + *
  81026. + * This file contains the functions to manage Queue Heads and Queue
  81027. + * Transfer Descriptors.
  81028. + */
  81029. +
  81030. +#include "dwc_otg_hcd.h"
  81031. +#include "dwc_otg_regs.h"
  81032. +
  81033. +extern bool microframe_schedule;
  81034. +
  81035. +/**
  81036. + * Free each QTD in the QH's QTD-list then free the QH. QH should already be
  81037. + * removed from a list. QTD list should already be empty if called from URB
  81038. + * Dequeue.
  81039. + *
  81040. + * @param hcd HCD instance.
  81041. + * @param qh The QH to free.
  81042. + */
  81043. +void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81044. +{
  81045. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  81046. +
  81047. + /* Free each QTD in the QTD list */
  81048. + DWC_SPINLOCK(hcd->lock);
  81049. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  81050. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  81051. + dwc_otg_hcd_qtd_free(qtd);
  81052. + }
  81053. +
  81054. + if (hcd->core_if->dma_desc_enable) {
  81055. + dwc_otg_hcd_qh_free_ddma(hcd, qh);
  81056. + } else if (qh->dw_align_buf) {
  81057. + uint32_t buf_size;
  81058. + if (qh->ep_type == UE_ISOCHRONOUS) {
  81059. + buf_size = 4096;
  81060. + } else {
  81061. + buf_size = hcd->core_if->core_params->max_transfer_size;
  81062. + }
  81063. + DWC_DMA_FREE(buf_size, qh->dw_align_buf, qh->dw_align_buf_dma);
  81064. + }
  81065. +
  81066. + DWC_FREE(qh);
  81067. + DWC_SPINUNLOCK(hcd->lock);
  81068. + return;
  81069. +}
  81070. +
  81071. +#define BitStuffTime(bytecount) ((8 * 7* bytecount) / 6)
  81072. +#define HS_HOST_DELAY 5 /* nanoseconds */
  81073. +#define FS_LS_HOST_DELAY 1000 /* nanoseconds */
  81074. +#define HUB_LS_SETUP 333 /* nanoseconds */
  81075. +#define NS_TO_US(ns) ((ns + 500) / 1000)
  81076. + /* convert & round nanoseconds to microseconds */
  81077. +
  81078. +static uint32_t calc_bus_time(int speed, int is_in, int is_isoc, int bytecount)
  81079. +{
  81080. + unsigned long retval;
  81081. +
  81082. + switch (speed) {
  81083. + case USB_SPEED_HIGH:
  81084. + if (is_isoc) {
  81085. + retval =
  81086. + ((38 * 8 * 2083) +
  81087. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  81088. + HS_HOST_DELAY;
  81089. + } else {
  81090. + retval =
  81091. + ((55 * 8 * 2083) +
  81092. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  81093. + HS_HOST_DELAY;
  81094. + }
  81095. + break;
  81096. + case USB_SPEED_FULL:
  81097. + if (is_isoc) {
  81098. + retval =
  81099. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  81100. + if (is_in) {
  81101. + retval = 7268 + FS_LS_HOST_DELAY + retval;
  81102. + } else {
  81103. + retval = 6265 + FS_LS_HOST_DELAY + retval;
  81104. + }
  81105. + } else {
  81106. + retval =
  81107. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  81108. + retval = 9107 + FS_LS_HOST_DELAY + retval;
  81109. + }
  81110. + break;
  81111. + case USB_SPEED_LOW:
  81112. + if (is_in) {
  81113. + retval =
  81114. + (67667 * (31 + 10 * BitStuffTime(bytecount))) /
  81115. + 1000;
  81116. + retval =
  81117. + 64060 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  81118. + retval;
  81119. + } else {
  81120. + retval =
  81121. + (66700 * (31 + 10 * BitStuffTime(bytecount))) /
  81122. + 1000;
  81123. + retval =
  81124. + 64107 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  81125. + retval;
  81126. + }
  81127. + break;
  81128. + default:
  81129. + DWC_WARN("Unknown device speed\n");
  81130. + retval = -1;
  81131. + }
  81132. +
  81133. + return NS_TO_US(retval);
  81134. +}
  81135. +
  81136. +/**
  81137. + * Initializes a QH structure.
  81138. + *
  81139. + * @param hcd The HCD state structure for the DWC OTG controller.
  81140. + * @param qh The QH to init.
  81141. + * @param urb Holds the information about the device/endpoint that we need
  81142. + * to initialize the QH.
  81143. + */
  81144. +#define SCHEDULE_SLOP 10
  81145. +void qh_init(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, dwc_otg_hcd_urb_t * urb)
  81146. +{
  81147. + char *speed, *type;
  81148. + int dev_speed;
  81149. + uint32_t hub_addr, hub_port;
  81150. +
  81151. + dwc_memset(qh, 0, sizeof(dwc_otg_qh_t));
  81152. +
  81153. + /* Initialize QH */
  81154. + qh->ep_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  81155. + qh->ep_is_in = dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
  81156. +
  81157. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  81158. + qh->maxp = dwc_otg_hcd_get_mps(&urb->pipe_info);
  81159. + DWC_CIRCLEQ_INIT(&qh->qtd_list);
  81160. + DWC_LIST_INIT(&qh->qh_list_entry);
  81161. + qh->channel = NULL;
  81162. +
  81163. + /* FS/LS Enpoint on HS Hub
  81164. + * NOT virtual root hub */
  81165. + dev_speed = hcd->fops->speed(hcd, urb->priv);
  81166. +
  81167. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &hub_port);
  81168. + qh->do_split = 0;
  81169. + if (microframe_schedule)
  81170. + qh->speed = dev_speed;
  81171. +
  81172. + qh->nak_frame = 0xffff;
  81173. +
  81174. + if (((dev_speed == USB_SPEED_LOW) ||
  81175. + (dev_speed == USB_SPEED_FULL)) &&
  81176. + (hub_addr != 0 && hub_addr != 1)) {
  81177. + DWC_DEBUGPL(DBG_HCD,
  81178. + "QH init: EP %d: TT found at hub addr %d, for port %d\n",
  81179. + dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
  81180. + hub_port);
  81181. + qh->do_split = 1;
  81182. + qh->skip_count = 0;
  81183. + }
  81184. +
  81185. + if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
  81186. + /* Compute scheduling parameters once and save them. */
  81187. + hprt0_data_t hprt;
  81188. +
  81189. + /** @todo Account for split transfers in the bus time. */
  81190. + int bytecount =
  81191. + dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
  81192. +
  81193. + qh->usecs =
  81194. + calc_bus_time((qh->do_split ? USB_SPEED_HIGH : dev_speed),
  81195. + qh->ep_is_in, (qh->ep_type == UE_ISOCHRONOUS),
  81196. + bytecount);
  81197. + /* Start in a slightly future (micro)frame. */
  81198. + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
  81199. + SCHEDULE_SLOP);
  81200. + qh->interval = urb->interval;
  81201. +
  81202. +#if 0
  81203. + /* Increase interrupt polling rate for debugging. */
  81204. + if (qh->ep_type == UE_INTERRUPT) {
  81205. + qh->interval = 8;
  81206. + }
  81207. +#endif
  81208. + hprt.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  81209. + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
  81210. + ((dev_speed == USB_SPEED_LOW) ||
  81211. + (dev_speed == USB_SPEED_FULL))) {
  81212. + qh->interval *= 8;
  81213. + qh->sched_frame |= 0x7;
  81214. + qh->start_split_frame = qh->sched_frame;
  81215. + }
  81216. +
  81217. + }
  81218. +
  81219. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
  81220. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
  81221. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
  81222. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  81223. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
  81224. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  81225. + dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  81226. + switch (dev_speed) {
  81227. + case USB_SPEED_LOW:
  81228. + qh->dev_speed = DWC_OTG_EP_SPEED_LOW;
  81229. + speed = "low";
  81230. + break;
  81231. + case USB_SPEED_FULL:
  81232. + qh->dev_speed = DWC_OTG_EP_SPEED_FULL;
  81233. + speed = "full";
  81234. + break;
  81235. + case USB_SPEED_HIGH:
  81236. + qh->dev_speed = DWC_OTG_EP_SPEED_HIGH;
  81237. + speed = "high";
  81238. + break;
  81239. + default:
  81240. + speed = "?";
  81241. + break;
  81242. + }
  81243. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
  81244. +
  81245. + switch (qh->ep_type) {
  81246. + case UE_ISOCHRONOUS:
  81247. + type = "isochronous";
  81248. + break;
  81249. + case UE_INTERRUPT:
  81250. + type = "interrupt";
  81251. + break;
  81252. + case UE_CONTROL:
  81253. + type = "control";
  81254. + break;
  81255. + case UE_BULK:
  81256. + type = "bulk";
  81257. + break;
  81258. + default:
  81259. + type = "?";
  81260. + break;
  81261. + }
  81262. +
  81263. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n", type);
  81264. +
  81265. +#ifdef DEBUG
  81266. + if (qh->ep_type == UE_INTERRUPT) {
  81267. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
  81268. + qh->usecs);
  81269. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
  81270. + qh->interval);
  81271. + }
  81272. +#endif
  81273. +
  81274. +}
  81275. +
  81276. +/**
  81277. + * This function allocates and initializes a QH.
  81278. + *
  81279. + * @param hcd The HCD state structure for the DWC OTG controller.
  81280. + * @param urb Holds the information about the device/endpoint that we need
  81281. + * to initialize the QH.
  81282. + * @param atomic_alloc Flag to do atomic allocation if needed
  81283. + *
  81284. + * @return Returns pointer to the newly allocated QH, or NULL on error. */
  81285. +dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  81286. + dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  81287. +{
  81288. + dwc_otg_qh_t *qh;
  81289. +
  81290. + /* Allocate memory */
  81291. + /** @todo add memflags argument */
  81292. + qh = dwc_otg_hcd_qh_alloc(atomic_alloc);
  81293. + if (qh == NULL) {
  81294. + DWC_ERROR("qh allocation failed");
  81295. + return NULL;
  81296. + }
  81297. +
  81298. + qh_init(hcd, qh, urb);
  81299. +
  81300. + if (hcd->core_if->dma_desc_enable
  81301. + && (dwc_otg_hcd_qh_init_ddma(hcd, qh) < 0)) {
  81302. + dwc_otg_hcd_qh_free(hcd, qh);
  81303. + return NULL;
  81304. + }
  81305. +
  81306. + return qh;
  81307. +}
  81308. +
  81309. +/* microframe_schedule=0 start */
  81310. +
  81311. +/**
  81312. + * Checks that a channel is available for a periodic transfer.
  81313. + *
  81314. + * @return 0 if successful, negative error code otherise.
  81315. + */
  81316. +static int periodic_channel_available(dwc_otg_hcd_t * hcd)
  81317. +{
  81318. + /*
  81319. + * Currently assuming that there is a dedicated host channnel for each
  81320. + * periodic transaction plus at least one host channel for
  81321. + * non-periodic transactions.
  81322. + */
  81323. + int status;
  81324. + int num_channels;
  81325. +
  81326. + num_channels = hcd->core_if->core_params->host_channels;
  81327. + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels)
  81328. + && (hcd->periodic_channels < num_channels - 1)) {
  81329. + status = 0;
  81330. + } else {
  81331. + DWC_INFO("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
  81332. + __func__, num_channels, hcd->periodic_channels, hcd->non_periodic_channels); //NOTICE
  81333. + status = -DWC_E_NO_SPACE;
  81334. + }
  81335. +
  81336. + return status;
  81337. +}
  81338. +
  81339. +/**
  81340. + * Checks that there is sufficient bandwidth for the specified QH in the
  81341. + * periodic schedule. For simplicity, this calculation assumes that all the
  81342. + * transfers in the periodic schedule may occur in the same (micro)frame.
  81343. + *
  81344. + * @param hcd The HCD state structure for the DWC OTG controller.
  81345. + * @param qh QH containing periodic bandwidth required.
  81346. + *
  81347. + * @return 0 if successful, negative error code otherwise.
  81348. + */
  81349. +static int check_periodic_bandwidth(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81350. +{
  81351. + int status;
  81352. + int16_t max_claimed_usecs;
  81353. +
  81354. + status = 0;
  81355. +
  81356. + if ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) || qh->do_split) {
  81357. + /*
  81358. + * High speed mode.
  81359. + * Max periodic usecs is 80% x 125 usec = 100 usec.
  81360. + */
  81361. +
  81362. + max_claimed_usecs = 100 - qh->usecs;
  81363. + } else {
  81364. + /*
  81365. + * Full speed mode.
  81366. + * Max periodic usecs is 90% x 1000 usec = 900 usec.
  81367. + */
  81368. + max_claimed_usecs = 900 - qh->usecs;
  81369. + }
  81370. +
  81371. + if (hcd->periodic_usecs > max_claimed_usecs) {
  81372. + DWC_INFO("%s: already claimed usecs %d, required usecs %d\n", __func__, hcd->periodic_usecs, qh->usecs); //NOTICE
  81373. + status = -DWC_E_NO_SPACE;
  81374. + }
  81375. +
  81376. + return status;
  81377. +}
  81378. +
  81379. +/* microframe_schedule=0 end */
  81380. +
  81381. +/**
  81382. + * Microframe scheduler
  81383. + * track the total use in hcd->frame_usecs
  81384. + * keep each qh use in qh->frame_usecs
  81385. + * when surrendering the qh then donate the time back
  81386. + */
  81387. +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
  81388. +
  81389. +/*
  81390. + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
  81391. + */
  81392. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
  81393. +{
  81394. + int i;
  81395. + for (i=0; i<8; i++) {
  81396. + _hcd->frame_usecs[i] = max_uframe_usecs[i];
  81397. + }
  81398. + return 0;
  81399. +}
  81400. +
  81401. +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  81402. +{
  81403. + int i;
  81404. + unsigned short utime;
  81405. + int t_left;
  81406. + int ret;
  81407. + int done;
  81408. +
  81409. + ret = -1;
  81410. + utime = _qh->usecs;
  81411. + t_left = utime;
  81412. + i = 0;
  81413. + done = 0;
  81414. + while (done == 0) {
  81415. + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
  81416. + if (utime <= _hcd->frame_usecs[i]) {
  81417. + _hcd->frame_usecs[i] -= utime;
  81418. + _qh->frame_usecs[i] += utime;
  81419. + t_left -= utime;
  81420. + ret = i;
  81421. + done = 1;
  81422. + return ret;
  81423. + } else {
  81424. + i++;
  81425. + if (i == 8) {
  81426. + done = 1;
  81427. + ret = -1;
  81428. + }
  81429. + }
  81430. + }
  81431. + return ret;
  81432. + }
  81433. +
  81434. +/*
  81435. + * use this for FS apps that can span multiple uframes
  81436. + */
  81437. +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  81438. +{
  81439. + int i;
  81440. + int j;
  81441. + unsigned short utime;
  81442. + int t_left;
  81443. + int ret;
  81444. + int done;
  81445. + unsigned short xtime;
  81446. +
  81447. + ret = -1;
  81448. + utime = _qh->usecs;
  81449. + t_left = utime;
  81450. + i = 0;
  81451. + done = 0;
  81452. +loop:
  81453. + while (done == 0) {
  81454. + if(_hcd->frame_usecs[i] <= 0) {
  81455. + i++;
  81456. + if (i == 8) {
  81457. + done = 1;
  81458. + ret = -1;
  81459. + }
  81460. + goto loop;
  81461. + }
  81462. +
  81463. + /*
  81464. + * we need n consecutive slots
  81465. + * so use j as a start slot j plus j+1 must be enough time (for now)
  81466. + */
  81467. + xtime= _hcd->frame_usecs[i];
  81468. + for (j = i+1 ; j < 8 ; j++ ) {
  81469. + /*
  81470. + * if we add this frame remaining time to xtime we may
  81471. + * be OK, if not we need to test j for a complete frame
  81472. + */
  81473. + if ((xtime+_hcd->frame_usecs[j]) < utime) {
  81474. + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
  81475. + j = 8;
  81476. + ret = -1;
  81477. + continue;
  81478. + }
  81479. + }
  81480. + if (xtime >= utime) {
  81481. + ret = i;
  81482. + j = 8; /* stop loop with a good value ret */
  81483. + continue;
  81484. + }
  81485. + /* add the frame time to x time */
  81486. + xtime += _hcd->frame_usecs[j];
  81487. + /* we must have a fully available next frame or break */
  81488. + if ((xtime < utime)
  81489. + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
  81490. + ret = -1;
  81491. + j = 8; /* stop loop with a bad value ret */
  81492. + continue;
  81493. + }
  81494. + }
  81495. + if (ret >= 0) {
  81496. + t_left = utime;
  81497. + for (j = i; (t_left>0) && (j < 8); j++ ) {
  81498. + t_left -= _hcd->frame_usecs[j];
  81499. + if ( t_left <= 0 ) {
  81500. + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
  81501. + _hcd->frame_usecs[j]= -t_left;
  81502. + ret = i;
  81503. + done = 1;
  81504. + } else {
  81505. + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
  81506. + _hcd->frame_usecs[j] = 0;
  81507. + }
  81508. + }
  81509. + } else {
  81510. + i++;
  81511. + if (i == 8) {
  81512. + done = 1;
  81513. + ret = -1;
  81514. + }
  81515. + }
  81516. + }
  81517. + return ret;
  81518. +}
  81519. +
  81520. +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  81521. +{
  81522. + int ret;
  81523. + ret = -1;
  81524. +
  81525. + if (_qh->speed == USB_SPEED_HIGH) {
  81526. + /* if this is a hs transaction we need a full frame */
  81527. + ret = find_single_uframe(_hcd, _qh);
  81528. + } else {
  81529. + /* if this is a fs transaction we may need a sequence of frames */
  81530. + ret = find_multi_uframe(_hcd, _qh);
  81531. + }
  81532. + return ret;
  81533. +}
  81534. +
  81535. +/**
  81536. + * Checks that the max transfer size allowed in a host channel is large enough
  81537. + * to handle the maximum data transfer in a single (micro)frame for a periodic
  81538. + * transfer.
  81539. + *
  81540. + * @param hcd The HCD state structure for the DWC OTG controller.
  81541. + * @param qh QH for a periodic endpoint.
  81542. + *
  81543. + * @return 0 if successful, negative error code otherwise.
  81544. + */
  81545. +static int check_max_xfer_size(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81546. +{
  81547. + int status;
  81548. + uint32_t max_xfer_size;
  81549. + uint32_t max_channel_xfer_size;
  81550. +
  81551. + status = 0;
  81552. +
  81553. + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
  81554. + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
  81555. +
  81556. + if (max_xfer_size > max_channel_xfer_size) {
  81557. + DWC_INFO("%s: Periodic xfer length %d > " "max xfer length for channel %d\n",
  81558. + __func__, max_xfer_size, max_channel_xfer_size); //NOTICE
  81559. + status = -DWC_E_NO_SPACE;
  81560. + }
  81561. +
  81562. + return status;
  81563. +}
  81564. +
  81565. +
  81566. +
  81567. +/**
  81568. + * Schedules an interrupt or isochronous transfer in the periodic schedule.
  81569. + *
  81570. + * @param hcd The HCD state structure for the DWC OTG controller.
  81571. + * @param qh QH for the periodic transfer. The QH should already contain the
  81572. + * scheduling information.
  81573. + *
  81574. + * @return 0 if successful, negative error code otherwise.
  81575. + */
  81576. +static int schedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81577. +{
  81578. + int status = 0;
  81579. +
  81580. + if (microframe_schedule) {
  81581. + int frame;
  81582. + status = find_uframe(hcd, qh);
  81583. + frame = -1;
  81584. + if (status == 0) {
  81585. + frame = 7;
  81586. + } else {
  81587. + if (status > 0 )
  81588. + frame = status-1;
  81589. + }
  81590. +
  81591. + /* Set the new frame up */
  81592. + if (frame > -1) {
  81593. + qh->sched_frame &= ~0x7;
  81594. + qh->sched_frame |= (frame & 7);
  81595. + }
  81596. +
  81597. + if (status != -1)
  81598. + status = 0;
  81599. + } else {
  81600. + status = periodic_channel_available(hcd);
  81601. + if (status) {
  81602. + DWC_INFO("%s: No host channel available for periodic " "transfer.\n", __func__); //NOTICE
  81603. + return status;
  81604. + }
  81605. +
  81606. + status = check_periodic_bandwidth(hcd, qh);
  81607. + }
  81608. + if (status) {
  81609. + DWC_INFO("%s: Insufficient periodic bandwidth for "
  81610. + "periodic transfer.\n", __func__);
  81611. + return status;
  81612. + }
  81613. + status = check_max_xfer_size(hcd, qh);
  81614. + if (status) {
  81615. + DWC_INFO("%s: Channel max transfer size too small "
  81616. + "for periodic transfer.\n", __func__);
  81617. + return status;
  81618. + }
  81619. +
  81620. + if (hcd->core_if->dma_desc_enable) {
  81621. + /* Don't rely on SOF and start in ready schedule */
  81622. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  81623. + }
  81624. + else {
  81625. + if(DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, hcd->fiq_state->next_sched_frame))
  81626. + {
  81627. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  81628. +
  81629. + }
  81630. + /* Always start in the inactive schedule. */
  81631. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_inactive, &qh->qh_list_entry);
  81632. + }
  81633. +
  81634. + if (!microframe_schedule) {
  81635. + /* Reserve the periodic channel. */
  81636. + hcd->periodic_channels++;
  81637. + }
  81638. +
  81639. + /* Update claimed usecs per (micro)frame. */
  81640. + hcd->periodic_usecs += qh->usecs;
  81641. +
  81642. + return status;
  81643. +}
  81644. +
  81645. +
  81646. +/**
  81647. + * This function adds a QH to either the non periodic or periodic schedule if
  81648. + * it is not already in the schedule. If the QH is already in the schedule, no
  81649. + * action is taken.
  81650. + *
  81651. + * @return 0 if successful, negative error code otherwise.
  81652. + */
  81653. +int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81654. +{
  81655. + int status = 0;
  81656. + gintmsk_data_t intr_mask = {.d32 = 0 };
  81657. +
  81658. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  81659. + /* QH already in a schedule. */
  81660. + return status;
  81661. + }
  81662. +
  81663. + /* Add the new QH to the appropriate schedule */
  81664. + if (dwc_qh_is_non_per(qh)) {
  81665. + /* Always start in the inactive schedule. */
  81666. + DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  81667. + &qh->qh_list_entry);
  81668. + //hcd->fiq_state->kick_np_queues = 1;
  81669. + } else {
  81670. + status = schedule_periodic(hcd, qh);
  81671. + if ( !hcd->periodic_qh_count ) {
  81672. + intr_mask.b.sofintr = 1;
  81673. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  81674. + intr_mask.d32, intr_mask.d32);
  81675. + }
  81676. + hcd->periodic_qh_count++;
  81677. + }
  81678. +
  81679. + return status;
  81680. +}
  81681. +
  81682. +/**
  81683. + * Removes an interrupt or isochronous transfer from the periodic schedule.
  81684. + *
  81685. + * @param hcd The HCD state structure for the DWC OTG controller.
  81686. + * @param qh QH for the periodic transfer.
  81687. + */
  81688. +static void deschedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81689. +{
  81690. + int i;
  81691. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  81692. +
  81693. + /* Update claimed usecs per (micro)frame. */
  81694. + hcd->periodic_usecs -= qh->usecs;
  81695. +
  81696. + if (!microframe_schedule) {
  81697. + /* Release the periodic channel reservation. */
  81698. + hcd->periodic_channels--;
  81699. + } else {
  81700. + for (i = 0; i < 8; i++) {
  81701. + hcd->frame_usecs[i] += qh->frame_usecs[i];
  81702. + qh->frame_usecs[i] = 0;
  81703. + }
  81704. + }
  81705. +}
  81706. +
  81707. +/**
  81708. + * Removes a QH from either the non-periodic or periodic schedule. Memory is
  81709. + * not freed.
  81710. + *
  81711. + * @param hcd The HCD state structure.
  81712. + * @param qh QH to remove from schedule. */
  81713. +void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81714. +{
  81715. + gintmsk_data_t intr_mask = {.d32 = 0 };
  81716. +
  81717. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  81718. + /* QH is not in a schedule. */
  81719. + return;
  81720. + }
  81721. +
  81722. + if (dwc_qh_is_non_per(qh)) {
  81723. + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
  81724. + hcd->non_periodic_qh_ptr =
  81725. + hcd->non_periodic_qh_ptr->next;
  81726. + }
  81727. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  81728. + //if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive))
  81729. + // hcd->fiq_state->kick_np_queues = 1;
  81730. + } else {
  81731. + deschedule_periodic(hcd, qh);
  81732. + hcd->periodic_qh_count--;
  81733. + if( !hcd->periodic_qh_count && !fiq_fsm_enable ) {
  81734. + intr_mask.b.sofintr = 1;
  81735. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  81736. + intr_mask.d32, 0);
  81737. + }
  81738. + }
  81739. +}
  81740. +
  81741. +/**
  81742. + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
  81743. + * non-periodic schedule. The QH is added to the inactive non-periodic
  81744. + * schedule if any QTDs are still attached to the QH.
  81745. + *
  81746. + * For periodic QHs, the QH is removed from the periodic queued schedule. If
  81747. + * there are any QTDs still attached to the QH, the QH is added to either the
  81748. + * periodic inactive schedule or the periodic ready schedule and its next
  81749. + * scheduled frame is calculated. The QH is placed in the ready schedule if
  81750. + * the scheduled frame has been reached already. Otherwise it's placed in the
  81751. + * inactive schedule. If there are no QTDs attached to the QH, the QH is
  81752. + * completely removed from the periodic schedule.
  81753. + */
  81754. +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  81755. + int sched_next_periodic_split)
  81756. +{
  81757. + if (dwc_qh_is_non_per(qh)) {
  81758. + dwc_otg_hcd_qh_remove(hcd, qh);
  81759. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  81760. + /* Add back to inactive non-periodic schedule. */
  81761. + dwc_otg_hcd_qh_add(hcd, qh);
  81762. + //hcd->fiq_state->kick_np_queues = 1;
  81763. + }
  81764. + } else {
  81765. + uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  81766. +
  81767. + if (qh->do_split) {
  81768. + /* Schedule the next continuing periodic split transfer */
  81769. + if (sched_next_periodic_split) {
  81770. +
  81771. + qh->sched_frame = frame_number;
  81772. +
  81773. + if (dwc_frame_num_le(frame_number,
  81774. + dwc_frame_num_inc
  81775. + (qh->start_split_frame,
  81776. + 1))) {
  81777. + /*
  81778. + * Allow one frame to elapse after start
  81779. + * split microframe before scheduling
  81780. + * complete split, but DONT if we are
  81781. + * doing the next start split in the
  81782. + * same frame for an ISOC out.
  81783. + */
  81784. + if ((qh->ep_type != UE_ISOCHRONOUS) ||
  81785. + (qh->ep_is_in != 0)) {
  81786. + qh->sched_frame =
  81787. + dwc_frame_num_inc(qh->sched_frame, 1);
  81788. + }
  81789. + }
  81790. + } else {
  81791. + qh->sched_frame =
  81792. + dwc_frame_num_inc(qh->start_split_frame,
  81793. + qh->interval);
  81794. + if (dwc_frame_num_le
  81795. + (qh->sched_frame, frame_number)) {
  81796. + qh->sched_frame = frame_number;
  81797. + }
  81798. + qh->sched_frame |= 0x7;
  81799. + qh->start_split_frame = qh->sched_frame;
  81800. + }
  81801. + } else {
  81802. + qh->sched_frame =
  81803. + dwc_frame_num_inc(qh->sched_frame, qh->interval);
  81804. + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
  81805. + qh->sched_frame = frame_number;
  81806. + }
  81807. + }
  81808. +
  81809. + if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  81810. + dwc_otg_hcd_qh_remove(hcd, qh);
  81811. + } else {
  81812. + /*
  81813. + * Remove from periodic_sched_queued and move to
  81814. + * appropriate queue.
  81815. + */
  81816. + if ((microframe_schedule && dwc_frame_num_le(qh->sched_frame, frame_number)) ||
  81817. + (!microframe_schedule && qh->sched_frame == frame_number)) {
  81818. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  81819. + &qh->qh_list_entry);
  81820. + } else {
  81821. + if(!dwc_frame_num_le(hcd->fiq_state->next_sched_frame, qh->sched_frame))
  81822. + {
  81823. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  81824. + }
  81825. +
  81826. + DWC_LIST_MOVE_HEAD
  81827. + (&hcd->periodic_sched_inactive,
  81828. + &qh->qh_list_entry);
  81829. + }
  81830. + }
  81831. + }
  81832. +}
  81833. +
  81834. +/**
  81835. + * This function allocates and initializes a QTD.
  81836. + *
  81837. + * @param urb The URB to create a QTD from. Each URB-QTD pair will end up
  81838. + * pointing to each other so each pair should have a unique correlation.
  81839. + * @param atomic_alloc Flag to do atomic alloc if needed
  81840. + *
  81841. + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
  81842. +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  81843. +{
  81844. + dwc_otg_qtd_t *qtd;
  81845. +
  81846. + qtd = dwc_otg_hcd_qtd_alloc(atomic_alloc);
  81847. + if (qtd == NULL) {
  81848. + return NULL;
  81849. + }
  81850. +
  81851. + dwc_otg_hcd_qtd_init(qtd, urb);
  81852. + return qtd;
  81853. +}
  81854. +
  81855. +/**
  81856. + * Initializes a QTD structure.
  81857. + *
  81858. + * @param qtd The QTD to initialize.
  81859. + * @param urb The URB to use for initialization. */
  81860. +void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb)
  81861. +{
  81862. + dwc_memset(qtd, 0, sizeof(dwc_otg_qtd_t));
  81863. + qtd->urb = urb;
  81864. + if (dwc_otg_hcd_get_pipe_type(&urb->pipe_info) == UE_CONTROL) {
  81865. + /*
  81866. + * The only time the QTD data toggle is used is on the data
  81867. + * phase of control transfers. This phase always starts with
  81868. + * DATA1.
  81869. + */
  81870. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  81871. + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
  81872. + }
  81873. +
  81874. + /* start split */
  81875. + qtd->complete_split = 0;
  81876. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  81877. + qtd->isoc_split_offset = 0;
  81878. + qtd->in_process = 0;
  81879. +
  81880. + /* Store the qtd ptr in the urb to reference what QTD. */
  81881. + urb->qtd = qtd;
  81882. + return;
  81883. +}
  81884. +
  81885. +/**
  81886. + * This function adds a QTD to the QTD-list of a QH. It will find the correct
  81887. + * QH to place the QTD into. If it does not find a QH, then it will create a
  81888. + * new QH. If the QH to which the QTD is added is not currently scheduled, it
  81889. + * is placed into the proper schedule based on its EP type.
  81890. + * HCD lock must be held and interrupts must be disabled on entry
  81891. + *
  81892. + * @param[in] qtd The QTD to add
  81893. + * @param[in] hcd The DWC HCD structure
  81894. + * @param[out] qh out parameter to return queue head
  81895. + * @param atomic_alloc Flag to do atomic alloc if needed
  81896. + *
  81897. + * @return 0 if successful, negative error code otherwise.
  81898. + */
  81899. +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
  81900. + dwc_otg_hcd_t * hcd, dwc_otg_qh_t ** qh, int atomic_alloc)
  81901. +{
  81902. + int retval = 0;
  81903. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  81904. +
  81905. + /*
  81906. + * Get the QH which holds the QTD-list to insert to. Create QH if it
  81907. + * doesn't exist.
  81908. + */
  81909. + if (*qh == NULL) {
  81910. + *qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
  81911. + if (*qh == NULL) {
  81912. + retval = -DWC_E_NO_MEMORY;
  81913. + goto done;
  81914. + } else {
  81915. + if (fiq_enable)
  81916. + hcd->fiq_state->kick_np_queues = 1;
  81917. + }
  81918. + }
  81919. + retval = dwc_otg_hcd_qh_add(hcd, *qh);
  81920. + if (retval == 0) {
  81921. + DWC_CIRCLEQ_INSERT_TAIL(&((*qh)->qtd_list), qtd,
  81922. + qtd_list_entry);
  81923. + qtd->qh = *qh;
  81924. + }
  81925. +done:
  81926. +
  81927. + return retval;
  81928. +}
  81929. +
  81930. +#endif /* DWC_DEVICE_ONLY */
  81931. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
  81932. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 1970-01-01 01:00:00.000000000 +0100
  81933. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 2014-04-24 16:04:39.819124254 +0200
  81934. @@ -0,0 +1,188 @@
  81935. +#ifndef _DWC_OS_DEP_H_
  81936. +#define _DWC_OS_DEP_H_
  81937. +
  81938. +/**
  81939. + * @file
  81940. + *
  81941. + * This file contains OS dependent structures.
  81942. + *
  81943. + */
  81944. +
  81945. +#include <linux/kernel.h>
  81946. +#include <linux/module.h>
  81947. +#include <linux/moduleparam.h>
  81948. +#include <linux/init.h>
  81949. +#include <linux/device.h>
  81950. +#include <linux/errno.h>
  81951. +#include <linux/types.h>
  81952. +#include <linux/slab.h>
  81953. +#include <linux/list.h>
  81954. +#include <linux/interrupt.h>
  81955. +#include <linux/ctype.h>
  81956. +#include <linux/string.h>
  81957. +#include <linux/dma-mapping.h>
  81958. +#include <linux/jiffies.h>
  81959. +#include <linux/delay.h>
  81960. +#include <linux/timer.h>
  81961. +#include <linux/workqueue.h>
  81962. +#include <linux/stat.h>
  81963. +#include <linux/pci.h>
  81964. +
  81965. +#include <linux/version.h>
  81966. +
  81967. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
  81968. +# include <linux/irq.h>
  81969. +#endif
  81970. +
  81971. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  81972. +# include <linux/usb/ch9.h>
  81973. +#else
  81974. +# include <linux/usb_ch9.h>
  81975. +#endif
  81976. +
  81977. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  81978. +# include <linux/usb/gadget.h>
  81979. +#else
  81980. +# include <linux/usb_gadget.h>
  81981. +#endif
  81982. +
  81983. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  81984. +# include <asm/irq.h>
  81985. +#endif
  81986. +
  81987. +#ifdef PCI_INTERFACE
  81988. +# include <asm/io.h>
  81989. +#endif
  81990. +
  81991. +#ifdef LM_INTERFACE
  81992. +# include <asm/unaligned.h>
  81993. +# include <asm/sizes.h>
  81994. +# include <asm/param.h>
  81995. +# include <asm/io.h>
  81996. +# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  81997. +# include <asm/arch/hardware.h>
  81998. +# include <asm/arch/lm.h>
  81999. +# include <asm/arch/irqs.h>
  82000. +# include <asm/arch/regs-irq.h>
  82001. +# else
  82002. +/* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
  82003. + here we assume that the machine architecture provides definitions
  82004. + in its own header
  82005. +*/
  82006. +# include <mach/lm.h>
  82007. +# include <mach/hardware.h>
  82008. +# endif
  82009. +#endif
  82010. +
  82011. +#ifdef PLATFORM_INTERFACE
  82012. +#include <linux/platform_device.h>
  82013. +#include <asm/mach/map.h>
  82014. +#endif
  82015. +
  82016. +/** The OS page size */
  82017. +#define DWC_OS_PAGE_SIZE PAGE_SIZE
  82018. +
  82019. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  82020. +typedef int gfp_t;
  82021. +#endif
  82022. +
  82023. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  82024. +# define IRQF_SHARED SA_SHIRQ
  82025. +#endif
  82026. +
  82027. +typedef struct os_dependent {
  82028. + /** Base address returned from ioremap() */
  82029. + void *base;
  82030. +
  82031. + /** Register offset for Diagnostic API */
  82032. + uint32_t reg_offset;
  82033. +
  82034. + /** Base address for MPHI peripheral */
  82035. + void *mphi_base;
  82036. +
  82037. +#ifdef LM_INTERFACE
  82038. + struct lm_device *lmdev;
  82039. +#elif defined(PCI_INTERFACE)
  82040. + struct pci_dev *pcidev;
  82041. +
  82042. + /** Start address of a PCI region */
  82043. + resource_size_t rsrc_start;
  82044. +
  82045. + /** Length address of a PCI region */
  82046. + resource_size_t rsrc_len;
  82047. +#elif defined(PLATFORM_INTERFACE)
  82048. + struct platform_device *platformdev;
  82049. +#endif
  82050. +
  82051. +} os_dependent_t;
  82052. +
  82053. +#ifdef __cplusplus
  82054. +}
  82055. +#endif
  82056. +
  82057. +
  82058. +
  82059. +/* Type for the our device on the chosen bus */
  82060. +#if defined(LM_INTERFACE)
  82061. +typedef struct lm_device dwc_bus_dev_t;
  82062. +#elif defined(PCI_INTERFACE)
  82063. +typedef struct pci_dev dwc_bus_dev_t;
  82064. +#elif defined(PLATFORM_INTERFACE)
  82065. +typedef struct platform_device dwc_bus_dev_t;
  82066. +#endif
  82067. +
  82068. +/* Helper macro to retrieve drvdata from the device on the chosen bus */
  82069. +#if defined(LM_INTERFACE)
  82070. +#define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
  82071. +#elif defined(PCI_INTERFACE)
  82072. +#define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
  82073. +#elif defined(PLATFORM_INTERFACE)
  82074. +#define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
  82075. +#endif
  82076. +
  82077. +/**
  82078. + * Helper macro returning the otg_device structure of a given struct device
  82079. + *
  82080. + * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  82081. + */
  82082. +#ifdef LM_INTERFACE
  82083. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  82084. + struct lm_device *lm_dev = \
  82085. + container_of(_dev, struct lm_device, dev); \
  82086. + _var = lm_get_drvdata(lm_dev); \
  82087. + } while (0)
  82088. +
  82089. +#elif defined(PCI_INTERFACE)
  82090. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  82091. + _var = dev_get_drvdata(_dev); \
  82092. + } while (0)
  82093. +
  82094. +#elif defined(PLATFORM_INTERFACE)
  82095. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  82096. + struct platform_device *platform_dev = \
  82097. + container_of(_dev, struct platform_device, dev); \
  82098. + _var = platform_get_drvdata(platform_dev); \
  82099. + } while (0)
  82100. +#endif
  82101. +
  82102. +
  82103. +/**
  82104. + * Helper macro returning the struct dev of the given struct os_dependent
  82105. + *
  82106. + * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
  82107. + */
  82108. +#ifdef LM_INTERFACE
  82109. +#define DWC_OTG_OS_GETDEV(_osdep) \
  82110. + ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
  82111. +#elif defined(PCI_INTERFACE)
  82112. +#define DWC_OTG_OS_GETDEV(_osdep) \
  82113. + ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
  82114. +#elif defined(PLATFORM_INTERFACE)
  82115. +#define DWC_OTG_OS_GETDEV(_osdep) \
  82116. + ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
  82117. +#endif
  82118. +
  82119. +
  82120. +
  82121. +
  82122. +#endif /* _DWC_OS_DEP_H_ */
  82123. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_pcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c
  82124. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 1970-01-01 01:00:00.000000000 +0100
  82125. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 2014-04-24 16:04:39.819124254 +0200
  82126. @@ -0,0 +1,2708 @@
  82127. +/* ==========================================================================
  82128. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
  82129. + * $Revision: #101 $
  82130. + * $Date: 2012/08/10 $
  82131. + * $Change: 2047372 $
  82132. + *
  82133. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  82134. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  82135. + * otherwise expressly agreed to in writing between Synopsys and you.
  82136. + *
  82137. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  82138. + * any End User Software License Agreement or Agreement for Licensed Product
  82139. + * with Synopsys or any supplement thereto. You are permitted to use and
  82140. + * redistribute this Software in source and binary forms, with or without
  82141. + * modification, provided that redistributions of source code must retain this
  82142. + * notice. You may not view, use, disclose, copy or distribute this file or
  82143. + * any information contained herein except pursuant to this license grant from
  82144. + * Synopsys. If you do not agree with this notice, including the disclaimer
  82145. + * below, then you are not authorized to use the Software.
  82146. + *
  82147. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  82148. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  82149. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  82150. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  82151. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  82152. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  82153. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  82154. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82155. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  82156. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  82157. + * DAMAGE.
  82158. + * ========================================================================== */
  82159. +#ifndef DWC_HOST_ONLY
  82160. +
  82161. +/** @file
  82162. + * This file implements PCD Core. All code in this file is portable and doesn't
  82163. + * use any OS specific functions.
  82164. + * PCD Core provides Interface, defined in <code><dwc_otg_pcd_if.h></code>
  82165. + * header file, which can be used to implement OS specific PCD interface.
  82166. + *
  82167. + * An important function of the PCD is managing interrupts generated
  82168. + * by the DWC_otg controller. The implementation of the DWC_otg device
  82169. + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
  82170. + *
  82171. + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
  82172. + * @todo Does it work when the request size is greater than DEPTSIZ
  82173. + * transfer size
  82174. + *
  82175. + */
  82176. +
  82177. +#include "dwc_otg_pcd.h"
  82178. +
  82179. +#ifdef DWC_UTE_CFI
  82180. +#include "dwc_otg_cfi.h"
  82181. +
  82182. +extern int init_cfi(cfiobject_t * cfiobj);
  82183. +#endif
  82184. +
  82185. +/**
  82186. + * Choose endpoint from ep arrays using usb_ep structure.
  82187. + */
  82188. +static dwc_otg_pcd_ep_t *get_ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  82189. +{
  82190. + int i;
  82191. + if (pcd->ep0.priv == handle) {
  82192. + return &pcd->ep0;
  82193. + }
  82194. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  82195. + if (pcd->in_ep[i].priv == handle)
  82196. + return &pcd->in_ep[i];
  82197. + if (pcd->out_ep[i].priv == handle)
  82198. + return &pcd->out_ep[i];
  82199. + }
  82200. +
  82201. + return NULL;
  82202. +}
  82203. +
  82204. +/**
  82205. + * This function completes a request. It call's the request call back.
  82206. + */
  82207. +void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req,
  82208. + int32_t status)
  82209. +{
  82210. + unsigned stopped = ep->stopped;
  82211. +
  82212. + DWC_DEBUGPL(DBG_PCDV, "%s(ep %p req %p)\n", __func__, ep, req);
  82213. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  82214. +
  82215. + /* don't modify queue heads during completion callback */
  82216. + ep->stopped = 1;
  82217. + /* spin_unlock/spin_lock now done in fops->complete() */
  82218. + ep->pcd->fops->complete(ep->pcd, ep->priv, req->priv, status,
  82219. + req->actual);
  82220. +
  82221. + if (ep->pcd->request_pending > 0) {
  82222. + --ep->pcd->request_pending;
  82223. + }
  82224. +
  82225. + ep->stopped = stopped;
  82226. + DWC_FREE(req);
  82227. +}
  82228. +
  82229. +/**
  82230. + * This function terminates all the requsts in the EP request queue.
  82231. + */
  82232. +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep)
  82233. +{
  82234. + dwc_otg_pcd_request_t *req;
  82235. +
  82236. + ep->stopped = 1;
  82237. +
  82238. + /* called with irqs blocked?? */
  82239. + while (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  82240. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  82241. + dwc_otg_request_done(ep, req, -DWC_E_SHUTDOWN);
  82242. + }
  82243. +}
  82244. +
  82245. +void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  82246. + const struct dwc_otg_pcd_function_ops *fops)
  82247. +{
  82248. + pcd->fops = fops;
  82249. +}
  82250. +
  82251. +/**
  82252. + * PCD Callback function for initializing the PCD when switching to
  82253. + * device mode.
  82254. + *
  82255. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  82256. + */
  82257. +static int32_t dwc_otg_pcd_start_cb(void *p)
  82258. +{
  82259. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  82260. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82261. +
  82262. + /*
  82263. + * Initialized the Core for Device mode.
  82264. + */
  82265. + if (dwc_otg_is_device_mode(core_if)) {
  82266. + dwc_otg_core_dev_init(core_if);
  82267. + /* Set core_if's lock pointer to the pcd->lock */
  82268. + core_if->lock = pcd->lock;
  82269. + }
  82270. + return 1;
  82271. +}
  82272. +
  82273. +/** CFI-specific buffer allocation function for EP */
  82274. +#ifdef DWC_UTE_CFI
  82275. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  82276. + size_t buflen, int flags)
  82277. +{
  82278. + dwc_otg_pcd_ep_t *ep;
  82279. + ep = get_ep_from_handle(pcd, pep);
  82280. + if (!ep) {
  82281. + DWC_WARN("bad ep\n");
  82282. + return -DWC_E_INVALID;
  82283. + }
  82284. +
  82285. + return pcd->cfi->ops.ep_alloc_buf(pcd->cfi, pcd, ep, addr, buflen,
  82286. + flags);
  82287. +}
  82288. +#else
  82289. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  82290. + size_t buflen, int flags);
  82291. +#endif
  82292. +
  82293. +/**
  82294. + * PCD Callback function for notifying the PCD when resuming from
  82295. + * suspend.
  82296. + *
  82297. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  82298. + */
  82299. +static int32_t dwc_otg_pcd_resume_cb(void *p)
  82300. +{
  82301. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  82302. +
  82303. + if (pcd->fops->resume) {
  82304. + pcd->fops->resume(pcd);
  82305. + }
  82306. +
  82307. + /* Stop the SRP timeout timer. */
  82308. + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS)
  82309. + || (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
  82310. + if (GET_CORE_IF(pcd)->srp_timer_started) {
  82311. + GET_CORE_IF(pcd)->srp_timer_started = 0;
  82312. + DWC_TIMER_CANCEL(GET_CORE_IF(pcd)->srp_timer);
  82313. + }
  82314. + }
  82315. + return 1;
  82316. +}
  82317. +
  82318. +/**
  82319. + * PCD Callback function for notifying the PCD device is suspended.
  82320. + *
  82321. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  82322. + */
  82323. +static int32_t dwc_otg_pcd_suspend_cb(void *p)
  82324. +{
  82325. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  82326. +
  82327. + if (pcd->fops->suspend) {
  82328. + DWC_SPINUNLOCK(pcd->lock);
  82329. + pcd->fops->suspend(pcd);
  82330. + DWC_SPINLOCK(pcd->lock);
  82331. + }
  82332. +
  82333. + return 1;
  82334. +}
  82335. +
  82336. +/**
  82337. + * PCD Callback function for stopping the PCD when switching to Host
  82338. + * mode.
  82339. + *
  82340. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  82341. + */
  82342. +static int32_t dwc_otg_pcd_stop_cb(void *p)
  82343. +{
  82344. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  82345. + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t * _pcd);
  82346. +
  82347. + dwc_otg_pcd_stop(pcd);
  82348. + return 1;
  82349. +}
  82350. +
  82351. +/**
  82352. + * PCD Callback structure for handling mode switching.
  82353. + */
  82354. +static dwc_otg_cil_callbacks_t pcd_callbacks = {
  82355. + .start = dwc_otg_pcd_start_cb,
  82356. + .stop = dwc_otg_pcd_stop_cb,
  82357. + .suspend = dwc_otg_pcd_suspend_cb,
  82358. + .resume_wakeup = dwc_otg_pcd_resume_cb,
  82359. + .p = 0, /* Set at registration */
  82360. +};
  82361. +
  82362. +/**
  82363. + * This function allocates a DMA Descriptor chain for the Endpoint
  82364. + * buffer to be used for a transfer to/from the specified endpoint.
  82365. + */
  82366. +dwc_otg_dev_dma_desc_t *dwc_otg_ep_alloc_desc_chain(dwc_dma_t * dma_desc_addr,
  82367. + uint32_t count)
  82368. +{
  82369. + return DWC_DMA_ALLOC_ATOMIC(count * sizeof(dwc_otg_dev_dma_desc_t),
  82370. + dma_desc_addr);
  82371. +}
  82372. +
  82373. +/**
  82374. + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
  82375. + */
  82376. +void dwc_otg_ep_free_desc_chain(dwc_otg_dev_dma_desc_t * desc_addr,
  82377. + uint32_t dma_desc_addr, uint32_t count)
  82378. +{
  82379. + DWC_DMA_FREE(count * sizeof(dwc_otg_dev_dma_desc_t), desc_addr,
  82380. + dma_desc_addr);
  82381. +}
  82382. +
  82383. +#ifdef DWC_EN_ISOC
  82384. +
  82385. +/**
  82386. + * This function initializes a descriptor chain for Isochronous transfer
  82387. + *
  82388. + * @param core_if Programming view of DWC_otg controller.
  82389. + * @param dwc_ep The EP to start the transfer on.
  82390. + *
  82391. + */
  82392. +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t * core_if,
  82393. + dwc_ep_t * dwc_ep)
  82394. +{
  82395. +
  82396. + dsts_data_t dsts = {.d32 = 0 };
  82397. + depctl_data_t depctl = {.d32 = 0 };
  82398. + volatile uint32_t *addr;
  82399. + int i, j;
  82400. + uint32_t len;
  82401. +
  82402. + if (dwc_ep->is_in)
  82403. + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
  82404. + else
  82405. + dwc_ep->desc_cnt =
  82406. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  82407. + dwc_ep->bInterval;
  82408. +
  82409. + /** Allocate descriptors for double buffering */
  82410. + dwc_ep->iso_desc_addr =
  82411. + dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,
  82412. + dwc_ep->desc_cnt * 2);
  82413. + if (dwc_ep->desc_addr) {
  82414. + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
  82415. + return;
  82416. + }
  82417. +
  82418. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  82419. +
  82420. + /** ISO OUT EP */
  82421. + if (dwc_ep->is_in == 0) {
  82422. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  82423. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  82424. + dma_addr_t dma_ad;
  82425. + uint32_t data_per_desc;
  82426. + dwc_otg_dev_out_ep_regs_t *out_regs =
  82427. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  82428. + int offset;
  82429. +
  82430. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  82431. + dma_ad = (dma_addr_t) DWC_READ_REG32(&(out_regs->doepdma));
  82432. +
  82433. + /** Buffer 0 descriptors setup */
  82434. + dma_ad = dwc_ep->dma_addr0;
  82435. +
  82436. + sts.b_iso_out.bs = BS_HOST_READY;
  82437. + sts.b_iso_out.rxsts = 0;
  82438. + sts.b_iso_out.l = 0;
  82439. + sts.b_iso_out.sp = 0;
  82440. + sts.b_iso_out.ioc = 0;
  82441. + sts.b_iso_out.pid = 0;
  82442. + sts.b_iso_out.framenum = 0;
  82443. +
  82444. + offset = 0;
  82445. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  82446. + i += dwc_ep->pkt_per_frm) {
  82447. +
  82448. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  82449. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  82450. + if (len > dwc_ep->data_per_frame)
  82451. + data_per_desc =
  82452. + dwc_ep->data_per_frame -
  82453. + j * dwc_ep->maxpacket;
  82454. + else
  82455. + data_per_desc = dwc_ep->maxpacket;
  82456. + len = data_per_desc % 4;
  82457. + if (len)
  82458. + data_per_desc += 4 - len;
  82459. +
  82460. + sts.b_iso_out.rxbytes = data_per_desc;
  82461. + dma_desc->buf = dma_ad;
  82462. + dma_desc->status.d32 = sts.d32;
  82463. +
  82464. + offset += data_per_desc;
  82465. + dma_desc++;
  82466. + dma_ad += data_per_desc;
  82467. + }
  82468. + }
  82469. +
  82470. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  82471. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  82472. + if (len > dwc_ep->data_per_frame)
  82473. + data_per_desc =
  82474. + dwc_ep->data_per_frame -
  82475. + j * dwc_ep->maxpacket;
  82476. + else
  82477. + data_per_desc = dwc_ep->maxpacket;
  82478. + len = data_per_desc % 4;
  82479. + if (len)
  82480. + data_per_desc += 4 - len;
  82481. + sts.b_iso_out.rxbytes = data_per_desc;
  82482. + dma_desc->buf = dma_ad;
  82483. + dma_desc->status.d32 = sts.d32;
  82484. +
  82485. + offset += data_per_desc;
  82486. + dma_desc++;
  82487. + dma_ad += data_per_desc;
  82488. + }
  82489. +
  82490. + sts.b_iso_out.ioc = 1;
  82491. + len = (j + 1) * dwc_ep->maxpacket;
  82492. + if (len > dwc_ep->data_per_frame)
  82493. + data_per_desc =
  82494. + dwc_ep->data_per_frame - j * dwc_ep->maxpacket;
  82495. + else
  82496. + data_per_desc = dwc_ep->maxpacket;
  82497. + len = data_per_desc % 4;
  82498. + if (len)
  82499. + data_per_desc += 4 - len;
  82500. + sts.b_iso_out.rxbytes = data_per_desc;
  82501. +
  82502. + dma_desc->buf = dma_ad;
  82503. + dma_desc->status.d32 = sts.d32;
  82504. + dma_desc++;
  82505. +
  82506. + /** Buffer 1 descriptors setup */
  82507. + sts.b_iso_out.ioc = 0;
  82508. + dma_ad = dwc_ep->dma_addr1;
  82509. +
  82510. + offset = 0;
  82511. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  82512. + i += dwc_ep->pkt_per_frm) {
  82513. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  82514. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  82515. + if (len > dwc_ep->data_per_frame)
  82516. + data_per_desc =
  82517. + dwc_ep->data_per_frame -
  82518. + j * dwc_ep->maxpacket;
  82519. + else
  82520. + data_per_desc = dwc_ep->maxpacket;
  82521. + len = data_per_desc % 4;
  82522. + if (len)
  82523. + data_per_desc += 4 - len;
  82524. +
  82525. + data_per_desc =
  82526. + sts.b_iso_out.rxbytes = data_per_desc;
  82527. + dma_desc->buf = dma_ad;
  82528. + dma_desc->status.d32 = sts.d32;
  82529. +
  82530. + offset += data_per_desc;
  82531. + dma_desc++;
  82532. + dma_ad += data_per_desc;
  82533. + }
  82534. + }
  82535. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  82536. + data_per_desc =
  82537. + ((j + 1) * dwc_ep->maxpacket >
  82538. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  82539. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  82540. + data_per_desc +=
  82541. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  82542. + sts.b_iso_out.rxbytes = data_per_desc;
  82543. + dma_desc->buf = dma_ad;
  82544. + dma_desc->status.d32 = sts.d32;
  82545. +
  82546. + offset += data_per_desc;
  82547. + dma_desc++;
  82548. + dma_ad += data_per_desc;
  82549. + }
  82550. +
  82551. + sts.b_iso_out.ioc = 1;
  82552. + sts.b_iso_out.l = 1;
  82553. + data_per_desc =
  82554. + ((j + 1) * dwc_ep->maxpacket >
  82555. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  82556. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  82557. + data_per_desc +=
  82558. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  82559. + sts.b_iso_out.rxbytes = data_per_desc;
  82560. +
  82561. + dma_desc->buf = dma_ad;
  82562. + dma_desc->status.d32 = sts.d32;
  82563. +
  82564. + dwc_ep->next_frame = 0;
  82565. +
  82566. + /** Write dma_ad into DOEPDMA register */
  82567. + DWC_WRITE_REG32(&(out_regs->doepdma),
  82568. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  82569. +
  82570. + }
  82571. + /** ISO IN EP */
  82572. + else {
  82573. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  82574. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  82575. + dma_addr_t dma_ad;
  82576. + dwc_otg_dev_in_ep_regs_t *in_regs =
  82577. + core_if->dev_if->in_ep_regs[dwc_ep->num];
  82578. + unsigned int frmnumber;
  82579. + fifosize_data_t txfifosize, rxfifosize;
  82580. +
  82581. + txfifosize.d32 =
  82582. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->
  82583. + dtxfsts);
  82584. + rxfifosize.d32 =
  82585. + DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  82586. +
  82587. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  82588. +
  82589. + dma_ad = dwc_ep->dma_addr0;
  82590. +
  82591. + dsts.d32 =
  82592. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  82593. +
  82594. + sts.b_iso_in.bs = BS_HOST_READY;
  82595. + sts.b_iso_in.txsts = 0;
  82596. + sts.b_iso_in.sp =
  82597. + (dwc_ep->data_per_frame % dwc_ep->maxpacket) ? 1 : 0;
  82598. + sts.b_iso_in.ioc = 0;
  82599. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  82600. +
  82601. + frmnumber = dwc_ep->next_frame;
  82602. +
  82603. + sts.b_iso_in.framenum = frmnumber;
  82604. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  82605. + sts.b_iso_in.l = 0;
  82606. +
  82607. + /** Buffer 0 descriptors setup */
  82608. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  82609. + dma_desc->buf = dma_ad;
  82610. + dma_desc->status.d32 = sts.d32;
  82611. + dma_desc++;
  82612. +
  82613. + dma_ad += dwc_ep->data_per_frame;
  82614. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  82615. + }
  82616. +
  82617. + sts.b_iso_in.ioc = 1;
  82618. + dma_desc->buf = dma_ad;
  82619. + dma_desc->status.d32 = sts.d32;
  82620. + ++dma_desc;
  82621. +
  82622. + /** Buffer 1 descriptors setup */
  82623. + sts.b_iso_in.ioc = 0;
  82624. + dma_ad = dwc_ep->dma_addr1;
  82625. +
  82626. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  82627. + i += dwc_ep->pkt_per_frm) {
  82628. + dma_desc->buf = dma_ad;
  82629. + dma_desc->status.d32 = sts.d32;
  82630. + dma_desc++;
  82631. +
  82632. + dma_ad += dwc_ep->data_per_frame;
  82633. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  82634. +
  82635. + sts.b_iso_in.ioc = 0;
  82636. + }
  82637. + sts.b_iso_in.ioc = 1;
  82638. + sts.b_iso_in.l = 1;
  82639. +
  82640. + dma_desc->buf = dma_ad;
  82641. + dma_desc->status.d32 = sts.d32;
  82642. +
  82643. + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
  82644. +
  82645. + /** Write dma_ad into diepdma register */
  82646. + DWC_WRITE_REG32(&(in_regs->diepdma),
  82647. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  82648. + }
  82649. + /** Enable endpoint, clear nak */
  82650. + depctl.d32 = 0;
  82651. + depctl.b.epena = 1;
  82652. + depctl.b.usbactep = 1;
  82653. + depctl.b.cnak = 1;
  82654. +
  82655. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  82656. + depctl.d32 = DWC_READ_REG32(addr);
  82657. +}
  82658. +
  82659. +/**
  82660. + * This function initializes a descriptor chain for Isochronous transfer
  82661. + *
  82662. + * @param core_if Programming view of DWC_otg controller.
  82663. + * @param ep The EP to start the transfer on.
  82664. + *
  82665. + */
  82666. +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  82667. + dwc_ep_t * ep)
  82668. +{
  82669. + depctl_data_t depctl = {.d32 = 0 };
  82670. + volatile uint32_t *addr;
  82671. +
  82672. + if (ep->is_in) {
  82673. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  82674. + } else {
  82675. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  82676. + }
  82677. +
  82678. + if (core_if->dma_enable == 0 || core_if->dma_desc_enable != 0) {
  82679. + return;
  82680. + } else {
  82681. + deptsiz_data_t deptsiz = {.d32 = 0 };
  82682. +
  82683. + ep->xfer_len =
  82684. + ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
  82685. + ep->pkt_cnt =
  82686. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  82687. + ep->xfer_count = 0;
  82688. + ep->xfer_buff =
  82689. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  82690. + ep->dma_addr =
  82691. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  82692. +
  82693. + if (ep->is_in) {
  82694. + /* Program the transfer size and packet count
  82695. + * as follows: xfersize = N * maxpacket +
  82696. + * short_packet pktcnt = N + (short_packet
  82697. + * exist ? 1 : 0)
  82698. + */
  82699. + deptsiz.b.mc = ep->pkt_per_frm;
  82700. + deptsiz.b.xfersize = ep->xfer_len;
  82701. + deptsiz.b.pktcnt =
  82702. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  82703. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  82704. + dieptsiz, deptsiz.d32);
  82705. +
  82706. + /* Write the DMA register */
  82707. + DWC_WRITE_REG32(&
  82708. + (core_if->dev_if->in_ep_regs[ep->num]->
  82709. + diepdma), (uint32_t) ep->dma_addr);
  82710. +
  82711. + } else {
  82712. + deptsiz.b.pktcnt =
  82713. + (ep->xfer_len + (ep->maxpacket - 1)) /
  82714. + ep->maxpacket;
  82715. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  82716. +
  82717. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  82718. + doeptsiz, deptsiz.d32);
  82719. +
  82720. + /* Write the DMA register */
  82721. + DWC_WRITE_REG32(&
  82722. + (core_if->dev_if->out_ep_regs[ep->num]->
  82723. + doepdma), (uint32_t) ep->dma_addr);
  82724. +
  82725. + }
  82726. + /** Enable endpoint, clear nak */
  82727. + depctl.d32 = 0;
  82728. + depctl.b.epena = 1;
  82729. + depctl.b.cnak = 1;
  82730. +
  82731. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  82732. + }
  82733. +}
  82734. +
  82735. +/**
  82736. + * This function does the setup for a data transfer for an EP and
  82737. + * starts the transfer. For an IN transfer, the packets will be
  82738. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  82739. + * the packets are unloaded from the Rx FIFO in the ISR.
  82740. + *
  82741. + * @param core_if Programming view of DWC_otg controller.
  82742. + * @param ep The EP to start the transfer on.
  82743. + */
  82744. +
  82745. +static void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t * core_if,
  82746. + dwc_ep_t * ep)
  82747. +{
  82748. + if (core_if->dma_enable) {
  82749. + if (core_if->dma_desc_enable) {
  82750. + if (ep->is_in) {
  82751. + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
  82752. + } else {
  82753. + ep->desc_cnt = ep->pkt_cnt;
  82754. + }
  82755. + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
  82756. + } else {
  82757. + if (core_if->pti_enh_enable) {
  82758. + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
  82759. + } else {
  82760. + ep->cur_pkt_addr =
  82761. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->
  82762. + xfer_buff0;
  82763. + ep->cur_pkt_dma_addr =
  82764. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->
  82765. + dma_addr0;
  82766. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  82767. + }
  82768. + }
  82769. + } else {
  82770. + ep->cur_pkt_addr =
  82771. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  82772. + ep->cur_pkt_dma_addr =
  82773. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  82774. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  82775. + }
  82776. +}
  82777. +
  82778. +/**
  82779. + * This function stops transfer for an EP and
  82780. + * resets the ep's variables.
  82781. + *
  82782. + * @param core_if Programming view of DWC_otg controller.
  82783. + * @param ep The EP to start the transfer on.
  82784. + */
  82785. +
  82786. +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  82787. +{
  82788. + depctl_data_t depctl = {.d32 = 0 };
  82789. + volatile uint32_t *addr;
  82790. +
  82791. + if (ep->is_in == 1) {
  82792. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  82793. + } else {
  82794. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  82795. + }
  82796. +
  82797. + /* disable the ep */
  82798. + depctl.d32 = DWC_READ_REG32(addr);
  82799. +
  82800. + depctl.b.epdis = 1;
  82801. + depctl.b.snak = 1;
  82802. +
  82803. + DWC_WRITE_REG32(addr, depctl.d32);
  82804. +
  82805. + if (core_if->dma_desc_enable &&
  82806. + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
  82807. + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,
  82808. + ep->iso_dma_desc_addr,
  82809. + ep->desc_cnt * 2);
  82810. + }
  82811. +
  82812. + /* reset varibales */
  82813. + ep->dma_addr0 = 0;
  82814. + ep->dma_addr1 = 0;
  82815. + ep->xfer_buff0 = 0;
  82816. + ep->xfer_buff1 = 0;
  82817. + ep->data_per_frame = 0;
  82818. + ep->data_pattern_frame = 0;
  82819. + ep->sync_frame = 0;
  82820. + ep->buf_proc_intrvl = 0;
  82821. + ep->bInterval = 0;
  82822. + ep->proc_buf_num = 0;
  82823. + ep->pkt_per_frm = 0;
  82824. + ep->pkt_per_frm = 0;
  82825. + ep->desc_cnt = 0;
  82826. + ep->iso_desc_addr = 0;
  82827. + ep->iso_dma_desc_addr = 0;
  82828. +}
  82829. +
  82830. +int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  82831. + uint8_t * buf0, uint8_t * buf1, dwc_dma_t dma0,
  82832. + dwc_dma_t dma1, int sync_frame, int dp_frame,
  82833. + int data_per_frame, int start_frame,
  82834. + int buf_proc_intrvl, void *req_handle,
  82835. + int atomic_alloc)
  82836. +{
  82837. + dwc_otg_pcd_ep_t *ep;
  82838. + dwc_irqflags_t flags = 0;
  82839. + dwc_ep_t *dwc_ep;
  82840. + int32_t frm_data;
  82841. + dsts_data_t dsts;
  82842. + dwc_otg_core_if_t *core_if;
  82843. +
  82844. + ep = get_ep_from_handle(pcd, ep_handle);
  82845. +
  82846. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  82847. + DWC_WARN("bad ep\n");
  82848. + return -DWC_E_INVALID;
  82849. + }
  82850. +
  82851. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82852. + core_if = GET_CORE_IF(pcd);
  82853. + dwc_ep = &ep->dwc_ep;
  82854. +
  82855. + if (ep->iso_req_handle) {
  82856. + DWC_WARN("ISO request in progress\n");
  82857. + }
  82858. +
  82859. + dwc_ep->dma_addr0 = dma0;
  82860. + dwc_ep->dma_addr1 = dma1;
  82861. +
  82862. + dwc_ep->xfer_buff0 = buf0;
  82863. + dwc_ep->xfer_buff1 = buf1;
  82864. +
  82865. + dwc_ep->data_per_frame = data_per_frame;
  82866. +
  82867. + /** @todo - pattern data support is to be implemented in the future */
  82868. + dwc_ep->data_pattern_frame = dp_frame;
  82869. + dwc_ep->sync_frame = sync_frame;
  82870. +
  82871. + dwc_ep->buf_proc_intrvl = buf_proc_intrvl;
  82872. +
  82873. + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
  82874. +
  82875. + dwc_ep->proc_buf_num = 0;
  82876. +
  82877. + dwc_ep->pkt_per_frm = 0;
  82878. + frm_data = ep->dwc_ep.data_per_frame;
  82879. + while (frm_data > 0) {
  82880. + dwc_ep->pkt_per_frm++;
  82881. + frm_data -= ep->dwc_ep.maxpacket;
  82882. + }
  82883. +
  82884. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  82885. +
  82886. + if (start_frame == -1) {
  82887. + dwc_ep->next_frame = dsts.b.soffn + 1;
  82888. + if (dwc_ep->bInterval != 1) {
  82889. + dwc_ep->next_frame =
  82890. + dwc_ep->next_frame + (dwc_ep->bInterval - 1 -
  82891. + dwc_ep->next_frame %
  82892. + dwc_ep->bInterval);
  82893. + }
  82894. + } else {
  82895. + dwc_ep->next_frame = start_frame;
  82896. + }
  82897. +
  82898. + if (!core_if->pti_enh_enable) {
  82899. + dwc_ep->pkt_cnt =
  82900. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  82901. + dwc_ep->bInterval;
  82902. + } else {
  82903. + dwc_ep->pkt_cnt =
  82904. + (dwc_ep->data_per_frame *
  82905. + (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
  82906. + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
  82907. + }
  82908. +
  82909. + if (core_if->dma_desc_enable) {
  82910. + dwc_ep->desc_cnt =
  82911. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  82912. + dwc_ep->bInterval;
  82913. + }
  82914. +
  82915. + if (atomic_alloc) {
  82916. + dwc_ep->pkt_info =
  82917. + DWC_ALLOC_ATOMIC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  82918. + } else {
  82919. + dwc_ep->pkt_info =
  82920. + DWC_ALLOC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  82921. + }
  82922. + if (!dwc_ep->pkt_info) {
  82923. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82924. + return -DWC_E_NO_MEMORY;
  82925. + }
  82926. + if (core_if->pti_enh_enable) {
  82927. + dwc_memset(dwc_ep->pkt_info, 0,
  82928. + sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  82929. + }
  82930. +
  82931. + dwc_ep->cur_pkt = 0;
  82932. + ep->iso_req_handle = req_handle;
  82933. +
  82934. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82935. + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
  82936. + return 0;
  82937. +}
  82938. +
  82939. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  82940. + void *req_handle)
  82941. +{
  82942. + dwc_irqflags_t flags = 0;
  82943. + dwc_otg_pcd_ep_t *ep;
  82944. + dwc_ep_t *dwc_ep;
  82945. +
  82946. + ep = get_ep_from_handle(pcd, ep_handle);
  82947. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  82948. + DWC_WARN("bad ep\n");
  82949. + return -DWC_E_INVALID;
  82950. + }
  82951. + dwc_ep = &ep->dwc_ep;
  82952. +
  82953. + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
  82954. +
  82955. + DWC_FREE(dwc_ep->pkt_info);
  82956. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82957. + if (ep->iso_req_handle != req_handle) {
  82958. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82959. + return -DWC_E_INVALID;
  82960. + }
  82961. +
  82962. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82963. +
  82964. + ep->iso_req_handle = 0;
  82965. + return 0;
  82966. +}
  82967. +
  82968. +/**
  82969. + * This function is used for perodical data exchnage between PCD and gadget drivers.
  82970. + * for Isochronous EPs
  82971. + *
  82972. + * - Every time a sync period completes this function is called to
  82973. + * perform data exchange between PCD and gadget
  82974. + */
  82975. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  82976. + void *req_handle)
  82977. +{
  82978. + int i;
  82979. + dwc_ep_t *dwc_ep;
  82980. +
  82981. + dwc_ep = &ep->dwc_ep;
  82982. +
  82983. + DWC_SPINUNLOCK(ep->pcd->lock);
  82984. + pcd->fops->isoc_complete(pcd, ep->priv, ep->iso_req_handle,
  82985. + dwc_ep->proc_buf_num ^ 0x1);
  82986. + DWC_SPINLOCK(ep->pcd->lock);
  82987. +
  82988. + for (i = 0; i < dwc_ep->pkt_cnt; ++i) {
  82989. + dwc_ep->pkt_info[i].status = 0;
  82990. + dwc_ep->pkt_info[i].offset = 0;
  82991. + dwc_ep->pkt_info[i].length = 0;
  82992. + }
  82993. +}
  82994. +
  82995. +int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd, void *ep_handle,
  82996. + void *iso_req_handle)
  82997. +{
  82998. + dwc_otg_pcd_ep_t *ep;
  82999. + dwc_ep_t *dwc_ep;
  83000. +
  83001. + ep = get_ep_from_handle(pcd, ep_handle);
  83002. + if (!ep->desc || ep->dwc_ep.num == 0) {
  83003. + DWC_WARN("bad ep\n");
  83004. + return -DWC_E_INVALID;
  83005. + }
  83006. + dwc_ep = &ep->dwc_ep;
  83007. +
  83008. + return dwc_ep->pkt_cnt;
  83009. +}
  83010. +
  83011. +void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd, void *ep_handle,
  83012. + void *iso_req_handle, int packet,
  83013. + int *status, int *actual, int *offset)
  83014. +{
  83015. + dwc_otg_pcd_ep_t *ep;
  83016. + dwc_ep_t *dwc_ep;
  83017. +
  83018. + ep = get_ep_from_handle(pcd, ep_handle);
  83019. + if (!ep)
  83020. + DWC_WARN("bad ep\n");
  83021. +
  83022. + dwc_ep = &ep->dwc_ep;
  83023. +
  83024. + *status = dwc_ep->pkt_info[packet].status;
  83025. + *actual = dwc_ep->pkt_info[packet].length;
  83026. + *offset = dwc_ep->pkt_info[packet].offset;
  83027. +}
  83028. +
  83029. +#endif /* DWC_EN_ISOC */
  83030. +
  83031. +static void dwc_otg_pcd_init_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * pcd_ep,
  83032. + uint32_t is_in, uint32_t ep_num)
  83033. +{
  83034. + /* Init EP structure */
  83035. + pcd_ep->desc = 0;
  83036. + pcd_ep->pcd = pcd;
  83037. + pcd_ep->stopped = 1;
  83038. + pcd_ep->queue_sof = 0;
  83039. +
  83040. + /* Init DWC ep structure */
  83041. + pcd_ep->dwc_ep.is_in = is_in;
  83042. + pcd_ep->dwc_ep.num = ep_num;
  83043. + pcd_ep->dwc_ep.active = 0;
  83044. + pcd_ep->dwc_ep.tx_fifo_num = 0;
  83045. + /* Control until ep is actvated */
  83046. + pcd_ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  83047. + pcd_ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
  83048. + pcd_ep->dwc_ep.dma_addr = 0;
  83049. + pcd_ep->dwc_ep.start_xfer_buff = 0;
  83050. + pcd_ep->dwc_ep.xfer_buff = 0;
  83051. + pcd_ep->dwc_ep.xfer_len = 0;
  83052. + pcd_ep->dwc_ep.xfer_count = 0;
  83053. + pcd_ep->dwc_ep.sent_zlp = 0;
  83054. + pcd_ep->dwc_ep.total_len = 0;
  83055. + pcd_ep->dwc_ep.desc_addr = 0;
  83056. + pcd_ep->dwc_ep.dma_desc_addr = 0;
  83057. + DWC_CIRCLEQ_INIT(&pcd_ep->queue);
  83058. +}
  83059. +
  83060. +/**
  83061. + * Initialize ep's
  83062. + */
  83063. +static void dwc_otg_pcd_reinit(dwc_otg_pcd_t * pcd)
  83064. +{
  83065. + int i;
  83066. + uint32_t hwcfg1;
  83067. + dwc_otg_pcd_ep_t *ep;
  83068. + int in_ep_cntr, out_ep_cntr;
  83069. + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
  83070. + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
  83071. +
  83072. + /**
  83073. + * Initialize the EP0 structure.
  83074. + */
  83075. + ep = &pcd->ep0;
  83076. + dwc_otg_pcd_init_ep(pcd, ep, 0, 0);
  83077. +
  83078. + in_ep_cntr = 0;
  83079. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
  83080. + for (i = 1; in_ep_cntr < num_in_eps; i++) {
  83081. + if ((hwcfg1 & 0x1) == 0) {
  83082. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
  83083. + in_ep_cntr++;
  83084. + /**
  83085. + * @todo NGS: Add direction to EP, based on contents
  83086. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  83087. + * sprintf(";r
  83088. + */
  83089. + dwc_otg_pcd_init_ep(pcd, ep, 1 /* IN */ , i);
  83090. +
  83091. + DWC_CIRCLEQ_INIT(&ep->queue);
  83092. + }
  83093. + hwcfg1 >>= 2;
  83094. + }
  83095. +
  83096. + out_ep_cntr = 0;
  83097. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
  83098. + for (i = 1; out_ep_cntr < num_out_eps; i++) {
  83099. + if ((hwcfg1 & 0x1) == 0) {
  83100. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
  83101. + out_ep_cntr++;
  83102. + /**
  83103. + * @todo NGS: Add direction to EP, based on contents
  83104. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  83105. + * sprintf(";r
  83106. + */
  83107. + dwc_otg_pcd_init_ep(pcd, ep, 0 /* OUT */ , i);
  83108. + DWC_CIRCLEQ_INIT(&ep->queue);
  83109. + }
  83110. + hwcfg1 >>= 2;
  83111. + }
  83112. +
  83113. + pcd->ep0state = EP0_DISCONNECT;
  83114. + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
  83115. + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  83116. +}
  83117. +
  83118. +/**
  83119. + * This function is called when the SRP timer expires. The SRP should
  83120. + * complete within 6 seconds.
  83121. + */
  83122. +static void srp_timeout(void *ptr)
  83123. +{
  83124. + gotgctl_data_t gotgctl;
  83125. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  83126. + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
  83127. +
  83128. + gotgctl.d32 = DWC_READ_REG32(addr);
  83129. +
  83130. + core_if->srp_timer_started = 0;
  83131. +
  83132. + if (core_if->adp_enable) {
  83133. + if (gotgctl.b.bsesvld == 0) {
  83134. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  83135. + DWC_PRINTF("SRP Timeout BSESSVLD = 0\n");
  83136. + /* Power off the core */
  83137. + if (core_if->power_down == 2) {
  83138. + gpwrdn.b.pwrdnswtch = 1;
  83139. + DWC_MODIFY_REG32(&core_if->
  83140. + core_global_regs->gpwrdn,
  83141. + gpwrdn.d32, 0);
  83142. + }
  83143. +
  83144. + gpwrdn.d32 = 0;
  83145. + gpwrdn.b.pmuintsel = 1;
  83146. + gpwrdn.b.pmuactv = 1;
  83147. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  83148. + gpwrdn.d32);
  83149. + dwc_otg_adp_probe_start(core_if);
  83150. + } else {
  83151. + DWC_PRINTF("SRP Timeout BSESSVLD = 1\n");
  83152. + core_if->op_state = B_PERIPHERAL;
  83153. + dwc_otg_core_init(core_if);
  83154. + dwc_otg_enable_global_interrupts(core_if);
  83155. + cil_pcd_start(core_if);
  83156. + }
  83157. + }
  83158. +
  83159. + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
  83160. + (core_if->core_params->i2c_enable)) {
  83161. + DWC_PRINTF("SRP Timeout\n");
  83162. +
  83163. + if ((core_if->srp_success) && (gotgctl.b.bsesvld)) {
  83164. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  83165. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  83166. + }
  83167. +
  83168. + /* Clear Session Request */
  83169. + gotgctl.d32 = 0;
  83170. + gotgctl.b.sesreq = 1;
  83171. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl,
  83172. + gotgctl.d32, 0);
  83173. +
  83174. + core_if->srp_success = 0;
  83175. + } else {
  83176. + __DWC_ERROR("Device not connected/responding\n");
  83177. + gotgctl.b.sesreq = 0;
  83178. + DWC_WRITE_REG32(addr, gotgctl.d32);
  83179. + }
  83180. + } else if (gotgctl.b.sesreq) {
  83181. + DWC_PRINTF("SRP Timeout\n");
  83182. +
  83183. + __DWC_ERROR("Device not connected/responding\n");
  83184. + gotgctl.b.sesreq = 0;
  83185. + DWC_WRITE_REG32(addr, gotgctl.d32);
  83186. + } else {
  83187. + DWC_PRINTF(" SRP GOTGCTL=%0x\n", gotgctl.d32);
  83188. + }
  83189. +}
  83190. +
  83191. +/**
  83192. + * Tasklet
  83193. + *
  83194. + */
  83195. +extern void start_next_request(dwc_otg_pcd_ep_t * ep);
  83196. +
  83197. +static void start_xfer_tasklet_func(void *data)
  83198. +{
  83199. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  83200. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83201. +
  83202. + int i;
  83203. + depctl_data_t diepctl;
  83204. +
  83205. + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
  83206. +
  83207. + diepctl.d32 = DWC_READ_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl);
  83208. +
  83209. + if (pcd->ep0.queue_sof) {
  83210. + pcd->ep0.queue_sof = 0;
  83211. + start_next_request(&pcd->ep0);
  83212. + // break;
  83213. + }
  83214. +
  83215. + for (i = 0; i < core_if->dev_if->num_in_eps; i++) {
  83216. + depctl_data_t diepctl;
  83217. + diepctl.d32 =
  83218. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  83219. +
  83220. + if (pcd->in_ep[i].queue_sof) {
  83221. + pcd->in_ep[i].queue_sof = 0;
  83222. + start_next_request(&pcd->in_ep[i]);
  83223. + // break;
  83224. + }
  83225. + }
  83226. +
  83227. + return;
  83228. +}
  83229. +
  83230. +/**
  83231. + * This function initialized the PCD portion of the driver.
  83232. + *
  83233. + */
  83234. +dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
  83235. +{
  83236. + dwc_otg_pcd_t *pcd = NULL;
  83237. + dwc_otg_dev_if_t *dev_if;
  83238. + int i;
  83239. +
  83240. + /*
  83241. + * Allocate PCD structure
  83242. + */
  83243. + pcd = DWC_ALLOC(sizeof(dwc_otg_pcd_t));
  83244. +
  83245. + if (pcd == NULL) {
  83246. + return NULL;
  83247. + }
  83248. +
  83249. + pcd->lock = DWC_SPINLOCK_ALLOC();
  83250. + DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
  83251. + pcd, core_if);//GRAYG
  83252. + if (!pcd->lock) {
  83253. + DWC_ERROR("Could not allocate lock for pcd");
  83254. + DWC_FREE(pcd);
  83255. + return NULL;
  83256. + }
  83257. + /* Set core_if's lock pointer to hcd->lock */
  83258. + core_if->lock = pcd->lock;
  83259. + pcd->core_if = core_if;
  83260. +
  83261. + dev_if = core_if->dev_if;
  83262. + dev_if->isoc_ep = NULL;
  83263. +
  83264. + if (core_if->hwcfg4.b.ded_fifo_en) {
  83265. + DWC_PRINTF("Dedicated Tx FIFOs mode\n");
  83266. + } else {
  83267. + DWC_PRINTF("Shared Tx FIFO mode\n");
  83268. + }
  83269. +
  83270. + /*
  83271. + * Initialized the Core for Device mode here if there is nod ADP support.
  83272. + * Otherwise it will be done later in dwc_otg_adp_start routine.
  83273. + */
  83274. + if (dwc_otg_is_device_mode(core_if) /*&& !core_if->adp_enable*/) {
  83275. + dwc_otg_core_dev_init(core_if);
  83276. + }
  83277. +
  83278. + /*
  83279. + * Register the PCD Callbacks.
  83280. + */
  83281. + dwc_otg_cil_register_pcd_callbacks(core_if, &pcd_callbacks, pcd);
  83282. +
  83283. + /*
  83284. + * Initialize the DMA buffer for SETUP packets
  83285. + */
  83286. + if (GET_CORE_IF(pcd)->dma_enable) {
  83287. + pcd->setup_pkt =
  83288. + DWC_DMA_ALLOC(sizeof(*pcd->setup_pkt) * 5,
  83289. + &pcd->setup_pkt_dma_handle);
  83290. + if (pcd->setup_pkt == NULL) {
  83291. + DWC_FREE(pcd);
  83292. + return NULL;
  83293. + }
  83294. +
  83295. + pcd->status_buf =
  83296. + DWC_DMA_ALLOC(sizeof(uint16_t),
  83297. + &pcd->status_buf_dma_handle);
  83298. + if (pcd->status_buf == NULL) {
  83299. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  83300. + pcd->setup_pkt, pcd->setup_pkt_dma_handle);
  83301. + DWC_FREE(pcd);
  83302. + return NULL;
  83303. + }
  83304. +
  83305. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  83306. + dev_if->setup_desc_addr[0] =
  83307. + dwc_otg_ep_alloc_desc_chain
  83308. + (&dev_if->dma_setup_desc_addr[0], 1);
  83309. + dev_if->setup_desc_addr[1] =
  83310. + dwc_otg_ep_alloc_desc_chain
  83311. + (&dev_if->dma_setup_desc_addr[1], 1);
  83312. + dev_if->in_desc_addr =
  83313. + dwc_otg_ep_alloc_desc_chain
  83314. + (&dev_if->dma_in_desc_addr, 1);
  83315. + dev_if->out_desc_addr =
  83316. + dwc_otg_ep_alloc_desc_chain
  83317. + (&dev_if->dma_out_desc_addr, 1);
  83318. + pcd->data_terminated = 0;
  83319. +
  83320. + if (dev_if->setup_desc_addr[0] == 0
  83321. + || dev_if->setup_desc_addr[1] == 0
  83322. + || dev_if->in_desc_addr == 0
  83323. + || dev_if->out_desc_addr == 0) {
  83324. +
  83325. + if (dev_if->out_desc_addr)
  83326. + dwc_otg_ep_free_desc_chain
  83327. + (dev_if->out_desc_addr,
  83328. + dev_if->dma_out_desc_addr, 1);
  83329. + if (dev_if->in_desc_addr)
  83330. + dwc_otg_ep_free_desc_chain
  83331. + (dev_if->in_desc_addr,
  83332. + dev_if->dma_in_desc_addr, 1);
  83333. + if (dev_if->setup_desc_addr[1])
  83334. + dwc_otg_ep_free_desc_chain
  83335. + (dev_if->setup_desc_addr[1],
  83336. + dev_if->dma_setup_desc_addr[1], 1);
  83337. + if (dev_if->setup_desc_addr[0])
  83338. + dwc_otg_ep_free_desc_chain
  83339. + (dev_if->setup_desc_addr[0],
  83340. + dev_if->dma_setup_desc_addr[0], 1);
  83341. +
  83342. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  83343. + pcd->setup_pkt,
  83344. + pcd->setup_pkt_dma_handle);
  83345. + DWC_DMA_FREE(sizeof(*pcd->status_buf),
  83346. + pcd->status_buf,
  83347. + pcd->status_buf_dma_handle);
  83348. +
  83349. + DWC_FREE(pcd);
  83350. +
  83351. + return NULL;
  83352. + }
  83353. + }
  83354. + } else {
  83355. + pcd->setup_pkt = DWC_ALLOC(sizeof(*pcd->setup_pkt) * 5);
  83356. + if (pcd->setup_pkt == NULL) {
  83357. + DWC_FREE(pcd);
  83358. + return NULL;
  83359. + }
  83360. +
  83361. + pcd->status_buf = DWC_ALLOC(sizeof(uint16_t));
  83362. + if (pcd->status_buf == NULL) {
  83363. + DWC_FREE(pcd->setup_pkt);
  83364. + DWC_FREE(pcd);
  83365. + return NULL;
  83366. + }
  83367. + }
  83368. +
  83369. + dwc_otg_pcd_reinit(pcd);
  83370. +
  83371. + /* Allocate the cfi object for the PCD */
  83372. +#ifdef DWC_UTE_CFI
  83373. + pcd->cfi = DWC_ALLOC(sizeof(cfiobject_t));
  83374. + if (NULL == pcd->cfi)
  83375. + goto fail;
  83376. + if (init_cfi(pcd->cfi)) {
  83377. + CFI_INFO("%s: Failed to init the CFI object\n", __func__);
  83378. + goto fail;
  83379. + }
  83380. +#endif
  83381. +
  83382. + /* Initialize tasklets */
  83383. + pcd->start_xfer_tasklet = DWC_TASK_ALLOC("xfer_tasklet",
  83384. + start_xfer_tasklet_func, pcd);
  83385. + pcd->test_mode_tasklet = DWC_TASK_ALLOC("test_mode_tasklet",
  83386. + do_test_mode, pcd);
  83387. +
  83388. + /* Initialize SRP timer */
  83389. + core_if->srp_timer = DWC_TIMER_ALLOC("SRP TIMER", srp_timeout, core_if);
  83390. +
  83391. + if (core_if->core_params->dev_out_nak) {
  83392. + /**
  83393. + * Initialize xfer timeout timer. Implemented for
  83394. + * 2.93a feature "Device DDMA OUT NAK Enhancement"
  83395. + */
  83396. + for(i = 0; i < MAX_EPS_CHANNELS; i++) {
  83397. + pcd->core_if->ep_xfer_timer[i] =
  83398. + DWC_TIMER_ALLOC("ep timer", ep_xfer_timeout,
  83399. + &pcd->core_if->ep_xfer_info[i]);
  83400. + }
  83401. + }
  83402. +
  83403. + return pcd;
  83404. +#ifdef DWC_UTE_CFI
  83405. +fail:
  83406. +#endif
  83407. + if (pcd->setup_pkt)
  83408. + DWC_FREE(pcd->setup_pkt);
  83409. + if (pcd->status_buf)
  83410. + DWC_FREE(pcd->status_buf);
  83411. +#ifdef DWC_UTE_CFI
  83412. + if (pcd->cfi)
  83413. + DWC_FREE(pcd->cfi);
  83414. +#endif
  83415. + if (pcd)
  83416. + DWC_FREE(pcd);
  83417. + return NULL;
  83418. +
  83419. +}
  83420. +
  83421. +/**
  83422. + * Remove PCD specific data
  83423. + */
  83424. +void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd)
  83425. +{
  83426. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  83427. + int i;
  83428. + if (pcd->core_if->core_params->dev_out_nak) {
  83429. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  83430. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[i]);
  83431. + pcd->core_if->ep_xfer_info[i].state = 0;
  83432. + }
  83433. + }
  83434. +
  83435. + if (GET_CORE_IF(pcd)->dma_enable) {
  83436. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5, pcd->setup_pkt,
  83437. + pcd->setup_pkt_dma_handle);
  83438. + DWC_DMA_FREE(sizeof(uint16_t), pcd->status_buf,
  83439. + pcd->status_buf_dma_handle);
  83440. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  83441. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0],
  83442. + dev_if->dma_setup_desc_addr
  83443. + [0], 1);
  83444. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1],
  83445. + dev_if->dma_setup_desc_addr
  83446. + [1], 1);
  83447. + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr,
  83448. + dev_if->dma_in_desc_addr, 1);
  83449. + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr,
  83450. + dev_if->dma_out_desc_addr,
  83451. + 1);
  83452. + }
  83453. + } else {
  83454. + DWC_FREE(pcd->setup_pkt);
  83455. + DWC_FREE(pcd->status_buf);
  83456. + }
  83457. + DWC_SPINLOCK_FREE(pcd->lock);
  83458. + /* Set core_if's lock pointer to NULL */
  83459. + pcd->core_if->lock = NULL;
  83460. +
  83461. + DWC_TASK_FREE(pcd->start_xfer_tasklet);
  83462. + DWC_TASK_FREE(pcd->test_mode_tasklet);
  83463. + if (pcd->core_if->core_params->dev_out_nak) {
  83464. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  83465. + if (pcd->core_if->ep_xfer_timer[i]) {
  83466. + DWC_TIMER_FREE(pcd->core_if->ep_xfer_timer[i]);
  83467. + }
  83468. + }
  83469. + }
  83470. +
  83471. +/* Release the CFI object's dynamic memory */
  83472. +#ifdef DWC_UTE_CFI
  83473. + if (pcd->cfi->ops.release) {
  83474. + pcd->cfi->ops.release(pcd->cfi);
  83475. + }
  83476. +#endif
  83477. +
  83478. + DWC_FREE(pcd);
  83479. +}
  83480. +
  83481. +/**
  83482. + * Returns whether registered pcd is dual speed or not
  83483. + */
  83484. +uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd)
  83485. +{
  83486. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83487. +
  83488. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) ||
  83489. + ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  83490. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  83491. + (core_if->core_params->ulpi_fs_ls))) {
  83492. + return 0;
  83493. + }
  83494. +
  83495. + return 1;
  83496. +}
  83497. +
  83498. +/**
  83499. + * Returns whether registered pcd is OTG capable or not
  83500. + */
  83501. +uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd)
  83502. +{
  83503. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83504. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  83505. +
  83506. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  83507. + if (!usbcfg.b.srpcap || !usbcfg.b.hnpcap) {
  83508. + return 0;
  83509. + }
  83510. +
  83511. + return 1;
  83512. +}
  83513. +
  83514. +/**
  83515. + * This function assigns periodic Tx FIFO to an periodic EP
  83516. + * in shared Tx FIFO mode
  83517. + */
  83518. +static uint32_t assign_tx_fifo(dwc_otg_core_if_t * core_if)
  83519. +{
  83520. + uint32_t TxMsk = 1;
  83521. + int i;
  83522. +
  83523. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i) {
  83524. + if ((TxMsk & core_if->tx_msk) == 0) {
  83525. + core_if->tx_msk |= TxMsk;
  83526. + return i + 1;
  83527. + }
  83528. + TxMsk <<= 1;
  83529. + }
  83530. + return 0;
  83531. +}
  83532. +
  83533. +/**
  83534. + * This function assigns periodic Tx FIFO to an periodic EP
  83535. + * in shared Tx FIFO mode
  83536. + */
  83537. +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t * core_if)
  83538. +{
  83539. + uint32_t PerTxMsk = 1;
  83540. + int i;
  83541. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i) {
  83542. + if ((PerTxMsk & core_if->p_tx_msk) == 0) {
  83543. + core_if->p_tx_msk |= PerTxMsk;
  83544. + return i + 1;
  83545. + }
  83546. + PerTxMsk <<= 1;
  83547. + }
  83548. + return 0;
  83549. +}
  83550. +
  83551. +/**
  83552. + * This function releases periodic Tx FIFO
  83553. + * in shared Tx FIFO mode
  83554. + */
  83555. +static void release_perio_tx_fifo(dwc_otg_core_if_t * core_if,
  83556. + uint32_t fifo_num)
  83557. +{
  83558. + core_if->p_tx_msk =
  83559. + (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
  83560. +}
  83561. +
  83562. +/**
  83563. + * This function releases periodic Tx FIFO
  83564. + * in shared Tx FIFO mode
  83565. + */
  83566. +static void release_tx_fifo(dwc_otg_core_if_t * core_if, uint32_t fifo_num)
  83567. +{
  83568. + core_if->tx_msk =
  83569. + (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
  83570. +}
  83571. +
  83572. +/**
  83573. + * This function is being called from gadget
  83574. + * to enable PCD endpoint.
  83575. + */
  83576. +int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  83577. + const uint8_t * ep_desc, void *usb_ep)
  83578. +{
  83579. + int num, dir;
  83580. + dwc_otg_pcd_ep_t *ep = NULL;
  83581. + const usb_endpoint_descriptor_t *desc;
  83582. + dwc_irqflags_t flags;
  83583. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  83584. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  83585. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  83586. + int retval = 0;
  83587. + int i, epcount;
  83588. +
  83589. + desc = (const usb_endpoint_descriptor_t *)ep_desc;
  83590. +
  83591. + if (!desc) {
  83592. + pcd->ep0.priv = usb_ep;
  83593. + ep = &pcd->ep0;
  83594. + retval = -DWC_E_INVALID;
  83595. + goto out;
  83596. + }
  83597. +
  83598. + num = UE_GET_ADDR(desc->bEndpointAddress);
  83599. + dir = UE_GET_DIR(desc->bEndpointAddress);
  83600. +
  83601. + if (!desc->wMaxPacketSize) {
  83602. + DWC_WARN("bad maxpacketsize\n");
  83603. + retval = -DWC_E_INVALID;
  83604. + goto out;
  83605. + }
  83606. +
  83607. + if (dir == UE_DIR_IN) {
  83608. + epcount = pcd->core_if->dev_if->num_in_eps;
  83609. + for (i = 0; i < epcount; i++) {
  83610. + if (num == pcd->in_ep[i].dwc_ep.num) {
  83611. + ep = &pcd->in_ep[i];
  83612. + break;
  83613. + }
  83614. + }
  83615. + } else {
  83616. + epcount = pcd->core_if->dev_if->num_out_eps;
  83617. + for (i = 0; i < epcount; i++) {
  83618. + if (num == pcd->out_ep[i].dwc_ep.num) {
  83619. + ep = &pcd->out_ep[i];
  83620. + break;
  83621. + }
  83622. + }
  83623. + }
  83624. +
  83625. + if (!ep) {
  83626. + DWC_WARN("bad address\n");
  83627. + retval = -DWC_E_INVALID;
  83628. + goto out;
  83629. + }
  83630. +
  83631. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83632. +
  83633. + ep->desc = desc;
  83634. + ep->priv = usb_ep;
  83635. +
  83636. + /*
  83637. + * Activate the EP
  83638. + */
  83639. + ep->stopped = 0;
  83640. +
  83641. + ep->dwc_ep.is_in = (dir == UE_DIR_IN);
  83642. + ep->dwc_ep.maxpacket = UGETW(desc->wMaxPacketSize);
  83643. +
  83644. + ep->dwc_ep.type = desc->bmAttributes & UE_XFERTYPE;
  83645. +
  83646. + if (ep->dwc_ep.is_in) {
  83647. + if (!GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  83648. + ep->dwc_ep.tx_fifo_num = 0;
  83649. +
  83650. + if (ep->dwc_ep.type == UE_ISOCHRONOUS) {
  83651. + /*
  83652. + * if ISOC EP then assign a Periodic Tx FIFO.
  83653. + */
  83654. + ep->dwc_ep.tx_fifo_num =
  83655. + assign_perio_tx_fifo(GET_CORE_IF(pcd));
  83656. + }
  83657. + } else {
  83658. + /*
  83659. + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
  83660. + */
  83661. + ep->dwc_ep.tx_fifo_num =
  83662. + assign_tx_fifo(GET_CORE_IF(pcd));
  83663. + }
  83664. +
  83665. + /* Calculating EP info controller base address */
  83666. + if (ep->dwc_ep.tx_fifo_num
  83667. + && GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  83668. + gdfifocfg.d32 =
  83669. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  83670. + core_global_regs->gdfifocfg);
  83671. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  83672. + dptxfsiz.d32 =
  83673. + (DWC_READ_REG32
  83674. + (&GET_CORE_IF(pcd)->core_global_regs->
  83675. + dtxfsiz[ep->dwc_ep.tx_fifo_num - 1]) >> 16);
  83676. + gdfifocfg.b.epinfobase =
  83677. + gdfifocfgbase.d32 + dptxfsiz.d32;
  83678. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  83679. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  83680. + core_global_regs->gdfifocfg,
  83681. + gdfifocfg.d32);
  83682. + }
  83683. + }
  83684. + }
  83685. + /* Set initial data PID. */
  83686. + if (ep->dwc_ep.type == UE_BULK) {
  83687. + ep->dwc_ep.data_pid_start = 0;
  83688. + }
  83689. +
  83690. + /* Alloc DMA Descriptors */
  83691. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  83692. +#ifndef DWC_UTE_PER_IO
  83693. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  83694. +#endif
  83695. + ep->dwc_ep.desc_addr =
  83696. + dwc_otg_ep_alloc_desc_chain(&ep->
  83697. + dwc_ep.dma_desc_addr,
  83698. + MAX_DMA_DESC_CNT);
  83699. + if (!ep->dwc_ep.desc_addr) {
  83700. + DWC_WARN("%s, can't allocate DMA descriptor\n",
  83701. + __func__);
  83702. + retval = -DWC_E_SHUTDOWN;
  83703. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83704. + goto out;
  83705. + }
  83706. +#ifndef DWC_UTE_PER_IO
  83707. + }
  83708. +#endif
  83709. + }
  83710. +
  83711. + DWC_DEBUGPL(DBG_PCD, "Activate %s: type=%d, mps=%d desc=%p\n",
  83712. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  83713. + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
  83714. +#ifdef DWC_UTE_PER_IO
  83715. + ep->dwc_ep.xiso_bInterval = 1 << (ep->desc->bInterval - 1);
  83716. +#endif
  83717. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  83718. + ep->dwc_ep.bInterval = 1 << (ep->desc->bInterval - 1);
  83719. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  83720. + }
  83721. +
  83722. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  83723. +
  83724. +#ifdef DWC_UTE_CFI
  83725. + if (pcd->cfi->ops.ep_enable) {
  83726. + pcd->cfi->ops.ep_enable(pcd->cfi, pcd, ep);
  83727. + }
  83728. +#endif
  83729. +
  83730. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83731. +
  83732. +out:
  83733. + return retval;
  83734. +}
  83735. +
  83736. +/**
  83737. + * This function is being called from gadget
  83738. + * to disable PCD endpoint.
  83739. + */
  83740. +int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle)
  83741. +{
  83742. + dwc_otg_pcd_ep_t *ep;
  83743. + dwc_irqflags_t flags;
  83744. + dwc_otg_dev_dma_desc_t *desc_addr;
  83745. + dwc_dma_t dma_desc_addr;
  83746. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  83747. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  83748. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  83749. +
  83750. + ep = get_ep_from_handle(pcd, ep_handle);
  83751. +
  83752. + if (!ep || !ep->desc) {
  83753. + DWC_DEBUGPL(DBG_PCD, "bad ep address\n");
  83754. + return -DWC_E_INVALID;
  83755. + }
  83756. +
  83757. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83758. +
  83759. + dwc_otg_request_nuke(ep);
  83760. +
  83761. + dwc_otg_ep_deactivate(GET_CORE_IF(pcd), &ep->dwc_ep);
  83762. + if (pcd->core_if->core_params->dev_out_nak) {
  83763. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[ep->dwc_ep.num]);
  83764. + pcd->core_if->ep_xfer_info[ep->dwc_ep.num].state = 0;
  83765. + }
  83766. + ep->desc = NULL;
  83767. + ep->stopped = 1;
  83768. +
  83769. + gdfifocfg.d32 =
  83770. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg);
  83771. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  83772. +
  83773. + if (ep->dwc_ep.is_in) {
  83774. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  83775. + /* Flush the Tx FIFO */
  83776. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd),
  83777. + ep->dwc_ep.tx_fifo_num);
  83778. + }
  83779. + release_perio_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  83780. + release_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  83781. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  83782. + /* Decreasing EPinfo Base Addr */
  83783. + dptxfsiz.d32 =
  83784. + (DWC_READ_REG32
  83785. + (&GET_CORE_IF(pcd)->
  83786. + core_global_regs->dtxfsiz[ep->dwc_ep.tx_fifo_num-1]) >> 16);
  83787. + gdfifocfg.b.epinfobase = gdfifocfgbase.d32 - dptxfsiz.d32;
  83788. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  83789. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg,
  83790. + gdfifocfg.d32);
  83791. + }
  83792. + }
  83793. + }
  83794. +
  83795. + /* Free DMA Descriptors */
  83796. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  83797. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  83798. + desc_addr = ep->dwc_ep.desc_addr;
  83799. + dma_desc_addr = ep->dwc_ep.dma_desc_addr;
  83800. +
  83801. + /* Cannot call dma_free_coherent() with IRQs disabled */
  83802. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83803. + dwc_otg_ep_free_desc_chain(desc_addr, dma_desc_addr,
  83804. + MAX_DMA_DESC_CNT);
  83805. +
  83806. + goto out_unlocked;
  83807. + }
  83808. + }
  83809. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83810. +
  83811. +out_unlocked:
  83812. + DWC_DEBUGPL(DBG_PCD, "%d %s disabled\n", ep->dwc_ep.num,
  83813. + ep->dwc_ep.is_in ? "IN" : "OUT");
  83814. + return 0;
  83815. +
  83816. +}
  83817. +
  83818. +/******************************************************************************/
  83819. +#ifdef DWC_UTE_PER_IO
  83820. +
  83821. +/**
  83822. + * Free the request and its extended parts
  83823. + *
  83824. + */
  83825. +void dwc_pcd_xiso_ereq_free(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req)
  83826. +{
  83827. + DWC_FREE(req->ext_req.per_io_frame_descs);
  83828. + DWC_FREE(req);
  83829. +}
  83830. +
  83831. +/**
  83832. + * Start the next request in the endpoint's queue.
  83833. + *
  83834. + */
  83835. +int dwc_otg_pcd_xiso_start_next_request(dwc_otg_pcd_t * pcd,
  83836. + dwc_otg_pcd_ep_t * ep)
  83837. +{
  83838. + int i;
  83839. + dwc_otg_pcd_request_t *req = NULL;
  83840. + dwc_ep_t *dwcep = NULL;
  83841. + struct dwc_iso_xreq_port *ereq = NULL;
  83842. + struct dwc_iso_pkt_desc_port *ddesc_iso;
  83843. + uint16_t nat;
  83844. + depctl_data_t diepctl;
  83845. +
  83846. + dwcep = &ep->dwc_ep;
  83847. +
  83848. + if (dwcep->xiso_active_xfers > 0) {
  83849. +#if 0 //Disable this to decrease s/w overhead that is crucial for Isoc transfers
  83850. + DWC_WARN("There are currently active transfers for EP%d \
  83851. + (active=%d; queued=%d)", dwcep->num, dwcep->xiso_active_xfers,
  83852. + dwcep->xiso_queued_xfers);
  83853. +#endif
  83854. + return 0;
  83855. + }
  83856. +
  83857. + nat = UGETW(ep->desc->wMaxPacketSize);
  83858. + nat = (nat >> 11) & 0x03;
  83859. +
  83860. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83861. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  83862. + ereq = &req->ext_req;
  83863. + ep->stopped = 0;
  83864. +
  83865. + /* Get the frame number */
  83866. + dwcep->xiso_frame_num =
  83867. + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  83868. + DWC_DEBUG("FRM_NUM=%d", dwcep->xiso_frame_num);
  83869. +
  83870. + ddesc_iso = ereq->per_io_frame_descs;
  83871. +
  83872. + if (dwcep->is_in) {
  83873. + /* Setup DMA Descriptor chain for IN Isoc request */
  83874. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  83875. + //if ((i % (nat + 1)) == 0)
  83876. + if ( i > 0 )
  83877. + dwcep->xiso_frame_num =
  83878. + (dwcep->xiso_bInterval +
  83879. + dwcep->xiso_frame_num) & 0x3FFF;
  83880. + dwcep->desc_addr[i].buf =
  83881. + req->dma + ddesc_iso[i].offset;
  83882. + dwcep->desc_addr[i].status.b_iso_in.txbytes =
  83883. + ddesc_iso[i].length;
  83884. + dwcep->desc_addr[i].status.b_iso_in.framenum =
  83885. + dwcep->xiso_frame_num;
  83886. + dwcep->desc_addr[i].status.b_iso_in.bs =
  83887. + BS_HOST_READY;
  83888. + dwcep->desc_addr[i].status.b_iso_in.txsts = 0;
  83889. + dwcep->desc_addr[i].status.b_iso_in.sp =
  83890. + (ddesc_iso[i].length %
  83891. + dwcep->maxpacket) ? 1 : 0;
  83892. + dwcep->desc_addr[i].status.b_iso_in.ioc = 0;
  83893. + dwcep->desc_addr[i].status.b_iso_in.pid = nat + 1;
  83894. + dwcep->desc_addr[i].status.b_iso_in.l = 0;
  83895. +
  83896. + /* Process the last descriptor */
  83897. + if (i == ereq->pio_pkt_count - 1) {
  83898. + dwcep->desc_addr[i].status.b_iso_in.ioc = 1;
  83899. + dwcep->desc_addr[i].status.b_iso_in.l = 1;
  83900. + }
  83901. + }
  83902. +
  83903. + /* Setup and start the transfer for this endpoint */
  83904. + dwcep->xiso_active_xfers++;
  83905. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->dev_if->
  83906. + in_ep_regs[dwcep->num]->diepdma,
  83907. + dwcep->dma_desc_addr);
  83908. + diepctl.d32 = 0;
  83909. + diepctl.b.epena = 1;
  83910. + diepctl.b.cnak = 1;
  83911. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->dev_if->
  83912. + in_ep_regs[dwcep->num]->diepctl, 0,
  83913. + diepctl.d32);
  83914. + } else {
  83915. + /* Setup DMA Descriptor chain for OUT Isoc request */
  83916. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  83917. + //if ((i % (nat + 1)) == 0)
  83918. + dwcep->xiso_frame_num = (dwcep->xiso_bInterval +
  83919. + dwcep->xiso_frame_num) & 0x3FFF;
  83920. + dwcep->desc_addr[i].buf =
  83921. + req->dma + ddesc_iso[i].offset;
  83922. + dwcep->desc_addr[i].status.b_iso_out.rxbytes =
  83923. + ddesc_iso[i].length;
  83924. + dwcep->desc_addr[i].status.b_iso_out.framenum =
  83925. + dwcep->xiso_frame_num;
  83926. + dwcep->desc_addr[i].status.b_iso_out.bs =
  83927. + BS_HOST_READY;
  83928. + dwcep->desc_addr[i].status.b_iso_out.rxsts = 0;
  83929. + dwcep->desc_addr[i].status.b_iso_out.sp =
  83930. + (ddesc_iso[i].length %
  83931. + dwcep->maxpacket) ? 1 : 0;
  83932. + dwcep->desc_addr[i].status.b_iso_out.ioc = 0;
  83933. + dwcep->desc_addr[i].status.b_iso_out.pid = nat + 1;
  83934. + dwcep->desc_addr[i].status.b_iso_out.l = 0;
  83935. +
  83936. + /* Process the last descriptor */
  83937. + if (i == ereq->pio_pkt_count - 1) {
  83938. + dwcep->desc_addr[i].status.b_iso_out.ioc = 1;
  83939. + dwcep->desc_addr[i].status.b_iso_out.l = 1;
  83940. + }
  83941. + }
  83942. +
  83943. + /* Setup and start the transfer for this endpoint */
  83944. + dwcep->xiso_active_xfers++;
  83945. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  83946. + dev_if->out_ep_regs[dwcep->num]->
  83947. + doepdma, dwcep->dma_desc_addr);
  83948. + diepctl.d32 = 0;
  83949. + diepctl.b.epena = 1;
  83950. + diepctl.b.cnak = 1;
  83951. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  83952. + dev_if->out_ep_regs[dwcep->num]->
  83953. + doepctl, 0, diepctl.d32);
  83954. + }
  83955. +
  83956. + } else {
  83957. + ep->stopped = 1;
  83958. + }
  83959. +
  83960. + return 0;
  83961. +}
  83962. +
  83963. +/**
  83964. + * - Remove the request from the queue
  83965. + */
  83966. +void complete_xiso_ep(dwc_otg_pcd_ep_t * ep)
  83967. +{
  83968. + dwc_otg_pcd_request_t *req = NULL;
  83969. + struct dwc_iso_xreq_port *ereq = NULL;
  83970. + struct dwc_iso_pkt_desc_port *ddesc_iso = NULL;
  83971. + dwc_ep_t *dwcep = NULL;
  83972. + int i;
  83973. +
  83974. + //DWC_DEBUG();
  83975. + dwcep = &ep->dwc_ep;
  83976. +
  83977. + /* Get the first pending request from the queue */
  83978. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83979. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  83980. + if (!req) {
  83981. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  83982. + return;
  83983. + }
  83984. + dwcep->xiso_active_xfers--;
  83985. + dwcep->xiso_queued_xfers--;
  83986. + /* Remove this request from the queue */
  83987. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  83988. + } else {
  83989. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  83990. + return;
  83991. + }
  83992. +
  83993. + ep->stopped = 1;
  83994. + ereq = &req->ext_req;
  83995. + ddesc_iso = ereq->per_io_frame_descs;
  83996. +
  83997. + if (dwcep->xiso_active_xfers < 0) {
  83998. + DWC_WARN("EP#%d (xiso_active_xfers=%d)", dwcep->num,
  83999. + dwcep->xiso_active_xfers);
  84000. + }
  84001. +
  84002. + /* Fill the Isoc descs of portable extended req from dma descriptors */
  84003. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  84004. + if (dwcep->is_in) { /* IN endpoints */
  84005. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  84006. + dwcep->desc_addr[i].status.b_iso_in.txbytes;
  84007. + ddesc_iso[i].status =
  84008. + dwcep->desc_addr[i].status.b_iso_in.txsts;
  84009. + } else { /* OUT endpoints */
  84010. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  84011. + dwcep->desc_addr[i].status.b_iso_out.rxbytes;
  84012. + ddesc_iso[i].status =
  84013. + dwcep->desc_addr[i].status.b_iso_out.rxsts;
  84014. + }
  84015. + }
  84016. +
  84017. + DWC_SPINUNLOCK(ep->pcd->lock);
  84018. +
  84019. + /* Call the completion function in the non-portable logic */
  84020. + ep->pcd->fops->xisoc_complete(ep->pcd, ep->priv, req->priv, 0,
  84021. + &req->ext_req);
  84022. +
  84023. + DWC_SPINLOCK(ep->pcd->lock);
  84024. +
  84025. + /* Free the request - specific freeing needed for extended request object */
  84026. + dwc_pcd_xiso_ereq_free(ep, req);
  84027. +
  84028. + /* Start the next request */
  84029. + dwc_otg_pcd_xiso_start_next_request(ep->pcd, ep);
  84030. +
  84031. + return;
  84032. +}
  84033. +
  84034. +/**
  84035. + * Create and initialize the Isoc pkt descriptors of the extended request.
  84036. + *
  84037. + */
  84038. +static int dwc_otg_pcd_xiso_create_pkt_descs(dwc_otg_pcd_request_t * req,
  84039. + void *ereq_nonport,
  84040. + int atomic_alloc)
  84041. +{
  84042. + struct dwc_iso_xreq_port *ereq = NULL;
  84043. + struct dwc_iso_xreq_port *req_mapped = NULL;
  84044. + struct dwc_iso_pkt_desc_port *ipds = NULL; /* To be created in this function */
  84045. + uint32_t pkt_count;
  84046. + int i;
  84047. +
  84048. + ereq = &req->ext_req;
  84049. + req_mapped = (struct dwc_iso_xreq_port *)ereq_nonport;
  84050. + pkt_count = req_mapped->pio_pkt_count;
  84051. +
  84052. + /* Create the isoc descs */
  84053. + if (atomic_alloc) {
  84054. + ipds = DWC_ALLOC_ATOMIC(sizeof(*ipds) * pkt_count);
  84055. + } else {
  84056. + ipds = DWC_ALLOC(sizeof(*ipds) * pkt_count);
  84057. + }
  84058. +
  84059. + if (!ipds) {
  84060. + DWC_ERROR("Failed to allocate isoc descriptors");
  84061. + return -DWC_E_NO_MEMORY;
  84062. + }
  84063. +
  84064. + /* Initialize the extended request fields */
  84065. + ereq->per_io_frame_descs = ipds;
  84066. + ereq->error_count = 0;
  84067. + ereq->pio_alloc_pkt_count = pkt_count;
  84068. + ereq->pio_pkt_count = pkt_count;
  84069. + ereq->tr_sub_flags = req_mapped->tr_sub_flags;
  84070. +
  84071. + /* Init the Isoc descriptors */
  84072. + for (i = 0; i < pkt_count; i++) {
  84073. + ipds[i].length = req_mapped->per_io_frame_descs[i].length;
  84074. + ipds[i].offset = req_mapped->per_io_frame_descs[i].offset;
  84075. + ipds[i].status = req_mapped->per_io_frame_descs[i].status; /* 0 */
  84076. + ipds[i].actual_length =
  84077. + req_mapped->per_io_frame_descs[i].actual_length;
  84078. + }
  84079. +
  84080. + return 0;
  84081. +}
  84082. +
  84083. +static void prn_ext_request(struct dwc_iso_xreq_port *ereq)
  84084. +{
  84085. + struct dwc_iso_pkt_desc_port *xfd = NULL;
  84086. + int i;
  84087. +
  84088. + DWC_DEBUG("per_io_frame_descs=%p", ereq->per_io_frame_descs);
  84089. + DWC_DEBUG("tr_sub_flags=%d", ereq->tr_sub_flags);
  84090. + DWC_DEBUG("error_count=%d", ereq->error_count);
  84091. + DWC_DEBUG("pio_alloc_pkt_count=%d", ereq->pio_alloc_pkt_count);
  84092. + DWC_DEBUG("pio_pkt_count=%d", ereq->pio_pkt_count);
  84093. + DWC_DEBUG("res=%d", ereq->res);
  84094. +
  84095. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  84096. + xfd = &ereq->per_io_frame_descs[0];
  84097. + DWC_DEBUG("FD #%d", i);
  84098. +
  84099. + DWC_DEBUG("xfd->actual_length=%d", xfd->actual_length);
  84100. + DWC_DEBUG("xfd->length=%d", xfd->length);
  84101. + DWC_DEBUG("xfd->offset=%d", xfd->offset);
  84102. + DWC_DEBUG("xfd->status=%d", xfd->status);
  84103. + }
  84104. +}
  84105. +
  84106. +/**
  84107. + *
  84108. + */
  84109. +int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84110. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  84111. + int zero, void *req_handle, int atomic_alloc,
  84112. + void *ereq_nonport)
  84113. +{
  84114. + dwc_otg_pcd_request_t *req = NULL;
  84115. + dwc_otg_pcd_ep_t *ep;
  84116. + dwc_irqflags_t flags;
  84117. + int res;
  84118. +
  84119. + ep = get_ep_from_handle(pcd, ep_handle);
  84120. + if (!ep) {
  84121. + DWC_WARN("bad ep\n");
  84122. + return -DWC_E_INVALID;
  84123. + }
  84124. +
  84125. + /* We support this extension only for DDMA mode */
  84126. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  84127. + if (!GET_CORE_IF(pcd)->dma_desc_enable)
  84128. + return -DWC_E_INVALID;
  84129. +
  84130. + /* Create a dwc_otg_pcd_request_t object */
  84131. + if (atomic_alloc) {
  84132. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  84133. + } else {
  84134. + req = DWC_ALLOC(sizeof(*req));
  84135. + }
  84136. +
  84137. + if (!req) {
  84138. + return -DWC_E_NO_MEMORY;
  84139. + }
  84140. +
  84141. + /* Create the Isoc descs for this request which shall be the exact match
  84142. + * of the structure sent to us from the non-portable logic */
  84143. + res =
  84144. + dwc_otg_pcd_xiso_create_pkt_descs(req, ereq_nonport, atomic_alloc);
  84145. + if (res) {
  84146. + DWC_WARN("Failed to init the Isoc descriptors");
  84147. + DWC_FREE(req);
  84148. + return res;
  84149. + }
  84150. +
  84151. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84152. +
  84153. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  84154. + req->buf = buf;
  84155. + req->dma = dma_buf;
  84156. + req->length = buflen;
  84157. + req->sent_zlp = zero;
  84158. + req->priv = req_handle;
  84159. +
  84160. + //DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84161. + ep->dwc_ep.dma_addr = dma_buf;
  84162. + ep->dwc_ep.start_xfer_buff = buf;
  84163. + ep->dwc_ep.xfer_buff = buf;
  84164. + ep->dwc_ep.xfer_len = 0;
  84165. + ep->dwc_ep.xfer_count = 0;
  84166. + ep->dwc_ep.sent_zlp = 0;
  84167. + ep->dwc_ep.total_len = buflen;
  84168. +
  84169. + /* Add this request to the tail */
  84170. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  84171. + ep->dwc_ep.xiso_queued_xfers++;
  84172. +
  84173. +//DWC_DEBUG("CP_0");
  84174. +//DWC_DEBUG("req->ext_req.tr_sub_flags=%d", req->ext_req.tr_sub_flags);
  84175. +//prn_ext_request((struct dwc_iso_xreq_port *) ereq_nonport);
  84176. +//prn_ext_request(&req->ext_req);
  84177. +
  84178. + //DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84179. +
  84180. + /* If the req->status == ASAP then check if there is any active transfer
  84181. + * for this endpoint. If no active transfers, then get the first entry
  84182. + * from the queue and start that transfer
  84183. + */
  84184. + if (req->ext_req.tr_sub_flags == DWC_EREQ_TF_ASAP) {
  84185. + res = dwc_otg_pcd_xiso_start_next_request(pcd, ep);
  84186. + if (res) {
  84187. + DWC_WARN("Failed to start the next Isoc transfer");
  84188. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84189. + DWC_FREE(req);
  84190. + return res;
  84191. + }
  84192. + }
  84193. +
  84194. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84195. + return 0;
  84196. +}
  84197. +
  84198. +#endif
  84199. +/* END ifdef DWC_UTE_PER_IO ***************************************************/
  84200. +int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84201. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  84202. + int zero, void *req_handle, int atomic_alloc)
  84203. +{
  84204. + dwc_irqflags_t flags;
  84205. + dwc_otg_pcd_request_t *req;
  84206. + dwc_otg_pcd_ep_t *ep;
  84207. + uint32_t max_transfer;
  84208. +
  84209. + ep = get_ep_from_handle(pcd, ep_handle);
  84210. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  84211. + DWC_WARN("bad ep\n");
  84212. + return -DWC_E_INVALID;
  84213. + }
  84214. +
  84215. + if (atomic_alloc) {
  84216. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  84217. + } else {
  84218. + req = DWC_ALLOC(sizeof(*req));
  84219. + }
  84220. +
  84221. + if (!req) {
  84222. + return -DWC_E_NO_MEMORY;
  84223. + }
  84224. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  84225. + if (!GET_CORE_IF(pcd)->core_params->opt) {
  84226. + if (ep->dwc_ep.num != 0) {
  84227. + DWC_ERROR("queue req %p, len %d buf %p\n",
  84228. + req_handle, buflen, buf);
  84229. + }
  84230. + }
  84231. +
  84232. + req->buf = buf;
  84233. + req->dma = dma_buf;
  84234. + req->length = buflen;
  84235. + req->sent_zlp = zero;
  84236. + req->priv = req_handle;
  84237. + req->dw_align_buf = NULL;
  84238. + if ((dma_buf & 0x3) && GET_CORE_IF(pcd)->dma_enable
  84239. + && !GET_CORE_IF(pcd)->dma_desc_enable)
  84240. + req->dw_align_buf = DWC_DMA_ALLOC(buflen,
  84241. + &req->dw_align_buf_dma);
  84242. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84243. +
  84244. + /*
  84245. + * After adding request to the queue for IN ISOC wait for In Token Received
  84246. + * when TX FIFO is empty interrupt and for OUT ISOC wait for OUT Token
  84247. + * Received when EP is disabled interrupt to obtain starting microframe
  84248. + * (odd/even) start transfer
  84249. + */
  84250. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  84251. + if (req != 0) {
  84252. + depctl_data_t depctl = {.d32 =
  84253. + DWC_READ_REG32(&pcd->core_if->dev_if->
  84254. + in_ep_regs[ep->dwc_ep.num]->
  84255. + diepctl) };
  84256. + ++pcd->request_pending;
  84257. +
  84258. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  84259. + if (ep->dwc_ep.is_in) {
  84260. + depctl.b.cnak = 1;
  84261. + DWC_WRITE_REG32(&pcd->core_if->dev_if->
  84262. + in_ep_regs[ep->dwc_ep.num]->
  84263. + diepctl, depctl.d32);
  84264. + }
  84265. +
  84266. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84267. + }
  84268. + return 0;
  84269. + }
  84270. +
  84271. + /*
  84272. + * For EP0 IN without premature status, zlp is required?
  84273. + */
  84274. + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
  84275. + DWC_DEBUGPL(DBG_PCDV, "%d-OUT ZLP\n", ep->dwc_ep.num);
  84276. + //_req->zero = 1;
  84277. + }
  84278. +
  84279. + /* Start the transfer */
  84280. + if (DWC_CIRCLEQ_EMPTY(&ep->queue) && !ep->stopped) {
  84281. + /* EP0 Transfer? */
  84282. + if (ep->dwc_ep.num == 0) {
  84283. + switch (pcd->ep0state) {
  84284. + case EP0_IN_DATA_PHASE:
  84285. + DWC_DEBUGPL(DBG_PCD,
  84286. + "%s ep0: EP0_IN_DATA_PHASE\n",
  84287. + __func__);
  84288. + break;
  84289. +
  84290. + case EP0_OUT_DATA_PHASE:
  84291. + DWC_DEBUGPL(DBG_PCD,
  84292. + "%s ep0: EP0_OUT_DATA_PHASE\n",
  84293. + __func__);
  84294. + if (pcd->request_config) {
  84295. + /* Complete STATUS PHASE */
  84296. + ep->dwc_ep.is_in = 1;
  84297. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  84298. + }
  84299. + break;
  84300. +
  84301. + case EP0_IN_STATUS_PHASE:
  84302. + DWC_DEBUGPL(DBG_PCD,
  84303. + "%s ep0: EP0_IN_STATUS_PHASE\n",
  84304. + __func__);
  84305. + break;
  84306. +
  84307. + default:
  84308. + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
  84309. + pcd->ep0state);
  84310. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84311. + return -DWC_E_SHUTDOWN;
  84312. + }
  84313. +
  84314. + ep->dwc_ep.dma_addr = dma_buf;
  84315. + ep->dwc_ep.start_xfer_buff = buf;
  84316. + ep->dwc_ep.xfer_buff = buf;
  84317. + ep->dwc_ep.xfer_len = buflen;
  84318. + ep->dwc_ep.xfer_count = 0;
  84319. + ep->dwc_ep.sent_zlp = 0;
  84320. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  84321. +
  84322. + if (zero) {
  84323. + if ((ep->dwc_ep.xfer_len %
  84324. + ep->dwc_ep.maxpacket == 0)
  84325. + && (ep->dwc_ep.xfer_len != 0)) {
  84326. + ep->dwc_ep.sent_zlp = 1;
  84327. + }
  84328. +
  84329. + }
  84330. +
  84331. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  84332. + &ep->dwc_ep);
  84333. + } // non-ep0 endpoints
  84334. + else {
  84335. +#ifdef DWC_UTE_CFI
  84336. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  84337. + /* store the request length */
  84338. + ep->dwc_ep.cfi_req_len = buflen;
  84339. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd,
  84340. + ep, req);
  84341. + } else {
  84342. +#endif
  84343. + max_transfer =
  84344. + GET_CORE_IF(ep->pcd)->core_params->
  84345. + max_transfer_size;
  84346. +
  84347. + /* Setup and start the Transfer */
  84348. + if (req->dw_align_buf){
  84349. + if (ep->dwc_ep.is_in)
  84350. + dwc_memcpy(req->dw_align_buf,
  84351. + buf, buflen);
  84352. + ep->dwc_ep.dma_addr =
  84353. + req->dw_align_buf_dma;
  84354. + ep->dwc_ep.start_xfer_buff =
  84355. + req->dw_align_buf;
  84356. + ep->dwc_ep.xfer_buff =
  84357. + req->dw_align_buf;
  84358. + } else {
  84359. + ep->dwc_ep.dma_addr = dma_buf;
  84360. + ep->dwc_ep.start_xfer_buff = buf;
  84361. + ep->dwc_ep.xfer_buff = buf;
  84362. + }
  84363. + ep->dwc_ep.xfer_len = 0;
  84364. + ep->dwc_ep.xfer_count = 0;
  84365. + ep->dwc_ep.sent_zlp = 0;
  84366. + ep->dwc_ep.total_len = buflen;
  84367. +
  84368. + ep->dwc_ep.maxxfer = max_transfer;
  84369. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  84370. + uint32_t out_max_xfer =
  84371. + DDMA_MAX_TRANSFER_SIZE -
  84372. + (DDMA_MAX_TRANSFER_SIZE % 4);
  84373. + if (ep->dwc_ep.is_in) {
  84374. + if (ep->dwc_ep.maxxfer >
  84375. + DDMA_MAX_TRANSFER_SIZE) {
  84376. + ep->dwc_ep.maxxfer =
  84377. + DDMA_MAX_TRANSFER_SIZE;
  84378. + }
  84379. + } else {
  84380. + if (ep->dwc_ep.maxxfer >
  84381. + out_max_xfer) {
  84382. + ep->dwc_ep.maxxfer =
  84383. + out_max_xfer;
  84384. + }
  84385. + }
  84386. + }
  84387. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  84388. + ep->dwc_ep.maxxfer -=
  84389. + (ep->dwc_ep.maxxfer %
  84390. + ep->dwc_ep.maxpacket);
  84391. + }
  84392. +
  84393. + if (zero) {
  84394. + if ((ep->dwc_ep.total_len %
  84395. + ep->dwc_ep.maxpacket == 0)
  84396. + && (ep->dwc_ep.total_len != 0)) {
  84397. + ep->dwc_ep.sent_zlp = 1;
  84398. + }
  84399. + }
  84400. +#ifdef DWC_UTE_CFI
  84401. + }
  84402. +#endif
  84403. + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd),
  84404. + &ep->dwc_ep);
  84405. + }
  84406. + }
  84407. +
  84408. + if (req != 0) {
  84409. + ++pcd->request_pending;
  84410. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  84411. + if (ep->dwc_ep.is_in && ep->stopped
  84412. + && !(GET_CORE_IF(pcd)->dma_enable)) {
  84413. + /** @todo NGS Create a function for this. */
  84414. + diepmsk_data_t diepmsk = {.d32 = 0 };
  84415. + diepmsk.b.intktxfemp = 1;
  84416. + if (GET_CORE_IF(pcd)->multiproc_int_enable) {
  84417. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  84418. + dev_if->dev_global_regs->diepeachintmsk
  84419. + [ep->dwc_ep.num], 0,
  84420. + diepmsk.d32);
  84421. + } else {
  84422. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  84423. + dev_if->dev_global_regs->
  84424. + diepmsk, 0, diepmsk.d32);
  84425. + }
  84426. +
  84427. + }
  84428. + }
  84429. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84430. +
  84431. + return 0;
  84432. +}
  84433. +
  84434. +int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84435. + void *req_handle)
  84436. +{
  84437. + dwc_irqflags_t flags;
  84438. + dwc_otg_pcd_request_t *req;
  84439. + dwc_otg_pcd_ep_t *ep;
  84440. +
  84441. + ep = get_ep_from_handle(pcd, ep_handle);
  84442. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  84443. + DWC_WARN("bad argument\n");
  84444. + return -DWC_E_INVALID;
  84445. + }
  84446. +
  84447. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84448. +
  84449. + /* make sure it's actually queued on this endpoint */
  84450. + DWC_CIRCLEQ_FOREACH(req, &ep->queue, queue_entry) {
  84451. + if (req->priv == (void *)req_handle) {
  84452. + break;
  84453. + }
  84454. + }
  84455. +
  84456. + if (req->priv != (void *)req_handle) {
  84457. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84458. + return -DWC_E_INVALID;
  84459. + }
  84460. +
  84461. + if (!DWC_CIRCLEQ_EMPTY_ENTRY(req, queue_entry)) {
  84462. + dwc_otg_request_done(ep, req, -DWC_E_RESTART);
  84463. + } else {
  84464. + req = NULL;
  84465. + }
  84466. +
  84467. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84468. +
  84469. + return req ? 0 : -DWC_E_SHUTDOWN;
  84470. +
  84471. +}
  84472. +
  84473. +/**
  84474. + * dwc_otg_pcd_ep_wedge - sets the halt feature and ignores clear requests
  84475. + *
  84476. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  84477. + * requests. If the gadget driver clears the halt status, it will
  84478. + * automatically unwedge the endpoint.
  84479. + *
  84480. + * Returns zero on success, else negative DWC error code.
  84481. + */
  84482. +int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle)
  84483. +{
  84484. + dwc_otg_pcd_ep_t *ep;
  84485. + dwc_irqflags_t flags;
  84486. + int retval = 0;
  84487. +
  84488. + ep = get_ep_from_handle(pcd, ep_handle);
  84489. +
  84490. + if ((!ep->desc && ep != &pcd->ep0) ||
  84491. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  84492. + DWC_WARN("%s, bad ep\n", __func__);
  84493. + return -DWC_E_INVALID;
  84494. + }
  84495. +
  84496. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84497. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84498. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  84499. + ep->dwc_ep.is_in ? "IN" : "OUT");
  84500. + retval = -DWC_E_AGAIN;
  84501. + } else {
  84502. + /* This code needs to be reviewed */
  84503. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  84504. + dtxfsts_data_t txstatus;
  84505. + fifosize_data_t txfifosize;
  84506. +
  84507. + txfifosize.d32 =
  84508. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  84509. + core_global_regs->dtxfsiz[ep->dwc_ep.
  84510. + tx_fifo_num]);
  84511. + txstatus.d32 =
  84512. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  84513. + dev_if->in_ep_regs[ep->dwc_ep.num]->
  84514. + dtxfsts);
  84515. +
  84516. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  84517. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  84518. + retval = -DWC_E_AGAIN;
  84519. + } else {
  84520. + if (ep->dwc_ep.num == 0) {
  84521. + pcd->ep0state = EP0_STALL;
  84522. + }
  84523. +
  84524. + ep->stopped = 1;
  84525. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  84526. + &ep->dwc_ep);
  84527. + }
  84528. + } else {
  84529. + if (ep->dwc_ep.num == 0) {
  84530. + pcd->ep0state = EP0_STALL;
  84531. + }
  84532. +
  84533. + ep->stopped = 1;
  84534. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  84535. + }
  84536. + }
  84537. +
  84538. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84539. +
  84540. + return retval;
  84541. +}
  84542. +
  84543. +int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value)
  84544. +{
  84545. + dwc_otg_pcd_ep_t *ep;
  84546. + dwc_irqflags_t flags;
  84547. + int retval = 0;
  84548. +
  84549. + ep = get_ep_from_handle(pcd, ep_handle);
  84550. +
  84551. + if (!ep || (!ep->desc && ep != &pcd->ep0) ||
  84552. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  84553. + DWC_WARN("%s, bad ep\n", __func__);
  84554. + return -DWC_E_INVALID;
  84555. + }
  84556. +
  84557. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84558. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84559. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  84560. + ep->dwc_ep.is_in ? "IN" : "OUT");
  84561. + retval = -DWC_E_AGAIN;
  84562. + } else if (value == 0) {
  84563. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  84564. + } else if (value == 1) {
  84565. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  84566. + dtxfsts_data_t txstatus;
  84567. + fifosize_data_t txfifosize;
  84568. +
  84569. + txfifosize.d32 =
  84570. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->
  84571. + dtxfsiz[ep->dwc_ep.tx_fifo_num]);
  84572. + txstatus.d32 =
  84573. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  84574. + in_ep_regs[ep->dwc_ep.num]->dtxfsts);
  84575. +
  84576. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  84577. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  84578. + retval = -DWC_E_AGAIN;
  84579. + } else {
  84580. + if (ep->dwc_ep.num == 0) {
  84581. + pcd->ep0state = EP0_STALL;
  84582. + }
  84583. +
  84584. + ep->stopped = 1;
  84585. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  84586. + &ep->dwc_ep);
  84587. + }
  84588. + } else {
  84589. + if (ep->dwc_ep.num == 0) {
  84590. + pcd->ep0state = EP0_STALL;
  84591. + }
  84592. +
  84593. + ep->stopped = 1;
  84594. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  84595. + }
  84596. + } else if (value == 2) {
  84597. + ep->dwc_ep.stall_clear_flag = 0;
  84598. + } else if (value == 3) {
  84599. + ep->dwc_ep.stall_clear_flag = 1;
  84600. + }
  84601. +
  84602. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84603. +
  84604. + return retval;
  84605. +}
  84606. +
  84607. +/**
  84608. + * This function initiates remote wakeup of the host from suspend state.
  84609. + */
  84610. +void dwc_otg_pcd_rem_wkup_from_suspend(dwc_otg_pcd_t * pcd, int set)
  84611. +{
  84612. + dctl_data_t dctl = { 0 };
  84613. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84614. + dsts_data_t dsts;
  84615. +
  84616. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  84617. + if (!dsts.b.suspsts) {
  84618. + DWC_WARN("Remote wakeup while is not in suspend state\n");
  84619. + }
  84620. + /* Check if DEVICE_REMOTE_WAKEUP feature enabled */
  84621. + if (pcd->remote_wakeup_enable) {
  84622. + if (set) {
  84623. +
  84624. + if (core_if->adp_enable) {
  84625. + gpwrdn_data_t gpwrdn;
  84626. +
  84627. + dwc_otg_adp_probe_stop(core_if);
  84628. +
  84629. + /* Mask SRP detected interrupt from Power Down Logic */
  84630. + gpwrdn.d32 = 0;
  84631. + gpwrdn.b.srp_det_msk = 1;
  84632. + DWC_MODIFY_REG32(&core_if->
  84633. + core_global_regs->gpwrdn,
  84634. + gpwrdn.d32, 0);
  84635. +
  84636. + /* Disable Power Down Logic */
  84637. + gpwrdn.d32 = 0;
  84638. + gpwrdn.b.pmuactv = 1;
  84639. + DWC_MODIFY_REG32(&core_if->
  84640. + core_global_regs->gpwrdn,
  84641. + gpwrdn.d32, 0);
  84642. +
  84643. + /*
  84644. + * Initialize the Core for Device mode.
  84645. + */
  84646. + core_if->op_state = B_PERIPHERAL;
  84647. + dwc_otg_core_init(core_if);
  84648. + dwc_otg_enable_global_interrupts(core_if);
  84649. + cil_pcd_start(core_if);
  84650. +
  84651. + dwc_otg_initiate_srp(core_if);
  84652. + }
  84653. +
  84654. + dctl.b.rmtwkupsig = 1;
  84655. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  84656. + dctl, 0, dctl.d32);
  84657. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  84658. +
  84659. + dwc_mdelay(2);
  84660. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  84661. + dctl, dctl.d32, 0);
  84662. + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
  84663. + }
  84664. + } else {
  84665. + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
  84666. + }
  84667. +}
  84668. +
  84669. +#ifdef CONFIG_USB_DWC_OTG_LPM
  84670. +/**
  84671. + * This function initiates remote wakeup of the host from L1 sleep state.
  84672. + */
  84673. +void dwc_otg_pcd_rem_wkup_from_sleep(dwc_otg_pcd_t * pcd, int set)
  84674. +{
  84675. + glpmcfg_data_t lpmcfg;
  84676. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84677. +
  84678. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  84679. +
  84680. + /* Check if we are in L1 state */
  84681. + if (!lpmcfg.b.prt_sleep_sts) {
  84682. + DWC_DEBUGPL(DBG_PCD, "Device is not in sleep state\n");
  84683. + return;
  84684. + }
  84685. +
  84686. + /* Check if host allows remote wakeup */
  84687. + if (!lpmcfg.b.rem_wkup_en) {
  84688. + DWC_DEBUGPL(DBG_PCD, "Host does not allow remote wakeup\n");
  84689. + return;
  84690. + }
  84691. +
  84692. + /* Check if Resume OK */
  84693. + if (!lpmcfg.b.sleep_state_resumeok) {
  84694. + DWC_DEBUGPL(DBG_PCD, "Sleep state resume is not OK\n");
  84695. + return;
  84696. + }
  84697. +
  84698. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  84699. + lpmcfg.b.en_utmi_sleep = 0;
  84700. + lpmcfg.b.hird_thres &= (~(1 << 4));
  84701. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  84702. +
  84703. + if (set) {
  84704. + dctl_data_t dctl = {.d32 = 0 };
  84705. + dctl.b.rmtwkupsig = 1;
  84706. + /* Set RmtWkUpSig bit to start remote wakup signaling.
  84707. + * Hardware will automatically clear this bit.
  84708. + */
  84709. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl,
  84710. + 0, dctl.d32);
  84711. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  84712. + }
  84713. +
  84714. +}
  84715. +#endif
  84716. +
  84717. +/**
  84718. + * Performs remote wakeup.
  84719. + */
  84720. +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set)
  84721. +{
  84722. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84723. + dwc_irqflags_t flags;
  84724. + if (dwc_otg_is_device_mode(core_if)) {
  84725. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84726. +#ifdef CONFIG_USB_DWC_OTG_LPM
  84727. + if (core_if->lx_state == DWC_OTG_L1) {
  84728. + dwc_otg_pcd_rem_wkup_from_sleep(pcd, set);
  84729. + } else {
  84730. +#endif
  84731. + dwc_otg_pcd_rem_wkup_from_suspend(pcd, set);
  84732. +#ifdef CONFIG_USB_DWC_OTG_LPM
  84733. + }
  84734. +#endif
  84735. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84736. + }
  84737. + return;
  84738. +}
  84739. +
  84740. +void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs)
  84741. +{
  84742. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84743. + dctl_data_t dctl = { 0 };
  84744. +
  84745. + if (dwc_otg_is_device_mode(core_if)) {
  84746. + dctl.b.sftdiscon = 1;
  84747. + DWC_PRINTF("Soft disconnect for %d useconds\n",no_of_usecs);
  84748. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  84749. + dwc_udelay(no_of_usecs);
  84750. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32,0);
  84751. +
  84752. + } else{
  84753. + DWC_PRINTF("NOT SUPPORTED IN HOST MODE\n");
  84754. + }
  84755. + return;
  84756. +
  84757. +}
  84758. +
  84759. +int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd)
  84760. +{
  84761. + dsts_data_t dsts;
  84762. + gotgctl_data_t gotgctl;
  84763. +
  84764. + /*
  84765. + * This function starts the Protocol if no session is in progress. If
  84766. + * a session is already in progress, but the device is suspended,
  84767. + * remote wakeup signaling is started.
  84768. + */
  84769. +
  84770. + /* Check if valid session */
  84771. + gotgctl.d32 =
  84772. + DWC_READ_REG32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
  84773. + if (gotgctl.b.bsesvld) {
  84774. + /* Check if suspend state */
  84775. + dsts.d32 =
  84776. + DWC_READ_REG32(&
  84777. + (GET_CORE_IF(pcd)->dev_if->
  84778. + dev_global_regs->dsts));
  84779. + if (dsts.b.suspsts) {
  84780. + dwc_otg_pcd_remote_wakeup(pcd, 1);
  84781. + }
  84782. + } else {
  84783. + dwc_otg_pcd_initiate_srp(pcd);
  84784. + }
  84785. +
  84786. + return 0;
  84787. +
  84788. +}
  84789. +
  84790. +/**
  84791. + * Start the SRP timer to detect when the SRP does not complete within
  84792. + * 6 seconds.
  84793. + *
  84794. + * @param pcd the pcd structure.
  84795. + */
  84796. +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd)
  84797. +{
  84798. + dwc_irqflags_t flags;
  84799. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84800. + dwc_otg_initiate_srp(GET_CORE_IF(pcd));
  84801. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84802. +}
  84803. +
  84804. +int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd)
  84805. +{
  84806. + return dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  84807. +}
  84808. +
  84809. +int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd)
  84810. +{
  84811. + return GET_CORE_IF(pcd)->core_params->lpm_enable;
  84812. +}
  84813. +
  84814. +uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd)
  84815. +{
  84816. + return pcd->b_hnp_enable;
  84817. +}
  84818. +
  84819. +uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd)
  84820. +{
  84821. + return pcd->a_hnp_support;
  84822. +}
  84823. +
  84824. +uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd)
  84825. +{
  84826. + return pcd->a_alt_hnp_support;
  84827. +}
  84828. +
  84829. +int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd)
  84830. +{
  84831. + return pcd->remote_wakeup_enable;
  84832. +}
  84833. +
  84834. +#endif /* DWC_HOST_ONLY */
  84835. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_pcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h
  84836. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 1970-01-01 01:00:00.000000000 +0100
  84837. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 2014-04-24 15:35:04.177565820 +0200
  84838. @@ -0,0 +1,266 @@
  84839. +/* ==========================================================================
  84840. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  84841. + * $Revision: #48 $
  84842. + * $Date: 2012/08/10 $
  84843. + * $Change: 2047372 $
  84844. + *
  84845. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  84846. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  84847. + * otherwise expressly agreed to in writing between Synopsys and you.
  84848. + *
  84849. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  84850. + * any End User Software License Agreement or Agreement for Licensed Product
  84851. + * with Synopsys or any supplement thereto. You are permitted to use and
  84852. + * redistribute this Software in source and binary forms, with or without
  84853. + * modification, provided that redistributions of source code must retain this
  84854. + * notice. You may not view, use, disclose, copy or distribute this file or
  84855. + * any information contained herein except pursuant to this license grant from
  84856. + * Synopsys. If you do not agree with this notice, including the disclaimer
  84857. + * below, then you are not authorized to use the Software.
  84858. + *
  84859. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  84860. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  84861. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  84862. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  84863. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  84864. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  84865. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  84866. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  84867. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  84868. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  84869. + * DAMAGE.
  84870. + * ========================================================================== */
  84871. +#ifndef DWC_HOST_ONLY
  84872. +#if !defined(__DWC_PCD_H__)
  84873. +#define __DWC_PCD_H__
  84874. +
  84875. +#include "dwc_otg_os_dep.h"
  84876. +#include "usb.h"
  84877. +#include "dwc_otg_cil.h"
  84878. +#include "dwc_otg_pcd_if.h"
  84879. +struct cfiobject;
  84880. +
  84881. +/**
  84882. + * @file
  84883. + *
  84884. + * This file contains the structures, constants, and interfaces for
  84885. + * the Perpherial Contoller Driver (PCD).
  84886. + *
  84887. + * The Peripheral Controller Driver (PCD) for Linux will implement the
  84888. + * Gadget API, so that the existing Gadget drivers can be used. For
  84889. + * the Mass Storage Function driver the File-backed USB Storage Gadget
  84890. + * (FBS) driver will be used. The FBS driver supports the
  84891. + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  84892. + * transports.
  84893. + *
  84894. + */
  84895. +
  84896. +/** Invalid DMA Address */
  84897. +#define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  84898. +
  84899. +/** Max Transfer size for any EP */
  84900. +#define DDMA_MAX_TRANSFER_SIZE 65535
  84901. +
  84902. +/**
  84903. + * Get the pointer to the core_if from the pcd pointer.
  84904. + */
  84905. +#define GET_CORE_IF( _pcd ) (_pcd->core_if)
  84906. +
  84907. +/**
  84908. + * States of EP0.
  84909. + */
  84910. +typedef enum ep0_state {
  84911. + EP0_DISCONNECT, /* no host */
  84912. + EP0_IDLE,
  84913. + EP0_IN_DATA_PHASE,
  84914. + EP0_OUT_DATA_PHASE,
  84915. + EP0_IN_STATUS_PHASE,
  84916. + EP0_OUT_STATUS_PHASE,
  84917. + EP0_STALL,
  84918. +} ep0state_e;
  84919. +
  84920. +/** Fordward declaration.*/
  84921. +struct dwc_otg_pcd;
  84922. +
  84923. +/** DWC_otg iso request structure.
  84924. + *
  84925. + */
  84926. +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  84927. +
  84928. +#ifdef DWC_UTE_PER_IO
  84929. +
  84930. +/**
  84931. + * This shall be the exact analogy of the same type structure defined in the
  84932. + * usb_gadget.h. Each descriptor contains
  84933. + */
  84934. +struct dwc_iso_pkt_desc_port {
  84935. + uint32_t offset;
  84936. + uint32_t length; /* expected length */
  84937. + uint32_t actual_length;
  84938. + uint32_t status;
  84939. +};
  84940. +
  84941. +struct dwc_iso_xreq_port {
  84942. + /** transfer/submission flag */
  84943. + uint32_t tr_sub_flags;
  84944. + /** Start the request ASAP */
  84945. +#define DWC_EREQ_TF_ASAP 0x00000002
  84946. + /** Just enqueue the request w/o initiating a transfer */
  84947. +#define DWC_EREQ_TF_ENQUEUE 0x00000004
  84948. +
  84949. + /**
  84950. + * count of ISO packets attached to this request - shall
  84951. + * not exceed the pio_alloc_pkt_count
  84952. + */
  84953. + uint32_t pio_pkt_count;
  84954. + /** count of ISO packets allocated for this request */
  84955. + uint32_t pio_alloc_pkt_count;
  84956. + /** number of ISO packet errors */
  84957. + uint32_t error_count;
  84958. + /** reserved for future extension */
  84959. + uint32_t res;
  84960. + /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  84961. + struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  84962. +};
  84963. +#endif
  84964. +/** DWC_otg request structure.
  84965. + * This structure is a list of requests.
  84966. + */
  84967. +typedef struct dwc_otg_pcd_request {
  84968. + void *priv;
  84969. + void *buf;
  84970. + dwc_dma_t dma;
  84971. + uint32_t length;
  84972. + uint32_t actual;
  84973. + unsigned sent_zlp:1;
  84974. + /**
  84975. + * Used instead of original buffer if
  84976. + * it(physical address) is not dword-aligned.
  84977. + **/
  84978. + uint8_t *dw_align_buf;
  84979. + dwc_dma_t dw_align_buf_dma;
  84980. +
  84981. + DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  84982. +#ifdef DWC_UTE_PER_IO
  84983. + struct dwc_iso_xreq_port ext_req;
  84984. + //void *priv_ereq_nport; /* */
  84985. +#endif
  84986. +} dwc_otg_pcd_request_t;
  84987. +
  84988. +DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  84989. +
  84990. +/** PCD EP structure.
  84991. + * This structure describes an EP, there is an array of EPs in the PCD
  84992. + * structure.
  84993. + */
  84994. +typedef struct dwc_otg_pcd_ep {
  84995. + /** USB EP Descriptor */
  84996. + const usb_endpoint_descriptor_t *desc;
  84997. +
  84998. + /** queue of dwc_otg_pcd_requests. */
  84999. + struct req_list queue;
  85000. + unsigned stopped:1;
  85001. + unsigned disabling:1;
  85002. + unsigned dma:1;
  85003. + unsigned queue_sof:1;
  85004. +
  85005. +#ifdef DWC_EN_ISOC
  85006. + /** ISOC req handle passed */
  85007. + void *iso_req_handle;
  85008. +#endif //_EN_ISOC_
  85009. +
  85010. + /** DWC_otg ep data. */
  85011. + dwc_ep_t dwc_ep;
  85012. +
  85013. + /** Pointer to PCD */
  85014. + struct dwc_otg_pcd *pcd;
  85015. +
  85016. + void *priv;
  85017. +} dwc_otg_pcd_ep_t;
  85018. +
  85019. +/** DWC_otg PCD Structure.
  85020. + * This structure encapsulates the data for the dwc_otg PCD.
  85021. + */
  85022. +struct dwc_otg_pcd {
  85023. + const struct dwc_otg_pcd_function_ops *fops;
  85024. + /** The DWC otg device pointer */
  85025. + struct dwc_otg_device *otg_dev;
  85026. + /** Core Interface */
  85027. + dwc_otg_core_if_t *core_if;
  85028. + /** State of EP0 */
  85029. + ep0state_e ep0state;
  85030. + /** EP0 Request is pending */
  85031. + unsigned ep0_pending:1;
  85032. + /** Indicates when SET CONFIGURATION Request is in process */
  85033. + unsigned request_config:1;
  85034. + /** The state of the Remote Wakeup Enable. */
  85035. + unsigned remote_wakeup_enable:1;
  85036. + /** The state of the B-Device HNP Enable. */
  85037. + unsigned b_hnp_enable:1;
  85038. + /** The state of A-Device HNP Support. */
  85039. + unsigned a_hnp_support:1;
  85040. + /** The state of the A-Device Alt HNP support. */
  85041. + unsigned a_alt_hnp_support:1;
  85042. + /** Count of pending Requests */
  85043. + unsigned request_pending;
  85044. +
  85045. + /** SETUP packet for EP0
  85046. + * This structure is allocated as a DMA buffer on PCD initialization
  85047. + * with enough space for up to 3 setup packets.
  85048. + */
  85049. + union {
  85050. + usb_device_request_t req;
  85051. + uint32_t d32[2];
  85052. + } *setup_pkt;
  85053. +
  85054. + dwc_dma_t setup_pkt_dma_handle;
  85055. +
  85056. + /* Additional buffer and flag for CTRL_WR premature case */
  85057. + uint8_t *backup_buf;
  85058. + unsigned data_terminated;
  85059. +
  85060. + /** 2-byte dma buffer used to return status from GET_STATUS */
  85061. + uint16_t *status_buf;
  85062. + dwc_dma_t status_buf_dma_handle;
  85063. +
  85064. + /** EP0 */
  85065. + dwc_otg_pcd_ep_t ep0;
  85066. +
  85067. + /** Array of IN EPs. */
  85068. + dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  85069. + /** Array of OUT EPs. */
  85070. + dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  85071. + /** number of valid EPs in the above array. */
  85072. +// unsigned num_eps : 4;
  85073. + dwc_spinlock_t *lock;
  85074. +
  85075. + /** Tasklet to defer starting of TEST mode transmissions until
  85076. + * Status Phase has been completed.
  85077. + */
  85078. + dwc_tasklet_t *test_mode_tasklet;
  85079. +
  85080. + /** Tasklet to delay starting of xfer in DMA mode */
  85081. + dwc_tasklet_t *start_xfer_tasklet;
  85082. +
  85083. + /** The test mode to enter when the tasklet is executed. */
  85084. + unsigned test_mode;
  85085. + /** The cfi_api structure that implements most of the CFI API
  85086. + * and OTG specific core configuration functionality
  85087. + */
  85088. +#ifdef DWC_UTE_CFI
  85089. + struct cfiobject *cfi;
  85090. +#endif
  85091. +
  85092. +};
  85093. +
  85094. +//FIXME this functions should be static, and this prototypes should be removed
  85095. +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  85096. +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  85097. + dwc_otg_pcd_request_t * req, int32_t status);
  85098. +
  85099. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  85100. + void *req_handle);
  85101. +
  85102. +extern void do_test_mode(void *data);
  85103. +#endif
  85104. +#endif /* DWC_HOST_ONLY */
  85105. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h
  85106. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 1970-01-01 01:00:00.000000000 +0100
  85107. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 2014-04-24 15:35:04.177565820 +0200
  85108. @@ -0,0 +1,360 @@
  85109. +/* ==========================================================================
  85110. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  85111. + * $Revision: #11 $
  85112. + * $Date: 2011/10/26 $
  85113. + * $Change: 1873028 $
  85114. + *
  85115. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  85116. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  85117. + * otherwise expressly agreed to in writing between Synopsys and you.
  85118. + *
  85119. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  85120. + * any End User Software License Agreement or Agreement for Licensed Product
  85121. + * with Synopsys or any supplement thereto. You are permitted to use and
  85122. + * redistribute this Software in source and binary forms, with or without
  85123. + * modification, provided that redistributions of source code must retain this
  85124. + * notice. You may not view, use, disclose, copy or distribute this file or
  85125. + * any information contained herein except pursuant to this license grant from
  85126. + * Synopsys. If you do not agree with this notice, including the disclaimer
  85127. + * below, then you are not authorized to use the Software.
  85128. + *
  85129. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  85130. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  85131. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  85132. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  85133. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  85134. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  85135. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  85136. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  85137. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  85138. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  85139. + * DAMAGE.
  85140. + * ========================================================================== */
  85141. +#ifndef DWC_HOST_ONLY
  85142. +
  85143. +#if !defined(__DWC_PCD_IF_H__)
  85144. +#define __DWC_PCD_IF_H__
  85145. +
  85146. +//#include "dwc_os.h"
  85147. +#include "dwc_otg_core_if.h"
  85148. +
  85149. +/** @file
  85150. + * This file defines DWC_OTG PCD Core API.
  85151. + */
  85152. +
  85153. +struct dwc_otg_pcd;
  85154. +typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  85155. +
  85156. +/** Maxpacket size for EP0 */
  85157. +#define MAX_EP0_SIZE 64
  85158. +/** Maxpacket size for any EP */
  85159. +#define MAX_PACKET_SIZE 1024
  85160. +
  85161. +/** @name Function Driver Callbacks */
  85162. +/** @{ */
  85163. +
  85164. +/** This function will be called whenever a previously queued request has
  85165. + * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  85166. + * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  85167. + * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  85168. + * parameters. */
  85169. +typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  85170. + void *req_handle, int32_t status,
  85171. + uint32_t actual);
  85172. +/**
  85173. + * This function will be called whenever a previousle queued ISOC request has
  85174. + * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  85175. + * function.
  85176. + * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  85177. + * functions.
  85178. + */
  85179. +typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  85180. + void *req_handle, int proc_buf_num);
  85181. +/** This function should handle any SETUP request that cannot be handled by the
  85182. + * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  85183. + * class-specific requests, etc. The function must non-blocking.
  85184. + *
  85185. + * Returns 0 on success.
  85186. + * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  85187. + * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  85188. + * Returns -DWC_E_SHUTDOWN on any other error. */
  85189. +typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  85190. +/** This is called whenever the device has been disconnected. The function
  85191. + * driver should take appropriate action to clean up all pending requests in the
  85192. + * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  85193. + * state. */
  85194. +typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  85195. +/** This function is called when device has been connected. */
  85196. +typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  85197. +/** This function is called when device has been suspended */
  85198. +typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  85199. +/** This function is called when device has received LPM tokens, i.e.
  85200. + * device has been sent to sleep state. */
  85201. +typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  85202. +/** This function is called when device has been resumed
  85203. + * from suspend(L2) or L1 sleep state. */
  85204. +typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  85205. +/** This function is called whenever hnp params has been changed.
  85206. + * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  85207. + * to get hnp parameters. */
  85208. +typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  85209. +/** This function is called whenever USB RESET is detected. */
  85210. +typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  85211. +
  85212. +typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  85213. +
  85214. +/**
  85215. + *
  85216. + * @param ep_handle Void pointer to the usb_ep structure
  85217. + * @param ereq_port Pointer to the extended request structure created in the
  85218. + * portable part.
  85219. + */
  85220. +typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  85221. + void *req_handle, int32_t status,
  85222. + void *ereq_port);
  85223. +/** Function Driver Ops Data Structure */
  85224. +struct dwc_otg_pcd_function_ops {
  85225. + dwc_connect_cb_t connect;
  85226. + dwc_disconnect_cb_t disconnect;
  85227. + dwc_setup_cb_t setup;
  85228. + dwc_completion_cb_t complete;
  85229. + dwc_isoc_completion_cb_t isoc_complete;
  85230. + dwc_suspend_cb_t suspend;
  85231. + dwc_sleep_cb_t sleep;
  85232. + dwc_resume_cb_t resume;
  85233. + dwc_reset_cb_t reset;
  85234. + dwc_hnp_params_changed_cb_t hnp_changed;
  85235. + cfi_setup_cb_t cfi_setup;
  85236. +#ifdef DWC_UTE_PER_IO
  85237. + xiso_completion_cb_t xisoc_complete;
  85238. +#endif
  85239. +};
  85240. +/** @} */
  85241. +
  85242. +/** @name Function Driver Functions */
  85243. +/** @{ */
  85244. +
  85245. +/** Call this function to get pointer on dwc_otg_pcd_t,
  85246. + * this pointer will be used for all PCD API functions.
  85247. + *
  85248. + * @param core_if The DWC_OTG Core
  85249. + */
  85250. +extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  85251. +
  85252. +/** Frees PCD allocated by dwc_otg_pcd_init
  85253. + *
  85254. + * @param pcd The PCD
  85255. + */
  85256. +extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  85257. +
  85258. +/** Call this to bind the function driver to the PCD Core.
  85259. + *
  85260. + * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  85261. + * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  85262. + */
  85263. +extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  85264. + const struct dwc_otg_pcd_function_ops *fops);
  85265. +
  85266. +/** Enables an endpoint for use. This function enables an endpoint in
  85267. + * the PCD. The endpoint is described by the ep_desc which has the
  85268. + * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  85269. + * to the endpoint from other API functions and in callbacks. Normally this
  85270. + * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  85271. + * core for that interface.
  85272. + *
  85273. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  85274. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  85275. + * Returns 0 on success.
  85276. + *
  85277. + * @param pcd The PCD
  85278. + * @param ep_desc Endpoint descriptor
  85279. + * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  85280. + */
  85281. +extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  85282. + const uint8_t * ep_desc, void *usb_ep);
  85283. +
  85284. +/** Disable the endpoint referenced by ep_handle.
  85285. + *
  85286. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  85287. + * Returns -DWC_E_SHUTDOWN if any other error occurred.
  85288. + * Returns 0 on success. */
  85289. +extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  85290. +
  85291. +/** Queue a data transfer request on the endpoint referenced by ep_handle.
  85292. + * After the transfer is completes, the complete callback will be called with
  85293. + * the request status.
  85294. + *
  85295. + * @param pcd The PCD
  85296. + * @param ep_handle The handle of the endpoint
  85297. + * @param buf The buffer for the data
  85298. + * @param dma_buf The DMA buffer for the data
  85299. + * @param buflen The length of the data transfer
  85300. + * @param zero Specifies whether to send zero length last packet.
  85301. + * @param req_handle Set this handle to any value to use to reference this
  85302. + * request in the ep_dequeue function or from the complete callback
  85303. + * @param atomic_alloc If driver need to perform atomic allocations
  85304. + * for internal data structures.
  85305. + *
  85306. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  85307. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  85308. + * Returns 0 on success. */
  85309. +extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  85310. + uint8_t * buf, dwc_dma_t dma_buf,
  85311. + uint32_t buflen, int zero, void *req_handle,
  85312. + int atomic_alloc);
  85313. +#ifdef DWC_UTE_PER_IO
  85314. +/**
  85315. + *
  85316. + * @param ereq_nonport Pointer to the extended request part of the
  85317. + * usb_request structure defined in usb_gadget.h file.
  85318. + */
  85319. +extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  85320. + uint8_t * buf, dwc_dma_t dma_buf,
  85321. + uint32_t buflen, int zero,
  85322. + void *req_handle, int atomic_alloc,
  85323. + void *ereq_nonport);
  85324. +
  85325. +#endif
  85326. +
  85327. +/** De-queue the specified data transfer that has not yet completed.
  85328. + *
  85329. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  85330. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  85331. + * Returns 0 on success. */
  85332. +extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  85333. + void *req_handle);
  85334. +
  85335. +/** Halt (STALL) an endpoint or clear it.
  85336. + *
  85337. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  85338. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  85339. + * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  85340. + * Returns 0 on success. */
  85341. +extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  85342. +
  85343. +/** This function */
  85344. +extern int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle);
  85345. +
  85346. +/** This function should be called on every hardware interrupt */
  85347. +extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  85348. +
  85349. +/** This function returns current frame number */
  85350. +extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  85351. +
  85352. +/**
  85353. + * Start isochronous transfers on the endpoint referenced by ep_handle.
  85354. + * For isochronous transfers duble buffering is used.
  85355. + * After processing each of buffers comlete callback will be called with
  85356. + * status for each transaction.
  85357. + *
  85358. + * @param pcd The PCD
  85359. + * @param ep_handle The handle of the endpoint
  85360. + * @param buf0 The virtual address of first data buffer
  85361. + * @param buf1 The virtual address of second data buffer
  85362. + * @param dma0 The DMA address of first data buffer
  85363. + * @param dma1 The DMA address of second data buffer
  85364. + * @param sync_frame Data pattern frame number
  85365. + * @param dp_frame Data size for pattern frame
  85366. + * @param data_per_frame Data size for regular frame
  85367. + * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  85368. + * @param buf_proc_intrvl Interval of ISOC Buffer processing
  85369. + * @param req_handle Handle of ISOC request
  85370. + * @param atomic_alloc Specefies whether to perform atomic allocation for
  85371. + * internal data structures.
  85372. + *
  85373. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  85374. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  85375. + * Returns -DW_E_SHUTDOWN for any other error.
  85376. + * Returns 0 on success
  85377. + */
  85378. +extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  85379. + uint8_t * buf0, uint8_t * buf1,
  85380. + dwc_dma_t dma0, dwc_dma_t dma1,
  85381. + int sync_frame, int dp_frame,
  85382. + int data_per_frame, int start_frame,
  85383. + int buf_proc_intrvl, void *req_handle,
  85384. + int atomic_alloc);
  85385. +
  85386. +/** Stop ISOC transfers on endpoint referenced by ep_handle.
  85387. + *
  85388. + * @param pcd The PCD
  85389. + * @param ep_handle The handle of the endpoint
  85390. + * @param req_handle Handle of ISOC request
  85391. + *
  85392. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  85393. + * Returns 0 on success
  85394. + */
  85395. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  85396. + void *req_handle);
  85397. +
  85398. +/** Get ISOC packet status.
  85399. + *
  85400. + * @param pcd The PCD
  85401. + * @param ep_handle The handle of the endpoint
  85402. + * @param iso_req_handle Isochronoush request handle
  85403. + * @param packet Number of packet
  85404. + * @param status Out parameter for returning status
  85405. + * @param actual Out parameter for returning actual length
  85406. + * @param offset Out parameter for returning offset
  85407. + *
  85408. + */
  85409. +extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  85410. + void *ep_handle,
  85411. + void *iso_req_handle, int packet,
  85412. + int *status, int *actual,
  85413. + int *offset);
  85414. +
  85415. +/** Get ISOC packet count.
  85416. + *
  85417. + * @param pcd The PCD
  85418. + * @param ep_handle The handle of the endpoint
  85419. + * @param iso_req_handle
  85420. + */
  85421. +extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  85422. + void *ep_handle,
  85423. + void *iso_req_handle);
  85424. +
  85425. +/** This function starts the SRP Protocol if no session is in progress. If
  85426. + * a session is already in progress, but the device is suspended,
  85427. + * remote wakeup signaling is started.
  85428. + */
  85429. +extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  85430. +
  85431. +/** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  85432. +extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  85433. +
  85434. +/** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  85435. +extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  85436. +
  85437. +/** Initiate SRP */
  85438. +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  85439. +
  85440. +/** Starts remote wakeup signaling. */
  85441. +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  85442. +
  85443. +/** Starts micorsecond soft disconnect. */
  85444. +extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  85445. +/** This function returns whether device is dualspeed.*/
  85446. +extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  85447. +
  85448. +/** This function returns whether device is otg. */
  85449. +extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  85450. +
  85451. +/** These functions allow to get hnp parameters */
  85452. +extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  85453. +extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  85454. +extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  85455. +
  85456. +/** CFI specific Interface functions */
  85457. +/** Allocate a cfi buffer */
  85458. +extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  85459. + dwc_dma_t * addr, size_t buflen,
  85460. + int flags);
  85461. +
  85462. +/******************************************************************************/
  85463. +
  85464. +/** @} */
  85465. +
  85466. +#endif /* __DWC_PCD_IF_H__ */
  85467. +
  85468. +#endif /* DWC_HOST_ONLY */
  85469. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
  85470. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  85471. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 2014-04-24 16:04:39.823124292 +0200
  85472. @@ -0,0 +1,5147 @@
  85473. +/* ==========================================================================
  85474. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
  85475. + * $Revision: #116 $
  85476. + * $Date: 2012/08/10 $
  85477. + * $Change: 2047372 $
  85478. + *
  85479. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  85480. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  85481. + * otherwise expressly agreed to in writing between Synopsys and you.
  85482. + *
  85483. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  85484. + * any End User Software License Agreement or Agreement for Licensed Product
  85485. + * with Synopsys or any supplement thereto. You are permitted to use and
  85486. + * redistribute this Software in source and binary forms, with or without
  85487. + * modification, provided that redistributions of source code must retain this
  85488. + * notice. You may not view, use, disclose, copy or distribute this file or
  85489. + * any information contained herein except pursuant to this license grant from
  85490. + * Synopsys. If you do not agree with this notice, including the disclaimer
  85491. + * below, then you are not authorized to use the Software.
  85492. + *
  85493. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  85494. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  85495. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  85496. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  85497. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  85498. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  85499. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  85500. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  85501. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  85502. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  85503. + * DAMAGE.
  85504. + * ========================================================================== */
  85505. +#ifndef DWC_HOST_ONLY
  85506. +
  85507. +#include "dwc_otg_pcd.h"
  85508. +
  85509. +#ifdef DWC_UTE_CFI
  85510. +#include "dwc_otg_cfi.h"
  85511. +#endif
  85512. +
  85513. +#ifdef DWC_UTE_PER_IO
  85514. +extern void complete_xiso_ep(dwc_otg_pcd_ep_t * ep);
  85515. +#endif
  85516. +//#define PRINT_CFI_DMA_DESCS
  85517. +
  85518. +#define DEBUG_EP0
  85519. +
  85520. +/**
  85521. + * This function updates OTG.
  85522. + */
  85523. +static void dwc_otg_pcd_update_otg(dwc_otg_pcd_t * pcd, const unsigned reset)
  85524. +{
  85525. +
  85526. + if (reset) {
  85527. + pcd->b_hnp_enable = 0;
  85528. + pcd->a_hnp_support = 0;
  85529. + pcd->a_alt_hnp_support = 0;
  85530. + }
  85531. +
  85532. + if (pcd->fops->hnp_changed) {
  85533. + pcd->fops->hnp_changed(pcd);
  85534. + }
  85535. +}
  85536. +
  85537. +/** @file
  85538. + * This file contains the implementation of the PCD Interrupt handlers.
  85539. + *
  85540. + * The PCD handles the device interrupts. Many conditions can cause a
  85541. + * device interrupt. When an interrupt occurs, the device interrupt
  85542. + * service routine determines the cause of the interrupt and
  85543. + * dispatches handling to the appropriate function. These interrupt
  85544. + * handling functions are described below.
  85545. + * All interrupt registers are processed from LSB to MSB.
  85546. + */
  85547. +
  85548. +/**
  85549. + * This function prints the ep0 state for debug purposes.
  85550. + */
  85551. +static inline void print_ep0_state(dwc_otg_pcd_t * pcd)
  85552. +{
  85553. +#ifdef DEBUG
  85554. + char str[40];
  85555. +
  85556. + switch (pcd->ep0state) {
  85557. + case EP0_DISCONNECT:
  85558. + dwc_strcpy(str, "EP0_DISCONNECT");
  85559. + break;
  85560. + case EP0_IDLE:
  85561. + dwc_strcpy(str, "EP0_IDLE");
  85562. + break;
  85563. + case EP0_IN_DATA_PHASE:
  85564. + dwc_strcpy(str, "EP0_IN_DATA_PHASE");
  85565. + break;
  85566. + case EP0_OUT_DATA_PHASE:
  85567. + dwc_strcpy(str, "EP0_OUT_DATA_PHASE");
  85568. + break;
  85569. + case EP0_IN_STATUS_PHASE:
  85570. + dwc_strcpy(str, "EP0_IN_STATUS_PHASE");
  85571. + break;
  85572. + case EP0_OUT_STATUS_PHASE:
  85573. + dwc_strcpy(str, "EP0_OUT_STATUS_PHASE");
  85574. + break;
  85575. + case EP0_STALL:
  85576. + dwc_strcpy(str, "EP0_STALL");
  85577. + break;
  85578. + default:
  85579. + dwc_strcpy(str, "EP0_INVALID");
  85580. + }
  85581. +
  85582. + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
  85583. +#endif
  85584. +}
  85585. +
  85586. +/**
  85587. + * This function calculate the size of the payload in the memory
  85588. + * for out endpoints and prints size for debug purposes(used in
  85589. + * 2.93a DevOutNak feature).
  85590. + */
  85591. +static inline void print_memory_payload(dwc_otg_pcd_t * pcd, dwc_ep_t * ep)
  85592. +{
  85593. +#ifdef DEBUG
  85594. + deptsiz_data_t deptsiz_init = {.d32 = 0 };
  85595. + deptsiz_data_t deptsiz_updt = {.d32 = 0 };
  85596. + int pack_num;
  85597. + unsigned payload;
  85598. +
  85599. + deptsiz_init.d32 = pcd->core_if->start_doeptsiz_val[ep->num];
  85600. + deptsiz_updt.d32 =
  85601. + DWC_READ_REG32(&pcd->core_if->dev_if->
  85602. + out_ep_regs[ep->num]->doeptsiz);
  85603. + /* Payload will be */
  85604. + payload = deptsiz_init.b.xfersize - deptsiz_updt.b.xfersize;
  85605. + /* Packet count is decremented every time a packet
  85606. + * is written to the RxFIFO not in to the external memory
  85607. + * So, if payload == 0, then it means no packet was sent to ext memory*/
  85608. + pack_num = (!payload) ? 0 : (deptsiz_init.b.pktcnt - deptsiz_updt.b.pktcnt);
  85609. + DWC_DEBUGPL(DBG_PCDV,
  85610. + "Payload for EP%d-%s\n",
  85611. + ep->num, (ep->is_in ? "IN" : "OUT"));
  85612. + DWC_DEBUGPL(DBG_PCDV,
  85613. + "Number of transfered bytes = 0x%08x\n", payload);
  85614. + DWC_DEBUGPL(DBG_PCDV,
  85615. + "Number of transfered packets = %d\n", pack_num);
  85616. +#endif
  85617. +}
  85618. +
  85619. +
  85620. +#ifdef DWC_UTE_CFI
  85621. +static inline void print_desc(struct dwc_otg_dma_desc *ddesc,
  85622. + const uint8_t * epname, int descnum)
  85623. +{
  85624. + CFI_INFO
  85625. + ("%s DMA_DESC(%d) buf=0x%08x bytes=0x%04x; sp=0x%x; l=0x%x; sts=0x%02x; bs=0x%02x\n",
  85626. + epname, descnum, ddesc->buf, ddesc->status.b.bytes,
  85627. + ddesc->status.b.sp, ddesc->status.b.l, ddesc->status.b.sts,
  85628. + ddesc->status.b.bs);
  85629. +}
  85630. +#endif
  85631. +
  85632. +/**
  85633. + * This function returns pointer to in ep struct with number ep_num
  85634. + */
  85635. +static inline dwc_otg_pcd_ep_t *get_in_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  85636. +{
  85637. + int i;
  85638. + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  85639. + if (ep_num == 0) {
  85640. + return &pcd->ep0;
  85641. + } else {
  85642. + for (i = 0; i < num_in_eps; ++i) {
  85643. + if (pcd->in_ep[i].dwc_ep.num == ep_num)
  85644. + return &pcd->in_ep[i];
  85645. + }
  85646. + return 0;
  85647. + }
  85648. +}
  85649. +
  85650. +/**
  85651. + * This function returns pointer to out ep struct with number ep_num
  85652. + */
  85653. +static inline dwc_otg_pcd_ep_t *get_out_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  85654. +{
  85655. + int i;
  85656. + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  85657. + if (ep_num == 0) {
  85658. + return &pcd->ep0;
  85659. + } else {
  85660. + for (i = 0; i < num_out_eps; ++i) {
  85661. + if (pcd->out_ep[i].dwc_ep.num == ep_num)
  85662. + return &pcd->out_ep[i];
  85663. + }
  85664. + return 0;
  85665. + }
  85666. +}
  85667. +
  85668. +/**
  85669. + * This functions gets a pointer to an EP from the wIndex address
  85670. + * value of the control request.
  85671. + */
  85672. +dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex)
  85673. +{
  85674. + dwc_otg_pcd_ep_t *ep;
  85675. + uint32_t ep_num = UE_GET_ADDR(wIndex);
  85676. +
  85677. + if (ep_num == 0) {
  85678. + ep = &pcd->ep0;
  85679. + } else if (UE_GET_DIR(wIndex) == UE_DIR_IN) { /* in ep */
  85680. + ep = &pcd->in_ep[ep_num - 1];
  85681. + } else {
  85682. + ep = &pcd->out_ep[ep_num - 1];
  85683. + }
  85684. +
  85685. + return ep;
  85686. +}
  85687. +
  85688. +/**
  85689. + * This function checks the EP request queue, if the queue is not
  85690. + * empty the next request is started.
  85691. + */
  85692. +void start_next_request(dwc_otg_pcd_ep_t * ep)
  85693. +{
  85694. + dwc_otg_pcd_request_t *req = 0;
  85695. + uint32_t max_transfer =
  85696. + GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
  85697. +
  85698. +#ifdef DWC_UTE_CFI
  85699. + struct dwc_otg_pcd *pcd;
  85700. + pcd = ep->pcd;
  85701. +#endif
  85702. +
  85703. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  85704. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  85705. +
  85706. +#ifdef DWC_UTE_CFI
  85707. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  85708. + ep->dwc_ep.cfi_req_len = req->length;
  85709. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd, ep, req);
  85710. + } else {
  85711. +#endif
  85712. + /* Setup and start the Transfer */
  85713. + if (req->dw_align_buf) {
  85714. + ep->dwc_ep.dma_addr = req->dw_align_buf_dma;
  85715. + ep->dwc_ep.start_xfer_buff = req->dw_align_buf;
  85716. + ep->dwc_ep.xfer_buff = req->dw_align_buf;
  85717. + } else {
  85718. + ep->dwc_ep.dma_addr = req->dma;
  85719. + ep->dwc_ep.start_xfer_buff = req->buf;
  85720. + ep->dwc_ep.xfer_buff = req->buf;
  85721. + }
  85722. + ep->dwc_ep.sent_zlp = 0;
  85723. + ep->dwc_ep.total_len = req->length;
  85724. + ep->dwc_ep.xfer_len = 0;
  85725. + ep->dwc_ep.xfer_count = 0;
  85726. +
  85727. + ep->dwc_ep.maxxfer = max_transfer;
  85728. + if (GET_CORE_IF(ep->pcd)->dma_desc_enable) {
  85729. + uint32_t out_max_xfer = DDMA_MAX_TRANSFER_SIZE
  85730. + - (DDMA_MAX_TRANSFER_SIZE % 4);
  85731. + if (ep->dwc_ep.is_in) {
  85732. + if (ep->dwc_ep.maxxfer >
  85733. + DDMA_MAX_TRANSFER_SIZE) {
  85734. + ep->dwc_ep.maxxfer =
  85735. + DDMA_MAX_TRANSFER_SIZE;
  85736. + }
  85737. + } else {
  85738. + if (ep->dwc_ep.maxxfer > out_max_xfer) {
  85739. + ep->dwc_ep.maxxfer =
  85740. + out_max_xfer;
  85741. + }
  85742. + }
  85743. + }
  85744. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  85745. + ep->dwc_ep.maxxfer -=
  85746. + (ep->dwc_ep.maxxfer % ep->dwc_ep.maxpacket);
  85747. + }
  85748. + if (req->sent_zlp) {
  85749. + if ((ep->dwc_ep.total_len %
  85750. + ep->dwc_ep.maxpacket == 0)
  85751. + && (ep->dwc_ep.total_len != 0)) {
  85752. + ep->dwc_ep.sent_zlp = 1;
  85753. + }
  85754. +
  85755. + }
  85756. +#ifdef DWC_UTE_CFI
  85757. + }
  85758. +#endif
  85759. + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
  85760. + } else if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  85761. + DWC_PRINTF("There are no more ISOC requests \n");
  85762. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  85763. + }
  85764. +}
  85765. +
  85766. +/**
  85767. + * This function handles the SOF Interrupts. At this time the SOF
  85768. + * Interrupt is disabled.
  85769. + */
  85770. +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t * pcd)
  85771. +{
  85772. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85773. +
  85774. + gintsts_data_t gintsts;
  85775. +
  85776. + DWC_DEBUGPL(DBG_PCD, "SOF\n");
  85777. +
  85778. + /* Clear interrupt */
  85779. + gintsts.d32 = 0;
  85780. + gintsts.b.sofintr = 1;
  85781. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  85782. +
  85783. + return 1;
  85784. +}
  85785. +
  85786. +/**
  85787. + * This function handles the Rx Status Queue Level Interrupt, which
  85788. + * indicates that there is a least one packet in the Rx FIFO. The
  85789. + * packets are moved from the FIFO to memory, where they will be
  85790. + * processed when the Endpoint Interrupt Register indicates Transfer
  85791. + * Complete or SETUP Phase Done.
  85792. + *
  85793. + * Repeat the following until the Rx Status Queue is empty:
  85794. + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
  85795. + * info
  85796. + * -# If Receive FIFO is empty then skip to step Clear the interrupt
  85797. + * and exit
  85798. + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
  85799. + * SETUP data to the buffer
  85800. + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
  85801. + * to the destination buffer
  85802. + */
  85803. +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t * pcd)
  85804. +{
  85805. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85806. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  85807. + gintmsk_data_t gintmask = {.d32 = 0 };
  85808. + device_grxsts_data_t status;
  85809. + dwc_otg_pcd_ep_t *ep;
  85810. + gintsts_data_t gintsts;
  85811. +#ifdef DEBUG
  85812. + static char *dpid_str[] = { "D0", "D2", "D1", "MDATA" };
  85813. +#endif
  85814. +
  85815. + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
  85816. + /* Disable the Rx Status Queue Level interrupt */
  85817. + gintmask.b.rxstsqlvl = 1;
  85818. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmask.d32, 0);
  85819. +
  85820. + /* Get the Status from the top of the FIFO */
  85821. + status.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  85822. +
  85823. + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
  85824. + "pktsts:%x Frame:%d(0x%0x)\n",
  85825. + status.b.epnum, status.b.bcnt,
  85826. + dpid_str[status.b.dpid],
  85827. + status.b.pktsts, status.b.fn, status.b.fn);
  85828. + /* Get pointer to EP structure */
  85829. + ep = get_out_ep(pcd, status.b.epnum);
  85830. +
  85831. + switch (status.b.pktsts) {
  85832. + case DWC_DSTS_GOUT_NAK:
  85833. + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
  85834. + break;
  85835. + case DWC_STS_DATA_UPDT:
  85836. + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
  85837. + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
  85838. + /** @todo NGS Check for buffer overflow? */
  85839. + dwc_otg_read_packet(core_if,
  85840. + ep->dwc_ep.xfer_buff,
  85841. + status.b.bcnt);
  85842. + ep->dwc_ep.xfer_count += status.b.bcnt;
  85843. + ep->dwc_ep.xfer_buff += status.b.bcnt;
  85844. + }
  85845. + break;
  85846. + case DWC_STS_XFER_COMP:
  85847. + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
  85848. + break;
  85849. + case DWC_DSTS_SETUP_COMP:
  85850. +#ifdef DEBUG_EP0
  85851. + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
  85852. +#endif
  85853. + break;
  85854. + case DWC_DSTS_SETUP_UPDT:
  85855. + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
  85856. +#ifdef DEBUG_EP0
  85857. + DWC_DEBUGPL(DBG_PCD,
  85858. + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
  85859. + pcd->setup_pkt->req.bmRequestType,
  85860. + pcd->setup_pkt->req.bRequest,
  85861. + UGETW(pcd->setup_pkt->req.wValue),
  85862. + UGETW(pcd->setup_pkt->req.wIndex),
  85863. + UGETW(pcd->setup_pkt->req.wLength));
  85864. +#endif
  85865. + ep->dwc_ep.xfer_count += status.b.bcnt;
  85866. + break;
  85867. + default:
  85868. + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
  85869. + status.b.pktsts);
  85870. + break;
  85871. + }
  85872. +
  85873. + /* Enable the Rx Status Queue Level interrupt */
  85874. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmask.d32);
  85875. + /* Clear interrupt */
  85876. + gintsts.d32 = 0;
  85877. + gintsts.b.rxstsqlvl = 1;
  85878. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  85879. +
  85880. + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
  85881. + return 1;
  85882. +}
  85883. +
  85884. +/**
  85885. + * This function examines the Device IN Token Learning Queue to
  85886. + * determine the EP number of the last IN token received. This
  85887. + * implementation is for the Mass Storage device where there are only
  85888. + * 2 IN EPs (Control-IN and BULK-IN).
  85889. + *
  85890. + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
  85891. + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
  85892. + *
  85893. + * @param core_if Programming view of DWC_otg controller.
  85894. + *
  85895. + */
  85896. +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t * core_if)
  85897. +{
  85898. + dwc_otg_device_global_regs_t *dev_global_regs =
  85899. + core_if->dev_if->dev_global_regs;
  85900. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  85901. + /* Number of Token Queue Registers */
  85902. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  85903. + dtknq1_data_t dtknqr1;
  85904. + uint32_t in_tkn_epnums[4];
  85905. + int ndx = 0;
  85906. + int i = 0;
  85907. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  85908. + int epnum = 0;
  85909. +
  85910. + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  85911. +
  85912. + /* Read the DTKNQ Registers */
  85913. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  85914. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  85915. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  85916. + in_tkn_epnums[i]);
  85917. + if (addr == &dev_global_regs->dvbusdis) {
  85918. + addr = &dev_global_regs->dtknqr3_dthrctl;
  85919. + } else {
  85920. + ++addr;
  85921. + }
  85922. +
  85923. + }
  85924. +
  85925. + /* Copy the DTKNQR1 data to the bit field. */
  85926. + dtknqr1.d32 = in_tkn_epnums[0];
  85927. + /* Get the EP numbers */
  85928. + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
  85929. + ndx = dtknqr1.b.intknwptr - 1;
  85930. +
  85931. + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
  85932. + if (ndx == -1) {
  85933. + /** @todo Find a simpler way to calculate the max
  85934. + * queue position.*/
  85935. + int cnt = TOKEN_Q_DEPTH;
  85936. + if (TOKEN_Q_DEPTH <= 6) {
  85937. + cnt = TOKEN_Q_DEPTH - 1;
  85938. + } else if (TOKEN_Q_DEPTH <= 14) {
  85939. + cnt = TOKEN_Q_DEPTH - 7;
  85940. + } else if (TOKEN_Q_DEPTH <= 22) {
  85941. + cnt = TOKEN_Q_DEPTH - 15;
  85942. + } else {
  85943. + cnt = TOKEN_Q_DEPTH - 23;
  85944. + }
  85945. + epnum = (in_tkn_epnums[DTKNQ_REG_CNT - 1] >> (cnt * 4)) & 0xF;
  85946. + } else {
  85947. + if (ndx <= 5) {
  85948. + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
  85949. + } else if (ndx <= 13) {
  85950. + ndx -= 6;
  85951. + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
  85952. + } else if (ndx <= 21) {
  85953. + ndx -= 14;
  85954. + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
  85955. + } else if (ndx <= 29) {
  85956. + ndx -= 22;
  85957. + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
  85958. + }
  85959. + }
  85960. + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
  85961. + return epnum;
  85962. +}
  85963. +
  85964. +/**
  85965. + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
  85966. + * The active request is checked for the next packet to be loaded into
  85967. + * the non-periodic Tx FIFO.
  85968. + */
  85969. +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t * pcd)
  85970. +{
  85971. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85972. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  85973. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  85974. + gnptxsts_data_t txstatus = {.d32 = 0 };
  85975. + gintsts_data_t gintsts;
  85976. +
  85977. + int epnum = 0;
  85978. + dwc_otg_pcd_ep_t *ep = 0;
  85979. + uint32_t len = 0;
  85980. + int dwords;
  85981. +
  85982. + /* Get the epnum from the IN Token Learning Queue. */
  85983. + epnum = get_ep_of_last_in_token(core_if);
  85984. + ep = get_in_ep(pcd, epnum);
  85985. +
  85986. + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %d \n", epnum);
  85987. +
  85988. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  85989. +
  85990. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  85991. + if (len > ep->dwc_ep.maxpacket) {
  85992. + len = ep->dwc_ep.maxpacket;
  85993. + }
  85994. + dwords = (len + 3) / 4;
  85995. +
  85996. + /* While there is space in the queue and space in the FIFO and
  85997. + * More data to tranfer, Write packets to the Tx FIFO */
  85998. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  85999. + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n", txstatus.d32);
  86000. +
  86001. + while (txstatus.b.nptxqspcavail > 0 &&
  86002. + txstatus.b.nptxfspcavail > dwords &&
  86003. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
  86004. + /* Write the FIFO */
  86005. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  86006. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  86007. +
  86008. + if (len > ep->dwc_ep.maxpacket) {
  86009. + len = ep->dwc_ep.maxpacket;
  86010. + }
  86011. +
  86012. + dwords = (len + 3) / 4;
  86013. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  86014. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n", txstatus.d32);
  86015. + }
  86016. +
  86017. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
  86018. + DWC_READ_REG32(&global_regs->gnptxsts));
  86019. +
  86020. + /* Clear interrupt */
  86021. + gintsts.d32 = 0;
  86022. + gintsts.b.nptxfempty = 1;
  86023. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  86024. +
  86025. + return 1;
  86026. +}
  86027. +
  86028. +/**
  86029. + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
  86030. + * The active request is checked for the next packet to be loaded into
  86031. + * apropriate Tx FIFO.
  86032. + */
  86033. +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t * pcd, uint32_t epnum)
  86034. +{
  86035. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86036. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86037. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  86038. + dtxfsts_data_t txstatus = {.d32 = 0 };
  86039. + dwc_otg_pcd_ep_t *ep = 0;
  86040. + uint32_t len = 0;
  86041. + int dwords;
  86042. +
  86043. + ep = get_in_ep(pcd, epnum);
  86044. +
  86045. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  86046. +
  86047. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  86048. +
  86049. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  86050. +
  86051. + if (len > ep->dwc_ep.maxpacket) {
  86052. + len = ep->dwc_ep.maxpacket;
  86053. + }
  86054. +
  86055. + dwords = (len + 3) / 4;
  86056. +
  86057. + /* While there is space in the queue and space in the FIFO and
  86058. + * More data to tranfer, Write packets to the Tx FIFO */
  86059. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  86060. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  86061. +
  86062. + while (txstatus.b.txfspcavail > dwords &&
  86063. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
  86064. + ep->dwc_ep.xfer_len != 0) {
  86065. + /* Write the FIFO */
  86066. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  86067. +
  86068. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  86069. + if (len > ep->dwc_ep.maxpacket) {
  86070. + len = ep->dwc_ep.maxpacket;
  86071. + }
  86072. +
  86073. + dwords = (len + 3) / 4;
  86074. + txstatus.d32 =
  86075. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  86076. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  86077. + txstatus.d32);
  86078. + }
  86079. +
  86080. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  86081. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  86082. +
  86083. + return 1;
  86084. +}
  86085. +
  86086. +/**
  86087. + * This function is called when the Device is disconnected. It stops
  86088. + * any active requests and informs the Gadget driver of the
  86089. + * disconnect.
  86090. + */
  86091. +void dwc_otg_pcd_stop(dwc_otg_pcd_t * pcd)
  86092. +{
  86093. + int i, num_in_eps, num_out_eps;
  86094. + dwc_otg_pcd_ep_t *ep;
  86095. +
  86096. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86097. +
  86098. + DWC_SPINLOCK(pcd->lock);
  86099. +
  86100. + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  86101. + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  86102. +
  86103. + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
  86104. + /* don't disconnect drivers more than once */
  86105. + if (pcd->ep0state == EP0_DISCONNECT) {
  86106. + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
  86107. + DWC_SPINUNLOCK(pcd->lock);
  86108. + return;
  86109. + }
  86110. + pcd->ep0state = EP0_DISCONNECT;
  86111. +
  86112. + /* Reset the OTG state. */
  86113. + dwc_otg_pcd_update_otg(pcd, 1);
  86114. +
  86115. + /* Disable the NP Tx Fifo Empty Interrupt. */
  86116. + intr_mask.b.nptxfempty = 1;
  86117. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86118. + intr_mask.d32, 0);
  86119. +
  86120. + /* Flush the FIFOs */
  86121. + /**@todo NGS Flush Periodic FIFOs */
  86122. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
  86123. + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
  86124. +
  86125. + /* prevent new request submissions, kill any outstanding requests */
  86126. + ep = &pcd->ep0;
  86127. + dwc_otg_request_nuke(ep);
  86128. + /* prevent new request submissions, kill any outstanding requests */
  86129. + for (i = 0; i < num_in_eps; i++) {
  86130. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
  86131. + dwc_otg_request_nuke(ep);
  86132. + }
  86133. + /* prevent new request submissions, kill any outstanding requests */
  86134. + for (i = 0; i < num_out_eps; i++) {
  86135. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
  86136. + dwc_otg_request_nuke(ep);
  86137. + }
  86138. +
  86139. + /* report disconnect; the driver is already quiesced */
  86140. + if (pcd->fops->disconnect) {
  86141. + DWC_SPINUNLOCK(pcd->lock);
  86142. + pcd->fops->disconnect(pcd);
  86143. + DWC_SPINLOCK(pcd->lock);
  86144. + }
  86145. + DWC_SPINUNLOCK(pcd->lock);
  86146. +}
  86147. +
  86148. +/**
  86149. + * This interrupt indicates that ...
  86150. + */
  86151. +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t * pcd)
  86152. +{
  86153. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86154. + gintsts_data_t gintsts;
  86155. +
  86156. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "i2cintr");
  86157. + intr_mask.b.i2cintr = 1;
  86158. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86159. + intr_mask.d32, 0);
  86160. +
  86161. + /* Clear interrupt */
  86162. + gintsts.d32 = 0;
  86163. + gintsts.b.i2cintr = 1;
  86164. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86165. + gintsts.d32);
  86166. + return 1;
  86167. +}
  86168. +
  86169. +/**
  86170. + * This interrupt indicates that ...
  86171. + */
  86172. +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t * pcd)
  86173. +{
  86174. + gintsts_data_t gintsts;
  86175. +#if defined(VERBOSE)
  86176. + DWC_PRINTF("Early Suspend Detected\n");
  86177. +#endif
  86178. +
  86179. + /* Clear interrupt */
  86180. + gintsts.d32 = 0;
  86181. + gintsts.b.erlysuspend = 1;
  86182. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86183. + gintsts.d32);
  86184. + return 1;
  86185. +}
  86186. +
  86187. +/**
  86188. + * This function configures EPO to receive SETUP packets.
  86189. + *
  86190. + * @todo NGS: Update the comments from the HW FS.
  86191. + *
  86192. + * -# Program the following fields in the endpoint specific registers
  86193. + * for Control OUT EP 0, in order to receive a setup packet
  86194. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  86195. + * setup packets)
  86196. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  86197. + * to back setup packets)
  86198. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  86199. + * store any setup packets received
  86200. + *
  86201. + * @param core_if Programming view of DWC_otg controller.
  86202. + * @param pcd Programming view of the PCD.
  86203. + */
  86204. +static inline void ep0_out_start(dwc_otg_core_if_t * core_if,
  86205. + dwc_otg_pcd_t * pcd)
  86206. +{
  86207. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86208. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  86209. + dwc_otg_dev_dma_desc_t *dma_desc;
  86210. + depctl_data_t doepctl = {.d32 = 0 };
  86211. +
  86212. +#ifdef VERBOSE
  86213. + DWC_DEBUGPL(DBG_PCDV, "%s() doepctl0=%0x\n", __func__,
  86214. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  86215. +#endif
  86216. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  86217. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  86218. + if (doepctl.b.epena) {
  86219. + return;
  86220. + }
  86221. + }
  86222. +
  86223. + doeptsize0.b.supcnt = 3;
  86224. + doeptsize0.b.pktcnt = 1;
  86225. + doeptsize0.b.xfersize = 8 * 3;
  86226. +
  86227. + if (core_if->dma_enable) {
  86228. + if (!core_if->dma_desc_enable) {
  86229. + /** put here as for Hermes mode deptisz register should not be written */
  86230. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  86231. + doeptsize0.d32);
  86232. +
  86233. + /** @todo dma needs to handle multiple setup packets (up to 3) */
  86234. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  86235. + pcd->setup_pkt_dma_handle);
  86236. + } else {
  86237. + dev_if->setup_desc_index =
  86238. + (dev_if->setup_desc_index + 1) & 1;
  86239. + dma_desc =
  86240. + dev_if->setup_desc_addr[dev_if->setup_desc_index];
  86241. +
  86242. + /** DMA Descriptor Setup */
  86243. + dma_desc->status.b.bs = BS_HOST_BUSY;
  86244. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  86245. + dma_desc->status.b.sr = 0;
  86246. + dma_desc->status.b.mtrf = 0;
  86247. + }
  86248. + dma_desc->status.b.l = 1;
  86249. + dma_desc->status.b.ioc = 1;
  86250. + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
  86251. + dma_desc->buf = pcd->setup_pkt_dma_handle;
  86252. + dma_desc->status.b.sts = 0;
  86253. + dma_desc->status.b.bs = BS_HOST_READY;
  86254. +
  86255. + /** DOEPDMA0 Register write */
  86256. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  86257. + dev_if->dma_setup_desc_addr
  86258. + [dev_if->setup_desc_index]);
  86259. + }
  86260. +
  86261. + } else {
  86262. + /** put here as for Hermes mode deptisz register should not be written */
  86263. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  86264. + doeptsize0.d32);
  86265. + }
  86266. +
  86267. + /** DOEPCTL0 Register write cnak will be set after setup interrupt */
  86268. + doepctl.d32 = 0;
  86269. + doepctl.b.epena = 1;
  86270. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  86271. + doepctl.b.cnak = 1;
  86272. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  86273. + } else {
  86274. + DWC_MODIFY_REG32(&dev_if->out_ep_regs[0]->doepctl, 0, doepctl.d32);
  86275. + }
  86276. +
  86277. +#ifdef VERBOSE
  86278. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  86279. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  86280. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  86281. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  86282. +#endif
  86283. +}
  86284. +
  86285. +/**
  86286. + * This interrupt occurs when a USB Reset is detected. When the USB
  86287. + * Reset Interrupt occurs the device state is set to DEFAULT and the
  86288. + * EP0 state is set to IDLE.
  86289. + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
  86290. + * -# Unmask the following interrupt bits
  86291. + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
  86292. + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
  86293. + * - DOEPMSK.SETUP = 1
  86294. + * - DOEPMSK.XferCompl = 1
  86295. + * - DIEPMSK.XferCompl = 1
  86296. + * - DIEPMSK.TimeOut = 1
  86297. + * -# Program the following fields in the endpoint specific registers
  86298. + * for Control OUT EP 0, in order to receive a setup packet
  86299. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  86300. + * setup packets)
  86301. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  86302. + * to back setup packets)
  86303. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  86304. + * store any setup packets received
  86305. + * At this point, all the required initialization, except for enabling
  86306. + * the control 0 OUT endpoint is done, for receiving SETUP packets.
  86307. + */
  86308. +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
  86309. +{
  86310. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86311. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86312. + depctl_data_t doepctl = {.d32 = 0 };
  86313. + depctl_data_t diepctl = {.d32 = 0 };
  86314. + daint_data_t daintmsk = {.d32 = 0 };
  86315. + doepmsk_data_t doepmsk = {.d32 = 0 };
  86316. + diepmsk_data_t diepmsk = {.d32 = 0 };
  86317. + dcfg_data_t dcfg = {.d32 = 0 };
  86318. + grstctl_t resetctl = {.d32 = 0 };
  86319. + dctl_data_t dctl = {.d32 = 0 };
  86320. + int i = 0;
  86321. + gintsts_data_t gintsts;
  86322. + pcgcctl_data_t power = {.d32 = 0 };
  86323. +
  86324. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  86325. + if (power.b.stoppclk) {
  86326. + power.d32 = 0;
  86327. + power.b.stoppclk = 1;
  86328. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  86329. +
  86330. + power.b.pwrclmp = 1;
  86331. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  86332. +
  86333. + power.b.rstpdwnmodule = 1;
  86334. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  86335. + }
  86336. +
  86337. + core_if->lx_state = DWC_OTG_L0;
  86338. +
  86339. + DWC_PRINTF("USB RESET\n");
  86340. +#ifdef DWC_EN_ISOC
  86341. + for (i = 1; i < 16; ++i) {
  86342. + dwc_otg_pcd_ep_t *ep;
  86343. + dwc_ep_t *dwc_ep;
  86344. + ep = get_in_ep(pcd, i);
  86345. + if (ep != 0) {
  86346. + dwc_ep = &ep->dwc_ep;
  86347. + dwc_ep->next_frame = 0xffffffff;
  86348. + }
  86349. + }
  86350. +#endif /* DWC_EN_ISOC */
  86351. +
  86352. + /* reset the HNP settings */
  86353. + dwc_otg_pcd_update_otg(pcd, 1);
  86354. +
  86355. + /* Clear the Remote Wakeup Signalling */
  86356. + dctl.b.rmtwkupsig = 1;
  86357. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  86358. +
  86359. + /* Set NAK for all OUT EPs */
  86360. + doepctl.b.snak = 1;
  86361. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  86362. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  86363. + }
  86364. +
  86365. + /* Flush the NP Tx FIFO */
  86366. + dwc_otg_flush_tx_fifo(core_if, 0x10);
  86367. + /* Flush the Learning Queue */
  86368. + resetctl.b.intknqflsh = 1;
  86369. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  86370. +
  86371. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  86372. + core_if->start_predict = 0;
  86373. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  86374. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  86375. + }
  86376. + core_if->nextep_seq[0] = 0;
  86377. + core_if->first_in_nextep_seq = 0;
  86378. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  86379. + diepctl.b.nextep = 0;
  86380. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  86381. +
  86382. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  86383. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  86384. + dcfg.b.epmscnt = 2;
  86385. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  86386. +
  86387. + DWC_DEBUGPL(DBG_PCDV,
  86388. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  86389. + __func__, core_if->first_in_nextep_seq);
  86390. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  86391. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  86392. + }
  86393. + }
  86394. +
  86395. + if (core_if->multiproc_int_enable) {
  86396. + daintmsk.b.inep0 = 1;
  86397. + daintmsk.b.outep0 = 1;
  86398. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk,
  86399. + daintmsk.d32);
  86400. +
  86401. + doepmsk.b.setup = 1;
  86402. + doepmsk.b.xfercompl = 1;
  86403. + doepmsk.b.ahberr = 1;
  86404. + doepmsk.b.epdisabled = 1;
  86405. +
  86406. + if ((core_if->dma_desc_enable) ||
  86407. + (core_if->dma_enable
  86408. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  86409. + doepmsk.b.stsphsercvd = 1;
  86410. + }
  86411. + if (core_if->dma_desc_enable)
  86412. + doepmsk.b.bna = 1;
  86413. +/*
  86414. + doepmsk.b.babble = 1;
  86415. + doepmsk.b.nyet = 1;
  86416. +
  86417. + if (core_if->dma_enable) {
  86418. + doepmsk.b.nak = 1;
  86419. + }
  86420. +*/
  86421. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepeachintmsk[0],
  86422. + doepmsk.d32);
  86423. +
  86424. + diepmsk.b.xfercompl = 1;
  86425. + diepmsk.b.timeout = 1;
  86426. + diepmsk.b.epdisabled = 1;
  86427. + diepmsk.b.ahberr = 1;
  86428. + diepmsk.b.intknepmis = 1;
  86429. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  86430. + diepmsk.b.intknepmis = 0;
  86431. +
  86432. +/* if (core_if->dma_desc_enable) {
  86433. + diepmsk.b.bna = 1;
  86434. + }
  86435. +*/
  86436. +/*
  86437. + if (core_if->dma_enable) {
  86438. + diepmsk.b.nak = 1;
  86439. + }
  86440. +*/
  86441. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepeachintmsk[0],
  86442. + diepmsk.d32);
  86443. + } else {
  86444. + daintmsk.b.inep0 = 1;
  86445. + daintmsk.b.outep0 = 1;
  86446. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk,
  86447. + daintmsk.d32);
  86448. +
  86449. + doepmsk.b.setup = 1;
  86450. + doepmsk.b.xfercompl = 1;
  86451. + doepmsk.b.ahberr = 1;
  86452. + doepmsk.b.epdisabled = 1;
  86453. +
  86454. + if ((core_if->dma_desc_enable) ||
  86455. + (core_if->dma_enable
  86456. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  86457. + doepmsk.b.stsphsercvd = 1;
  86458. + }
  86459. + if (core_if->dma_desc_enable)
  86460. + doepmsk.b.bna = 1;
  86461. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
  86462. +
  86463. + diepmsk.b.xfercompl = 1;
  86464. + diepmsk.b.timeout = 1;
  86465. + diepmsk.b.epdisabled = 1;
  86466. + diepmsk.b.ahberr = 1;
  86467. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  86468. + diepmsk.b.intknepmis = 0;
  86469. +/*
  86470. + if (core_if->dma_desc_enable) {
  86471. + diepmsk.b.bna = 1;
  86472. + }
  86473. +*/
  86474. +
  86475. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
  86476. + }
  86477. +
  86478. + /* Reset Device Address */
  86479. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  86480. + dcfg.b.devaddr = 0;
  86481. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  86482. +
  86483. + /* setup EP0 to receive SETUP packets */
  86484. + if (core_if->snpsid <= OTG_CORE_REV_2_94a)
  86485. + ep0_out_start(core_if, pcd);
  86486. +
  86487. + /* Clear interrupt */
  86488. + gintsts.d32 = 0;
  86489. + gintsts.b.usbreset = 1;
  86490. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  86491. +
  86492. + return 1;
  86493. +}
  86494. +
  86495. +/**
  86496. + * Get the device speed from the device status register and convert it
  86497. + * to USB speed constant.
  86498. + *
  86499. + * @param core_if Programming view of DWC_otg controller.
  86500. + */
  86501. +static int get_device_speed(dwc_otg_core_if_t * core_if)
  86502. +{
  86503. + dsts_data_t dsts;
  86504. + int speed = 0;
  86505. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  86506. +
  86507. + switch (dsts.b.enumspd) {
  86508. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  86509. + speed = USB_SPEED_HIGH;
  86510. + break;
  86511. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  86512. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  86513. + speed = USB_SPEED_FULL;
  86514. + break;
  86515. +
  86516. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  86517. + speed = USB_SPEED_LOW;
  86518. + break;
  86519. + }
  86520. +
  86521. + return speed;
  86522. +}
  86523. +
  86524. +/**
  86525. + * Read the device status register and set the device speed in the
  86526. + * data structure.
  86527. + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
  86528. + */
  86529. +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t * pcd)
  86530. +{
  86531. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86532. + gintsts_data_t gintsts;
  86533. + gusbcfg_data_t gusbcfg;
  86534. + dwc_otg_core_global_regs_t *global_regs =
  86535. + GET_CORE_IF(pcd)->core_global_regs;
  86536. + uint8_t utmi16b, utmi8b;
  86537. + int speed;
  86538. + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
  86539. +
  86540. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_2_60a) {
  86541. + utmi16b = 6; //vahrama old value was 6;
  86542. + utmi8b = 9;
  86543. + } else {
  86544. + utmi16b = 4;
  86545. + utmi8b = 8;
  86546. + }
  86547. + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
  86548. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a) {
  86549. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  86550. + }
  86551. +
  86552. +#ifdef DEBUG_EP0
  86553. + print_ep0_state(pcd);
  86554. +#endif
  86555. +
  86556. + if (pcd->ep0state == EP0_DISCONNECT) {
  86557. + pcd->ep0state = EP0_IDLE;
  86558. + } else if (pcd->ep0state == EP0_STALL) {
  86559. + pcd->ep0state = EP0_IDLE;
  86560. + }
  86561. +
  86562. + pcd->ep0state = EP0_IDLE;
  86563. +
  86564. + ep0->stopped = 0;
  86565. +
  86566. + speed = get_device_speed(GET_CORE_IF(pcd));
  86567. + pcd->fops->connect(pcd, speed);
  86568. +
  86569. + /* Set USB turnaround time based on device speed and PHY interface. */
  86570. + gusbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  86571. + if (speed == USB_SPEED_HIGH) {
  86572. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  86573. + DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
  86574. + /* ULPI interface */
  86575. + gusbcfg.b.usbtrdtim = 9;
  86576. + }
  86577. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  86578. + DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
  86579. + /* UTMI+ interface */
  86580. + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
  86581. + gusbcfg.b.usbtrdtim = utmi8b;
  86582. + } else if (GET_CORE_IF(pcd)->hwcfg4.
  86583. + b.utmi_phy_data_width == 1) {
  86584. + gusbcfg.b.usbtrdtim = utmi16b;
  86585. + } else if (GET_CORE_IF(pcd)->
  86586. + core_params->phy_utmi_width == 8) {
  86587. + gusbcfg.b.usbtrdtim = utmi8b;
  86588. + } else {
  86589. + gusbcfg.b.usbtrdtim = utmi16b;
  86590. + }
  86591. + }
  86592. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  86593. + DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
  86594. + /* UTMI+ OR ULPI interface */
  86595. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  86596. + /* ULPI interface */
  86597. + gusbcfg.b.usbtrdtim = 9;
  86598. + } else {
  86599. + /* UTMI+ interface */
  86600. + if (GET_CORE_IF(pcd)->
  86601. + core_params->phy_utmi_width == 16) {
  86602. + gusbcfg.b.usbtrdtim = utmi16b;
  86603. + } else {
  86604. + gusbcfg.b.usbtrdtim = utmi8b;
  86605. + }
  86606. + }
  86607. + }
  86608. + } else {
  86609. + /* Full or low speed */
  86610. + gusbcfg.b.usbtrdtim = 9;
  86611. + }
  86612. + DWC_WRITE_REG32(&global_regs->gusbcfg, gusbcfg.d32);
  86613. +
  86614. + /* Clear interrupt */
  86615. + gintsts.d32 = 0;
  86616. + gintsts.b.enumdone = 1;
  86617. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86618. + gintsts.d32);
  86619. + return 1;
  86620. +}
  86621. +
  86622. +/**
  86623. + * This interrupt indicates that the ISO OUT Packet was dropped due to
  86624. + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
  86625. + * read all the data from the Rx FIFO.
  86626. + */
  86627. +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t * pcd)
  86628. +{
  86629. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86630. + gintsts_data_t gintsts;
  86631. +
  86632. + DWC_WARN("INTERRUPT Handler not implemented for %s\n",
  86633. + "ISOC Out Dropped");
  86634. +
  86635. + intr_mask.b.isooutdrop = 1;
  86636. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86637. + intr_mask.d32, 0);
  86638. +
  86639. + /* Clear interrupt */
  86640. + gintsts.d32 = 0;
  86641. + gintsts.b.isooutdrop = 1;
  86642. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86643. + gintsts.d32);
  86644. +
  86645. + return 1;
  86646. +}
  86647. +
  86648. +/**
  86649. + * This interrupt indicates the end of the portion of the micro-frame
  86650. + * for periodic transactions. If there is a periodic transaction for
  86651. + * the next frame, load the packets into the EP periodic Tx FIFO.
  86652. + */
  86653. +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t * pcd)
  86654. +{
  86655. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86656. + gintsts_data_t gintsts;
  86657. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "EOP");
  86658. +
  86659. + intr_mask.b.eopframe = 1;
  86660. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86661. + intr_mask.d32, 0);
  86662. +
  86663. + /* Clear interrupt */
  86664. + gintsts.d32 = 0;
  86665. + gintsts.b.eopframe = 1;
  86666. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86667. + gintsts.d32);
  86668. +
  86669. + return 1;
  86670. +}
  86671. +
  86672. +/**
  86673. + * This interrupt indicates that EP of the packet on the top of the
  86674. + * non-periodic Tx FIFO does not match EP of the IN Token received.
  86675. + *
  86676. + * The "Device IN Token Queue" Registers are read to determine the
  86677. + * order the IN Tokens have been received. The non-periodic Tx FIFO
  86678. + * is flushed, so it can be reloaded in the order seen in the IN Token
  86679. + * Queue.
  86680. + */
  86681. +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_pcd_t * pcd)
  86682. +{
  86683. + gintsts_data_t gintsts;
  86684. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86685. + dctl_data_t dctl;
  86686. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86687. +
  86688. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  86689. + core_if->start_predict = 1;
  86690. +
  86691. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  86692. +
  86693. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  86694. + if (!gintsts.b.ginnakeff) {
  86695. + /* Disable EP Mismatch interrupt */
  86696. + intr_mask.d32 = 0;
  86697. + intr_mask.b.epmismatch = 1;
  86698. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  86699. + /* Enable the Global IN NAK Effective Interrupt */
  86700. + intr_mask.d32 = 0;
  86701. + intr_mask.b.ginnakeff = 1;
  86702. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  86703. + /* Set the global non-periodic IN NAK handshake */
  86704. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  86705. + dctl.b.sgnpinnak = 1;
  86706. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  86707. + } else {
  86708. + DWC_PRINTF("gintsts.b.ginnakeff = 1! dctl.b.sgnpinnak not set\n");
  86709. + }
  86710. + /* Disabling of all EP's will be done in dwc_otg_pcd_handle_in_nak_effective()
  86711. + * handler after Global IN NAK Effective interrupt will be asserted */
  86712. + }
  86713. + /* Clear interrupt */
  86714. + gintsts.d32 = 0;
  86715. + gintsts.b.epmismatch = 1;
  86716. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  86717. +
  86718. + return 1;
  86719. +}
  86720. +
  86721. +/**
  86722. + * This interrupt is valid only in DMA mode. This interrupt indicates that the
  86723. + * core has stopped fetching data for IN endpoints due to the unavailability of
  86724. + * TxFIFO space or Request Queue space. This interrupt is used by the
  86725. + * application for an endpoint mismatch algorithm.
  86726. + *
  86727. + * @param pcd The PCD
  86728. + */
  86729. +int32_t dwc_otg_pcd_handle_ep_fetsusp_intr(dwc_otg_pcd_t * pcd)
  86730. +{
  86731. + gintsts_data_t gintsts;
  86732. + gintmsk_data_t gintmsk_data;
  86733. + dctl_data_t dctl;
  86734. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86735. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  86736. +
  86737. + /* Clear the global non-periodic IN NAK handshake */
  86738. + dctl.d32 = 0;
  86739. + dctl.b.cgnpinnak = 1;
  86740. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  86741. +
  86742. + /* Mask GINTSTS.FETSUSP interrupt */
  86743. + gintmsk_data.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  86744. + gintmsk_data.b.fetsusp = 0;
  86745. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_data.d32);
  86746. +
  86747. + /* Clear interrupt */
  86748. + gintsts.d32 = 0;
  86749. + gintsts.b.fetsusp = 1;
  86750. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  86751. +
  86752. + return 1;
  86753. +}
  86754. +/**
  86755. + * This funcion stalls EP0.
  86756. + */
  86757. +static inline void ep0_do_stall(dwc_otg_pcd_t * pcd, const int err_val)
  86758. +{
  86759. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86760. + usb_device_request_t *ctrl = &pcd->setup_pkt->req;
  86761. + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
  86762. + ctrl->bmRequestType, ctrl->bRequest, err_val);
  86763. +
  86764. + ep0->dwc_ep.is_in = 1;
  86765. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep0->dwc_ep);
  86766. + pcd->ep0.stopped = 1;
  86767. + pcd->ep0state = EP0_IDLE;
  86768. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  86769. +}
  86770. +
  86771. +/**
  86772. + * This functions delegates the setup command to the gadget driver.
  86773. + */
  86774. +static inline void do_gadget_setup(dwc_otg_pcd_t * pcd,
  86775. + usb_device_request_t * ctrl)
  86776. +{
  86777. + int ret = 0;
  86778. + DWC_SPINUNLOCK(pcd->lock);
  86779. + ret = pcd->fops->setup(pcd, (uint8_t *) ctrl);
  86780. + DWC_SPINLOCK(pcd->lock);
  86781. + if (ret < 0) {
  86782. + ep0_do_stall(pcd, ret);
  86783. + }
  86784. +
  86785. + /** @todo This is a g_file_storage gadget driver specific
  86786. + * workaround: a DELAYED_STATUS result from the fsg_setup
  86787. + * routine will result in the gadget queueing a EP0 IN status
  86788. + * phase for a two-stage control transfer. Exactly the same as
  86789. + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
  86790. + * specific request. Need a generic way to know when the gadget
  86791. + * driver will queue the status phase. Can we assume when we
  86792. + * call the gadget driver setup() function that it will always
  86793. + * queue and require the following flag? Need to look into
  86794. + * this.
  86795. + */
  86796. +
  86797. + if (ret == 256 + 999) {
  86798. + pcd->request_config = 1;
  86799. + }
  86800. +}
  86801. +
  86802. +#ifdef DWC_UTE_CFI
  86803. +/**
  86804. + * This functions delegates the CFI setup commands to the gadget driver.
  86805. + * This function will return a negative value to indicate a failure.
  86806. + */
  86807. +static inline int cfi_gadget_setup(dwc_otg_pcd_t * pcd,
  86808. + struct cfi_usb_ctrlrequest *ctrl_req)
  86809. +{
  86810. + int ret = 0;
  86811. +
  86812. + if (pcd->fops && pcd->fops->cfi_setup) {
  86813. + DWC_SPINUNLOCK(pcd->lock);
  86814. + ret = pcd->fops->cfi_setup(pcd, ctrl_req);
  86815. + DWC_SPINLOCK(pcd->lock);
  86816. + if (ret < 0) {
  86817. + ep0_do_stall(pcd, ret);
  86818. + return ret;
  86819. + }
  86820. + }
  86821. +
  86822. + return ret;
  86823. +}
  86824. +#endif
  86825. +
  86826. +/**
  86827. + * This function starts the Zero-Length Packet for the IN status phase
  86828. + * of a 2 stage control transfer.
  86829. + */
  86830. +static inline void do_setup_in_status_phase(dwc_otg_pcd_t * pcd)
  86831. +{
  86832. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86833. + if (pcd->ep0state == EP0_STALL) {
  86834. + return;
  86835. + }
  86836. +
  86837. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  86838. +
  86839. + /* Prepare for more SETUP Packets */
  86840. + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
  86841. + if ((GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a)
  86842. + && (pcd->core_if->dma_desc_enable)
  86843. + && (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len)) {
  86844. + DWC_DEBUGPL(DBG_PCDV,
  86845. + "Data terminated wait next packet in out_desc_addr\n");
  86846. + pcd->backup_buf = phys_to_virt(ep0->dwc_ep.dma_addr);
  86847. + pcd->data_terminated = 1;
  86848. + }
  86849. + ep0->dwc_ep.xfer_len = 0;
  86850. + ep0->dwc_ep.xfer_count = 0;
  86851. + ep0->dwc_ep.is_in = 1;
  86852. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  86853. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  86854. +
  86855. + /* Prepare for more SETUP Packets */
  86856. + //ep0_out_start(GET_CORE_IF(pcd), pcd);
  86857. +}
  86858. +
  86859. +/**
  86860. + * This function starts the Zero-Length Packet for the OUT status phase
  86861. + * of a 2 stage control transfer.
  86862. + */
  86863. +static inline void do_setup_out_status_phase(dwc_otg_pcd_t * pcd)
  86864. +{
  86865. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86866. + if (pcd->ep0state == EP0_STALL) {
  86867. + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
  86868. + return;
  86869. + }
  86870. + pcd->ep0state = EP0_OUT_STATUS_PHASE;
  86871. +
  86872. + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
  86873. + ep0->dwc_ep.xfer_len = 0;
  86874. + ep0->dwc_ep.xfer_count = 0;
  86875. + ep0->dwc_ep.is_in = 0;
  86876. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  86877. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  86878. +
  86879. + /* Prepare for more SETUP Packets */
  86880. + if (GET_CORE_IF(pcd)->dma_enable == 0) {
  86881. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  86882. + }
  86883. +}
  86884. +
  86885. +/**
  86886. + * Clear the EP halt (STALL) and if pending requests start the
  86887. + * transfer.
  86888. + */
  86889. +static inline void pcd_clear_halt(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  86890. +{
  86891. + if (ep->dwc_ep.stall_clear_flag == 0)
  86892. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  86893. +
  86894. + /* Reactive the EP */
  86895. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  86896. + if (ep->stopped) {
  86897. + ep->stopped = 0;
  86898. + /* If there is a request in the EP queue start it */
  86899. +
  86900. + /** @todo FIXME: this causes an EP mismatch in DMA mode.
  86901. + * epmismatch not yet implemented. */
  86902. +
  86903. + /*
  86904. + * Above fixme is solved by implmenting a tasklet to call the
  86905. + * start_next_request(), outside of interrupt context at some
  86906. + * time after the current time, after a clear-halt setup packet.
  86907. + * Still need to implement ep mismatch in the future if a gadget
  86908. + * ever uses more than one endpoint at once
  86909. + */
  86910. + ep->queue_sof = 1;
  86911. + DWC_TASK_SCHEDULE(pcd->start_xfer_tasklet);
  86912. + }
  86913. + /* Start Control Status Phase */
  86914. + do_setup_in_status_phase(pcd);
  86915. +}
  86916. +
  86917. +/**
  86918. + * This function is called when the SET_FEATURE TEST_MODE Setup packet
  86919. + * is sent from the host. The Device Control register is written with
  86920. + * the Test Mode bits set to the specified Test Mode. This is done as
  86921. + * a tasklet so that the "Status" phase of the control transfer
  86922. + * completes before transmitting the TEST packets.
  86923. + *
  86924. + * @todo This has not been tested since the tasklet struct was put
  86925. + * into the PCD struct!
  86926. + *
  86927. + */
  86928. +void do_test_mode(void *data)
  86929. +{
  86930. + dctl_data_t dctl;
  86931. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  86932. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86933. + int test_mode = pcd->test_mode;
  86934. +
  86935. +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
  86936. +
  86937. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  86938. + switch (test_mode) {
  86939. + case 1: // TEST_J
  86940. + dctl.b.tstctl = 1;
  86941. + break;
  86942. +
  86943. + case 2: // TEST_K
  86944. + dctl.b.tstctl = 2;
  86945. + break;
  86946. +
  86947. + case 3: // TEST_SE0_NAK
  86948. + dctl.b.tstctl = 3;
  86949. + break;
  86950. +
  86951. + case 4: // TEST_PACKET
  86952. + dctl.b.tstctl = 4;
  86953. + break;
  86954. +
  86955. + case 5: // TEST_FORCE_ENABLE
  86956. + dctl.b.tstctl = 5;
  86957. + break;
  86958. + }
  86959. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  86960. +}
  86961. +
  86962. +/**
  86963. + * This function process the GET_STATUS Setup Commands.
  86964. + */
  86965. +static inline void do_get_status(dwc_otg_pcd_t * pcd)
  86966. +{
  86967. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  86968. + dwc_otg_pcd_ep_t *ep;
  86969. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86970. + uint16_t *status = pcd->status_buf;
  86971. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86972. +
  86973. +#ifdef DEBUG_EP0
  86974. + DWC_DEBUGPL(DBG_PCD,
  86975. + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
  86976. + ctrl.bmRequestType, ctrl.bRequest,
  86977. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  86978. + UGETW(ctrl.wLength));
  86979. +#endif
  86980. +
  86981. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  86982. + case UT_DEVICE:
  86983. + if(UGETW(ctrl.wIndex) == 0xF000) { /* OTG Status selector */
  86984. + DWC_PRINTF("wIndex - %d\n", UGETW(ctrl.wIndex));
  86985. + DWC_PRINTF("OTG VERSION - %d\n", core_if->otg_ver);
  86986. + DWC_PRINTF("OTG CAP - %d, %d\n",
  86987. + core_if->core_params->otg_cap,
  86988. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  86989. + if (core_if->otg_ver == 1
  86990. + && core_if->core_params->otg_cap ==
  86991. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  86992. + uint8_t *otgsts = (uint8_t*)pcd->status_buf;
  86993. + *otgsts = (core_if->otg_sts & 0x1);
  86994. + pcd->ep0_pending = 1;
  86995. + ep0->dwc_ep.start_xfer_buff =
  86996. + (uint8_t *) otgsts;
  86997. + ep0->dwc_ep.xfer_buff = (uint8_t *) otgsts;
  86998. + ep0->dwc_ep.dma_addr =
  86999. + pcd->status_buf_dma_handle;
  87000. + ep0->dwc_ep.xfer_len = 1;
  87001. + ep0->dwc_ep.xfer_count = 0;
  87002. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  87003. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  87004. + &ep0->dwc_ep);
  87005. + return;
  87006. + } else {
  87007. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87008. + return;
  87009. + }
  87010. + break;
  87011. + } else {
  87012. + *status = 0x1; /* Self powered */
  87013. + *status |= pcd->remote_wakeup_enable << 1;
  87014. + break;
  87015. + }
  87016. + case UT_INTERFACE:
  87017. + *status = 0;
  87018. + break;
  87019. +
  87020. + case UT_ENDPOINT:
  87021. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  87022. + if (ep == 0 || UGETW(ctrl.wLength) > 2) {
  87023. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87024. + return;
  87025. + }
  87026. + /** @todo check for EP stall */
  87027. + *status = ep->stopped;
  87028. + break;
  87029. + }
  87030. + pcd->ep0_pending = 1;
  87031. + ep0->dwc_ep.start_xfer_buff = (uint8_t *) status;
  87032. + ep0->dwc_ep.xfer_buff = (uint8_t *) status;
  87033. + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
  87034. + ep0->dwc_ep.xfer_len = 2;
  87035. + ep0->dwc_ep.xfer_count = 0;
  87036. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  87037. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  87038. +}
  87039. +
  87040. +/**
  87041. + * This function process the SET_FEATURE Setup Commands.
  87042. + */
  87043. +static inline void do_set_feature(dwc_otg_pcd_t * pcd)
  87044. +{
  87045. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87046. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  87047. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  87048. + dwc_otg_pcd_ep_t *ep = 0;
  87049. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  87050. + gotgctl_data_t gotgctl = {.d32 = 0 };
  87051. +
  87052. + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  87053. + ctrl.bmRequestType, ctrl.bRequest,
  87054. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  87055. + UGETW(ctrl.wLength));
  87056. + DWC_DEBUGPL(DBG_PCD, "otg_cap=%d\n", otg_cap_param);
  87057. +
  87058. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  87059. + case UT_DEVICE:
  87060. + switch (UGETW(ctrl.wValue)) {
  87061. + case UF_DEVICE_REMOTE_WAKEUP:
  87062. + pcd->remote_wakeup_enable = 1;
  87063. + break;
  87064. +
  87065. + case UF_TEST_MODE:
  87066. + /* Setup the Test Mode tasklet to do the Test
  87067. + * Packet generation after the SETUP Status
  87068. + * phase has completed. */
  87069. +
  87070. + /** @todo This has not been tested since the
  87071. + * tasklet struct was put into the PCD
  87072. + * struct! */
  87073. + pcd->test_mode = UGETW(ctrl.wIndex) >> 8;
  87074. + DWC_TASK_SCHEDULE(pcd->test_mode_tasklet);
  87075. + break;
  87076. +
  87077. + case UF_DEVICE_B_HNP_ENABLE:
  87078. + DWC_DEBUGPL(DBG_PCDV,
  87079. + "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
  87080. +
  87081. + /* dev may initiate HNP */
  87082. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  87083. + pcd->b_hnp_enable = 1;
  87084. + dwc_otg_pcd_update_otg(pcd, 0);
  87085. + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
  87086. + /**@todo Is the gotgctl.devhnpen cleared
  87087. + * by a USB Reset? */
  87088. + gotgctl.b.devhnpen = 1;
  87089. + gotgctl.b.hnpreq = 1;
  87090. + DWC_WRITE_REG32(&global_regs->gotgctl,
  87091. + gotgctl.d32);
  87092. + } else {
  87093. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87094. + return;
  87095. + }
  87096. + break;
  87097. +
  87098. + case UF_DEVICE_A_HNP_SUPPORT:
  87099. + /* RH port supports HNP */
  87100. + DWC_DEBUGPL(DBG_PCDV,
  87101. + "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
  87102. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  87103. + pcd->a_hnp_support = 1;
  87104. + dwc_otg_pcd_update_otg(pcd, 0);
  87105. + } else {
  87106. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87107. + return;
  87108. + }
  87109. + break;
  87110. +
  87111. + case UF_DEVICE_A_ALT_HNP_SUPPORT:
  87112. + /* other RH port does */
  87113. + DWC_DEBUGPL(DBG_PCDV,
  87114. + "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
  87115. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  87116. + pcd->a_alt_hnp_support = 1;
  87117. + dwc_otg_pcd_update_otg(pcd, 0);
  87118. + } else {
  87119. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87120. + return;
  87121. + }
  87122. + break;
  87123. +
  87124. + default:
  87125. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87126. + return;
  87127. +
  87128. + }
  87129. + do_setup_in_status_phase(pcd);
  87130. + break;
  87131. +
  87132. + case UT_INTERFACE:
  87133. + do_gadget_setup(pcd, &ctrl);
  87134. + break;
  87135. +
  87136. + case UT_ENDPOINT:
  87137. + if (UGETW(ctrl.wValue) == UF_ENDPOINT_HALT) {
  87138. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  87139. + if (ep == 0) {
  87140. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87141. + return;
  87142. + }
  87143. + ep->stopped = 1;
  87144. + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
  87145. + }
  87146. + do_setup_in_status_phase(pcd);
  87147. + break;
  87148. + }
  87149. +}
  87150. +
  87151. +/**
  87152. + * This function process the CLEAR_FEATURE Setup Commands.
  87153. + */
  87154. +static inline void do_clear_feature(dwc_otg_pcd_t * pcd)
  87155. +{
  87156. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  87157. + dwc_otg_pcd_ep_t *ep = 0;
  87158. +
  87159. + DWC_DEBUGPL(DBG_PCD,
  87160. + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  87161. + ctrl.bmRequestType, ctrl.bRequest,
  87162. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  87163. + UGETW(ctrl.wLength));
  87164. +
  87165. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  87166. + case UT_DEVICE:
  87167. + switch (UGETW(ctrl.wValue)) {
  87168. + case UF_DEVICE_REMOTE_WAKEUP:
  87169. + pcd->remote_wakeup_enable = 0;
  87170. + break;
  87171. +
  87172. + case UF_TEST_MODE:
  87173. + /** @todo Add CLEAR_FEATURE for TEST modes. */
  87174. + break;
  87175. +
  87176. + default:
  87177. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87178. + return;
  87179. + }
  87180. + do_setup_in_status_phase(pcd);
  87181. + break;
  87182. +
  87183. + case UT_ENDPOINT:
  87184. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  87185. + if (ep == 0) {
  87186. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87187. + return;
  87188. + }
  87189. +
  87190. + pcd_clear_halt(pcd, ep);
  87191. +
  87192. + break;
  87193. + }
  87194. +}
  87195. +
  87196. +/**
  87197. + * This function process the SET_ADDRESS Setup Commands.
  87198. + */
  87199. +static inline void do_set_address(dwc_otg_pcd_t * pcd)
  87200. +{
  87201. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  87202. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  87203. +
  87204. + if (ctrl.bmRequestType == UT_DEVICE) {
  87205. + dcfg_data_t dcfg = {.d32 = 0 };
  87206. +
  87207. +#ifdef DEBUG_EP0
  87208. +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
  87209. +#endif
  87210. + dcfg.b.devaddr = UGETW(ctrl.wValue);
  87211. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
  87212. + do_setup_in_status_phase(pcd);
  87213. + }
  87214. +}
  87215. +
  87216. +/**
  87217. + * This function processes SETUP commands. In Linux, the USB Command
  87218. + * processing is done in two places - the first being the PCD and the
  87219. + * second in the Gadget Driver (for example, the File-Backed Storage
  87220. + * Gadget Driver).
  87221. + *
  87222. + * <table>
  87223. + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
  87224. + *
  87225. + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
  87226. + * defined in chapter 9 of the USB 2.0 Specification chapter 9
  87227. + * </td></tr>
  87228. + *
  87229. + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  87230. + * requests are the ENDPOINT_HALT feature is procesed, all others the
  87231. + * interface requests are ignored.</td></tr>
  87232. + *
  87233. + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  87234. + * requests are processed by the PCD. Interface requests are passed
  87235. + * to the Gadget Driver.</td></tr>
  87236. + *
  87237. + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
  87238. + * with device address received </td></tr>
  87239. + *
  87240. + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
  87241. + * requested descriptor</td></tr>
  87242. + *
  87243. + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
  87244. + * not implemented by any of the existing Gadget Drivers.</td></tr>
  87245. + *
  87246. + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
  87247. + * all EPs and enable EPs for new configuration.</td></tr>
  87248. + *
  87249. + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
  87250. + * the current configuration</td></tr>
  87251. + *
  87252. + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
  87253. + * EPs and enable EPs for new configuration.</td></tr>
  87254. + *
  87255. + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
  87256. + * current interface.</td></tr>
  87257. + *
  87258. + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
  87259. + * message.</td></tr>
  87260. + * </table>
  87261. + *
  87262. + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
  87263. + * processed by pcd_setup. Calling the Function Driver's setup function from
  87264. + * pcd_setup processes the gadget SETUP commands.
  87265. + */
  87266. +static inline void pcd_setup(dwc_otg_pcd_t * pcd)
  87267. +{
  87268. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87269. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  87270. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  87271. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  87272. +
  87273. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  87274. +
  87275. +#ifdef DWC_UTE_CFI
  87276. + int retval = 0;
  87277. + struct cfi_usb_ctrlrequest cfi_req;
  87278. +#endif
  87279. +
  87280. + doeptsize0.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doeptsiz);
  87281. +
  87282. + /** In BDMA more then 1 setup packet is not supported till 3.00a */
  87283. + if (core_if->dma_enable && core_if->dma_desc_enable == 0
  87284. + && (doeptsize0.b.supcnt < 2)
  87285. + && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  87286. + DWC_ERROR
  87287. + ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
  87288. + }
  87289. + if ((core_if->snpsid >= OTG_CORE_REV_3_00a)
  87290. + && (core_if->dma_enable == 1) && (core_if->dma_desc_enable == 0)) {
  87291. + ctrl =
  87292. + (pcd->setup_pkt +
  87293. + (3 - doeptsize0.b.supcnt - 1 +
  87294. + ep0->dwc_ep.stp_rollover))->req;
  87295. + }
  87296. +#ifdef DEBUG_EP0
  87297. + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  87298. + ctrl.bmRequestType, ctrl.bRequest,
  87299. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  87300. + UGETW(ctrl.wLength));
  87301. +#endif
  87302. +
  87303. + /* Clean up the request queue */
  87304. + dwc_otg_request_nuke(ep0);
  87305. + ep0->stopped = 0;
  87306. +
  87307. + if (ctrl.bmRequestType & UE_DIR_IN) {
  87308. + ep0->dwc_ep.is_in = 1;
  87309. + pcd->ep0state = EP0_IN_DATA_PHASE;
  87310. + } else {
  87311. + ep0->dwc_ep.is_in = 0;
  87312. + pcd->ep0state = EP0_OUT_DATA_PHASE;
  87313. + }
  87314. +
  87315. + if (UGETW(ctrl.wLength) == 0) {
  87316. + ep0->dwc_ep.is_in = 1;
  87317. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  87318. + }
  87319. +
  87320. + if (UT_GET_TYPE(ctrl.bmRequestType) != UT_STANDARD) {
  87321. +
  87322. +#ifdef DWC_UTE_CFI
  87323. + DWC_MEMCPY(&cfi_req, &ctrl, sizeof(usb_device_request_t));
  87324. +
  87325. + //printk(KERN_ALERT "CFI: req_type=0x%02x; req=0x%02x\n",
  87326. + ctrl.bRequestType, ctrl.bRequest);
  87327. + if (UT_GET_TYPE(cfi_req.bRequestType) == UT_VENDOR) {
  87328. + if (cfi_req.bRequest > 0xB0 && cfi_req.bRequest < 0xBF) {
  87329. + retval = cfi_setup(pcd, &cfi_req);
  87330. + if (retval < 0) {
  87331. + ep0_do_stall(pcd, retval);
  87332. + pcd->ep0_pending = 0;
  87333. + return;
  87334. + }
  87335. +
  87336. + /* if need gadget setup then call it and check the retval */
  87337. + if (pcd->cfi->need_gadget_att) {
  87338. + retval =
  87339. + cfi_gadget_setup(pcd,
  87340. + &pcd->
  87341. + cfi->ctrl_req);
  87342. + if (retval < 0) {
  87343. + pcd->ep0_pending = 0;
  87344. + return;
  87345. + }
  87346. + }
  87347. +
  87348. + if (pcd->cfi->need_status_in_complete) {
  87349. + do_setup_in_status_phase(pcd);
  87350. + }
  87351. + return;
  87352. + }
  87353. + }
  87354. +#endif
  87355. +
  87356. + /* handle non-standard (class/vendor) requests in the gadget driver */
  87357. + do_gadget_setup(pcd, &ctrl);
  87358. + return;
  87359. + }
  87360. +
  87361. + /** @todo NGS: Handle bad setup packet? */
  87362. +
  87363. +///////////////////////////////////////////
  87364. +//// --- Standard Request handling --- ////
  87365. +
  87366. + switch (ctrl.bRequest) {
  87367. + case UR_GET_STATUS:
  87368. + do_get_status(pcd);
  87369. + break;
  87370. +
  87371. + case UR_CLEAR_FEATURE:
  87372. + do_clear_feature(pcd);
  87373. + break;
  87374. +
  87375. + case UR_SET_FEATURE:
  87376. + do_set_feature(pcd);
  87377. + break;
  87378. +
  87379. + case UR_SET_ADDRESS:
  87380. + do_set_address(pcd);
  87381. + break;
  87382. +
  87383. + case UR_SET_INTERFACE:
  87384. + case UR_SET_CONFIG:
  87385. +// _pcd->request_config = 1; /* Configuration changed */
  87386. + do_gadget_setup(pcd, &ctrl);
  87387. + break;
  87388. +
  87389. + case UR_SYNCH_FRAME:
  87390. + do_gadget_setup(pcd, &ctrl);
  87391. + break;
  87392. +
  87393. + default:
  87394. + /* Call the Gadget Driver's setup functions */
  87395. + do_gadget_setup(pcd, &ctrl);
  87396. + break;
  87397. + }
  87398. +}
  87399. +
  87400. +/**
  87401. + * This function completes the ep0 control transfer.
  87402. + */
  87403. +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t * ep)
  87404. +{
  87405. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  87406. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  87407. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  87408. + dev_if->in_ep_regs[ep->dwc_ep.num];
  87409. +#ifdef DEBUG_EP0
  87410. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  87411. + dev_if->out_ep_regs[ep->dwc_ep.num];
  87412. +#endif
  87413. + deptsiz0_data_t deptsiz;
  87414. + dev_dma_desc_sts_t desc_sts;
  87415. + dwc_otg_pcd_request_t *req;
  87416. + int is_last = 0;
  87417. + dwc_otg_pcd_t *pcd = ep->pcd;
  87418. +
  87419. +#ifdef DWC_UTE_CFI
  87420. + struct cfi_usb_ctrlrequest *ctrlreq;
  87421. + int retval = -DWC_E_NOT_SUPPORTED;
  87422. +#endif
  87423. +
  87424. + desc_sts.b.bytes = 0;
  87425. +
  87426. + if (pcd->ep0_pending && DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  87427. + if (ep->dwc_ep.is_in) {
  87428. +#ifdef DEBUG_EP0
  87429. + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
  87430. +#endif
  87431. + do_setup_out_status_phase(pcd);
  87432. + } else {
  87433. +#ifdef DEBUG_EP0
  87434. + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
  87435. +#endif
  87436. +
  87437. +#ifdef DWC_UTE_CFI
  87438. + ctrlreq = &pcd->cfi->ctrl_req;
  87439. +
  87440. + if (UT_GET_TYPE(ctrlreq->bRequestType) == UT_VENDOR) {
  87441. + if (ctrlreq->bRequest > 0xB0
  87442. + && ctrlreq->bRequest < 0xBF) {
  87443. +
  87444. + /* Return if the PCD failed to handle the request */
  87445. + if ((retval =
  87446. + pcd->cfi->ops.
  87447. + ctrl_write_complete(pcd->cfi,
  87448. + pcd)) < 0) {
  87449. + CFI_INFO
  87450. + ("ERROR setting a new value in the PCD(%d)\n",
  87451. + retval);
  87452. + ep0_do_stall(pcd, retval);
  87453. + pcd->ep0_pending = 0;
  87454. + return 0;
  87455. + }
  87456. +
  87457. + /* If the gadget needs to be notified on the request */
  87458. + if (pcd->cfi->need_gadget_att == 1) {
  87459. + //retval = do_gadget_setup(pcd, &pcd->cfi->ctrl_req);
  87460. + retval =
  87461. + cfi_gadget_setup(pcd,
  87462. + &pcd->cfi->
  87463. + ctrl_req);
  87464. +
  87465. + /* Return from the function if the gadget failed to process
  87466. + * the request properly - this should never happen !!!
  87467. + */
  87468. + if (retval < 0) {
  87469. + CFI_INFO
  87470. + ("ERROR setting a new value in the gadget(%d)\n",
  87471. + retval);
  87472. + pcd->ep0_pending = 0;
  87473. + return 0;
  87474. + }
  87475. + }
  87476. +
  87477. + CFI_INFO("%s: RETVAL=%d\n", __func__,
  87478. + retval);
  87479. + /* If we hit here then the PCD and the gadget has properly
  87480. + * handled the request - so send the ZLP IN to the host.
  87481. + */
  87482. + /* @todo: MAS - decide whether we need to start the setup
  87483. + * stage based on the need_setup value of the cfi object
  87484. + */
  87485. + do_setup_in_status_phase(pcd);
  87486. + pcd->ep0_pending = 0;
  87487. + return 1;
  87488. + }
  87489. + }
  87490. +#endif
  87491. +
  87492. + do_setup_in_status_phase(pcd);
  87493. + }
  87494. + pcd->ep0_pending = 0;
  87495. + return 1;
  87496. + }
  87497. +
  87498. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  87499. + return 0;
  87500. + }
  87501. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  87502. +
  87503. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE
  87504. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  87505. + is_last = 1;
  87506. + } else if (ep->dwc_ep.is_in) {
  87507. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  87508. + if (core_if->dma_desc_enable != 0)
  87509. + desc_sts = dev_if->in_desc_addr->status;
  87510. +#ifdef DEBUG_EP0
  87511. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xfersize=%d pktcnt=%d\n",
  87512. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  87513. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  87514. +#endif
  87515. +
  87516. + if (((core_if->dma_desc_enable == 0)
  87517. + && (deptsiz.b.xfersize == 0))
  87518. + || ((core_if->dma_desc_enable != 0)
  87519. + && (desc_sts.b.bytes == 0))) {
  87520. + req->actual = ep->dwc_ep.xfer_count;
  87521. + /* Is a Zero Len Packet needed? */
  87522. + if (req->sent_zlp) {
  87523. +#ifdef DEBUG_EP0
  87524. + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
  87525. +#endif
  87526. + req->sent_zlp = 0;
  87527. + }
  87528. + do_setup_out_status_phase(pcd);
  87529. + }
  87530. + } else {
  87531. + /* ep0-OUT */
  87532. +#ifdef DEBUG_EP0
  87533. + deptsiz.d32 = DWC_READ_REG32(&out_ep_regs->doeptsiz);
  87534. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xsize=%d pktcnt=%d\n",
  87535. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  87536. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  87537. +#endif
  87538. + req->actual = ep->dwc_ep.xfer_count;
  87539. +
  87540. + /* Is a Zero Len Packet needed? */
  87541. + if (req->sent_zlp) {
  87542. +#ifdef DEBUG_EP0
  87543. + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
  87544. +#endif
  87545. + req->sent_zlp = 0;
  87546. + }
  87547. + /* For older cores do setup in status phase in Slave/BDMA modes,
  87548. + * starting from 3.00 do that only in slave, and for DMA modes
  87549. + * just re-enable ep 0 OUT here*/
  87550. + if (core_if->dma_enable == 0
  87551. + || (core_if->dma_desc_enable == 0
  87552. + && core_if->snpsid <= OTG_CORE_REV_2_94a)) {
  87553. + do_setup_in_status_phase(pcd);
  87554. + } else if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  87555. + DWC_DEBUGPL(DBG_PCDV,
  87556. + "Enable out ep before in status phase\n");
  87557. + ep0_out_start(core_if, pcd);
  87558. + }
  87559. + }
  87560. +
  87561. + /* Complete the request */
  87562. + if (is_last) {
  87563. + dwc_otg_request_done(ep, req, 0);
  87564. + ep->dwc_ep.start_xfer_buff = 0;
  87565. + ep->dwc_ep.xfer_buff = 0;
  87566. + ep->dwc_ep.xfer_len = 0;
  87567. + return 1;
  87568. + }
  87569. + return 0;
  87570. +}
  87571. +
  87572. +#ifdef DWC_UTE_CFI
  87573. +/**
  87574. + * This function calculates traverses all the CFI DMA descriptors and
  87575. + * and accumulates the bytes that are left to be transfered.
  87576. + *
  87577. + * @return The total bytes left to transfered, or a negative value as failure
  87578. + */
  87579. +static inline int cfi_calc_desc_residue(dwc_otg_pcd_ep_t * ep)
  87580. +{
  87581. + int32_t ret = 0;
  87582. + int i;
  87583. + struct dwc_otg_dma_desc *ddesc = NULL;
  87584. + struct cfi_ep *cfiep;
  87585. +
  87586. + /* See if the pcd_ep has its respective cfi_ep mapped */
  87587. + cfiep = get_cfi_ep_by_pcd_ep(ep->pcd->cfi, ep);
  87588. + if (!cfiep) {
  87589. + CFI_INFO("%s: Failed to find ep\n", __func__);
  87590. + return -1;
  87591. + }
  87592. +
  87593. + ddesc = ep->dwc_ep.descs;
  87594. +
  87595. + for (i = 0; (i < cfiep->desc_count) && (i < MAX_DMA_DESCS_PER_EP); i++) {
  87596. +
  87597. +#if defined(PRINT_CFI_DMA_DESCS)
  87598. + print_desc(ddesc, ep->ep.name, i);
  87599. +#endif
  87600. + ret += ddesc->status.b.bytes;
  87601. + ddesc++;
  87602. + }
  87603. +
  87604. + if (ret)
  87605. + CFI_INFO("!!!!!!!!!! WARNING (%s) - residue=%d\n", __func__,
  87606. + ret);
  87607. +
  87608. + return ret;
  87609. +}
  87610. +#endif
  87611. +
  87612. +/**
  87613. + * This function completes the request for the EP. If there are
  87614. + * additional requests for the EP in the queue they will be started.
  87615. + */
  87616. +static void complete_ep(dwc_otg_pcd_ep_t * ep)
  87617. +{
  87618. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  87619. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  87620. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  87621. + dev_if->in_ep_regs[ep->dwc_ep.num];
  87622. + deptsiz_data_t deptsiz;
  87623. + dev_dma_desc_sts_t desc_sts;
  87624. + dwc_otg_pcd_request_t *req = 0;
  87625. + dwc_otg_dev_dma_desc_t *dma_desc;
  87626. + uint32_t byte_count = 0;
  87627. + int is_last = 0;
  87628. + int i;
  87629. +
  87630. + DWC_DEBUGPL(DBG_PCDV, "%s() %d-%s\n", __func__, ep->dwc_ep.num,
  87631. + (ep->dwc_ep.is_in ? "IN" : "OUT"));
  87632. +
  87633. + /* Get any pending requests */
  87634. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  87635. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  87636. + if (!req) {
  87637. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  87638. + return;
  87639. + }
  87640. + } else {
  87641. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  87642. + return;
  87643. + }
  87644. +
  87645. + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
  87646. +
  87647. + if (ep->dwc_ep.is_in) {
  87648. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  87649. +
  87650. + if (core_if->dma_enable) {
  87651. + if (core_if->dma_desc_enable == 0) {
  87652. + if (deptsiz.b.xfersize == 0
  87653. + && deptsiz.b.pktcnt == 0) {
  87654. + byte_count =
  87655. + ep->dwc_ep.xfer_len -
  87656. + ep->dwc_ep.xfer_count;
  87657. +
  87658. + ep->dwc_ep.xfer_buff += byte_count;
  87659. + ep->dwc_ep.dma_addr += byte_count;
  87660. + ep->dwc_ep.xfer_count += byte_count;
  87661. +
  87662. + DWC_DEBUGPL(DBG_PCDV,
  87663. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  87664. + ep->dwc_ep.num,
  87665. + (ep->dwc_ep.
  87666. + is_in ? "IN" : "OUT"),
  87667. + ep->dwc_ep.xfer_len,
  87668. + deptsiz.b.xfersize,
  87669. + deptsiz.b.pktcnt);
  87670. +
  87671. + if (ep->dwc_ep.xfer_len <
  87672. + ep->dwc_ep.total_len) {
  87673. + dwc_otg_ep_start_transfer
  87674. + (core_if, &ep->dwc_ep);
  87675. + } else if (ep->dwc_ep.sent_zlp) {
  87676. + /*
  87677. + * This fragment of code should initiate 0
  87678. + * length transfer in case if it is queued
  87679. + * a transfer with size divisible to EPs max
  87680. + * packet size and with usb_request zero field
  87681. + * is set, which means that after data is transfered,
  87682. + * it is also should be transfered
  87683. + * a 0 length packet at the end. For Slave and
  87684. + * Buffer DMA modes in this case SW has
  87685. + * to initiate 2 transfers one with transfer size,
  87686. + * and the second with 0 size. For Descriptor
  87687. + * DMA mode SW is able to initiate a transfer,
  87688. + * which will handle all the packets including
  87689. + * the last 0 length.
  87690. + */
  87691. + ep->dwc_ep.sent_zlp = 0;
  87692. + dwc_otg_ep_start_zl_transfer
  87693. + (core_if, &ep->dwc_ep);
  87694. + } else {
  87695. + is_last = 1;
  87696. + }
  87697. + } else {
  87698. + if (ep->dwc_ep.type ==
  87699. + DWC_OTG_EP_TYPE_ISOC) {
  87700. + req->actual = 0;
  87701. + dwc_otg_request_done(ep, req, 0);
  87702. +
  87703. + ep->dwc_ep.start_xfer_buff = 0;
  87704. + ep->dwc_ep.xfer_buff = 0;
  87705. + ep->dwc_ep.xfer_len = 0;
  87706. +
  87707. + /* If there is a request in the queue start it. */
  87708. + start_next_request(ep);
  87709. + } else
  87710. + DWC_WARN
  87711. + ("Incomplete transfer (%d - %s [siz=%d pkt=%d])\n",
  87712. + ep->dwc_ep.num,
  87713. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  87714. + deptsiz.b.xfersize,
  87715. + deptsiz.b.pktcnt);
  87716. + }
  87717. + } else {
  87718. + dma_desc = ep->dwc_ep.desc_addr;
  87719. + byte_count = 0;
  87720. + ep->dwc_ep.sent_zlp = 0;
  87721. +
  87722. +#ifdef DWC_UTE_CFI
  87723. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  87724. + ep->dwc_ep.buff_mode);
  87725. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  87726. + int residue;
  87727. +
  87728. + residue = cfi_calc_desc_residue(ep);
  87729. + if (residue < 0)
  87730. + return;
  87731. +
  87732. + byte_count = residue;
  87733. + } else {
  87734. +#endif
  87735. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  87736. + ++i) {
  87737. + desc_sts = dma_desc->status;
  87738. + byte_count += desc_sts.b.bytes;
  87739. + dma_desc++;
  87740. + }
  87741. +#ifdef DWC_UTE_CFI
  87742. + }
  87743. +#endif
  87744. + if (byte_count == 0) {
  87745. + ep->dwc_ep.xfer_count =
  87746. + ep->dwc_ep.total_len;
  87747. + is_last = 1;
  87748. + } else {
  87749. + DWC_WARN("Incomplete transfer\n");
  87750. + }
  87751. + }
  87752. + } else {
  87753. + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
  87754. + DWC_DEBUGPL(DBG_PCDV,
  87755. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  87756. + ep->dwc_ep.num,
  87757. + ep->dwc_ep.is_in ? "IN" : "OUT",
  87758. + ep->dwc_ep.xfer_len,
  87759. + deptsiz.b.xfersize,
  87760. + deptsiz.b.pktcnt);
  87761. +
  87762. + /* Check if the whole transfer was completed,
  87763. + * if no, setup transfer for next portion of data
  87764. + */
  87765. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  87766. + dwc_otg_ep_start_transfer(core_if,
  87767. + &ep->dwc_ep);
  87768. + } else if (ep->dwc_ep.sent_zlp) {
  87769. + /*
  87770. + * This fragment of code should initiate 0
  87771. + * length trasfer in case if it is queued
  87772. + * a trasfer with size divisible to EPs max
  87773. + * packet size and with usb_request zero field
  87774. + * is set, which means that after data is transfered,
  87775. + * it is also should be transfered
  87776. + * a 0 length packet at the end. For Slave and
  87777. + * Buffer DMA modes in this case SW has
  87778. + * to initiate 2 transfers one with transfer size,
  87779. + * and the second with 0 size. For Desriptor
  87780. + * DMA mode SW is able to initiate a transfer,
  87781. + * which will handle all the packets including
  87782. + * the last 0 legth.
  87783. + */
  87784. + ep->dwc_ep.sent_zlp = 0;
  87785. + dwc_otg_ep_start_zl_transfer(core_if,
  87786. + &ep->dwc_ep);
  87787. + } else {
  87788. + is_last = 1;
  87789. + }
  87790. + } else {
  87791. + DWC_WARN
  87792. + ("Incomplete transfer (%d-%s [siz=%d pkt=%d])\n",
  87793. + ep->dwc_ep.num,
  87794. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  87795. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  87796. + }
  87797. + }
  87798. + } else {
  87799. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  87800. + dev_if->out_ep_regs[ep->dwc_ep.num];
  87801. + desc_sts.d32 = 0;
  87802. + if (core_if->dma_enable) {
  87803. + if (core_if->dma_desc_enable) {
  87804. + dma_desc = ep->dwc_ep.desc_addr;
  87805. + byte_count = 0;
  87806. + ep->dwc_ep.sent_zlp = 0;
  87807. +
  87808. +#ifdef DWC_UTE_CFI
  87809. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  87810. + ep->dwc_ep.buff_mode);
  87811. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  87812. + int residue;
  87813. + residue = cfi_calc_desc_residue(ep);
  87814. + if (residue < 0)
  87815. + return;
  87816. + byte_count = residue;
  87817. + } else {
  87818. +#endif
  87819. +
  87820. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  87821. + ++i) {
  87822. + desc_sts = dma_desc->status;
  87823. + byte_count += desc_sts.b.bytes;
  87824. + dma_desc++;
  87825. + }
  87826. +
  87827. +#ifdef DWC_UTE_CFI
  87828. + }
  87829. +#endif
  87830. + /* Checking for interrupt Out transfers with not
  87831. + * dword aligned mps sizes
  87832. + */
  87833. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_INTR &&
  87834. + (ep->dwc_ep.maxpacket%4)) {
  87835. + ep->dwc_ep.xfer_count =
  87836. + ep->dwc_ep.total_len - byte_count;
  87837. + if ((ep->dwc_ep.xfer_len %
  87838. + ep->dwc_ep.maxpacket)
  87839. + && (ep->dwc_ep.xfer_len /
  87840. + ep->dwc_ep.maxpacket <
  87841. + MAX_DMA_DESC_CNT))
  87842. + ep->dwc_ep.xfer_len -=
  87843. + (ep->dwc_ep.desc_cnt -
  87844. + 1) * ep->dwc_ep.maxpacket +
  87845. + ep->dwc_ep.xfer_len %
  87846. + ep->dwc_ep.maxpacket;
  87847. + else
  87848. + ep->dwc_ep.xfer_len -=
  87849. + ep->dwc_ep.desc_cnt *
  87850. + ep->dwc_ep.maxpacket;
  87851. + if (ep->dwc_ep.xfer_len > 0) {
  87852. + dwc_otg_ep_start_transfer
  87853. + (core_if, &ep->dwc_ep);
  87854. + } else {
  87855. + is_last = 1;
  87856. + }
  87857. + } else {
  87858. + ep->dwc_ep.xfer_count =
  87859. + ep->dwc_ep.total_len - byte_count +
  87860. + ((4 -
  87861. + (ep->dwc_ep.
  87862. + total_len & 0x3)) & 0x3);
  87863. + is_last = 1;
  87864. + }
  87865. + } else {
  87866. + deptsiz.d32 = 0;
  87867. + deptsiz.d32 =
  87868. + DWC_READ_REG32(&out_ep_regs->doeptsiz);
  87869. +
  87870. + byte_count = (ep->dwc_ep.xfer_len -
  87871. + ep->dwc_ep.xfer_count -
  87872. + deptsiz.b.xfersize);
  87873. + ep->dwc_ep.xfer_buff += byte_count;
  87874. + ep->dwc_ep.dma_addr += byte_count;
  87875. + ep->dwc_ep.xfer_count += byte_count;
  87876. +
  87877. + /* Check if the whole transfer was completed,
  87878. + * if no, setup transfer for next portion of data
  87879. + */
  87880. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  87881. + dwc_otg_ep_start_transfer(core_if,
  87882. + &ep->dwc_ep);
  87883. + } else if (ep->dwc_ep.sent_zlp) {
  87884. + /*
  87885. + * This fragment of code should initiate 0
  87886. + * length trasfer in case if it is queued
  87887. + * a trasfer with size divisible to EPs max
  87888. + * packet size and with usb_request zero field
  87889. + * is set, which means that after data is transfered,
  87890. + * it is also should be transfered
  87891. + * a 0 length packet at the end. For Slave and
  87892. + * Buffer DMA modes in this case SW has
  87893. + * to initiate 2 transfers one with transfer size,
  87894. + * and the second with 0 size. For Desriptor
  87895. + * DMA mode SW is able to initiate a transfer,
  87896. + * which will handle all the packets including
  87897. + * the last 0 legth.
  87898. + */
  87899. + ep->dwc_ep.sent_zlp = 0;
  87900. + dwc_otg_ep_start_zl_transfer(core_if,
  87901. + &ep->dwc_ep);
  87902. + } else {
  87903. + is_last = 1;
  87904. + }
  87905. + }
  87906. + } else {
  87907. + /* Check if the whole transfer was completed,
  87908. + * if no, setup transfer for next portion of data
  87909. + */
  87910. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  87911. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  87912. + } else if (ep->dwc_ep.sent_zlp) {
  87913. + /*
  87914. + * This fragment of code should initiate 0
  87915. + * length transfer in case if it is queued
  87916. + * a transfer with size divisible to EPs max
  87917. + * packet size and with usb_request zero field
  87918. + * is set, which means that after data is transfered,
  87919. + * it is also should be transfered
  87920. + * a 0 length packet at the end. For Slave and
  87921. + * Buffer DMA modes in this case SW has
  87922. + * to initiate 2 transfers one with transfer size,
  87923. + * and the second with 0 size. For Descriptor
  87924. + * DMA mode SW is able to initiate a transfer,
  87925. + * which will handle all the packets including
  87926. + * the last 0 length.
  87927. + */
  87928. + ep->dwc_ep.sent_zlp = 0;
  87929. + dwc_otg_ep_start_zl_transfer(core_if,
  87930. + &ep->dwc_ep);
  87931. + } else {
  87932. + is_last = 1;
  87933. + }
  87934. + }
  87935. +
  87936. + DWC_DEBUGPL(DBG_PCDV,
  87937. + "addr %p, %d-%s len=%d cnt=%d xsize=%d pktcnt=%d\n",
  87938. + &out_ep_regs->doeptsiz, ep->dwc_ep.num,
  87939. + ep->dwc_ep.is_in ? "IN" : "OUT",
  87940. + ep->dwc_ep.xfer_len, ep->dwc_ep.xfer_count,
  87941. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  87942. + }
  87943. +
  87944. + /* Complete the request */
  87945. + if (is_last) {
  87946. +#ifdef DWC_UTE_CFI
  87947. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  87948. + req->actual = ep->dwc_ep.cfi_req_len - byte_count;
  87949. + } else {
  87950. +#endif
  87951. + req->actual = ep->dwc_ep.xfer_count;
  87952. +#ifdef DWC_UTE_CFI
  87953. + }
  87954. +#endif
  87955. + if (req->dw_align_buf) {
  87956. + if (!ep->dwc_ep.is_in) {
  87957. + dwc_memcpy(req->buf, req->dw_align_buf, req->length);
  87958. + }
  87959. + DWC_DMA_FREE(req->length, req->dw_align_buf,
  87960. + req->dw_align_buf_dma);
  87961. + }
  87962. +
  87963. + dwc_otg_request_done(ep, req, 0);
  87964. +
  87965. + ep->dwc_ep.start_xfer_buff = 0;
  87966. + ep->dwc_ep.xfer_buff = 0;
  87967. + ep->dwc_ep.xfer_len = 0;
  87968. +
  87969. + /* If there is a request in the queue start it. */
  87970. + start_next_request(ep);
  87971. + }
  87972. +}
  87973. +
  87974. +#ifdef DWC_EN_ISOC
  87975. +
  87976. +/**
  87977. + * This function BNA interrupt for Isochronous EPs
  87978. + *
  87979. + */
  87980. +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t * ep)
  87981. +{
  87982. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  87983. + volatile uint32_t *addr;
  87984. + depctl_data_t depctl = {.d32 = 0 };
  87985. + dwc_otg_pcd_t *pcd = ep->pcd;
  87986. + dwc_otg_dev_dma_desc_t *dma_desc;
  87987. + int i;
  87988. +
  87989. + dma_desc =
  87990. + dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
  87991. +
  87992. + if (dwc_ep->is_in) {
  87993. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  87994. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  87995. + sts.d32 = dma_desc->status.d32;
  87996. + sts.b_iso_in.bs = BS_HOST_READY;
  87997. + dma_desc->status.d32 = sts.d32;
  87998. + }
  87999. + } else {
  88000. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  88001. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  88002. + sts.d32 = dma_desc->status.d32;
  88003. + sts.b_iso_out.bs = BS_HOST_READY;
  88004. + dma_desc->status.d32 = sts.d32;
  88005. + }
  88006. + }
  88007. +
  88008. + if (dwc_ep->is_in == 0) {
  88009. + addr =
  88010. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->
  88011. + num]->doepctl;
  88012. + } else {
  88013. + addr =
  88014. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  88015. + }
  88016. + depctl.b.epena = 1;
  88017. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  88018. +}
  88019. +
  88020. +/**
  88021. + * This function sets latest iso packet information(non-PTI mode)
  88022. + *
  88023. + * @param core_if Programming view of DWC_otg controller.
  88024. + * @param ep The EP to start the transfer on.
  88025. + *
  88026. + */
  88027. +void set_current_pkt_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  88028. +{
  88029. + deptsiz_data_t deptsiz = {.d32 = 0 };
  88030. + dma_addr_t dma_addr;
  88031. + uint32_t offset;
  88032. +
  88033. + if (ep->proc_buf_num)
  88034. + dma_addr = ep->dma_addr1;
  88035. + else
  88036. + dma_addr = ep->dma_addr0;
  88037. +
  88038. + if (ep->is_in) {
  88039. + deptsiz.d32 =
  88040. + DWC_READ_REG32(&core_if->dev_if->
  88041. + in_ep_regs[ep->num]->dieptsiz);
  88042. + offset = ep->data_per_frame;
  88043. + } else {
  88044. + deptsiz.d32 =
  88045. + DWC_READ_REG32(&core_if->dev_if->
  88046. + out_ep_regs[ep->num]->doeptsiz);
  88047. + offset =
  88048. + ep->data_per_frame +
  88049. + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
  88050. + }
  88051. +
  88052. + if (!deptsiz.b.xfersize) {
  88053. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  88054. + ep->pkt_info[ep->cur_pkt].offset =
  88055. + ep->cur_pkt_dma_addr - dma_addr;
  88056. + ep->pkt_info[ep->cur_pkt].status = 0;
  88057. + } else {
  88058. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  88059. + ep->pkt_info[ep->cur_pkt].offset =
  88060. + ep->cur_pkt_dma_addr - dma_addr;
  88061. + ep->pkt_info[ep->cur_pkt].status = -DWC_E_NO_DATA;
  88062. + }
  88063. + ep->cur_pkt_addr += offset;
  88064. + ep->cur_pkt_dma_addr += offset;
  88065. + ep->cur_pkt++;
  88066. +}
  88067. +
  88068. +/**
  88069. + * This function sets latest iso packet information(DDMA mode)
  88070. + *
  88071. + * @param core_if Programming view of DWC_otg controller.
  88072. + * @param dwc_ep The EP to start the transfer on.
  88073. + *
  88074. + */
  88075. +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t * core_if,
  88076. + dwc_ep_t * dwc_ep)
  88077. +{
  88078. + dwc_otg_dev_dma_desc_t *dma_desc;
  88079. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  88080. + iso_pkt_info_t *iso_packet;
  88081. + uint32_t data_per_desc;
  88082. + uint32_t offset;
  88083. + int i, j;
  88084. +
  88085. + iso_packet = dwc_ep->pkt_info;
  88086. +
  88087. + /** Reinit closed DMA Descriptors*/
  88088. + /** ISO OUT EP */
  88089. + if (dwc_ep->is_in == 0) {
  88090. + dma_desc =
  88091. + dwc_ep->iso_desc_addr +
  88092. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  88093. + offset = 0;
  88094. +
  88095. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  88096. + i += dwc_ep->pkt_per_frm) {
  88097. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  88098. + data_per_desc =
  88099. + ((j + 1) * dwc_ep->maxpacket >
  88100. + dwc_ep->
  88101. + data_per_frame) ? dwc_ep->data_per_frame -
  88102. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88103. + data_per_desc +=
  88104. + (data_per_desc % 4) ? (4 -
  88105. + data_per_desc %
  88106. + 4) : 0;
  88107. +
  88108. + sts.d32 = dma_desc->status.d32;
  88109. +
  88110. + /* Write status in iso_packet_decsriptor */
  88111. + iso_packet->status =
  88112. + sts.b_iso_out.rxsts +
  88113. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  88114. + if (iso_packet->status) {
  88115. + iso_packet->status = -DWC_E_NO_DATA;
  88116. + }
  88117. +
  88118. + /* Received data length */
  88119. + if (!sts.b_iso_out.rxbytes) {
  88120. + iso_packet->length =
  88121. + data_per_desc -
  88122. + sts.b_iso_out.rxbytes;
  88123. + } else {
  88124. + iso_packet->length =
  88125. + data_per_desc -
  88126. + sts.b_iso_out.rxbytes + (4 -
  88127. + dwc_ep->data_per_frame
  88128. + % 4);
  88129. + }
  88130. +
  88131. + iso_packet->offset = offset;
  88132. +
  88133. + offset += data_per_desc;
  88134. + dma_desc++;
  88135. + iso_packet++;
  88136. + }
  88137. + }
  88138. +
  88139. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  88140. + data_per_desc =
  88141. + ((j + 1) * dwc_ep->maxpacket >
  88142. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  88143. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88144. + data_per_desc +=
  88145. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  88146. +
  88147. + sts.d32 = dma_desc->status.d32;
  88148. +
  88149. + /* Write status in iso_packet_decsriptor */
  88150. + iso_packet->status =
  88151. + sts.b_iso_out.rxsts +
  88152. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  88153. + if (iso_packet->status) {
  88154. + iso_packet->status = -DWC_E_NO_DATA;
  88155. + }
  88156. +
  88157. + /* Received data length */
  88158. + iso_packet->length =
  88159. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  88160. +
  88161. + iso_packet->offset = offset;
  88162. +
  88163. + offset += data_per_desc;
  88164. + iso_packet++;
  88165. + dma_desc++;
  88166. + }
  88167. +
  88168. + sts.d32 = dma_desc->status.d32;
  88169. +
  88170. + /* Write status in iso_packet_decsriptor */
  88171. + iso_packet->status =
  88172. + sts.b_iso_out.rxsts + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  88173. + if (iso_packet->status) {
  88174. + iso_packet->status = -DWC_E_NO_DATA;
  88175. + }
  88176. + /* Received data length */
  88177. + if (!sts.b_iso_out.rxbytes) {
  88178. + iso_packet->length =
  88179. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  88180. + } else {
  88181. + iso_packet->length =
  88182. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
  88183. + (4 - dwc_ep->data_per_frame % 4);
  88184. + }
  88185. +
  88186. + iso_packet->offset = offset;
  88187. + } else {
  88188. +/** ISO IN EP */
  88189. +
  88190. + dma_desc =
  88191. + dwc_ep->iso_desc_addr +
  88192. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  88193. +
  88194. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  88195. + sts.d32 = dma_desc->status.d32;
  88196. +
  88197. + /* Write status in iso packet descriptor */
  88198. + iso_packet->status =
  88199. + sts.b_iso_in.txsts +
  88200. + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  88201. + if (iso_packet->status != 0) {
  88202. + iso_packet->status = -DWC_E_NO_DATA;
  88203. +
  88204. + }
  88205. + /* Bytes has been transfered */
  88206. + iso_packet->length =
  88207. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  88208. +
  88209. + dma_desc++;
  88210. + iso_packet++;
  88211. + }
  88212. +
  88213. + sts.d32 = dma_desc->status.d32;
  88214. + while (sts.b_iso_in.bs == BS_DMA_BUSY) {
  88215. + sts.d32 = dma_desc->status.d32;
  88216. + }
  88217. +
  88218. + /* Write status in iso packet descriptor ??? do be done with ERROR codes */
  88219. + iso_packet->status =
  88220. + sts.b_iso_in.txsts + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  88221. + if (iso_packet->status != 0) {
  88222. + iso_packet->status = -DWC_E_NO_DATA;
  88223. + }
  88224. +
  88225. + /* Bytes has been transfered */
  88226. + iso_packet->length =
  88227. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  88228. + }
  88229. +}
  88230. +
  88231. +/**
  88232. + * This function reinitialize DMA Descriptors for Isochronous transfer
  88233. + *
  88234. + * @param core_if Programming view of DWC_otg controller.
  88235. + * @param dwc_ep The EP to start the transfer on.
  88236. + *
  88237. + */
  88238. +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  88239. +{
  88240. + int i, j;
  88241. + dwc_otg_dev_dma_desc_t *dma_desc;
  88242. + dma_addr_t dma_ad;
  88243. + volatile uint32_t *addr;
  88244. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  88245. + uint32_t data_per_desc;
  88246. +
  88247. + if (dwc_ep->is_in == 0) {
  88248. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  88249. + } else {
  88250. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  88251. + }
  88252. +
  88253. + if (dwc_ep->proc_buf_num == 0) {
  88254. + /** Buffer 0 descriptors setup */
  88255. + dma_ad = dwc_ep->dma_addr0;
  88256. + } else {
  88257. + /** Buffer 1 descriptors setup */
  88258. + dma_ad = dwc_ep->dma_addr1;
  88259. + }
  88260. +
  88261. + /** Reinit closed DMA Descriptors*/
  88262. + /** ISO OUT EP */
  88263. + if (dwc_ep->is_in == 0) {
  88264. + dma_desc =
  88265. + dwc_ep->iso_desc_addr +
  88266. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  88267. +
  88268. + sts.b_iso_out.bs = BS_HOST_READY;
  88269. + sts.b_iso_out.rxsts = 0;
  88270. + sts.b_iso_out.l = 0;
  88271. + sts.b_iso_out.sp = 0;
  88272. + sts.b_iso_out.ioc = 0;
  88273. + sts.b_iso_out.pid = 0;
  88274. + sts.b_iso_out.framenum = 0;
  88275. +
  88276. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  88277. + i += dwc_ep->pkt_per_frm) {
  88278. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  88279. + data_per_desc =
  88280. + ((j + 1) * dwc_ep->maxpacket >
  88281. + dwc_ep->
  88282. + data_per_frame) ? dwc_ep->data_per_frame -
  88283. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88284. + data_per_desc +=
  88285. + (data_per_desc % 4) ? (4 -
  88286. + data_per_desc %
  88287. + 4) : 0;
  88288. + sts.b_iso_out.rxbytes = data_per_desc;
  88289. + dma_desc->buf = dma_ad;
  88290. + dma_desc->status.d32 = sts.d32;
  88291. +
  88292. + dma_ad += data_per_desc;
  88293. + dma_desc++;
  88294. + }
  88295. + }
  88296. +
  88297. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  88298. +
  88299. + data_per_desc =
  88300. + ((j + 1) * dwc_ep->maxpacket >
  88301. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  88302. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88303. + data_per_desc +=
  88304. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  88305. + sts.b_iso_out.rxbytes = data_per_desc;
  88306. +
  88307. + dma_desc->buf = dma_ad;
  88308. + dma_desc->status.d32 = sts.d32;
  88309. +
  88310. + dma_desc++;
  88311. + dma_ad += data_per_desc;
  88312. + }
  88313. +
  88314. + sts.b_iso_out.ioc = 1;
  88315. + sts.b_iso_out.l = dwc_ep->proc_buf_num;
  88316. +
  88317. + data_per_desc =
  88318. + ((j + 1) * dwc_ep->maxpacket >
  88319. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  88320. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88321. + data_per_desc +=
  88322. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  88323. + sts.b_iso_out.rxbytes = data_per_desc;
  88324. +
  88325. + dma_desc->buf = dma_ad;
  88326. + dma_desc->status.d32 = sts.d32;
  88327. + } else {
  88328. +/** ISO IN EP */
  88329. +
  88330. + dma_desc =
  88331. + dwc_ep->iso_desc_addr +
  88332. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  88333. +
  88334. + sts.b_iso_in.bs = BS_HOST_READY;
  88335. + sts.b_iso_in.txsts = 0;
  88336. + sts.b_iso_in.sp = 0;
  88337. + sts.b_iso_in.ioc = 0;
  88338. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  88339. + sts.b_iso_in.framenum = dwc_ep->next_frame;
  88340. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  88341. + sts.b_iso_in.l = 0;
  88342. +
  88343. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  88344. + dma_desc->buf = dma_ad;
  88345. + dma_desc->status.d32 = sts.d32;
  88346. +
  88347. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  88348. + dma_ad += dwc_ep->data_per_frame;
  88349. + dma_desc++;
  88350. + }
  88351. +
  88352. + sts.b_iso_in.ioc = 1;
  88353. + sts.b_iso_in.l = dwc_ep->proc_buf_num;
  88354. +
  88355. + dma_desc->buf = dma_ad;
  88356. + dma_desc->status.d32 = sts.d32;
  88357. +
  88358. + dwc_ep->next_frame =
  88359. + sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
  88360. + }
  88361. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  88362. +}
  88363. +
  88364. +/**
  88365. + * This function is to handle Iso EP transfer complete interrupt
  88366. + * in case Iso out packet was dropped
  88367. + *
  88368. + * @param core_if Programming view of DWC_otg controller.
  88369. + * @param dwc_ep The EP for wihich transfer complete was asserted
  88370. + *
  88371. + */
  88372. +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t * core_if,
  88373. + dwc_ep_t * dwc_ep)
  88374. +{
  88375. + uint32_t dma_addr;
  88376. + uint32_t drp_pkt;
  88377. + uint32_t drp_pkt_cnt;
  88378. + deptsiz_data_t deptsiz = {.d32 = 0 };
  88379. + depctl_data_t depctl = {.d32 = 0 };
  88380. + int i;
  88381. +
  88382. + deptsiz.d32 =
  88383. + DWC_READ_REG32(&core_if->dev_if->
  88384. + out_ep_regs[dwc_ep->num]->doeptsiz);
  88385. +
  88386. + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
  88387. + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
  88388. +
  88389. + /* Setting dropped packets status */
  88390. + for (i = 0; i < drp_pkt_cnt; ++i) {
  88391. + dwc_ep->pkt_info[drp_pkt].status = -DWC_E_NO_DATA;
  88392. + drp_pkt++;
  88393. + deptsiz.b.pktcnt--;
  88394. + }
  88395. +
  88396. + if (deptsiz.b.pktcnt > 0) {
  88397. + deptsiz.b.xfersize =
  88398. + dwc_ep->xfer_len - (dwc_ep->pkt_cnt -
  88399. + deptsiz.b.pktcnt) * dwc_ep->maxpacket;
  88400. + } else {
  88401. + deptsiz.b.xfersize = 0;
  88402. + deptsiz.b.pktcnt = 0;
  88403. + }
  88404. +
  88405. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz,
  88406. + deptsiz.d32);
  88407. +
  88408. + if (deptsiz.b.pktcnt > 0) {
  88409. + if (dwc_ep->proc_buf_num) {
  88410. + dma_addr =
  88411. + dwc_ep->dma_addr1 + dwc_ep->xfer_len -
  88412. + deptsiz.b.xfersize;
  88413. + } else {
  88414. + dma_addr =
  88415. + dwc_ep->dma_addr0 + dwc_ep->xfer_len -
  88416. + deptsiz.b.xfersize;;
  88417. + }
  88418. +
  88419. + DWC_WRITE_REG32(&core_if->dev_if->
  88420. + out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
  88421. +
  88422. + /** Re-enable endpoint, clear nak */
  88423. + depctl.d32 = 0;
  88424. + depctl.b.epena = 1;
  88425. + depctl.b.cnak = 1;
  88426. +
  88427. + DWC_MODIFY_REG32(&core_if->dev_if->
  88428. + out_ep_regs[dwc_ep->num]->doepctl, depctl.d32,
  88429. + depctl.d32);
  88430. + return 0;
  88431. + } else {
  88432. + return 1;
  88433. + }
  88434. +}
  88435. +
  88436. +/**
  88437. + * This function sets iso packets information(PTI mode)
  88438. + *
  88439. + * @param core_if Programming view of DWC_otg controller.
  88440. + * @param ep The EP to start the transfer on.
  88441. + *
  88442. + */
  88443. +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  88444. +{
  88445. + int i, j;
  88446. + dma_addr_t dma_ad;
  88447. + iso_pkt_info_t *packet_info = ep->pkt_info;
  88448. + uint32_t offset;
  88449. + uint32_t frame_data;
  88450. + deptsiz_data_t deptsiz;
  88451. +
  88452. + if (ep->proc_buf_num == 0) {
  88453. + /** Buffer 0 descriptors setup */
  88454. + dma_ad = ep->dma_addr0;
  88455. + } else {
  88456. + /** Buffer 1 descriptors setup */
  88457. + dma_ad = ep->dma_addr1;
  88458. + }
  88459. +
  88460. + if (ep->is_in) {
  88461. + deptsiz.d32 =
  88462. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  88463. + dieptsiz);
  88464. + } else {
  88465. + deptsiz.d32 =
  88466. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  88467. + doeptsiz);
  88468. + }
  88469. +
  88470. + if (!deptsiz.b.xfersize) {
  88471. + offset = 0;
  88472. + for (i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm) {
  88473. + frame_data = ep->data_per_frame;
  88474. + for (j = 0; j < ep->pkt_per_frm; ++j) {
  88475. +
  88476. + /* Packet status - is not set as initially
  88477. + * it is set to 0 and if packet was sent
  88478. + successfully, status field will remain 0*/
  88479. +
  88480. + /* Bytes has been transfered */
  88481. + packet_info->length =
  88482. + (ep->maxpacket <
  88483. + frame_data) ? ep->maxpacket : frame_data;
  88484. +
  88485. + /* Received packet offset */
  88486. + packet_info->offset = offset;
  88487. + offset += packet_info->length;
  88488. + frame_data -= packet_info->length;
  88489. +
  88490. + packet_info++;
  88491. + }
  88492. + }
  88493. + return 1;
  88494. + } else {
  88495. + /* This is a workaround for in case of Transfer Complete with
  88496. + * PktDrpSts interrupts merging - in this case Transfer complete
  88497. + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
  88498. + * set and with DOEPTSIZ register non zero. Investigations showed,
  88499. + * that this happens when Out packet is dropped, but because of
  88500. + * interrupts merging during first interrupt handling PktDrpSts
  88501. + * bit is cleared and for next merged interrupts it is not reset.
  88502. + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
  88503. + */
  88504. + if (ep->is_in) {
  88505. + return 1;
  88506. + } else {
  88507. + return handle_iso_out_pkt_dropped(core_if, ep);
  88508. + }
  88509. + }
  88510. +}
  88511. +
  88512. +/**
  88513. + * This function is to handle Iso EP transfer complete interrupt
  88514. + *
  88515. + * @param pcd The PCD
  88516. + * @param ep The EP for which transfer complete was asserted
  88517. + *
  88518. + */
  88519. +static void complete_iso_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  88520. +{
  88521. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  88522. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  88523. + uint8_t is_last = 0;
  88524. +
  88525. + if (ep->dwc_ep.next_frame == 0xffffffff) {
  88526. + DWC_WARN("Next frame is not set!\n");
  88527. + return;
  88528. + }
  88529. +
  88530. + if (core_if->dma_enable) {
  88531. + if (core_if->dma_desc_enable) {
  88532. + set_ddma_iso_pkts_info(core_if, dwc_ep);
  88533. + reinit_ddma_iso_xfer(core_if, dwc_ep);
  88534. + is_last = 1;
  88535. + } else {
  88536. + if (core_if->pti_enh_enable) {
  88537. + if (set_iso_pkts_info(core_if, dwc_ep)) {
  88538. + dwc_ep->proc_buf_num =
  88539. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  88540. + dwc_otg_iso_ep_start_buf_transfer
  88541. + (core_if, dwc_ep);
  88542. + is_last = 1;
  88543. + }
  88544. + } else {
  88545. + set_current_pkt_info(core_if, dwc_ep);
  88546. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  88547. + is_last = 1;
  88548. + dwc_ep->cur_pkt = 0;
  88549. + dwc_ep->proc_buf_num =
  88550. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  88551. + if (dwc_ep->proc_buf_num) {
  88552. + dwc_ep->cur_pkt_addr =
  88553. + dwc_ep->xfer_buff1;
  88554. + dwc_ep->cur_pkt_dma_addr =
  88555. + dwc_ep->dma_addr1;
  88556. + } else {
  88557. + dwc_ep->cur_pkt_addr =
  88558. + dwc_ep->xfer_buff0;
  88559. + dwc_ep->cur_pkt_dma_addr =
  88560. + dwc_ep->dma_addr0;
  88561. + }
  88562. +
  88563. + }
  88564. + dwc_otg_iso_ep_start_frm_transfer(core_if,
  88565. + dwc_ep);
  88566. + }
  88567. + }
  88568. + } else {
  88569. + set_current_pkt_info(core_if, dwc_ep);
  88570. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  88571. + is_last = 1;
  88572. + dwc_ep->cur_pkt = 0;
  88573. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  88574. + if (dwc_ep->proc_buf_num) {
  88575. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
  88576. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
  88577. + } else {
  88578. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
  88579. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
  88580. + }
  88581. +
  88582. + }
  88583. + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
  88584. + }
  88585. + if (is_last)
  88586. + dwc_otg_iso_buffer_done(pcd, ep, ep->iso_req_handle);
  88587. +}
  88588. +#endif /* DWC_EN_ISOC */
  88589. +
  88590. +/**
  88591. + * This function handle BNA interrupt for Non Isochronous EPs
  88592. + *
  88593. + */
  88594. +static void dwc_otg_pcd_handle_noniso_bna(dwc_otg_pcd_ep_t * ep)
  88595. +{
  88596. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  88597. + volatile uint32_t *addr;
  88598. + depctl_data_t depctl = {.d32 = 0 };
  88599. + dwc_otg_pcd_t *pcd = ep->pcd;
  88600. + dwc_otg_dev_dma_desc_t *dma_desc;
  88601. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  88602. + dwc_otg_core_if_t *core_if = ep->pcd->core_if;
  88603. + int i, start;
  88604. +
  88605. + if (!dwc_ep->desc_cnt)
  88606. + DWC_WARN("Ep%d %s Descriptor count = %d \n", dwc_ep->num,
  88607. + (dwc_ep->is_in ? "IN" : "OUT"), dwc_ep->desc_cnt);
  88608. +
  88609. + if (core_if->core_params->cont_on_bna && !dwc_ep->is_in
  88610. + && dwc_ep->type != DWC_OTG_EP_TYPE_CONTROL) {
  88611. + uint32_t doepdma;
  88612. + dwc_otg_dev_out_ep_regs_t *out_regs =
  88613. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  88614. + doepdma = DWC_READ_REG32(&(out_regs->doepdma));
  88615. + start = (doepdma - dwc_ep->dma_desc_addr)/sizeof(dwc_otg_dev_dma_desc_t);
  88616. + dma_desc = &(dwc_ep->desc_addr[start]);
  88617. + } else {
  88618. + start = 0;
  88619. + dma_desc = dwc_ep->desc_addr;
  88620. + }
  88621. +
  88622. +
  88623. + for (i = start; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  88624. + sts.d32 = dma_desc->status.d32;
  88625. + sts.b.bs = BS_HOST_READY;
  88626. + dma_desc->status.d32 = sts.d32;
  88627. + }
  88628. +
  88629. + if (dwc_ep->is_in == 0) {
  88630. + addr =
  88631. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->
  88632. + doepctl;
  88633. + } else {
  88634. + addr =
  88635. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  88636. + }
  88637. + depctl.b.epena = 1;
  88638. + depctl.b.cnak = 1;
  88639. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  88640. +}
  88641. +
  88642. +/**
  88643. + * This function handles EP0 Control transfers.
  88644. + *
  88645. + * The state of the control transfers are tracked in
  88646. + * <code>ep0state</code>.
  88647. + */
  88648. +static void handle_ep0(dwc_otg_pcd_t * pcd)
  88649. +{
  88650. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  88651. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  88652. + dev_dma_desc_sts_t desc_sts;
  88653. + deptsiz0_data_t deptsiz;
  88654. + uint32_t byte_count;
  88655. +
  88656. +#ifdef DEBUG_EP0
  88657. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  88658. + print_ep0_state(pcd);
  88659. +#endif
  88660. +
  88661. +// DWC_PRINTF("HANDLE EP0\n");
  88662. +
  88663. + switch (pcd->ep0state) {
  88664. + case EP0_DISCONNECT:
  88665. + break;
  88666. +
  88667. + case EP0_IDLE:
  88668. + pcd->request_config = 0;
  88669. +
  88670. + pcd_setup(pcd);
  88671. + break;
  88672. +
  88673. + case EP0_IN_DATA_PHASE:
  88674. +#ifdef DEBUG_EP0
  88675. + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
  88676. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  88677. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  88678. +#endif
  88679. +
  88680. + if (core_if->dma_enable != 0) {
  88681. + /*
  88682. + * For EP0 we can only program 1 packet at a time so we
  88683. + * need to do the make calculations after each complete.
  88684. + * Call write_packet to make the calculations, as in
  88685. + * slave mode, and use those values to determine if we
  88686. + * can complete.
  88687. + */
  88688. + if (core_if->dma_desc_enable == 0) {
  88689. + deptsiz.d32 =
  88690. + DWC_READ_REG32(&core_if->
  88691. + dev_if->in_ep_regs[0]->
  88692. + dieptsiz);
  88693. + byte_count =
  88694. + ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
  88695. + } else {
  88696. + desc_sts =
  88697. + core_if->dev_if->in_desc_addr->status;
  88698. + byte_count =
  88699. + ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
  88700. + }
  88701. + ep0->dwc_ep.xfer_count += byte_count;
  88702. + ep0->dwc_ep.xfer_buff += byte_count;
  88703. + ep0->dwc_ep.dma_addr += byte_count;
  88704. + }
  88705. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  88706. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  88707. + &ep0->dwc_ep);
  88708. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  88709. + } else if (ep0->dwc_ep.sent_zlp) {
  88710. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  88711. + &ep0->dwc_ep);
  88712. + ep0->dwc_ep.sent_zlp = 0;
  88713. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  88714. + } else {
  88715. + ep0_complete_request(ep0);
  88716. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  88717. + }
  88718. + break;
  88719. + case EP0_OUT_DATA_PHASE:
  88720. +#ifdef DEBUG_EP0
  88721. + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
  88722. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  88723. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  88724. +#endif
  88725. + if (core_if->dma_enable != 0) {
  88726. + if (core_if->dma_desc_enable == 0) {
  88727. + deptsiz.d32 =
  88728. + DWC_READ_REG32(&core_if->
  88729. + dev_if->out_ep_regs[0]->
  88730. + doeptsiz);
  88731. + byte_count =
  88732. + ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
  88733. + } else {
  88734. + desc_sts =
  88735. + core_if->dev_if->out_desc_addr->status;
  88736. + byte_count =
  88737. + ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
  88738. + }
  88739. + ep0->dwc_ep.xfer_count += byte_count;
  88740. + ep0->dwc_ep.xfer_buff += byte_count;
  88741. + ep0->dwc_ep.dma_addr += byte_count;
  88742. + }
  88743. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  88744. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  88745. + &ep0->dwc_ep);
  88746. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  88747. + } else if (ep0->dwc_ep.sent_zlp) {
  88748. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  88749. + &ep0->dwc_ep);
  88750. + ep0->dwc_ep.sent_zlp = 0;
  88751. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  88752. + } else {
  88753. + ep0_complete_request(ep0);
  88754. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  88755. + }
  88756. + break;
  88757. +
  88758. + case EP0_IN_STATUS_PHASE:
  88759. + case EP0_OUT_STATUS_PHASE:
  88760. + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
  88761. + ep0_complete_request(ep0);
  88762. + pcd->ep0state = EP0_IDLE;
  88763. + ep0->stopped = 1;
  88764. + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
  88765. +
  88766. + /* Prepare for more SETUP Packets */
  88767. + if (core_if->dma_enable) {
  88768. + ep0_out_start(core_if, pcd);
  88769. + }
  88770. + break;
  88771. +
  88772. + case EP0_STALL:
  88773. + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
  88774. + break;
  88775. + }
  88776. +#ifdef DEBUG_EP0
  88777. + print_ep0_state(pcd);
  88778. +#endif
  88779. +}
  88780. +
  88781. +/**
  88782. + * Restart transfer
  88783. + */
  88784. +static void restart_transfer(dwc_otg_pcd_t * pcd, const uint32_t epnum)
  88785. +{
  88786. + dwc_otg_core_if_t *core_if;
  88787. + dwc_otg_dev_if_t *dev_if;
  88788. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  88789. + dwc_otg_pcd_ep_t *ep;
  88790. +
  88791. + ep = get_in_ep(pcd, epnum);
  88792. +
  88793. +#ifdef DWC_EN_ISOC
  88794. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  88795. + return;
  88796. + }
  88797. +#endif /* DWC_EN_ISOC */
  88798. +
  88799. + core_if = GET_CORE_IF(pcd);
  88800. + dev_if = core_if->dev_if;
  88801. +
  88802. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  88803. +
  88804. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x xfer_len=%0x"
  88805. + " stopped=%d\n", ep->dwc_ep.xfer_buff,
  88806. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len, ep->stopped);
  88807. + /*
  88808. + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
  88809. + */
  88810. + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
  88811. + ep->dwc_ep.start_xfer_buff != 0) {
  88812. + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
  88813. + ep->dwc_ep.xfer_count = 0;
  88814. + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
  88815. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  88816. + } else {
  88817. + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
  88818. + /* convert packet size to dwords. */
  88819. + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
  88820. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  88821. + }
  88822. + ep->stopped = 0;
  88823. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x "
  88824. + "xfer_len=%0x stopped=%d\n",
  88825. + ep->dwc_ep.xfer_buff,
  88826. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len,
  88827. + ep->stopped);
  88828. + if (epnum == 0) {
  88829. + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
  88830. + } else {
  88831. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  88832. + }
  88833. + }
  88834. +}
  88835. +
  88836. +/*
  88837. + * This function create new nextep sequnce based on Learn Queue.
  88838. + *
  88839. + * @param core_if Programming view of DWC_otg controller
  88840. + */
  88841. +void predict_nextep_seq( dwc_otg_core_if_t * core_if)
  88842. +{
  88843. + dwc_otg_device_global_regs_t *dev_global_regs =
  88844. + core_if->dev_if->dev_global_regs;
  88845. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  88846. + /* Number of Token Queue Registers */
  88847. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  88848. + dtknq1_data_t dtknqr1;
  88849. + uint32_t in_tkn_epnums[4];
  88850. + uint8_t seqnum[MAX_EPS_CHANNELS];
  88851. + uint8_t intkn_seq[TOKEN_Q_DEPTH];
  88852. + grstctl_t resetctl = {.d32 = 0 };
  88853. + uint8_t temp;
  88854. + int ndx = 0;
  88855. + int start = 0;
  88856. + int end = 0;
  88857. + int sort_done = 0;
  88858. + int i = 0;
  88859. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  88860. +
  88861. +
  88862. + DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  88863. +
  88864. + /* Read the DTKNQ Registers */
  88865. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  88866. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  88867. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  88868. + in_tkn_epnums[i]);
  88869. + if (addr == &dev_global_regs->dvbusdis) {
  88870. + addr = &dev_global_regs->dtknqr3_dthrctl;
  88871. + } else {
  88872. + ++addr;
  88873. + }
  88874. +
  88875. + }
  88876. +
  88877. + /* Copy the DTKNQR1 data to the bit field. */
  88878. + dtknqr1.d32 = in_tkn_epnums[0];
  88879. + if (dtknqr1.b.wrap_bit) {
  88880. + ndx = dtknqr1.b.intknwptr;
  88881. + end = ndx -1;
  88882. + if (end < 0)
  88883. + end = TOKEN_Q_DEPTH -1;
  88884. + } else {
  88885. + ndx = 0;
  88886. + end = dtknqr1.b.intknwptr -1;
  88887. + if (end < 0)
  88888. + end = 0;
  88889. + }
  88890. + start = ndx;
  88891. +
  88892. + /* Fill seqnum[] by initial values: EP number + 31 */
  88893. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  88894. + seqnum[i] = i +31;
  88895. + }
  88896. +
  88897. + /* Fill intkn_seq[] from in_tkn_epnums[0] */
  88898. + for (i=0; i < 6; i++)
  88899. + intkn_seq[i] = (in_tkn_epnums[0] >> ((7-i) * 4)) & 0xf;
  88900. +
  88901. + if (TOKEN_Q_DEPTH > 6) {
  88902. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  88903. + for (i=6; i < 14; i++)
  88904. + intkn_seq[i] =
  88905. + (in_tkn_epnums[1] >> ((7 - (i - 6)) * 4)) & 0xf;
  88906. + }
  88907. +
  88908. + if (TOKEN_Q_DEPTH > 14) {
  88909. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  88910. + for (i=14; i < 22; i++)
  88911. + intkn_seq[i] =
  88912. + (in_tkn_epnums[2] >> ((7 - (i - 14)) * 4)) & 0xf;
  88913. + }
  88914. +
  88915. + if (TOKEN_Q_DEPTH > 22) {
  88916. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  88917. + for (i=22; i < 30; i++)
  88918. + intkn_seq[i] =
  88919. + (in_tkn_epnums[3] >> ((7 - (i - 22)) * 4)) & 0xf;
  88920. + }
  88921. +
  88922. + DWC_DEBUGPL(DBG_PCDV, "%s start=%d end=%d intkn_seq[]:\n", __func__,
  88923. + start, end);
  88924. + for (i=0; i<TOKEN_Q_DEPTH; i++)
  88925. + DWC_DEBUGPL(DBG_PCDV,"%d\n", intkn_seq[i]);
  88926. +
  88927. + /* Update seqnum based on intkn_seq[] */
  88928. + i = 0;
  88929. + do {
  88930. + seqnum[intkn_seq[ndx]] = i;
  88931. + ndx++;
  88932. + i++;
  88933. + if (ndx == TOKEN_Q_DEPTH)
  88934. + ndx = 0;
  88935. + } while ( i < TOKEN_Q_DEPTH );
  88936. +
  88937. + /* Mark non active EP's in seqnum[] by 0xff */
  88938. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  88939. + if (core_if->nextep_seq[i] == 0xff )
  88940. + seqnum[i] = 0xff;
  88941. + }
  88942. +
  88943. + /* Sort seqnum[] */
  88944. + sort_done = 0;
  88945. + while (!sort_done) {
  88946. + sort_done = 1;
  88947. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  88948. + if (seqnum[i] > seqnum[i+1]) {
  88949. + temp = seqnum[i];
  88950. + seqnum[i] = seqnum[i+1];
  88951. + seqnum[i+1] = temp;
  88952. + sort_done = 0;
  88953. + }
  88954. + }
  88955. + }
  88956. +
  88957. + ndx = start + seqnum[0];
  88958. + if (ndx >= TOKEN_Q_DEPTH)
  88959. + ndx = ndx % TOKEN_Q_DEPTH;
  88960. + core_if->first_in_nextep_seq = intkn_seq[ndx];
  88961. +
  88962. + /* Update seqnum[] by EP numbers */
  88963. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  88964. + ndx = start + i;
  88965. + if (seqnum[i] < 31) {
  88966. + ndx = start + seqnum[i];
  88967. + if (ndx >= TOKEN_Q_DEPTH)
  88968. + ndx = ndx % TOKEN_Q_DEPTH;
  88969. + seqnum[i] = intkn_seq[ndx];
  88970. + } else {
  88971. + if (seqnum[i] < 0xff) {
  88972. + seqnum[i] = seqnum[i] - 31;
  88973. + } else {
  88974. + break;
  88975. + }
  88976. + }
  88977. + }
  88978. +
  88979. + /* Update nextep_seq[] based on seqnum[] */
  88980. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  88981. + if (seqnum[i] != 0xff) {
  88982. + if (seqnum[i+1] != 0xff) {
  88983. + core_if->nextep_seq[seqnum[i]] = seqnum[i+1];
  88984. + } else {
  88985. + core_if->nextep_seq[seqnum[i]] = core_if->first_in_nextep_seq;
  88986. + break;
  88987. + }
  88988. + } else {
  88989. + break;
  88990. + }
  88991. + }
  88992. +
  88993. + DWC_DEBUGPL(DBG_PCDV, "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  88994. + __func__, core_if->first_in_nextep_seq);
  88995. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  88996. + DWC_DEBUGPL(DBG_PCDV,"%2d\n", core_if->nextep_seq[i]);
  88997. + }
  88998. +
  88999. + /* Flush the Learning Queue */
  89000. + resetctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->grstctl);
  89001. + resetctl.b.intknqflsh = 1;
  89002. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  89003. +
  89004. +
  89005. +}
  89006. +
  89007. +/**
  89008. + * handle the IN EP disable interrupt.
  89009. + */
  89010. +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t * pcd,
  89011. + const uint32_t epnum)
  89012. +{
  89013. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89014. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  89015. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  89016. + dctl_data_t dctl = {.d32 = 0 };
  89017. + dwc_otg_pcd_ep_t *ep;
  89018. + dwc_ep_t *dwc_ep;
  89019. + gintmsk_data_t gintmsk_data;
  89020. + depctl_data_t depctl;
  89021. + uint32_t diepdma;
  89022. + uint32_t remain_to_transfer = 0;
  89023. + uint8_t i;
  89024. + uint32_t xfer_size;
  89025. +
  89026. + ep = get_in_ep(pcd, epnum);
  89027. + dwc_ep = &ep->dwc_ep;
  89028. +
  89029. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89030. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  89031. + complete_ep(ep);
  89032. + return;
  89033. + }
  89034. +
  89035. + DWC_DEBUGPL(DBG_PCD, "diepctl%d=%0x\n", epnum,
  89036. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl));
  89037. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  89038. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  89039. +
  89040. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  89041. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  89042. +
  89043. + if ((core_if->start_predict == 0) || (depctl.b.eptype & 1)) {
  89044. + if (ep->stopped) {
  89045. + if (core_if->en_multiple_tx_fifo)
  89046. + /* Flush the Tx FIFO */
  89047. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  89048. + /* Clear the Global IN NP NAK */
  89049. + dctl.d32 = 0;
  89050. + dctl.b.cgnpinnak = 1;
  89051. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  89052. + /* Restart the transaction */
  89053. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  89054. + restart_transfer(pcd, epnum);
  89055. + }
  89056. + } else {
  89057. + /* Restart the transaction */
  89058. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  89059. + restart_transfer(pcd, epnum);
  89060. + }
  89061. + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
  89062. + }
  89063. + return;
  89064. + }
  89065. +
  89066. + if (core_if->start_predict > 2) { // NP IN EP
  89067. + core_if->start_predict--;
  89068. + return;
  89069. + }
  89070. +
  89071. + core_if->start_predict--;
  89072. +
  89073. + if (core_if->start_predict == 1) { // All NP IN Ep's disabled now
  89074. +
  89075. + predict_nextep_seq(core_if);
  89076. +
  89077. + /* Update all active IN EP's NextEP field based of nextep_seq[] */
  89078. + for ( i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  89079. + depctl.d32 =
  89080. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89081. + if (core_if->nextep_seq[i] != 0xff) { // Active NP IN EP
  89082. + depctl.b.nextep = core_if->nextep_seq[i];
  89083. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  89084. + }
  89085. + }
  89086. + /* Flush Shared NP TxFIFO */
  89087. + dwc_otg_flush_tx_fifo(core_if, 0);
  89088. + /* Rewind buffers */
  89089. + if (!core_if->dma_desc_enable) {
  89090. + i = core_if->first_in_nextep_seq;
  89091. + do {
  89092. + ep = get_in_ep(pcd, i);
  89093. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  89094. + xfer_size = ep->dwc_ep.total_len - ep->dwc_ep.xfer_count;
  89095. + if (xfer_size > ep->dwc_ep.maxxfer)
  89096. + xfer_size = ep->dwc_ep.maxxfer;
  89097. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89098. + if (dieptsiz.b.pktcnt != 0) {
  89099. + if (xfer_size == 0) {
  89100. + remain_to_transfer = 0;
  89101. + } else {
  89102. + if ((xfer_size % ep->dwc_ep.maxpacket) == 0) {
  89103. + remain_to_transfer =
  89104. + dieptsiz.b.pktcnt * ep->dwc_ep.maxpacket;
  89105. + } else {
  89106. + remain_to_transfer = ((dieptsiz.b.pktcnt -1) * ep->dwc_ep.maxpacket)
  89107. + + (xfer_size % ep->dwc_ep.maxpacket);
  89108. + }
  89109. + }
  89110. + diepdma = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepdma);
  89111. + dieptsiz.b.xfersize = remain_to_transfer;
  89112. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, dieptsiz.d32);
  89113. + diepdma = ep->dwc_ep.dma_addr + (xfer_size - remain_to_transfer);
  89114. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, diepdma);
  89115. + }
  89116. + i = core_if->nextep_seq[i];
  89117. + } while (i != core_if->first_in_nextep_seq);
  89118. + } else { // dma_desc_enable
  89119. + DWC_PRINTF("%s Learning Queue not supported in DDMA\n", __func__);
  89120. + }
  89121. +
  89122. + /* Restart transfers in predicted sequences */
  89123. + i = core_if->first_in_nextep_seq;
  89124. + do {
  89125. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  89126. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89127. + if (dieptsiz.b.pktcnt != 0) {
  89128. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89129. + depctl.b.epena = 1;
  89130. + depctl.b.cnak = 1;
  89131. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  89132. + }
  89133. + i = core_if->nextep_seq[i];
  89134. + } while (i != core_if->first_in_nextep_seq);
  89135. +
  89136. + /* Clear the global non-periodic IN NAK handshake */
  89137. + dctl.d32 = 0;
  89138. + dctl.b.cgnpinnak = 1;
  89139. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  89140. +
  89141. + /* Unmask EP Mismatch interrupt */
  89142. + gintmsk_data.d32 = 0;
  89143. + gintmsk_data.b.epmismatch = 1;
  89144. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk_data.d32);
  89145. +
  89146. + core_if->start_predict = 0;
  89147. +
  89148. + }
  89149. +}
  89150. +
  89151. +/**
  89152. + * Handler for the IN EP timeout handshake interrupt.
  89153. + */
  89154. +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t * pcd,
  89155. + const uint32_t epnum)
  89156. +{
  89157. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89158. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  89159. +
  89160. +#ifdef DEBUG
  89161. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  89162. + uint32_t num = 0;
  89163. +#endif
  89164. + dctl_data_t dctl = {.d32 = 0 };
  89165. + dwc_otg_pcd_ep_t *ep;
  89166. +
  89167. + gintmsk_data_t intr_mask = {.d32 = 0 };
  89168. +
  89169. + ep = get_in_ep(pcd, epnum);
  89170. +
  89171. + /* Disable the NP Tx Fifo Empty Interrrupt */
  89172. + if (!core_if->dma_enable) {
  89173. + intr_mask.b.nptxfempty = 1;
  89174. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  89175. + intr_mask.d32, 0);
  89176. + }
  89177. + /** @todo NGS Check EP type.
  89178. + * Implement for Periodic EPs */
  89179. + /*
  89180. + * Non-periodic EP
  89181. + */
  89182. + /* Enable the Global IN NAK Effective Interrupt */
  89183. + intr_mask.b.ginnakeff = 1;
  89184. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  89185. +
  89186. + /* Set Global IN NAK */
  89187. + dctl.b.sgnpinnak = 1;
  89188. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  89189. +
  89190. + ep->stopped = 1;
  89191. +
  89192. +#ifdef DEBUG
  89193. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[num]->dieptsiz);
  89194. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  89195. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  89196. +#endif
  89197. +
  89198. +#ifdef DISABLE_PERIODIC_EP
  89199. + /*
  89200. + * Set the NAK bit for this EP to
  89201. + * start the disable process.
  89202. + */
  89203. + diepctl.d32 = 0;
  89204. + diepctl.b.snak = 1;
  89205. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32,
  89206. + diepctl.d32);
  89207. + ep->disabling = 1;
  89208. + ep->stopped = 1;
  89209. +#endif
  89210. +}
  89211. +
  89212. +/**
  89213. + * Handler for the IN EP NAK interrupt.
  89214. + */
  89215. +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t * pcd,
  89216. + const uint32_t epnum)
  89217. +{
  89218. + /** @todo implement ISR */
  89219. + dwc_otg_core_if_t *core_if;
  89220. + diepmsk_data_t intr_mask = {.d32 = 0 };
  89221. +
  89222. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
  89223. + core_if = GET_CORE_IF(pcd);
  89224. + intr_mask.b.nak = 1;
  89225. +
  89226. + if (core_if->multiproc_int_enable) {
  89227. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  89228. + diepeachintmsk[epnum], intr_mask.d32, 0);
  89229. + } else {
  89230. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->diepmsk,
  89231. + intr_mask.d32, 0);
  89232. + }
  89233. +
  89234. + return 1;
  89235. +}
  89236. +
  89237. +/**
  89238. + * Handler for the OUT EP Babble interrupt.
  89239. + */
  89240. +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t * pcd,
  89241. + const uint32_t epnum)
  89242. +{
  89243. + /** @todo implement ISR */
  89244. + dwc_otg_core_if_t *core_if;
  89245. + doepmsk_data_t intr_mask = {.d32 = 0 };
  89246. +
  89247. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  89248. + "OUT EP Babble");
  89249. + core_if = GET_CORE_IF(pcd);
  89250. + intr_mask.b.babble = 1;
  89251. +
  89252. + if (core_if->multiproc_int_enable) {
  89253. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  89254. + doepeachintmsk[epnum], intr_mask.d32, 0);
  89255. + } else {
  89256. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  89257. + intr_mask.d32, 0);
  89258. + }
  89259. +
  89260. + return 1;
  89261. +}
  89262. +
  89263. +/**
  89264. + * Handler for the OUT EP NAK interrupt.
  89265. + */
  89266. +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t * pcd,
  89267. + const uint32_t epnum)
  89268. +{
  89269. + /** @todo implement ISR */
  89270. + dwc_otg_core_if_t *core_if;
  89271. + doepmsk_data_t intr_mask = {.d32 = 0 };
  89272. +
  89273. + DWC_DEBUGPL(DBG_ANY, "INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
  89274. + core_if = GET_CORE_IF(pcd);
  89275. + intr_mask.b.nak = 1;
  89276. +
  89277. + if (core_if->multiproc_int_enable) {
  89278. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  89279. + doepeachintmsk[epnum], intr_mask.d32, 0);
  89280. + } else {
  89281. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  89282. + intr_mask.d32, 0);
  89283. + }
  89284. +
  89285. + return 1;
  89286. +}
  89287. +
  89288. +/**
  89289. + * Handler for the OUT EP NYET interrupt.
  89290. + */
  89291. +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t * pcd,
  89292. + const uint32_t epnum)
  89293. +{
  89294. + /** @todo implement ISR */
  89295. + dwc_otg_core_if_t *core_if;
  89296. + doepmsk_data_t intr_mask = {.d32 = 0 };
  89297. +
  89298. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
  89299. + core_if = GET_CORE_IF(pcd);
  89300. + intr_mask.b.nyet = 1;
  89301. +
  89302. + if (core_if->multiproc_int_enable) {
  89303. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  89304. + doepeachintmsk[epnum], intr_mask.d32, 0);
  89305. + } else {
  89306. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  89307. + intr_mask.d32, 0);
  89308. + }
  89309. +
  89310. + return 1;
  89311. +}
  89312. +
  89313. +/**
  89314. + * This interrupt indicates that an IN EP has a pending Interrupt.
  89315. + * The sequence for handling the IN EP interrupt is shown below:
  89316. + * -# Read the Device All Endpoint Interrupt register
  89317. + * -# Repeat the following for each IN EP interrupt bit set (from
  89318. + * LSB to MSB).
  89319. + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
  89320. + * -# If "Transfer Complete" call the request complete function
  89321. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  89322. + * -# If "AHB Error Interrupt" log error
  89323. + * -# If "Time-out Handshake" log error
  89324. + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
  89325. + * FIFO.
  89326. + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
  89327. + * Mismatch Interrupt)
  89328. + */
  89329. +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t * pcd)
  89330. +{
  89331. +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
  89332. +do { \
  89333. + diepint_data_t diepint = {.d32=0}; \
  89334. + diepint.b.__intr = 1; \
  89335. + DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
  89336. + diepint.d32); \
  89337. +} while (0)
  89338. +
  89339. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89340. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  89341. + diepint_data_t diepint = {.d32 = 0 };
  89342. + depctl_data_t depctl = {.d32 = 0 };
  89343. + uint32_t ep_intr;
  89344. + uint32_t epnum = 0;
  89345. + dwc_otg_pcd_ep_t *ep;
  89346. + dwc_ep_t *dwc_ep;
  89347. + gintmsk_data_t intr_mask = {.d32 = 0 };
  89348. +
  89349. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
  89350. +
  89351. + /* Read in the device interrupt bits */
  89352. + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
  89353. +
  89354. + /* Service the Device IN interrupts for each endpoint */
  89355. + while (ep_intr) {
  89356. + if (ep_intr & 0x1) {
  89357. + uint32_t empty_msk;
  89358. + /* Get EP pointer */
  89359. + ep = get_in_ep(pcd, epnum);
  89360. + dwc_ep = &ep->dwc_ep;
  89361. +
  89362. + depctl.d32 =
  89363. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  89364. + empty_msk =
  89365. + DWC_READ_REG32(&dev_if->
  89366. + dev_global_regs->dtknqr4_fifoemptymsk);
  89367. +
  89368. + DWC_DEBUGPL(DBG_PCDV,
  89369. + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
  89370. + epnum, empty_msk, depctl.d32);
  89371. +
  89372. + DWC_DEBUGPL(DBG_PCD,
  89373. + "EP%d-%s: type=%d, mps=%d\n",
  89374. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  89375. + dwc_ep->type, dwc_ep->maxpacket);
  89376. +
  89377. + diepint.d32 =
  89378. + dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
  89379. +
  89380. + DWC_DEBUGPL(DBG_PCDV,
  89381. + "EP %d Interrupt Register - 0x%x\n", epnum,
  89382. + diepint.d32);
  89383. + /* Transfer complete */
  89384. + if (diepint.b.xfercompl) {
  89385. + /* Disable the NP Tx FIFO Empty
  89386. + * Interrupt */
  89387. + if (core_if->en_multiple_tx_fifo == 0) {
  89388. + intr_mask.b.nptxfempty = 1;
  89389. + DWC_MODIFY_REG32
  89390. + (&core_if->core_global_regs->gintmsk,
  89391. + intr_mask.d32, 0);
  89392. + } else {
  89393. + /* Disable the Tx FIFO Empty Interrupt for this EP */
  89394. + uint32_t fifoemptymsk =
  89395. + 0x1 << dwc_ep->num;
  89396. + DWC_MODIFY_REG32(&core_if->
  89397. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  89398. + fifoemptymsk, 0);
  89399. + }
  89400. + /* Clear the bit in DIEPINTn for this interrupt */
  89401. + CLEAR_IN_EP_INTR(core_if, epnum, xfercompl);
  89402. +
  89403. + /* Complete the transfer */
  89404. + if (epnum == 0) {
  89405. + handle_ep0(pcd);
  89406. + }
  89407. +#ifdef DWC_EN_ISOC
  89408. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89409. + if (!ep->stopped)
  89410. + complete_iso_ep(pcd, ep);
  89411. + }
  89412. +#endif /* DWC_EN_ISOC */
  89413. +#ifdef DWC_UTE_PER_IO
  89414. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89415. + if (!ep->stopped)
  89416. + complete_xiso_ep(ep);
  89417. + }
  89418. +#endif /* DWC_UTE_PER_IO */
  89419. + else {
  89420. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC &&
  89421. + dwc_ep->bInterval > 1) {
  89422. + dwc_ep->frame_num += dwc_ep->bInterval;
  89423. + if (dwc_ep->frame_num > 0x3FFF)
  89424. + {
  89425. + dwc_ep->frm_overrun = 1;
  89426. + dwc_ep->frame_num &= 0x3FFF;
  89427. + } else
  89428. + dwc_ep->frm_overrun = 0;
  89429. + }
  89430. + complete_ep(ep);
  89431. + if(diepint.b.nak)
  89432. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  89433. + }
  89434. + }
  89435. + /* Endpoint disable */
  89436. + if (diepint.b.epdisabled) {
  89437. + DWC_DEBUGPL(DBG_ANY, "EP%d IN disabled\n",
  89438. + epnum);
  89439. + handle_in_ep_disable_intr(pcd, epnum);
  89440. +
  89441. + /* Clear the bit in DIEPINTn for this interrupt */
  89442. + CLEAR_IN_EP_INTR(core_if, epnum, epdisabled);
  89443. + }
  89444. + /* AHB Error */
  89445. + if (diepint.b.ahberr) {
  89446. + DWC_ERROR("EP%d IN AHB Error\n", epnum);
  89447. + /* Clear the bit in DIEPINTn for this interrupt */
  89448. + CLEAR_IN_EP_INTR(core_if, epnum, ahberr);
  89449. + }
  89450. + /* TimeOUT Handshake (non-ISOC IN EPs) */
  89451. + if (diepint.b.timeout) {
  89452. + DWC_ERROR("EP%d IN Time-out\n", epnum);
  89453. + handle_in_ep_timeout_intr(pcd, epnum);
  89454. +
  89455. + CLEAR_IN_EP_INTR(core_if, epnum, timeout);
  89456. + }
  89457. + /** IN Token received with TxF Empty */
  89458. + if (diepint.b.intktxfemp) {
  89459. + DWC_DEBUGPL(DBG_ANY,
  89460. + "EP%d IN TKN TxFifo Empty\n",
  89461. + epnum);
  89462. + if (!ep->stopped && epnum != 0) {
  89463. +
  89464. + diepmsk_data_t diepmsk = {.d32 = 0 };
  89465. + diepmsk.b.intktxfemp = 1;
  89466. +
  89467. + if (core_if->multiproc_int_enable) {
  89468. + DWC_MODIFY_REG32
  89469. + (&dev_if->dev_global_regs->diepeachintmsk
  89470. + [epnum], diepmsk.d32, 0);
  89471. + } else {
  89472. + DWC_MODIFY_REG32
  89473. + (&dev_if->dev_global_regs->diepmsk,
  89474. + diepmsk.d32, 0);
  89475. + }
  89476. + } else if (core_if->dma_desc_enable
  89477. + && epnum == 0
  89478. + && pcd->ep0state ==
  89479. + EP0_OUT_STATUS_PHASE) {
  89480. + // EP0 IN set STALL
  89481. + depctl.d32 =
  89482. + DWC_READ_REG32(&dev_if->in_ep_regs
  89483. + [epnum]->diepctl);
  89484. +
  89485. + /* set the disable and stall bits */
  89486. + if (depctl.b.epena) {
  89487. + depctl.b.epdis = 1;
  89488. + }
  89489. + depctl.b.stall = 1;
  89490. + DWC_WRITE_REG32(&dev_if->in_ep_regs
  89491. + [epnum]->diepctl,
  89492. + depctl.d32);
  89493. + }
  89494. + CLEAR_IN_EP_INTR(core_if, epnum, intktxfemp);
  89495. + }
  89496. + /** IN Token Received with EP mismatch */
  89497. + if (diepint.b.intknepmis) {
  89498. + DWC_DEBUGPL(DBG_ANY,
  89499. + "EP%d IN TKN EP Mismatch\n", epnum);
  89500. + CLEAR_IN_EP_INTR(core_if, epnum, intknepmis);
  89501. + }
  89502. + /** IN Endpoint NAK Effective */
  89503. + if (diepint.b.inepnakeff) {
  89504. + DWC_DEBUGPL(DBG_ANY,
  89505. + "EP%d IN EP NAK Effective\n",
  89506. + epnum);
  89507. + /* Periodic EP */
  89508. + if (ep->disabling) {
  89509. + depctl.d32 = 0;
  89510. + depctl.b.snak = 1;
  89511. + depctl.b.epdis = 1;
  89512. + DWC_MODIFY_REG32(&dev_if->in_ep_regs
  89513. + [epnum]->diepctl,
  89514. + depctl.d32,
  89515. + depctl.d32);
  89516. + }
  89517. + CLEAR_IN_EP_INTR(core_if, epnum, inepnakeff);
  89518. +
  89519. + }
  89520. +
  89521. + /** IN EP Tx FIFO Empty Intr */
  89522. + if (diepint.b.emptyintr) {
  89523. + DWC_DEBUGPL(DBG_ANY,
  89524. + "EP%d Tx FIFO Empty Intr \n",
  89525. + epnum);
  89526. + write_empty_tx_fifo(pcd, epnum);
  89527. +
  89528. + CLEAR_IN_EP_INTR(core_if, epnum, emptyintr);
  89529. +
  89530. + }
  89531. +
  89532. + /** IN EP BNA Intr */
  89533. + if (diepint.b.bna) {
  89534. + CLEAR_IN_EP_INTR(core_if, epnum, bna);
  89535. + if (core_if->dma_desc_enable) {
  89536. +#ifdef DWC_EN_ISOC
  89537. + if (dwc_ep->type ==
  89538. + DWC_OTG_EP_TYPE_ISOC) {
  89539. + /*
  89540. + * This checking is performed to prevent first "false" BNA
  89541. + * handling occuring right after reconnect
  89542. + */
  89543. + if (dwc_ep->next_frame !=
  89544. + 0xffffffff)
  89545. + dwc_otg_pcd_handle_iso_bna(ep);
  89546. + } else
  89547. +#endif /* DWC_EN_ISOC */
  89548. + {
  89549. + dwc_otg_pcd_handle_noniso_bna(ep);
  89550. + }
  89551. + }
  89552. + }
  89553. + /* NAK Interrutp */
  89554. + if (diepint.b.nak) {
  89555. + DWC_DEBUGPL(DBG_ANY, "EP%d IN NAK Interrupt\n",
  89556. + epnum);
  89557. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  89558. + depctl_data_t depctl;
  89559. + if (ep->dwc_ep.frame_num == 0xFFFFFFFF) {
  89560. + ep->dwc_ep.frame_num = core_if->frame_num;
  89561. + if (ep->dwc_ep.bInterval > 1) {
  89562. + depctl.d32 = 0;
  89563. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  89564. + if (ep->dwc_ep.frame_num & 0x1) {
  89565. + depctl.b.setd1pid = 1;
  89566. + depctl.b.setd0pid = 0;
  89567. + } else {
  89568. + depctl.b.setd0pid = 1;
  89569. + depctl.b.setd1pid = 0;
  89570. + }
  89571. + DWC_WRITE_REG32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
  89572. + }
  89573. + start_next_request(ep);
  89574. + }
  89575. + ep->dwc_ep.frame_num += ep->dwc_ep.bInterval;
  89576. + if (dwc_ep->frame_num > 0x3FFF) {
  89577. + dwc_ep->frm_overrun = 1;
  89578. + dwc_ep->frame_num &= 0x3FFF;
  89579. + } else
  89580. + dwc_ep->frm_overrun = 0;
  89581. + }
  89582. +
  89583. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  89584. + }
  89585. + }
  89586. + epnum++;
  89587. + ep_intr >>= 1;
  89588. + }
  89589. +
  89590. + return 1;
  89591. +#undef CLEAR_IN_EP_INTR
  89592. +}
  89593. +
  89594. +/**
  89595. + * This interrupt indicates that an OUT EP has a pending Interrupt.
  89596. + * The sequence for handling the OUT EP interrupt is shown below:
  89597. + * -# Read the Device All Endpoint Interrupt register
  89598. + * -# Repeat the following for each OUT EP interrupt bit set (from
  89599. + * LSB to MSB).
  89600. + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
  89601. + * -# If "Transfer Complete" call the request complete function
  89602. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  89603. + * -# If "AHB Error Interrupt" log error
  89604. + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
  89605. + * Command Processing)
  89606. + */
  89607. +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t * pcd)
  89608. +{
  89609. +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
  89610. +do { \
  89611. + doepint_data_t doepint = {.d32=0}; \
  89612. + doepint.b.__intr = 1; \
  89613. + DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
  89614. + doepint.d32); \
  89615. +} while (0)
  89616. +
  89617. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89618. + uint32_t ep_intr;
  89619. + doepint_data_t doepint = {.d32 = 0 };
  89620. + uint32_t epnum = 0;
  89621. + dwc_otg_pcd_ep_t *ep;
  89622. + dwc_ep_t *dwc_ep;
  89623. + dctl_data_t dctl = {.d32 = 0 };
  89624. + gintmsk_data_t gintmsk = {.d32 = 0 };
  89625. +
  89626. +
  89627. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  89628. +
  89629. + /* Read in the device interrupt bits */
  89630. + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
  89631. +
  89632. + while (ep_intr) {
  89633. + if (ep_intr & 0x1) {
  89634. + /* Get EP pointer */
  89635. + ep = get_out_ep(pcd, epnum);
  89636. + dwc_ep = &ep->dwc_ep;
  89637. +
  89638. +#ifdef VERBOSE
  89639. + DWC_DEBUGPL(DBG_PCDV,
  89640. + "EP%d-%s: type=%d, mps=%d\n",
  89641. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  89642. + dwc_ep->type, dwc_ep->maxpacket);
  89643. +#endif
  89644. + doepint.d32 =
  89645. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
  89646. + /* Moved this interrupt upper due to core deffect of asserting
  89647. + * OUT EP 0 xfercompl along with stsphsrcvd in BDMA */
  89648. + if (doepint.b.stsphsercvd) {
  89649. + deptsiz0_data_t deptsiz;
  89650. + CLEAR_OUT_EP_INTR(core_if, epnum, stsphsercvd);
  89651. + deptsiz.d32 =
  89652. + DWC_READ_REG32(&core_if->dev_if->
  89653. + out_ep_regs[0]->doeptsiz);
  89654. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  89655. + && core_if->dma_enable
  89656. + && core_if->dma_desc_enable == 0
  89657. + && doepint.b.xfercompl
  89658. + && deptsiz.b.xfersize == 24) {
  89659. + CLEAR_OUT_EP_INTR(core_if, epnum,
  89660. + xfercompl);
  89661. + doepint.b.xfercompl = 0;
  89662. + ep0_out_start(core_if, pcd);
  89663. + }
  89664. + if ((core_if->dma_desc_enable) ||
  89665. + (core_if->dma_enable
  89666. + && core_if->snpsid >=
  89667. + OTG_CORE_REV_3_00a)) {
  89668. + do_setup_in_status_phase(pcd);
  89669. + }
  89670. + }
  89671. + /* Transfer complete */
  89672. + if (doepint.b.xfercompl) {
  89673. +
  89674. + if (epnum == 0) {
  89675. + /* Clear the bit in DOEPINTn for this interrupt */
  89676. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  89677. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  89678. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  89679. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepint),
  89680. + doepint.d32);
  89681. + DWC_DEBUGPL(DBG_PCDV, "DOEPCTL=%x \n",
  89682. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepctl));
  89683. +
  89684. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  89685. + && core_if->dma_enable == 0) {
  89686. + doepint_data_t doepint;
  89687. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  89688. + out_ep_regs[0]->doepint);
  89689. + if (pcd->ep0state == EP0_IDLE && doepint.b.sr) {
  89690. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  89691. + goto exit_xfercompl;
  89692. + }
  89693. + }
  89694. + /* In case of DDMA look at SR bit to go to the Data Stage */
  89695. + if (core_if->dma_desc_enable) {
  89696. + dev_dma_desc_sts_t status = {.d32 = 0};
  89697. + if (pcd->ep0state == EP0_IDLE) {
  89698. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  89699. + dev_if->setup_desc_index]->status.d32;
  89700. + if(pcd->data_terminated) {
  89701. + pcd->data_terminated = 0;
  89702. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  89703. + dwc_memcpy(&pcd->setup_pkt->req, pcd->backup_buf, 8);
  89704. + }
  89705. + if (status.b.sr) {
  89706. + if (doepint.b.setup) {
  89707. + DWC_DEBUGPL(DBG_PCDV, "DMA DESC EP0_IDLE SR=1 setup=1\n");
  89708. + /* Already started data stage, clear setup */
  89709. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  89710. + doepint.b.setup = 0;
  89711. + handle_ep0(pcd);
  89712. + /* Prepare for more setup packets */
  89713. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  89714. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  89715. + ep0_out_start(core_if, pcd);
  89716. + }
  89717. +
  89718. + goto exit_xfercompl;
  89719. + } else {
  89720. + /* Prepare for more setup packets */
  89721. + DWC_DEBUGPL(DBG_PCDV,
  89722. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  89723. + ep0_out_start(core_if, pcd);
  89724. + }
  89725. + }
  89726. + } else {
  89727. + dwc_otg_pcd_request_t *req;
  89728. + dev_dma_desc_sts_t status = {.d32 = 0};
  89729. + diepint_data_t diepint0;
  89730. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  89731. + in_ep_regs[0]->diepint);
  89732. +
  89733. + if (pcd->ep0state == EP0_STALL || pcd->ep0state == EP0_DISCONNECT) {
  89734. + DWC_ERROR("EP0 is stalled/disconnected\n");
  89735. + }
  89736. +
  89737. + /* Clear IN xfercompl if set */
  89738. + if (diepint0.b.xfercompl && (pcd->ep0state == EP0_IN_STATUS_PHASE
  89739. + || pcd->ep0state == EP0_IN_DATA_PHASE)) {
  89740. + DWC_WRITE_REG32(&core_if->dev_if->
  89741. + in_ep_regs[0]->diepint, diepint0.d32);
  89742. + }
  89743. +
  89744. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  89745. + dev_if->setup_desc_index]->status.d32;
  89746. +
  89747. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len
  89748. + && (pcd->ep0state == EP0_OUT_DATA_PHASE))
  89749. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  89750. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
  89751. + status.d32 = core_if->dev_if->
  89752. + out_desc_addr->status.d32;
  89753. +
  89754. + if (status.b.sr) {
  89755. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  89756. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  89757. + } else {
  89758. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  89759. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  89760. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  89761. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  89762. + /* Read arrived setup packet from req->buf */
  89763. + dwc_memcpy(&pcd->setup_pkt->req,
  89764. + req->buf + ep->dwc_ep.xfer_count, 8);
  89765. + }
  89766. + req->actual = ep->dwc_ep.xfer_count;
  89767. + dwc_otg_request_done(ep, req, -ECONNRESET);
  89768. + ep->dwc_ep.start_xfer_buff = 0;
  89769. + ep->dwc_ep.xfer_buff = 0;
  89770. + ep->dwc_ep.xfer_len = 0;
  89771. + }
  89772. + pcd->ep0state = EP0_IDLE;
  89773. + if (doepint.b.setup) {
  89774. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  89775. + /* Data stage started, clear setup */
  89776. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  89777. + doepint.b.setup = 0;
  89778. + handle_ep0(pcd);
  89779. + /* Prepare for setup packets if ep0in was enabled*/
  89780. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  89781. + ep0_out_start(core_if, pcd);
  89782. + }
  89783. +
  89784. + goto exit_xfercompl;
  89785. + } else {
  89786. + /* Prepare for more setup packets */
  89787. + DWC_DEBUGPL(DBG_PCDV,
  89788. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  89789. + ep0_out_start(core_if, pcd);
  89790. + }
  89791. + }
  89792. + }
  89793. + }
  89794. + if (core_if->snpsid >= OTG_CORE_REV_2_94a && core_if->dma_enable
  89795. + && core_if->dma_desc_enable == 0) {
  89796. + doepint_data_t doepint_temp = {.d32 = 0};
  89797. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  89798. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  89799. + out_ep_regs[ep->dwc_ep.num]->doepint);
  89800. + doeptsize0.d32 = DWC_READ_REG32(&core_if->dev_if->
  89801. + out_ep_regs[ep->dwc_ep.num]->doeptsiz);
  89802. + if (pcd->ep0state == EP0_IDLE) {
  89803. + if (doepint_temp.b.sr) {
  89804. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  89805. + }
  89806. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  89807. + out_ep_regs[0]->doepint);
  89808. + if (doeptsize0.b.supcnt == 3) {
  89809. + DWC_DEBUGPL(DBG_ANY, "Rolling over!!!!!!!\n");
  89810. + ep->dwc_ep.stp_rollover = 1;
  89811. + }
  89812. + if (doepint.b.setup) {
  89813. +retry:
  89814. + /* Already started data stage, clear setup */
  89815. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  89816. + doepint.b.setup = 0;
  89817. + handle_ep0(pcd);
  89818. + ep->dwc_ep.stp_rollover = 0;
  89819. + /* Prepare for more setup packets */
  89820. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  89821. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  89822. + ep0_out_start(core_if, pcd);
  89823. + }
  89824. + goto exit_xfercompl;
  89825. + } else {
  89826. + /* Prepare for more setup packets */
  89827. + DWC_DEBUGPL(DBG_ANY,
  89828. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  89829. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  89830. + out_ep_regs[0]->doepint);
  89831. + if(doepint.b.setup)
  89832. + goto retry;
  89833. + ep0_out_start(core_if, pcd);
  89834. + }
  89835. + } else {
  89836. + dwc_otg_pcd_request_t *req;
  89837. + diepint_data_t diepint0 = {.d32 = 0};
  89838. + doepint_data_t doepint_temp = {.d32 = 0};
  89839. + depctl_data_t diepctl0;
  89840. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  89841. + in_ep_regs[0]->diepint);
  89842. + diepctl0.d32 = DWC_READ_REG32(&core_if->dev_if->
  89843. + in_ep_regs[0]->diepctl);
  89844. +
  89845. + if (pcd->ep0state == EP0_IN_DATA_PHASE
  89846. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  89847. + if (diepint0.b.xfercompl) {
  89848. + DWC_WRITE_REG32(&core_if->dev_if->
  89849. + in_ep_regs[0]->diepint, diepint0.d32);
  89850. + }
  89851. + if (diepctl0.b.epena) {
  89852. + diepint_data_t diepint = {.d32 = 0};
  89853. + diepctl0.b.snak = 1;
  89854. + DWC_WRITE_REG32(&core_if->dev_if->
  89855. + in_ep_regs[0]->diepctl, diepctl0.d32);
  89856. + do {
  89857. + dwc_udelay(10);
  89858. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  89859. + in_ep_regs[0]->diepint);
  89860. + } while (!diepint.b.inepnakeff);
  89861. + diepint.b.inepnakeff = 1;
  89862. + DWC_WRITE_REG32(&core_if->dev_if->
  89863. + in_ep_regs[0]->diepint, diepint.d32);
  89864. + diepctl0.d32 = 0;
  89865. + diepctl0.b.epdis = 1;
  89866. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl,
  89867. + diepctl0.d32);
  89868. + do {
  89869. + dwc_udelay(10);
  89870. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  89871. + in_ep_regs[0]->diepint);
  89872. + } while (!diepint.b.epdisabled);
  89873. + diepint.b.epdisabled = 1;
  89874. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepint,
  89875. + diepint.d32);
  89876. + }
  89877. + }
  89878. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  89879. + out_ep_regs[ep->dwc_ep.num]->doepint);
  89880. + if (doepint_temp.b.sr) {
  89881. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  89882. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  89883. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  89884. + } else {
  89885. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  89886. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  89887. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  89888. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  89889. + /* Read arrived setup packet from req->buf */
  89890. + dwc_memcpy(&pcd->setup_pkt->req,
  89891. + req->buf + ep->dwc_ep.xfer_count, 8);
  89892. + }
  89893. + req->actual = ep->dwc_ep.xfer_count;
  89894. + dwc_otg_request_done(ep, req, -ECONNRESET);
  89895. + ep->dwc_ep.start_xfer_buff = 0;
  89896. + ep->dwc_ep.xfer_buff = 0;
  89897. + ep->dwc_ep.xfer_len = 0;
  89898. + }
  89899. + pcd->ep0state = EP0_IDLE;
  89900. + if (doepint.b.setup) {
  89901. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  89902. + /* Data stage started, clear setup */
  89903. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  89904. + doepint.b.setup = 0;
  89905. + handle_ep0(pcd);
  89906. + /* Prepare for setup packets if ep0in was enabled*/
  89907. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  89908. + ep0_out_start(core_if, pcd);
  89909. + }
  89910. + goto exit_xfercompl;
  89911. + } else {
  89912. + /* Prepare for more setup packets */
  89913. + DWC_DEBUGPL(DBG_PCDV,
  89914. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  89915. + ep0_out_start(core_if, pcd);
  89916. + }
  89917. + }
  89918. + }
  89919. + }
  89920. + if (core_if->dma_enable == 0 || pcd->ep0state != EP0_IDLE)
  89921. + handle_ep0(pcd);
  89922. +exit_xfercompl:
  89923. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  89924. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep), doepint.d32);
  89925. + } else {
  89926. + if (core_if->dma_desc_enable == 0
  89927. + || pcd->ep0state != EP0_IDLE)
  89928. + handle_ep0(pcd);
  89929. + }
  89930. +#ifdef DWC_EN_ISOC
  89931. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89932. + if (doepint.b.pktdrpsts == 0) {
  89933. + /* Clear the bit in DOEPINTn for this interrupt */
  89934. + CLEAR_OUT_EP_INTR(core_if,
  89935. + epnum,
  89936. + xfercompl);
  89937. + complete_iso_ep(pcd, ep);
  89938. + } else {
  89939. +
  89940. + doepint_data_t doepint = {.d32 = 0 };
  89941. + doepint.b.xfercompl = 1;
  89942. + doepint.b.pktdrpsts = 1;
  89943. + DWC_WRITE_REG32
  89944. + (&core_if->dev_if->out_ep_regs
  89945. + [epnum]->doepint,
  89946. + doepint.d32);
  89947. + if (handle_iso_out_pkt_dropped
  89948. + (core_if, dwc_ep)) {
  89949. + complete_iso_ep(pcd,
  89950. + ep);
  89951. + }
  89952. + }
  89953. +#endif /* DWC_EN_ISOC */
  89954. +#ifdef DWC_UTE_PER_IO
  89955. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89956. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  89957. + if (!ep->stopped)
  89958. + complete_xiso_ep(ep);
  89959. +#endif /* DWC_UTE_PER_IO */
  89960. + } else {
  89961. + /* Clear the bit in DOEPINTn for this interrupt */
  89962. + CLEAR_OUT_EP_INTR(core_if, epnum,
  89963. + xfercompl);
  89964. +
  89965. + if (core_if->core_params->dev_out_nak) {
  89966. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[epnum]);
  89967. + pcd->core_if->ep_xfer_info[epnum].state = 0;
  89968. +#ifdef DEBUG
  89969. + print_memory_payload(pcd, dwc_ep);
  89970. +#endif
  89971. + }
  89972. + complete_ep(ep);
  89973. + }
  89974. +
  89975. + }
  89976. +
  89977. + /* Endpoint disable */
  89978. + if (doepint.b.epdisabled) {
  89979. +
  89980. + /* Clear the bit in DOEPINTn for this interrupt */
  89981. + CLEAR_OUT_EP_INTR(core_if, epnum, epdisabled);
  89982. + if (core_if->core_params->dev_out_nak) {
  89983. +#ifdef DEBUG
  89984. + print_memory_payload(pcd, dwc_ep);
  89985. +#endif
  89986. + /* In case of timeout condition */
  89987. + if (core_if->ep_xfer_info[epnum].state == 2) {
  89988. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  89989. + dev_global_regs->dctl);
  89990. + dctl.b.cgoutnak = 1;
  89991. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  89992. + dctl.d32);
  89993. + /* Unmask goutnakeff interrupt which was masked
  89994. + * during handle nak out interrupt */
  89995. + gintmsk.b.goutnakeff = 1;
  89996. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  89997. + 0, gintmsk.d32);
  89998. +
  89999. + complete_ep(ep);
  90000. + }
  90001. + }
  90002. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  90003. + {
  90004. + dctl_data_t dctl;
  90005. + gintmsk_data_t intr_mask = {.d32 = 0};
  90006. + dwc_otg_pcd_request_t *req = 0;
  90007. +
  90008. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  90009. + dev_global_regs->dctl);
  90010. + dctl.b.cgoutnak = 1;
  90011. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  90012. + dctl.d32);
  90013. +
  90014. + intr_mask.d32 = 0;
  90015. + intr_mask.b.incomplisoout = 1;
  90016. +
  90017. + /* Get any pending requests */
  90018. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  90019. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  90020. + if (!req) {
  90021. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  90022. + } else {
  90023. + dwc_otg_request_done(ep, req, 0);
  90024. + start_next_request(ep);
  90025. + }
  90026. + } else {
  90027. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  90028. + }
  90029. + }
  90030. + }
  90031. + /* AHB Error */
  90032. + if (doepint.b.ahberr) {
  90033. + DWC_ERROR("EP%d OUT AHB Error\n", epnum);
  90034. + DWC_ERROR("EP%d DEPDMA=0x%08x \n",
  90035. + epnum, core_if->dev_if->out_ep_regs[epnum]->doepdma);
  90036. + CLEAR_OUT_EP_INTR(core_if, epnum, ahberr);
  90037. + }
  90038. + /* Setup Phase Done (contorl EPs) */
  90039. + if (doepint.b.setup) {
  90040. +#ifdef DEBUG_EP0
  90041. + DWC_DEBUGPL(DBG_PCD, "EP%d SETUP Done\n", epnum);
  90042. +#endif
  90043. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  90044. +
  90045. + handle_ep0(pcd);
  90046. + }
  90047. +
  90048. + /** OUT EP BNA Intr */
  90049. + if (doepint.b.bna) {
  90050. + CLEAR_OUT_EP_INTR(core_if, epnum, bna);
  90051. + if (core_if->dma_desc_enable) {
  90052. +#ifdef DWC_EN_ISOC
  90053. + if (dwc_ep->type ==
  90054. + DWC_OTG_EP_TYPE_ISOC) {
  90055. + /*
  90056. + * This checking is performed to prevent first "false" BNA
  90057. + * handling occuring right after reconnect
  90058. + */
  90059. + if (dwc_ep->next_frame !=
  90060. + 0xffffffff)
  90061. + dwc_otg_pcd_handle_iso_bna(ep);
  90062. + } else
  90063. +#endif /* DWC_EN_ISOC */
  90064. + {
  90065. + dwc_otg_pcd_handle_noniso_bna(ep);
  90066. + }
  90067. + }
  90068. + }
  90069. + /* Babble Interrupt */
  90070. + if (doepint.b.babble) {
  90071. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Babble\n",
  90072. + epnum);
  90073. + handle_out_ep_babble_intr(pcd, epnum);
  90074. +
  90075. + CLEAR_OUT_EP_INTR(core_if, epnum, babble);
  90076. + }
  90077. + if (doepint.b.outtknepdis) {
  90078. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Token received when EP is \
  90079. + disabled\n",epnum);
  90080. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  90081. + doepmsk_data_t doepmsk = {.d32 = 0};
  90082. + ep->dwc_ep.frame_num = core_if->frame_num;
  90083. + if (ep->dwc_ep.bInterval > 1) {
  90084. + depctl_data_t depctl;
  90085. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  90086. + out_ep_regs[epnum]->doepctl);
  90087. + if (ep->dwc_ep.frame_num & 0x1) {
  90088. + depctl.b.setd1pid = 1;
  90089. + depctl.b.setd0pid = 0;
  90090. + } else {
  90091. + depctl.b.setd0pid = 1;
  90092. + depctl.b.setd1pid = 0;
  90093. + }
  90094. + DWC_WRITE_REG32(&core_if->dev_if->
  90095. + out_ep_regs[epnum]->doepctl, depctl.d32);
  90096. + }
  90097. + start_next_request(ep);
  90098. + doepmsk.b.outtknepdis = 1;
  90099. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  90100. + doepmsk.d32, 0);
  90101. + }
  90102. + CLEAR_OUT_EP_INTR(core_if, epnum, outtknepdis);
  90103. + }
  90104. +
  90105. + /* NAK Interrutp */
  90106. + if (doepint.b.nak) {
  90107. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NAK\n", epnum);
  90108. + handle_out_ep_nak_intr(pcd, epnum);
  90109. +
  90110. + CLEAR_OUT_EP_INTR(core_if, epnum, nak);
  90111. + }
  90112. + /* NYET Interrutp */
  90113. + if (doepint.b.nyet) {
  90114. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NYET\n", epnum);
  90115. + handle_out_ep_nyet_intr(pcd, epnum);
  90116. +
  90117. + CLEAR_OUT_EP_INTR(core_if, epnum, nyet);
  90118. + }
  90119. + }
  90120. +
  90121. + epnum++;
  90122. + ep_intr >>= 1;
  90123. + }
  90124. +
  90125. + return 1;
  90126. +
  90127. +#undef CLEAR_OUT_EP_INTR
  90128. +}
  90129. +static int drop_transfer(uint32_t trgt_fr, uint32_t curr_fr, uint8_t frm_overrun)
  90130. +{
  90131. + int retval = 0;
  90132. + if(!frm_overrun && curr_fr >= trgt_fr)
  90133. + retval = 1;
  90134. + else if (frm_overrun
  90135. + && (curr_fr >= trgt_fr && ((curr_fr - trgt_fr) < 0x3FFF / 2)))
  90136. + retval = 1;
  90137. + return retval;
  90138. +}
  90139. +/**
  90140. + * Incomplete ISO IN Transfer Interrupt.
  90141. + * This interrupt indicates one of the following conditions occurred
  90142. + * while transmitting an ISOC transaction.
  90143. + * - Corrupted IN Token for ISOC EP.
  90144. + * - Packet not complete in FIFO.
  90145. + * The follow actions will be taken:
  90146. + * -# Determine the EP
  90147. + * -# Set incomplete flag in dwc_ep structure
  90148. + * -# Disable EP; when "Endpoint Disabled" interrupt is received
  90149. + * Flush FIFO
  90150. + */
  90151. +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t * pcd)
  90152. +{
  90153. + gintsts_data_t gintsts;
  90154. +
  90155. +#ifdef DWC_EN_ISOC
  90156. + dwc_otg_dev_if_t *dev_if;
  90157. + deptsiz_data_t deptsiz = {.d32 = 0 };
  90158. + depctl_data_t depctl = {.d32 = 0 };
  90159. + dsts_data_t dsts = {.d32 = 0 };
  90160. + dwc_ep_t *dwc_ep;
  90161. + int i;
  90162. +
  90163. + dev_if = GET_CORE_IF(pcd)->dev_if;
  90164. +
  90165. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  90166. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  90167. + if (dwc_ep->active && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  90168. + deptsiz.d32 =
  90169. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  90170. + depctl.d32 =
  90171. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  90172. +
  90173. + if (depctl.b.epdis && deptsiz.d32) {
  90174. + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
  90175. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  90176. + dwc_ep->cur_pkt = 0;
  90177. + dwc_ep->proc_buf_num =
  90178. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  90179. +
  90180. + if (dwc_ep->proc_buf_num) {
  90181. + dwc_ep->cur_pkt_addr =
  90182. + dwc_ep->xfer_buff1;
  90183. + dwc_ep->cur_pkt_dma_addr =
  90184. + dwc_ep->dma_addr1;
  90185. + } else {
  90186. + dwc_ep->cur_pkt_addr =
  90187. + dwc_ep->xfer_buff0;
  90188. + dwc_ep->cur_pkt_dma_addr =
  90189. + dwc_ep->dma_addr0;
  90190. + }
  90191. +
  90192. + }
  90193. +
  90194. + dsts.d32 =
  90195. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  90196. + dev_global_regs->dsts);
  90197. + dwc_ep->next_frame = dsts.b.soffn;
  90198. +
  90199. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  90200. + (pcd),
  90201. + dwc_ep);
  90202. + }
  90203. + }
  90204. + }
  90205. +
  90206. +#else
  90207. + depctl_data_t depctl = {.d32 = 0 };
  90208. + dwc_ep_t *dwc_ep;
  90209. + dwc_otg_dev_if_t *dev_if;
  90210. + int i;
  90211. + dev_if = GET_CORE_IF(pcd)->dev_if;
  90212. +
  90213. + DWC_DEBUGPL(DBG_PCD,"Incomplete ISO IN \n");
  90214. +
  90215. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  90216. + dwc_ep = &pcd->in_ep[i-1].dwc_ep;
  90217. + depctl.d32 =
  90218. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  90219. + if (depctl.b.epena && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  90220. + if (drop_transfer(dwc_ep->frame_num, GET_CORE_IF(pcd)->frame_num,
  90221. + dwc_ep->frm_overrun))
  90222. + {
  90223. + depctl.d32 =
  90224. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  90225. + depctl.b.snak = 1;
  90226. + depctl.b.epdis = 1;
  90227. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32, depctl.d32);
  90228. + }
  90229. + }
  90230. + }
  90231. +
  90232. + /*intr_mask.b.incomplisoin = 1;
  90233. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  90234. + intr_mask.d32, 0); */
  90235. +#endif //DWC_EN_ISOC
  90236. +
  90237. + /* Clear interrupt */
  90238. + gintsts.d32 = 0;
  90239. + gintsts.b.incomplisoin = 1;
  90240. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  90241. + gintsts.d32);
  90242. +
  90243. + return 1;
  90244. +}
  90245. +
  90246. +/**
  90247. + * Incomplete ISO OUT Transfer Interrupt.
  90248. + *
  90249. + * This interrupt indicates that the core has dropped an ISO OUT
  90250. + * packet. The following conditions can be the cause:
  90251. + * - FIFO Full, the entire packet would not fit in the FIFO.
  90252. + * - CRC Error
  90253. + * - Corrupted Token
  90254. + * The follow actions will be taken:
  90255. + * -# Determine the EP
  90256. + * -# Set incomplete flag in dwc_ep structure
  90257. + * -# Read any data from the FIFO
  90258. + * -# Disable EP. When "Endpoint Disabled" interrupt is received
  90259. + * re-enable EP.
  90260. + */
  90261. +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t * pcd)
  90262. +{
  90263. +
  90264. + gintsts_data_t gintsts;
  90265. +
  90266. +#ifdef DWC_EN_ISOC
  90267. + dwc_otg_dev_if_t *dev_if;
  90268. + deptsiz_data_t deptsiz = {.d32 = 0 };
  90269. + depctl_data_t depctl = {.d32 = 0 };
  90270. + dsts_data_t dsts = {.d32 = 0 };
  90271. + dwc_ep_t *dwc_ep;
  90272. + int i;
  90273. +
  90274. + dev_if = GET_CORE_IF(pcd)->dev_if;
  90275. +
  90276. + for (i = 1; i <= dev_if->num_out_eps; ++i) {
  90277. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  90278. + if (pcd->out_ep[i].dwc_ep.active &&
  90279. + pcd->out_ep[i].dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  90280. + deptsiz.d32 =
  90281. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doeptsiz);
  90282. + depctl.d32 =
  90283. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  90284. +
  90285. + if (depctl.b.epdis && deptsiz.d32) {
  90286. + set_current_pkt_info(GET_CORE_IF(pcd),
  90287. + &pcd->out_ep[i].dwc_ep);
  90288. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  90289. + dwc_ep->cur_pkt = 0;
  90290. + dwc_ep->proc_buf_num =
  90291. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  90292. +
  90293. + if (dwc_ep->proc_buf_num) {
  90294. + dwc_ep->cur_pkt_addr =
  90295. + dwc_ep->xfer_buff1;
  90296. + dwc_ep->cur_pkt_dma_addr =
  90297. + dwc_ep->dma_addr1;
  90298. + } else {
  90299. + dwc_ep->cur_pkt_addr =
  90300. + dwc_ep->xfer_buff0;
  90301. + dwc_ep->cur_pkt_dma_addr =
  90302. + dwc_ep->dma_addr0;
  90303. + }
  90304. +
  90305. + }
  90306. +
  90307. + dsts.d32 =
  90308. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  90309. + dev_global_regs->dsts);
  90310. + dwc_ep->next_frame = dsts.b.soffn;
  90311. +
  90312. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  90313. + (pcd),
  90314. + dwc_ep);
  90315. + }
  90316. + }
  90317. + }
  90318. +#else
  90319. + /** @todo implement ISR */
  90320. + gintmsk_data_t intr_mask = {.d32 = 0 };
  90321. + dwc_otg_core_if_t *core_if;
  90322. + deptsiz_data_t deptsiz = {.d32 = 0 };
  90323. + depctl_data_t depctl = {.d32 = 0 };
  90324. + dctl_data_t dctl = {.d32 = 0 };
  90325. + dwc_ep_t *dwc_ep = NULL;
  90326. + int i;
  90327. + core_if = GET_CORE_IF(pcd);
  90328. +
  90329. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  90330. + dwc_ep = &pcd->out_ep[i].dwc_ep;
  90331. + depctl.d32 =
  90332. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  90333. + if (depctl.b.epena && depctl.b.dpid == (core_if->frame_num & 0x1)) {
  90334. + core_if->dev_if->isoc_ep = dwc_ep;
  90335. + deptsiz.d32 =
  90336. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
  90337. + break;
  90338. + }
  90339. + }
  90340. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  90341. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  90342. + intr_mask.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  90343. +
  90344. + if (!intr_mask.b.goutnakeff) {
  90345. + /* Unmask it */
  90346. + intr_mask.b.goutnakeff = 1;
  90347. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32);
  90348. + }
  90349. + if (!gintsts.b.goutnakeff) {
  90350. + dctl.b.sgoutnak = 1;
  90351. + }
  90352. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  90353. +
  90354. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  90355. + if (depctl.b.epena) {
  90356. + depctl.b.epdis = 1;
  90357. + depctl.b.snak = 1;
  90358. + }
  90359. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl, depctl.d32);
  90360. +
  90361. + intr_mask.d32 = 0;
  90362. + intr_mask.b.incomplisoout = 1;
  90363. +
  90364. +#endif /* DWC_EN_ISOC */
  90365. +
  90366. + /* Clear interrupt */
  90367. + gintsts.d32 = 0;
  90368. + gintsts.b.incomplisoout = 1;
  90369. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  90370. + gintsts.d32);
  90371. +
  90372. + return 1;
  90373. +}
  90374. +
  90375. +/**
  90376. + * This function handles the Global IN NAK Effective interrupt.
  90377. + *
  90378. + */
  90379. +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t * pcd)
  90380. +{
  90381. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  90382. + depctl_data_t diepctl = {.d32 = 0 };
  90383. + gintmsk_data_t intr_mask = {.d32 = 0 };
  90384. + gintsts_data_t gintsts;
  90385. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  90386. + int i;
  90387. +
  90388. + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
  90389. +
  90390. + /* Disable all active IN EPs */
  90391. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  90392. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  90393. + if (!(diepctl.b.eptype & 1) && diepctl.b.epena) {
  90394. + if (core_if->start_predict > 0)
  90395. + core_if->start_predict++;
  90396. + diepctl.b.epdis = 1;
  90397. + diepctl.b.snak = 1;
  90398. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, diepctl.d32);
  90399. + }
  90400. + }
  90401. +
  90402. +
  90403. + /* Disable the Global IN NAK Effective Interrupt */
  90404. + intr_mask.b.ginnakeff = 1;
  90405. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  90406. + intr_mask.d32, 0);
  90407. +
  90408. + /* Clear interrupt */
  90409. + gintsts.d32 = 0;
  90410. + gintsts.b.ginnakeff = 1;
  90411. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  90412. + gintsts.d32);
  90413. +
  90414. + return 1;
  90415. +}
  90416. +
  90417. +/**
  90418. + * OUT NAK Effective.
  90419. + *
  90420. + */
  90421. +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t * pcd)
  90422. +{
  90423. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  90424. + gintmsk_data_t intr_mask = {.d32 = 0 };
  90425. + gintsts_data_t gintsts;
  90426. + depctl_data_t doepctl;
  90427. + int i;
  90428. +
  90429. + /* Disable the Global OUT NAK Effective Interrupt */
  90430. + intr_mask.b.goutnakeff = 1;
  90431. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  90432. + intr_mask.d32, 0);
  90433. +
  90434. + /* If DEV OUT NAK enabled*/
  90435. + if (pcd->core_if->core_params->dev_out_nak) {
  90436. + /* Run over all out endpoints to determine the ep number on
  90437. + * which the timeout has happened
  90438. + */
  90439. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  90440. + if ( pcd->core_if->ep_xfer_info[i].state == 2 )
  90441. + break;
  90442. + }
  90443. + if (i > dev_if->num_out_eps) {
  90444. + dctl_data_t dctl;
  90445. + dctl.d32 =
  90446. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  90447. + dctl.b.cgoutnak = 1;
  90448. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl,
  90449. + dctl.d32);
  90450. + goto out;
  90451. + }
  90452. +
  90453. + /* Disable the endpoint */
  90454. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  90455. + if (doepctl.b.epena) {
  90456. + doepctl.b.epdis = 1;
  90457. + doepctl.b.snak = 1;
  90458. + }
  90459. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  90460. + return 1;
  90461. + }
  90462. + /* We come here from Incomplete ISO OUT handler */
  90463. + if (dev_if->isoc_ep) {
  90464. + dwc_ep_t *dwc_ep = (dwc_ep_t *)dev_if->isoc_ep;
  90465. + uint32_t epnum = dwc_ep->num;
  90466. + doepint_data_t doepint;
  90467. + doepint.d32 =
  90468. + DWC_READ_REG32(&dev_if->out_ep_regs[dwc_ep->num]->doepint);
  90469. + dev_if->isoc_ep = NULL;
  90470. + doepctl.d32 =
  90471. + DWC_READ_REG32(&dev_if->out_ep_regs[epnum]->doepctl);
  90472. + DWC_PRINTF("Before disable DOEPCTL = %08x\n", doepctl.d32);
  90473. + if (doepctl.b.epena) {
  90474. + doepctl.b.epdis = 1;
  90475. + doepctl.b.snak = 1;
  90476. + }
  90477. + DWC_WRITE_REG32(&dev_if->out_ep_regs[epnum]->doepctl,
  90478. + doepctl.d32);
  90479. + return 1;
  90480. + } else
  90481. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  90482. + "Global OUT NAK Effective\n");
  90483. +
  90484. +out:
  90485. + /* Clear interrupt */
  90486. + gintsts.d32 = 0;
  90487. + gintsts.b.goutnakeff = 1;
  90488. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  90489. + gintsts.d32);
  90490. +
  90491. + return 1;
  90492. +}
  90493. +
  90494. +/**
  90495. + * PCD interrupt handler.
  90496. + *
  90497. + * The PCD handles the device interrupts. Many conditions can cause a
  90498. + * device interrupt. When an interrupt occurs, the device interrupt
  90499. + * service routine determines the cause of the interrupt and
  90500. + * dispatches handling to the appropriate function. These interrupt
  90501. + * handling functions are described below.
  90502. + *
  90503. + * All interrupt registers are processed from LSB to MSB.
  90504. + *
  90505. + */
  90506. +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd)
  90507. +{
  90508. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  90509. +#ifdef VERBOSE
  90510. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  90511. +#endif
  90512. + gintsts_data_t gintr_status;
  90513. + int32_t retval = 0;
  90514. +
  90515. + /* Exit from ISR if core is hibernated */
  90516. + if (core_if->hibernation_suspend == 1) {
  90517. + return retval;
  90518. + }
  90519. +#ifdef VERBOSE
  90520. + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
  90521. + __func__,
  90522. + DWC_READ_REG32(&global_regs->gintsts),
  90523. + DWC_READ_REG32(&global_regs->gintmsk));
  90524. +#endif
  90525. +
  90526. + if (dwc_otg_is_device_mode(core_if)) {
  90527. + DWC_SPINLOCK(pcd->lock);
  90528. +#ifdef VERBOSE
  90529. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
  90530. + __func__,
  90531. + DWC_READ_REG32(&global_regs->gintsts),
  90532. + DWC_READ_REG32(&global_regs->gintmsk));
  90533. +#endif
  90534. +
  90535. + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
  90536. +
  90537. + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
  90538. + __func__, gintr_status.d32);
  90539. +
  90540. + if (gintr_status.b.sofintr) {
  90541. + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
  90542. + }
  90543. + if (gintr_status.b.rxstsqlvl) {
  90544. + retval |=
  90545. + dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
  90546. + }
  90547. + if (gintr_status.b.nptxfempty) {
  90548. + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
  90549. + }
  90550. + if (gintr_status.b.goutnakeff) {
  90551. + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
  90552. + }
  90553. + if (gintr_status.b.i2cintr) {
  90554. + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
  90555. + }
  90556. + if (gintr_status.b.erlysuspend) {
  90557. + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
  90558. + }
  90559. + if (gintr_status.b.usbreset) {
  90560. + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
  90561. + }
  90562. + if (gintr_status.b.enumdone) {
  90563. + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
  90564. + }
  90565. + if (gintr_status.b.isooutdrop) {
  90566. + retval |=
  90567. + dwc_otg_pcd_handle_isoc_out_packet_dropped_intr
  90568. + (pcd);
  90569. + }
  90570. + if (gintr_status.b.eopframe) {
  90571. + retval |=
  90572. + dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
  90573. + }
  90574. + if (gintr_status.b.inepint) {
  90575. + if (!core_if->multiproc_int_enable) {
  90576. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  90577. + }
  90578. + }
  90579. + if (gintr_status.b.outepintr) {
  90580. + if (!core_if->multiproc_int_enable) {
  90581. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  90582. + }
  90583. + }
  90584. + if (gintr_status.b.epmismatch) {
  90585. + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(pcd);
  90586. + }
  90587. + if (gintr_status.b.fetsusp) {
  90588. + retval |= dwc_otg_pcd_handle_ep_fetsusp_intr(pcd);
  90589. + }
  90590. + if (gintr_status.b.ginnakeff) {
  90591. + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
  90592. + }
  90593. + if (gintr_status.b.incomplisoin) {
  90594. + retval |=
  90595. + dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
  90596. + }
  90597. + if (gintr_status.b.incomplisoout) {
  90598. + retval |=
  90599. + dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
  90600. + }
  90601. +
  90602. + /* In MPI mode Device Endpoints interrupts are asserted
  90603. + * without setting outepintr and inepint bits set, so these
  90604. + * Interrupt handlers are called without checking these bit-fields
  90605. + */
  90606. + if (core_if->multiproc_int_enable) {
  90607. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  90608. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  90609. + }
  90610. +#ifdef VERBOSE
  90611. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
  90612. + DWC_READ_REG32(&global_regs->gintsts));
  90613. +#endif
  90614. + DWC_SPINUNLOCK(pcd->lock);
  90615. + }
  90616. + return retval;
  90617. +}
  90618. +
  90619. +#endif /* DWC_HOST_ONLY */
  90620. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  90621. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  90622. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 2014-04-24 16:04:39.823124292 +0200
  90623. @@ -0,0 +1,1358 @@
  90624. + /* ==========================================================================
  90625. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
  90626. + * $Revision: #21 $
  90627. + * $Date: 2012/08/10 $
  90628. + * $Change: 2047372 $
  90629. + *
  90630. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  90631. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  90632. + * otherwise expressly agreed to in writing between Synopsys and you.
  90633. + *
  90634. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  90635. + * any End User Software License Agreement or Agreement for Licensed Product
  90636. + * with Synopsys or any supplement thereto. You are permitted to use and
  90637. + * redistribute this Software in source and binary forms, with or without
  90638. + * modification, provided that redistributions of source code must retain this
  90639. + * notice. You may not view, use, disclose, copy or distribute this file or
  90640. + * any information contained herein except pursuant to this license grant from
  90641. + * Synopsys. If you do not agree with this notice, including the disclaimer
  90642. + * below, then you are not authorized to use the Software.
  90643. + *
  90644. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  90645. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  90646. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  90647. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  90648. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  90649. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  90650. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  90651. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  90652. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  90653. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  90654. + * DAMAGE.
  90655. + * ========================================================================== */
  90656. +#ifndef DWC_HOST_ONLY
  90657. +
  90658. +/** @file
  90659. + * This file implements the Peripheral Controller Driver.
  90660. + *
  90661. + * The Peripheral Controller Driver (PCD) is responsible for
  90662. + * translating requests from the Function Driver into the appropriate
  90663. + * actions on the DWC_otg controller. It isolates the Function Driver
  90664. + * from the specifics of the controller by providing an API to the
  90665. + * Function Driver.
  90666. + *
  90667. + * The Peripheral Controller Driver for Linux will implement the
  90668. + * Gadget API, so that the existing Gadget drivers can be used.
  90669. + * (Gadget Driver is the Linux terminology for a Function Driver.)
  90670. + *
  90671. + * The Linux Gadget API is defined in the header file
  90672. + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
  90673. + * defined in the structure <code>usb_ep_ops</code> and the USB
  90674. + * Controller API is defined in the structure
  90675. + * <code>usb_gadget_ops</code>.
  90676. + *
  90677. + */
  90678. +
  90679. +#include "dwc_otg_os_dep.h"
  90680. +#include "dwc_otg_pcd_if.h"
  90681. +#include "dwc_otg_pcd.h"
  90682. +#include "dwc_otg_driver.h"
  90683. +#include "dwc_otg_dbg.h"
  90684. +
  90685. +static struct gadget_wrapper {
  90686. + dwc_otg_pcd_t *pcd;
  90687. +
  90688. + struct usb_gadget gadget;
  90689. + struct usb_gadget_driver *driver;
  90690. +
  90691. + struct usb_ep ep0;
  90692. + struct usb_ep in_ep[16];
  90693. + struct usb_ep out_ep[16];
  90694. +
  90695. +} *gadget_wrapper;
  90696. +
  90697. +/* Display the contents of the buffer */
  90698. +extern void dump_msg(const u8 * buf, unsigned int length);
  90699. +/**
  90700. + * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
  90701. + * if the endpoint is not found
  90702. + */
  90703. +static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  90704. +{
  90705. + int i;
  90706. + if (pcd->ep0.priv == handle) {
  90707. + return &pcd->ep0;
  90708. + }
  90709. +
  90710. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  90711. + if (pcd->in_ep[i].priv == handle)
  90712. + return &pcd->in_ep[i];
  90713. + if (pcd->out_ep[i].priv == handle)
  90714. + return &pcd->out_ep[i];
  90715. + }
  90716. +
  90717. + return NULL;
  90718. +}
  90719. +
  90720. +/* USB Endpoint Operations */
  90721. +/*
  90722. + * The following sections briefly describe the behavior of the Gadget
  90723. + * API endpoint operations implemented in the DWC_otg driver
  90724. + * software. Detailed descriptions of the generic behavior of each of
  90725. + * these functions can be found in the Linux header file
  90726. + * include/linux/usb_gadget.h.
  90727. + *
  90728. + * The Gadget API provides wrapper functions for each of the function
  90729. + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
  90730. + * function, which then calls the underlying PCD function. The
  90731. + * following sections are named according to the wrapper
  90732. + * functions. Within each section, the corresponding DWC_otg PCD
  90733. + * function name is specified.
  90734. + *
  90735. + */
  90736. +
  90737. +/**
  90738. + * This function is called by the Gadget Driver for each EP to be
  90739. + * configured for the current configuration (SET_CONFIGURATION).
  90740. + *
  90741. + * This function initializes the dwc_otg_ep_t data structure, and then
  90742. + * calls dwc_otg_ep_activate.
  90743. + */
  90744. +static int ep_enable(struct usb_ep *usb_ep,
  90745. + const struct usb_endpoint_descriptor *ep_desc)
  90746. +{
  90747. + int retval;
  90748. +
  90749. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
  90750. +
  90751. + if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
  90752. + DWC_WARN("%s, bad ep or descriptor\n", __func__);
  90753. + return -EINVAL;
  90754. + }
  90755. + if (usb_ep == &gadget_wrapper->ep0) {
  90756. + DWC_WARN("%s, bad ep(0)\n", __func__);
  90757. + return -EINVAL;
  90758. + }
  90759. +
  90760. + /* Check FIFO size? */
  90761. + if (!ep_desc->wMaxPacketSize) {
  90762. + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
  90763. + return -ERANGE;
  90764. + }
  90765. +
  90766. + if (!gadget_wrapper->driver ||
  90767. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  90768. + DWC_WARN("%s, bogus device state\n", __func__);
  90769. + return -ESHUTDOWN;
  90770. + }
  90771. +
  90772. + /* Delete after check - MAS */
  90773. +#if 0
  90774. + nat = (uint32_t) ep_desc->wMaxPacketSize;
  90775. + printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
  90776. + nat = (nat >> 11) & 0x03;
  90777. + printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
  90778. +#endif
  90779. + retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
  90780. + (const uint8_t *)ep_desc,
  90781. + (void *)usb_ep);
  90782. + if (retval) {
  90783. + DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
  90784. + return -EINVAL;
  90785. + }
  90786. +
  90787. + usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
  90788. +
  90789. + return 0;
  90790. +}
  90791. +
  90792. +/**
  90793. + * This function is called when an EP is disabled due to disconnect or
  90794. + * change in configuration. Any pending requests will terminate with a
  90795. + * status of -ESHUTDOWN.
  90796. + *
  90797. + * This function modifies the dwc_otg_ep_t data structure for this EP,
  90798. + * and then calls dwc_otg_ep_deactivate.
  90799. + */
  90800. +static int ep_disable(struct usb_ep *usb_ep)
  90801. +{
  90802. + int retval;
  90803. +
  90804. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
  90805. + if (!usb_ep) {
  90806. + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
  90807. + usb_ep ? usb_ep->name : NULL);
  90808. + return -EINVAL;
  90809. + }
  90810. +
  90811. + retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
  90812. + if (retval) {
  90813. + retval = -EINVAL;
  90814. + }
  90815. +
  90816. + return retval;
  90817. +}
  90818. +
  90819. +/**
  90820. + * This function allocates a request object to use with the specified
  90821. + * endpoint.
  90822. + *
  90823. + * @param ep The endpoint to be used with with the request
  90824. + * @param gfp_flags the GFP_* flags to use.
  90825. + */
  90826. +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
  90827. + gfp_t gfp_flags)
  90828. +{
  90829. + struct usb_request *usb_req;
  90830. +
  90831. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
  90832. + if (0 == ep) {
  90833. + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
  90834. + return 0;
  90835. + }
  90836. + usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
  90837. + if (0 == usb_req) {
  90838. + DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
  90839. + return 0;
  90840. + }
  90841. + memset(usb_req, 0, sizeof(*usb_req));
  90842. + usb_req->dma = DWC_DMA_ADDR_INVALID;
  90843. +
  90844. + return usb_req;
  90845. +}
  90846. +
  90847. +/**
  90848. + * This function frees a request object.
  90849. + *
  90850. + * @param ep The endpoint associated with the request
  90851. + * @param req The request being freed
  90852. + */
  90853. +static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
  90854. +{
  90855. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
  90856. +
  90857. + if (0 == ep || 0 == req) {
  90858. + DWC_WARN("%s() %s\n", __func__,
  90859. + "Invalid ep or req argument!\n");
  90860. + return;
  90861. + }
  90862. +
  90863. + kfree(req);
  90864. +}
  90865. +
  90866. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  90867. +/**
  90868. + * This function allocates an I/O buffer to be used for a transfer
  90869. + * to/from the specified endpoint.
  90870. + *
  90871. + * @param usb_ep The endpoint to be used with with the request
  90872. + * @param bytes The desired number of bytes for the buffer
  90873. + * @param dma Pointer to the buffer's DMA address; must be valid
  90874. + * @param gfp_flags the GFP_* flags to use.
  90875. + * @return address of a new buffer or null is buffer could not be allocated.
  90876. + */
  90877. +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
  90878. + dma_addr_t * dma, gfp_t gfp_flags)
  90879. +{
  90880. + void *buf;
  90881. + dwc_otg_pcd_t *pcd = 0;
  90882. +
  90883. + pcd = gadget_wrapper->pcd;
  90884. +
  90885. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
  90886. + dma, gfp_flags);
  90887. +
  90888. + /* Check dword alignment */
  90889. + if ((bytes & 0x3UL) != 0) {
  90890. + DWC_WARN("%s() Buffer size is not a multiple of"
  90891. + "DWORD size (%d)", __func__, bytes);
  90892. + }
  90893. +
  90894. + buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
  90895. +
  90896. + /* Check dword alignment */
  90897. + if (((int)buf & 0x3UL) != 0) {
  90898. + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
  90899. + __func__, buf);
  90900. + }
  90901. +
  90902. + return buf;
  90903. +}
  90904. +
  90905. +/**
  90906. + * This function frees an I/O buffer that was allocated by alloc_buffer.
  90907. + *
  90908. + * @param usb_ep the endpoint associated with the buffer
  90909. + * @param buf address of the buffer
  90910. + * @param dma The buffer's DMA address
  90911. + * @param bytes The number of bytes of the buffer
  90912. + */
  90913. +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
  90914. + dma_addr_t dma, unsigned bytes)
  90915. +{
  90916. + dwc_otg_pcd_t *pcd = 0;
  90917. +
  90918. + pcd = gadget_wrapper->pcd;
  90919. +
  90920. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
  90921. +
  90922. + dma_free_coherent(NULL, bytes, buf, dma);
  90923. +}
  90924. +#endif
  90925. +
  90926. +/**
  90927. + * This function is used to submit an I/O Request to an EP.
  90928. + *
  90929. + * - When the request completes the request's completion callback
  90930. + * is called to return the request to the driver.
  90931. + * - An EP, except control EPs, may have multiple requests
  90932. + * pending.
  90933. + * - Once submitted the request cannot be examined or modified.
  90934. + * - Each request is turned into one or more packets.
  90935. + * - A BULK EP can queue any amount of data; the transfer is
  90936. + * packetized.
  90937. + * - Zero length Packets are specified with the request 'zero'
  90938. + * flag.
  90939. + */
  90940. +static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
  90941. + gfp_t gfp_flags)
  90942. +{
  90943. + dwc_otg_pcd_t *pcd;
  90944. + struct dwc_otg_pcd_ep *ep = NULL;
  90945. + int retval = 0, is_isoc_ep = 0;
  90946. + dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
  90947. +
  90948. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
  90949. + __func__, usb_ep, usb_req, gfp_flags);
  90950. +
  90951. + if (!usb_req || !usb_req->complete || !usb_req->buf) {
  90952. + DWC_WARN("bad params\n");
  90953. + return -EINVAL;
  90954. + }
  90955. +
  90956. + if (!usb_ep) {
  90957. + DWC_WARN("bad ep\n");
  90958. + return -EINVAL;
  90959. + }
  90960. +
  90961. + pcd = gadget_wrapper->pcd;
  90962. + if (!gadget_wrapper->driver ||
  90963. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  90964. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  90965. + gadget_wrapper->gadget.speed);
  90966. + DWC_WARN("bogus device state\n");
  90967. + return -ESHUTDOWN;
  90968. + }
  90969. +
  90970. + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
  90971. + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
  90972. +
  90973. + usb_req->status = -EINPROGRESS;
  90974. + usb_req->actual = 0;
  90975. +
  90976. + ep = ep_from_handle(pcd, usb_ep);
  90977. + if (ep == NULL)
  90978. + is_isoc_ep = 0;
  90979. + else
  90980. + is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
  90981. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  90982. + dma_addr = usb_req->dma;
  90983. +#else
  90984. + if (GET_CORE_IF(pcd)->dma_enable) {
  90985. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  90986. + struct device *dev = NULL;
  90987. +
  90988. + if (otg_dev != NULL)
  90989. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  90990. +
  90991. + if (usb_req->length != 0 &&
  90992. + usb_req->dma == DWC_DMA_ADDR_INVALID) {
  90993. + dma_addr = dma_map_single(dev, usb_req->buf,
  90994. + usb_req->length,
  90995. + ep->dwc_ep.is_in ?
  90996. + DMA_TO_DEVICE:
  90997. + DMA_FROM_DEVICE);
  90998. + }
  90999. + }
  91000. +#endif
  91001. +
  91002. +#ifdef DWC_UTE_PER_IO
  91003. + if (is_isoc_ep == 1) {
  91004. + retval = dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  91005. + usb_req->length, usb_req->zero, usb_req,
  91006. + gfp_flags == GFP_ATOMIC ? 1 : 0, &usb_req->ext_req);
  91007. + if (retval)
  91008. + return -EINVAL;
  91009. +
  91010. + return 0;
  91011. + }
  91012. +#endif
  91013. + retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  91014. + usb_req->length, usb_req->zero, usb_req,
  91015. + gfp_flags == GFP_ATOMIC ? 1 : 0);
  91016. + if (retval) {
  91017. + return -EINVAL;
  91018. + }
  91019. +
  91020. + return 0;
  91021. +}
  91022. +
  91023. +/**
  91024. + * This function cancels an I/O request from an EP.
  91025. + */
  91026. +static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
  91027. +{
  91028. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
  91029. +
  91030. + if (!usb_ep || !usb_req) {
  91031. + DWC_WARN("bad argument\n");
  91032. + return -EINVAL;
  91033. + }
  91034. + if (!gadget_wrapper->driver ||
  91035. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  91036. + DWC_WARN("bogus device state\n");
  91037. + return -ESHUTDOWN;
  91038. + }
  91039. + if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
  91040. + return -EINVAL;
  91041. + }
  91042. +
  91043. + return 0;
  91044. +}
  91045. +
  91046. +/**
  91047. + * usb_ep_set_halt stalls an endpoint.
  91048. + *
  91049. + * usb_ep_clear_halt clears an endpoint halt and resets its data
  91050. + * toggle.
  91051. + *
  91052. + * Both of these functions are implemented with the same underlying
  91053. + * function. The behavior depends on the value argument.
  91054. + *
  91055. + * @param[in] usb_ep the Endpoint to halt or clear halt.
  91056. + * @param[in] value
  91057. + * - 0 means clear_halt.
  91058. + * - 1 means set_halt,
  91059. + * - 2 means clear stall lock flag.
  91060. + * - 3 means set stall lock flag.
  91061. + */
  91062. +static int ep_halt(struct usb_ep *usb_ep, int value)
  91063. +{
  91064. + int retval = 0;
  91065. +
  91066. + DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
  91067. +
  91068. + if (!usb_ep) {
  91069. + DWC_WARN("bad ep\n");
  91070. + return -EINVAL;
  91071. + }
  91072. +
  91073. + retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
  91074. + if (retval == -DWC_E_AGAIN) {
  91075. + return -EAGAIN;
  91076. + } else if (retval) {
  91077. + retval = -EINVAL;
  91078. + }
  91079. +
  91080. + return retval;
  91081. +}
  91082. +
  91083. +//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  91084. +#if 0
  91085. +/**
  91086. + * ep_wedge: sets the halt feature and ignores clear requests
  91087. + *
  91088. + * @usb_ep: the endpoint being wedged
  91089. + *
  91090. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  91091. + * requests. If the gadget driver clears the halt status, it will
  91092. + * automatically unwedge the endpoint.
  91093. + *
  91094. + * Returns zero on success, else negative errno. *
  91095. + * Check usb_ep_set_wedge() at "usb_gadget.h" for details
  91096. + */
  91097. +static int ep_wedge(struct usb_ep *usb_ep)
  91098. +{
  91099. + int retval = 0;
  91100. +
  91101. + DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
  91102. +
  91103. + if (!usb_ep) {
  91104. + DWC_WARN("bad ep\n");
  91105. + return -EINVAL;
  91106. + }
  91107. +
  91108. + retval = dwc_otg_pcd_ep_wedge(gadget_wrapper->pcd, usb_ep);
  91109. + if (retval == -DWC_E_AGAIN) {
  91110. + retval = -EAGAIN;
  91111. + } else if (retval) {
  91112. + retval = -EINVAL;
  91113. + }
  91114. +
  91115. + return retval;
  91116. +}
  91117. +#endif
  91118. +
  91119. +#ifdef DWC_EN_ISOC
  91120. +/**
  91121. + * This function is used to submit an ISOC Transfer Request to an EP.
  91122. + *
  91123. + * - Every time a sync period completes the request's completion callback
  91124. + * is called to provide data to the gadget driver.
  91125. + * - Once submitted the request cannot be modified.
  91126. + * - Each request is turned into periodic data packets untill ISO
  91127. + * Transfer is stopped..
  91128. + */
  91129. +static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
  91130. + gfp_t gfp_flags)
  91131. +{
  91132. + int retval = 0;
  91133. +
  91134. + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
  91135. + DWC_WARN("bad params\n");
  91136. + return -EINVAL;
  91137. + }
  91138. +
  91139. + if (!usb_ep) {
  91140. + DWC_PRINTF("bad params\n");
  91141. + return -EINVAL;
  91142. + }
  91143. +
  91144. + req->status = -EINPROGRESS;
  91145. +
  91146. + retval =
  91147. + dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
  91148. + req->buf1, req->dma0, req->dma1,
  91149. + req->sync_frame, req->data_pattern_frame,
  91150. + req->data_per_frame,
  91151. + req->
  91152. + flags & USB_REQ_ISO_ASAP ? -1 :
  91153. + req->start_frame, req->buf_proc_intrvl,
  91154. + req, gfp_flags == GFP_ATOMIC ? 1 : 0);
  91155. +
  91156. + if (retval) {
  91157. + return -EINVAL;
  91158. + }
  91159. +
  91160. + return retval;
  91161. +}
  91162. +
  91163. +/**
  91164. + * This function stops ISO EP Periodic Data Transfer.
  91165. + */
  91166. +static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
  91167. +{
  91168. + int retval = 0;
  91169. + if (!usb_ep) {
  91170. + DWC_WARN("bad ep\n");
  91171. + }
  91172. +
  91173. + if (!gadget_wrapper->driver ||
  91174. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  91175. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  91176. + gadget_wrapper->gadget.speed);
  91177. + DWC_WARN("bogus device state\n");
  91178. + }
  91179. +
  91180. + dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
  91181. + if (retval) {
  91182. + retval = -EINVAL;
  91183. + }
  91184. +
  91185. + return retval;
  91186. +}
  91187. +
  91188. +static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
  91189. + int packets, gfp_t gfp_flags)
  91190. +{
  91191. + struct usb_iso_request *pReq = NULL;
  91192. + uint32_t req_size;
  91193. +
  91194. + req_size = sizeof(struct usb_iso_request);
  91195. + req_size +=
  91196. + (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
  91197. +
  91198. + pReq = kmalloc(req_size, gfp_flags);
  91199. + if (!pReq) {
  91200. + DWC_WARN("Can't allocate Iso Request\n");
  91201. + return 0;
  91202. + }
  91203. + pReq->iso_packet_desc0 = (void *)(pReq + 1);
  91204. +
  91205. + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
  91206. +
  91207. + return pReq;
  91208. +}
  91209. +
  91210. +static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
  91211. +{
  91212. + kfree(req);
  91213. +}
  91214. +
  91215. +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
  91216. + .ep_ops = {
  91217. + .enable = ep_enable,
  91218. + .disable = ep_disable,
  91219. +
  91220. + .alloc_request = dwc_otg_pcd_alloc_request,
  91221. + .free_request = dwc_otg_pcd_free_request,
  91222. +
  91223. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  91224. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  91225. + .free_buffer = dwc_otg_pcd_free_buffer,
  91226. +#endif
  91227. +
  91228. + .queue = ep_queue,
  91229. + .dequeue = ep_dequeue,
  91230. +
  91231. + .set_halt = ep_halt,
  91232. + .fifo_status = 0,
  91233. + .fifo_flush = 0,
  91234. + },
  91235. + .iso_ep_start = iso_ep_start,
  91236. + .iso_ep_stop = iso_ep_stop,
  91237. + .alloc_iso_request = alloc_iso_request,
  91238. + .free_iso_request = free_iso_request,
  91239. +};
  91240. +
  91241. +#else
  91242. +
  91243. + int (*enable) (struct usb_ep *ep,
  91244. + const struct usb_endpoint_descriptor *desc);
  91245. + int (*disable) (struct usb_ep *ep);
  91246. +
  91247. + struct usb_request *(*alloc_request) (struct usb_ep *ep,
  91248. + gfp_t gfp_flags);
  91249. + void (*free_request) (struct usb_ep *ep, struct usb_request *req);
  91250. +
  91251. + int (*queue) (struct usb_ep *ep, struct usb_request *req,
  91252. + gfp_t gfp_flags);
  91253. + int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
  91254. +
  91255. + int (*set_halt) (struct usb_ep *ep, int value);
  91256. + int (*set_wedge) (struct usb_ep *ep);
  91257. +
  91258. + int (*fifo_status) (struct usb_ep *ep);
  91259. + void (*fifo_flush) (struct usb_ep *ep);
  91260. +static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
  91261. + .enable = ep_enable,
  91262. + .disable = ep_disable,
  91263. +
  91264. + .alloc_request = dwc_otg_pcd_alloc_request,
  91265. + .free_request = dwc_otg_pcd_free_request,
  91266. +
  91267. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  91268. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  91269. + .free_buffer = dwc_otg_pcd_free_buffer,
  91270. +#else
  91271. + /* .set_wedge = ep_wedge, */
  91272. + .set_wedge = NULL, /* uses set_halt instead */
  91273. +#endif
  91274. +
  91275. + .queue = ep_queue,
  91276. + .dequeue = ep_dequeue,
  91277. +
  91278. + .set_halt = ep_halt,
  91279. + .fifo_status = 0,
  91280. + .fifo_flush = 0,
  91281. +
  91282. +};
  91283. +
  91284. +#endif /* _EN_ISOC_ */
  91285. +/* Gadget Operations */
  91286. +/**
  91287. + * The following gadget operations will be implemented in the DWC_otg
  91288. + * PCD. Functions in the API that are not described below are not
  91289. + * implemented.
  91290. + *
  91291. + * The Gadget API provides wrapper functions for each of the function
  91292. + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
  91293. + * wrapper function, which then calls the underlying PCD function. The
  91294. + * following sections are named according to the wrapper functions
  91295. + * (except for ioctl, which doesn't have a wrapper function). Within
  91296. + * each section, the corresponding DWC_otg PCD function name is
  91297. + * specified.
  91298. + *
  91299. + */
  91300. +
  91301. +/**
  91302. + *Gets the USB Frame number of the last SOF.
  91303. + */
  91304. +static int get_frame_number(struct usb_gadget *gadget)
  91305. +{
  91306. + struct gadget_wrapper *d;
  91307. +
  91308. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  91309. +
  91310. + if (gadget == 0) {
  91311. + return -ENODEV;
  91312. + }
  91313. +
  91314. + d = container_of(gadget, struct gadget_wrapper, gadget);
  91315. + return dwc_otg_pcd_get_frame_number(d->pcd);
  91316. +}
  91317. +
  91318. +#ifdef CONFIG_USB_DWC_OTG_LPM
  91319. +static int test_lpm_enabled(struct usb_gadget *gadget)
  91320. +{
  91321. + struct gadget_wrapper *d;
  91322. +
  91323. + d = container_of(gadget, struct gadget_wrapper, gadget);
  91324. +
  91325. + return dwc_otg_pcd_is_lpm_enabled(d->pcd);
  91326. +}
  91327. +#endif
  91328. +
  91329. +/**
  91330. + * Initiates Session Request Protocol (SRP) to wakeup the host if no
  91331. + * session is in progress. If a session is already in progress, but
  91332. + * the device is suspended, remote wakeup signaling is started.
  91333. + *
  91334. + */
  91335. +static int wakeup(struct usb_gadget *gadget)
  91336. +{
  91337. + struct gadget_wrapper *d;
  91338. +
  91339. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  91340. +
  91341. + if (gadget == 0) {
  91342. + return -ENODEV;
  91343. + } else {
  91344. + d = container_of(gadget, struct gadget_wrapper, gadget);
  91345. + }
  91346. + dwc_otg_pcd_wakeup(d->pcd);
  91347. + return 0;
  91348. +}
  91349. +
  91350. +static const struct usb_gadget_ops dwc_otg_pcd_ops = {
  91351. + .get_frame = get_frame_number,
  91352. + .wakeup = wakeup,
  91353. +#ifdef CONFIG_USB_DWC_OTG_LPM
  91354. + .lpm_support = test_lpm_enabled,
  91355. +#endif
  91356. + // current versions must always be self-powered
  91357. +};
  91358. +
  91359. +static int _setup(dwc_otg_pcd_t * pcd, uint8_t * bytes)
  91360. +{
  91361. + int retval = -DWC_E_NOT_SUPPORTED;
  91362. + if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
  91363. + retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
  91364. + (struct usb_ctrlrequest
  91365. + *)bytes);
  91366. + }
  91367. +
  91368. + if (retval == -ENOTSUPP) {
  91369. + retval = -DWC_E_NOT_SUPPORTED;
  91370. + } else if (retval < 0) {
  91371. + retval = -DWC_E_INVALID;
  91372. + }
  91373. +
  91374. + return retval;
  91375. +}
  91376. +
  91377. +#ifdef DWC_EN_ISOC
  91378. +static int _isoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  91379. + void *req_handle, int proc_buf_num)
  91380. +{
  91381. + int i, packet_count;
  91382. + struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
  91383. + struct usb_iso_request *iso_req = req_handle;
  91384. +
  91385. + if (proc_buf_num) {
  91386. + iso_packet = iso_req->iso_packet_desc1;
  91387. + } else {
  91388. + iso_packet = iso_req->iso_packet_desc0;
  91389. + }
  91390. + packet_count =
  91391. + dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
  91392. + for (i = 0; i < packet_count; ++i) {
  91393. + int status;
  91394. + int actual;
  91395. + int offset;
  91396. + dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
  91397. + i, &status, &actual, &offset);
  91398. + switch (status) {
  91399. + case -DWC_E_NO_DATA:
  91400. + status = -ENODATA;
  91401. + break;
  91402. + default:
  91403. + if (status) {
  91404. + DWC_PRINTF("unknown status in isoc packet\n");
  91405. + }
  91406. +
  91407. + }
  91408. + iso_packet[i].status = status;
  91409. + iso_packet[i].offset = offset;
  91410. + iso_packet[i].actual_length = actual;
  91411. + }
  91412. +
  91413. + iso_req->status = 0;
  91414. + iso_req->process_buffer(ep_handle, iso_req);
  91415. +
  91416. + return 0;
  91417. +}
  91418. +#endif /* DWC_EN_ISOC */
  91419. +
  91420. +#ifdef DWC_UTE_PER_IO
  91421. +/**
  91422. + * Copy the contents of the extended request to the Linux usb_request's
  91423. + * extended part and call the gadget's completion.
  91424. + *
  91425. + * @param pcd Pointer to the pcd structure
  91426. + * @param ep_handle Void pointer to the usb_ep structure
  91427. + * @param req_handle Void pointer to the usb_request structure
  91428. + * @param status Request status returned from the portable logic
  91429. + * @param ereq_port Void pointer to the extended request structure
  91430. + * created in the the portable part that contains the
  91431. + * results of the processed iso packets.
  91432. + */
  91433. +static int _xisoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  91434. + void *req_handle, int32_t status, void *ereq_port)
  91435. +{
  91436. + struct dwc_ute_iso_req_ext *ereqorg = NULL;
  91437. + struct dwc_iso_xreq_port *ereqport = NULL;
  91438. + struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
  91439. + int i;
  91440. + struct usb_request *req;
  91441. + //struct dwc_ute_iso_packet_descriptor *
  91442. + //int status = 0;
  91443. +
  91444. + req = (struct usb_request *)req_handle;
  91445. + ereqorg = &req->ext_req;
  91446. + ereqport = (struct dwc_iso_xreq_port *)ereq_port;
  91447. + desc_org = ereqorg->per_io_frame_descs;
  91448. +
  91449. + if (req && req->complete) {
  91450. + /* Copy the request data from the portable logic to our request */
  91451. + for (i = 0; i < ereqport->pio_pkt_count; i++) {
  91452. + desc_org[i].actual_length =
  91453. + ereqport->per_io_frame_descs[i].actual_length;
  91454. + desc_org[i].status =
  91455. + ereqport->per_io_frame_descs[i].status;
  91456. + }
  91457. +
  91458. + switch (status) {
  91459. + case -DWC_E_SHUTDOWN:
  91460. + req->status = -ESHUTDOWN;
  91461. + break;
  91462. + case -DWC_E_RESTART:
  91463. + req->status = -ECONNRESET;
  91464. + break;
  91465. + case -DWC_E_INVALID:
  91466. + req->status = -EINVAL;
  91467. + break;
  91468. + case -DWC_E_TIMEOUT:
  91469. + req->status = -ETIMEDOUT;
  91470. + break;
  91471. + default:
  91472. + req->status = status;
  91473. + }
  91474. +
  91475. + /* And call the gadget's completion */
  91476. + req->complete(ep_handle, req);
  91477. + }
  91478. +
  91479. + return 0;
  91480. +}
  91481. +#endif /* DWC_UTE_PER_IO */
  91482. +
  91483. +static int _complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  91484. + void *req_handle, int32_t status, uint32_t actual)
  91485. +{
  91486. + struct usb_request *req = (struct usb_request *)req_handle;
  91487. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  91488. + struct dwc_otg_pcd_ep *ep = NULL;
  91489. +#endif
  91490. +
  91491. + if (req && req->complete) {
  91492. + switch (status) {
  91493. + case -DWC_E_SHUTDOWN:
  91494. + req->status = -ESHUTDOWN;
  91495. + break;
  91496. + case -DWC_E_RESTART:
  91497. + req->status = -ECONNRESET;
  91498. + break;
  91499. + case -DWC_E_INVALID:
  91500. + req->status = -EINVAL;
  91501. + break;
  91502. + case -DWC_E_TIMEOUT:
  91503. + req->status = -ETIMEDOUT;
  91504. + break;
  91505. + default:
  91506. + req->status = status;
  91507. +
  91508. + }
  91509. +
  91510. + req->actual = actual;
  91511. + DWC_SPINUNLOCK(pcd->lock);
  91512. + req->complete(ep_handle, req);
  91513. + DWC_SPINLOCK(pcd->lock);
  91514. + }
  91515. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  91516. + ep = ep_from_handle(pcd, ep_handle);
  91517. + if (GET_CORE_IF(pcd)->dma_enable) {
  91518. + if (req->length != 0) {
  91519. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  91520. + struct device *dev = NULL;
  91521. +
  91522. + if (otg_dev != NULL)
  91523. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  91524. +
  91525. + dma_unmap_single(dev, req->dma, req->length,
  91526. + ep->dwc_ep.is_in ?
  91527. + DMA_TO_DEVICE: DMA_FROM_DEVICE);
  91528. + }
  91529. + }
  91530. +#endif
  91531. +
  91532. + return 0;
  91533. +}
  91534. +
  91535. +static int _connect(dwc_otg_pcd_t * pcd, int speed)
  91536. +{
  91537. + gadget_wrapper->gadget.speed = speed;
  91538. + return 0;
  91539. +}
  91540. +
  91541. +static int _disconnect(dwc_otg_pcd_t * pcd)
  91542. +{
  91543. + if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
  91544. + gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
  91545. + }
  91546. + return 0;
  91547. +}
  91548. +
  91549. +static int _resume(dwc_otg_pcd_t * pcd)
  91550. +{
  91551. + if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
  91552. + gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
  91553. + }
  91554. +
  91555. + return 0;
  91556. +}
  91557. +
  91558. +static int _suspend(dwc_otg_pcd_t * pcd)
  91559. +{
  91560. + if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
  91561. + gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
  91562. + }
  91563. + return 0;
  91564. +}
  91565. +
  91566. +/**
  91567. + * This function updates the otg values in the gadget structure.
  91568. + */
  91569. +static int _hnp_changed(dwc_otg_pcd_t * pcd)
  91570. +{
  91571. +
  91572. + if (!gadget_wrapper->gadget.is_otg)
  91573. + return 0;
  91574. +
  91575. + gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
  91576. + gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
  91577. + gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
  91578. + return 0;
  91579. +}
  91580. +
  91581. +static int _reset(dwc_otg_pcd_t * pcd)
  91582. +{
  91583. + return 0;
  91584. +}
  91585. +
  91586. +#ifdef DWC_UTE_CFI
  91587. +static int _cfi_setup(dwc_otg_pcd_t * pcd, void *cfi_req)
  91588. +{
  91589. + int retval = -DWC_E_INVALID;
  91590. + if (gadget_wrapper->driver->cfi_feature_setup) {
  91591. + retval =
  91592. + gadget_wrapper->driver->
  91593. + cfi_feature_setup(&gadget_wrapper->gadget,
  91594. + (struct cfi_usb_ctrlrequest *)cfi_req);
  91595. + }
  91596. +
  91597. + return retval;
  91598. +}
  91599. +#endif
  91600. +
  91601. +static const struct dwc_otg_pcd_function_ops fops = {
  91602. + .complete = _complete,
  91603. +#ifdef DWC_EN_ISOC
  91604. + .isoc_complete = _isoc_complete,
  91605. +#endif
  91606. + .setup = _setup,
  91607. + .disconnect = _disconnect,
  91608. + .connect = _connect,
  91609. + .resume = _resume,
  91610. + .suspend = _suspend,
  91611. + .hnp_changed = _hnp_changed,
  91612. + .reset = _reset,
  91613. +#ifdef DWC_UTE_CFI
  91614. + .cfi_setup = _cfi_setup,
  91615. +#endif
  91616. +#ifdef DWC_UTE_PER_IO
  91617. + .xisoc_complete = _xisoc_complete,
  91618. +#endif
  91619. +};
  91620. +
  91621. +/**
  91622. + * This function is the top level PCD interrupt handler.
  91623. + */
  91624. +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
  91625. +{
  91626. + dwc_otg_pcd_t *pcd = dev;
  91627. + int32_t retval = IRQ_NONE;
  91628. +
  91629. + retval = dwc_otg_pcd_handle_intr(pcd);
  91630. + if (retval != 0) {
  91631. + S3C2410X_CLEAR_EINTPEND();
  91632. + }
  91633. + return IRQ_RETVAL(retval);
  91634. +}
  91635. +
  91636. +/**
  91637. + * This function initialized the usb_ep structures to there default
  91638. + * state.
  91639. + *
  91640. + * @param d Pointer on gadget_wrapper.
  91641. + */
  91642. +void gadget_add_eps(struct gadget_wrapper *d)
  91643. +{
  91644. + static const char *names[] = {
  91645. +
  91646. + "ep0",
  91647. + "ep1in",
  91648. + "ep2in",
  91649. + "ep3in",
  91650. + "ep4in",
  91651. + "ep5in",
  91652. + "ep6in",
  91653. + "ep7in",
  91654. + "ep8in",
  91655. + "ep9in",
  91656. + "ep10in",
  91657. + "ep11in",
  91658. + "ep12in",
  91659. + "ep13in",
  91660. + "ep14in",
  91661. + "ep15in",
  91662. + "ep1out",
  91663. + "ep2out",
  91664. + "ep3out",
  91665. + "ep4out",
  91666. + "ep5out",
  91667. + "ep6out",
  91668. + "ep7out",
  91669. + "ep8out",
  91670. + "ep9out",
  91671. + "ep10out",
  91672. + "ep11out",
  91673. + "ep12out",
  91674. + "ep13out",
  91675. + "ep14out",
  91676. + "ep15out"
  91677. + };
  91678. +
  91679. + int i;
  91680. + struct usb_ep *ep;
  91681. + int8_t dev_endpoints;
  91682. +
  91683. + DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
  91684. +
  91685. + INIT_LIST_HEAD(&d->gadget.ep_list);
  91686. + d->gadget.ep0 = &d->ep0;
  91687. + d->gadget.speed = USB_SPEED_UNKNOWN;
  91688. +
  91689. + INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
  91690. +
  91691. + /**
  91692. + * Initialize the EP0 structure.
  91693. + */
  91694. + ep = &d->ep0;
  91695. +
  91696. + /* Init the usb_ep structure. */
  91697. + ep->name = names[0];
  91698. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  91699. +
  91700. + /**
  91701. + * @todo NGS: What should the max packet size be set to
  91702. + * here? Before EP type is set?
  91703. + */
  91704. + ep->maxpacket = MAX_PACKET_SIZE;
  91705. + dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
  91706. +
  91707. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  91708. +
  91709. + /**
  91710. + * Initialize the EP structures.
  91711. + */
  91712. + dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
  91713. +
  91714. + for (i = 0; i < dev_endpoints; i++) {
  91715. + ep = &d->in_ep[i];
  91716. +
  91717. + /* Init the usb_ep structure. */
  91718. + ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
  91719. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  91720. +
  91721. + /**
  91722. + * @todo NGS: What should the max packet size be set to
  91723. + * here? Before EP type is set?
  91724. + */
  91725. + ep->maxpacket = MAX_PACKET_SIZE;
  91726. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  91727. + }
  91728. +
  91729. + dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
  91730. +
  91731. + for (i = 0; i < dev_endpoints; i++) {
  91732. + ep = &d->out_ep[i];
  91733. +
  91734. + /* Init the usb_ep structure. */
  91735. + ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
  91736. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  91737. +
  91738. + /**
  91739. + * @todo NGS: What should the max packet size be set to
  91740. + * here? Before EP type is set?
  91741. + */
  91742. + ep->maxpacket = MAX_PACKET_SIZE;
  91743. +
  91744. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  91745. + }
  91746. +
  91747. + /* remove ep0 from the list. There is a ep0 pointer. */
  91748. + list_del_init(&d->ep0.ep_list);
  91749. +
  91750. + d->ep0.maxpacket = MAX_EP0_SIZE;
  91751. +}
  91752. +
  91753. +/**
  91754. + * This function releases the Gadget device.
  91755. + * required by device_unregister().
  91756. + *
  91757. + * @todo Should this do something? Should it free the PCD?
  91758. + */
  91759. +static void dwc_otg_pcd_gadget_release(struct device *dev)
  91760. +{
  91761. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
  91762. +}
  91763. +
  91764. +static struct gadget_wrapper *alloc_wrapper(dwc_bus_dev_t *_dev)
  91765. +{
  91766. + static char pcd_name[] = "dwc_otg_pcd";
  91767. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  91768. + struct gadget_wrapper *d;
  91769. + int retval;
  91770. +
  91771. + d = DWC_ALLOC(sizeof(*d));
  91772. + if (d == NULL) {
  91773. + return NULL;
  91774. + }
  91775. +
  91776. + memset(d, 0, sizeof(*d));
  91777. +
  91778. + d->gadget.name = pcd_name;
  91779. + d->pcd = otg_dev->pcd;
  91780. +
  91781. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  91782. + strcpy(d->gadget.dev.bus_id, "gadget");
  91783. +#else
  91784. + dev_set_name(&d->gadget.dev, "%s", "gadget");
  91785. +#endif
  91786. +
  91787. + d->gadget.dev.parent = &_dev->dev;
  91788. + d->gadget.dev.release = dwc_otg_pcd_gadget_release;
  91789. + d->gadget.ops = &dwc_otg_pcd_ops;
  91790. + d->gadget.max_speed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd) ? USB_SPEED_HIGH:USB_SPEED_FULL;
  91791. + d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
  91792. +
  91793. + d->driver = 0;
  91794. + /* Register the gadget device */
  91795. + retval = device_register(&d->gadget.dev);
  91796. + if (retval != 0) {
  91797. + DWC_ERROR("device_register failed\n");
  91798. + DWC_FREE(d);
  91799. + return NULL;
  91800. + }
  91801. +
  91802. + return d;
  91803. +}
  91804. +
  91805. +static void free_wrapper(struct gadget_wrapper *d)
  91806. +{
  91807. + if (d->driver) {
  91808. + /* should have been done already by driver model core */
  91809. + DWC_WARN("driver '%s' is still registered\n",
  91810. + d->driver->driver.name);
  91811. + usb_gadget_unregister_driver(d->driver);
  91812. + }
  91813. +
  91814. + device_unregister(&d->gadget.dev);
  91815. + DWC_FREE(d);
  91816. +}
  91817. +
  91818. +/**
  91819. + * This function initialized the PCD portion of the driver.
  91820. + *
  91821. + */
  91822. +int pcd_init(dwc_bus_dev_t *_dev)
  91823. +{
  91824. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  91825. + int retval = 0;
  91826. +
  91827. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev=%p\n", __func__, _dev, otg_dev);
  91828. +
  91829. + otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
  91830. +
  91831. + if (!otg_dev->pcd) {
  91832. + DWC_ERROR("dwc_otg_pcd_init failed\n");
  91833. + return -ENOMEM;
  91834. + }
  91835. +
  91836. + otg_dev->pcd->otg_dev = otg_dev;
  91837. + gadget_wrapper = alloc_wrapper(_dev);
  91838. +
  91839. + /*
  91840. + * Initialize EP structures
  91841. + */
  91842. + gadget_add_eps(gadget_wrapper);
  91843. + /*
  91844. + * Setup interupt handler
  91845. + */
  91846. +#ifdef PLATFORM_INTERFACE
  91847. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  91848. + platform_get_irq(_dev, 0));
  91849. + retval = request_irq(platform_get_irq(_dev, 0), dwc_otg_pcd_irq,
  91850. + IRQF_SHARED, gadget_wrapper->gadget.name,
  91851. + otg_dev->pcd);
  91852. + if (retval != 0) {
  91853. + DWC_ERROR("request of irq%d failed\n",
  91854. + platform_get_irq(_dev, 0));
  91855. + free_wrapper(gadget_wrapper);
  91856. + return -EBUSY;
  91857. + }
  91858. +#else
  91859. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  91860. + _dev->irq);
  91861. + retval = request_irq(_dev->irq, dwc_otg_pcd_irq,
  91862. + IRQF_SHARED | IRQF_DISABLED,
  91863. + gadget_wrapper->gadget.name, otg_dev->pcd);
  91864. + if (retval != 0) {
  91865. + DWC_ERROR("request of irq%d failed\n", _dev->irq);
  91866. + free_wrapper(gadget_wrapper);
  91867. + return -EBUSY;
  91868. + }
  91869. +#endif
  91870. +
  91871. + dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
  91872. +
  91873. + return retval;
  91874. +}
  91875. +
  91876. +/**
  91877. + * Cleanup the PCD.
  91878. + */
  91879. +void pcd_remove(dwc_bus_dev_t *_dev)
  91880. +{
  91881. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  91882. + dwc_otg_pcd_t *pcd = otg_dev->pcd;
  91883. +
  91884. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  91885. +
  91886. + /*
  91887. + * Free the IRQ
  91888. + */
  91889. +#ifdef PLATFORM_INTERFACE
  91890. + free_irq(platform_get_irq(_dev, 0), pcd);
  91891. +#else
  91892. + free_irq(_dev->irq, pcd);
  91893. +#endif
  91894. + dwc_otg_pcd_remove(otg_dev->pcd);
  91895. + free_wrapper(gadget_wrapper);
  91896. + otg_dev->pcd = 0;
  91897. +}
  91898. +
  91899. +/**
  91900. + * This function registers a gadget driver with the PCD.
  91901. + *
  91902. + * When a driver is successfully registered, it will receive control
  91903. + * requests including set_configuration(), which enables non-control
  91904. + * requests. then usb traffic follows until a disconnect is reported.
  91905. + * then a host may connect again, or the driver might get unbound.
  91906. + *
  91907. + * @param driver The driver being registered
  91908. + * @param bind The bind function of gadget driver
  91909. + */
  91910. +
  91911. +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
  91912. +{
  91913. + int retval;
  91914. +
  91915. + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
  91916. + driver->driver.name);
  91917. +
  91918. + if (!driver || driver->max_speed == USB_SPEED_UNKNOWN ||
  91919. + !driver->bind ||
  91920. + !driver->unbind || !driver->disconnect || !driver->setup) {
  91921. + DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
  91922. + return -EINVAL;
  91923. + }
  91924. + if (gadget_wrapper == 0) {
  91925. + DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
  91926. + return -ENODEV;
  91927. + }
  91928. + if (gadget_wrapper->driver != 0) {
  91929. + DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
  91930. + return -EBUSY;
  91931. + }
  91932. +
  91933. + /* hook up the driver */
  91934. + gadget_wrapper->driver = driver;
  91935. + gadget_wrapper->gadget.dev.driver = &driver->driver;
  91936. +
  91937. + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
  91938. + retval = driver->bind(&gadget_wrapper->gadget, gadget_wrapper->driver);
  91939. + if (retval) {
  91940. + DWC_ERROR("bind to driver %s --> error %d\n",
  91941. + driver->driver.name, retval);
  91942. + gadget_wrapper->driver = 0;
  91943. + gadget_wrapper->gadget.dev.driver = 0;
  91944. + return retval;
  91945. + }
  91946. + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
  91947. + driver->driver.name);
  91948. + return 0;
  91949. +}
  91950. +EXPORT_SYMBOL(usb_gadget_probe_driver);
  91951. +
  91952. +/**
  91953. + * This function unregisters a gadget driver
  91954. + *
  91955. + * @param driver The driver being unregistered
  91956. + */
  91957. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  91958. +{
  91959. + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
  91960. +
  91961. + if (gadget_wrapper == 0) {
  91962. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
  91963. + -ENODEV);
  91964. + return -ENODEV;
  91965. + }
  91966. + if (driver == 0 || driver != gadget_wrapper->driver) {
  91967. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
  91968. + -EINVAL);
  91969. + return -EINVAL;
  91970. + }
  91971. +
  91972. + driver->unbind(&gadget_wrapper->gadget);
  91973. + gadget_wrapper->driver = 0;
  91974. +
  91975. + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
  91976. + return 0;
  91977. +}
  91978. +
  91979. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  91980. +
  91981. +#endif /* DWC_HOST_ONLY */
  91982. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_regs.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h
  91983. --- linux-3.12.18/drivers/usb/host/dwc_otg/dwc_otg_regs.h 1970-01-01 01:00:00.000000000 +0100
  91984. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h 2014-04-24 16:04:39.823124292 +0200
  91985. @@ -0,0 +1,2550 @@
  91986. +/* ==========================================================================
  91987. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
  91988. + * $Revision: #98 $
  91989. + * $Date: 2012/08/10 $
  91990. + * $Change: 2047372 $
  91991. + *
  91992. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  91993. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  91994. + * otherwise expressly agreed to in writing between Synopsys and you.
  91995. + *
  91996. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  91997. + * any End User Software License Agreement or Agreement for Licensed Product
  91998. + * with Synopsys or any supplement thereto. You are permitted to use and
  91999. + * redistribute this Software in source and binary forms, with or without
  92000. + * modification, provided that redistributions of source code must retain this
  92001. + * notice. You may not view, use, disclose, copy or distribute this file or
  92002. + * any information contained herein except pursuant to this license grant from
  92003. + * Synopsys. If you do not agree with this notice, including the disclaimer
  92004. + * below, then you are not authorized to use the Software.
  92005. + *
  92006. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  92007. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  92008. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  92009. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  92010. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  92011. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  92012. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  92013. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  92014. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  92015. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  92016. + * DAMAGE.
  92017. + * ========================================================================== */
  92018. +
  92019. +#ifndef __DWC_OTG_REGS_H__
  92020. +#define __DWC_OTG_REGS_H__
  92021. +
  92022. +#include "dwc_otg_core_if.h"
  92023. +
  92024. +/**
  92025. + * @file
  92026. + *
  92027. + * This file contains the data structures for accessing the DWC_otg core registers.
  92028. + *
  92029. + * The application interfaces with the HS OTG core by reading from and
  92030. + * writing to the Control and Status Register (CSR) space through the
  92031. + * AHB Slave interface. These registers are 32 bits wide, and the
  92032. + * addresses are 32-bit-block aligned.
  92033. + * CSRs are classified as follows:
  92034. + * - Core Global Registers
  92035. + * - Device Mode Registers
  92036. + * - Device Global Registers
  92037. + * - Device Endpoint Specific Registers
  92038. + * - Host Mode Registers
  92039. + * - Host Global Registers
  92040. + * - Host Port CSRs
  92041. + * - Host Channel Specific Registers
  92042. + *
  92043. + * Only the Core Global registers can be accessed in both Device and
  92044. + * Host modes. When the HS OTG core is operating in one mode, either
  92045. + * Device or Host, the application must not access registers from the
  92046. + * other mode. When the core switches from one mode to another, the
  92047. + * registers in the new mode of operation must be reprogrammed as they
  92048. + * would be after a power-on reset.
  92049. + */
  92050. +
  92051. +/****************************************************************************/
  92052. +/** DWC_otg Core registers .
  92053. + * The dwc_otg_core_global_regs structure defines the size
  92054. + * and relative field offsets for the Core Global registers.
  92055. + */
  92056. +typedef struct dwc_otg_core_global_regs {
  92057. + /** OTG Control and Status Register. <i>Offset: 000h</i> */
  92058. + volatile uint32_t gotgctl;
  92059. + /** OTG Interrupt Register. <i>Offset: 004h</i> */
  92060. + volatile uint32_t gotgint;
  92061. + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
  92062. + volatile uint32_t gahbcfg;
  92063. +
  92064. +#define DWC_GLBINTRMASK 0x0001
  92065. +#define DWC_DMAENABLE 0x0020
  92066. +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
  92067. +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
  92068. +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
  92069. +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
  92070. +
  92071. + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
  92072. + volatile uint32_t gusbcfg;
  92073. + /**Core Reset Register. <i>Offset: 010h</i> */
  92074. + volatile uint32_t grstctl;
  92075. + /**Core Interrupt Register. <i>Offset: 014h</i> */
  92076. + volatile uint32_t gintsts;
  92077. + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
  92078. + volatile uint32_t gintmsk;
  92079. + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
  92080. + volatile uint32_t grxstsr;
  92081. + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
  92082. + volatile uint32_t grxstsp;
  92083. + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
  92084. + volatile uint32_t grxfsiz;
  92085. + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
  92086. + volatile uint32_t gnptxfsiz;
  92087. + /**Non Periodic Transmit FIFO/Queue Status Register (Read
  92088. + * Only). <i>Offset: 02Ch</i> */
  92089. + volatile uint32_t gnptxsts;
  92090. + /**I2C Access Register. <i>Offset: 030h</i> */
  92091. + volatile uint32_t gi2cctl;
  92092. + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
  92093. + volatile uint32_t gpvndctl;
  92094. + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
  92095. + volatile uint32_t ggpio;
  92096. + /**User ID Register. <i>Offset: 03Ch</i> */
  92097. + volatile uint32_t guid;
  92098. + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
  92099. + volatile uint32_t gsnpsid;
  92100. + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
  92101. + volatile uint32_t ghwcfg1;
  92102. + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
  92103. + volatile uint32_t ghwcfg2;
  92104. +#define DWC_SLAVE_ONLY_ARCH 0
  92105. +#define DWC_EXT_DMA_ARCH 1
  92106. +#define DWC_INT_DMA_ARCH 2
  92107. +
  92108. +#define DWC_MODE_HNP_SRP_CAPABLE 0
  92109. +#define DWC_MODE_SRP_ONLY_CAPABLE 1
  92110. +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
  92111. +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
  92112. +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
  92113. +#define DWC_MODE_SRP_CAPABLE_HOST 5
  92114. +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
  92115. +
  92116. + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
  92117. + volatile uint32_t ghwcfg3;
  92118. + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
  92119. + volatile uint32_t ghwcfg4;
  92120. + /** Core LPM Configuration register <i>Offset: 054h</i>*/
  92121. + volatile uint32_t glpmcfg;
  92122. + /** Global PowerDn Register <i>Offset: 058h</i> */
  92123. + volatile uint32_t gpwrdn;
  92124. + /** Global DFIFO SW Config Register <i>Offset: 05Ch</i> */
  92125. + volatile uint32_t gdfifocfg;
  92126. + /** ADP Control Register <i>Offset: 060h</i> */
  92127. + volatile uint32_t adpctl;
  92128. + /** Reserved <i>Offset: 064h-0FFh</i> */
  92129. + volatile uint32_t reserved39[39];
  92130. + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
  92131. + volatile uint32_t hptxfsiz;
  92132. + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
  92133. + otherwise Device Transmit FIFO#n Register.
  92134. + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
  92135. + volatile uint32_t dtxfsiz[15];
  92136. +} dwc_otg_core_global_regs_t;
  92137. +
  92138. +/**
  92139. + * This union represents the bit fields of the Core OTG Control
  92140. + * and Status Register (GOTGCTL). Set the bits using the bit
  92141. + * fields then write the <i>d32</i> value to the register.
  92142. + */
  92143. +typedef union gotgctl_data {
  92144. + /** raw register data */
  92145. + uint32_t d32;
  92146. + /** register bits */
  92147. + struct {
  92148. + unsigned sesreqscs:1;
  92149. + unsigned sesreq:1;
  92150. + unsigned vbvalidoven:1;
  92151. + unsigned vbvalidovval:1;
  92152. + unsigned avalidoven:1;
  92153. + unsigned avalidovval:1;
  92154. + unsigned bvalidoven:1;
  92155. + unsigned bvalidovval:1;
  92156. + unsigned hstnegscs:1;
  92157. + unsigned hnpreq:1;
  92158. + unsigned hstsethnpen:1;
  92159. + unsigned devhnpen:1;
  92160. + unsigned reserved12_15:4;
  92161. + unsigned conidsts:1;
  92162. + unsigned dbnctime:1;
  92163. + unsigned asesvld:1;
  92164. + unsigned bsesvld:1;
  92165. + unsigned otgver:1;
  92166. + unsigned reserved1:1;
  92167. + unsigned multvalidbc:5;
  92168. + unsigned chirpen:1;
  92169. + unsigned reserved28_31:4;
  92170. + } b;
  92171. +} gotgctl_data_t;
  92172. +
  92173. +/**
  92174. + * This union represents the bit fields of the Core OTG Interrupt Register
  92175. + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
  92176. + * value to the register.
  92177. + */
  92178. +typedef union gotgint_data {
  92179. + /** raw register data */
  92180. + uint32_t d32;
  92181. + /** register bits */
  92182. + struct {
  92183. + /** Current Mode */
  92184. + unsigned reserved0_1:2;
  92185. +
  92186. + /** Session End Detected */
  92187. + unsigned sesenddet:1;
  92188. +
  92189. + unsigned reserved3_7:5;
  92190. +
  92191. + /** Session Request Success Status Change */
  92192. + unsigned sesreqsucstschng:1;
  92193. + /** Host Negotiation Success Status Change */
  92194. + unsigned hstnegsucstschng:1;
  92195. +
  92196. + unsigned reserved10_16:7;
  92197. +
  92198. + /** Host Negotiation Detected */
  92199. + unsigned hstnegdet:1;
  92200. + /** A-Device Timeout Change */
  92201. + unsigned adevtoutchng:1;
  92202. + /** Debounce Done */
  92203. + unsigned debdone:1;
  92204. + /** Multi-Valued input changed */
  92205. + unsigned mvic:1;
  92206. +
  92207. + unsigned reserved31_21:11;
  92208. +
  92209. + } b;
  92210. +} gotgint_data_t;
  92211. +
  92212. +/**
  92213. + * This union represents the bit fields of the Core AHB Configuration
  92214. + * Register (GAHBCFG). Set/clear the bits using the bit fields then
  92215. + * write the <i>d32</i> value to the register.
  92216. + */
  92217. +typedef union gahbcfg_data {
  92218. + /** raw register data */
  92219. + uint32_t d32;
  92220. + /** register bits */
  92221. + struct {
  92222. + unsigned glblintrmsk:1;
  92223. +#define DWC_GAHBCFG_GLBINT_ENABLE 1
  92224. +
  92225. + unsigned hburstlen:4;
  92226. +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  92227. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  92228. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  92229. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  92230. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  92231. +
  92232. + unsigned dmaenable:1;
  92233. +#define DWC_GAHBCFG_DMAENABLE 1
  92234. + unsigned reserved:1;
  92235. + unsigned nptxfemplvl_txfemplvl:1;
  92236. + unsigned ptxfemplvl:1;
  92237. +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
  92238. +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
  92239. + unsigned reserved9_20:12;
  92240. + unsigned remmemsupp:1;
  92241. + unsigned notialldmawrit:1;
  92242. + unsigned ahbsingle:1;
  92243. + unsigned reserved24_31:8;
  92244. + } b;
  92245. +} gahbcfg_data_t;
  92246. +
  92247. +/**
  92248. + * This union represents the bit fields of the Core USB Configuration
  92249. + * Register (GUSBCFG). Set the bits using the bit fields then write
  92250. + * the <i>d32</i> value to the register.
  92251. + */
  92252. +typedef union gusbcfg_data {
  92253. + /** raw register data */
  92254. + uint32_t d32;
  92255. + /** register bits */
  92256. + struct {
  92257. + unsigned toutcal:3;
  92258. + unsigned phyif:1;
  92259. + unsigned ulpi_utmi_sel:1;
  92260. + unsigned fsintf:1;
  92261. + unsigned physel:1;
  92262. + unsigned ddrsel:1;
  92263. + unsigned srpcap:1;
  92264. + unsigned hnpcap:1;
  92265. + unsigned usbtrdtim:4;
  92266. + unsigned reserved1:1;
  92267. + unsigned phylpwrclksel:1;
  92268. + unsigned otgutmifssel:1;
  92269. + unsigned ulpi_fsls:1;
  92270. + unsigned ulpi_auto_res:1;
  92271. + unsigned ulpi_clk_sus_m:1;
  92272. + unsigned ulpi_ext_vbus_drv:1;
  92273. + unsigned ulpi_int_vbus_indicator:1;
  92274. + unsigned term_sel_dl_pulse:1;
  92275. + unsigned indicator_complement:1;
  92276. + unsigned indicator_pass_through:1;
  92277. + unsigned ulpi_int_prot_dis:1;
  92278. + unsigned ic_usb_cap:1;
  92279. + unsigned ic_traffic_pull_remove:1;
  92280. + unsigned tx_end_delay:1;
  92281. + unsigned force_host_mode:1;
  92282. + unsigned force_dev_mode:1;
  92283. + unsigned reserved31:1;
  92284. + } b;
  92285. +} gusbcfg_data_t;
  92286. +
  92287. +/**
  92288. + * This union represents the bit fields of the Core Reset Register
  92289. + * (GRSTCTL). Set/clear the bits using the bit fields then write the
  92290. + * <i>d32</i> value to the register.
  92291. + */
  92292. +typedef union grstctl_data {
  92293. + /** raw register data */
  92294. + uint32_t d32;
  92295. + /** register bits */
  92296. + struct {
  92297. + /** Core Soft Reset (CSftRst) (Device and Host)
  92298. + *
  92299. + * The application can flush the control logic in the
  92300. + * entire core using this bit. This bit resets the
  92301. + * pipelines in the AHB Clock domain as well as the
  92302. + * PHY Clock domain.
  92303. + *
  92304. + * The state machines are reset to an IDLE state, the
  92305. + * control bits in the CSRs are cleared, all the
  92306. + * transmit FIFOs and the receive FIFO are flushed.
  92307. + *
  92308. + * The status mask bits that control the generation of
  92309. + * the interrupt, are cleared, to clear the
  92310. + * interrupt. The interrupt status bits are not
  92311. + * cleared, so the application can get the status of
  92312. + * any events that occurred in the core after it has
  92313. + * set this bit.
  92314. + *
  92315. + * Any transactions on the AHB are terminated as soon
  92316. + * as possible following the protocol. Any
  92317. + * transactions on the USB are terminated immediately.
  92318. + *
  92319. + * The configuration settings in the CSRs are
  92320. + * unchanged, so the software doesn't have to
  92321. + * reprogram these registers (Device
  92322. + * Configuration/Host Configuration/Core System
  92323. + * Configuration/Core PHY Configuration).
  92324. + *
  92325. + * The application can write to this bit, any time it
  92326. + * wants to reset the core. This is a self clearing
  92327. + * bit and the core clears this bit after all the
  92328. + * necessary logic is reset in the core, which may
  92329. + * take several clocks, depending on the current state
  92330. + * of the core.
  92331. + */
  92332. + unsigned csftrst:1;
  92333. + /** Hclk Soft Reset
  92334. + *
  92335. + * The application uses this bit to reset the control logic in
  92336. + * the AHB clock domain. Only AHB clock domain pipelines are
  92337. + * reset.
  92338. + */
  92339. + unsigned hsftrst:1;
  92340. + /** Host Frame Counter Reset (Host Only)<br>
  92341. + *
  92342. + * The application can reset the (micro)frame number
  92343. + * counter inside the core, using this bit. When the
  92344. + * (micro)frame counter is reset, the subsequent SOF
  92345. + * sent out by the core, will have a (micro)frame
  92346. + * number of 0.
  92347. + */
  92348. + unsigned hstfrm:1;
  92349. + /** In Token Sequence Learning Queue Flush
  92350. + * (INTknQFlsh) (Device Only)
  92351. + */
  92352. + unsigned intknqflsh:1;
  92353. + /** RxFIFO Flush (RxFFlsh) (Device and Host)
  92354. + *
  92355. + * The application can flush the entire Receive FIFO
  92356. + * using this bit. The application must first
  92357. + * ensure that the core is not in the middle of a
  92358. + * transaction. The application should write into
  92359. + * this bit, only after making sure that neither the
  92360. + * DMA engine is reading from the RxFIFO nor the MAC
  92361. + * is writing the data in to the FIFO. The
  92362. + * application should wait until the bit is cleared
  92363. + * before performing any other operations. This bit
  92364. + * will takes 8 clocks (slowest of PHY or AHB clock)
  92365. + * to clear.
  92366. + */
  92367. + unsigned rxfflsh:1;
  92368. + /** TxFIFO Flush (TxFFlsh) (Device and Host).
  92369. + *
  92370. + * This bit is used to selectively flush a single or
  92371. + * all transmit FIFOs. The application must first
  92372. + * ensure that the core is not in the middle of a
  92373. + * transaction. The application should write into
  92374. + * this bit, only after making sure that neither the
  92375. + * DMA engine is writing into the TxFIFO nor the MAC
  92376. + * is reading the data out of the FIFO. The
  92377. + * application should wait until the core clears this
  92378. + * bit, before performing any operations. This bit
  92379. + * will takes 8 clocks (slowest of PHY or AHB clock)
  92380. + * to clear.
  92381. + */
  92382. + unsigned txfflsh:1;
  92383. +
  92384. + /** TxFIFO Number (TxFNum) (Device and Host).
  92385. + *
  92386. + * This is the FIFO number which needs to be flushed,
  92387. + * using the TxFIFO Flush bit. This field should not
  92388. + * be changed until the TxFIFO Flush bit is cleared by
  92389. + * the core.
  92390. + * - 0x0 : Non Periodic TxFIFO Flush
  92391. + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
  92392. + * or Periodic TxFIFO in host mode
  92393. + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
  92394. + * - ...
  92395. + * - 0xF : Periodic TxFIFO #15 Flush in device mode
  92396. + * - 0x10: Flush all the Transmit NonPeriodic and
  92397. + * Transmit Periodic FIFOs in the core
  92398. + */
  92399. + unsigned txfnum:5;
  92400. + /** Reserved */
  92401. + unsigned reserved11_29:19;
  92402. + /** DMA Request Signal. Indicated DMA request is in
  92403. + * probress. Used for debug purpose. */
  92404. + unsigned dmareq:1;
  92405. + /** AHB Master Idle. Indicates the AHB Master State
  92406. + * Machine is in IDLE condition. */
  92407. + unsigned ahbidle:1;
  92408. + } b;
  92409. +} grstctl_t;
  92410. +
  92411. +/**
  92412. + * This union represents the bit fields of the Core Interrupt Mask
  92413. + * Register (GINTMSK). Set/clear the bits using the bit fields then
  92414. + * write the <i>d32</i> value to the register.
  92415. + */
  92416. +typedef union gintmsk_data {
  92417. + /** raw register data */
  92418. + uint32_t d32;
  92419. + /** register bits */
  92420. + struct {
  92421. + unsigned reserved0:1;
  92422. + unsigned modemismatch:1;
  92423. + unsigned otgintr:1;
  92424. + unsigned sofintr:1;
  92425. + unsigned rxstsqlvl:1;
  92426. + unsigned nptxfempty:1;
  92427. + unsigned ginnakeff:1;
  92428. + unsigned goutnakeff:1;
  92429. + unsigned ulpickint:1;
  92430. + unsigned i2cintr:1;
  92431. + unsigned erlysuspend:1;
  92432. + unsigned usbsuspend:1;
  92433. + unsigned usbreset:1;
  92434. + unsigned enumdone:1;
  92435. + unsigned isooutdrop:1;
  92436. + unsigned eopframe:1;
  92437. + unsigned restoredone:1;
  92438. + unsigned epmismatch:1;
  92439. + unsigned inepintr:1;
  92440. + unsigned outepintr:1;
  92441. + unsigned incomplisoin:1;
  92442. + unsigned incomplisoout:1;
  92443. + unsigned fetsusp:1;
  92444. + unsigned resetdet:1;
  92445. + unsigned portintr:1;
  92446. + unsigned hcintr:1;
  92447. + unsigned ptxfempty:1;
  92448. + unsigned lpmtranrcvd:1;
  92449. + unsigned conidstschng:1;
  92450. + unsigned disconnect:1;
  92451. + unsigned sessreqintr:1;
  92452. + unsigned wkupintr:1;
  92453. + } b;
  92454. +} gintmsk_data_t;
  92455. +/**
  92456. + * This union represents the bit fields of the Core Interrupt Register
  92457. + * (GINTSTS). Set/clear the bits using the bit fields then write the
  92458. + * <i>d32</i> value to the register.
  92459. + */
  92460. +typedef union gintsts_data {
  92461. + /** raw register data */
  92462. + uint32_t d32;
  92463. +#define DWC_SOF_INTR_MASK 0x0008
  92464. + /** register bits */
  92465. + struct {
  92466. +#define DWC_HOST_MODE 1
  92467. + unsigned curmode:1;
  92468. + unsigned modemismatch:1;
  92469. + unsigned otgintr:1;
  92470. + unsigned sofintr:1;
  92471. + unsigned rxstsqlvl:1;
  92472. + unsigned nptxfempty:1;
  92473. + unsigned ginnakeff:1;
  92474. + unsigned goutnakeff:1;
  92475. + unsigned ulpickint:1;
  92476. + unsigned i2cintr:1;
  92477. + unsigned erlysuspend:1;
  92478. + unsigned usbsuspend:1;
  92479. + unsigned usbreset:1;
  92480. + unsigned enumdone:1;
  92481. + unsigned isooutdrop:1;
  92482. + unsigned eopframe:1;
  92483. + unsigned restoredone:1;
  92484. + unsigned epmismatch:1;
  92485. + unsigned inepint:1;
  92486. + unsigned outepintr:1;
  92487. + unsigned incomplisoin:1;
  92488. + unsigned incomplisoout:1;
  92489. + unsigned fetsusp:1;
  92490. + unsigned resetdet:1;
  92491. + unsigned portintr:1;
  92492. + unsigned hcintr:1;
  92493. + unsigned ptxfempty:1;
  92494. + unsigned lpmtranrcvd:1;
  92495. + unsigned conidstschng:1;
  92496. + unsigned disconnect:1;
  92497. + unsigned sessreqintr:1;
  92498. + unsigned wkupintr:1;
  92499. + } b;
  92500. +} gintsts_data_t;
  92501. +
  92502. +/**
  92503. + * This union represents the bit fields in the Device Receive Status Read and
  92504. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  92505. + * element then read out the bits using the <i>b</i>it elements.
  92506. + */
  92507. +typedef union device_grxsts_data {
  92508. + /** raw register data */
  92509. + uint32_t d32;
  92510. + /** register bits */
  92511. + struct {
  92512. + unsigned epnum:4;
  92513. + unsigned bcnt:11;
  92514. + unsigned dpid:2;
  92515. +
  92516. +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
  92517. +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
  92518. +
  92519. +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
  92520. +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
  92521. +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
  92522. + unsigned pktsts:4;
  92523. + unsigned fn:4;
  92524. + unsigned reserved25_31:7;
  92525. + } b;
  92526. +} device_grxsts_data_t;
  92527. +
  92528. +/**
  92529. + * This union represents the bit fields in the Host Receive Status Read and
  92530. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  92531. + * element then read out the bits using the <i>b</i>it elements.
  92532. + */
  92533. +typedef union host_grxsts_data {
  92534. + /** raw register data */
  92535. + uint32_t d32;
  92536. + /** register bits */
  92537. + struct {
  92538. + unsigned chnum:4;
  92539. + unsigned bcnt:11;
  92540. + unsigned dpid:2;
  92541. +
  92542. + unsigned pktsts:4;
  92543. +#define DWC_GRXSTS_PKTSTS_IN 0x2
  92544. +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
  92545. +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
  92546. +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
  92547. +
  92548. + unsigned reserved21_31:11;
  92549. + } b;
  92550. +} host_grxsts_data_t;
  92551. +
  92552. +/**
  92553. + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
  92554. + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element
  92555. + * then read out the bits using the <i>b</i>it elements.
  92556. + */
  92557. +typedef union fifosize_data {
  92558. + /** raw register data */
  92559. + uint32_t d32;
  92560. + /** register bits */
  92561. + struct {
  92562. + unsigned startaddr:16;
  92563. + unsigned depth:16;
  92564. + } b;
  92565. +} fifosize_data_t;
  92566. +
  92567. +/**
  92568. + * This union represents the bit fields in the Non-Periodic Transmit
  92569. + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
  92570. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  92571. + * elements.
  92572. + */
  92573. +typedef union gnptxsts_data {
  92574. + /** raw register data */
  92575. + uint32_t d32;
  92576. + /** register bits */
  92577. + struct {
  92578. + unsigned nptxfspcavail:16;
  92579. + unsigned nptxqspcavail:8;
  92580. + /** Top of the Non-Periodic Transmit Request Queue
  92581. + * - bit 24 - Terminate (Last entry for the selected
  92582. + * channel/EP)
  92583. + * - bits 26:25 - Token Type
  92584. + * - 2'b00 - IN/OUT
  92585. + * - 2'b01 - Zero Length OUT
  92586. + * - 2'b10 - PING/Complete Split
  92587. + * - 2'b11 - Channel Halt
  92588. + * - bits 30:27 - Channel/EP Number
  92589. + */
  92590. + unsigned nptxqtop_terminate:1;
  92591. + unsigned nptxqtop_token:2;
  92592. + unsigned nptxqtop_chnep:4;
  92593. + unsigned reserved:1;
  92594. + } b;
  92595. +} gnptxsts_data_t;
  92596. +
  92597. +/**
  92598. + * This union represents the bit fields in the Transmit
  92599. + * FIFO Status Register (DTXFSTS). Read the register into the
  92600. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  92601. + * elements.
  92602. + */
  92603. +typedef union dtxfsts_data {
  92604. + /** raw register data */
  92605. + uint32_t d32;
  92606. + /** register bits */
  92607. + struct {
  92608. + unsigned txfspcavail:16;
  92609. + unsigned reserved:16;
  92610. + } b;
  92611. +} dtxfsts_data_t;
  92612. +
  92613. +/**
  92614. + * This union represents the bit fields in the I2C Control Register
  92615. + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
  92616. + * bits using the <i>b</i>it elements.
  92617. + */
  92618. +typedef union gi2cctl_data {
  92619. + /** raw register data */
  92620. + uint32_t d32;
  92621. + /** register bits */
  92622. + struct {
  92623. + unsigned rwdata:8;
  92624. + unsigned regaddr:8;
  92625. + unsigned addr:7;
  92626. + unsigned i2cen:1;
  92627. + unsigned ack:1;
  92628. + unsigned i2csuspctl:1;
  92629. + unsigned i2cdevaddr:2;
  92630. + unsigned i2cdatse0:1;
  92631. + unsigned reserved:1;
  92632. + unsigned rw:1;
  92633. + unsigned bsydne:1;
  92634. + } b;
  92635. +} gi2cctl_data_t;
  92636. +
  92637. +/**
  92638. + * This union represents the bit fields in the PHY Vendor Control Register
  92639. + * (GPVNDCTL). Read the register into the <i>d32</i> element then read out the
  92640. + * bits using the <i>b</i>it elements.
  92641. + */
  92642. +typedef union gpvndctl_data {
  92643. + /** raw register data */
  92644. + uint32_t d32;
  92645. + /** register bits */
  92646. + struct {
  92647. + unsigned regdata:8;
  92648. + unsigned vctrl:8;
  92649. + unsigned regaddr16_21:6;
  92650. + unsigned regwr:1;
  92651. + unsigned reserved23_24:2;
  92652. + unsigned newregreq:1;
  92653. + unsigned vstsbsy:1;
  92654. + unsigned vstsdone:1;
  92655. + unsigned reserved28_30:3;
  92656. + unsigned disulpidrvr:1;
  92657. + } b;
  92658. +} gpvndctl_data_t;
  92659. +
  92660. +/**
  92661. + * This union represents the bit fields in the General Purpose
  92662. + * Input/Output Register (GGPIO).
  92663. + * Read the register into the <i>d32</i> element then read out the
  92664. + * bits using the <i>b</i>it elements.
  92665. + */
  92666. +typedef union ggpio_data {
  92667. + /** raw register data */
  92668. + uint32_t d32;
  92669. + /** register bits */
  92670. + struct {
  92671. + unsigned gpi:16;
  92672. + unsigned gpo:16;
  92673. + } b;
  92674. +} ggpio_data_t;
  92675. +
  92676. +/**
  92677. + * This union represents the bit fields in the User ID Register
  92678. + * (GUID). Read the register into the <i>d32</i> element then read out the
  92679. + * bits using the <i>b</i>it elements.
  92680. + */
  92681. +typedef union guid_data {
  92682. + /** raw register data */
  92683. + uint32_t d32;
  92684. + /** register bits */
  92685. + struct {
  92686. + unsigned rwdata:32;
  92687. + } b;
  92688. +} guid_data_t;
  92689. +
  92690. +/**
  92691. + * This union represents the bit fields in the Synopsys ID Register
  92692. + * (GSNPSID). Read the register into the <i>d32</i> element then read out the
  92693. + * bits using the <i>b</i>it elements.
  92694. + */
  92695. +typedef union gsnpsid_data {
  92696. + /** raw register data */
  92697. + uint32_t d32;
  92698. + /** register bits */
  92699. + struct {
  92700. + unsigned rwdata:32;
  92701. + } b;
  92702. +} gsnpsid_data_t;
  92703. +
  92704. +/**
  92705. + * This union represents the bit fields in the User HW Config1
  92706. + * Register. Read the register into the <i>d32</i> element then read
  92707. + * out the bits using the <i>b</i>it elements.
  92708. + */
  92709. +typedef union hwcfg1_data {
  92710. + /** raw register data */
  92711. + uint32_t d32;
  92712. + /** register bits */
  92713. + struct {
  92714. + unsigned ep_dir0:2;
  92715. + unsigned ep_dir1:2;
  92716. + unsigned ep_dir2:2;
  92717. + unsigned ep_dir3:2;
  92718. + unsigned ep_dir4:2;
  92719. + unsigned ep_dir5:2;
  92720. + unsigned ep_dir6:2;
  92721. + unsigned ep_dir7:2;
  92722. + unsigned ep_dir8:2;
  92723. + unsigned ep_dir9:2;
  92724. + unsigned ep_dir10:2;
  92725. + unsigned ep_dir11:2;
  92726. + unsigned ep_dir12:2;
  92727. + unsigned ep_dir13:2;
  92728. + unsigned ep_dir14:2;
  92729. + unsigned ep_dir15:2;
  92730. + } b;
  92731. +} hwcfg1_data_t;
  92732. +
  92733. +/**
  92734. + * This union represents the bit fields in the User HW Config2
  92735. + * Register. Read the register into the <i>d32</i> element then read
  92736. + * out the bits using the <i>b</i>it elements.
  92737. + */
  92738. +typedef union hwcfg2_data {
  92739. + /** raw register data */
  92740. + uint32_t d32;
  92741. + /** register bits */
  92742. + struct {
  92743. + /* GHWCFG2 */
  92744. + unsigned op_mode:3;
  92745. +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
  92746. +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
  92747. +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
  92748. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
  92749. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
  92750. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
  92751. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
  92752. +
  92753. + unsigned architecture:2;
  92754. + unsigned point2point:1;
  92755. + unsigned hs_phy_type:2;
  92756. +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
  92757. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
  92758. +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
  92759. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
  92760. +
  92761. + unsigned fs_phy_type:2;
  92762. + unsigned num_dev_ep:4;
  92763. + unsigned num_host_chan:4;
  92764. + unsigned perio_ep_supported:1;
  92765. + unsigned dynamic_fifo:1;
  92766. + unsigned multi_proc_int:1;
  92767. + unsigned reserved21:1;
  92768. + unsigned nonperio_tx_q_depth:2;
  92769. + unsigned host_perio_tx_q_depth:2;
  92770. + unsigned dev_token_q_depth:5;
  92771. + unsigned otg_enable_ic_usb:1;
  92772. + } b;
  92773. +} hwcfg2_data_t;
  92774. +
  92775. +/**
  92776. + * This union represents the bit fields in the User HW Config3
  92777. + * Register. Read the register into the <i>d32</i> element then read
  92778. + * out the bits using the <i>b</i>it elements.
  92779. + */
  92780. +typedef union hwcfg3_data {
  92781. + /** raw register data */
  92782. + uint32_t d32;
  92783. + /** register bits */
  92784. + struct {
  92785. + /* GHWCFG3 */
  92786. + unsigned xfer_size_cntr_width:4;
  92787. + unsigned packet_size_cntr_width:3;
  92788. + unsigned otg_func:1;
  92789. + unsigned i2c:1;
  92790. + unsigned vendor_ctrl_if:1;
  92791. + unsigned optional_features:1;
  92792. + unsigned synch_reset_type:1;
  92793. + unsigned adp_supp:1;
  92794. + unsigned otg_enable_hsic:1;
  92795. + unsigned bc_support:1;
  92796. + unsigned otg_lpm_en:1;
  92797. + unsigned dfifo_depth:16;
  92798. + } b;
  92799. +} hwcfg3_data_t;
  92800. +
  92801. +/**
  92802. + * This union represents the bit fields in the User HW Config4
  92803. + * Register. Read the register into the <i>d32</i> element then read
  92804. + * out the bits using the <i>b</i>it elements.
  92805. + */
  92806. +typedef union hwcfg4_data {
  92807. + /** raw register data */
  92808. + uint32_t d32;
  92809. + /** register bits */
  92810. + struct {
  92811. + unsigned num_dev_perio_in_ep:4;
  92812. + unsigned power_optimiz:1;
  92813. + unsigned min_ahb_freq:1;
  92814. + unsigned hiber:1;
  92815. + unsigned xhiber:1;
  92816. + unsigned reserved:6;
  92817. + unsigned utmi_phy_data_width:2;
  92818. + unsigned num_dev_mode_ctrl_ep:4;
  92819. + unsigned iddig_filt_en:1;
  92820. + unsigned vbus_valid_filt_en:1;
  92821. + unsigned a_valid_filt_en:1;
  92822. + unsigned b_valid_filt_en:1;
  92823. + unsigned session_end_filt_en:1;
  92824. + unsigned ded_fifo_en:1;
  92825. + unsigned num_in_eps:4;
  92826. + unsigned desc_dma:1;
  92827. + unsigned desc_dma_dyn:1;
  92828. + } b;
  92829. +} hwcfg4_data_t;
  92830. +
  92831. +/**
  92832. + * This union represents the bit fields of the Core LPM Configuration
  92833. + * Register (GLPMCFG). Set the bits using bit fields then write
  92834. + * the <i>d32</i> value to the register.
  92835. + */
  92836. +typedef union glpmctl_data {
  92837. + /** raw register data */
  92838. + uint32_t d32;
  92839. + /** register bits */
  92840. + struct {
  92841. + /** LPM-Capable (LPMCap) (Device and Host)
  92842. + * The application uses this bit to control
  92843. + * the DWC_otg core LPM capabilities.
  92844. + */
  92845. + unsigned lpm_cap_en:1;
  92846. + /** LPM response programmed by application (AppL1Res) (Device)
  92847. + * Handshake response to LPM token pre-programmed
  92848. + * by device application software.
  92849. + */
  92850. + unsigned appl_resp:1;
  92851. + /** Host Initiated Resume Duration (HIRD) (Device and Host)
  92852. + * In Host mode this field indicates the value of HIRD
  92853. + * to be sent in an LPM transaction.
  92854. + * In Device mode this field is updated with the
  92855. + * Received LPM Token HIRD bmAttribute
  92856. + * when an ACK/NYET/STALL response is sent
  92857. + * to an LPM transaction.
  92858. + */
  92859. + unsigned hird:4;
  92860. + /** RemoteWakeEnable (bRemoteWake) (Device and Host)
  92861. + * In Host mode this bit indicates the value of remote
  92862. + * wake up to be sent in wIndex field of LPM transaction.
  92863. + * In Device mode this field is updated with the
  92864. + * Received LPM Token bRemoteWake bmAttribute
  92865. + * when an ACK/NYET/STALL response is sent
  92866. + * to an LPM transaction.
  92867. + */
  92868. + unsigned rem_wkup_en:1;
  92869. + /** Enable utmi_sleep_n (EnblSlpM) (Device and Host)
  92870. + * The application uses this bit to control
  92871. + * the utmi_sleep_n assertion to the PHY when in L1 state.
  92872. + */
  92873. + unsigned en_utmi_sleep:1;
  92874. + /** HIRD Threshold (HIRD_Thres) (Device and Host)
  92875. + */
  92876. + unsigned hird_thres:5;
  92877. + /** LPM Response (CoreL1Res) (Device and Host)
  92878. + * In Host mode this bit contains handsake response to
  92879. + * LPM transaction.
  92880. + * In Device mode the response of the core to
  92881. + * LPM transaction received is reflected in these two bits.
  92882. + - 0x0 : ERROR (No handshake response)
  92883. + - 0x1 : STALL
  92884. + - 0x2 : NYET
  92885. + - 0x3 : ACK
  92886. + */
  92887. + unsigned lpm_resp:2;
  92888. + /** Port Sleep Status (SlpSts) (Device and Host)
  92889. + * This bit is set as long as a Sleep condition
  92890. + * is present on the USB bus.
  92891. + */
  92892. + unsigned prt_sleep_sts:1;
  92893. + /** Sleep State Resume OK (L1ResumeOK) (Device and Host)
  92894. + * Indicates that the application or host
  92895. + * can start resume from Sleep state.
  92896. + */
  92897. + unsigned sleep_state_resumeok:1;
  92898. + /** LPM channel Index (LPM_Chnl_Indx) (Host)
  92899. + * The channel number on which the LPM transaction
  92900. + * has to be applied while sending
  92901. + * an LPM transaction to the local device.
  92902. + */
  92903. + unsigned lpm_chan_index:4;
  92904. + /** LPM Retry Count (LPM_Retry_Cnt) (Host)
  92905. + * Number host retries that would be performed
  92906. + * if the device response was not valid response.
  92907. + */
  92908. + unsigned retry_count:3;
  92909. + /** Send LPM Transaction (SndLPM) (Host)
  92910. + * When set by application software,
  92911. + * an LPM transaction containing two tokens
  92912. + * is sent.
  92913. + */
  92914. + unsigned send_lpm:1;
  92915. + /** LPM Retry status (LPM_RetryCnt_Sts) (Host)
  92916. + * Number of LPM Host Retries still remaining
  92917. + * to be transmitted for the current LPM sequence
  92918. + */
  92919. + unsigned retry_count_sts:3;
  92920. + unsigned reserved28_29:2;
  92921. + /** In host mode once this bit is set, the host
  92922. + * configures to drive the HSIC Idle state on the bus.
  92923. + * It then waits for the device to initiate the Connect sequence.
  92924. + * In device mode once this bit is set, the device waits for
  92925. + * the HSIC Idle line state on the bus. Upon receving the Idle
  92926. + * line state, it initiates the HSIC Connect sequence.
  92927. + */
  92928. + unsigned hsic_connect:1;
  92929. + /** This bit overrides and functionally inverts
  92930. + * the if_select_hsic input port signal.
  92931. + */
  92932. + unsigned inv_sel_hsic:1;
  92933. + } b;
  92934. +} glpmcfg_data_t;
  92935. +
  92936. +/**
  92937. + * This union represents the bit fields of the Core ADP Timer, Control and
  92938. + * Status Register (ADPTIMCTLSTS). Set the bits using bit fields then write
  92939. + * the <i>d32</i> value to the register.
  92940. + */
  92941. +typedef union adpctl_data {
  92942. + /** raw register data */
  92943. + uint32_t d32;
  92944. + /** register bits */
  92945. + struct {
  92946. + /** Probe Discharge (PRB_DSCHG)
  92947. + * These bits set the times for TADP_DSCHG.
  92948. + * These bits are defined as follows:
  92949. + * 2'b00 - 4 msec
  92950. + * 2'b01 - 8 msec
  92951. + * 2'b10 - 16 msec
  92952. + * 2'b11 - 32 msec
  92953. + */
  92954. + unsigned prb_dschg:2;
  92955. + /** Probe Delta (PRB_DELTA)
  92956. + * These bits set the resolution for RTIM value.
  92957. + * The bits are defined in units of 32 kHz clock cycles as follows:
  92958. + * 2'b00 - 1 cycles
  92959. + * 2'b01 - 2 cycles
  92960. + * 2'b10 - 3 cycles
  92961. + * 2'b11 - 4 cycles
  92962. + * For example if this value is chosen to 2'b01, it means that RTIM
  92963. + * increments for every 3(three) 32Khz clock cycles.
  92964. + */
  92965. + unsigned prb_delta:2;
  92966. + /** Probe Period (PRB_PER)
  92967. + * These bits sets the TADP_PRD as shown in Figure 4 as follows:
  92968. + * 2'b00 - 0.625 to 0.925 sec (typical 0.775 sec)
  92969. + * 2'b01 - 1.25 to 1.85 sec (typical 1.55 sec)
  92970. + * 2'b10 - 1.9 to 2.6 sec (typical 2.275 sec)
  92971. + * 2'b11 - Reserved
  92972. + */
  92973. + unsigned prb_per:2;
  92974. + /** These bits capture the latest time it took for VBUS to ramp from
  92975. + * VADP_SINK to VADP_PRB.
  92976. + * 0x000 - 1 cycles
  92977. + * 0x001 - 2 cycles
  92978. + * 0x002 - 3 cycles
  92979. + * etc
  92980. + * 0x7FF - 2048 cycles
  92981. + * A time of 1024 cycles at 32 kHz corresponds to a time of 32 msec.
  92982. + */
  92983. + unsigned rtim:11;
  92984. + /** Enable Probe (EnaPrb)
  92985. + * When programmed to 1'b1, the core performs a probe operation.
  92986. + * This bit is valid only if OTG_Ver = 1'b1.
  92987. + */
  92988. + unsigned enaprb:1;
  92989. + /** Enable Sense (EnaSns)
  92990. + * When programmed to 1'b1, the core performs a Sense operation.
  92991. + * This bit is valid only if OTG_Ver = 1'b1.
  92992. + */
  92993. + unsigned enasns:1;
  92994. + /** ADP Reset (ADPRes)
  92995. + * When set, ADP controller is reset.
  92996. + * This bit is valid only if OTG_Ver = 1'b1.
  92997. + */
  92998. + unsigned adpres:1;
  92999. + /** ADP Enable (ADPEn)
  93000. + * When set, the core performs either ADP probing or sensing
  93001. + * based on EnaPrb or EnaSns.
  93002. + * This bit is valid only if OTG_Ver = 1'b1.
  93003. + */
  93004. + unsigned adpen:1;
  93005. + /** ADP Probe Interrupt (ADP_PRB_INT)
  93006. + * When this bit is set, it means that the VBUS
  93007. + * voltage is greater than VADP_PRB or VADP_PRB is reached.
  93008. + * This bit is valid only if OTG_Ver = 1'b1.
  93009. + */
  93010. + unsigned adp_prb_int:1;
  93011. + /**
  93012. + * ADP Sense Interrupt (ADP_SNS_INT)
  93013. + * When this bit is set, it means that the VBUS voltage is greater than
  93014. + * VADP_SNS value or VADP_SNS is reached.
  93015. + * This bit is valid only if OTG_Ver = 1'b1.
  93016. + */
  93017. + unsigned adp_sns_int:1;
  93018. + /** ADP Tomeout Interrupt (ADP_TMOUT_INT)
  93019. + * This bit is relevant only for an ADP probe.
  93020. + * When this bit is set, it means that the ramp time has
  93021. + * completed ie ADPCTL.RTIM has reached its terminal value
  93022. + * of 0x7FF. This is a debug feature that allows software
  93023. + * to read the ramp time after each cycle.
  93024. + * This bit is valid only if OTG_Ver = 1'b1.
  93025. + */
  93026. + unsigned adp_tmout_int:1;
  93027. + /** ADP Probe Interrupt Mask (ADP_PRB_INT_MSK)
  93028. + * When this bit is set, it unmasks the interrupt due to ADP_PRB_INT.
  93029. + * This bit is valid only if OTG_Ver = 1'b1.
  93030. + */
  93031. + unsigned adp_prb_int_msk:1;
  93032. + /** ADP Sense Interrupt Mask (ADP_SNS_INT_MSK)
  93033. + * When this bit is set, it unmasks the interrupt due to ADP_SNS_INT.
  93034. + * This bit is valid only if OTG_Ver = 1'b1.
  93035. + */
  93036. + unsigned adp_sns_int_msk:1;
  93037. + /** ADP Timoeout Interrupt Mask (ADP_TMOUT_MSK)
  93038. + * When this bit is set, it unmasks the interrupt due to ADP_TMOUT_INT.
  93039. + * This bit is valid only if OTG_Ver = 1'b1.
  93040. + */
  93041. + unsigned adp_tmout_int_msk:1;
  93042. + /** Access Request
  93043. + * 2'b00 - Read/Write Valid (updated by the core)
  93044. + * 2'b01 - Read
  93045. + * 2'b00 - Write
  93046. + * 2'b00 - Reserved
  93047. + */
  93048. + unsigned ar:2;
  93049. + /** Reserved */
  93050. + unsigned reserved29_31:3;
  93051. + } b;
  93052. +} adpctl_data_t;
  93053. +
  93054. +////////////////////////////////////////////
  93055. +// Device Registers
  93056. +/**
  93057. + * Device Global Registers. <i>Offsets 800h-BFFh</i>
  93058. + *
  93059. + * The following structures define the size and relative field offsets
  93060. + * for the Device Mode Registers.
  93061. + *
  93062. + * <i>These registers are visible only in Device mode and must not be
  93063. + * accessed in Host mode, as the results are unknown.</i>
  93064. + */
  93065. +typedef struct dwc_otg_dev_global_regs {
  93066. + /** Device Configuration Register. <i>Offset 800h</i> */
  93067. + volatile uint32_t dcfg;
  93068. + /** Device Control Register. <i>Offset: 804h</i> */
  93069. + volatile uint32_t dctl;
  93070. + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
  93071. + volatile uint32_t dsts;
  93072. + /** Reserved. <i>Offset: 80Ch</i> */
  93073. + uint32_t unused;
  93074. + /** Device IN Endpoint Common Interrupt Mask
  93075. + * Register. <i>Offset: 810h</i> */
  93076. + volatile uint32_t diepmsk;
  93077. + /** Device OUT Endpoint Common Interrupt Mask
  93078. + * Register. <i>Offset: 814h</i> */
  93079. + volatile uint32_t doepmsk;
  93080. + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
  93081. + volatile uint32_t daint;
  93082. + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
  93083. + * 81Ch</i> */
  93084. + volatile uint32_t daintmsk;
  93085. + /** Device IN Token Queue Read Register-1 (Read Only).
  93086. + * <i>Offset: 820h</i> */
  93087. + volatile uint32_t dtknqr1;
  93088. + /** Device IN Token Queue Read Register-2 (Read Only).
  93089. + * <i>Offset: 824h</i> */
  93090. + volatile uint32_t dtknqr2;
  93091. + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
  93092. + volatile uint32_t dvbusdis;
  93093. + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
  93094. + volatile uint32_t dvbuspulse;
  93095. + /** Device IN Token Queue Read Register-3 (Read Only). /
  93096. + * Device Thresholding control register (Read/Write)
  93097. + * <i>Offset: 830h</i> */
  93098. + volatile uint32_t dtknqr3_dthrctl;
  93099. + /** Device IN Token Queue Read Register-4 (Read Only). /
  93100. + * Device IN EPs empty Inr. Mask Register (Read/Write)
  93101. + * <i>Offset: 834h</i> */
  93102. + volatile uint32_t dtknqr4_fifoemptymsk;
  93103. + /** Device Each Endpoint Interrupt Register (Read Only). /
  93104. + * <i>Offset: 838h</i> */
  93105. + volatile uint32_t deachint;
  93106. + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
  93107. + * <i>Offset: 83Ch</i> */
  93108. + volatile uint32_t deachintmsk;
  93109. + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
  93110. + * <i>Offset: 840h</i> */
  93111. + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
  93112. + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
  93113. + * <i>Offset: 880h</i> */
  93114. + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
  93115. +} dwc_otg_device_global_regs_t;
  93116. +
  93117. +/**
  93118. + * This union represents the bit fields in the Device Configuration
  93119. + * Register. Read the register into the <i>d32</i> member then
  93120. + * set/clear the bits using the <i>b</i>it elements. Write the
  93121. + * <i>d32</i> member to the dcfg register.
  93122. + */
  93123. +typedef union dcfg_data {
  93124. + /** raw register data */
  93125. + uint32_t d32;
  93126. + /** register bits */
  93127. + struct {
  93128. + /** Device Speed */
  93129. + unsigned devspd:2;
  93130. + /** Non Zero Length Status OUT Handshake */
  93131. + unsigned nzstsouthshk:1;
  93132. +#define DWC_DCFG_SEND_STALL 1
  93133. +
  93134. + unsigned ena32khzs:1;
  93135. + /** Device Addresses */
  93136. + unsigned devaddr:7;
  93137. + /** Periodic Frame Interval */
  93138. + unsigned perfrint:2;
  93139. +#define DWC_DCFG_FRAME_INTERVAL_80 0
  93140. +#define DWC_DCFG_FRAME_INTERVAL_85 1
  93141. +#define DWC_DCFG_FRAME_INTERVAL_90 2
  93142. +#define DWC_DCFG_FRAME_INTERVAL_95 3
  93143. +
  93144. + /** Enable Device OUT NAK for bulk in DDMA mode */
  93145. + unsigned endevoutnak:1;
  93146. +
  93147. + unsigned reserved14_17:4;
  93148. + /** In Endpoint Mis-match count */
  93149. + unsigned epmscnt:5;
  93150. + /** Enable Descriptor DMA in Device mode */
  93151. + unsigned descdma:1;
  93152. + unsigned perschintvl:2;
  93153. + unsigned resvalid:6;
  93154. + } b;
  93155. +} dcfg_data_t;
  93156. +
  93157. +/**
  93158. + * This union represents the bit fields in the Device Control
  93159. + * Register. Read the register into the <i>d32</i> member then
  93160. + * set/clear the bits using the <i>b</i>it elements.
  93161. + */
  93162. +typedef union dctl_data {
  93163. + /** raw register data */
  93164. + uint32_t d32;
  93165. + /** register bits */
  93166. + struct {
  93167. + /** Remote Wakeup */
  93168. + unsigned rmtwkupsig:1;
  93169. + /** Soft Disconnect */
  93170. + unsigned sftdiscon:1;
  93171. + /** Global Non-Periodic IN NAK Status */
  93172. + unsigned gnpinnaksts:1;
  93173. + /** Global OUT NAK Status */
  93174. + unsigned goutnaksts:1;
  93175. + /** Test Control */
  93176. + unsigned tstctl:3;
  93177. + /** Set Global Non-Periodic IN NAK */
  93178. + unsigned sgnpinnak:1;
  93179. + /** Clear Global Non-Periodic IN NAK */
  93180. + unsigned cgnpinnak:1;
  93181. + /** Set Global OUT NAK */
  93182. + unsigned sgoutnak:1;
  93183. + /** Clear Global OUT NAK */
  93184. + unsigned cgoutnak:1;
  93185. + /** Power-On Programming Done */
  93186. + unsigned pwronprgdone:1;
  93187. + /** Reserved */
  93188. + unsigned reserved:1;
  93189. + /** Global Multi Count */
  93190. + unsigned gmc:2;
  93191. + /** Ignore Frame Number for ISOC EPs */
  93192. + unsigned ifrmnum:1;
  93193. + /** NAK on Babble */
  93194. + unsigned nakonbble:1;
  93195. + /** Enable Continue on BNA */
  93196. + unsigned encontonbna:1;
  93197. +
  93198. + unsigned reserved18_31:14;
  93199. + } b;
  93200. +} dctl_data_t;
  93201. +
  93202. +/**
  93203. + * This union represents the bit fields in the Device Status
  93204. + * Register. Read the register into the <i>d32</i> member then
  93205. + * set/clear the bits using the <i>b</i>it elements.
  93206. + */
  93207. +typedef union dsts_data {
  93208. + /** raw register data */
  93209. + uint32_t d32;
  93210. + /** register bits */
  93211. + struct {
  93212. + /** Suspend Status */
  93213. + unsigned suspsts:1;
  93214. + /** Enumerated Speed */
  93215. + unsigned enumspd:2;
  93216. +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
  93217. +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
  93218. +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
  93219. +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
  93220. + /** Erratic Error */
  93221. + unsigned errticerr:1;
  93222. + unsigned reserved4_7:4;
  93223. + /** Frame or Microframe Number of the received SOF */
  93224. + unsigned soffn:14;
  93225. + unsigned reserved22_31:10;
  93226. + } b;
  93227. +} dsts_data_t;
  93228. +
  93229. +/**
  93230. + * This union represents the bit fields in the Device IN EP Interrupt
  93231. + * Register and the Device IN EP Common Mask Register.
  93232. + *
  93233. + * - Read the register into the <i>d32</i> member then set/clear the
  93234. + * bits using the <i>b</i>it elements.
  93235. + */
  93236. +typedef union diepint_data {
  93237. + /** raw register data */
  93238. + uint32_t d32;
  93239. + /** register bits */
  93240. + struct {
  93241. + /** Transfer complete mask */
  93242. + unsigned xfercompl:1;
  93243. + /** Endpoint disable mask */
  93244. + unsigned epdisabled:1;
  93245. + /** AHB Error mask */
  93246. + unsigned ahberr:1;
  93247. + /** TimeOUT Handshake mask (non-ISOC EPs) */
  93248. + unsigned timeout:1;
  93249. + /** IN Token received with TxF Empty mask */
  93250. + unsigned intktxfemp:1;
  93251. + /** IN Token Received with EP mismatch mask */
  93252. + unsigned intknepmis:1;
  93253. + /** IN Endpoint NAK Effective mask */
  93254. + unsigned inepnakeff:1;
  93255. + /** Reserved */
  93256. + unsigned emptyintr:1;
  93257. +
  93258. + unsigned txfifoundrn:1;
  93259. +
  93260. + /** BNA Interrupt mask */
  93261. + unsigned bna:1;
  93262. +
  93263. + unsigned reserved10_12:3;
  93264. + /** BNA Interrupt mask */
  93265. + unsigned nak:1;
  93266. +
  93267. + unsigned reserved14_31:18;
  93268. + } b;
  93269. +} diepint_data_t;
  93270. +
  93271. +/**
  93272. + * This union represents the bit fields in the Device IN EP
  93273. + * Common/Dedicated Interrupt Mask Register.
  93274. + */
  93275. +typedef union diepint_data diepmsk_data_t;
  93276. +
  93277. +/**
  93278. + * This union represents the bit fields in the Device OUT EP Interrupt
  93279. + * Registerand Device OUT EP Common Interrupt Mask Register.
  93280. + *
  93281. + * - Read the register into the <i>d32</i> member then set/clear the
  93282. + * bits using the <i>b</i>it elements.
  93283. + */
  93284. +typedef union doepint_data {
  93285. + /** raw register data */
  93286. + uint32_t d32;
  93287. + /** register bits */
  93288. + struct {
  93289. + /** Transfer complete */
  93290. + unsigned xfercompl:1;
  93291. + /** Endpoint disable */
  93292. + unsigned epdisabled:1;
  93293. + /** AHB Error */
  93294. + unsigned ahberr:1;
  93295. + /** Setup Phase Done (contorl EPs) */
  93296. + unsigned setup:1;
  93297. + /** OUT Token Received when Endpoint Disabled */
  93298. + unsigned outtknepdis:1;
  93299. +
  93300. + unsigned stsphsercvd:1;
  93301. + /** Back-to-Back SETUP Packets Received */
  93302. + unsigned back2backsetup:1;
  93303. +
  93304. + unsigned reserved7:1;
  93305. + /** OUT packet Error */
  93306. + unsigned outpkterr:1;
  93307. + /** BNA Interrupt */
  93308. + unsigned bna:1;
  93309. +
  93310. + unsigned reserved10:1;
  93311. + /** Packet Drop Status */
  93312. + unsigned pktdrpsts:1;
  93313. + /** Babble Interrupt */
  93314. + unsigned babble:1;
  93315. + /** NAK Interrupt */
  93316. + unsigned nak:1;
  93317. + /** NYET Interrupt */
  93318. + unsigned nyet:1;
  93319. + /** Bit indicating setup packet received */
  93320. + unsigned sr:1;
  93321. +
  93322. + unsigned reserved16_31:16;
  93323. + } b;
  93324. +} doepint_data_t;
  93325. +
  93326. +/**
  93327. + * This union represents the bit fields in the Device OUT EP
  93328. + * Common/Dedicated Interrupt Mask Register.
  93329. + */
  93330. +typedef union doepint_data doepmsk_data_t;
  93331. +
  93332. +/**
  93333. + * This union represents the bit fields in the Device All EP Interrupt
  93334. + * and Mask Registers.
  93335. + * - Read the register into the <i>d32</i> member then set/clear the
  93336. + * bits using the <i>b</i>it elements.
  93337. + */
  93338. +typedef union daint_data {
  93339. + /** raw register data */
  93340. + uint32_t d32;
  93341. + /** register bits */
  93342. + struct {
  93343. + /** IN Endpoint bits */
  93344. + unsigned in:16;
  93345. + /** OUT Endpoint bits */
  93346. + unsigned out:16;
  93347. + } ep;
  93348. + struct {
  93349. + /** IN Endpoint bits */
  93350. + unsigned inep0:1;
  93351. + unsigned inep1:1;
  93352. + unsigned inep2:1;
  93353. + unsigned inep3:1;
  93354. + unsigned inep4:1;
  93355. + unsigned inep5:1;
  93356. + unsigned inep6:1;
  93357. + unsigned inep7:1;
  93358. + unsigned inep8:1;
  93359. + unsigned inep9:1;
  93360. + unsigned inep10:1;
  93361. + unsigned inep11:1;
  93362. + unsigned inep12:1;
  93363. + unsigned inep13:1;
  93364. + unsigned inep14:1;
  93365. + unsigned inep15:1;
  93366. + /** OUT Endpoint bits */
  93367. + unsigned outep0:1;
  93368. + unsigned outep1:1;
  93369. + unsigned outep2:1;
  93370. + unsigned outep3:1;
  93371. + unsigned outep4:1;
  93372. + unsigned outep5:1;
  93373. + unsigned outep6:1;
  93374. + unsigned outep7:1;
  93375. + unsigned outep8:1;
  93376. + unsigned outep9:1;
  93377. + unsigned outep10:1;
  93378. + unsigned outep11:1;
  93379. + unsigned outep12:1;
  93380. + unsigned outep13:1;
  93381. + unsigned outep14:1;
  93382. + unsigned outep15:1;
  93383. + } b;
  93384. +} daint_data_t;
  93385. +
  93386. +/**
  93387. + * This union represents the bit fields in the Device IN Token Queue
  93388. + * Read Registers.
  93389. + * - Read the register into the <i>d32</i> member.
  93390. + * - READ-ONLY Register
  93391. + */
  93392. +typedef union dtknq1_data {
  93393. + /** raw register data */
  93394. + uint32_t d32;
  93395. + /** register bits */
  93396. + struct {
  93397. + /** In Token Queue Write Pointer */
  93398. + unsigned intknwptr:5;
  93399. + /** Reserved */
  93400. + unsigned reserved05_06:2;
  93401. + /** write pointer has wrapped. */
  93402. + unsigned wrap_bit:1;
  93403. + /** EP Numbers of IN Tokens 0 ... 4 */
  93404. + unsigned epnums0_5:24;
  93405. + } b;
  93406. +} dtknq1_data_t;
  93407. +
  93408. +/**
  93409. + * This union represents Threshold control Register
  93410. + * - Read and write the register into the <i>d32</i> member.
  93411. + * - READ-WRITABLE Register
  93412. + */
  93413. +typedef union dthrctl_data {
  93414. + /** raw register data */
  93415. + uint32_t d32;
  93416. + /** register bits */
  93417. + struct {
  93418. + /** non ISO Tx Thr. Enable */
  93419. + unsigned non_iso_thr_en:1;
  93420. + /** ISO Tx Thr. Enable */
  93421. + unsigned iso_thr_en:1;
  93422. + /** Tx Thr. Length */
  93423. + unsigned tx_thr_len:9;
  93424. + /** AHB Threshold ratio */
  93425. + unsigned ahb_thr_ratio:2;
  93426. + /** Reserved */
  93427. + unsigned reserved13_15:3;
  93428. + /** Rx Thr. Enable */
  93429. + unsigned rx_thr_en:1;
  93430. + /** Rx Thr. Length */
  93431. + unsigned rx_thr_len:9;
  93432. + unsigned reserved26:1;
  93433. + /** Arbiter Parking Enable*/
  93434. + unsigned arbprken:1;
  93435. + /** Reserved */
  93436. + unsigned reserved28_31:4;
  93437. + } b;
  93438. +} dthrctl_data_t;
  93439. +
  93440. +/**
  93441. + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
  93442. + * 900h-AFCh</i>
  93443. + *
  93444. + * There will be one set of endpoint registers per logical endpoint
  93445. + * implemented.
  93446. + *
  93447. + * <i>These registers are visible only in Device mode and must not be
  93448. + * accessed in Host mode, as the results are unknown.</i>
  93449. + */
  93450. +typedef struct dwc_otg_dev_in_ep_regs {
  93451. + /** Device IN Endpoint Control Register. <i>Offset:900h +
  93452. + * (ep_num * 20h) + 00h</i> */
  93453. + volatile uint32_t diepctl;
  93454. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
  93455. + uint32_t reserved04;
  93456. + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
  93457. + * (ep_num * 20h) + 08h</i> */
  93458. + volatile uint32_t diepint;
  93459. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
  93460. + uint32_t reserved0C;
  93461. + /** Device IN Endpoint Transfer Size
  93462. + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
  93463. + volatile uint32_t dieptsiz;
  93464. + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
  93465. + * (ep_num * 20h) + 14h</i> */
  93466. + volatile uint32_t diepdma;
  93467. + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
  93468. + * (ep_num * 20h) + 18h</i> */
  93469. + volatile uint32_t dtxfsts;
  93470. + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
  93471. + * (ep_num * 20h) + 1Ch</i> */
  93472. + volatile uint32_t diepdmab;
  93473. +} dwc_otg_dev_in_ep_regs_t;
  93474. +
  93475. +/**
  93476. + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
  93477. + * B00h-CFCh</i>
  93478. + *
  93479. + * There will be one set of endpoint registers per logical endpoint
  93480. + * implemented.
  93481. + *
  93482. + * <i>These registers are visible only in Device mode and must not be
  93483. + * accessed in Host mode, as the results are unknown.</i>
  93484. + */
  93485. +typedef struct dwc_otg_dev_out_ep_regs {
  93486. + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
  93487. + * (ep_num * 20h) + 00h</i> */
  93488. + volatile uint32_t doepctl;
  93489. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 04h</i> */
  93490. + uint32_t reserved04;
  93491. + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
  93492. + * (ep_num * 20h) + 08h</i> */
  93493. + volatile uint32_t doepint;
  93494. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
  93495. + uint32_t reserved0C;
  93496. + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
  93497. + * B00h + (ep_num * 20h) + 10h</i> */
  93498. + volatile uint32_t doeptsiz;
  93499. + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
  93500. + * + (ep_num * 20h) + 14h</i> */
  93501. + volatile uint32_t doepdma;
  93502. + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 18h</i> */
  93503. + uint32_t unused;
  93504. + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
  93505. + * + (ep_num * 20h) + 1Ch</i> */
  93506. + uint32_t doepdmab;
  93507. +} dwc_otg_dev_out_ep_regs_t;
  93508. +
  93509. +/**
  93510. + * This union represents the bit fields in the Device EP Control
  93511. + * Register. Read the register into the <i>d32</i> member then
  93512. + * set/clear the bits using the <i>b</i>it elements.
  93513. + */
  93514. +typedef union depctl_data {
  93515. + /** raw register data */
  93516. + uint32_t d32;
  93517. + /** register bits */
  93518. + struct {
  93519. + /** Maximum Packet Size
  93520. + * IN/OUT EPn
  93521. + * IN/OUT EP0 - 2 bits
  93522. + * 2'b00: 64 Bytes
  93523. + * 2'b01: 32
  93524. + * 2'b10: 16
  93525. + * 2'b11: 8 */
  93526. + unsigned mps:11;
  93527. +#define DWC_DEP0CTL_MPS_64 0
  93528. +#define DWC_DEP0CTL_MPS_32 1
  93529. +#define DWC_DEP0CTL_MPS_16 2
  93530. +#define DWC_DEP0CTL_MPS_8 3
  93531. +
  93532. + /** Next Endpoint
  93533. + * IN EPn/IN EP0
  93534. + * OUT EPn/OUT EP0 - reserved */
  93535. + unsigned nextep:4;
  93536. +
  93537. + /** USB Active Endpoint */
  93538. + unsigned usbactep:1;
  93539. +
  93540. + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
  93541. + * This field contains the PID of the packet going to
  93542. + * be received or transmitted on this endpoint. The
  93543. + * application should program the PID of the first
  93544. + * packet going to be received or transmitted on this
  93545. + * endpoint , after the endpoint is
  93546. + * activated. Application use the SetD1PID and
  93547. + * SetD0PID fields of this register to program either
  93548. + * D0 or D1 PID.
  93549. + *
  93550. + * The encoding for this field is
  93551. + * - 0: D0
  93552. + * - 1: D1
  93553. + */
  93554. + unsigned dpid:1;
  93555. +
  93556. + /** NAK Status */
  93557. + unsigned naksts:1;
  93558. +
  93559. + /** Endpoint Type
  93560. + * 2'b00: Control
  93561. + * 2'b01: Isochronous
  93562. + * 2'b10: Bulk
  93563. + * 2'b11: Interrupt */
  93564. + unsigned eptype:2;
  93565. +
  93566. + /** Snoop Mode
  93567. + * OUT EPn/OUT EP0
  93568. + * IN EPn/IN EP0 - reserved */
  93569. + unsigned snp:1;
  93570. +
  93571. + /** Stall Handshake */
  93572. + unsigned stall:1;
  93573. +
  93574. + /** Tx Fifo Number
  93575. + * IN EPn/IN EP0
  93576. + * OUT EPn/OUT EP0 - reserved */
  93577. + unsigned txfnum:4;
  93578. +
  93579. + /** Clear NAK */
  93580. + unsigned cnak:1;
  93581. + /** Set NAK */
  93582. + unsigned snak:1;
  93583. + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
  93584. + * Writing to this field sets the Endpoint DPID (DPID)
  93585. + * field in this register to DATA0. Set Even
  93586. + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
  93587. + * Writing to this field sets the Even/Odd
  93588. + * (micro)frame (EO_FrNum) field to even (micro)
  93589. + * frame.
  93590. + */
  93591. + unsigned setd0pid:1;
  93592. + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
  93593. + * Writing to this field sets the Endpoint DPID (DPID)
  93594. + * field in this register to DATA1 Set Odd
  93595. + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
  93596. + * Writing to this field sets the Even/Odd
  93597. + * (micro)frame (EO_FrNum) field to odd (micro) frame.
  93598. + */
  93599. + unsigned setd1pid:1;
  93600. +
  93601. + /** Endpoint Disable */
  93602. + unsigned epdis:1;
  93603. + /** Endpoint Enable */
  93604. + unsigned epena:1;
  93605. + } b;
  93606. +} depctl_data_t;
  93607. +
  93608. +/**
  93609. + * This union represents the bit fields in the Device EP Transfer
  93610. + * Size Register. Read the register into the <i>d32</i> member then
  93611. + * set/clear the bits using the <i>b</i>it elements.
  93612. + */
  93613. +typedef union deptsiz_data {
  93614. + /** raw register data */
  93615. + uint32_t d32;
  93616. + /** register bits */
  93617. + struct {
  93618. + /** Transfer size */
  93619. + unsigned xfersize:19;
  93620. +/** Max packet count for EP (pow(2,10)-1) */
  93621. +#define MAX_PKT_CNT 1023
  93622. + /** Packet Count */
  93623. + unsigned pktcnt:10;
  93624. + /** Multi Count - Periodic IN endpoints */
  93625. + unsigned mc:2;
  93626. + unsigned reserved:1;
  93627. + } b;
  93628. +} deptsiz_data_t;
  93629. +
  93630. +/**
  93631. + * This union represents the bit fields in the Device EP 0 Transfer
  93632. + * Size Register. Read the register into the <i>d32</i> member then
  93633. + * set/clear the bits using the <i>b</i>it elements.
  93634. + */
  93635. +typedef union deptsiz0_data {
  93636. + /** raw register data */
  93637. + uint32_t d32;
  93638. + /** register bits */
  93639. + struct {
  93640. + /** Transfer size */
  93641. + unsigned xfersize:7;
  93642. + /** Reserved */
  93643. + unsigned reserved7_18:12;
  93644. + /** Packet Count */
  93645. + unsigned pktcnt:2;
  93646. + /** Reserved */
  93647. + unsigned reserved21_28:8;
  93648. + /**Setup Packet Count (DOEPTSIZ0 Only) */
  93649. + unsigned supcnt:2;
  93650. + unsigned reserved31;
  93651. + } b;
  93652. +} deptsiz0_data_t;
  93653. +
  93654. +/////////////////////////////////////////////////
  93655. +// DMA Descriptor Specific Structures
  93656. +//
  93657. +
  93658. +/** Buffer status definitions */
  93659. +
  93660. +#define BS_HOST_READY 0x0
  93661. +#define BS_DMA_BUSY 0x1
  93662. +#define BS_DMA_DONE 0x2
  93663. +#define BS_HOST_BUSY 0x3
  93664. +
  93665. +/** Receive/Transmit status definitions */
  93666. +
  93667. +#define RTS_SUCCESS 0x0
  93668. +#define RTS_BUFFLUSH 0x1
  93669. +#define RTS_RESERVED 0x2
  93670. +#define RTS_BUFERR 0x3
  93671. +
  93672. +/**
  93673. + * This union represents the bit fields in the DMA Descriptor
  93674. + * status quadlet. Read the quadlet into the <i>d32</i> member then
  93675. + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
  93676. + * <i>b_iso_in</i> elements.
  93677. + */
  93678. +typedef union dev_dma_desc_sts {
  93679. + /** raw register data */
  93680. + uint32_t d32;
  93681. + /** quadlet bits */
  93682. + struct {
  93683. + /** Received number of bytes */
  93684. + unsigned bytes:16;
  93685. + /** NAK bit - only for OUT EPs */
  93686. + unsigned nak:1;
  93687. + unsigned reserved17_22:6;
  93688. + /** Multiple Transfer - only for OUT EPs */
  93689. + unsigned mtrf:1;
  93690. + /** Setup Packet received - only for OUT EPs */
  93691. + unsigned sr:1;
  93692. + /** Interrupt On Complete */
  93693. + unsigned ioc:1;
  93694. + /** Short Packet */
  93695. + unsigned sp:1;
  93696. + /** Last */
  93697. + unsigned l:1;
  93698. + /** Receive Status */
  93699. + unsigned sts:2;
  93700. + /** Buffer Status */
  93701. + unsigned bs:2;
  93702. + } b;
  93703. +
  93704. +//#ifdef DWC_EN_ISOC
  93705. + /** iso out quadlet bits */
  93706. + struct {
  93707. + /** Received number of bytes */
  93708. + unsigned rxbytes:11;
  93709. +
  93710. + unsigned reserved11:1;
  93711. + /** Frame Number */
  93712. + unsigned framenum:11;
  93713. + /** Received ISO Data PID */
  93714. + unsigned pid:2;
  93715. + /** Interrupt On Complete */
  93716. + unsigned ioc:1;
  93717. + /** Short Packet */
  93718. + unsigned sp:1;
  93719. + /** Last */
  93720. + unsigned l:1;
  93721. + /** Receive Status */
  93722. + unsigned rxsts:2;
  93723. + /** Buffer Status */
  93724. + unsigned bs:2;
  93725. + } b_iso_out;
  93726. +
  93727. + /** iso in quadlet bits */
  93728. + struct {
  93729. + /** Transmited number of bytes */
  93730. + unsigned txbytes:12;
  93731. + /** Frame Number */
  93732. + unsigned framenum:11;
  93733. + /** Transmited ISO Data PID */
  93734. + unsigned pid:2;
  93735. + /** Interrupt On Complete */
  93736. + unsigned ioc:1;
  93737. + /** Short Packet */
  93738. + unsigned sp:1;
  93739. + /** Last */
  93740. + unsigned l:1;
  93741. + /** Transmit Status */
  93742. + unsigned txsts:2;
  93743. + /** Buffer Status */
  93744. + unsigned bs:2;
  93745. + } b_iso_in;
  93746. +//#endif /* DWC_EN_ISOC */
  93747. +} dev_dma_desc_sts_t;
  93748. +
  93749. +/**
  93750. + * DMA Descriptor structure
  93751. + *
  93752. + * DMA Descriptor structure contains two quadlets:
  93753. + * Status quadlet and Data buffer pointer.
  93754. + */
  93755. +typedef struct dwc_otg_dev_dma_desc {
  93756. + /** DMA Descriptor status quadlet */
  93757. + dev_dma_desc_sts_t status;
  93758. + /** DMA Descriptor data buffer pointer */
  93759. + uint32_t buf;
  93760. +} dwc_otg_dev_dma_desc_t;
  93761. +
  93762. +/**
  93763. + * The dwc_otg_dev_if structure contains information needed to manage
  93764. + * the DWC_otg controller acting in device mode. It represents the
  93765. + * programming view of the device-specific aspects of the controller.
  93766. + */
  93767. +typedef struct dwc_otg_dev_if {
  93768. + /** Pointer to device Global registers.
  93769. + * Device Global Registers starting at offset 800h
  93770. + */
  93771. + dwc_otg_device_global_regs_t *dev_global_regs;
  93772. +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
  93773. +
  93774. + /**
  93775. + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
  93776. + */
  93777. + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
  93778. +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
  93779. +#define DWC_EP_REG_OFFSET 0x20
  93780. +
  93781. + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
  93782. + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
  93783. +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
  93784. +
  93785. + /* Device configuration information */
  93786. + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
  93787. + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
  93788. + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
  93789. +
  93790. + /** Size of periodic FIFOs (Bytes) */
  93791. + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
  93792. +
  93793. + /** Size of Tx FIFOs (Bytes) */
  93794. + uint16_t tx_fifo_size[MAX_TX_FIFOS];
  93795. +
  93796. + /** Thresholding enable flags and length varaiables **/
  93797. + uint16_t rx_thr_en;
  93798. + uint16_t iso_tx_thr_en;
  93799. + uint16_t non_iso_tx_thr_en;
  93800. +
  93801. + uint16_t rx_thr_length;
  93802. + uint16_t tx_thr_length;
  93803. +
  93804. + /**
  93805. + * Pointers to the DMA Descriptors for EP0 Control
  93806. + * transfers (virtual and physical)
  93807. + */
  93808. +
  93809. + /** 2 descriptors for SETUP packets */
  93810. + dwc_dma_t dma_setup_desc_addr[2];
  93811. + dwc_otg_dev_dma_desc_t *setup_desc_addr[2];
  93812. +
  93813. + /** Pointer to Descriptor with latest SETUP packet */
  93814. + dwc_otg_dev_dma_desc_t *psetup;
  93815. +
  93816. + /** Index of current SETUP handler descriptor */
  93817. + uint32_t setup_desc_index;
  93818. +
  93819. + /** Descriptor for Data In or Status In phases */
  93820. + dwc_dma_t dma_in_desc_addr;
  93821. + dwc_otg_dev_dma_desc_t *in_desc_addr;
  93822. +
  93823. + /** Descriptor for Data Out or Status Out phases */
  93824. + dwc_dma_t dma_out_desc_addr;
  93825. + dwc_otg_dev_dma_desc_t *out_desc_addr;
  93826. +
  93827. + /** Setup Packet Detected - if set clear NAK when queueing */
  93828. + uint32_t spd;
  93829. + /** Isoc ep pointer on which incomplete happens */
  93830. + void *isoc_ep;
  93831. +
  93832. +} dwc_otg_dev_if_t;
  93833. +
  93834. +/////////////////////////////////////////////////
  93835. +// Host Mode Register Structures
  93836. +//
  93837. +/**
  93838. + * The Host Global Registers structure defines the size and relative
  93839. + * field offsets for the Host Mode Global Registers. Host Global
  93840. + * Registers offsets 400h-7FFh.
  93841. +*/
  93842. +typedef struct dwc_otg_host_global_regs {
  93843. + /** Host Configuration Register. <i>Offset: 400h</i> */
  93844. + volatile uint32_t hcfg;
  93845. + /** Host Frame Interval Register. <i>Offset: 404h</i> */
  93846. + volatile uint32_t hfir;
  93847. + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
  93848. + volatile uint32_t hfnum;
  93849. + /** Reserved. <i>Offset: 40Ch</i> */
  93850. + uint32_t reserved40C;
  93851. + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
  93852. + volatile uint32_t hptxsts;
  93853. + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
  93854. + volatile uint32_t haint;
  93855. + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
  93856. + volatile uint32_t haintmsk;
  93857. + /** Host Frame List Base Address Register . <i>Offset: 41Ch</i> */
  93858. + volatile uint32_t hflbaddr;
  93859. +} dwc_otg_host_global_regs_t;
  93860. +
  93861. +/**
  93862. + * This union represents the bit fields in the Host Configuration Register.
  93863. + * Read the register into the <i>d32</i> member then set/clear the bits using
  93864. + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
  93865. + */
  93866. +typedef union hcfg_data {
  93867. + /** raw register data */
  93868. + uint32_t d32;
  93869. +
  93870. + /** register bits */
  93871. + struct {
  93872. + /** FS/LS Phy Clock Select */
  93873. + unsigned fslspclksel:2;
  93874. +#define DWC_HCFG_30_60_MHZ 0
  93875. +#define DWC_HCFG_48_MHZ 1
  93876. +#define DWC_HCFG_6_MHZ 2
  93877. +
  93878. + /** FS/LS Only Support */
  93879. + unsigned fslssupp:1;
  93880. + unsigned reserved3_6:4;
  93881. + /** Enable 32-KHz Suspend Mode */
  93882. + unsigned ena32khzs:1;
  93883. + /** Resume Validation Periiod */
  93884. + unsigned resvalid:8;
  93885. + unsigned reserved16_22:7;
  93886. + /** Enable Scatter/gather DMA in Host mode */
  93887. + unsigned descdma:1;
  93888. + /** Frame List Entries */
  93889. + unsigned frlisten:2;
  93890. + /** Enable Periodic Scheduling */
  93891. + unsigned perschedena:1;
  93892. + unsigned reserved27_30:4;
  93893. + unsigned modechtimen:1;
  93894. + } b;
  93895. +} hcfg_data_t;
  93896. +
  93897. +/**
  93898. + * This union represents the bit fields in the Host Frame Remaing/Number
  93899. + * Register.
  93900. + */
  93901. +typedef union hfir_data {
  93902. + /** raw register data */
  93903. + uint32_t d32;
  93904. +
  93905. + /** register bits */
  93906. + struct {
  93907. + unsigned frint:16;
  93908. + unsigned hfirrldctrl:1;
  93909. + unsigned reserved:15;
  93910. + } b;
  93911. +} hfir_data_t;
  93912. +
  93913. +/**
  93914. + * This union represents the bit fields in the Host Frame Remaing/Number
  93915. + * Register.
  93916. + */
  93917. +typedef union hfnum_data {
  93918. + /** raw register data */
  93919. + uint32_t d32;
  93920. +
  93921. + /** register bits */
  93922. + struct {
  93923. + unsigned frnum:16;
  93924. +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
  93925. + unsigned frrem:16;
  93926. + } b;
  93927. +} hfnum_data_t;
  93928. +
  93929. +typedef union hptxsts_data {
  93930. + /** raw register data */
  93931. + uint32_t d32;
  93932. +
  93933. + /** register bits */
  93934. + struct {
  93935. + unsigned ptxfspcavail:16;
  93936. + unsigned ptxqspcavail:8;
  93937. + /** Top of the Periodic Transmit Request Queue
  93938. + * - bit 24 - Terminate (last entry for the selected channel)
  93939. + * - bits 26:25 - Token Type
  93940. + * - 2'b00 - Zero length
  93941. + * - 2'b01 - Ping
  93942. + * - 2'b10 - Disable
  93943. + * - bits 30:27 - Channel Number
  93944. + * - bit 31 - Odd/even microframe
  93945. + */
  93946. + unsigned ptxqtop_terminate:1;
  93947. + unsigned ptxqtop_token:2;
  93948. + unsigned ptxqtop_chnum:4;
  93949. + unsigned ptxqtop_odd:1;
  93950. + } b;
  93951. +} hptxsts_data_t;
  93952. +
  93953. +/**
  93954. + * This union represents the bit fields in the Host Port Control and Status
  93955. + * Register. Read the register into the <i>d32</i> member then set/clear the
  93956. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  93957. + * hprt0 register.
  93958. + */
  93959. +typedef union hprt0_data {
  93960. + /** raw register data */
  93961. + uint32_t d32;
  93962. + /** register bits */
  93963. + struct {
  93964. + unsigned prtconnsts:1;
  93965. + unsigned prtconndet:1;
  93966. + unsigned prtena:1;
  93967. + unsigned prtenchng:1;
  93968. + unsigned prtovrcurract:1;
  93969. + unsigned prtovrcurrchng:1;
  93970. + unsigned prtres:1;
  93971. + unsigned prtsusp:1;
  93972. + unsigned prtrst:1;
  93973. + unsigned reserved9:1;
  93974. + unsigned prtlnsts:2;
  93975. + unsigned prtpwr:1;
  93976. + unsigned prttstctl:4;
  93977. + unsigned prtspd:2;
  93978. +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
  93979. +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
  93980. +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
  93981. + unsigned reserved19_31:13;
  93982. + } b;
  93983. +} hprt0_data_t;
  93984. +
  93985. +/**
  93986. + * This union represents the bit fields in the Host All Interrupt
  93987. + * Register.
  93988. + */
  93989. +typedef union haint_data {
  93990. + /** raw register data */
  93991. + uint32_t d32;
  93992. + /** register bits */
  93993. + struct {
  93994. + unsigned ch0:1;
  93995. + unsigned ch1:1;
  93996. + unsigned ch2:1;
  93997. + unsigned ch3:1;
  93998. + unsigned ch4:1;
  93999. + unsigned ch5:1;
  94000. + unsigned ch6:1;
  94001. + unsigned ch7:1;
  94002. + unsigned ch8:1;
  94003. + unsigned ch9:1;
  94004. + unsigned ch10:1;
  94005. + unsigned ch11:1;
  94006. + unsigned ch12:1;
  94007. + unsigned ch13:1;
  94008. + unsigned ch14:1;
  94009. + unsigned ch15:1;
  94010. + unsigned reserved:16;
  94011. + } b;
  94012. +
  94013. + struct {
  94014. + unsigned chint:16;
  94015. + unsigned reserved:16;
  94016. + } b2;
  94017. +} haint_data_t;
  94018. +
  94019. +/**
  94020. + * This union represents the bit fields in the Host All Interrupt
  94021. + * Register.
  94022. + */
  94023. +typedef union haintmsk_data {
  94024. + /** raw register data */
  94025. + uint32_t d32;
  94026. + /** register bits */
  94027. + struct {
  94028. + unsigned ch0:1;
  94029. + unsigned ch1:1;
  94030. + unsigned ch2:1;
  94031. + unsigned ch3:1;
  94032. + unsigned ch4:1;
  94033. + unsigned ch5:1;
  94034. + unsigned ch6:1;
  94035. + unsigned ch7:1;
  94036. + unsigned ch8:1;
  94037. + unsigned ch9:1;
  94038. + unsigned ch10:1;
  94039. + unsigned ch11:1;
  94040. + unsigned ch12:1;
  94041. + unsigned ch13:1;
  94042. + unsigned ch14:1;
  94043. + unsigned ch15:1;
  94044. + unsigned reserved:16;
  94045. + } b;
  94046. +
  94047. + struct {
  94048. + unsigned chint:16;
  94049. + unsigned reserved:16;
  94050. + } b2;
  94051. +} haintmsk_data_t;
  94052. +
  94053. +/**
  94054. + * Host Channel Specific Registers. <i>500h-5FCh</i>
  94055. + */
  94056. +typedef struct dwc_otg_hc_regs {
  94057. + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
  94058. + volatile uint32_t hcchar;
  94059. + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
  94060. + volatile uint32_t hcsplt;
  94061. + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
  94062. + volatile uint32_t hcint;
  94063. + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
  94064. + volatile uint32_t hcintmsk;
  94065. + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
  94066. + volatile uint32_t hctsiz;
  94067. + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
  94068. + volatile uint32_t hcdma;
  94069. + volatile uint32_t reserved;
  94070. + /** Host Channel 0 DMA Buffer Address Register. <i>Offset: 500h + (chan_num * 20h) + 1Ch</i> */
  94071. + volatile uint32_t hcdmab;
  94072. +} dwc_otg_hc_regs_t;
  94073. +
  94074. +/**
  94075. + * This union represents the bit fields in the Host Channel Characteristics
  94076. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94077. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  94078. + * hcchar register.
  94079. + */
  94080. +typedef union hcchar_data {
  94081. + /** raw register data */
  94082. + uint32_t d32;
  94083. +
  94084. + /** register bits */
  94085. + struct {
  94086. + /** Maximum packet size in bytes */
  94087. + unsigned mps:11;
  94088. +
  94089. + /** Endpoint number */
  94090. + unsigned epnum:4;
  94091. +
  94092. + /** 0: OUT, 1: IN */
  94093. + unsigned epdir:1;
  94094. +
  94095. + unsigned reserved:1;
  94096. +
  94097. + /** 0: Full/high speed device, 1: Low speed device */
  94098. + unsigned lspddev:1;
  94099. +
  94100. + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
  94101. + unsigned eptype:2;
  94102. +
  94103. + /** Packets per frame for periodic transfers. 0 is reserved. */
  94104. + unsigned multicnt:2;
  94105. +
  94106. + /** Device address */
  94107. + unsigned devaddr:7;
  94108. +
  94109. + /**
  94110. + * Frame to transmit periodic transaction.
  94111. + * 0: even, 1: odd
  94112. + */
  94113. + unsigned oddfrm:1;
  94114. +
  94115. + /** Channel disable */
  94116. + unsigned chdis:1;
  94117. +
  94118. + /** Channel enable */
  94119. + unsigned chen:1;
  94120. + } b;
  94121. +} hcchar_data_t;
  94122. +
  94123. +typedef union hcsplt_data {
  94124. + /** raw register data */
  94125. + uint32_t d32;
  94126. +
  94127. + /** register bits */
  94128. + struct {
  94129. + /** Port Address */
  94130. + unsigned prtaddr:7;
  94131. +
  94132. + /** Hub Address */
  94133. + unsigned hubaddr:7;
  94134. +
  94135. + /** Transaction Position */
  94136. + unsigned xactpos:2;
  94137. +#define DWC_HCSPLIT_XACTPOS_MID 0
  94138. +#define DWC_HCSPLIT_XACTPOS_END 1
  94139. +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
  94140. +#define DWC_HCSPLIT_XACTPOS_ALL 3
  94141. +
  94142. + /** Do Complete Split */
  94143. + unsigned compsplt:1;
  94144. +
  94145. + /** Reserved */
  94146. + unsigned reserved:14;
  94147. +
  94148. + /** Split Enble */
  94149. + unsigned spltena:1;
  94150. + } b;
  94151. +} hcsplt_data_t;
  94152. +
  94153. +/**
  94154. + * This union represents the bit fields in the Host All Interrupt
  94155. + * Register.
  94156. + */
  94157. +typedef union hcint_data {
  94158. + /** raw register data */
  94159. + uint32_t d32;
  94160. + /** register bits */
  94161. + struct {
  94162. + /** Transfer Complete */
  94163. + unsigned xfercomp:1;
  94164. + /** Channel Halted */
  94165. + unsigned chhltd:1;
  94166. + /** AHB Error */
  94167. + unsigned ahberr:1;
  94168. + /** STALL Response Received */
  94169. + unsigned stall:1;
  94170. + /** NAK Response Received */
  94171. + unsigned nak:1;
  94172. + /** ACK Response Received */
  94173. + unsigned ack:1;
  94174. + /** NYET Response Received */
  94175. + unsigned nyet:1;
  94176. + /** Transaction Err */
  94177. + unsigned xacterr:1;
  94178. + /** Babble Error */
  94179. + unsigned bblerr:1;
  94180. + /** Frame Overrun */
  94181. + unsigned frmovrun:1;
  94182. + /** Data Toggle Error */
  94183. + unsigned datatglerr:1;
  94184. + /** Buffer Not Available (only for DDMA mode) */
  94185. + unsigned bna:1;
  94186. + /** Exessive transaction error (only for DDMA mode) */
  94187. + unsigned xcs_xact:1;
  94188. + /** Frame List Rollover interrupt */
  94189. + unsigned frm_list_roll:1;
  94190. + /** Reserved */
  94191. + unsigned reserved14_31:18;
  94192. + } b;
  94193. +} hcint_data_t;
  94194. +
  94195. +/**
  94196. + * This union represents the bit fields in the Host Channel Interrupt Mask
  94197. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94198. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  94199. + * hcintmsk register.
  94200. + */
  94201. +typedef union hcintmsk_data {
  94202. + /** raw register data */
  94203. + uint32_t d32;
  94204. +
  94205. + /** register bits */
  94206. + struct {
  94207. + unsigned xfercompl:1;
  94208. + unsigned chhltd:1;
  94209. + unsigned ahberr:1;
  94210. + unsigned stall:1;
  94211. + unsigned nak:1;
  94212. + unsigned ack:1;
  94213. + unsigned nyet:1;
  94214. + unsigned xacterr:1;
  94215. + unsigned bblerr:1;
  94216. + unsigned frmovrun:1;
  94217. + unsigned datatglerr:1;
  94218. + unsigned bna:1;
  94219. + unsigned xcs_xact:1;
  94220. + unsigned frm_list_roll:1;
  94221. + unsigned reserved14_31:18;
  94222. + } b;
  94223. +} hcintmsk_data_t;
  94224. +
  94225. +/**
  94226. + * This union represents the bit fields in the Host Channel Transfer Size
  94227. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94228. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  94229. + * hcchar register.
  94230. + */
  94231. +
  94232. +typedef union hctsiz_data {
  94233. + /** raw register data */
  94234. + uint32_t d32;
  94235. +
  94236. + /** register bits */
  94237. + struct {
  94238. + /** Total transfer size in bytes */
  94239. + unsigned xfersize:19;
  94240. +
  94241. + /** Data packets to transfer */
  94242. + unsigned pktcnt:10;
  94243. +
  94244. + /**
  94245. + * Packet ID for next data packet
  94246. + * 0: DATA0
  94247. + * 1: DATA2
  94248. + * 2: DATA1
  94249. + * 3: MDATA (non-Control), SETUP (Control)
  94250. + */
  94251. + unsigned pid:2;
  94252. +#define DWC_HCTSIZ_DATA0 0
  94253. +#define DWC_HCTSIZ_DATA1 2
  94254. +#define DWC_HCTSIZ_DATA2 1
  94255. +#define DWC_HCTSIZ_MDATA 3
  94256. +#define DWC_HCTSIZ_SETUP 3
  94257. +
  94258. + /** Do PING protocol when 1 */
  94259. + unsigned dopng:1;
  94260. + } b;
  94261. +
  94262. + /** register bits */
  94263. + struct {
  94264. + /** Scheduling information */
  94265. + unsigned schinfo:8;
  94266. +
  94267. + /** Number of transfer descriptors.
  94268. + * Max value:
  94269. + * 64 in general,
  94270. + * 256 only for HS isochronous endpoint.
  94271. + */
  94272. + unsigned ntd:8;
  94273. +
  94274. + /** Data packets to transfer */
  94275. + unsigned reserved16_28:13;
  94276. +
  94277. + /**
  94278. + * Packet ID for next data packet
  94279. + * 0: DATA0
  94280. + * 1: DATA2
  94281. + * 2: DATA1
  94282. + * 3: MDATA (non-Control)
  94283. + */
  94284. + unsigned pid:2;
  94285. +
  94286. + /** Do PING protocol when 1 */
  94287. + unsigned dopng:1;
  94288. + } b_ddma;
  94289. +} hctsiz_data_t;
  94290. +
  94291. +/**
  94292. + * This union represents the bit fields in the Host DMA Address
  94293. + * Register used in Descriptor DMA mode.
  94294. + */
  94295. +typedef union hcdma_data {
  94296. + /** raw register data */
  94297. + uint32_t d32;
  94298. + /** register bits */
  94299. + struct {
  94300. + unsigned reserved0_2:3;
  94301. + /** Current Transfer Descriptor. Not used for ISOC */
  94302. + unsigned ctd:8;
  94303. + /** Start Address of Descriptor List */
  94304. + unsigned dma_addr:21;
  94305. + } b;
  94306. +} hcdma_data_t;
  94307. +
  94308. +/**
  94309. + * This union represents the bit fields in the DMA Descriptor
  94310. + * status quadlet for host mode. Read the quadlet into the <i>d32</i> member then
  94311. + * set/clear the bits using the <i>b</i>it elements.
  94312. + */
  94313. +typedef union host_dma_desc_sts {
  94314. + /** raw register data */
  94315. + uint32_t d32;
  94316. + /** quadlet bits */
  94317. +
  94318. + /* for non-isochronous */
  94319. + struct {
  94320. + /** Number of bytes */
  94321. + unsigned n_bytes:17;
  94322. + /** QTD offset to jump when Short Packet received - only for IN EPs */
  94323. + unsigned qtd_offset:6;
  94324. + /**
  94325. + * Set to request the core to jump to alternate QTD if
  94326. + * Short Packet received - only for IN EPs
  94327. + */
  94328. + unsigned a_qtd:1;
  94329. + /**
  94330. + * Setup Packet bit. When set indicates that buffer contains
  94331. + * setup packet.
  94332. + */
  94333. + unsigned sup:1;
  94334. + /** Interrupt On Complete */
  94335. + unsigned ioc:1;
  94336. + /** End of List */
  94337. + unsigned eol:1;
  94338. + unsigned reserved27:1;
  94339. + /** Rx/Tx Status */
  94340. + unsigned sts:2;
  94341. +#define DMA_DESC_STS_PKTERR 1
  94342. + unsigned reserved30:1;
  94343. + /** Active Bit */
  94344. + unsigned a:1;
  94345. + } b;
  94346. + /* for isochronous */
  94347. + struct {
  94348. + /** Number of bytes */
  94349. + unsigned n_bytes:12;
  94350. + unsigned reserved12_24:13;
  94351. + /** Interrupt On Complete */
  94352. + unsigned ioc:1;
  94353. + unsigned reserved26_27:2;
  94354. + /** Rx/Tx Status */
  94355. + unsigned sts:2;
  94356. + unsigned reserved30:1;
  94357. + /** Active Bit */
  94358. + unsigned a:1;
  94359. + } b_isoc;
  94360. +} host_dma_desc_sts_t;
  94361. +
  94362. +#define MAX_DMA_DESC_SIZE 131071
  94363. +#define MAX_DMA_DESC_NUM_GENERIC 64
  94364. +#define MAX_DMA_DESC_NUM_HS_ISOC 256
  94365. +#define MAX_FRLIST_EN_NUM 64
  94366. +/**
  94367. + * Host-mode DMA Descriptor structure
  94368. + *
  94369. + * DMA Descriptor structure contains two quadlets:
  94370. + * Status quadlet and Data buffer pointer.
  94371. + */
  94372. +typedef struct dwc_otg_host_dma_desc {
  94373. + /** DMA Descriptor status quadlet */
  94374. + host_dma_desc_sts_t status;
  94375. + /** DMA Descriptor data buffer pointer */
  94376. + uint32_t buf;
  94377. +} dwc_otg_host_dma_desc_t;
  94378. +
  94379. +/** OTG Host Interface Structure.
  94380. + *
  94381. + * The OTG Host Interface Structure structure contains information
  94382. + * needed to manage the DWC_otg controller acting in host mode. It
  94383. + * represents the programming view of the host-specific aspects of the
  94384. + * controller.
  94385. + */
  94386. +typedef struct dwc_otg_host_if {
  94387. + /** Host Global Registers starting at offset 400h.*/
  94388. + dwc_otg_host_global_regs_t *host_global_regs;
  94389. +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
  94390. +
  94391. + /** Host Port 0 Control and Status Register */
  94392. + volatile uint32_t *hprt0;
  94393. +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
  94394. +
  94395. + /** Host Channel Specific Registers at offsets 500h-5FCh. */
  94396. + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
  94397. +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
  94398. +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
  94399. +
  94400. + /* Host configuration information */
  94401. + /** Number of Host Channels (range: 1-16) */
  94402. + uint8_t num_host_channels;
  94403. + /** Periodic EPs supported (0: no, 1: yes) */
  94404. + uint8_t perio_eps_supported;
  94405. + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
  94406. + uint16_t perio_tx_fifo_size;
  94407. +
  94408. +} dwc_otg_host_if_t;
  94409. +
  94410. +/**
  94411. + * This union represents the bit fields in the Power and Clock Gating Control
  94412. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94413. + * bits using the <i>b</i>it elements.
  94414. + */
  94415. +typedef union pcgcctl_data {
  94416. + /** raw register data */
  94417. + uint32_t d32;
  94418. +
  94419. + /** register bits */
  94420. + struct {
  94421. + /** Stop Pclk */
  94422. + unsigned stoppclk:1;
  94423. + /** Gate Hclk */
  94424. + unsigned gatehclk:1;
  94425. + /** Power Clamp */
  94426. + unsigned pwrclmp:1;
  94427. + /** Reset Power Down Modules */
  94428. + unsigned rstpdwnmodule:1;
  94429. + /** Reserved */
  94430. + unsigned reserved:1;
  94431. + /** Enable Sleep Clock Gating (Enbl_L1Gating) */
  94432. + unsigned enbl_sleep_gating:1;
  94433. + /** PHY In Sleep (PhySleep) */
  94434. + unsigned phy_in_sleep:1;
  94435. + /** Deep Sleep*/
  94436. + unsigned deep_sleep:1;
  94437. + unsigned resetaftsusp:1;
  94438. + unsigned restoremode:1;
  94439. + unsigned enbl_extnd_hiber:1;
  94440. + unsigned extnd_hiber_pwrclmp:1;
  94441. + unsigned extnd_hiber_switch:1;
  94442. + unsigned ess_reg_restored:1;
  94443. + unsigned prt_clk_sel:2;
  94444. + unsigned port_power:1;
  94445. + unsigned max_xcvrselect:2;
  94446. + unsigned max_termsel:1;
  94447. + unsigned mac_dev_addr:7;
  94448. + unsigned p2hd_dev_enum_spd:2;
  94449. + unsigned p2hd_prt_spd:2;
  94450. + unsigned if_dev_mode:1;
  94451. + } b;
  94452. +} pcgcctl_data_t;
  94453. +
  94454. +/**
  94455. + * This union represents the bit fields in the Global Data FIFO Software
  94456. + * Configuration Register. Read the register into the <i>d32</i> member then
  94457. + * set/clear the bits using the <i>b</i>it elements.
  94458. + */
  94459. +typedef union gdfifocfg_data {
  94460. + /* raw register data */
  94461. + uint32_t d32;
  94462. + /** register bits */
  94463. + struct {
  94464. + /** OTG Data FIFO depth */
  94465. + unsigned gdfifocfg:16;
  94466. + /** Start address of EP info controller */
  94467. + unsigned epinfobase:16;
  94468. + } b;
  94469. +} gdfifocfg_data_t;
  94470. +
  94471. +/**
  94472. + * This union represents the bit fields in the Global Power Down Register
  94473. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94474. + * bits using the <i>b</i>it elements.
  94475. + */
  94476. +typedef union gpwrdn_data {
  94477. + /* raw register data */
  94478. + uint32_t d32;
  94479. +
  94480. + /** register bits */
  94481. + struct {
  94482. + /** PMU Interrupt Select */
  94483. + unsigned pmuintsel:1;
  94484. + /** PMU Active */
  94485. + unsigned pmuactv:1;
  94486. + /** Restore */
  94487. + unsigned restore:1;
  94488. + /** Power Down Clamp */
  94489. + unsigned pwrdnclmp:1;
  94490. + /** Power Down Reset */
  94491. + unsigned pwrdnrstn:1;
  94492. + /** Power Down Switch */
  94493. + unsigned pwrdnswtch:1;
  94494. + /** Disable VBUS */
  94495. + unsigned dis_vbus:1;
  94496. + /** Line State Change */
  94497. + unsigned lnstschng:1;
  94498. + /** Line state change mask */
  94499. + unsigned lnstchng_msk:1;
  94500. + /** Reset Detected */
  94501. + unsigned rst_det:1;
  94502. + /** Reset Detect mask */
  94503. + unsigned rst_det_msk:1;
  94504. + /** Disconnect Detected */
  94505. + unsigned disconn_det:1;
  94506. + /** Disconnect Detect mask */
  94507. + unsigned disconn_det_msk:1;
  94508. + /** Connect Detected*/
  94509. + unsigned connect_det:1;
  94510. + /** Connect Detected Mask*/
  94511. + unsigned connect_det_msk:1;
  94512. + /** SRP Detected */
  94513. + unsigned srp_det:1;
  94514. + /** SRP Detect mask */
  94515. + unsigned srp_det_msk:1;
  94516. + /** Status Change Interrupt */
  94517. + unsigned sts_chngint:1;
  94518. + /** Status Change Interrupt Mask */
  94519. + unsigned sts_chngint_msk:1;
  94520. + /** Line State */
  94521. + unsigned linestate:2;
  94522. + /** Indicates current mode(status of IDDIG signal) */
  94523. + unsigned idsts:1;
  94524. + /** B Session Valid signal status*/
  94525. + unsigned bsessvld:1;
  94526. + /** ADP Event Detected */
  94527. + unsigned adp_int:1;
  94528. + /** Multi Valued ID pin */
  94529. + unsigned mult_val_id_bc:5;
  94530. + /** Reserved 24_31 */
  94531. + unsigned reserved29_31:3;
  94532. + } b;
  94533. +} gpwrdn_data_t;
  94534. +
  94535. +#endif
  94536. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/Makefile linux-rpi/drivers/usb/host/dwc_otg/Makefile
  94537. --- linux-3.12.18/drivers/usb/host/dwc_otg/Makefile 1970-01-01 01:00:00.000000000 +0100
  94538. +++ linux-rpi/drivers/usb/host/dwc_otg/Makefile 2014-04-24 16:04:39.815124215 +0200
  94539. @@ -0,0 +1,82 @@
  94540. +#
  94541. +# Makefile for DWC_otg Highspeed USB controller driver
  94542. +#
  94543. +
  94544. +ifneq ($(KERNELRELEASE),)
  94545. +
  94546. +# Use the BUS_INTERFACE variable to compile the software for either
  94547. +# PCI(PCI_INTERFACE) or LM(LM_INTERFACE) bus.
  94548. +ifeq ($(BUS_INTERFACE),)
  94549. +# BUS_INTERFACE = -DPCI_INTERFACE
  94550. +# BUS_INTERFACE = -DLM_INTERFACE
  94551. + BUS_INTERFACE = -DPLATFORM_INTERFACE
  94552. +endif
  94553. +
  94554. +#ccflags-y += -DDEBUG
  94555. +#ccflags-y += -DDWC_OTG_DEBUGLEV=1 # reduce common debug msgs
  94556. +
  94557. +# Use one of the following flags to compile the software in host-only or
  94558. +# device-only mode.
  94559. +#ccflags-y += -DDWC_HOST_ONLY
  94560. +#ccflags-y += -DDWC_DEVICE_ONLY
  94561. +
  94562. +ccflags-y += -Dlinux -DDWC_HS_ELECT_TST
  94563. +#ccflags-y += -DDWC_EN_ISOC
  94564. +ccflags-y += -I$(obj)/../dwc_common_port
  94565. +#ccflags-y += -I$(PORTLIB)
  94566. +ccflags-y += -DDWC_LINUX
  94567. +ccflags-y += $(CFI)
  94568. +ccflags-y += $(BUS_INTERFACE)
  94569. +#ccflags-y += -DDWC_DEV_SRPCAP
  94570. +
  94571. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg.o
  94572. +
  94573. +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
  94574. +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
  94575. +dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  94576. +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
  94577. +dwc_otg-objs += dwc_otg_adp.o
  94578. +dwc_otg-objs += dwc_otg_fiq_fsm.o
  94579. +dwc_otg-objs += dwc_otg_fiq_stub.o
  94580. +ifneq ($(CFI),)
  94581. +dwc_otg-objs += dwc_otg_cfi.o
  94582. +endif
  94583. +
  94584. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  94585. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  94586. +
  94587. +ifneq ($(kernrel3),2.6.20)
  94588. +ccflags-y += $(CPPFLAGS)
  94589. +endif
  94590. +
  94591. +else
  94592. +
  94593. +PWD := $(shell pwd)
  94594. +PORTLIB := $(PWD)/../dwc_common_port
  94595. +
  94596. +# Command paths
  94597. +CTAGS := $(CTAGS)
  94598. +DOXYGEN := $(DOXYGEN)
  94599. +
  94600. +default: portlib
  94601. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  94602. +
  94603. +install: default
  94604. + $(MAKE) -C$(KDIR) M=$(PORTLIB) modules_install
  94605. + $(MAKE) -C$(KDIR) M=$(PWD) modules_install
  94606. +
  94607. +portlib:
  94608. + $(MAKE) -C$(KDIR) M=$(PORTLIB) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  94609. + cp $(PORTLIB)/Module.symvers $(PWD)/
  94610. +
  94611. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  94612. + $(DOXYGEN) doc/doxygen.cfg
  94613. +
  94614. +tags: $(wildcard *.[hc])
  94615. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  94616. +
  94617. +
  94618. +clean:
  94619. + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions Module.symvers
  94620. +
  94621. +endif
  94622. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm
  94623. --- linux-3.12.18/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 1970-01-01 01:00:00.000000000 +0100
  94624. +++ linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 2014-04-24 16:04:39.823124292 +0200
  94625. @@ -0,0 +1,337 @@
  94626. +package dwc_otg_test;
  94627. +
  94628. +use strict;
  94629. +use Exporter ();
  94630. +
  94631. +use vars qw(@ISA @EXPORT
  94632. +$sysfsdir $paramdir $errors $params
  94633. +);
  94634. +
  94635. +@ISA = qw(Exporter);
  94636. +
  94637. +#
  94638. +# Globals
  94639. +#
  94640. +$sysfsdir = "/sys/devices/lm0";
  94641. +$paramdir = "/sys/module/dwc_otg";
  94642. +$errors = 0;
  94643. +
  94644. +$params = [
  94645. + {
  94646. + NAME => "otg_cap",
  94647. + DEFAULT => 0,
  94648. + ENUM => [],
  94649. + LOW => 0,
  94650. + HIGH => 2
  94651. + },
  94652. + {
  94653. + NAME => "dma_enable",
  94654. + DEFAULT => 0,
  94655. + ENUM => [],
  94656. + LOW => 0,
  94657. + HIGH => 1
  94658. + },
  94659. + {
  94660. + NAME => "dma_burst_size",
  94661. + DEFAULT => 32,
  94662. + ENUM => [1, 4, 8, 16, 32, 64, 128, 256],
  94663. + LOW => 1,
  94664. + HIGH => 256
  94665. + },
  94666. + {
  94667. + NAME => "host_speed",
  94668. + DEFAULT => 0,
  94669. + ENUM => [],
  94670. + LOW => 0,
  94671. + HIGH => 1
  94672. + },
  94673. + {
  94674. + NAME => "host_support_fs_ls_low_power",
  94675. + DEFAULT => 0,
  94676. + ENUM => [],
  94677. + LOW => 0,
  94678. + HIGH => 1
  94679. + },
  94680. + {
  94681. + NAME => "host_ls_low_power_phy_clk",
  94682. + DEFAULT => 0,
  94683. + ENUM => [],
  94684. + LOW => 0,
  94685. + HIGH => 1
  94686. + },
  94687. + {
  94688. + NAME => "dev_speed",
  94689. + DEFAULT => 0,
  94690. + ENUM => [],
  94691. + LOW => 0,
  94692. + HIGH => 1
  94693. + },
  94694. + {
  94695. + NAME => "enable_dynamic_fifo",
  94696. + DEFAULT => 1,
  94697. + ENUM => [],
  94698. + LOW => 0,
  94699. + HIGH => 1
  94700. + },
  94701. + {
  94702. + NAME => "data_fifo_size",
  94703. + DEFAULT => 8192,
  94704. + ENUM => [],
  94705. + LOW => 32,
  94706. + HIGH => 32768
  94707. + },
  94708. + {
  94709. + NAME => "dev_rx_fifo_size",
  94710. + DEFAULT => 1064,
  94711. + ENUM => [],
  94712. + LOW => 16,
  94713. + HIGH => 32768
  94714. + },
  94715. + {
  94716. + NAME => "dev_nperio_tx_fifo_size",
  94717. + DEFAULT => 1024,
  94718. + ENUM => [],
  94719. + LOW => 16,
  94720. + HIGH => 32768
  94721. + },
  94722. + {
  94723. + NAME => "dev_perio_tx_fifo_size_1",
  94724. + DEFAULT => 256,
  94725. + ENUM => [],
  94726. + LOW => 4,
  94727. + HIGH => 768
  94728. + },
  94729. + {
  94730. + NAME => "dev_perio_tx_fifo_size_2",
  94731. + DEFAULT => 256,
  94732. + ENUM => [],
  94733. + LOW => 4,
  94734. + HIGH => 768
  94735. + },
  94736. + {
  94737. + NAME => "dev_perio_tx_fifo_size_3",
  94738. + DEFAULT => 256,
  94739. + ENUM => [],
  94740. + LOW => 4,
  94741. + HIGH => 768
  94742. + },
  94743. + {
  94744. + NAME => "dev_perio_tx_fifo_size_4",
  94745. + DEFAULT => 256,
  94746. + ENUM => [],
  94747. + LOW => 4,
  94748. + HIGH => 768
  94749. + },
  94750. + {
  94751. + NAME => "dev_perio_tx_fifo_size_5",
  94752. + DEFAULT => 256,
  94753. + ENUM => [],
  94754. + LOW => 4,
  94755. + HIGH => 768
  94756. + },
  94757. + {
  94758. + NAME => "dev_perio_tx_fifo_size_6",
  94759. + DEFAULT => 256,
  94760. + ENUM => [],
  94761. + LOW => 4,
  94762. + HIGH => 768
  94763. + },
  94764. + {
  94765. + NAME => "dev_perio_tx_fifo_size_7",
  94766. + DEFAULT => 256,
  94767. + ENUM => [],
  94768. + LOW => 4,
  94769. + HIGH => 768
  94770. + },
  94771. + {
  94772. + NAME => "dev_perio_tx_fifo_size_8",
  94773. + DEFAULT => 256,
  94774. + ENUM => [],
  94775. + LOW => 4,
  94776. + HIGH => 768
  94777. + },
  94778. + {
  94779. + NAME => "dev_perio_tx_fifo_size_9",
  94780. + DEFAULT => 256,
  94781. + ENUM => [],
  94782. + LOW => 4,
  94783. + HIGH => 768
  94784. + },
  94785. + {
  94786. + NAME => "dev_perio_tx_fifo_size_10",
  94787. + DEFAULT => 256,
  94788. + ENUM => [],
  94789. + LOW => 4,
  94790. + HIGH => 768
  94791. + },
  94792. + {
  94793. + NAME => "dev_perio_tx_fifo_size_11",
  94794. + DEFAULT => 256,
  94795. + ENUM => [],
  94796. + LOW => 4,
  94797. + HIGH => 768
  94798. + },
  94799. + {
  94800. + NAME => "dev_perio_tx_fifo_size_12",
  94801. + DEFAULT => 256,
  94802. + ENUM => [],
  94803. + LOW => 4,
  94804. + HIGH => 768
  94805. + },
  94806. + {
  94807. + NAME => "dev_perio_tx_fifo_size_13",
  94808. + DEFAULT => 256,
  94809. + ENUM => [],
  94810. + LOW => 4,
  94811. + HIGH => 768
  94812. + },
  94813. + {
  94814. + NAME => "dev_perio_tx_fifo_size_14",
  94815. + DEFAULT => 256,
  94816. + ENUM => [],
  94817. + LOW => 4,
  94818. + HIGH => 768
  94819. + },
  94820. + {
  94821. + NAME => "dev_perio_tx_fifo_size_15",
  94822. + DEFAULT => 256,
  94823. + ENUM => [],
  94824. + LOW => 4,
  94825. + HIGH => 768
  94826. + },
  94827. + {
  94828. + NAME => "host_rx_fifo_size",
  94829. + DEFAULT => 1024,
  94830. + ENUM => [],
  94831. + LOW => 16,
  94832. + HIGH => 32768
  94833. + },
  94834. + {
  94835. + NAME => "host_nperio_tx_fifo_size",
  94836. + DEFAULT => 1024,
  94837. + ENUM => [],
  94838. + LOW => 16,
  94839. + HIGH => 32768
  94840. + },
  94841. + {
  94842. + NAME => "host_perio_tx_fifo_size",
  94843. + DEFAULT => 1024,
  94844. + ENUM => [],
  94845. + LOW => 16,
  94846. + HIGH => 32768
  94847. + },
  94848. + {
  94849. + NAME => "max_transfer_size",
  94850. + DEFAULT => 65535,
  94851. + ENUM => [],
  94852. + LOW => 2047,
  94853. + HIGH => 65535
  94854. + },
  94855. + {
  94856. + NAME => "max_packet_count",
  94857. + DEFAULT => 511,
  94858. + ENUM => [],
  94859. + LOW => 15,
  94860. + HIGH => 511
  94861. + },
  94862. + {
  94863. + NAME => "host_channels",
  94864. + DEFAULT => 12,
  94865. + ENUM => [],
  94866. + LOW => 1,
  94867. + HIGH => 16
  94868. + },
  94869. + {
  94870. + NAME => "dev_endpoints",
  94871. + DEFAULT => 6,
  94872. + ENUM => [],
  94873. + LOW => 1,
  94874. + HIGH => 15
  94875. + },
  94876. + {
  94877. + NAME => "phy_type",
  94878. + DEFAULT => 1,
  94879. + ENUM => [],
  94880. + LOW => 0,
  94881. + HIGH => 2
  94882. + },
  94883. + {
  94884. + NAME => "phy_utmi_width",
  94885. + DEFAULT => 16,
  94886. + ENUM => [8, 16],
  94887. + LOW => 8,
  94888. + HIGH => 16
  94889. + },
  94890. + {
  94891. + NAME => "phy_ulpi_ddr",
  94892. + DEFAULT => 0,
  94893. + ENUM => [],
  94894. + LOW => 0,
  94895. + HIGH => 1
  94896. + },
  94897. + ];
  94898. +
  94899. +
  94900. +#
  94901. +#
  94902. +sub check_arch {
  94903. + $_ = `uname -m`;
  94904. + chomp;
  94905. + unless (m/armv4tl/) {
  94906. + warn "# \n# Can't execute on $_. Run on integrator platform.\n# \n";
  94907. + return 0;
  94908. + }
  94909. + return 1;
  94910. +}
  94911. +
  94912. +#
  94913. +#
  94914. +sub load_module {
  94915. + my $params = shift;
  94916. + print "\nRemoving Module\n";
  94917. + system "rmmod dwc_otg";
  94918. + print "Loading Module\n";
  94919. + if ($params ne "") {
  94920. + print "Module Parameters: $params\n";
  94921. + }
  94922. + if (system("modprobe dwc_otg $params")) {
  94923. + warn "Unable to load module\n";
  94924. + return 0;
  94925. + }
  94926. + return 1;
  94927. +}
  94928. +
  94929. +#
  94930. +#
  94931. +sub test_status {
  94932. + my $arg = shift;
  94933. +
  94934. + print "\n";
  94935. +
  94936. + if (defined $arg) {
  94937. + warn "WARNING: $arg\n";
  94938. + }
  94939. +
  94940. + if ($errors > 0) {
  94941. + warn "TEST FAILED with $errors errors\n";
  94942. + return 0;
  94943. + } else {
  94944. + print "TEST PASSED\n";
  94945. + return 0 if (defined $arg);
  94946. + }
  94947. + return 1;
  94948. +}
  94949. +
  94950. +#
  94951. +#
  94952. +@EXPORT = qw(
  94953. +$sysfsdir
  94954. +$paramdir
  94955. +$params
  94956. +$errors
  94957. +check_arch
  94958. +load_module
  94959. +test_status
  94960. +);
  94961. +
  94962. +1;
  94963. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/test/Makefile linux-rpi/drivers/usb/host/dwc_otg/test/Makefile
  94964. --- linux-3.12.18/drivers/usb/host/dwc_otg/test/Makefile 1970-01-01 01:00:00.000000000 +0100
  94965. +++ linux-rpi/drivers/usb/host/dwc_otg/test/Makefile 2014-04-24 15:35:04.177565820 +0200
  94966. @@ -0,0 +1,16 @@
  94967. +
  94968. +PERL=/usr/bin/perl
  94969. +PL_TESTS=test_sysfs.pl test_mod_param.pl
  94970. +
  94971. +.PHONY : test
  94972. +test : perl_tests
  94973. +
  94974. +perl_tests :
  94975. + @echo
  94976. + @echo Running perl tests
  94977. + @for test in $(PL_TESTS); do \
  94978. + if $(PERL) ./$$test ; then \
  94979. + echo "=======> $$test, PASSED" ; \
  94980. + else echo "=======> $$test, FAILED" ; \
  94981. + fi \
  94982. + done
  94983. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/test/test_mod_param.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl
  94984. --- linux-3.12.18/drivers/usb/host/dwc_otg/test/test_mod_param.pl 1970-01-01 01:00:00.000000000 +0100
  94985. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl 2014-04-24 16:04:39.823124292 +0200
  94986. @@ -0,0 +1,133 @@
  94987. +#!/usr/bin/perl -w
  94988. +#
  94989. +# Run this program on the integrator.
  94990. +#
  94991. +# - Tests module parameter default values.
  94992. +# - Tests setting of valid module parameter values via modprobe.
  94993. +# - Tests invalid module parameter values.
  94994. +# -----------------------------------------------------------------------------
  94995. +use strict;
  94996. +use dwc_otg_test;
  94997. +
  94998. +check_arch() or die;
  94999. +
  95000. +#
  95001. +#
  95002. +sub test {
  95003. + my ($param,$expected) = @_;
  95004. + my $value = get($param);
  95005. +
  95006. + if ($value == $expected) {
  95007. + print "$param = $value, okay\n";
  95008. + }
  95009. +
  95010. + else {
  95011. + warn "ERROR: value of $param != $expected, $value\n";
  95012. + $errors ++;
  95013. + }
  95014. +}
  95015. +
  95016. +#
  95017. +#
  95018. +sub get {
  95019. + my $param = shift;
  95020. + my $tmp = `cat $paramdir/$param`;
  95021. + chomp $tmp;
  95022. + return $tmp;
  95023. +}
  95024. +
  95025. +#
  95026. +#
  95027. +sub test_main {
  95028. +
  95029. + print "\nTesting Module Parameters\n";
  95030. +
  95031. + load_module("") or die;
  95032. +
  95033. + # Test initial values
  95034. + print "\nTesting Default Values\n";
  95035. + foreach (@{$params}) {
  95036. + test ($_->{NAME}, $_->{DEFAULT});
  95037. + }
  95038. +
  95039. + # Test low value
  95040. + print "\nTesting Low Value\n";
  95041. + my $cmd_params = "";
  95042. + foreach (@{$params}) {
  95043. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{LOW} ";
  95044. + }
  95045. + load_module($cmd_params) or die;
  95046. +
  95047. + foreach (@{$params}) {
  95048. + test ($_->{NAME}, $_->{LOW});
  95049. + }
  95050. +
  95051. + # Test high value
  95052. + print "\nTesting High Value\n";
  95053. + $cmd_params = "";
  95054. + foreach (@{$params}) {
  95055. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{HIGH} ";
  95056. + }
  95057. + load_module($cmd_params) or die;
  95058. +
  95059. + foreach (@{$params}) {
  95060. + test ($_->{NAME}, $_->{HIGH});
  95061. + }
  95062. +
  95063. + # Test Enum
  95064. + print "\nTesting Enumerated\n";
  95065. + foreach (@{$params}) {
  95066. + if (defined $_->{ENUM}) {
  95067. + my $value;
  95068. + foreach $value (@{$_->{ENUM}}) {
  95069. + $cmd_params = "$_->{NAME}=$value";
  95070. + load_module($cmd_params) or die;
  95071. + test ($_->{NAME}, $value);
  95072. + }
  95073. + }
  95074. + }
  95075. +
  95076. + # Test Invalid Values
  95077. + print "\nTesting Invalid Values\n";
  95078. + $cmd_params = "";
  95079. + foreach (@{$params}) {
  95080. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{LOW}-1;
  95081. + }
  95082. + load_module($cmd_params) or die;
  95083. +
  95084. + foreach (@{$params}) {
  95085. + test ($_->{NAME}, $_->{DEFAULT});
  95086. + }
  95087. +
  95088. + $cmd_params = "";
  95089. + foreach (@{$params}) {
  95090. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{HIGH}+1;
  95091. + }
  95092. + load_module($cmd_params) or die;
  95093. +
  95094. + foreach (@{$params}) {
  95095. + test ($_->{NAME}, $_->{DEFAULT});
  95096. + }
  95097. +
  95098. + print "\nTesting Enumerated\n";
  95099. + foreach (@{$params}) {
  95100. + if (defined $_->{ENUM}) {
  95101. + my $value;
  95102. + foreach $value (@{$_->{ENUM}}) {
  95103. + $value = $value + 1;
  95104. + $cmd_params = "$_->{NAME}=$value";
  95105. + load_module($cmd_params) or die;
  95106. + test ($_->{NAME}, $_->{DEFAULT});
  95107. + $value = $value - 2;
  95108. + $cmd_params = "$_->{NAME}=$value";
  95109. + load_module($cmd_params) or die;
  95110. + test ($_->{NAME}, $_->{DEFAULT});
  95111. + }
  95112. + }
  95113. + }
  95114. +
  95115. + test_status() or die;
  95116. +}
  95117. +
  95118. +test_main();
  95119. +0;
  95120. diff -Nur linux-3.12.18/drivers/usb/host/dwc_otg/test/test_sysfs.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl
  95121. --- linux-3.12.18/drivers/usb/host/dwc_otg/test/test_sysfs.pl 1970-01-01 01:00:00.000000000 +0100
  95122. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl 2014-04-24 16:04:39.823124292 +0200
  95123. @@ -0,0 +1,193 @@
  95124. +#!/usr/bin/perl -w
  95125. +#
  95126. +# Run this program on the integrator
  95127. +# - Tests select sysfs attributes.
  95128. +# - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
  95129. +# -----------------------------------------------------------------------------
  95130. +use strict;
  95131. +use dwc_otg_test;
  95132. +
  95133. +check_arch() or die;
  95134. +
  95135. +#
  95136. +#
  95137. +sub test {
  95138. + my ($attr,$expected) = @_;
  95139. + my $string = get($attr);
  95140. +
  95141. + if ($string eq $expected) {
  95142. + printf("$attr = $string, okay\n");
  95143. + }
  95144. + else {
  95145. + warn "ERROR: value of $attr != $expected, $string\n";
  95146. + $errors ++;
  95147. + }
  95148. +}
  95149. +
  95150. +#
  95151. +#
  95152. +sub set {
  95153. + my ($reg, $value) = @_;
  95154. + system "echo $value > $sysfsdir/$reg";
  95155. +}
  95156. +
  95157. +#
  95158. +#
  95159. +sub get {
  95160. + my $attr = shift;
  95161. + my $string = `cat $sysfsdir/$attr`;
  95162. + chomp $string;
  95163. + if ($string =~ m/\s\=\s/) {
  95164. + my $tmp;
  95165. + ($tmp, $string) = split /\s=\s/, $string;
  95166. + }
  95167. + return $string;
  95168. +}
  95169. +
  95170. +#
  95171. +#
  95172. +sub test_main {
  95173. + print("\nTesting Sysfs Attributes\n");
  95174. +
  95175. + load_module("") or die;
  95176. +
  95177. + # Test initial values of regoffset/regvalue/guid/gsnpsid
  95178. + print("\nTesting Default Values\n");
  95179. +
  95180. + test("regoffset", "0xffffffff");
  95181. + test("regvalue", "invalid offset");
  95182. + test("guid", "0x12345678"); # this will fail if it has been changed
  95183. + test("gsnpsid", "0x4f54200a");
  95184. +
  95185. + # Test operation of regoffset/regvalue
  95186. + print("\nTesting regoffset\n");
  95187. + set('regoffset', '5a5a5a5a');
  95188. + test("regoffset", "0xffffffff");
  95189. +
  95190. + set('regoffset', '0');
  95191. + test("regoffset", "0x00000000");
  95192. +
  95193. + set('regoffset', '40000');
  95194. + test("regoffset", "0x00000000");
  95195. +
  95196. + set('regoffset', '3ffff');
  95197. + test("regoffset", "0x0003ffff");
  95198. +
  95199. + set('regoffset', '1');
  95200. + test("regoffset", "0x00000001");
  95201. +
  95202. + print("\nTesting regvalue\n");
  95203. + set('regoffset', '3c');
  95204. + test("regvalue", "0x12345678");
  95205. + set('regvalue', '5a5a5a5a');
  95206. + test("regvalue", "0x5a5a5a5a");
  95207. + set('regvalue','a5a5a5a5');
  95208. + test("regvalue", "0xa5a5a5a5");
  95209. + set('guid','12345678');
  95210. +
  95211. + # Test HNP Capable
  95212. + print("\nTesting HNP Capable bit\n");
  95213. + set('hnpcapable', '1');
  95214. + test("hnpcapable", "0x1");
  95215. + set('hnpcapable','0');
  95216. + test("hnpcapable", "0x0");
  95217. +
  95218. + set('regoffset','0c');
  95219. +
  95220. + my $old = get('gusbcfg');
  95221. + print("setting hnpcapable\n");
  95222. + set('hnpcapable', '1');
  95223. + test("hnpcapable", "0x1");
  95224. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
  95225. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
  95226. +
  95227. + $old = get('gusbcfg');
  95228. + print("clearing hnpcapable\n");
  95229. + set('hnpcapable', '0');
  95230. + test("hnpcapable", "0x0");
  95231. + test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  95232. + test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  95233. +
  95234. + # Test SRP Capable
  95235. + print("\nTesting SRP Capable bit\n");
  95236. + set('srpcapable', '1');
  95237. + test("srpcapable", "0x1");
  95238. + set('srpcapable','0');
  95239. + test("srpcapable", "0x0");
  95240. +
  95241. + set('regoffset','0c');
  95242. +
  95243. + $old = get('gusbcfg');
  95244. + print("setting srpcapable\n");
  95245. + set('srpcapable', '1');
  95246. + test("srpcapable", "0x1");
  95247. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
  95248. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
  95249. +
  95250. + $old = get('gusbcfg');
  95251. + print("clearing srpcapable\n");
  95252. + set('srpcapable', '0');
  95253. + test("srpcapable", "0x0");
  95254. + test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  95255. + test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  95256. +
  95257. + # Test GGPIO
  95258. + print("\nTesting GGPIO\n");
  95259. + set('ggpio','5a5a5a5a');
  95260. + test('ggpio','0x5a5a0000');
  95261. + set('ggpio','a5a5a5a5');
  95262. + test('ggpio','0xa5a50000');
  95263. + set('ggpio','11110000');
  95264. + test('ggpio','0x11110000');
  95265. + set('ggpio','00001111');
  95266. + test('ggpio','0x00000000');
  95267. +
  95268. + # Test DEVSPEED
  95269. + print("\nTesting DEVSPEED\n");
  95270. + set('regoffset','800');
  95271. + $old = get('regvalue');
  95272. + set('devspeed','0');
  95273. + test('devspeed','0x0');
  95274. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  95275. + set('devspeed','1');
  95276. + test('devspeed','0x1');
  95277. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  95278. + set('devspeed','2');
  95279. + test('devspeed','0x2');
  95280. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
  95281. + set('devspeed','3');
  95282. + test('devspeed','0x3');
  95283. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
  95284. + set('devspeed','4');
  95285. + test('devspeed','0x0');
  95286. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  95287. + set('devspeed','5');
  95288. + test('devspeed','0x1');
  95289. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  95290. +
  95291. +
  95292. + # mode Returns the current mode:0 for device mode1 for host mode Read
  95293. + # hnp Initiate the Host Negotiation Protocol. Read returns the status. Read/Write
  95294. + # srp Initiate the Session Request Protocol. Read returns the status. Read/Write
  95295. + # buspower Get or Set the Power State of the bus (0 - Off or 1 - On) Read/Write
  95296. + # bussuspend Suspend the USB bus. Read/Write
  95297. + # busconnected Get the connection status of the bus Read
  95298. +
  95299. + # gotgctl Get or set the Core Control Status Register. Read/Write
  95300. + ## gusbcfg Get or set the Core USB Configuration Register Read/Write
  95301. + # grxfsiz Get or set the Receive FIFO Size Register Read/Write
  95302. + # gnptxfsiz Get or set the non-periodic Transmit Size Register Read/Write
  95303. + # gpvndctl Get or set the PHY Vendor Control Register Read/Write
  95304. + ## ggpio Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
  95305. + ## guid Get or set the value of the User ID Register Read/Write
  95306. + ## gsnpsid Get the value of the Synopsys ID Regester Read
  95307. + ## devspeed Get or set the device speed setting in the DCFG register Read/Write
  95308. + # enumspeed Gets the device enumeration Speed. Read
  95309. + # hptxfsiz Get the value of the Host Periodic Transmit FIFO Read
  95310. + # hprt0 Get or Set the value in the Host Port Control and Status Register Read/Write
  95311. +
  95312. + test_status("TEST NYI") or die;
  95313. +}
  95314. +
  95315. +test_main();
  95316. +0;
  95317. diff -Nur linux-3.12.18/drivers/usb/host/Kconfig linux-rpi/drivers/usb/host/Kconfig
  95318. --- linux-3.12.18/drivers/usb/host/Kconfig 2014-04-18 11:14:28.000000000 +0200
  95319. +++ linux-rpi/drivers/usb/host/Kconfig 2014-04-24 16:04:39.811124176 +0200
  95320. @@ -650,6 +650,19 @@
  95321. To compile this driver a module, choose M here: the module
  95322. will be called "hwa-hc".
  95323. +config USB_DWCOTG
  95324. + tristate "Synopsis DWC host support"
  95325. + depends on USB
  95326. + help
  95327. + The Synopsis DWC controller is a dual-role
  95328. + host/peripheral/OTG ("On The Go") USB controllers.
  95329. +
  95330. + Enable this option to support this IP in host controller mode.
  95331. + If unsure, say N.
  95332. +
  95333. + To compile this driver as a module, choose M here: the
  95334. + modules built will be called dwc_otg and dwc_common_port.
  95335. +
  95336. config USB_IMX21_HCD
  95337. tristate "i.MX21 HCD support"
  95338. depends on ARM && ARCH_MXC
  95339. diff -Nur linux-3.12.18/drivers/usb/host/Makefile linux-rpi/drivers/usb/host/Makefile
  95340. --- linux-3.12.18/drivers/usb/host/Makefile 2014-04-18 11:14:28.000000000 +0200
  95341. +++ linux-rpi/drivers/usb/host/Makefile 2014-04-24 16:04:39.811124176 +0200
  95342. @@ -56,6 +56,8 @@
  95343. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  95344. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  95345. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  95346. +
  95347. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg/ dwc_common_port/
  95348. obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
  95349. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
  95350. obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
  95351. diff -Nur linux-3.12.18/drivers/usb/Makefile linux-rpi/drivers/usb/Makefile
  95352. --- linux-3.12.18/drivers/usb/Makefile 2014-04-18 11:14:28.000000000 +0200
  95353. +++ linux-rpi/drivers/usb/Makefile 2014-04-24 16:04:39.695123055 +0200
  95354. @@ -23,6 +23,7 @@
  95355. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  95356. obj-$(CONFIG_USB_HWA_HCD) += host/
  95357. obj-$(CONFIG_USB_ISP1760_HCD) += host/
  95358. +obj-$(CONFIG_USB_DWCOTG) += host/
  95359. obj-$(CONFIG_USB_IMX21_HCD) += host/
  95360. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
  95361. obj-$(CONFIG_USB_FUSBH200_HCD) += host/
  95362. diff -Nur linux-3.12.18/drivers/vhost/net.c linux-rpi/drivers/vhost/net.c
  95363. --- linux-3.12.18/drivers/vhost/net.c 2014-04-18 11:14:28.000000000 +0200
  95364. +++ linux-rpi/drivers/vhost/net.c 2014-04-24 16:04:39.911125143 +0200
  95365. @@ -501,13 +501,9 @@
  95366. r = -ENOBUFS;
  95367. goto err;
  95368. }
  95369. - r = vhost_get_vq_desc(vq->dev, vq, vq->iov + seg,
  95370. + d = vhost_get_vq_desc(vq->dev, vq, vq->iov + seg,
  95371. ARRAY_SIZE(vq->iov) - seg, &out,
  95372. &in, log, log_num);
  95373. - if (unlikely(r < 0))
  95374. - goto err;
  95375. -
  95376. - d = r;
  95377. if (d == vq->num) {
  95378. r = 0;
  95379. goto err;
  95380. @@ -532,12 +528,6 @@
  95381. *iovcount = seg;
  95382. if (unlikely(log))
  95383. *log_num = nlogs;
  95384. -
  95385. - /* Detect overrun */
  95386. - if (unlikely(datalen > 0)) {
  95387. - r = UIO_MAXIOV + 1;
  95388. - goto err;
  95389. - }
  95390. return headcount;
  95391. err:
  95392. vhost_discard_vq_desc(vq, headcount);
  95393. @@ -593,14 +583,6 @@
  95394. /* On error, stop handling until the next kick. */
  95395. if (unlikely(headcount < 0))
  95396. break;
  95397. - /* On overrun, truncate and discard */
  95398. - if (unlikely(headcount > UIO_MAXIOV)) {
  95399. - msg.msg_iovlen = 1;
  95400. - err = sock->ops->recvmsg(NULL, sock, &msg,
  95401. - 1, MSG_DONTWAIT | MSG_TRUNC);
  95402. - pr_debug("Discarded rx packet: len %zd\n", sock_len);
  95403. - continue;
  95404. - }
  95405. /* OK, now we need to know about added descriptors. */
  95406. if (!headcount) {
  95407. if (unlikely(vhost_enable_notify(&net->dev, vq))) {
  95408. diff -Nur linux-3.12.18/drivers/video/bcm2708_fb.c linux-rpi/drivers/video/bcm2708_fb.c
  95409. --- linux-3.12.18/drivers/video/bcm2708_fb.c 1970-01-01 01:00:00.000000000 +0100
  95410. +++ linux-rpi/drivers/video/bcm2708_fb.c 2014-04-24 16:04:39.919125220 +0200
  95411. @@ -0,0 +1,762 @@
  95412. +/*
  95413. + * linux/drivers/video/bcm2708_fb.c
  95414. + *
  95415. + * Copyright (C) 2010 Broadcom
  95416. + *
  95417. + * This file is subject to the terms and conditions of the GNU General Public
  95418. + * License. See the file COPYING in the main directory of this archive
  95419. + * for more details.
  95420. + *
  95421. + * Broadcom simple framebuffer driver
  95422. + *
  95423. + * This file is derived from cirrusfb.c
  95424. + * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  95425. + *
  95426. + */
  95427. +#include <linux/module.h>
  95428. +#include <linux/kernel.h>
  95429. +#include <linux/errno.h>
  95430. +#include <linux/string.h>
  95431. +#include <linux/slab.h>
  95432. +#include <linux/mm.h>
  95433. +#include <linux/fb.h>
  95434. +#include <linux/init.h>
  95435. +#include <linux/interrupt.h>
  95436. +#include <linux/ioport.h>
  95437. +#include <linux/list.h>
  95438. +#include <linux/platform_device.h>
  95439. +#include <linux/clk.h>
  95440. +#include <linux/printk.h>
  95441. +#include <linux/console.h>
  95442. +#include <linux/debugfs.h>
  95443. +
  95444. +#include <mach/dma.h>
  95445. +#include <mach/platform.h>
  95446. +#include <mach/vcio.h>
  95447. +
  95448. +#include <asm/sizes.h>
  95449. +#include <linux/io.h>
  95450. +#include <linux/dma-mapping.h>
  95451. +
  95452. +#ifdef BCM2708_FB_DEBUG
  95453. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  95454. +#else
  95455. +#define print_debug(fmt,...)
  95456. +#endif
  95457. +
  95458. +/* This is limited to 16 characters when displayed by X startup */
  95459. +static const char *bcm2708_name = "BCM2708 FB";
  95460. +
  95461. +#define DRIVER_NAME "bcm2708_fb"
  95462. +
  95463. +static int fbwidth = 800; /* module parameter */
  95464. +static int fbheight = 480; /* module parameter */
  95465. +static int fbdepth = 16; /* module parameter */
  95466. +static int fbswap = 0; /* module parameter */
  95467. +
  95468. +static u32 dma_busy_wait_threshold = 1<<15;
  95469. +module_param(dma_busy_wait_threshold, int, 0644);
  95470. +MODULE_PARM_DESC(dma_busy_wait_threshold, "Busy-wait for DMA completion below this area");
  95471. +
  95472. +/* this data structure describes each frame buffer device we find */
  95473. +
  95474. +struct fbinfo_s {
  95475. + u32 xres, yres, xres_virtual, yres_virtual;
  95476. + u32 pitch, bpp;
  95477. + u32 xoffset, yoffset;
  95478. + u32 base;
  95479. + u32 screen_size;
  95480. + u16 cmap[256];
  95481. +};
  95482. +
  95483. +struct bcm2708_fb_stats {
  95484. + struct debugfs_regset32 regset;
  95485. + u32 dma_copies;
  95486. + u32 dma_irqs;
  95487. +};
  95488. +
  95489. +struct bcm2708_fb {
  95490. + struct fb_info fb;
  95491. + struct platform_device *dev;
  95492. + struct fbinfo_s *info;
  95493. + dma_addr_t dma;
  95494. + u32 cmap[16];
  95495. + int dma_chan;
  95496. + int dma_irq;
  95497. + void __iomem *dma_chan_base;
  95498. + void *cb_base; /* DMA control blocks */
  95499. + dma_addr_t cb_handle;
  95500. + struct dentry *debugfs_dir;
  95501. + wait_queue_head_t dma_waitq;
  95502. + struct bcm2708_fb_stats stats;
  95503. +};
  95504. +
  95505. +#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
  95506. +
  95507. +static void bcm2708_fb_debugfs_deinit(struct bcm2708_fb *fb)
  95508. +{
  95509. + debugfs_remove_recursive(fb->debugfs_dir);
  95510. + fb->debugfs_dir = NULL;
  95511. +}
  95512. +
  95513. +static int bcm2708_fb_debugfs_init(struct bcm2708_fb *fb)
  95514. +{
  95515. + static struct debugfs_reg32 stats_registers[] = {
  95516. + {
  95517. + "dma_copies",
  95518. + offsetof(struct bcm2708_fb_stats, dma_copies)
  95519. + },
  95520. + {
  95521. + "dma_irqs",
  95522. + offsetof(struct bcm2708_fb_stats, dma_irqs)
  95523. + },
  95524. + };
  95525. +
  95526. + fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
  95527. + if (!fb->debugfs_dir) {
  95528. + pr_warn("%s: could not create debugfs entry\n",
  95529. + __func__);
  95530. + return -EFAULT;
  95531. + }
  95532. +
  95533. + fb->stats.regset.regs = stats_registers;
  95534. + fb->stats.regset.nregs = ARRAY_SIZE(stats_registers);
  95535. + fb->stats.regset.base = &fb->stats;
  95536. +
  95537. + if (!debugfs_create_regset32(
  95538. + "stats", 0444, fb->debugfs_dir, &fb->stats.regset)) {
  95539. + pr_warn("%s: could not create statistics registers\n",
  95540. + __func__);
  95541. + goto fail;
  95542. + }
  95543. + return 0;
  95544. +
  95545. +fail:
  95546. + bcm2708_fb_debugfs_deinit(fb);
  95547. + return -EFAULT;
  95548. +}
  95549. +
  95550. +static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
  95551. +{
  95552. + int ret = 0;
  95553. +
  95554. + memset(&var->transp, 0, sizeof(var->transp));
  95555. +
  95556. + var->red.msb_right = 0;
  95557. + var->green.msb_right = 0;
  95558. + var->blue.msb_right = 0;
  95559. +
  95560. + switch (var->bits_per_pixel) {
  95561. + case 1:
  95562. + case 2:
  95563. + case 4:
  95564. + case 8:
  95565. + var->red.length = var->bits_per_pixel;
  95566. + var->red.offset = 0;
  95567. + var->green.length = var->bits_per_pixel;
  95568. + var->green.offset = 0;
  95569. + var->blue.length = var->bits_per_pixel;
  95570. + var->blue.offset = 0;
  95571. + break;
  95572. + case 16:
  95573. + var->red.length = 5;
  95574. + var->blue.length = 5;
  95575. + /*
  95576. + * Green length can be 5 or 6 depending whether
  95577. + * we're operating in RGB555 or RGB565 mode.
  95578. + */
  95579. + if (var->green.length != 5 && var->green.length != 6)
  95580. + var->green.length = 6;
  95581. + break;
  95582. + case 24:
  95583. + var->red.length = 8;
  95584. + var->blue.length = 8;
  95585. + var->green.length = 8;
  95586. + break;
  95587. + case 32:
  95588. + var->red.length = 8;
  95589. + var->green.length = 8;
  95590. + var->blue.length = 8;
  95591. + var->transp.length = 8;
  95592. + break;
  95593. + default:
  95594. + ret = -EINVAL;
  95595. + break;
  95596. + }
  95597. +
  95598. + /*
  95599. + * >= 16bpp displays have separate colour component bitfields
  95600. + * encoded in the pixel data. Calculate their position from
  95601. + * the bitfield length defined above.
  95602. + */
  95603. + if (ret == 0 && var->bits_per_pixel >= 24 && fbswap) {
  95604. + var->blue.offset = 0;
  95605. + var->green.offset = var->blue.offset + var->blue.length;
  95606. + var->red.offset = var->green.offset + var->green.length;
  95607. + var->transp.offset = var->red.offset + var->red.length;
  95608. + } else if (ret == 0 && var->bits_per_pixel >= 24) {
  95609. + var->red.offset = 0;
  95610. + var->green.offset = var->red.offset + var->red.length;
  95611. + var->blue.offset = var->green.offset + var->green.length;
  95612. + var->transp.offset = var->blue.offset + var->blue.length;
  95613. + } else if (ret == 0 && var->bits_per_pixel >= 16) {
  95614. + var->blue.offset = 0;
  95615. + var->green.offset = var->blue.offset + var->blue.length;
  95616. + var->red.offset = var->green.offset + var->green.length;
  95617. + var->transp.offset = var->red.offset + var->red.length;
  95618. + }
  95619. +
  95620. + return ret;
  95621. +}
  95622. +
  95623. +static int bcm2708_fb_check_var(struct fb_var_screeninfo *var,
  95624. + struct fb_info *info)
  95625. +{
  95626. + /* info input, var output */
  95627. + int yres;
  95628. +
  95629. + /* info input, var output */
  95630. + print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
  95631. + info->var.xres, info->var.yres, info->var.xres_virtual,
  95632. + info->var.yres_virtual, (int)info->screen_size,
  95633. + info->var.bits_per_pixel);
  95634. + print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
  95635. + var->xres, var->yres, var->xres_virtual, var->yres_virtual,
  95636. + var->bits_per_pixel);
  95637. +
  95638. + if (!var->bits_per_pixel)
  95639. + var->bits_per_pixel = 16;
  95640. +
  95641. + if (bcm2708_fb_set_bitfields(var) != 0) {
  95642. + pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
  95643. + var->bits_per_pixel);
  95644. + return -EINVAL;
  95645. + }
  95646. +
  95647. +
  95648. + if (var->xres_virtual < var->xres)
  95649. + var->xres_virtual = var->xres;
  95650. + /* use highest possible virtual resolution */
  95651. + if (var->yres_virtual == -1) {
  95652. + var->yres_virtual = 480;
  95653. +
  95654. + pr_err
  95655. + ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
  95656. + var->xres_virtual, var->yres_virtual);
  95657. + }
  95658. + if (var->yres_virtual < var->yres)
  95659. + var->yres_virtual = var->yres;
  95660. +
  95661. + if (var->xoffset < 0)
  95662. + var->xoffset = 0;
  95663. + if (var->yoffset < 0)
  95664. + var->yoffset = 0;
  95665. +
  95666. + /* truncate xoffset and yoffset to maximum if too high */
  95667. + if (var->xoffset > var->xres_virtual - var->xres)
  95668. + var->xoffset = var->xres_virtual - var->xres - 1;
  95669. + if (var->yoffset > var->yres_virtual - var->yres)
  95670. + var->yoffset = var->yres_virtual - var->yres - 1;
  95671. +
  95672. + yres = var->yres;
  95673. + if (var->vmode & FB_VMODE_DOUBLE)
  95674. + yres *= 2;
  95675. + else if (var->vmode & FB_VMODE_INTERLACED)
  95676. + yres = (yres + 1) / 2;
  95677. +
  95678. + if (var->xres * yres > 1920 * 1200) {
  95679. + pr_err("bcm2708_fb_check_var: ERROR: Pixel size >= 1920x1200; "
  95680. + "special treatment required! (TODO)\n");
  95681. + return -EINVAL;
  95682. + }
  95683. +
  95684. + return 0;
  95685. +}
  95686. +
  95687. +static int bcm2708_fb_set_par(struct fb_info *info)
  95688. +{
  95689. + uint32_t val = 0;
  95690. + struct bcm2708_fb *fb = to_bcm2708(info);
  95691. + volatile struct fbinfo_s *fbinfo = fb->info;
  95692. + fbinfo->xres = info->var.xres;
  95693. + fbinfo->yres = info->var.yres;
  95694. + fbinfo->xres_virtual = info->var.xres_virtual;
  95695. + fbinfo->yres_virtual = info->var.yres_virtual;
  95696. + fbinfo->bpp = info->var.bits_per_pixel;
  95697. + fbinfo->xoffset = info->var.xoffset;
  95698. + fbinfo->yoffset = info->var.yoffset;
  95699. + fbinfo->base = 0; /* filled in by VC */
  95700. + fbinfo->pitch = 0; /* filled in by VC */
  95701. +
  95702. + print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
  95703. + info->var.xres, info->var.yres, info->var.xres_virtual,
  95704. + info->var.yres_virtual, (int)info->screen_size,
  95705. + info->var.bits_per_pixel);
  95706. +
  95707. + /* ensure last write to fbinfo is visible to GPU */
  95708. + wmb();
  95709. +
  95710. + /* inform vc about new framebuffer */
  95711. + bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
  95712. +
  95713. + /* TODO: replace fb driver with vchiq version */
  95714. + /* wait for response */
  95715. + bcm_mailbox_read(MBOX_CHAN_FB, &val);
  95716. +
  95717. + /* ensure GPU writes are visible to us */
  95718. + rmb();
  95719. +
  95720. + if (val == 0) {
  95721. + fb->fb.fix.line_length = fbinfo->pitch;
  95722. +
  95723. + if (info->var.bits_per_pixel <= 8)
  95724. + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  95725. + else
  95726. + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  95727. +
  95728. + fb->fb.fix.smem_start = fbinfo->base;
  95729. + fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
  95730. + fb->fb.screen_size = fbinfo->screen_size;
  95731. + if (fb->fb.screen_base)
  95732. + iounmap(fb->fb.screen_base);
  95733. + fb->fb.screen_base =
  95734. + (void *)ioremap_wc(fb->fb.fix.smem_start, fb->fb.screen_size);
  95735. + if (!fb->fb.screen_base) {
  95736. + /* the console may currently be locked */
  95737. + console_trylock();
  95738. + console_unlock();
  95739. +
  95740. + BUG(); /* what can we do here */
  95741. + }
  95742. + }
  95743. + print_debug
  95744. + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
  95745. + (void *)fb->fb.screen_base, (void *)fb->fb.fix.smem_start,
  95746. + fbinfo->xres, fbinfo->yres, fbinfo->bpp,
  95747. + fbinfo->pitch, (int)fb->fb.screen_size, val);
  95748. +
  95749. + return val;
  95750. +}
  95751. +
  95752. +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
  95753. +{
  95754. + unsigned int mask = (1 << bf->length) - 1;
  95755. +
  95756. + return (val >> (16 - bf->length) & mask) << bf->offset;
  95757. +}
  95758. +
  95759. +
  95760. +static int bcm2708_fb_setcolreg(unsigned int regno, unsigned int red,
  95761. + unsigned int green, unsigned int blue,
  95762. + unsigned int transp, struct fb_info *info)
  95763. +{
  95764. + struct bcm2708_fb *fb = to_bcm2708(info);
  95765. +
  95766. + /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
  95767. + if (fb->fb.var.bits_per_pixel <= 8) {
  95768. + if (regno < 256) {
  95769. + /* blue [0:4], green [5:10], red [11:15] */
  95770. + fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
  95771. + ((green >> (16-6)) & 0x3f) << 5 |
  95772. + ((blue >> (16-5)) & 0x1f) << 0;
  95773. + }
  95774. + /* 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 */
  95775. + /* So just call it for what looks like the last colour in a list for now. */
  95776. + if (regno == 15 || regno == 255)
  95777. + bcm2708_fb_set_par(info);
  95778. + } else if (regno < 16) {
  95779. + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
  95780. + convert_bitfield(blue, &fb->fb.var.blue) |
  95781. + convert_bitfield(green, &fb->fb.var.green) |
  95782. + convert_bitfield(red, &fb->fb.var.red);
  95783. + }
  95784. + return regno > 255;
  95785. +}
  95786. +
  95787. +static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
  95788. +{
  95789. + /*print_debug("bcm2708_fb_blank\n"); */
  95790. + return -1;
  95791. +}
  95792. +
  95793. +static void bcm2708_fb_fillrect(struct fb_info *info,
  95794. + const struct fb_fillrect *rect)
  95795. +{
  95796. + /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
  95797. + cfb_fillrect(info, rect);
  95798. +}
  95799. +
  95800. +/* A helper function for configuring dma control block */
  95801. +static void set_dma_cb(struct bcm2708_dma_cb *cb,
  95802. + int burst_size,
  95803. + dma_addr_t dst,
  95804. + int dst_stride,
  95805. + dma_addr_t src,
  95806. + int src_stride,
  95807. + int w,
  95808. + int h)
  95809. +{
  95810. + cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
  95811. + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
  95812. + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
  95813. + cb->dst = dst;
  95814. + cb->src = src;
  95815. + /*
  95816. + * This is not really obvious from the DMA documentation,
  95817. + * but the top 16 bits must be programmmed to "height -1"
  95818. + * and not "height" in 2D mode.
  95819. + */
  95820. + cb->length = ((h - 1) << 16) | w;
  95821. + cb->stride = ((dst_stride - w) << 16) | (u16)(src_stride - w);
  95822. + cb->pad[0] = 0;
  95823. + cb->pad[1] = 0;
  95824. +}
  95825. +
  95826. +static void bcm2708_fb_copyarea(struct fb_info *info,
  95827. + const struct fb_copyarea *region)
  95828. +{
  95829. + struct bcm2708_fb *fb = to_bcm2708(info);
  95830. + struct bcm2708_dma_cb *cb = fb->cb_base;
  95831. + int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
  95832. + /* Channel 0 supports larger bursts and is a bit faster */
  95833. + int burst_size = (fb->dma_chan == 0) ? 8 : 2;
  95834. + int pixels = region->width * region->height;
  95835. +
  95836. + /* Fallback to cfb_copyarea() if we don't like something */
  95837. + if (bytes_per_pixel > 4 ||
  95838. + info->var.xres * info->var.yres > 1920 * 1200 ||
  95839. + region->width <= 0 || region->width > info->var.xres ||
  95840. + region->height <= 0 || region->height > info->var.yres ||
  95841. + region->sx < 0 || region->sx >= info->var.xres ||
  95842. + region->sy < 0 || region->sy >= info->var.yres ||
  95843. + region->dx < 0 || region->dx >= info->var.xres ||
  95844. + region->dy < 0 || region->dy >= info->var.yres ||
  95845. + region->sx + region->width > info->var.xres ||
  95846. + region->dx + region->width > info->var.xres ||
  95847. + region->sy + region->height > info->var.yres ||
  95848. + region->dy + region->height > info->var.yres) {
  95849. + cfb_copyarea(info, region);
  95850. + return;
  95851. + }
  95852. +
  95853. + if (region->dy == region->sy && region->dx > region->sx) {
  95854. + /*
  95855. + * A difficult case of overlapped copy. Because DMA can't
  95856. + * copy individual scanlines in backwards direction, we need
  95857. + * two-pass processing. We do it by programming a chain of dma
  95858. + * control blocks in the first 16K part of the buffer and use
  95859. + * the remaining 48K as the intermediate temporary scratch
  95860. + * buffer. The buffer size is sufficient to handle up to
  95861. + * 1920x1200 resolution at 32bpp pixel depth.
  95862. + */
  95863. + int y;
  95864. + dma_addr_t control_block_pa = fb->cb_handle;
  95865. + dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
  95866. + int scanline_size = bytes_per_pixel * region->width;
  95867. + int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
  95868. +
  95869. + for (y = 0; y < region->height; y += scanlines_per_cb) {
  95870. + dma_addr_t src =
  95871. + fb->fb.fix.smem_start +
  95872. + bytes_per_pixel * region->sx +
  95873. + (region->sy + y) * fb->fb.fix.line_length;
  95874. + dma_addr_t dst =
  95875. + fb->fb.fix.smem_start +
  95876. + bytes_per_pixel * region->dx +
  95877. + (region->dy + y) * fb->fb.fix.line_length;
  95878. +
  95879. + if (region->height - y < scanlines_per_cb)
  95880. + scanlines_per_cb = region->height - y;
  95881. +
  95882. + set_dma_cb(cb, burst_size, scratchbuf, scanline_size,
  95883. + src, fb->fb.fix.line_length,
  95884. + scanline_size, scanlines_per_cb);
  95885. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  95886. + cb->next = control_block_pa;
  95887. + cb++;
  95888. +
  95889. + set_dma_cb(cb, burst_size, dst, fb->fb.fix.line_length,
  95890. + scratchbuf, scanline_size,
  95891. + scanline_size, scanlines_per_cb);
  95892. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  95893. + cb->next = control_block_pa;
  95894. + cb++;
  95895. + }
  95896. + /* move the pointer back to the last dma control block */
  95897. + cb--;
  95898. + } else {
  95899. + /* A single dma control block is enough. */
  95900. + int sy, dy, stride;
  95901. + if (region->dy <= region->sy) {
  95902. + /* processing from top to bottom */
  95903. + dy = region->dy;
  95904. + sy = region->sy;
  95905. + stride = fb->fb.fix.line_length;
  95906. + } else {
  95907. + /* processing from bottom to top */
  95908. + dy = region->dy + region->height - 1;
  95909. + sy = region->sy + region->height - 1;
  95910. + stride = -fb->fb.fix.line_length;
  95911. + }
  95912. + set_dma_cb(cb, burst_size,
  95913. + fb->fb.fix.smem_start + dy * fb->fb.fix.line_length +
  95914. + bytes_per_pixel * region->dx,
  95915. + stride,
  95916. + fb->fb.fix.smem_start + sy * fb->fb.fix.line_length +
  95917. + bytes_per_pixel * region->sx,
  95918. + stride,
  95919. + region->width * bytes_per_pixel,
  95920. + region->height);
  95921. + }
  95922. +
  95923. + /* end of dma control blocks chain */
  95924. + cb->next = 0;
  95925. +
  95926. +
  95927. + if (pixels < dma_busy_wait_threshold) {
  95928. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  95929. + bcm_dma_wait_idle(fb->dma_chan_base);
  95930. + } else {
  95931. + void __iomem *dma_chan = fb->dma_chan_base;
  95932. + cb->info |= BCM2708_DMA_INT_EN;
  95933. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  95934. + while (bcm_dma_is_busy(dma_chan)) {
  95935. + wait_event_interruptible(
  95936. + fb->dma_waitq,
  95937. + !bcm_dma_is_busy(dma_chan));
  95938. + }
  95939. + fb->stats.dma_irqs++;
  95940. + }
  95941. + fb->stats.dma_copies++;
  95942. +}
  95943. +
  95944. +static void bcm2708_fb_imageblit(struct fb_info *info,
  95945. + const struct fb_image *image)
  95946. +{
  95947. + /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
  95948. + cfb_imageblit(info, image);
  95949. +}
  95950. +
  95951. +static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
  95952. +{
  95953. + struct bcm2708_fb *fb = cxt;
  95954. +
  95955. + /* FIXME: should read status register to check if this is
  95956. + * actually interrupting us or not, in case this interrupt
  95957. + * ever becomes shared amongst several DMA channels
  95958. + *
  95959. + * readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_IRQ;
  95960. + */
  95961. +
  95962. + /* acknowledge the interrupt */
  95963. + writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
  95964. +
  95965. + wake_up(&fb->dma_waitq);
  95966. + return IRQ_HANDLED;
  95967. +}
  95968. +
  95969. +static struct fb_ops bcm2708_fb_ops = {
  95970. + .owner = THIS_MODULE,
  95971. + .fb_check_var = bcm2708_fb_check_var,
  95972. + .fb_set_par = bcm2708_fb_set_par,
  95973. + .fb_setcolreg = bcm2708_fb_setcolreg,
  95974. + .fb_blank = bcm2708_fb_blank,
  95975. + .fb_fillrect = bcm2708_fb_fillrect,
  95976. + .fb_copyarea = bcm2708_fb_copyarea,
  95977. + .fb_imageblit = bcm2708_fb_imageblit,
  95978. +};
  95979. +
  95980. +static int bcm2708_fb_register(struct bcm2708_fb *fb)
  95981. +{
  95982. + int ret;
  95983. + dma_addr_t dma;
  95984. + void *mem;
  95985. +
  95986. + mem =
  95987. + dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), &dma,
  95988. + GFP_KERNEL);
  95989. +
  95990. + if (NULL == mem) {
  95991. + pr_err(": unable to allocate fbinfo buffer\n");
  95992. + ret = -ENOMEM;
  95993. + } else {
  95994. + fb->info = (struct fbinfo_s *)mem;
  95995. + fb->dma = dma;
  95996. + }
  95997. + fb->fb.fbops = &bcm2708_fb_ops;
  95998. + fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
  95999. + fb->fb.pseudo_palette = fb->cmap;
  96000. +
  96001. + strncpy(fb->fb.fix.id, bcm2708_name, sizeof(fb->fb.fix.id));
  96002. + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  96003. + fb->fb.fix.type_aux = 0;
  96004. + fb->fb.fix.xpanstep = 0;
  96005. + fb->fb.fix.ypanstep = 0;
  96006. + fb->fb.fix.ywrapstep = 0;
  96007. + fb->fb.fix.accel = FB_ACCEL_NONE;
  96008. +
  96009. + fb->fb.var.xres = fbwidth;
  96010. + fb->fb.var.yres = fbheight;
  96011. + fb->fb.var.xres_virtual = fbwidth;
  96012. + fb->fb.var.yres_virtual = fbheight;
  96013. + fb->fb.var.bits_per_pixel = fbdepth;
  96014. + fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
  96015. + fb->fb.var.activate = FB_ACTIVATE_NOW;
  96016. + fb->fb.var.nonstd = 0;
  96017. + fb->fb.var.height = -1; /* height of picture in mm */
  96018. + fb->fb.var.width = -1; /* width of picture in mm */
  96019. + fb->fb.var.accel_flags = 0;
  96020. +
  96021. + fb->fb.monspecs.hfmin = 0;
  96022. + fb->fb.monspecs.hfmax = 100000;
  96023. + fb->fb.monspecs.vfmin = 0;
  96024. + fb->fb.monspecs.vfmax = 400;
  96025. + fb->fb.monspecs.dclkmin = 1000000;
  96026. + fb->fb.monspecs.dclkmax = 100000000;
  96027. +
  96028. + bcm2708_fb_set_bitfields(&fb->fb.var);
  96029. + init_waitqueue_head(&fb->dma_waitq);
  96030. +
  96031. + /*
  96032. + * Allocate colourmap.
  96033. + */
  96034. +
  96035. + fb_set_var(&fb->fb, &fb->fb.var);
  96036. +
  96037. + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n", fbwidth
  96038. + fbheight, fbdepth, fbswap);
  96039. +
  96040. + ret = register_framebuffer(&fb->fb);
  96041. + print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
  96042. + if (ret == 0)
  96043. + goto out;
  96044. +
  96045. + print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
  96046. +out:
  96047. + return ret;
  96048. +}
  96049. +
  96050. +static int bcm2708_fb_probe(struct platform_device *dev)
  96051. +{
  96052. + struct bcm2708_fb *fb;
  96053. + int ret;
  96054. +
  96055. + fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
  96056. + if (!fb) {
  96057. + dev_err(&dev->dev,
  96058. + "could not allocate new bcm2708_fb struct\n");
  96059. + ret = -ENOMEM;
  96060. + goto free_region;
  96061. + }
  96062. +
  96063. + bcm2708_fb_debugfs_init(fb);
  96064. +
  96065. + fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
  96066. + &fb->cb_handle, GFP_KERNEL);
  96067. + if (!fb->cb_base) {
  96068. + dev_err(&dev->dev, "cannot allocate DMA CBs\n");
  96069. + ret = -ENOMEM;
  96070. + goto free_fb;
  96071. + }
  96072. +
  96073. + pr_info("BCM2708FB: allocated DMA memory %08x\n",
  96074. + fb->cb_handle);
  96075. +
  96076. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
  96077. + &fb->dma_chan_base, &fb->dma_irq);
  96078. + if (ret < 0) {
  96079. + dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
  96080. + goto free_cb;
  96081. + }
  96082. + fb->dma_chan = ret;
  96083. +
  96084. + ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
  96085. + 0, "bcm2708_fb dma", fb);
  96086. + if (ret) {
  96087. + pr_err("%s: failed to request DMA irq\n", __func__);
  96088. + goto free_dma_chan;
  96089. + }
  96090. +
  96091. +
  96092. + pr_info("BCM2708FB: allocated DMA channel %d @ %p\n",
  96093. + fb->dma_chan, fb->dma_chan_base);
  96094. +
  96095. + fb->dev = dev;
  96096. +
  96097. + ret = bcm2708_fb_register(fb);
  96098. + if (ret == 0) {
  96099. + platform_set_drvdata(dev, fb);
  96100. + goto out;
  96101. + }
  96102. +
  96103. +free_dma_chan:
  96104. + bcm_dma_chan_free(fb->dma_chan);
  96105. +free_cb:
  96106. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  96107. +free_fb:
  96108. + kfree(fb);
  96109. +free_region:
  96110. + dev_err(&dev->dev, "probe failed, err %d\n", ret);
  96111. +out:
  96112. + return ret;
  96113. +}
  96114. +
  96115. +static int bcm2708_fb_remove(struct platform_device *dev)
  96116. +{
  96117. + struct bcm2708_fb *fb = platform_get_drvdata(dev);
  96118. +
  96119. + platform_set_drvdata(dev, NULL);
  96120. +
  96121. + if (fb->fb.screen_base)
  96122. + iounmap(fb->fb.screen_base);
  96123. + unregister_framebuffer(&fb->fb);
  96124. +
  96125. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  96126. + bcm_dma_chan_free(fb->dma_chan);
  96127. +
  96128. + dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
  96129. + fb->dma);
  96130. + bcm2708_fb_debugfs_deinit(fb);
  96131. +
  96132. + free_irq(fb->dma_irq, fb);
  96133. +
  96134. + kfree(fb);
  96135. +
  96136. + return 0;
  96137. +}
  96138. +
  96139. +static struct platform_driver bcm2708_fb_driver = {
  96140. + .probe = bcm2708_fb_probe,
  96141. + .remove = bcm2708_fb_remove,
  96142. + .driver = {
  96143. + .name = DRIVER_NAME,
  96144. + .owner = THIS_MODULE,
  96145. + },
  96146. +};
  96147. +
  96148. +static int __init bcm2708_fb_init(void)
  96149. +{
  96150. + return platform_driver_register(&bcm2708_fb_driver);
  96151. +}
  96152. +
  96153. +module_init(bcm2708_fb_init);
  96154. +
  96155. +static void __exit bcm2708_fb_exit(void)
  96156. +{
  96157. + platform_driver_unregister(&bcm2708_fb_driver);
  96158. +}
  96159. +
  96160. +module_exit(bcm2708_fb_exit);
  96161. +
  96162. +module_param(fbwidth, int, 0644);
  96163. +module_param(fbheight, int, 0644);
  96164. +module_param(fbdepth, int, 0644);
  96165. +module_param(fbswap, int, 0644);
  96166. +
  96167. +MODULE_DESCRIPTION("BCM2708 framebuffer driver");
  96168. +MODULE_LICENSE("GPL");
  96169. +
  96170. +MODULE_PARM_DESC(fbwidth, "Width of ARM Framebuffer");
  96171. +MODULE_PARM_DESC(fbheight, "Height of ARM Framebuffer");
  96172. +MODULE_PARM_DESC(fbdepth, "Bit depth of ARM Framebuffer");
  96173. +MODULE_PARM_DESC(fbswap, "Swap order of red and blue in 24 and 32 bit modes");
  96174. diff -Nur linux-3.12.18/drivers/video/cfbimgblt.c linux-rpi/drivers/video/cfbimgblt.c
  96175. --- linux-3.12.18/drivers/video/cfbimgblt.c 2014-04-18 11:14:28.000000000 +0200
  96176. +++ linux-rpi/drivers/video/cfbimgblt.c 2014-04-24 15:35:04.265566801 +0200
  96177. @@ -28,6 +28,11 @@
  96178. *
  96179. * Also need to add code to deal with cards endians that are different than
  96180. * the native cpu endians. I also need to deal with MSB position in the word.
  96181. + * Modified by Harm Hanemaaijer (fgenfb@yahoo.com) 2013:
  96182. + * - Provide optimized versions of fast_imageblit for 16 and 32bpp that are
  96183. + * significantly faster than the previous implementation.
  96184. + * - Simplify the fast/slow_imageblit selection code, avoiding integer
  96185. + * divides.
  96186. */
  96187. #include <linux/module.h>
  96188. #include <linux/string.h>
  96189. @@ -262,6 +267,133 @@
  96190. }
  96191. }
  96192. +/*
  96193. + * Optimized fast_imageblit for bpp == 16. ppw = 2, bit_mask = 3 folded
  96194. + * into the code, main loop unrolled.
  96195. + */
  96196. +
  96197. +static inline void fast_imageblit16(const struct fb_image *image,
  96198. + struct fb_info *p, u8 __iomem * dst1,
  96199. + u32 fgcolor, u32 bgcolor)
  96200. +{
  96201. + u32 fgx = fgcolor, bgx = bgcolor;
  96202. + u32 spitch = (image->width + 7) / 8;
  96203. + u32 end_mask, eorx;
  96204. + const char *s = image->data, *src;
  96205. + u32 __iomem *dst;
  96206. + const u32 *tab = NULL;
  96207. + int i, j, k;
  96208. +
  96209. + tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
  96210. +
  96211. + fgx <<= 16;
  96212. + bgx <<= 16;
  96213. + fgx |= fgcolor;
  96214. + bgx |= bgcolor;
  96215. +
  96216. + eorx = fgx ^ bgx;
  96217. + k = image->width / 2;
  96218. +
  96219. + for (i = image->height; i--;) {
  96220. + dst = (u32 __iomem *) dst1;
  96221. + src = s;
  96222. +
  96223. + j = k;
  96224. + while (j >= 4) {
  96225. + u8 bits = *src;
  96226. + end_mask = tab[(bits >> 6) & 3];
  96227. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96228. + end_mask = tab[(bits >> 4) & 3];
  96229. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96230. + end_mask = tab[(bits >> 2) & 3];
  96231. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96232. + end_mask = tab[bits & 3];
  96233. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96234. + src++;
  96235. + j -= 4;
  96236. + }
  96237. + if (j != 0) {
  96238. + u8 bits = *src;
  96239. + end_mask = tab[(bits >> 6) & 3];
  96240. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96241. + if (j >= 2) {
  96242. + end_mask = tab[(bits >> 4) & 3];
  96243. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96244. + if (j == 3) {
  96245. + end_mask = tab[(bits >> 2) & 3];
  96246. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  96247. + }
  96248. + }
  96249. + }
  96250. + dst1 += p->fix.line_length;
  96251. + s += spitch;
  96252. + }
  96253. +}
  96254. +
  96255. +/*
  96256. + * Optimized fast_imageblit for bpp == 32. ppw = 1, bit_mask = 1 folded
  96257. + * into the code, main loop unrolled.
  96258. + */
  96259. +
  96260. +static inline void fast_imageblit32(const struct fb_image *image,
  96261. + struct fb_info *p, u8 __iomem * dst1,
  96262. + u32 fgcolor, u32 bgcolor)
  96263. +{
  96264. + u32 fgx = fgcolor, bgx = bgcolor;
  96265. + u32 spitch = (image->width + 7) / 8;
  96266. + u32 end_mask, eorx;
  96267. + const char *s = image->data, *src;
  96268. + u32 __iomem *dst;
  96269. + const u32 *tab = NULL;
  96270. + int i, j, k;
  96271. +
  96272. + tab = cfb_tab32;
  96273. +
  96274. + eorx = fgx ^ bgx;
  96275. + k = image->width;
  96276. +
  96277. + for (i = image->height; i--;) {
  96278. + dst = (u32 __iomem *) dst1;
  96279. + src = s;
  96280. +
  96281. + j = k;
  96282. + while (j >= 8) {
  96283. + u8 bits = *src;
  96284. + end_mask = tab[(bits >> 7) & 1];
  96285. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96286. + end_mask = tab[(bits >> 6) & 1];
  96287. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96288. + end_mask = tab[(bits >> 5) & 1];
  96289. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96290. + end_mask = tab[(bits >> 4) & 1];
  96291. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96292. + end_mask = tab[(bits >> 3) & 1];
  96293. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96294. + end_mask = tab[(bits >> 2) & 1];
  96295. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96296. + end_mask = tab[(bits >> 1) & 1];
  96297. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96298. + end_mask = tab[bits & 1];
  96299. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96300. + src++;
  96301. + j -= 8;
  96302. + }
  96303. + if (j != 0) {
  96304. + u32 bits = (u32) * src;
  96305. + while (j > 1) {
  96306. + end_mask = tab[(bits >> 7) & 1];
  96307. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96308. + bits <<= 1;
  96309. + j--;
  96310. + }
  96311. + end_mask = tab[(bits >> 7) & 1];
  96312. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  96313. + }
  96314. + dst1 += p->fix.line_length;
  96315. + s += spitch;
  96316. + }
  96317. +}
  96318. +
  96319. void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
  96320. {
  96321. u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
  96322. @@ -294,11 +426,21 @@
  96323. bgcolor = image->bg_color;
  96324. }
  96325. - if (32 % bpp == 0 && !start_index && !pitch_index &&
  96326. - ((width & (32/bpp-1)) == 0) &&
  96327. - bpp >= 8 && bpp <= 32)
  96328. - fast_imageblit(image, p, dst1, fgcolor, bgcolor);
  96329. - else
  96330. + if (!start_index && !pitch_index) {
  96331. + if (bpp == 32)
  96332. + fast_imageblit32(image, p, dst1, fgcolor,
  96333. + bgcolor);
  96334. + else if (bpp == 16 && (width & 1) == 0)
  96335. + fast_imageblit16(image, p, dst1, fgcolor,
  96336. + bgcolor);
  96337. + else if (bpp == 8 && (width & 3) == 0)
  96338. + fast_imageblit(image, p, dst1, fgcolor,
  96339. + bgcolor);
  96340. + else
  96341. + slow_imageblit(image, p, dst1, fgcolor,
  96342. + bgcolor,
  96343. + start_index, pitch_index);
  96344. + } else
  96345. slow_imageblit(image, p, dst1, fgcolor, bgcolor,
  96346. start_index, pitch_index);
  96347. } else
  96348. diff -Nur linux-3.12.18/drivers/video/fbmem.c linux-rpi/drivers/video/fbmem.c
  96349. --- linux-3.12.18/drivers/video/fbmem.c 2014-04-18 11:14:28.000000000 +0200
  96350. +++ linux-rpi/drivers/video/fbmem.c 2014-04-24 16:04:39.923125259 +0200
  96351. @@ -1083,6 +1083,25 @@
  96352. }
  96353. EXPORT_SYMBOL(fb_blank);
  96354. +static int fb_copyarea_user(struct fb_info *info,
  96355. + struct fb_copyarea *copy)
  96356. +{
  96357. + int ret = 0;
  96358. + if (!lock_fb_info(info))
  96359. + return -ENODEV;
  96360. + if (copy->dx + copy->width > info->var.xres ||
  96361. + copy->sx + copy->width > info->var.xres ||
  96362. + copy->dy + copy->height > info->var.yres ||
  96363. + copy->sy + copy->height > info->var.yres) {
  96364. + ret = -EINVAL;
  96365. + goto out;
  96366. + }
  96367. + info->fbops->fb_copyarea(info, copy);
  96368. +out:
  96369. + unlock_fb_info(info);
  96370. + return ret;
  96371. +}
  96372. +
  96373. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  96374. unsigned long arg)
  96375. {
  96376. @@ -1093,6 +1112,7 @@
  96377. struct fb_cmap cmap_from;
  96378. struct fb_cmap_user cmap;
  96379. struct fb_event event;
  96380. + struct fb_copyarea copy;
  96381. void __user *argp = (void __user *)arg;
  96382. long ret = 0;
  96383. @@ -1108,16 +1128,14 @@
  96384. case FBIOPUT_VSCREENINFO:
  96385. if (copy_from_user(&var, argp, sizeof(var)))
  96386. return -EFAULT;
  96387. - console_lock();
  96388. - if (!lock_fb_info(info)) {
  96389. - console_unlock();
  96390. + if (!lock_fb_info(info))
  96391. return -ENODEV;
  96392. - }
  96393. + console_lock();
  96394. info->flags |= FBINFO_MISC_USEREVENT;
  96395. ret = fb_set_var(info, &var);
  96396. info->flags &= ~FBINFO_MISC_USEREVENT;
  96397. - unlock_fb_info(info);
  96398. console_unlock();
  96399. + unlock_fb_info(info);
  96400. if (!ret && copy_to_user(argp, &var, sizeof(var)))
  96401. ret = -EFAULT;
  96402. break;
  96403. @@ -1146,14 +1164,12 @@
  96404. case FBIOPAN_DISPLAY:
  96405. if (copy_from_user(&var, argp, sizeof(var)))
  96406. return -EFAULT;
  96407. - console_lock();
  96408. - if (!lock_fb_info(info)) {
  96409. - console_unlock();
  96410. + if (!lock_fb_info(info))
  96411. return -ENODEV;
  96412. - }
  96413. + console_lock();
  96414. ret = fb_pan_display(info, &var);
  96415. - unlock_fb_info(info);
  96416. console_unlock();
  96417. + unlock_fb_info(info);
  96418. if (ret == 0 && copy_to_user(argp, &var, sizeof(var)))
  96419. return -EFAULT;
  96420. break;
  96421. @@ -1188,28 +1204,33 @@
  96422. break;
  96423. }
  96424. event.data = &con2fb;
  96425. - console_lock();
  96426. - if (!lock_fb_info(info)) {
  96427. - console_unlock();
  96428. + if (!lock_fb_info(info))
  96429. return -ENODEV;
  96430. - }
  96431. + console_lock();
  96432. event.info = info;
  96433. ret = fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP, &event);
  96434. - unlock_fb_info(info);
  96435. console_unlock();
  96436. + unlock_fb_info(info);
  96437. break;
  96438. case FBIOBLANK:
  96439. - console_lock();
  96440. - if (!lock_fb_info(info)) {
  96441. - console_unlock();
  96442. + if (!lock_fb_info(info))
  96443. return -ENODEV;
  96444. - }
  96445. + console_lock();
  96446. info->flags |= FBINFO_MISC_USEREVENT;
  96447. ret = fb_blank(info, arg);
  96448. info->flags &= ~FBINFO_MISC_USEREVENT;
  96449. - unlock_fb_info(info);
  96450. console_unlock();
  96451. + unlock_fb_info(info);
  96452. break;
  96453. + case FBIOCOPYAREA:
  96454. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  96455. + /* only provide this ioctl if it is accelerated */
  96456. + if (copy_from_user(&copy, argp, sizeof(copy)))
  96457. + return -EFAULT;
  96458. + ret = fb_copyarea_user(info, &copy);
  96459. + break;
  96460. + }
  96461. + /* fall through */
  96462. default:
  96463. if (!lock_fb_info(info))
  96464. return -ENODEV;
  96465. @@ -1364,6 +1385,7 @@
  96466. case FBIOPAN_DISPLAY:
  96467. case FBIOGET_CON2FBMAP:
  96468. case FBIOPUT_CON2FBMAP:
  96469. + case FBIOCOPYAREA:
  96470. arg = (unsigned long) compat_ptr(arg);
  96471. case FBIOBLANK:
  96472. ret = do_fb_ioctl(info, cmd, arg);
  96473. @@ -1577,10 +1599,10 @@
  96474. static int do_unregister_framebuffer(struct fb_info *fb_info);
  96475. #define VGA_FB_PHYS 0xA0000
  96476. -static int do_remove_conflicting_framebuffers(struct apertures_struct *a,
  96477. - const char *name, bool primary)
  96478. +static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
  96479. + const char *name, bool primary)
  96480. {
  96481. - int i, ret;
  96482. + int i;
  96483. /* check all firmware fbs and kick off if the base addr overlaps */
  96484. for (i = 0 ; i < FB_MAX; i++) {
  96485. @@ -1596,31 +1618,25 @@
  96486. (primary && gen_aper && gen_aper->count &&
  96487. gen_aper->ranges[0].base == VGA_FB_PHYS)) {
  96488. - printk(KERN_INFO "fb: switching to %s from %s\n",
  96489. + printk(KERN_INFO "fb: conflicting fb hw usage "
  96490. + "%s vs %s - removing generic driver\n",
  96491. name, registered_fb[i]->fix.id);
  96492. - ret = do_unregister_framebuffer(registered_fb[i]);
  96493. - if (ret)
  96494. - return ret;
  96495. + do_unregister_framebuffer(registered_fb[i]);
  96496. }
  96497. }
  96498. -
  96499. - return 0;
  96500. }
  96501. static int do_register_framebuffer(struct fb_info *fb_info)
  96502. {
  96503. - int i, ret;
  96504. + int i;
  96505. struct fb_event event;
  96506. struct fb_videomode mode;
  96507. if (fb_check_foreignness(fb_info))
  96508. return -ENOSYS;
  96509. - ret = do_remove_conflicting_framebuffers(fb_info->apertures,
  96510. - fb_info->fix.id,
  96511. - fb_is_primary_device(fb_info));
  96512. - if (ret)
  96513. - return ret;
  96514. + do_remove_conflicting_framebuffers(fb_info->apertures, fb_info->fix.id,
  96515. + fb_is_primary_device(fb_info));
  96516. if (num_registered_fb == FB_MAX)
  96517. return -ENXIO;
  96518. @@ -1674,15 +1690,12 @@
  96519. registered_fb[i] = fb_info;
  96520. event.info = fb_info;
  96521. - console_lock();
  96522. - if (!lock_fb_info(fb_info)) {
  96523. - console_unlock();
  96524. + if (!lock_fb_info(fb_info))
  96525. return -ENODEV;
  96526. - }
  96527. -
  96528. + console_lock();
  96529. fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
  96530. - unlock_fb_info(fb_info);
  96531. console_unlock();
  96532. + unlock_fb_info(fb_info);
  96533. return 0;
  96534. }
  96535. @@ -1695,16 +1708,13 @@
  96536. if (i < 0 || i >= FB_MAX || registered_fb[i] != fb_info)
  96537. return -EINVAL;
  96538. - console_lock();
  96539. - if (!lock_fb_info(fb_info)) {
  96540. - console_unlock();
  96541. + if (!lock_fb_info(fb_info))
  96542. return -ENODEV;
  96543. - }
  96544. -
  96545. + console_lock();
  96546. event.info = fb_info;
  96547. ret = fb_notifier_call_chain(FB_EVENT_FB_UNBIND, &event);
  96548. - unlock_fb_info(fb_info);
  96549. console_unlock();
  96550. + unlock_fb_info(fb_info);
  96551. if (ret)
  96552. return -EINVAL;
  96553. @@ -1745,16 +1755,12 @@
  96554. }
  96555. EXPORT_SYMBOL(unlink_framebuffer);
  96556. -int remove_conflicting_framebuffers(struct apertures_struct *a,
  96557. - const char *name, bool primary)
  96558. +void remove_conflicting_framebuffers(struct apertures_struct *a,
  96559. + const char *name, bool primary)
  96560. {
  96561. - int ret;
  96562. -
  96563. mutex_lock(&registration_lock);
  96564. - ret = do_remove_conflicting_framebuffers(a, name, primary);
  96565. + do_remove_conflicting_framebuffers(a, name, primary);
  96566. mutex_unlock(&registration_lock);
  96567. -
  96568. - return ret;
  96569. }
  96570. EXPORT_SYMBOL(remove_conflicting_framebuffers);
  96571. diff -Nur linux-3.12.18/drivers/video/fbsysfs.c linux-rpi/drivers/video/fbsysfs.c
  96572. --- linux-3.12.18/drivers/video/fbsysfs.c 2014-04-18 11:14:28.000000000 +0200
  96573. +++ linux-rpi/drivers/video/fbsysfs.c 2014-04-24 15:35:04.277566935 +0200
  96574. @@ -177,12 +177,9 @@
  96575. if (i * sizeof(struct fb_videomode) != count)
  96576. return -EINVAL;
  96577. - console_lock();
  96578. - if (!lock_fb_info(fb_info)) {
  96579. - console_unlock();
  96580. + if (!lock_fb_info(fb_info))
  96581. return -ENODEV;
  96582. - }
  96583. -
  96584. + console_lock();
  96585. list_splice(&fb_info->modelist, &old_list);
  96586. fb_videomode_to_modelist((const struct fb_videomode *)buf, i,
  96587. &fb_info->modelist);
  96588. @@ -192,8 +189,8 @@
  96589. } else
  96590. fb_destroy_modelist(&old_list);
  96591. - unlock_fb_info(fb_info);
  96592. console_unlock();
  96593. + unlock_fb_info(fb_info);
  96594. return 0;
  96595. }
  96596. @@ -407,16 +404,12 @@
  96597. state = simple_strtoul(buf, &last, 0);
  96598. - console_lock();
  96599. - if (!lock_fb_info(fb_info)) {
  96600. - console_unlock();
  96601. + if (!lock_fb_info(fb_info))
  96602. return -ENODEV;
  96603. - }
  96604. -
  96605. + console_lock();
  96606. fb_set_suspend(fb_info, (int)state);
  96607. -
  96608. - unlock_fb_info(fb_info);
  96609. console_unlock();
  96610. + unlock_fb_info(fb_info);
  96611. return count;
  96612. }
  96613. diff -Nur linux-3.12.18/drivers/video/Kconfig linux-rpi/drivers/video/Kconfig
  96614. --- linux-3.12.18/drivers/video/Kconfig 2014-04-18 11:14:28.000000000 +0200
  96615. +++ linux-rpi/drivers/video/Kconfig 2014-04-24 16:04:39.911125143 +0200
  96616. @@ -310,6 +310,20 @@
  96617. help
  96618. Support the Permedia2 FIFO disconnect feature.
  96619. +config FB_BCM2708
  96620. + tristate "BCM2708 framebuffer support"
  96621. + depends on FB && ARM
  96622. + select FB_CFB_FILLRECT
  96623. + select FB_CFB_COPYAREA
  96624. + select FB_CFB_IMAGEBLIT
  96625. + help
  96626. + This framebuffer device driver is for the BCM2708 framebuffer.
  96627. +
  96628. + If you want to compile this as a module (=code which can be
  96629. + inserted into and removed from the running kernel), say M
  96630. + here and read <file:Documentation/kbuild/modules.txt>. The module
  96631. + will be called bcm2708_fb.
  96632. +
  96633. config FB_ARMCLCD
  96634. tristate "ARM PrimeCell PL110 support"
  96635. depends on FB && ARM && ARM_AMBA
  96636. diff -Nur linux-3.12.18/drivers/video/logo/logo_linux_clut224.ppm linux-rpi/drivers/video/logo/logo_linux_clut224.ppm
  96637. --- linux-3.12.18/drivers/video/logo/logo_linux_clut224.ppm 2014-04-18 11:14:28.000000000 +0200
  96638. +++ linux-rpi/drivers/video/logo/logo_linux_clut224.ppm 2014-04-24 15:35:04.285567024 +0200
  96639. @@ -1,1604 +1,883 @@
  96640. P3
  96641. -# Standard 224-color Linux logo
  96642. -80 80
  96643. +63 80
  96644. 255
  96645. - 0 0 0 0 0 0 0 0 0 0 0 0
  96646. - 0 0 0 0 0 0 0 0 0 0 0 0
  96647. - 0 0 0 0 0 0 0 0 0 0 0 0
  96648. - 0 0 0 0 0 0 0 0 0 0 0 0
  96649. - 0 0 0 0 0 0 0 0 0 0 0 0
  96650. - 0 0 0 0 0 0 0 0 0 0 0 0
  96651. - 0 0 0 0 0 0 0 0 0 0 0 0
  96652. - 0 0 0 0 0 0 0 0 0 0 0 0
  96653. - 0 0 0 0 0 0 0 0 0 0 0 0
  96654. - 6 6 6 6 6 6 10 10 10 10 10 10
  96655. - 10 10 10 6 6 6 6 6 6 6 6 6
  96656. - 0 0 0 0 0 0 0 0 0 0 0 0
  96657. - 0 0 0 0 0 0 0 0 0 0 0 0
  96658. - 0 0 0 0 0 0 0 0 0 0 0 0
  96659. - 0 0 0 0 0 0 0 0 0 0 0 0
  96660. - 0 0 0 0 0 0 0 0 0 0 0 0
  96661. - 0 0 0 0 0 0 0 0 0 0 0 0
  96662. - 0 0 0 0 0 0 0 0 0 0 0 0
  96663. - 0 0 0 0 0 0 0 0 0 0 0 0
  96664. - 0 0 0 0 0 0 0 0 0 0 0 0
  96665. - 0 0 0 0 0 0 0 0 0 0 0 0
  96666. - 0 0 0 0 0 0 0 0 0 0 0 0
  96667. - 0 0 0 0 0 0 0 0 0 0 0 0
  96668. - 0 0 0 0 0 0 0 0 0 0 0 0
  96669. - 0 0 0 0 0 0 0 0 0 0 0 0
  96670. - 0 0 0 0 0 0 0 0 0 0 0 0
  96671. - 0 0 0 0 0 0 0 0 0 0 0 0
  96672. - 0 0 0 0 0 0 0 0 0 0 0 0
  96673. - 0 0 0 6 6 6 10 10 10 14 14 14
  96674. - 22 22 22 26 26 26 30 30 30 34 34 34
  96675. - 30 30 30 30 30 30 26 26 26 18 18 18
  96676. - 14 14 14 10 10 10 6 6 6 0 0 0
  96677. - 0 0 0 0 0 0 0 0 0 0 0 0
  96678. - 0 0 0 0 0 0 0 0 0 0 0 0
  96679. - 0 0 0 0 0 0 0 0 0 0 0 0
  96680. - 0 0 0 0 0 0 0 0 0 0 0 0
  96681. - 0 0 0 0 0 0 0 0 0 0 0 0
  96682. - 0 0 0 0 0 0 0 0 0 0 0 0
  96683. - 0 0 0 0 0 0 0 0 0 0 0 0
  96684. - 0 0 0 0 0 0 0 0 0 0 0 0
  96685. - 0 0 0 0 0 0 0 0 0 0 0 0
  96686. - 0 0 0 0 0 1 0 0 1 0 0 0
  96687. - 0 0 0 0 0 0 0 0 0 0 0 0
  96688. - 0 0 0 0 0 0 0 0 0 0 0 0
  96689. - 0 0 0 0 0 0 0 0 0 0 0 0
  96690. - 0 0 0 0 0 0 0 0 0 0 0 0
  96691. - 0 0 0 0 0 0 0 0 0 0 0 0
  96692. - 0 0 0 0 0 0 0 0 0 0 0 0
  96693. - 6 6 6 14 14 14 26 26 26 42 42 42
  96694. - 54 54 54 66 66 66 78 78 78 78 78 78
  96695. - 78 78 78 74 74 74 66 66 66 54 54 54
  96696. - 42 42 42 26 26 26 18 18 18 10 10 10
  96697. - 6 6 6 0 0 0 0 0 0 0 0 0
  96698. - 0 0 0 0 0 0 0 0 0 0 0 0
  96699. - 0 0 0 0 0 0 0 0 0 0 0 0
  96700. - 0 0 0 0 0 0 0 0 0 0 0 0
  96701. - 0 0 0 0 0 0 0 0 0 0 0 0
  96702. - 0 0 0 0 0 0 0 0 0 0 0 0
  96703. - 0 0 0 0 0 0 0 0 0 0 0 0
  96704. - 0 0 0 0 0 0 0 0 0 0 0 0
  96705. - 0 0 0 0 0 0 0 0 0 0 0 0
  96706. - 0 0 1 0 0 0 0 0 0 0 0 0
  96707. - 0 0 0 0 0 0 0 0 0 0 0 0
  96708. - 0 0 0 0 0 0 0 0 0 0 0 0
  96709. - 0 0 0 0 0 0 0 0 0 0 0 0
  96710. - 0 0 0 0 0 0 0 0 0 0 0 0
  96711. - 0 0 0 0 0 0 0 0 0 0 0 0
  96712. - 0 0 0 0 0 0 0 0 0 10 10 10
  96713. - 22 22 22 42 42 42 66 66 66 86 86 86
  96714. - 66 66 66 38 38 38 38 38 38 22 22 22
  96715. - 26 26 26 34 34 34 54 54 54 66 66 66
  96716. - 86 86 86 70 70 70 46 46 46 26 26 26
  96717. - 14 14 14 6 6 6 0 0 0 0 0 0
  96718. - 0 0 0 0 0 0 0 0 0 0 0 0
  96719. - 0 0 0 0 0 0 0 0 0 0 0 0
  96720. - 0 0 0 0 0 0 0 0 0 0 0 0
  96721. - 0 0 0 0 0 0 0 0 0 0 0 0
  96722. - 0 0 0 0 0 0 0 0 0 0 0 0
  96723. - 0 0 0 0 0 0 0 0 0 0 0 0
  96724. - 0 0 0 0 0 0 0 0 0 0 0 0
  96725. - 0 0 0 0 0 0 0 0 0 0 0 0
  96726. - 0 0 1 0 0 1 0 0 1 0 0 0
  96727. - 0 0 0 0 0 0 0 0 0 0 0 0
  96728. - 0 0 0 0 0 0 0 0 0 0 0 0
  96729. - 0 0 0 0 0 0 0 0 0 0 0 0
  96730. - 0 0 0 0 0 0 0 0 0 0 0 0
  96731. - 0 0 0 0 0 0 0 0 0 0 0 0
  96732. - 0 0 0 0 0 0 10 10 10 26 26 26
  96733. - 50 50 50 82 82 82 58 58 58 6 6 6
  96734. - 2 2 6 2 2 6 2 2 6 2 2 6
  96735. - 2 2 6 2 2 6 2 2 6 2 2 6
  96736. - 6 6 6 54 54 54 86 86 86 66 66 66
  96737. - 38 38 38 18 18 18 6 6 6 0 0 0
  96738. - 0 0 0 0 0 0 0 0 0 0 0 0
  96739. - 0 0 0 0 0 0 0 0 0 0 0 0
  96740. - 0 0 0 0 0 0 0 0 0 0 0 0
  96741. - 0 0 0 0 0 0 0 0 0 0 0 0
  96742. - 0 0 0 0 0 0 0 0 0 0 0 0
  96743. - 0 0 0 0 0 0 0 0 0 0 0 0
  96744. - 0 0 0 0 0 0 0 0 0 0 0 0
  96745. - 0 0 0 0 0 0 0 0 0 0 0 0
  96746. - 0 0 0 0 0 0 0 0 0 0 0 0
  96747. - 0 0 0 0 0 0 0 0 0 0 0 0
  96748. - 0 0 0 0 0 0 0 0 0 0 0 0
  96749. - 0 0 0 0 0 0 0 0 0 0 0 0
  96750. - 0 0 0 0 0 0 0 0 0 0 0 0
  96751. - 0 0 0 0 0 0 0 0 0 0 0 0
  96752. - 0 0 0 6 6 6 22 22 22 50 50 50
  96753. - 78 78 78 34 34 34 2 2 6 2 2 6
  96754. - 2 2 6 2 2 6 2 2 6 2 2 6
  96755. - 2 2 6 2 2 6 2 2 6 2 2 6
  96756. - 2 2 6 2 2 6 6 6 6 70 70 70
  96757. - 78 78 78 46 46 46 22 22 22 6 6 6
  96758. - 0 0 0 0 0 0 0 0 0 0 0 0
  96759. - 0 0 0 0 0 0 0 0 0 0 0 0
  96760. - 0 0 0 0 0 0 0 0 0 0 0 0
  96761. - 0 0 0 0 0 0 0 0 0 0 0 0
  96762. - 0 0 0 0 0 0 0 0 0 0 0 0
  96763. - 0 0 0 0 0 0 0 0 0 0 0 0
  96764. - 0 0 0 0 0 0 0 0 0 0 0 0
  96765. - 0 0 0 0 0 0 0 0 0 0 0 0
  96766. - 0 0 1 0 0 1 0 0 1 0 0 0
  96767. - 0 0 0 0 0 0 0 0 0 0 0 0
  96768. - 0 0 0 0 0 0 0 0 0 0 0 0
  96769. - 0 0 0 0 0 0 0 0 0 0 0 0
  96770. - 0 0 0 0 0 0 0 0 0 0 0 0
  96771. - 0 0 0 0 0 0 0 0 0 0 0 0
  96772. - 6 6 6 18 18 18 42 42 42 82 82 82
  96773. - 26 26 26 2 2 6 2 2 6 2 2 6
  96774. - 2 2 6 2 2 6 2 2 6 2 2 6
  96775. - 2 2 6 2 2 6 2 2 6 14 14 14
  96776. - 46 46 46 34 34 34 6 6 6 2 2 6
  96777. - 42 42 42 78 78 78 42 42 42 18 18 18
  96778. - 6 6 6 0 0 0 0 0 0 0 0 0
  96779. - 0 0 0 0 0 0 0 0 0 0 0 0
  96780. - 0 0 0 0 0 0 0 0 0 0 0 0
  96781. - 0 0 0 0 0 0 0 0 0 0 0 0
  96782. - 0 0 0 0 0 0 0 0 0 0 0 0
  96783. - 0 0 0 0 0 0 0 0 0 0 0 0
  96784. - 0 0 0 0 0 0 0 0 0 0 0 0
  96785. - 0 0 0 0 0 0 0 0 0 0 0 0
  96786. - 0 0 1 0 0 0 0 0 1 0 0 0
  96787. - 0 0 0 0 0 0 0 0 0 0 0 0
  96788. - 0 0 0 0 0 0 0 0 0 0 0 0
  96789. - 0 0 0 0 0 0 0 0 0 0 0 0
  96790. - 0 0 0 0 0 0 0 0 0 0 0 0
  96791. - 0 0 0 0 0 0 0 0 0 0 0 0
  96792. - 10 10 10 30 30 30 66 66 66 58 58 58
  96793. - 2 2 6 2 2 6 2 2 6 2 2 6
  96794. - 2 2 6 2 2 6 2 2 6 2 2 6
  96795. - 2 2 6 2 2 6 2 2 6 26 26 26
  96796. - 86 86 86 101 101 101 46 46 46 10 10 10
  96797. - 2 2 6 58 58 58 70 70 70 34 34 34
  96798. - 10 10 10 0 0 0 0 0 0 0 0 0
  96799. - 0 0 0 0 0 0 0 0 0 0 0 0
  96800. - 0 0 0 0 0 0 0 0 0 0 0 0
  96801. - 0 0 0 0 0 0 0 0 0 0 0 0
  96802. - 0 0 0 0 0 0 0 0 0 0 0 0
  96803. - 0 0 0 0 0 0 0 0 0 0 0 0
  96804. - 0 0 0 0 0 0 0 0 0 0 0 0
  96805. - 0 0 0 0 0 0 0 0 0 0 0 0
  96806. - 0 0 1 0 0 1 0 0 1 0 0 0
  96807. - 0 0 0 0 0 0 0 0 0 0 0 0
  96808. - 0 0 0 0 0 0 0 0 0 0 0 0
  96809. - 0 0 0 0 0 0 0 0 0 0 0 0
  96810. - 0 0 0 0 0 0 0 0 0 0 0 0
  96811. - 0 0 0 0 0 0 0 0 0 0 0 0
  96812. - 14 14 14 42 42 42 86 86 86 10 10 10
  96813. - 2 2 6 2 2 6 2 2 6 2 2 6
  96814. - 2 2 6 2 2 6 2 2 6 2 2 6
  96815. - 2 2 6 2 2 6 2 2 6 30 30 30
  96816. - 94 94 94 94 94 94 58 58 58 26 26 26
  96817. - 2 2 6 6 6 6 78 78 78 54 54 54
  96818. - 22 22 22 6 6 6 0 0 0 0 0 0
  96819. - 0 0 0 0 0 0 0 0 0 0 0 0
  96820. - 0 0 0 0 0 0 0 0 0 0 0 0
  96821. - 0 0 0 0 0 0 0 0 0 0 0 0
  96822. - 0 0 0 0 0 0 0 0 0 0 0 0
  96823. - 0 0 0 0 0 0 0 0 0 0 0 0
  96824. - 0 0 0 0 0 0 0 0 0 0 0 0
  96825. - 0 0 0 0 0 0 0 0 0 0 0 0
  96826. - 0 0 0 0 0 0 0 0 0 0 0 0
  96827. - 0 0 0 0 0 0 0 0 0 0 0 0
  96828. - 0 0 0 0 0 0 0 0 0 0 0 0
  96829. - 0 0 0 0 0 0 0 0 0 0 0 0
  96830. - 0 0 0 0 0 0 0 0 0 0 0 0
  96831. - 0 0 0 0 0 0 0 0 0 6 6 6
  96832. - 22 22 22 62 62 62 62 62 62 2 2 6
  96833. - 2 2 6 2 2 6 2 2 6 2 2 6
  96834. - 2 2 6 2 2 6 2 2 6 2 2 6
  96835. - 2 2 6 2 2 6 2 2 6 26 26 26
  96836. - 54 54 54 38 38 38 18 18 18 10 10 10
  96837. - 2 2 6 2 2 6 34 34 34 82 82 82
  96838. - 38 38 38 14 14 14 0 0 0 0 0 0
  96839. - 0 0 0 0 0 0 0 0 0 0 0 0
  96840. - 0 0 0 0 0 0 0 0 0 0 0 0
  96841. - 0 0 0 0 0 0 0 0 0 0 0 0
  96842. - 0 0 0 0 0 0 0 0 0 0 0 0
  96843. - 0 0 0 0 0 0 0 0 0 0 0 0
  96844. - 0 0 0 0 0 0 0 0 0 0 0 0
  96845. - 0 0 0 0 0 0 0 0 0 0 0 0
  96846. - 0 0 0 0 0 1 0 0 1 0 0 0
  96847. - 0 0 0 0 0 0 0 0 0 0 0 0
  96848. - 0 0 0 0 0 0 0 0 0 0 0 0
  96849. - 0 0 0 0 0 0 0 0 0 0 0 0
  96850. - 0 0 0 0 0 0 0 0 0 0 0 0
  96851. - 0 0 0 0 0 0 0 0 0 6 6 6
  96852. - 30 30 30 78 78 78 30 30 30 2 2 6
  96853. - 2 2 6 2 2 6 2 2 6 2 2 6
  96854. - 2 2 6 2 2 6 2 2 6 2 2 6
  96855. - 2 2 6 2 2 6 2 2 6 10 10 10
  96856. - 10 10 10 2 2 6 2 2 6 2 2 6
  96857. - 2 2 6 2 2 6 2 2 6 78 78 78
  96858. - 50 50 50 18 18 18 6 6 6 0 0 0
  96859. - 0 0 0 0 0 0 0 0 0 0 0 0
  96860. - 0 0 0 0 0 0 0 0 0 0 0 0
  96861. - 0 0 0 0 0 0 0 0 0 0 0 0
  96862. - 0 0 0 0 0 0 0 0 0 0 0 0
  96863. - 0 0 0 0 0 0 0 0 0 0 0 0
  96864. - 0 0 0 0 0 0 0 0 0 0 0 0
  96865. - 0 0 0 0 0 0 0 0 0 0 0 0
  96866. - 0 0 1 0 0 0 0 0 0 0 0 0
  96867. - 0 0 0 0 0 0 0 0 0 0 0 0
  96868. - 0 0 0 0 0 0 0 0 0 0 0 0
  96869. - 0 0 0 0 0 0 0 0 0 0 0 0
  96870. - 0 0 0 0 0 0 0 0 0 0 0 0
  96871. - 0 0 0 0 0 0 0 0 0 10 10 10
  96872. - 38 38 38 86 86 86 14 14 14 2 2 6
  96873. - 2 2 6 2 2 6 2 2 6 2 2 6
  96874. - 2 2 6 2 2 6 2 2 6 2 2 6
  96875. - 2 2 6 2 2 6 2 2 6 2 2 6
  96876. - 2 2 6 2 2 6 2 2 6 2 2 6
  96877. - 2 2 6 2 2 6 2 2 6 54 54 54
  96878. - 66 66 66 26 26 26 6 6 6 0 0 0
  96879. - 0 0 0 0 0 0 0 0 0 0 0 0
  96880. - 0 0 0 0 0 0 0 0 0 0 0 0
  96881. - 0 0 0 0 0 0 0 0 0 0 0 0
  96882. - 0 0 0 0 0 0 0 0 0 0 0 0
  96883. - 0 0 0 0 0 0 0 0 0 0 0 0
  96884. - 0 0 0 0 0 0 0 0 0 0 0 0
  96885. - 0 0 0 0 0 0 0 0 0 0 0 0
  96886. - 0 0 0 0 0 1 0 0 1 0 0 0
  96887. - 0 0 0 0 0 0 0 0 0 0 0 0
  96888. - 0 0 0 0 0 0 0 0 0 0 0 0
  96889. - 0 0 0 0 0 0 0 0 0 0 0 0
  96890. - 0 0 0 0 0 0 0 0 0 0 0 0
  96891. - 0 0 0 0 0 0 0 0 0 14 14 14
  96892. - 42 42 42 82 82 82 2 2 6 2 2 6
  96893. - 2 2 6 6 6 6 10 10 10 2 2 6
  96894. - 2 2 6 2 2 6 2 2 6 2 2 6
  96895. - 2 2 6 2 2 6 2 2 6 6 6 6
  96896. - 14 14 14 10 10 10 2 2 6 2 2 6
  96897. - 2 2 6 2 2 6 2 2 6 18 18 18
  96898. - 82 82 82 34 34 34 10 10 10 0 0 0
  96899. - 0 0 0 0 0 0 0 0 0 0 0 0
  96900. - 0 0 0 0 0 0 0 0 0 0 0 0
  96901. - 0 0 0 0 0 0 0 0 0 0 0 0
  96902. - 0 0 0 0 0 0 0 0 0 0 0 0
  96903. - 0 0 0 0 0 0 0 0 0 0 0 0
  96904. - 0 0 0 0 0 0 0 0 0 0 0 0
  96905. - 0 0 0 0 0 0 0 0 0 0 0 0
  96906. - 0 0 1 0 0 0 0 0 0 0 0 0
  96907. - 0 0 0 0 0 0 0 0 0 0 0 0
  96908. - 0 0 0 0 0 0 0 0 0 0 0 0
  96909. - 0 0 0 0 0 0 0 0 0 0 0 0
  96910. - 0 0 0 0 0 0 0 0 0 0 0 0
  96911. - 0 0 0 0 0 0 0 0 0 14 14 14
  96912. - 46 46 46 86 86 86 2 2 6 2 2 6
  96913. - 6 6 6 6 6 6 22 22 22 34 34 34
  96914. - 6 6 6 2 2 6 2 2 6 2 2 6
  96915. - 2 2 6 2 2 6 18 18 18 34 34 34
  96916. - 10 10 10 50 50 50 22 22 22 2 2 6
  96917. - 2 2 6 2 2 6 2 2 6 10 10 10
  96918. - 86 86 86 42 42 42 14 14 14 0 0 0
  96919. - 0 0 0 0 0 0 0 0 0 0 0 0
  96920. - 0 0 0 0 0 0 0 0 0 0 0 0
  96921. - 0 0 0 0 0 0 0 0 0 0 0 0
  96922. - 0 0 0 0 0 0 0 0 0 0 0 0
  96923. - 0 0 0 0 0 0 0 0 0 0 0 0
  96924. - 0 0 0 0 0 0 0 0 0 0 0 0
  96925. - 0 0 0 0 0 0 0 0 0 0 0 0
  96926. - 0 0 1 0 0 1 0 0 1 0 0 0
  96927. - 0 0 0 0 0 0 0 0 0 0 0 0
  96928. - 0 0 0 0 0 0 0 0 0 0 0 0
  96929. - 0 0 0 0 0 0 0 0 0 0 0 0
  96930. - 0 0 0 0 0 0 0 0 0 0 0 0
  96931. - 0 0 0 0 0 0 0 0 0 14 14 14
  96932. - 46 46 46 86 86 86 2 2 6 2 2 6
  96933. - 38 38 38 116 116 116 94 94 94 22 22 22
  96934. - 22 22 22 2 2 6 2 2 6 2 2 6
  96935. - 14 14 14 86 86 86 138 138 138 162 162 162
  96936. -154 154 154 38 38 38 26 26 26 6 6 6
  96937. - 2 2 6 2 2 6 2 2 6 2 2 6
  96938. - 86 86 86 46 46 46 14 14 14 0 0 0
  96939. - 0 0 0 0 0 0 0 0 0 0 0 0
  96940. - 0 0 0 0 0 0 0 0 0 0 0 0
  96941. - 0 0 0 0 0 0 0 0 0 0 0 0
  96942. - 0 0 0 0 0 0 0 0 0 0 0 0
  96943. - 0 0 0 0 0 0 0 0 0 0 0 0
  96944. - 0 0 0 0 0 0 0 0 0 0 0 0
  96945. - 0 0 0 0 0 0 0 0 0 0 0 0
  96946. - 0 0 0 0 0 0 0 0 0 0 0 0
  96947. - 0 0 0 0 0 0 0 0 0 0 0 0
  96948. - 0 0 0 0 0 0 0 0 0 0 0 0
  96949. - 0 0 0 0 0 0 0 0 0 0 0 0
  96950. - 0 0 0 0 0 0 0 0 0 0 0 0
  96951. - 0 0 0 0 0 0 0 0 0 14 14 14
  96952. - 46 46 46 86 86 86 2 2 6 14 14 14
  96953. -134 134 134 198 198 198 195 195 195 116 116 116
  96954. - 10 10 10 2 2 6 2 2 6 6 6 6
  96955. -101 98 89 187 187 187 210 210 210 218 218 218
  96956. -214 214 214 134 134 134 14 14 14 6 6 6
  96957. - 2 2 6 2 2 6 2 2 6 2 2 6
  96958. - 86 86 86 50 50 50 18 18 18 6 6 6
  96959. - 0 0 0 0 0 0 0 0 0 0 0 0
  96960. - 0 0 0 0 0 0 0 0 0 0 0 0
  96961. - 0 0 0 0 0 0 0 0 0 0 0 0
  96962. - 0 0 0 0 0 0 0 0 0 0 0 0
  96963. - 0 0 0 0 0 0 0 0 0 0 0 0
  96964. - 0 0 0 0 0 0 0 0 0 0 0 0
  96965. - 0 0 0 0 0 0 0 0 1 0 0 0
  96966. - 0 0 1 0 0 1 0 0 1 0 0 0
  96967. - 0 0 0 0 0 0 0 0 0 0 0 0
  96968. - 0 0 0 0 0 0 0 0 0 0 0 0
  96969. - 0 0 0 0 0 0 0 0 0 0 0 0
  96970. - 0 0 0 0 0 0 0 0 0 0 0 0
  96971. - 0 0 0 0 0 0 0 0 0 14 14 14
  96972. - 46 46 46 86 86 86 2 2 6 54 54 54
  96973. -218 218 218 195 195 195 226 226 226 246 246 246
  96974. - 58 58 58 2 2 6 2 2 6 30 30 30
  96975. -210 210 210 253 253 253 174 174 174 123 123 123
  96976. -221 221 221 234 234 234 74 74 74 2 2 6
  96977. - 2 2 6 2 2 6 2 2 6 2 2 6
  96978. - 70 70 70 58 58 58 22 22 22 6 6 6
  96979. - 0 0 0 0 0 0 0 0 0 0 0 0
  96980. - 0 0 0 0 0 0 0 0 0 0 0 0
  96981. - 0 0 0 0 0 0 0 0 0 0 0 0
  96982. - 0 0 0 0 0 0 0 0 0 0 0 0
  96983. - 0 0 0 0 0 0 0 0 0 0 0 0
  96984. - 0 0 0 0 0 0 0 0 0 0 0 0
  96985. - 0 0 0 0 0 0 0 0 0 0 0 0
  96986. - 0 0 0 0 0 0 0 0 0 0 0 0
  96987. - 0 0 0 0 0 0 0 0 0 0 0 0
  96988. - 0 0 0 0 0 0 0 0 0 0 0 0
  96989. - 0 0 0 0 0 0 0 0 0 0 0 0
  96990. - 0 0 0 0 0 0 0 0 0 0 0 0
  96991. - 0 0 0 0 0 0 0 0 0 14 14 14
  96992. - 46 46 46 82 82 82 2 2 6 106 106 106
  96993. -170 170 170 26 26 26 86 86 86 226 226 226
  96994. -123 123 123 10 10 10 14 14 14 46 46 46
  96995. -231 231 231 190 190 190 6 6 6 70 70 70
  96996. - 90 90 90 238 238 238 158 158 158 2 2 6
  96997. - 2 2 6 2 2 6 2 2 6 2 2 6
  96998. - 70 70 70 58 58 58 22 22 22 6 6 6
  96999. - 0 0 0 0 0 0 0 0 0 0 0 0
  97000. - 0 0 0 0 0 0 0 0 0 0 0 0
  97001. - 0 0 0 0 0 0 0 0 0 0 0 0
  97002. - 0 0 0 0 0 0 0 0 0 0 0 0
  97003. - 0 0 0 0 0 0 0 0 0 0 0 0
  97004. - 0 0 0 0 0 0 0 0 0 0 0 0
  97005. - 0 0 0 0 0 0 0 0 1 0 0 0
  97006. - 0 0 1 0 0 1 0 0 1 0 0 0
  97007. - 0 0 0 0 0 0 0 0 0 0 0 0
  97008. - 0 0 0 0 0 0 0 0 0 0 0 0
  97009. - 0 0 0 0 0 0 0 0 0 0 0 0
  97010. - 0 0 0 0 0 0 0 0 0 0 0 0
  97011. - 0 0 0 0 0 0 0 0 0 14 14 14
  97012. - 42 42 42 86 86 86 6 6 6 116 116 116
  97013. -106 106 106 6 6 6 70 70 70 149 149 149
  97014. -128 128 128 18 18 18 38 38 38 54 54 54
  97015. -221 221 221 106 106 106 2 2 6 14 14 14
  97016. - 46 46 46 190 190 190 198 198 198 2 2 6
  97017. - 2 2 6 2 2 6 2 2 6 2 2 6
  97018. - 74 74 74 62 62 62 22 22 22 6 6 6
  97019. - 0 0 0 0 0 0 0 0 0 0 0 0
  97020. - 0 0 0 0 0 0 0 0 0 0 0 0
  97021. - 0 0 0 0 0 0 0 0 0 0 0 0
  97022. - 0 0 0 0 0 0 0 0 0 0 0 0
  97023. - 0 0 0 0 0 0 0 0 0 0 0 0
  97024. - 0 0 0 0 0 0 0 0 0 0 0 0
  97025. - 0 0 0 0 0 0 0 0 1 0 0 0
  97026. - 0 0 1 0 0 0 0 0 1 0 0 0
  97027. - 0 0 0 0 0 0 0 0 0 0 0 0
  97028. - 0 0 0 0 0 0 0 0 0 0 0 0
  97029. - 0 0 0 0 0 0 0 0 0 0 0 0
  97030. - 0 0 0 0 0 0 0 0 0 0 0 0
  97031. - 0 0 0 0 0 0 0 0 0 14 14 14
  97032. - 42 42 42 94 94 94 14 14 14 101 101 101
  97033. -128 128 128 2 2 6 18 18 18 116 116 116
  97034. -118 98 46 121 92 8 121 92 8 98 78 10
  97035. -162 162 162 106 106 106 2 2 6 2 2 6
  97036. - 2 2 6 195 195 195 195 195 195 6 6 6
  97037. - 2 2 6 2 2 6 2 2 6 2 2 6
  97038. - 74 74 74 62 62 62 22 22 22 6 6 6
  97039. - 0 0 0 0 0 0 0 0 0 0 0 0
  97040. - 0 0 0 0 0 0 0 0 0 0 0 0
  97041. - 0 0 0 0 0 0 0 0 0 0 0 0
  97042. - 0 0 0 0 0 0 0 0 0 0 0 0
  97043. - 0 0 0 0 0 0 0 0 0 0 0 0
  97044. - 0 0 0 0 0 0 0 0 0 0 0 0
  97045. - 0 0 0 0 0 0 0 0 1 0 0 1
  97046. - 0 0 1 0 0 0 0 0 1 0 0 0
  97047. - 0 0 0 0 0 0 0 0 0 0 0 0
  97048. - 0 0 0 0 0 0 0 0 0 0 0 0
  97049. - 0 0 0 0 0 0 0 0 0 0 0 0
  97050. - 0 0 0 0 0 0 0 0 0 0 0 0
  97051. - 0 0 0 0 0 0 0 0 0 10 10 10
  97052. - 38 38 38 90 90 90 14 14 14 58 58 58
  97053. -210 210 210 26 26 26 54 38 6 154 114 10
  97054. -226 170 11 236 186 11 225 175 15 184 144 12
  97055. -215 174 15 175 146 61 37 26 9 2 2 6
  97056. - 70 70 70 246 246 246 138 138 138 2 2 6
  97057. - 2 2 6 2 2 6 2 2 6 2 2 6
  97058. - 70 70 70 66 66 66 26 26 26 6 6 6
  97059. - 0 0 0 0 0 0 0 0 0 0 0 0
  97060. - 0 0 0 0 0 0 0 0 0 0 0 0
  97061. - 0 0 0 0 0 0 0 0 0 0 0 0
  97062. - 0 0 0 0 0 0 0 0 0 0 0 0
  97063. - 0 0 0 0 0 0 0 0 0 0 0 0
  97064. - 0 0 0 0 0 0 0 0 0 0 0 0
  97065. - 0 0 0 0 0 0 0 0 0 0 0 0
  97066. - 0 0 0 0 0 0 0 0 0 0 0 0
  97067. - 0 0 0 0 0 0 0 0 0 0 0 0
  97068. - 0 0 0 0 0 0 0 0 0 0 0 0
  97069. - 0 0 0 0 0 0 0 0 0 0 0 0
  97070. - 0 0 0 0 0 0 0 0 0 0 0 0
  97071. - 0 0 0 0 0 0 0 0 0 10 10 10
  97072. - 38 38 38 86 86 86 14 14 14 10 10 10
  97073. -195 195 195 188 164 115 192 133 9 225 175 15
  97074. -239 182 13 234 190 10 232 195 16 232 200 30
  97075. -245 207 45 241 208 19 232 195 16 184 144 12
  97076. -218 194 134 211 206 186 42 42 42 2 2 6
  97077. - 2 2 6 2 2 6 2 2 6 2 2 6
  97078. - 50 50 50 74 74 74 30 30 30 6 6 6
  97079. - 0 0 0 0 0 0 0 0 0 0 0 0
  97080. - 0 0 0 0 0 0 0 0 0 0 0 0
  97081. - 0 0 0 0 0 0 0 0 0 0 0 0
  97082. - 0 0 0 0 0 0 0 0 0 0 0 0
  97083. - 0 0 0 0 0 0 0 0 0 0 0 0
  97084. - 0 0 0 0 0 0 0 0 0 0 0 0
  97085. - 0 0 0 0 0 0 0 0 0 0 0 0
  97086. - 0 0 0 0 0 0 0 0 0 0 0 0
  97087. - 0 0 0 0 0 0 0 0 0 0 0 0
  97088. - 0 0 0 0 0 0 0 0 0 0 0 0
  97089. - 0 0 0 0 0 0 0 0 0 0 0 0
  97090. - 0 0 0 0 0 0 0 0 0 0 0 0
  97091. - 0 0 0 0 0 0 0 0 0 10 10 10
  97092. - 34 34 34 86 86 86 14 14 14 2 2 6
  97093. -121 87 25 192 133 9 219 162 10 239 182 13
  97094. -236 186 11 232 195 16 241 208 19 244 214 54
  97095. -246 218 60 246 218 38 246 215 20 241 208 19
  97096. -241 208 19 226 184 13 121 87 25 2 2 6
  97097. - 2 2 6 2 2 6 2 2 6 2 2 6
  97098. - 50 50 50 82 82 82 34 34 34 10 10 10
  97099. - 0 0 0 0 0 0 0 0 0 0 0 0
  97100. - 0 0 0 0 0 0 0 0 0 0 0 0
  97101. - 0 0 0 0 0 0 0 0 0 0 0 0
  97102. - 0 0 0 0 0 0 0 0 0 0 0 0
  97103. - 0 0 0 0 0 0 0 0 0 0 0 0
  97104. - 0 0 0 0 0 0 0 0 0 0 0 0
  97105. - 0 0 0 0 0 0 0 0 0 0 0 0
  97106. - 0 0 0 0 0 0 0 0 0 0 0 0
  97107. - 0 0 0 0 0 0 0 0 0 0 0 0
  97108. - 0 0 0 0 0 0 0 0 0 0 0 0
  97109. - 0 0 0 0 0 0 0 0 0 0 0 0
  97110. - 0 0 0 0 0 0 0 0 0 0 0 0
  97111. - 0 0 0 0 0 0 0 0 0 10 10 10
  97112. - 34 34 34 82 82 82 30 30 30 61 42 6
  97113. -180 123 7 206 145 10 230 174 11 239 182 13
  97114. -234 190 10 238 202 15 241 208 19 246 218 74
  97115. -246 218 38 246 215 20 246 215 20 246 215 20
  97116. -226 184 13 215 174 15 184 144 12 6 6 6
  97117. - 2 2 6 2 2 6 2 2 6 2 2 6
  97118. - 26 26 26 94 94 94 42 42 42 14 14 14
  97119. - 0 0 0 0 0 0 0 0 0 0 0 0
  97120. - 0 0 0 0 0 0 0 0 0 0 0 0
  97121. - 0 0 0 0 0 0 0 0 0 0 0 0
  97122. - 0 0 0 0 0 0 0 0 0 0 0 0
  97123. - 0 0 0 0 0 0 0 0 0 0 0 0
  97124. - 0 0 0 0 0 0 0 0 0 0 0 0
  97125. - 0 0 0 0 0 0 0 0 0 0 0 0
  97126. - 0 0 0 0 0 0 0 0 0 0 0 0
  97127. - 0 0 0 0 0 0 0 0 0 0 0 0
  97128. - 0 0 0 0 0 0 0 0 0 0 0 0
  97129. - 0 0 0 0 0 0 0 0 0 0 0 0
  97130. - 0 0 0 0 0 0 0 0 0 0 0 0
  97131. - 0 0 0 0 0 0 0 0 0 10 10 10
  97132. - 30 30 30 78 78 78 50 50 50 104 69 6
  97133. -192 133 9 216 158 10 236 178 12 236 186 11
  97134. -232 195 16 241 208 19 244 214 54 245 215 43
  97135. -246 215 20 246 215 20 241 208 19 198 155 10
  97136. -200 144 11 216 158 10 156 118 10 2 2 6
  97137. - 2 2 6 2 2 6 2 2 6 2 2 6
  97138. - 6 6 6 90 90 90 54 54 54 18 18 18
  97139. - 6 6 6 0 0 0 0 0 0 0 0 0
  97140. - 0 0 0 0 0 0 0 0 0 0 0 0
  97141. - 0 0 0 0 0 0 0 0 0 0 0 0
  97142. - 0 0 0 0 0 0 0 0 0 0 0 0
  97143. - 0 0 0 0 0 0 0 0 0 0 0 0
  97144. - 0 0 0 0 0 0 0 0 0 0 0 0
  97145. - 0 0 0 0 0 0 0 0 0 0 0 0
  97146. - 0 0 0 0 0 0 0 0 0 0 0 0
  97147. - 0 0 0 0 0 0 0 0 0 0 0 0
  97148. - 0 0 0 0 0 0 0 0 0 0 0 0
  97149. - 0 0 0 0 0 0 0 0 0 0 0 0
  97150. - 0 0 0 0 0 0 0 0 0 0 0 0
  97151. - 0 0 0 0 0 0 0 0 0 10 10 10
  97152. - 30 30 30 78 78 78 46 46 46 22 22 22
  97153. -137 92 6 210 162 10 239 182 13 238 190 10
  97154. -238 202 15 241 208 19 246 215 20 246 215 20
  97155. -241 208 19 203 166 17 185 133 11 210 150 10
  97156. -216 158 10 210 150 10 102 78 10 2 2 6
  97157. - 6 6 6 54 54 54 14 14 14 2 2 6
  97158. - 2 2 6 62 62 62 74 74 74 30 30 30
  97159. - 10 10 10 0 0 0 0 0 0 0 0 0
  97160. - 0 0 0 0 0 0 0 0 0 0 0 0
  97161. - 0 0 0 0 0 0 0 0 0 0 0 0
  97162. - 0 0 0 0 0 0 0 0 0 0 0 0
  97163. - 0 0 0 0 0 0 0 0 0 0 0 0
  97164. - 0 0 0 0 0 0 0 0 0 0 0 0
  97165. - 0 0 0 0 0 0 0 0 0 0 0 0
  97166. - 0 0 0 0 0 0 0 0 0 0 0 0
  97167. - 0 0 0 0 0 0 0 0 0 0 0 0
  97168. - 0 0 0 0 0 0 0 0 0 0 0 0
  97169. - 0 0 0 0 0 0 0 0 0 0 0 0
  97170. - 0 0 0 0 0 0 0 0 0 0 0 0
  97171. - 0 0 0 0 0 0 0 0 0 10 10 10
  97172. - 34 34 34 78 78 78 50 50 50 6 6 6
  97173. - 94 70 30 139 102 15 190 146 13 226 184 13
  97174. -232 200 30 232 195 16 215 174 15 190 146 13
  97175. -168 122 10 192 133 9 210 150 10 213 154 11
  97176. -202 150 34 182 157 106 101 98 89 2 2 6
  97177. - 2 2 6 78 78 78 116 116 116 58 58 58
  97178. - 2 2 6 22 22 22 90 90 90 46 46 46
  97179. - 18 18 18 6 6 6 0 0 0 0 0 0
  97180. - 0 0 0 0 0 0 0 0 0 0 0 0
  97181. - 0 0 0 0 0 0 0 0 0 0 0 0
  97182. - 0 0 0 0 0 0 0 0 0 0 0 0
  97183. - 0 0 0 0 0 0 0 0 0 0 0 0
  97184. - 0 0 0 0 0 0 0 0 0 0 0 0
  97185. - 0 0 0 0 0 0 0 0 0 0 0 0
  97186. - 0 0 0 0 0 0 0 0 0 0 0 0
  97187. - 0 0 0 0 0 0 0 0 0 0 0 0
  97188. - 0 0 0 0 0 0 0 0 0 0 0 0
  97189. - 0 0 0 0 0 0 0 0 0 0 0 0
  97190. - 0 0 0 0 0 0 0 0 0 0 0 0
  97191. - 0 0 0 0 0 0 0 0 0 10 10 10
  97192. - 38 38 38 86 86 86 50 50 50 6 6 6
  97193. -128 128 128 174 154 114 156 107 11 168 122 10
  97194. -198 155 10 184 144 12 197 138 11 200 144 11
  97195. -206 145 10 206 145 10 197 138 11 188 164 115
  97196. -195 195 195 198 198 198 174 174 174 14 14 14
  97197. - 2 2 6 22 22 22 116 116 116 116 116 116
  97198. - 22 22 22 2 2 6 74 74 74 70 70 70
  97199. - 30 30 30 10 10 10 0 0 0 0 0 0
  97200. - 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
  97202. - 0 0 0 0 0 0 0 0 0 0 0 0
  97203. - 0 0 0 0 0 0 0 0 0 0 0 0
  97204. - 0 0 0 0 0 0 0 0 0 0 0 0
  97205. - 0 0 0 0 0 0 0 0 0 0 0 0
  97206. - 0 0 0 0 0 0 0 0 0 0 0 0
  97207. - 0 0 0 0 0 0 0 0 0 0 0 0
  97208. - 0 0 0 0 0 0 0 0 0 0 0 0
  97209. - 0 0 0 0 0 0 0 0 0 0 0 0
  97210. - 0 0 0 0 0 0 0 0 0 0 0 0
  97211. - 0 0 0 0 0 0 6 6 6 18 18 18
  97212. - 50 50 50 101 101 101 26 26 26 10 10 10
  97213. -138 138 138 190 190 190 174 154 114 156 107 11
  97214. -197 138 11 200 144 11 197 138 11 192 133 9
  97215. -180 123 7 190 142 34 190 178 144 187 187 187
  97216. -202 202 202 221 221 221 214 214 214 66 66 66
  97217. - 2 2 6 2 2 6 50 50 50 62 62 62
  97218. - 6 6 6 2 2 6 10 10 10 90 90 90
  97219. - 50 50 50 18 18 18 6 6 6 0 0 0
  97220. - 0 0 0 0 0 0 0 0 0 0 0 0
  97221. - 0 0 0 0 0 0 0 0 0 0 0 0
  97222. - 0 0 0 0 0 0 0 0 0 0 0 0
  97223. - 0 0 0 0 0 0 0 0 0 0 0 0
  97224. - 0 0 0 0 0 0 0 0 0 0 0 0
  97225. - 0 0 0 0 0 0 0 0 0 0 0 0
  97226. - 0 0 0 0 0 0 0 0 0 0 0 0
  97227. - 0 0 0 0 0 0 0 0 0 0 0 0
  97228. - 0 0 0 0 0 0 0 0 0 0 0 0
  97229. - 0 0 0 0 0 0 0 0 0 0 0 0
  97230. - 0 0 0 0 0 0 0 0 0 0 0 0
  97231. - 0 0 0 0 0 0 10 10 10 34 34 34
  97232. - 74 74 74 74 74 74 2 2 6 6 6 6
  97233. -144 144 144 198 198 198 190 190 190 178 166 146
  97234. -154 121 60 156 107 11 156 107 11 168 124 44
  97235. -174 154 114 187 187 187 190 190 190 210 210 210
  97236. -246 246 246 253 253 253 253 253 253 182 182 182
  97237. - 6 6 6 2 2 6 2 2 6 2 2 6
  97238. - 2 2 6 2 2 6 2 2 6 62 62 62
  97239. - 74 74 74 34 34 34 14 14 14 0 0 0
  97240. - 0 0 0 0 0 0 0 0 0 0 0 0
  97241. - 0 0 0 0 0 0 0 0 0 0 0 0
  97242. - 0 0 0 0 0 0 0 0 0 0 0 0
  97243. - 0 0 0 0 0 0 0 0 0 0 0 0
  97244. - 0 0 0 0 0 0 0 0 0 0 0 0
  97245. - 0 0 0 0 0 0 0 0 0 0 0 0
  97246. - 0 0 0 0 0 0 0 0 0 0 0 0
  97247. - 0 0 0 0 0 0 0 0 0 0 0 0
  97248. - 0 0 0 0 0 0 0 0 0 0 0 0
  97249. - 0 0 0 0 0 0 0 0 0 0 0 0
  97250. - 0 0 0 0 0 0 0 0 0 0 0 0
  97251. - 0 0 0 10 10 10 22 22 22 54 54 54
  97252. - 94 94 94 18 18 18 2 2 6 46 46 46
  97253. -234 234 234 221 221 221 190 190 190 190 190 190
  97254. -190 190 190 187 187 187 187 187 187 190 190 190
  97255. -190 190 190 195 195 195 214 214 214 242 242 242
  97256. -253 253 253 253 253 253 253 253 253 253 253 253
  97257. - 82 82 82 2 2 6 2 2 6 2 2 6
  97258. - 2 2 6 2 2 6 2 2 6 14 14 14
  97259. - 86 86 86 54 54 54 22 22 22 6 6 6
  97260. - 0 0 0 0 0 0 0 0 0 0 0 0
  97261. - 0 0 0 0 0 0 0 0 0 0 0 0
  97262. - 0 0 0 0 0 0 0 0 0 0 0 0
  97263. - 0 0 0 0 0 0 0 0 0 0 0 0
  97264. - 0 0 0 0 0 0 0 0 0 0 0 0
  97265. - 0 0 0 0 0 0 0 0 0 0 0 0
  97266. - 0 0 0 0 0 0 0 0 0 0 0 0
  97267. - 0 0 0 0 0 0 0 0 0 0 0 0
  97268. - 0 0 0 0 0 0 0 0 0 0 0 0
  97269. - 0 0 0 0 0 0 0 0 0 0 0 0
  97270. - 0 0 0 0 0 0 0 0 0 0 0 0
  97271. - 6 6 6 18 18 18 46 46 46 90 90 90
  97272. - 46 46 46 18 18 18 6 6 6 182 182 182
  97273. -253 253 253 246 246 246 206 206 206 190 190 190
  97274. -190 190 190 190 190 190 190 190 190 190 190 190
  97275. -206 206 206 231 231 231 250 250 250 253 253 253
  97276. -253 253 253 253 253 253 253 253 253 253 253 253
  97277. -202 202 202 14 14 14 2 2 6 2 2 6
  97278. - 2 2 6 2 2 6 2 2 6 2 2 6
  97279. - 42 42 42 86 86 86 42 42 42 18 18 18
  97280. - 6 6 6 0 0 0 0 0 0 0 0 0
  97281. - 0 0 0 0 0 0 0 0 0 0 0 0
  97282. - 0 0 0 0 0 0 0 0 0 0 0 0
  97283. - 0 0 0 0 0 0 0 0 0 0 0 0
  97284. - 0 0 0 0 0 0 0 0 0 0 0 0
  97285. - 0 0 0 0 0 0 0 0 0 0 0 0
  97286. - 0 0 0 0 0 0 0 0 0 0 0 0
  97287. - 0 0 0 0 0 0 0 0 0 0 0 0
  97288. - 0 0 0 0 0 0 0 0 0 0 0 0
  97289. - 0 0 0 0 0 0 0 0 0 0 0 0
  97290. - 0 0 0 0 0 0 0 0 0 6 6 6
  97291. - 14 14 14 38 38 38 74 74 74 66 66 66
  97292. - 2 2 6 6 6 6 90 90 90 250 250 250
  97293. -253 253 253 253 253 253 238 238 238 198 198 198
  97294. -190 190 190 190 190 190 195 195 195 221 221 221
  97295. -246 246 246 253 253 253 253 253 253 253 253 253
  97296. -253 253 253 253 253 253 253 253 253 253 253 253
  97297. -253 253 253 82 82 82 2 2 6 2 2 6
  97298. - 2 2 6 2 2 6 2 2 6 2 2 6
  97299. - 2 2 6 78 78 78 70 70 70 34 34 34
  97300. - 14 14 14 6 6 6 0 0 0 0 0 0
  97301. - 0 0 0 0 0 0 0 0 0 0 0 0
  97302. - 0 0 0 0 0 0 0 0 0 0 0 0
  97303. - 0 0 0 0 0 0 0 0 0 0 0 0
  97304. - 0 0 0 0 0 0 0 0 0 0 0 0
  97305. - 0 0 0 0 0 0 0 0 0 0 0 0
  97306. - 0 0 0 0 0 0 0 0 0 0 0 0
  97307. - 0 0 0 0 0 0 0 0 0 0 0 0
  97308. - 0 0 0 0 0 0 0 0 0 0 0 0
  97309. - 0 0 0 0 0 0 0 0 0 0 0 0
  97310. - 0 0 0 0 0 0 0 0 0 14 14 14
  97311. - 34 34 34 66 66 66 78 78 78 6 6 6
  97312. - 2 2 6 18 18 18 218 218 218 253 253 253
  97313. -253 253 253 253 253 253 253 253 253 246 246 246
  97314. -226 226 226 231 231 231 246 246 246 253 253 253
  97315. -253 253 253 253 253 253 253 253 253 253 253 253
  97316. -253 253 253 253 253 253 253 253 253 253 253 253
  97317. -253 253 253 178 178 178 2 2 6 2 2 6
  97318. - 2 2 6 2 2 6 2 2 6 2 2 6
  97319. - 2 2 6 18 18 18 90 90 90 62 62 62
  97320. - 30 30 30 10 10 10 0 0 0 0 0 0
  97321. - 0 0 0 0 0 0 0 0 0 0 0 0
  97322. - 0 0 0 0 0 0 0 0 0 0 0 0
  97323. - 0 0 0 0 0 0 0 0 0 0 0 0
  97324. - 0 0 0 0 0 0 0 0 0 0 0 0
  97325. - 0 0 0 0 0 0 0 0 0 0 0 0
  97326. - 0 0 0 0 0 0 0 0 0 0 0 0
  97327. - 0 0 0 0 0 0 0 0 0 0 0 0
  97328. - 0 0 0 0 0 0 0 0 0 0 0 0
  97329. - 0 0 0 0 0 0 0 0 0 0 0 0
  97330. - 0 0 0 0 0 0 10 10 10 26 26 26
  97331. - 58 58 58 90 90 90 18 18 18 2 2 6
  97332. - 2 2 6 110 110 110 253 253 253 253 253 253
  97333. -253 253 253 253 253 253 253 253 253 253 253 253
  97334. -250 250 250 253 253 253 253 253 253 253 253 253
  97335. -253 253 253 253 253 253 253 253 253 253 253 253
  97336. -253 253 253 253 253 253 253 253 253 253 253 253
  97337. -253 253 253 231 231 231 18 18 18 2 2 6
  97338. - 2 2 6 2 2 6 2 2 6 2 2 6
  97339. - 2 2 6 2 2 6 18 18 18 94 94 94
  97340. - 54 54 54 26 26 26 10 10 10 0 0 0
  97341. - 0 0 0 0 0 0 0 0 0 0 0 0
  97342. - 0 0 0 0 0 0 0 0 0 0 0 0
  97343. - 0 0 0 0 0 0 0 0 0 0 0 0
  97344. - 0 0 0 0 0 0 0 0 0 0 0 0
  97345. - 0 0 0 0 0 0 0 0 0 0 0 0
  97346. - 0 0 0 0 0 0 0 0 0 0 0 0
  97347. - 0 0 0 0 0 0 0 0 0 0 0 0
  97348. - 0 0 0 0 0 0 0 0 0 0 0 0
  97349. - 0 0 0 0 0 0 0 0 0 0 0 0
  97350. - 0 0 0 6 6 6 22 22 22 50 50 50
  97351. - 90 90 90 26 26 26 2 2 6 2 2 6
  97352. - 14 14 14 195 195 195 250 250 250 253 253 253
  97353. -253 253 253 253 253 253 253 253 253 253 253 253
  97354. -253 253 253 253 253 253 253 253 253 253 253 253
  97355. -253 253 253 253 253 253 253 253 253 253 253 253
  97356. -253 253 253 253 253 253 253 253 253 253 253 253
  97357. -250 250 250 242 242 242 54 54 54 2 2 6
  97358. - 2 2 6 2 2 6 2 2 6 2 2 6
  97359. - 2 2 6 2 2 6 2 2 6 38 38 38
  97360. - 86 86 86 50 50 50 22 22 22 6 6 6
  97361. - 0 0 0 0 0 0 0 0 0 0 0 0
  97362. - 0 0 0 0 0 0 0 0 0 0 0 0
  97363. - 0 0 0 0 0 0 0 0 0 0 0 0
  97364. - 0 0 0 0 0 0 0 0 0 0 0 0
  97365. - 0 0 0 0 0 0 0 0 0 0 0 0
  97366. - 0 0 0 0 0 0 0 0 0 0 0 0
  97367. - 0 0 0 0 0 0 0 0 0 0 0 0
  97368. - 0 0 0 0 0 0 0 0 0 0 0 0
  97369. - 0 0 0 0 0 0 0 0 0 0 0 0
  97370. - 6 6 6 14 14 14 38 38 38 82 82 82
  97371. - 34 34 34 2 2 6 2 2 6 2 2 6
  97372. - 42 42 42 195 195 195 246 246 246 253 253 253
  97373. -253 253 253 253 253 253 253 253 253 250 250 250
  97374. -242 242 242 242 242 242 250 250 250 253 253 253
  97375. -253 253 253 253 253 253 253 253 253 253 253 253
  97376. -253 253 253 250 250 250 246 246 246 238 238 238
  97377. -226 226 226 231 231 231 101 101 101 6 6 6
  97378. - 2 2 6 2 2 6 2 2 6 2 2 6
  97379. - 2 2 6 2 2 6 2 2 6 2 2 6
  97380. - 38 38 38 82 82 82 42 42 42 14 14 14
  97381. - 6 6 6 0 0 0 0 0 0 0 0 0
  97382. - 0 0 0 0 0 0 0 0 0 0 0 0
  97383. - 0 0 0 0 0 0 0 0 0 0 0 0
  97384. - 0 0 0 0 0 0 0 0 0 0 0 0
  97385. - 0 0 0 0 0 0 0 0 0 0 0 0
  97386. - 0 0 0 0 0 0 0 0 0 0 0 0
  97387. - 0 0 0 0 0 0 0 0 0 0 0 0
  97388. - 0 0 0 0 0 0 0 0 0 0 0 0
  97389. - 0 0 0 0 0 0 0 0 0 0 0 0
  97390. - 10 10 10 26 26 26 62 62 62 66 66 66
  97391. - 2 2 6 2 2 6 2 2 6 6 6 6
  97392. - 70 70 70 170 170 170 206 206 206 234 234 234
  97393. -246 246 246 250 250 250 250 250 250 238 238 238
  97394. -226 226 226 231 231 231 238 238 238 250 250 250
  97395. -250 250 250 250 250 250 246 246 246 231 231 231
  97396. -214 214 214 206 206 206 202 202 202 202 202 202
  97397. -198 198 198 202 202 202 182 182 182 18 18 18
  97398. - 2 2 6 2 2 6 2 2 6 2 2 6
  97399. - 2 2 6 2 2 6 2 2 6 2 2 6
  97400. - 2 2 6 62 62 62 66 66 66 30 30 30
  97401. - 10 10 10 0 0 0 0 0 0 0 0 0
  97402. - 0 0 0 0 0 0 0 0 0 0 0 0
  97403. - 0 0 0 0 0 0 0 0 0 0 0 0
  97404. - 0 0 0 0 0 0 0 0 0 0 0 0
  97405. - 0 0 0 0 0 0 0 0 0 0 0 0
  97406. - 0 0 0 0 0 0 0 0 0 0 0 0
  97407. - 0 0 0 0 0 0 0 0 0 0 0 0
  97408. - 0 0 0 0 0 0 0 0 0 0 0 0
  97409. - 0 0 0 0 0 0 0 0 0 0 0 0
  97410. - 14 14 14 42 42 42 82 82 82 18 18 18
  97411. - 2 2 6 2 2 6 2 2 6 10 10 10
  97412. - 94 94 94 182 182 182 218 218 218 242 242 242
  97413. -250 250 250 253 253 253 253 253 253 250 250 250
  97414. -234 234 234 253 253 253 253 253 253 253 253 253
  97415. -253 253 253 253 253 253 253 253 253 246 246 246
  97416. -238 238 238 226 226 226 210 210 210 202 202 202
  97417. -195 195 195 195 195 195 210 210 210 158 158 158
  97418. - 6 6 6 14 14 14 50 50 50 14 14 14
  97419. - 2 2 6 2 2 6 2 2 6 2 2 6
  97420. - 2 2 6 6 6 6 86 86 86 46 46 46
  97421. - 18 18 18 6 6 6 0 0 0 0 0 0
  97422. - 0 0 0 0 0 0 0 0 0 0 0 0
  97423. - 0 0 0 0 0 0 0 0 0 0 0 0
  97424. - 0 0 0 0 0 0 0 0 0 0 0 0
  97425. - 0 0 0 0 0 0 0 0 0 0 0 0
  97426. - 0 0 0 0 0 0 0 0 0 0 0 0
  97427. - 0 0 0 0 0 0 0 0 0 0 0 0
  97428. - 0 0 0 0 0 0 0 0 0 0 0 0
  97429. - 0 0 0 0 0 0 0 0 0 6 6 6
  97430. - 22 22 22 54 54 54 70 70 70 2 2 6
  97431. - 2 2 6 10 10 10 2 2 6 22 22 22
  97432. -166 166 166 231 231 231 250 250 250 253 253 253
  97433. -253 253 253 253 253 253 253 253 253 250 250 250
  97434. -242 242 242 253 253 253 253 253 253 253 253 253
  97435. -253 253 253 253 253 253 253 253 253 253 253 253
  97436. -253 253 253 253 253 253 253 253 253 246 246 246
  97437. -231 231 231 206 206 206 198 198 198 226 226 226
  97438. - 94 94 94 2 2 6 6 6 6 38 38 38
  97439. - 30 30 30 2 2 6 2 2 6 2 2 6
  97440. - 2 2 6 2 2 6 62 62 62 66 66 66
  97441. - 26 26 26 10 10 10 0 0 0 0 0 0
  97442. - 0 0 0 0 0 0 0 0 0 0 0 0
  97443. - 0 0 0 0 0 0 0 0 0 0 0 0
  97444. - 0 0 0 0 0 0 0 0 0 0 0 0
  97445. - 0 0 0 0 0 0 0 0 0 0 0 0
  97446. - 0 0 0 0 0 0 0 0 0 0 0 0
  97447. - 0 0 0 0 0 0 0 0 0 0 0 0
  97448. - 0 0 0 0 0 0 0 0 0 0 0 0
  97449. - 0 0 0 0 0 0 0 0 0 10 10 10
  97450. - 30 30 30 74 74 74 50 50 50 2 2 6
  97451. - 26 26 26 26 26 26 2 2 6 106 106 106
  97452. -238 238 238 253 253 253 253 253 253 253 253 253
  97453. -253 253 253 253 253 253 253 253 253 253 253 253
  97454. -253 253 253 253 253 253 253 253 253 253 253 253
  97455. -253 253 253 253 253 253 253 253 253 253 253 253
  97456. -253 253 253 253 253 253 253 253 253 253 253 253
  97457. -253 253 253 246 246 246 218 218 218 202 202 202
  97458. -210 210 210 14 14 14 2 2 6 2 2 6
  97459. - 30 30 30 22 22 22 2 2 6 2 2 6
  97460. - 2 2 6 2 2 6 18 18 18 86 86 86
  97461. - 42 42 42 14 14 14 0 0 0 0 0 0
  97462. - 0 0 0 0 0 0 0 0 0 0 0 0
  97463. - 0 0 0 0 0 0 0 0 0 0 0 0
  97464. - 0 0 0 0 0 0 0 0 0 0 0 0
  97465. - 0 0 0 0 0 0 0 0 0 0 0 0
  97466. - 0 0 0 0 0 0 0 0 0 0 0 0
  97467. - 0 0 0 0 0 0 0 0 0 0 0 0
  97468. - 0 0 0 0 0 0 0 0 0 0 0 0
  97469. - 0 0 0 0 0 0 0 0 0 14 14 14
  97470. - 42 42 42 90 90 90 22 22 22 2 2 6
  97471. - 42 42 42 2 2 6 18 18 18 218 218 218
  97472. -253 253 253 253 253 253 253 253 253 253 253 253
  97473. -253 253 253 253 253 253 253 253 253 253 253 253
  97474. -253 253 253 253 253 253 253 253 253 253 253 253
  97475. -253 253 253 253 253 253 253 253 253 253 253 253
  97476. -253 253 253 253 253 253 253 253 253 253 253 253
  97477. -253 253 253 253 253 253 250 250 250 221 221 221
  97478. -218 218 218 101 101 101 2 2 6 14 14 14
  97479. - 18 18 18 38 38 38 10 10 10 2 2 6
  97480. - 2 2 6 2 2 6 2 2 6 78 78 78
  97481. - 58 58 58 22 22 22 6 6 6 0 0 0
  97482. - 0 0 0 0 0 0 0 0 0 0 0 0
  97483. - 0 0 0 0 0 0 0 0 0 0 0 0
  97484. - 0 0 0 0 0 0 0 0 0 0 0 0
  97485. - 0 0 0 0 0 0 0 0 0 0 0 0
  97486. - 0 0 0 0 0 0 0 0 0 0 0 0
  97487. - 0 0 0 0 0 0 0 0 0 0 0 0
  97488. - 0 0 0 0 0 0 0 0 0 0 0 0
  97489. - 0 0 0 0 0 0 6 6 6 18 18 18
  97490. - 54 54 54 82 82 82 2 2 6 26 26 26
  97491. - 22 22 22 2 2 6 123 123 123 253 253 253
  97492. -253 253 253 253 253 253 253 253 253 253 253 253
  97493. -253 253 253 253 253 253 253 253 253 253 253 253
  97494. -253 253 253 253 253 253 253 253 253 253 253 253
  97495. -253 253 253 253 253 253 253 253 253 253 253 253
  97496. -253 253 253 253 253 253 253 253 253 253 253 253
  97497. -253 253 253 253 253 253 253 253 253 250 250 250
  97498. -238 238 238 198 198 198 6 6 6 38 38 38
  97499. - 58 58 58 26 26 26 38 38 38 2 2 6
  97500. - 2 2 6 2 2 6 2 2 6 46 46 46
  97501. - 78 78 78 30 30 30 10 10 10 0 0 0
  97502. - 0 0 0 0 0 0 0 0 0 0 0 0
  97503. - 0 0 0 0 0 0 0 0 0 0 0 0
  97504. - 0 0 0 0 0 0 0 0 0 0 0 0
  97505. - 0 0 0 0 0 0 0 0 0 0 0 0
  97506. - 0 0 0 0 0 0 0 0 0 0 0 0
  97507. - 0 0 0 0 0 0 0 0 0 0 0 0
  97508. - 0 0 0 0 0 0 0 0 0 0 0 0
  97509. - 0 0 0 0 0 0 10 10 10 30 30 30
  97510. - 74 74 74 58 58 58 2 2 6 42 42 42
  97511. - 2 2 6 22 22 22 231 231 231 253 253 253
  97512. -253 253 253 253 253 253 253 253 253 253 253 253
  97513. -253 253 253 253 253 253 253 253 253 250 250 250
  97514. -253 253 253 253 253 253 253 253 253 253 253 253
  97515. -253 253 253 253 253 253 253 253 253 253 253 253
  97516. -253 253 253 253 253 253 253 253 253 253 253 253
  97517. -253 253 253 253 253 253 253 253 253 253 253 253
  97518. -253 253 253 246 246 246 46 46 46 38 38 38
  97519. - 42 42 42 14 14 14 38 38 38 14 14 14
  97520. - 2 2 6 2 2 6 2 2 6 6 6 6
  97521. - 86 86 86 46 46 46 14 14 14 0 0 0
  97522. - 0 0 0 0 0 0 0 0 0 0 0 0
  97523. - 0 0 0 0 0 0 0 0 0 0 0 0
  97524. - 0 0 0 0 0 0 0 0 0 0 0 0
  97525. - 0 0 0 0 0 0 0 0 0 0 0 0
  97526. - 0 0 0 0 0 0 0 0 0 0 0 0
  97527. - 0 0 0 0 0 0 0 0 0 0 0 0
  97528. - 0 0 0 0 0 0 0 0 0 0 0 0
  97529. - 0 0 0 6 6 6 14 14 14 42 42 42
  97530. - 90 90 90 18 18 18 18 18 18 26 26 26
  97531. - 2 2 6 116 116 116 253 253 253 253 253 253
  97532. -253 253 253 253 253 253 253 253 253 253 253 253
  97533. -253 253 253 253 253 253 250 250 250 238 238 238
  97534. -253 253 253 253 253 253 253 253 253 253 253 253
  97535. -253 253 253 253 253 253 253 253 253 253 253 253
  97536. -253 253 253 253 253 253 253 253 253 253 253 253
  97537. -253 253 253 253 253 253 253 253 253 253 253 253
  97538. -253 253 253 253 253 253 94 94 94 6 6 6
  97539. - 2 2 6 2 2 6 10 10 10 34 34 34
  97540. - 2 2 6 2 2 6 2 2 6 2 2 6
  97541. - 74 74 74 58 58 58 22 22 22 6 6 6
  97542. - 0 0 0 0 0 0 0 0 0 0 0 0
  97543. - 0 0 0 0 0 0 0 0 0 0 0 0
  97544. - 0 0 0 0 0 0 0 0 0 0 0 0
  97545. - 0 0 0 0 0 0 0 0 0 0 0 0
  97546. - 0 0 0 0 0 0 0 0 0 0 0 0
  97547. - 0 0 0 0 0 0 0 0 0 0 0 0
  97548. - 0 0 0 0 0 0 0 0 0 0 0 0
  97549. - 0 0 0 10 10 10 26 26 26 66 66 66
  97550. - 82 82 82 2 2 6 38 38 38 6 6 6
  97551. - 14 14 14 210 210 210 253 253 253 253 253 253
  97552. -253 253 253 253 253 253 253 253 253 253 253 253
  97553. -253 253 253 253 253 253 246 246 246 242 242 242
  97554. -253 253 253 253 253 253 253 253 253 253 253 253
  97555. -253 253 253 253 253 253 253 253 253 253 253 253
  97556. -253 253 253 253 253 253 253 253 253 253 253 253
  97557. -253 253 253 253 253 253 253 253 253 253 253 253
  97558. -253 253 253 253 253 253 144 144 144 2 2 6
  97559. - 2 2 6 2 2 6 2 2 6 46 46 46
  97560. - 2 2 6 2 2 6 2 2 6 2 2 6
  97561. - 42 42 42 74 74 74 30 30 30 10 10 10
  97562. - 0 0 0 0 0 0 0 0 0 0 0 0
  97563. - 0 0 0 0 0 0 0 0 0 0 0 0
  97564. - 0 0 0 0 0 0 0 0 0 0 0 0
  97565. - 0 0 0 0 0 0 0 0 0 0 0 0
  97566. - 0 0 0 0 0 0 0 0 0 0 0 0
  97567. - 0 0 0 0 0 0 0 0 0 0 0 0
  97568. - 0 0 0 0 0 0 0 0 0 0 0 0
  97569. - 6 6 6 14 14 14 42 42 42 90 90 90
  97570. - 26 26 26 6 6 6 42 42 42 2 2 6
  97571. - 74 74 74 250 250 250 253 253 253 253 253 253
  97572. -253 253 253 253 253 253 253 253 253 253 253 253
  97573. -253 253 253 253 253 253 242 242 242 242 242 242
  97574. -253 253 253 253 253 253 253 253 253 253 253 253
  97575. -253 253 253 253 253 253 253 253 253 253 253 253
  97576. -253 253 253 253 253 253 253 253 253 253 253 253
  97577. -253 253 253 253 253 253 253 253 253 253 253 253
  97578. -253 253 253 253 253 253 182 182 182 2 2 6
  97579. - 2 2 6 2 2 6 2 2 6 46 46 46
  97580. - 2 2 6 2 2 6 2 2 6 2 2 6
  97581. - 10 10 10 86 86 86 38 38 38 10 10 10
  97582. - 0 0 0 0 0 0 0 0 0 0 0 0
  97583. - 0 0 0 0 0 0 0 0 0 0 0 0
  97584. - 0 0 0 0 0 0 0 0 0 0 0 0
  97585. - 0 0 0 0 0 0 0 0 0 0 0 0
  97586. - 0 0 0 0 0 0 0 0 0 0 0 0
  97587. - 0 0 0 0 0 0 0 0 0 0 0 0
  97588. - 0 0 0 0 0 0 0 0 0 0 0 0
  97589. - 10 10 10 26 26 26 66 66 66 82 82 82
  97590. - 2 2 6 22 22 22 18 18 18 2 2 6
  97591. -149 149 149 253 253 253 253 253 253 253 253 253
  97592. -253 253 253 253 253 253 253 253 253 253 253 253
  97593. -253 253 253 253 253 253 234 234 234 242 242 242
  97594. -253 253 253 253 253 253 253 253 253 253 253 253
  97595. -253 253 253 253 253 253 253 253 253 253 253 253
  97596. -253 253 253 253 253 253 253 253 253 253 253 253
  97597. -253 253 253 253 253 253 253 253 253 253 253 253
  97598. -253 253 253 253 253 253 206 206 206 2 2 6
  97599. - 2 2 6 2 2 6 2 2 6 38 38 38
  97600. - 2 2 6 2 2 6 2 2 6 2 2 6
  97601. - 6 6 6 86 86 86 46 46 46 14 14 14
  97602. - 0 0 0 0 0 0 0 0 0 0 0 0
  97603. - 0 0 0 0 0 0 0 0 0 0 0 0
  97604. - 0 0 0 0 0 0 0 0 0 0 0 0
  97605. - 0 0 0 0 0 0 0 0 0 0 0 0
  97606. - 0 0 0 0 0 0 0 0 0 0 0 0
  97607. - 0 0 0 0 0 0 0 0 0 0 0 0
  97608. - 0 0 0 0 0 0 0 0 0 6 6 6
  97609. - 18 18 18 46 46 46 86 86 86 18 18 18
  97610. - 2 2 6 34 34 34 10 10 10 6 6 6
  97611. -210 210 210 253 253 253 253 253 253 253 253 253
  97612. -253 253 253 253 253 253 253 253 253 253 253 253
  97613. -253 253 253 253 253 253 234 234 234 242 242 242
  97614. -253 253 253 253 253 253 253 253 253 253 253 253
  97615. -253 253 253 253 253 253 253 253 253 253 253 253
  97616. -253 253 253 253 253 253 253 253 253 253 253 253
  97617. -253 253 253 253 253 253 253 253 253 253 253 253
  97618. -253 253 253 253 253 253 221 221 221 6 6 6
  97619. - 2 2 6 2 2 6 6 6 6 30 30 30
  97620. - 2 2 6 2 2 6 2 2 6 2 2 6
  97621. - 2 2 6 82 82 82 54 54 54 18 18 18
  97622. - 6 6 6 0 0 0 0 0 0 0 0 0
  97623. - 0 0 0 0 0 0 0 0 0 0 0 0
  97624. - 0 0 0 0 0 0 0 0 0 0 0 0
  97625. - 0 0 0 0 0 0 0 0 0 0 0 0
  97626. - 0 0 0 0 0 0 0 0 0 0 0 0
  97627. - 0 0 0 0 0 0 0 0 0 0 0 0
  97628. - 0 0 0 0 0 0 0 0 0 10 10 10
  97629. - 26 26 26 66 66 66 62 62 62 2 2 6
  97630. - 2 2 6 38 38 38 10 10 10 26 26 26
  97631. -238 238 238 253 253 253 253 253 253 253 253 253
  97632. -253 253 253 253 253 253 253 253 253 253 253 253
  97633. -253 253 253 253 253 253 231 231 231 238 238 238
  97634. -253 253 253 253 253 253 253 253 253 253 253 253
  97635. -253 253 253 253 253 253 253 253 253 253 253 253
  97636. -253 253 253 253 253 253 253 253 253 253 253 253
  97637. -253 253 253 253 253 253 253 253 253 253 253 253
  97638. -253 253 253 253 253 253 231 231 231 6 6 6
  97639. - 2 2 6 2 2 6 10 10 10 30 30 30
  97640. - 2 2 6 2 2 6 2 2 6 2 2 6
  97641. - 2 2 6 66 66 66 58 58 58 22 22 22
  97642. - 6 6 6 0 0 0 0 0 0 0 0 0
  97643. - 0 0 0 0 0 0 0 0 0 0 0 0
  97644. - 0 0 0 0 0 0 0 0 0 0 0 0
  97645. - 0 0 0 0 0 0 0 0 0 0 0 0
  97646. - 0 0 0 0 0 0 0 0 0 0 0 0
  97647. - 0 0 0 0 0 0 0 0 0 0 0 0
  97648. - 0 0 0 0 0 0 0 0 0 10 10 10
  97649. - 38 38 38 78 78 78 6 6 6 2 2 6
  97650. - 2 2 6 46 46 46 14 14 14 42 42 42
  97651. -246 246 246 253 253 253 253 253 253 253 253 253
  97652. -253 253 253 253 253 253 253 253 253 253 253 253
  97653. -253 253 253 253 253 253 231 231 231 242 242 242
  97654. -253 253 253 253 253 253 253 253 253 253 253 253
  97655. -253 253 253 253 253 253 253 253 253 253 253 253
  97656. -253 253 253 253 253 253 253 253 253 253 253 253
  97657. -253 253 253 253 253 253 253 253 253 253 253 253
  97658. -253 253 253 253 253 253 234 234 234 10 10 10
  97659. - 2 2 6 2 2 6 22 22 22 14 14 14
  97660. - 2 2 6 2 2 6 2 2 6 2 2 6
  97661. - 2 2 6 66 66 66 62 62 62 22 22 22
  97662. - 6 6 6 0 0 0 0 0 0 0 0 0
  97663. - 0 0 0 0 0 0 0 0 0 0 0 0
  97664. - 0 0 0 0 0 0 0 0 0 0 0 0
  97665. - 0 0 0 0 0 0 0 0 0 0 0 0
  97666. - 0 0 0 0 0 0 0 0 0 0 0 0
  97667. - 0 0 0 0 0 0 0 0 0 0 0 0
  97668. - 0 0 0 0 0 0 6 6 6 18 18 18
  97669. - 50 50 50 74 74 74 2 2 6 2 2 6
  97670. - 14 14 14 70 70 70 34 34 34 62 62 62
  97671. -250 250 250 253 253 253 253 253 253 253 253 253
  97672. -253 253 253 253 253 253 253 253 253 253 253 253
  97673. -253 253 253 253 253 253 231 231 231 246 246 246
  97674. -253 253 253 253 253 253 253 253 253 253 253 253
  97675. -253 253 253 253 253 253 253 253 253 253 253 253
  97676. -253 253 253 253 253 253 253 253 253 253 253 253
  97677. -253 253 253 253 253 253 253 253 253 253 253 253
  97678. -253 253 253 253 253 253 234 234 234 14 14 14
  97679. - 2 2 6 2 2 6 30 30 30 2 2 6
  97680. - 2 2 6 2 2 6 2 2 6 2 2 6
  97681. - 2 2 6 66 66 66 62 62 62 22 22 22
  97682. - 6 6 6 0 0 0 0 0 0 0 0 0
  97683. - 0 0 0 0 0 0 0 0 0 0 0 0
  97684. - 0 0 0 0 0 0 0 0 0 0 0 0
  97685. - 0 0 0 0 0 0 0 0 0 0 0 0
  97686. - 0 0 0 0 0 0 0 0 0 0 0 0
  97687. - 0 0 0 0 0 0 0 0 0 0 0 0
  97688. - 0 0 0 0 0 0 6 6 6 18 18 18
  97689. - 54 54 54 62 62 62 2 2 6 2 2 6
  97690. - 2 2 6 30 30 30 46 46 46 70 70 70
  97691. -250 250 250 253 253 253 253 253 253 253 253 253
  97692. -253 253 253 253 253 253 253 253 253 253 253 253
  97693. -253 253 253 253 253 253 231 231 231 246 246 246
  97694. -253 253 253 253 253 253 253 253 253 253 253 253
  97695. -253 253 253 253 253 253 253 253 253 253 253 253
  97696. -253 253 253 253 253 253 253 253 253 253 253 253
  97697. -253 253 253 253 253 253 253 253 253 253 253 253
  97698. -253 253 253 253 253 253 226 226 226 10 10 10
  97699. - 2 2 6 6 6 6 30 30 30 2 2 6
  97700. - 2 2 6 2 2 6 2 2 6 2 2 6
  97701. - 2 2 6 66 66 66 58 58 58 22 22 22
  97702. - 6 6 6 0 0 0 0 0 0 0 0 0
  97703. - 0 0 0 0 0 0 0 0 0 0 0 0
  97704. - 0 0 0 0 0 0 0 0 0 0 0 0
  97705. - 0 0 0 0 0 0 0 0 0 0 0 0
  97706. - 0 0 0 0 0 0 0 0 0 0 0 0
  97707. - 0 0 0 0 0 0 0 0 0 0 0 0
  97708. - 0 0 0 0 0 0 6 6 6 22 22 22
  97709. - 58 58 58 62 62 62 2 2 6 2 2 6
  97710. - 2 2 6 2 2 6 30 30 30 78 78 78
  97711. -250 250 250 253 253 253 253 253 253 253 253 253
  97712. -253 253 253 253 253 253 253 253 253 253 253 253
  97713. -253 253 253 253 253 253 231 231 231 246 246 246
  97714. -253 253 253 253 253 253 253 253 253 253 253 253
  97715. -253 253 253 253 253 253 253 253 253 253 253 253
  97716. -253 253 253 253 253 253 253 253 253 253 253 253
  97717. -253 253 253 253 253 253 253 253 253 253 253 253
  97718. -253 253 253 253 253 253 206 206 206 2 2 6
  97719. - 22 22 22 34 34 34 18 14 6 22 22 22
  97720. - 26 26 26 18 18 18 6 6 6 2 2 6
  97721. - 2 2 6 82 82 82 54 54 54 18 18 18
  97722. - 6 6 6 0 0 0 0 0 0 0 0 0
  97723. - 0 0 0 0 0 0 0 0 0 0 0 0
  97724. - 0 0 0 0 0 0 0 0 0 0 0 0
  97725. - 0 0 0 0 0 0 0 0 0 0 0 0
  97726. - 0 0 0 0 0 0 0 0 0 0 0 0
  97727. - 0 0 0 0 0 0 0 0 0 0 0 0
  97728. - 0 0 0 0 0 0 6 6 6 26 26 26
  97729. - 62 62 62 106 106 106 74 54 14 185 133 11
  97730. -210 162 10 121 92 8 6 6 6 62 62 62
  97731. -238 238 238 253 253 253 253 253 253 253 253 253
  97732. -253 253 253 253 253 253 253 253 253 253 253 253
  97733. -253 253 253 253 253 253 231 231 231 246 246 246
  97734. -253 253 253 253 253 253 253 253 253 253 253 253
  97735. -253 253 253 253 253 253 253 253 253 253 253 253
  97736. -253 253 253 253 253 253 253 253 253 253 253 253
  97737. -253 253 253 253 253 253 253 253 253 253 253 253
  97738. -253 253 253 253 253 253 158 158 158 18 18 18
  97739. - 14 14 14 2 2 6 2 2 6 2 2 6
  97740. - 6 6 6 18 18 18 66 66 66 38 38 38
  97741. - 6 6 6 94 94 94 50 50 50 18 18 18
  97742. - 6 6 6 0 0 0 0 0 0 0 0 0
  97743. - 0 0 0 0 0 0 0 0 0 0 0 0
  97744. - 0 0 0 0 0 0 0 0 0 0 0 0
  97745. - 0 0 0 0 0 0 0 0 0 0 0 0
  97746. - 0 0 0 0 0 0 0 0 0 0 0 0
  97747. - 0 0 0 0 0 0 0 0 0 6 6 6
  97748. - 10 10 10 10 10 10 18 18 18 38 38 38
  97749. - 78 78 78 142 134 106 216 158 10 242 186 14
  97750. -246 190 14 246 190 14 156 118 10 10 10 10
  97751. - 90 90 90 238 238 238 253 253 253 253 253 253
  97752. -253 253 253 253 253 253 253 253 253 253 253 253
  97753. -253 253 253 253 253 253 231 231 231 250 250 250
  97754. -253 253 253 253 253 253 253 253 253 253 253 253
  97755. -253 253 253 253 253 253 253 253 253 253 253 253
  97756. -253 253 253 253 253 253 253 253 253 253 253 253
  97757. -253 253 253 253 253 253 253 253 253 246 230 190
  97758. -238 204 91 238 204 91 181 142 44 37 26 9
  97759. - 2 2 6 2 2 6 2 2 6 2 2 6
  97760. - 2 2 6 2 2 6 38 38 38 46 46 46
  97761. - 26 26 26 106 106 106 54 54 54 18 18 18
  97762. - 6 6 6 0 0 0 0 0 0 0 0 0
  97763. - 0 0 0 0 0 0 0 0 0 0 0 0
  97764. - 0 0 0 0 0 0 0 0 0 0 0 0
  97765. - 0 0 0 0 0 0 0 0 0 0 0 0
  97766. - 0 0 0 0 0 0 0 0 0 0 0 0
  97767. - 0 0 0 6 6 6 14 14 14 22 22 22
  97768. - 30 30 30 38 38 38 50 50 50 70 70 70
  97769. -106 106 106 190 142 34 226 170 11 242 186 14
  97770. -246 190 14 246 190 14 246 190 14 154 114 10
  97771. - 6 6 6 74 74 74 226 226 226 253 253 253
  97772. -253 253 253 253 253 253 253 253 253 253 253 253
  97773. -253 253 253 253 253 253 231 231 231 250 250 250
  97774. -253 253 253 253 253 253 253 253 253 253 253 253
  97775. -253 253 253 253 253 253 253 253 253 253 253 253
  97776. -253 253 253 253 253 253 253 253 253 253 253 253
  97777. -253 253 253 253 253 253 253 253 253 228 184 62
  97778. -241 196 14 241 208 19 232 195 16 38 30 10
  97779. - 2 2 6 2 2 6 2 2 6 2 2 6
  97780. - 2 2 6 6 6 6 30 30 30 26 26 26
  97781. -203 166 17 154 142 90 66 66 66 26 26 26
  97782. - 6 6 6 0 0 0 0 0 0 0 0 0
  97783. - 0 0 0 0 0 0 0 0 0 0 0 0
  97784. - 0 0 0 0 0 0 0 0 0 0 0 0
  97785. - 0 0 0 0 0 0 0 0 0 0 0 0
  97786. - 0 0 0 0 0 0 0 0 0 0 0 0
  97787. - 6 6 6 18 18 18 38 38 38 58 58 58
  97788. - 78 78 78 86 86 86 101 101 101 123 123 123
  97789. -175 146 61 210 150 10 234 174 13 246 186 14
  97790. -246 190 14 246 190 14 246 190 14 238 190 10
  97791. -102 78 10 2 2 6 46 46 46 198 198 198
  97792. -253 253 253 253 253 253 253 253 253 253 253 253
  97793. -253 253 253 253 253 253 234 234 234 242 242 242
  97794. -253 253 253 253 253 253 253 253 253 253 253 253
  97795. -253 253 253 253 253 253 253 253 253 253 253 253
  97796. -253 253 253 253 253 253 253 253 253 253 253 253
  97797. -253 253 253 253 253 253 253 253 253 224 178 62
  97798. -242 186 14 241 196 14 210 166 10 22 18 6
  97799. - 2 2 6 2 2 6 2 2 6 2 2 6
  97800. - 2 2 6 2 2 6 6 6 6 121 92 8
  97801. -238 202 15 232 195 16 82 82 82 34 34 34
  97802. - 10 10 10 0 0 0 0 0 0 0 0 0
  97803. - 0 0 0 0 0 0 0 0 0 0 0 0
  97804. - 0 0 0 0 0 0 0 0 0 0 0 0
  97805. - 0 0 0 0 0 0 0 0 0 0 0 0
  97806. - 0 0 0 0 0 0 0 0 0 0 0 0
  97807. - 14 14 14 38 38 38 70 70 70 154 122 46
  97808. -190 142 34 200 144 11 197 138 11 197 138 11
  97809. -213 154 11 226 170 11 242 186 14 246 190 14
  97810. -246 190 14 246 190 14 246 190 14 246 190 14
  97811. -225 175 15 46 32 6 2 2 6 22 22 22
  97812. -158 158 158 250 250 250 253 253 253 253 253 253
  97813. -253 253 253 253 253 253 253 253 253 253 253 253
  97814. -253 253 253 253 253 253 253 253 253 253 253 253
  97815. -253 253 253 253 253 253 253 253 253 253 253 253
  97816. -253 253 253 253 253 253 253 253 253 253 253 253
  97817. -253 253 253 250 250 250 242 242 242 224 178 62
  97818. -239 182 13 236 186 11 213 154 11 46 32 6
  97819. - 2 2 6 2 2 6 2 2 6 2 2 6
  97820. - 2 2 6 2 2 6 61 42 6 225 175 15
  97821. -238 190 10 236 186 11 112 100 78 42 42 42
  97822. - 14 14 14 0 0 0 0 0 0 0 0 0
  97823. - 0 0 0 0 0 0 0 0 0 0 0 0
  97824. - 0 0 0 0 0 0 0 0 0 0 0 0
  97825. - 0 0 0 0 0 0 0 0 0 0 0 0
  97826. - 0 0 0 0 0 0 0 0 0 6 6 6
  97827. - 22 22 22 54 54 54 154 122 46 213 154 11
  97828. -226 170 11 230 174 11 226 170 11 226 170 11
  97829. -236 178 12 242 186 14 246 190 14 246 190 14
  97830. -246 190 14 246 190 14 246 190 14 246 190 14
  97831. -241 196 14 184 144 12 10 10 10 2 2 6
  97832. - 6 6 6 116 116 116 242 242 242 253 253 253
  97833. -253 253 253 253 253 253 253 253 253 253 253 253
  97834. -253 253 253 253 253 253 253 253 253 253 253 253
  97835. -253 253 253 253 253 253 253 253 253 253 253 253
  97836. -253 253 253 253 253 253 253 253 253 253 253 253
  97837. -253 253 253 231 231 231 198 198 198 214 170 54
  97838. -236 178 12 236 178 12 210 150 10 137 92 6
  97839. - 18 14 6 2 2 6 2 2 6 2 2 6
  97840. - 6 6 6 70 47 6 200 144 11 236 178 12
  97841. -239 182 13 239 182 13 124 112 88 58 58 58
  97842. - 22 22 22 6 6 6 0 0 0 0 0 0
  97843. - 0 0 0 0 0 0 0 0 0 0 0 0
  97844. - 0 0 0 0 0 0 0 0 0 0 0 0
  97845. - 0 0 0 0 0 0 0 0 0 0 0 0
  97846. - 0 0 0 0 0 0 0 0 0 10 10 10
  97847. - 30 30 30 70 70 70 180 133 36 226 170 11
  97848. -239 182 13 242 186 14 242 186 14 246 186 14
  97849. -246 190 14 246 190 14 246 190 14 246 190 14
  97850. -246 190 14 246 190 14 246 190 14 246 190 14
  97851. -246 190 14 232 195 16 98 70 6 2 2 6
  97852. - 2 2 6 2 2 6 66 66 66 221 221 221
  97853. -253 253 253 253 253 253 253 253 253 253 253 253
  97854. -253 253 253 253 253 253 253 253 253 253 253 253
  97855. -253 253 253 253 253 253 253 253 253 253 253 253
  97856. -253 253 253 253 253 253 253 253 253 253 253 253
  97857. -253 253 253 206 206 206 198 198 198 214 166 58
  97858. -230 174 11 230 174 11 216 158 10 192 133 9
  97859. -163 110 8 116 81 8 102 78 10 116 81 8
  97860. -167 114 7 197 138 11 226 170 11 239 182 13
  97861. -242 186 14 242 186 14 162 146 94 78 78 78
  97862. - 34 34 34 14 14 14 6 6 6 0 0 0
  97863. - 0 0 0 0 0 0 0 0 0 0 0 0
  97864. - 0 0 0 0 0 0 0 0 0 0 0 0
  97865. - 0 0 0 0 0 0 0 0 0 0 0 0
  97866. - 0 0 0 0 0 0 0 0 0 6 6 6
  97867. - 30 30 30 78 78 78 190 142 34 226 170 11
  97868. -239 182 13 246 190 14 246 190 14 246 190 14
  97869. -246 190 14 246 190 14 246 190 14 246 190 14
  97870. -246 190 14 246 190 14 246 190 14 246 190 14
  97871. -246 190 14 241 196 14 203 166 17 22 18 6
  97872. - 2 2 6 2 2 6 2 2 6 38 38 38
  97873. -218 218 218 253 253 253 253 253 253 253 253 253
  97874. -253 253 253 253 253 253 253 253 253 253 253 253
  97875. -253 253 253 253 253 253 253 253 253 253 253 253
  97876. -253 253 253 253 253 253 253 253 253 253 253 253
  97877. -250 250 250 206 206 206 198 198 198 202 162 69
  97878. -226 170 11 236 178 12 224 166 10 210 150 10
  97879. -200 144 11 197 138 11 192 133 9 197 138 11
  97880. -210 150 10 226 170 11 242 186 14 246 190 14
  97881. -246 190 14 246 186 14 225 175 15 124 112 88
  97882. - 62 62 62 30 30 30 14 14 14 6 6 6
  97883. - 0 0 0 0 0 0 0 0 0 0 0 0
  97884. - 0 0 0 0 0 0 0 0 0 0 0 0
  97885. - 0 0 0 0 0 0 0 0 0 0 0 0
  97886. - 0 0 0 0 0 0 0 0 0 10 10 10
  97887. - 30 30 30 78 78 78 174 135 50 224 166 10
  97888. -239 182 13 246 190 14 246 190 14 246 190 14
  97889. -246 190 14 246 190 14 246 190 14 246 190 14
  97890. -246 190 14 246 190 14 246 190 14 246 190 14
  97891. -246 190 14 246 190 14 241 196 14 139 102 15
  97892. - 2 2 6 2 2 6 2 2 6 2 2 6
  97893. - 78 78 78 250 250 250 253 253 253 253 253 253
  97894. -253 253 253 253 253 253 253 253 253 253 253 253
  97895. -253 253 253 253 253 253 253 253 253 253 253 253
  97896. -253 253 253 253 253 253 253 253 253 253 253 253
  97897. -250 250 250 214 214 214 198 198 198 190 150 46
  97898. -219 162 10 236 178 12 234 174 13 224 166 10
  97899. -216 158 10 213 154 11 213 154 11 216 158 10
  97900. -226 170 11 239 182 13 246 190 14 246 190 14
  97901. -246 190 14 246 190 14 242 186 14 206 162 42
  97902. -101 101 101 58 58 58 30 30 30 14 14 14
  97903. - 6 6 6 0 0 0 0 0 0 0 0 0
  97904. - 0 0 0 0 0 0 0 0 0 0 0 0
  97905. - 0 0 0 0 0 0 0 0 0 0 0 0
  97906. - 0 0 0 0 0 0 0 0 0 10 10 10
  97907. - 30 30 30 74 74 74 174 135 50 216 158 10
  97908. -236 178 12 246 190 14 246 190 14 246 190 14
  97909. -246 190 14 246 190 14 246 190 14 246 190 14
  97910. -246 190 14 246 190 14 246 190 14 246 190 14
  97911. -246 190 14 246 190 14 241 196 14 226 184 13
  97912. - 61 42 6 2 2 6 2 2 6 2 2 6
  97913. - 22 22 22 238 238 238 253 253 253 253 253 253
  97914. -253 253 253 253 253 253 253 253 253 253 253 253
  97915. -253 253 253 253 253 253 253 253 253 253 253 253
  97916. -253 253 253 253 253 253 253 253 253 253 253 253
  97917. -253 253 253 226 226 226 187 187 187 180 133 36
  97918. -216 158 10 236 178 12 239 182 13 236 178 12
  97919. -230 174 11 226 170 11 226 170 11 230 174 11
  97920. -236 178 12 242 186 14 246 190 14 246 190 14
  97921. -246 190 14 246 190 14 246 186 14 239 182 13
  97922. -206 162 42 106 106 106 66 66 66 34 34 34
  97923. - 14 14 14 6 6 6 0 0 0 0 0 0
  97924. - 0 0 0 0 0 0 0 0 0 0 0 0
  97925. - 0 0 0 0 0 0 0 0 0 0 0 0
  97926. - 0 0 0 0 0 0 0 0 0 6 6 6
  97927. - 26 26 26 70 70 70 163 133 67 213 154 11
  97928. -236 178 12 246 190 14 246 190 14 246 190 14
  97929. -246 190 14 246 190 14 246 190 14 246 190 14
  97930. -246 190 14 246 190 14 246 190 14 246 190 14
  97931. -246 190 14 246 190 14 246 190 14 241 196 14
  97932. -190 146 13 18 14 6 2 2 6 2 2 6
  97933. - 46 46 46 246 246 246 253 253 253 253 253 253
  97934. -253 253 253 253 253 253 253 253 253 253 253 253
  97935. -253 253 253 253 253 253 253 253 253 253 253 253
  97936. -253 253 253 253 253 253 253 253 253 253 253 253
  97937. -253 253 253 221 221 221 86 86 86 156 107 11
  97938. -216 158 10 236 178 12 242 186 14 246 186 14
  97939. -242 186 14 239 182 13 239 182 13 242 186 14
  97940. -242 186 14 246 186 14 246 190 14 246 190 14
  97941. -246 190 14 246 190 14 246 190 14 246 190 14
  97942. -242 186 14 225 175 15 142 122 72 66 66 66
  97943. - 30 30 30 10 10 10 0 0 0 0 0 0
  97944. - 0 0 0 0 0 0 0 0 0 0 0 0
  97945. - 0 0 0 0 0 0 0 0 0 0 0 0
  97946. - 0 0 0 0 0 0 0 0 0 6 6 6
  97947. - 26 26 26 70 70 70 163 133 67 210 150 10
  97948. -236 178 12 246 190 14 246 190 14 246 190 14
  97949. -246 190 14 246 190 14 246 190 14 246 190 14
  97950. -246 190 14 246 190 14 246 190 14 246 190 14
  97951. -246 190 14 246 190 14 246 190 14 246 190 14
  97952. -232 195 16 121 92 8 34 34 34 106 106 106
  97953. -221 221 221 253 253 253 253 253 253 253 253 253
  97954. -253 253 253 253 253 253 253 253 253 253 253 253
  97955. -253 253 253 253 253 253 253 253 253 253 253 253
  97956. -253 253 253 253 253 253 253 253 253 253 253 253
  97957. -242 242 242 82 82 82 18 14 6 163 110 8
  97958. -216 158 10 236 178 12 242 186 14 246 190 14
  97959. -246 190 14 246 190 14 246 190 14 246 190 14
  97960. -246 190 14 246 190 14 246 190 14 246 190 14
  97961. -246 190 14 246 190 14 246 190 14 246 190 14
  97962. -246 190 14 246 190 14 242 186 14 163 133 67
  97963. - 46 46 46 18 18 18 6 6 6 0 0 0
  97964. - 0 0 0 0 0 0 0 0 0 0 0 0
  97965. - 0 0 0 0 0 0 0 0 0 0 0 0
  97966. - 0 0 0 0 0 0 0 0 0 10 10 10
  97967. - 30 30 30 78 78 78 163 133 67 210 150 10
  97968. -236 178 12 246 186 14 246 190 14 246 190 14
  97969. -246 190 14 246 190 14 246 190 14 246 190 14
  97970. -246 190 14 246 190 14 246 190 14 246 190 14
  97971. -246 190 14 246 190 14 246 190 14 246 190 14
  97972. -241 196 14 215 174 15 190 178 144 253 253 253
  97973. -253 253 253 253 253 253 253 253 253 253 253 253
  97974. -253 253 253 253 253 253 253 253 253 253 253 253
  97975. -253 253 253 253 253 253 253 253 253 253 253 253
  97976. -253 253 253 253 253 253 253 253 253 218 218 218
  97977. - 58 58 58 2 2 6 22 18 6 167 114 7
  97978. -216 158 10 236 178 12 246 186 14 246 190 14
  97979. -246 190 14 246 190 14 246 190 14 246 190 14
  97980. -246 190 14 246 190 14 246 190 14 246 190 14
  97981. -246 190 14 246 190 14 246 190 14 246 190 14
  97982. -246 190 14 246 186 14 242 186 14 190 150 46
  97983. - 54 54 54 22 22 22 6 6 6 0 0 0
  97984. - 0 0 0 0 0 0 0 0 0 0 0 0
  97985. - 0 0 0 0 0 0 0 0 0 0 0 0
  97986. - 0 0 0 0 0 0 0 0 0 14 14 14
  97987. - 38 38 38 86 86 86 180 133 36 213 154 11
  97988. -236 178 12 246 186 14 246 190 14 246 190 14
  97989. -246 190 14 246 190 14 246 190 14 246 190 14
  97990. -246 190 14 246 190 14 246 190 14 246 190 14
  97991. -246 190 14 246 190 14 246 190 14 246 190 14
  97992. -246 190 14 232 195 16 190 146 13 214 214 214
  97993. -253 253 253 253 253 253 253 253 253 253 253 253
  97994. -253 253 253 253 253 253 253 253 253 253 253 253
  97995. -253 253 253 253 253 253 253 253 253 253 253 253
  97996. -253 253 253 250 250 250 170 170 170 26 26 26
  97997. - 2 2 6 2 2 6 37 26 9 163 110 8
  97998. -219 162 10 239 182 13 246 186 14 246 190 14
  97999. -246 190 14 246 190 14 246 190 14 246 190 14
  98000. -246 190 14 246 190 14 246 190 14 246 190 14
  98001. -246 190 14 246 190 14 246 190 14 246 190 14
  98002. -246 186 14 236 178 12 224 166 10 142 122 72
  98003. - 46 46 46 18 18 18 6 6 6 0 0 0
  98004. - 0 0 0 0 0 0 0 0 0 0 0 0
  98005. - 0 0 0 0 0 0 0 0 0 0 0 0
  98006. - 0 0 0 0 0 0 6 6 6 18 18 18
  98007. - 50 50 50 109 106 95 192 133 9 224 166 10
  98008. -242 186 14 246 190 14 246 190 14 246 190 14
  98009. -246 190 14 246 190 14 246 190 14 246 190 14
  98010. -246 190 14 246 190 14 246 190 14 246 190 14
  98011. -246 190 14 246 190 14 246 190 14 246 190 14
  98012. -242 186 14 226 184 13 210 162 10 142 110 46
  98013. -226 226 226 253 253 253 253 253 253 253 253 253
  98014. -253 253 253 253 253 253 253 253 253 253 253 253
  98015. -253 253 253 253 253 253 253 253 253 253 253 253
  98016. -198 198 198 66 66 66 2 2 6 2 2 6
  98017. - 2 2 6 2 2 6 50 34 6 156 107 11
  98018. -219 162 10 239 182 13 246 186 14 246 190 14
  98019. -246 190 14 246 190 14 246 190 14 246 190 14
  98020. -246 190 14 246 190 14 246 190 14 246 190 14
  98021. -246 190 14 246 190 14 246 190 14 242 186 14
  98022. -234 174 13 213 154 11 154 122 46 66 66 66
  98023. - 30 30 30 10 10 10 0 0 0 0 0 0
  98024. - 0 0 0 0 0 0 0 0 0 0 0 0
  98025. - 0 0 0 0 0 0 0 0 0 0 0 0
  98026. - 0 0 0 0 0 0 6 6 6 22 22 22
  98027. - 58 58 58 154 121 60 206 145 10 234 174 13
  98028. -242 186 14 246 186 14 246 190 14 246 190 14
  98029. -246 190 14 246 190 14 246 190 14 246 190 14
  98030. -246 190 14 246 190 14 246 190 14 246 190 14
  98031. -246 190 14 246 190 14 246 190 14 246 190 14
  98032. -246 186 14 236 178 12 210 162 10 163 110 8
  98033. - 61 42 6 138 138 138 218 218 218 250 250 250
  98034. -253 253 253 253 253 253 253 253 253 250 250 250
  98035. -242 242 242 210 210 210 144 144 144 66 66 66
  98036. - 6 6 6 2 2 6 2 2 6 2 2 6
  98037. - 2 2 6 2 2 6 61 42 6 163 110 8
  98038. -216 158 10 236 178 12 246 190 14 246 190 14
  98039. -246 190 14 246 190 14 246 190 14 246 190 14
  98040. -246 190 14 246 190 14 246 190 14 246 190 14
  98041. -246 190 14 239 182 13 230 174 11 216 158 10
  98042. -190 142 34 124 112 88 70 70 70 38 38 38
  98043. - 18 18 18 6 6 6 0 0 0 0 0 0
  98044. - 0 0 0 0 0 0 0 0 0 0 0 0
  98045. - 0 0 0 0 0 0 0 0 0 0 0 0
  98046. - 0 0 0 0 0 0 6 6 6 22 22 22
  98047. - 62 62 62 168 124 44 206 145 10 224 166 10
  98048. -236 178 12 239 182 13 242 186 14 242 186 14
  98049. -246 186 14 246 190 14 246 190 14 246 190 14
  98050. -246 190 14 246 190 14 246 190 14 246 190 14
  98051. -246 190 14 246 190 14 246 190 14 246 190 14
  98052. -246 190 14 236 178 12 216 158 10 175 118 6
  98053. - 80 54 7 2 2 6 6 6 6 30 30 30
  98054. - 54 54 54 62 62 62 50 50 50 38 38 38
  98055. - 14 14 14 2 2 6 2 2 6 2 2 6
  98056. - 2 2 6 2 2 6 2 2 6 2 2 6
  98057. - 2 2 6 6 6 6 80 54 7 167 114 7
  98058. -213 154 11 236 178 12 246 190 14 246 190 14
  98059. -246 190 14 246 190 14 246 190 14 246 190 14
  98060. -246 190 14 242 186 14 239 182 13 239 182 13
  98061. -230 174 11 210 150 10 174 135 50 124 112 88
  98062. - 82 82 82 54 54 54 34 34 34 18 18 18
  98063. - 6 6 6 0 0 0 0 0 0 0 0 0
  98064. - 0 0 0 0 0 0 0 0 0 0 0 0
  98065. - 0 0 0 0 0 0 0 0 0 0 0 0
  98066. - 0 0 0 0 0 0 6 6 6 18 18 18
  98067. - 50 50 50 158 118 36 192 133 9 200 144 11
  98068. -216 158 10 219 162 10 224 166 10 226 170 11
  98069. -230 174 11 236 178 12 239 182 13 239 182 13
  98070. -242 186 14 246 186 14 246 190 14 246 190 14
  98071. -246 190 14 246 190 14 246 190 14 246 190 14
  98072. -246 186 14 230 174 11 210 150 10 163 110 8
  98073. -104 69 6 10 10 10 2 2 6 2 2 6
  98074. - 2 2 6 2 2 6 2 2 6 2 2 6
  98075. - 2 2 6 2 2 6 2 2 6 2 2 6
  98076. - 2 2 6 2 2 6 2 2 6 2 2 6
  98077. - 2 2 6 6 6 6 91 60 6 167 114 7
  98078. -206 145 10 230 174 11 242 186 14 246 190 14
  98079. -246 190 14 246 190 14 246 186 14 242 186 14
  98080. -239 182 13 230 174 11 224 166 10 213 154 11
  98081. -180 133 36 124 112 88 86 86 86 58 58 58
  98082. - 38 38 38 22 22 22 10 10 10 6 6 6
  98083. - 0 0 0 0 0 0 0 0 0 0 0 0
  98084. - 0 0 0 0 0 0 0 0 0 0 0 0
  98085. - 0 0 0 0 0 0 0 0 0 0 0 0
  98086. - 0 0 0 0 0 0 0 0 0 14 14 14
  98087. - 34 34 34 70 70 70 138 110 50 158 118 36
  98088. -167 114 7 180 123 7 192 133 9 197 138 11
  98089. -200 144 11 206 145 10 213 154 11 219 162 10
  98090. -224 166 10 230 174 11 239 182 13 242 186 14
  98091. -246 186 14 246 186 14 246 186 14 246 186 14
  98092. -239 182 13 216 158 10 185 133 11 152 99 6
  98093. -104 69 6 18 14 6 2 2 6 2 2 6
  98094. - 2 2 6 2 2 6 2 2 6 2 2 6
  98095. - 2 2 6 2 2 6 2 2 6 2 2 6
  98096. - 2 2 6 2 2 6 2 2 6 2 2 6
  98097. - 2 2 6 6 6 6 80 54 7 152 99 6
  98098. -192 133 9 219 162 10 236 178 12 239 182 13
  98099. -246 186 14 242 186 14 239 182 13 236 178 12
  98100. -224 166 10 206 145 10 192 133 9 154 121 60
  98101. - 94 94 94 62 62 62 42 42 42 22 22 22
  98102. - 14 14 14 6 6 6 0 0 0 0 0 0
  98103. - 0 0 0 0 0 0 0 0 0 0 0 0
  98104. - 0 0 0 0 0 0 0 0 0 0 0 0
  98105. - 0 0 0 0 0 0 0 0 0 0 0 0
  98106. - 0 0 0 0 0 0 0 0 0 6 6 6
  98107. - 18 18 18 34 34 34 58 58 58 78 78 78
  98108. -101 98 89 124 112 88 142 110 46 156 107 11
  98109. -163 110 8 167 114 7 175 118 6 180 123 7
  98110. -185 133 11 197 138 11 210 150 10 219 162 10
  98111. -226 170 11 236 178 12 236 178 12 234 174 13
  98112. -219 162 10 197 138 11 163 110 8 130 83 6
  98113. - 91 60 6 10 10 10 2 2 6 2 2 6
  98114. - 18 18 18 38 38 38 38 38 38 38 38 38
  98115. - 38 38 38 38 38 38 38 38 38 38 38 38
  98116. - 38 38 38 38 38 38 26 26 26 2 2 6
  98117. - 2 2 6 6 6 6 70 47 6 137 92 6
  98118. -175 118 6 200 144 11 219 162 10 230 174 11
  98119. -234 174 13 230 174 11 219 162 10 210 150 10
  98120. -192 133 9 163 110 8 124 112 88 82 82 82
  98121. - 50 50 50 30 30 30 14 14 14 6 6 6
  98122. - 0 0 0 0 0 0 0 0 0 0 0 0
  98123. - 0 0 0 0 0 0 0 0 0 0 0 0
  98124. - 0 0 0 0 0 0 0 0 0 0 0 0
  98125. - 0 0 0 0 0 0 0 0 0 0 0 0
  98126. - 0 0 0 0 0 0 0 0 0 0 0 0
  98127. - 6 6 6 14 14 14 22 22 22 34 34 34
  98128. - 42 42 42 58 58 58 74 74 74 86 86 86
  98129. -101 98 89 122 102 70 130 98 46 121 87 25
  98130. -137 92 6 152 99 6 163 110 8 180 123 7
  98131. -185 133 11 197 138 11 206 145 10 200 144 11
  98132. -180 123 7 156 107 11 130 83 6 104 69 6
  98133. - 50 34 6 54 54 54 110 110 110 101 98 89
  98134. - 86 86 86 82 82 82 78 78 78 78 78 78
  98135. - 78 78 78 78 78 78 78 78 78 78 78 78
  98136. - 78 78 78 82 82 82 86 86 86 94 94 94
  98137. -106 106 106 101 101 101 86 66 34 124 80 6
  98138. -156 107 11 180 123 7 192 133 9 200 144 11
  98139. -206 145 10 200 144 11 192 133 9 175 118 6
  98140. -139 102 15 109 106 95 70 70 70 42 42 42
  98141. - 22 22 22 10 10 10 0 0 0 0 0 0
  98142. - 0 0 0 0 0 0 0 0 0 0 0 0
  98143. - 0 0 0 0 0 0 0 0 0 0 0 0
  98144. - 0 0 0 0 0 0 0 0 0 0 0 0
  98145. - 0 0 0 0 0 0 0 0 0 0 0 0
  98146. - 0 0 0 0 0 0 0 0 0 0 0 0
  98147. - 0 0 0 0 0 0 6 6 6 10 10 10
  98148. - 14 14 14 22 22 22 30 30 30 38 38 38
  98149. - 50 50 50 62 62 62 74 74 74 90 90 90
  98150. -101 98 89 112 100 78 121 87 25 124 80 6
  98151. -137 92 6 152 99 6 152 99 6 152 99 6
  98152. -138 86 6 124 80 6 98 70 6 86 66 30
  98153. -101 98 89 82 82 82 58 58 58 46 46 46
  98154. - 38 38 38 34 34 34 34 34 34 34 34 34
  98155. - 34 34 34 34 34 34 34 34 34 34 34 34
  98156. - 34 34 34 34 34 34 38 38 38 42 42 42
  98157. - 54 54 54 82 82 82 94 86 76 91 60 6
  98158. -134 86 6 156 107 11 167 114 7 175 118 6
  98159. -175 118 6 167 114 7 152 99 6 121 87 25
  98160. -101 98 89 62 62 62 34 34 34 18 18 18
  98161. - 6 6 6 0 0 0 0 0 0 0 0 0
  98162. - 0 0 0 0 0 0 0 0 0 0 0 0
  98163. - 0 0 0 0 0 0 0 0 0 0 0 0
  98164. - 0 0 0 0 0 0 0 0 0 0 0 0
  98165. - 0 0 0 0 0 0 0 0 0 0 0 0
  98166. - 0 0 0 0 0 0 0 0 0 0 0 0
  98167. - 0 0 0 0 0 0 0 0 0 0 0 0
  98168. - 0 0 0 6 6 6 6 6 6 10 10 10
  98169. - 18 18 18 22 22 22 30 30 30 42 42 42
  98170. - 50 50 50 66 66 66 86 86 86 101 98 89
  98171. -106 86 58 98 70 6 104 69 6 104 69 6
  98172. -104 69 6 91 60 6 82 62 34 90 90 90
  98173. - 62 62 62 38 38 38 22 22 22 14 14 14
  98174. - 10 10 10 10 10 10 10 10 10 10 10 10
  98175. - 10 10 10 10 10 10 6 6 6 10 10 10
  98176. - 10 10 10 10 10 10 10 10 10 14 14 14
  98177. - 22 22 22 42 42 42 70 70 70 89 81 66
  98178. - 80 54 7 104 69 6 124 80 6 137 92 6
  98179. -134 86 6 116 81 8 100 82 52 86 86 86
  98180. - 58 58 58 30 30 30 14 14 14 6 6 6
  98181. - 0 0 0 0 0 0 0 0 0 0 0 0
  98182. - 0 0 0 0 0 0 0 0 0 0 0 0
  98183. - 0 0 0 0 0 0 0 0 0 0 0 0
  98184. - 0 0 0 0 0 0 0 0 0 0 0 0
  98185. - 0 0 0 0 0 0 0 0 0 0 0 0
  98186. - 0 0 0 0 0 0 0 0 0 0 0 0
  98187. - 0 0 0 0 0 0 0 0 0 0 0 0
  98188. - 0 0 0 0 0 0 0 0 0 0 0 0
  98189. - 0 0 0 6 6 6 10 10 10 14 14 14
  98190. - 18 18 18 26 26 26 38 38 38 54 54 54
  98191. - 70 70 70 86 86 86 94 86 76 89 81 66
  98192. - 89 81 66 86 86 86 74 74 74 50 50 50
  98193. - 30 30 30 14 14 14 6 6 6 0 0 0
  98194. - 0 0 0 0 0 0 0 0 0 0 0 0
  98195. - 0 0 0 0 0 0 0 0 0 0 0 0
  98196. - 0 0 0 0 0 0 0 0 0 0 0 0
  98197. - 6 6 6 18 18 18 34 34 34 58 58 58
  98198. - 82 82 82 89 81 66 89 81 66 89 81 66
  98199. - 94 86 66 94 86 76 74 74 74 50 50 50
  98200. - 26 26 26 14 14 14 6 6 6 0 0 0
  98201. - 0 0 0 0 0 0 0 0 0 0 0 0
  98202. - 0 0 0 0 0 0 0 0 0 0 0 0
  98203. - 0 0 0 0 0 0 0 0 0 0 0 0
  98204. - 0 0 0 0 0 0 0 0 0 0 0 0
  98205. - 0 0 0 0 0 0 0 0 0 0 0 0
  98206. - 0 0 0 0 0 0 0 0 0 0 0 0
  98207. - 0 0 0 0 0 0 0 0 0 0 0 0
  98208. - 0 0 0 0 0 0 0 0 0 0 0 0
  98209. - 0 0 0 0 0 0 0 0 0 0 0 0
  98210. - 6 6 6 6 6 6 14 14 14 18 18 18
  98211. - 30 30 30 38 38 38 46 46 46 54 54 54
  98212. - 50 50 50 42 42 42 30 30 30 18 18 18
  98213. - 10 10 10 0 0 0 0 0 0 0 0 0
  98214. - 0 0 0 0 0 0 0 0 0 0 0 0
  98215. - 0 0 0 0 0 0 0 0 0 0 0 0
  98216. - 0 0 0 0 0 0 0 0 0 0 0 0
  98217. - 0 0 0 6 6 6 14 14 14 26 26 26
  98218. - 38 38 38 50 50 50 58 58 58 58 58 58
  98219. - 54 54 54 42 42 42 30 30 30 18 18 18
  98220. - 10 10 10 0 0 0 0 0 0 0 0 0
  98221. - 0 0 0 0 0 0 0 0 0 0 0 0
  98222. - 0 0 0 0 0 0 0 0 0 0 0 0
  98223. - 0 0 0 0 0 0 0 0 0 0 0 0
  98224. - 0 0 0 0 0 0 0 0 0 0 0 0
  98225. - 0 0 0 0 0 0 0 0 0 0 0 0
  98226. - 0 0 0 0 0 0 0 0 0 0 0 0
  98227. - 0 0 0 0 0 0 0 0 0 0 0 0
  98228. - 0 0 0 0 0 0 0 0 0 0 0 0
  98229. - 0 0 0 0 0 0 0 0 0 0 0 0
  98230. - 0 0 0 0 0 0 0 0 0 6 6 6
  98231. - 6 6 6 10 10 10 14 14 14 18 18 18
  98232. - 18 18 18 14 14 14 10 10 10 6 6 6
  98233. - 0 0 0 0 0 0 0 0 0 0 0 0
  98234. - 0 0 0 0 0 0 0 0 0 0 0 0
  98235. - 0 0 0 0 0 0 0 0 0 0 0 0
  98236. - 0 0 0 0 0 0 0 0 0 0 0 0
  98237. - 0 0 0 0 0 0 0 0 0 6 6 6
  98238. - 14 14 14 18 18 18 22 22 22 22 22 22
  98239. - 18 18 18 14 14 14 10 10 10 6 6 6
  98240. - 0 0 0 0 0 0 0 0 0 0 0 0
  98241. - 0 0 0 0 0 0 0 0 0 0 0 0
  98242. - 0 0 0 0 0 0 0 0 0 0 0 0
  98243. - 0 0 0 0 0 0 0 0 0 0 0 0
  98244. - 0 0 0 0 0 0 0 0 0 0 0 0
  98245. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98246. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98247. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98248. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98249. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98250. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98251. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98252. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98253. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98254. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98255. +0 0 0 0 0 0 0 0 0
  98256. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98257. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98258. +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0
  98259. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98260. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98261. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98262. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98263. +0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
  98264. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98265. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98266. +0 0 0 0 0 0 0 0 0
  98267. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98268. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  98269. +10 15 3 2 3 1 12 18 4 42 61 14 19 27 6 11 16 4
  98270. +38 55 13 10 15 3 3 4 1 10 15 3 0 0 0 0 0 0
  98271. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98272. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98273. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 1
  98274. +12 18 4 1 1 0 23 34 8 31 45 11 10 15 3 32 47 11
  98275. +34 49 12 3 4 1 3 4 1 3 4 1 0 0 0 0 0 0
  98276. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98277. +0 0 0 0 0 0 0 0 0
  98278. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98279. +0 0 0 0 0 0 10 15 3 29 42 10 26 37 9 12 18 4
  98280. +55 80 19 81 118 28 55 80 19 92 132 31 106 153 36 69 100 23
  98281. +100 144 34 80 116 27 42 61 14 81 118 28 23 34 8 27 40 9
  98282. +15 21 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98283. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98284. +0 0 0 0 0 0 1 1 0 29 42 10 15 21 5 50 72 17
  98285. +74 107 25 45 64 15 102 148 35 80 116 27 84 121 28 111 160 38
  98286. +69 100 23 65 94 22 81 118 28 29 42 10 17 25 6 29 42 10
  98287. +23 34 8 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  98288. +0 0 0 0 0 0 0 0 0
  98289. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  98290. +15 21 5 15 21 5 34 49 12 101 146 34 111 161 38 97 141 33
  98291. +97 141 33 119 172 41 117 170 40 116 167 40 118 170 40 118 171 40
  98292. +117 169 40 118 170 40 111 160 38 118 170 40 96 138 32 89 128 30
  98293. +81 118 28 11 16 4 10 15 3 1 1 0 0 0 0 0 0 0
  98294. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98295. +3 4 1 3 4 1 34 49 12 101 146 34 79 115 27 111 160 38
  98296. +114 165 39 113 163 39 118 170 40 117 169 40 118 171 40 117 169 40
  98297. +116 167 40 119 172 41 113 163 39 92 132 31 105 151 36 113 163 39
  98298. +75 109 26 19 27 6 16 23 5 11 16 4 0 1 0 0 0 0
  98299. +0 0 0 0 0 0 0 0 0
  98300. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  98301. +80 116 27 106 153 36 105 151 36 114 165 39 118 170 40 118 171 40
  98302. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98303. +117 169 40 117 169 40 117 170 40 117 169 40 118 170 40 118 170 40
  98304. +117 170 40 75 109 26 75 109 26 34 49 12 0 0 0 0 0 0
  98305. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  98306. +64 92 22 65 94 22 100 144 34 118 171 40 118 170 40 117 169 40
  98307. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98308. +117 169 40 117 169 40 117 169 40 118 171 41 118 170 40 117 169 40
  98309. +109 158 37 105 151 36 104 150 35 47 69 16 0 0 0 0 0 0
  98310. +0 0 0 0 0 0 0 0 0
  98311. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98312. +42 61 14 115 167 39 118 170 40 117 169 40 117 169 40 117 169 40
  98313. +117 170 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  98314. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98315. +117 169 40 117 169 40 118 170 40 96 138 32 17 25 6 0 0 0
  98316. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 69 16
  98317. +114 165 39 117 168 40 117 170 40 117 169 40 117 169 40 117 169 40
  98318. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98319. +117 169 40 117 169 40 118 170 40 117 169 40 117 169 40 117 169 40
  98320. +117 170 40 119 172 41 96 138 32 12 18 4 0 0 0 0 0 0
  98321. +0 0 0 0 0 0 0 0 0
  98322. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  98323. +32 47 11 105 151 36 118 170 40 117 169 40 117 169 40 116 168 40
  98324. +109 157 37 111 160 38 117 169 40 118 171 40 117 169 40 117 169 40
  98325. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98326. +117 169 40 117 169 40 117 169 40 118 171 40 69 100 23 2 3 1
  98327. +0 0 0 0 0 0 0 0 0 0 0 0 19 27 6 101 146 34
  98328. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98329. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 170 40
  98330. +118 171 40 115 166 39 107 154 36 111 161 38 117 169 40 117 169 40
  98331. +117 169 40 118 171 40 75 109 26 19 27 6 2 3 1 0 0 0
  98332. +0 0 0 0 0 0 0 0 0
  98333. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 23 5
  98334. +89 128 30 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98335. +111 160 38 92 132 31 79 115 27 96 138 32 115 166 39 119 171 41
  98336. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98337. +117 169 40 117 169 40 117 169 40 118 170 40 109 157 37 26 37 9
  98338. +0 0 0 0 0 0 0 0 0 0 0 0 64 92 22 118 171 40
  98339. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98340. +117 169 40 117 169 40 117 169 40 118 170 40 118 171 40 109 157 37
  98341. +89 128 30 81 118 28 100 144 34 115 166 39 117 169 40 117 169 40
  98342. +117 169 40 117 170 40 113 163 39 60 86 20 1 1 0 0 0 0
  98343. +0 0 0 0 0 0 0 0 0
  98344. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98345. +27 40 9 96 138 32 118 170 40 117 169 40 117 169 40 117 169 40
  98346. +117 170 40 117 169 40 101 146 34 67 96 23 55 80 19 84 121 28
  98347. +113 163 39 119 171 41 117 169 40 117 169 40 117 169 40 117 169 40
  98348. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 65 94 22
  98349. +0 0 0 0 0 0 0 0 0 15 21 5 101 146 34 118 171 40
  98350. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98351. +117 169 40 118 170 40 118 171 40 104 150 35 69 100 23 53 76 18
  98352. +81 118 28 111 160 38 118 170 40 117 169 40 117 169 40 117 169 40
  98353. +117 169 40 114 165 39 69 100 23 10 15 3 0 0 0 0 0 0
  98354. +0 0 0 0 0 0 0 0 0
  98355. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  98356. +31 45 11 77 111 26 117 169 40 117 169 40 117 169 40 117 169 40
  98357. +117 169 40 117 169 40 118 170 40 116 168 40 92 132 31 47 69 16
  98358. +38 55 13 81 118 28 113 163 39 119 171 41 117 169 40 117 169 40
  98359. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 41 92 132 31
  98360. +10 15 3 0 0 0 0 0 0 36 52 12 115 166 39 117 169 40
  98361. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  98362. +118 171 40 102 148 35 64 92 22 34 49 12 65 94 22 106 153 36
  98363. +118 171 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  98364. +118 170 40 107 154 36 55 80 19 15 21 5 0 0 0 0 0 0
  98365. +0 0 0 0 0 0 0 0 0
  98366. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98367. +29 42 10 101 146 34 118 171 40 117 169 40 117 169 40 117 169 40
  98368. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 113 163 39
  98369. +75 109 26 27 40 9 36 52 12 89 128 30 116 167 40 118 171 40
  98370. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 104 150 35
  98371. +16 23 5 0 0 0 0 0 0 53 76 18 118 171 40 117 169 40
  98372. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 109 157 37
  98373. +67 96 23 23 34 8 42 61 14 96 138 32 118 170 40 118 170 40
  98374. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98375. +117 169 40 117 169 40 74 107 25 10 15 3 0 0 0 0 0 0
  98376. +0 0 0 0 0 0 0 0 0
  98377. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98378. +0 0 0 31 45 11 101 146 34 118 170 40 117 169 40 117 169 40
  98379. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98380. +119 171 41 102 148 35 47 69 16 14 20 5 50 72 17 102 148 35
  98381. +118 171 40 117 169 40 117 169 40 117 169 40 118 170 40 102 148 35
  98382. +15 21 5 0 0 0 0 0 0 50 72 17 118 170 40 117 169 40
  98383. +117 169 40 117 169 40 118 170 40 116 167 40 84 121 28 27 40 9
  98384. +19 27 6 74 107 25 114 165 39 118 171 40 117 169 40 117 169 40
  98385. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98386. +117 169 40 75 109 26 10 15 4 0 0 0 0 0 0 0 0 0
  98387. +0 0 0 0 0 0 0 0 0
  98388. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98389. +0 0 0 38 55 13 102 148 35 118 171 40 117 169 40 117 169 40
  98390. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98391. +117 169 40 118 170 40 115 167 39 77 111 26 17 25 6 19 27 6
  98392. +77 111 26 115 166 39 118 170 40 117 169 40 119 172 41 81 118 28
  98393. +3 4 1 0 0 0 0 0 0 27 40 9 111 160 38 118 170 40
  98394. +117 169 40 118 171 40 105 151 36 50 72 17 10 15 3 38 55 13
  98395. +100 144 34 118 171 40 117 169 40 117 169 40 117 169 40 117 169 40
  98396. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98397. +117 169 40 79 115 27 15 21 5 0 0 0 0 0 0 0 0 0
  98398. +0 0 0 0 0 0 0 0 0
  98399. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98400. +0 0 0 10 15 3 64 92 22 111 160 38 117 169 40 117 169 40
  98401. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98402. +117 169 40 117 169 40 117 169 40 118 171 40 96 138 32 32 47 11
  98403. +3 4 1 50 72 17 107 154 36 120 173 41 105 151 36 31 45 11
  98404. +0 0 0 0 0 0 0 0 0 3 4 1 65 94 22 117 169 40
  98405. +118 170 40 89 128 30 26 37 9 3 4 1 60 86 20 111 161 38
  98406. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98407. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98408. +97 141 33 36 52 12 1 1 0 0 0 0 0 0 0 0 0 0
  98409. +0 0 0 0 0 0 0 0 0
  98410. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98411. +0 0 0 0 0 0 14 20 5 75 109 26 117 168 40 117 169 40
  98412. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98413. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 107 154 36
  98414. +45 64 15 2 3 1 31 45 11 75 109 26 32 47 11 0 1 0
  98415. +0 0 0 0 0 0 0 0 0 0 0 0 10 15 3 55 80 19
  98416. +65 94 22 11 16 4 11 16 4 75 109 26 116 168 40 118 170 40
  98417. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98418. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 107 154 36
  98419. +47 69 16 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0
  98420. +0 0 0 0 0 0 0 0 0
  98421. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98422. +0 0 0 0 0 0 12 18 4 69 100 23 111 161 38 118 171 40
  98423. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98424. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  98425. +111 160 38 50 72 17 2 3 1 2 3 1 0 0 0 0 0 0
  98426. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  98427. +1 1 0 12 18 4 81 118 28 118 170 40 117 169 40 117 169 40
  98428. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98429. +117 169 40 117 169 40 117 169 40 117 170 40 118 171 40 101 146 34
  98430. +42 61 14 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  98431. +0 0 0 0 0 0 0 0 0
  98432. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98433. +0 0 0 0 0 0 0 0 0 3 4 1 36 52 12 89 128 30
  98434. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98435. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98436. +118 171 41 101 146 34 14 20 5 0 0 0 0 0 0 0 0 0
  98437. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98438. +0 0 0 47 69 16 118 170 40 117 169 40 117 169 40 117 169 40
  98439. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98440. +117 169 40 117 169 40 117 170 40 111 160 38 69 100 23 19 27 6
  98441. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98442. +0 0 0 0 0 0 0 0 0
  98443. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98444. +0 0 0 0 0 0 0 0 0 0 0 0 11 16 4 69 100 23
  98445. +115 167 39 119 172 41 117 169 40 117 169 40 117 169 40 117 169 40
  98446. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98447. +119 172 41 75 109 26 3 4 1 0 0 0 0 0 0 0 0 0
  98448. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98449. +0 0 0 23 34 8 106 153 36 118 170 40 117 169 40 117 169 40
  98450. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98451. +117 169 40 118 170 40 119 172 41 105 151 36 42 61 14 2 3 1
  98452. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98453. +0 0 0 0 0 0 0 0 0
  98454. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98455. +0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 15 21 5
  98456. +45 64 15 80 116 27 114 165 39 118 170 40 117 169 40 117 169 40
  98457. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 119 172 41
  98458. +97 141 33 20 30 7 0 0 0 0 0 0 0 0 0 0 0 0
  98459. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98460. +0 0 0 1 1 0 53 76 18 114 165 39 118 171 40 117 169 40
  98461. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98462. +118 171 40 104 150 35 64 92 22 31 45 11 10 15 3 0 0 0
  98463. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98464. +0 0 0 0 0 0 0 0 0
  98465. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98466. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98467. +0 0 0 36 52 12 97 141 33 109 158 37 113 163 39 116 168 40
  98468. +117 169 40 117 170 40 118 170 40 119 172 41 115 167 39 84 121 28
  98469. +23 34 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98470. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98471. +0 0 0 0 0 0 3 4 1 50 72 17 102 148 35 118 171 40
  98472. +119 171 41 118 170 40 117 169 40 117 169 40 115 166 39 111 161 38
  98473. +109 157 37 79 115 27 12 18 4 0 0 0 0 0 0 0 0 0
  98474. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98475. +0 0 0 0 0 0 0 0 0
  98476. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98477. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98478. +0 0 0 3 4 1 15 21 5 23 34 8 45 64 15 106 153 36
  98479. +116 167 40 111 160 38 101 146 34 79 115 27 42 61 14 10 15 3
  98480. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98481. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98482. +0 0 0 0 0 0 0 0 0 1 1 0 20 30 7 60 86 20
  98483. +89 128 30 106 153 36 113 163 39 117 169 40 84 121 28 29 42 10
  98484. +19 27 6 10 15 3 2 3 1 0 0 0 0 0 0 0 0 0
  98485. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98486. +0 0 0 0 0 0 0 0 0
  98487. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98488. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98489. +0 0 0 0 0 0 0 0 0 0 0 0 16 23 5 38 55 13
  98490. +36 52 12 26 37 9 12 18 4 2 3 1 0 0 0 0 0 0
  98491. +0 0 0 0 0 0 0 0 0 1 0 0 19 2 7 52 5 18
  98492. +78 7 27 88 8 31 81 7 29 56 5 19 25 2 9 3 0 1
  98493. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98494. +3 4 1 19 27 6 31 45 11 38 55 13 32 47 11 3 4 1
  98495. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98496. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98497. +0 0 0 0 0 0 0 0 0
  98498. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98499. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98500. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  98501. +9 0 3 12 1 4 9 0 3 4 0 1 0 0 0 0 0 0
  98502. +0 0 0 0 0 0 28 3 10 99 9 35 156 14 55 182 16 64
  98503. +189 17 66 190 17 67 189 17 66 184 17 65 166 15 58 118 13 41
  98504. +45 4 16 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  98505. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98506. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98507. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98508. +0 0 0 0 0 0 0 0 0
  98509. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98510. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98511. +0 0 0 0 0 0 11 1 4 52 5 18 101 9 35 134 12 47
  98512. +151 14 53 154 14 54 151 14 53 113 10 40 11 1 4 0 0 0
  98513. +3 0 1 67 6 24 159 14 56 190 17 67 190 17 67 188 17 66
  98514. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 191 17 67
  98515. +174 16 61 101 9 35 14 1 5 0 0 0 35 3 12 108 10 38
  98516. +122 11 43 122 11 43 112 10 39 87 8 30 50 5 17 13 1 5
  98517. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98518. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98519. +0 0 0 0 0 0 0 0 0
  98520. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98521. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98522. +3 0 1 56 5 19 141 13 49 182 16 64 191 17 67 191 17 67
  98523. +190 17 67 190 17 67 191 17 67 113 10 40 3 0 1 1 0 0
  98524. +79 7 28 180 16 63 190 17 67 188 17 66 188 17 66 188 17 66
  98525. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98526. +189 17 66 188 17 66 122 11 43 11 1 4 41 4 14 176 16 62
  98527. +191 17 67 191 17 67 191 17 67 190 17 67 181 16 63 146 13 51
  98528. +75 7 26 10 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  98529. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98530. +0 0 0 0 0 0 0 0 0
  98531. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98532. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1 2
  98533. +90 8 32 178 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  98534. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 41 4 14
  98535. +173 16 61 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  98536. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98537. +188 17 66 188 17 66 188 17 66 88 8 31 1 0 0 89 8 31
  98538. +185 17 65 189 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  98539. +186 17 65 124 11 43 25 2 9 0 0 0 0 0 0 0 0 0
  98540. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98541. +0 0 0 0 0 0 0 0 0
  98542. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98543. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 89 8 31
  98544. +184 17 65 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98545. +190 17 67 151 14 53 34 3 12 0 0 0 0 0 0 79 7 28
  98546. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98547. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98548. +188 17 66 188 17 66 191 17 67 146 13 51 9 1 3 7 1 2
  98549. +108 10 38 187 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  98550. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 0 0 0
  98551. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98552. +0 0 0 0 0 0 0 0 0
  98553. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98554. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 176 16 62
  98555. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  98556. +151 14 53 38 3 13 0 0 0 0 0 0 0 0 0 50 5 17
  98557. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98558. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98559. +188 17 66 188 17 66 191 17 67 141 13 49 7 1 3 0 0 0
  98560. +11 1 4 112 10 39 187 17 66 189 17 66 188 17 66 188 17 66
  98561. +188 17 66 188 17 66 190 17 67 113 10 40 5 0 2 0 0 0
  98562. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98563. +0 0 0 0 0 0 0 0 0
  98564. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98565. +0 0 0 0 0 0 0 0 0 7 1 3 132 12 46 191 17 67
  98566. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 146 13 51
  98567. +35 3 12 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  98568. +101 9 35 185 17 65 190 17 67 188 17 66 188 17 66 188 17 66
  98569. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98570. +188 17 66 190 17 67 180 16 63 67 6 24 0 0 0 0 0 0
  98571. +0 0 0 11 1 4 108 10 38 186 17 65 189 17 66 188 17 66
  98572. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  98573. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98574. +0 0 0 0 0 0 0 0 0
  98575. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98576. +0 0 0 0 0 0 0 0 0 44 4 15 177 16 62 189 17 66
  98577. +188 17 66 188 17 66 189 17 66 189 17 66 134 12 47 28 3 10
  98578. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98579. +8 1 3 79 7 28 159 14 56 188 17 66 191 17 67 190 17 67
  98580. +189 17 66 189 17 66 189 17 66 189 17 66 190 17 67 191 17 67
  98581. +188 17 66 158 14 55 72 7 25 4 0 1 0 0 0 0 0 0
  98582. +0 0 0 0 0 0 8 1 3 95 9 33 182 16 64 189 17 67
  98583. +188 17 66 188 17 66 188 17 66 191 17 67 122 11 43 3 0 1
  98584. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98585. +0 0 0 0 0 0 0 0 0
  98586. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98587. +0 0 0 0 0 0 0 0 0 88 8 31 190 17 67 188 17 66
  98588. +188 17 66 189 17 66 185 17 65 113 10 40 18 2 6 0 0 0
  98589. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98590. +0 0 0 1 0 0 24 2 8 77 7 27 124 11 43 154 14 54
  98591. +168 15 59 173 16 61 173 16 61 168 15 59 154 14 54 124 11 43
  98592. +77 7 27 22 2 8 0 0 0 0 0 0 0 0 0 0 0 0
  98593. +0 0 0 0 0 0 0 0 0 5 0 2 77 7 27 173 16 61
  98594. +190 17 67 188 17 66 188 17 66 190 17 67 164 15 57 23 2 8
  98595. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98596. +0 0 0 0 0 0 0 0 0
  98597. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98598. +0 0 0 0 0 0 1 0 0 118 13 41 191 17 67 188 17 66
  98599. +190 17 67 174 16 61 87 8 30 8 1 3 0 0 0 0 0 0
  98600. +0 0 0 0 0 0 10 1 4 29 3 10 40 4 14 36 3 13
  98601. +18 2 6 2 0 1 0 0 0 0 0 0 3 0 1 14 1 5
  98602. +26 2 9 33 3 11 32 3 11 25 2 9 13 1 5 3 0 1
  98603. +0 0 0 14 1 5 56 5 19 95 9 33 109 10 38 101 9 35
  98604. +77 7 27 35 3 12 5 0 2 0 0 0 1 0 0 56 5 19
  98605. +156 14 55 190 17 67 188 17 66 188 17 66 182 16 64 50 5 17
  98606. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98607. +0 0 0 0 0 0 0 0 0
  98608. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98609. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 189 17 66
  98610. +151 14 53 52 5 18 2 0 1 0 0 0 0 0 0 1 0 0
  98611. +28 3 10 90 8 32 146 13 51 170 15 60 178 16 62 174 16 61
  98612. +158 14 55 112 10 39 40 4 14 1 0 0 0 0 0 0 0 0
  98613. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  98614. +56 5 19 146 13 51 183 17 64 191 17 67 191 17 67 191 17 67
  98615. +188 17 66 173 16 61 122 11 43 41 4 14 1 0 0 0 0 0
  98616. +30 3 10 124 11 43 185 17 65 190 17 67 187 17 66 67 6 24
  98617. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98618. +0 0 0 0 0 0 0 0 0
  98619. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98620. +0 0 0 0 0 0 6 1 2 134 12 47 168 15 59 99 9 35
  98621. +21 2 7 0 0 0 0 0 0 0 0 0 6 1 2 77 7 27
  98622. +162 15 57 190 17 67 191 17 67 189 17 66 189 17 66 189 17 66
  98623. +190 17 67 191 17 67 169 15 59 75 7 26 3 0 1 0 0 0
  98624. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 79 7 28
  98625. +178 16 62 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  98626. +188 17 66 189 17 66 191 17 67 170 15 60 79 7 28 5 0 2
  98627. +0 0 0 10 1 3 78 7 27 159 14 56 188 17 66 75 7 26
  98628. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98629. +0 0 0 0 0 0 0 0 0
  98630. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98631. +0 0 0 0 0 0 1 0 0 35 3 12 29 3 10 2 0 1
  98632. +0 0 0 0 0 0 0 0 0 9 1 3 101 9 35 183 17 64
  98633. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98634. +188 17 66 188 17 66 190 17 67 178 16 63 67 6 23 0 0 0
  98635. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 174 16 61
  98636. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98637. +188 17 66 188 17 66 188 17 66 190 17 67 182 16 64 89 8 31
  98638. +4 0 1 0 0 0 0 0 0 25 2 9 73 7 26 31 3 11
  98639. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98640. +0 0 0 0 0 0 0 0 0
  98641. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98642. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98643. +0 0 0 0 0 0 4 0 1 98 9 34 187 17 66 189 17 66
  98644. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98645. +188 17 66 188 17 66 188 17 66 190 17 67 158 14 55 25 2 9
  98646. +0 0 0 0 0 0 0 0 0 8 1 3 134 12 47 191 17 67
  98647. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98648. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 180 16 63
  98649. +68 6 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98650. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98651. +0 0 0 0 0 0 0 0 0
  98652. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98653. +0 0 0 6 1 2 19 2 7 3 0 1 0 0 0 0 0 0
  98654. +0 0 0 0 0 0 65 6 23 180 16 63 189 17 66 188 17 66
  98655. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98656. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 83 8 29
  98657. +0 0 0 0 0 0 0 0 0 41 4 14 177 16 62 189 17 66
  98658. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98659. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  98660. +159 14 56 28 3 10 0 0 0 0 0 0 0 0 0 23 2 8
  98661. +41 4 14 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0
  98662. +0 0 0 0 0 0 0 0 0
  98663. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98664. +23 2 8 113 10 40 159 14 56 65 6 23 0 0 0 0 0 0
  98665. +0 0 0 16 1 6 146 13 51 191 17 67 188 17 66 188 17 66
  98666. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98667. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 132 12 46
  98668. +5 0 2 0 0 0 0 0 0 77 7 27 189 17 66 188 17 66
  98669. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98670. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98671. +190 17 67 98 9 34 0 0 0 0 0 0 12 1 4 134 12 47
  98672. +178 16 63 108 10 38 16 1 6 0 0 0 0 0 0 0 0 0
  98673. +0 0 0 0 0 0 0 0 0
  98674. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 3 10
  98675. +141 13 49 190 17 67 191 17 67 134 12 47 6 1 2 0 0 0
  98676. +0 0 0 68 6 24 186 17 65 188 17 66 188 17 66 188 17 66
  98677. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98678. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 156 14 55
  98679. +14 1 5 0 0 0 0 0 0 98 9 34 191 17 67 188 17 66
  98680. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98681. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98682. +190 17 67 156 14 55 19 2 7 0 0 0 47 4 16 181 16 63
  98683. +190 17 67 189 17 66 126 14 44 17 2 6 0 0 0 0 0 0
  98684. +0 0 0 0 0 0 0 0 0
  98685. +0 0 0 0 0 0 0 0 0 0 0 0 16 1 6 134 12 47
  98686. +191 17 67 188 17 66 190 17 67 162 15 57 19 2 7 0 0 0
  98687. +3 0 1 123 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  98688. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98689. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 163 15 57
  98690. +20 2 7 0 0 0 0 0 0 101 9 35 191 17 67 188 17 66
  98691. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98692. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98693. +188 17 66 182 16 64 52 5 18 0 0 0 73 7 26 188 17 66
  98694. +188 17 66 188 17 66 189 17 66 109 10 38 5 0 2 0 0 0
  98695. +0 0 0 0 0 0 0 0 0
  98696. +0 0 0 0 0 0 0 0 0 0 0 0 95 9 33 189 17 66
  98697. +188 17 66 188 17 66 189 17 66 171 15 60 29 3 10 0 0 0
  98698. +16 1 6 156 14 55 190 17 67 188 17 66 188 17 66 188 17 66
  98699. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98700. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 158 14 55
  98701. +17 2 6 0 0 0 0 0 0 85 8 30 190 17 67 188 17 66
  98702. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98703. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98704. +188 17 66 189 17 66 81 7 29 0 0 0 85 8 30 190 17 67
  98705. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  98706. +0 0 0 0 0 0 0 0 0
  98707. +0 0 0 0 0 0 0 0 0 25 2 9 162 15 57 190 17 67
  98708. +188 17 66 188 17 66 189 17 66 173 16 61 31 3 11 0 0 0
  98709. +30 3 10 171 15 60 189 17 66 188 17 66 188 17 66 188 17 66
  98710. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98711. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 141 13 49
  98712. +7 1 2 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  98713. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98714. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98715. +188 17 66 191 17 67 98 9 34 0 0 0 88 8 31 190 17 67
  98716. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 5 0 2
  98717. +0 0 0 0 0 0 0 0 0
  98718. +0 0 0 0 0 0 0 0 0 68 6 24 187 17 66 188 17 66
  98719. +188 17 66 188 17 66 189 17 66 170 15 60 28 3 10 0 0 0
  98720. +34 3 12 174 16 61 189 17 66 188 17 66 188 17 66 188 17 66
  98721. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98722. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 101 9 35
  98723. +0 0 0 0 0 0 0 0 0 21 2 7 159 14 56 190 17 67
  98724. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98725. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98726. +188 17 66 191 17 67 98 9 34 0 0 0 81 7 29 189 17 66
  98727. +188 17 66 188 17 66 188 17 66 189 17 66 168 15 59 28 3 10
  98728. +0 0 0 0 0 0 0 0 0
  98729. +0 0 0 0 0 0 0 0 0 109 10 38 191 17 67 188 17 66
  98730. +188 17 66 188 17 66 190 17 67 163 15 57 21 2 7 0 0 0
  98731. +26 2 9 168 15 59 189 17 66 188 17 66 188 17 66 188 17 66
  98732. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98733. +188 17 66 188 17 66 188 17 66 189 17 66 180 16 63 47 4 16
  98734. +0 0 0 0 0 0 0 0 0 0 0 0 108 10 38 190 17 67
  98735. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98736. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98737. +188 17 66 189 17 66 78 7 27 0 0 0 68 6 24 187 17 66
  98738. +188 17 66 188 17 66 188 17 66 188 17 66 183 17 64 56 5 19
  98739. +0 0 0 0 0 0 0 0 0
  98740. +0 0 0 0 0 0 3 0 1 131 12 46 191 17 67 188 17 66
  98741. +188 17 66 188 17 66 190 17 67 151 14 53 12 1 4 0 0 0
  98742. +11 1 4 146 13 51 190 17 67 188 17 66 188 17 66 188 17 66
  98743. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98744. +188 17 66 188 17 66 188 17 66 191 17 67 126 14 44 7 1 2
  98745. +0 0 0 0 0 0 0 0 0 0 0 0 32 3 11 164 15 58
  98746. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98747. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98748. +189 17 66 178 16 62 44 4 15 0 0 0 50 5 17 182 16 64
  98749. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  98750. +0 0 0 0 0 0 0 0 0
  98751. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 188 17 66
  98752. +188 17 66 188 17 66 191 17 67 131 12 46 3 0 1 0 0 0
  98753. +0 0 0 101 9 35 190 17 67 188 17 66 188 17 66 188 17 66
  98754. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98755. +188 17 66 188 17 66 190 17 67 170 15 60 44 4 15 0 0 0
  98756. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 7 27
  98757. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98758. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98759. +191 17 67 134 12 47 9 1 3 0 0 0 31 3 11 171 15 60
  98760. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  98761. +0 0 0 0 0 0 0 0 0
  98762. +0 0 0 0 0 0 2 0 1 124 11 43 191 17 67 188 17 66
  98763. +188 17 66 188 17 66 191 17 67 101 9 35 0 0 0 0 0 0
  98764. +0 0 0 35 3 12 168 15 59 190 17 67 188 17 66 188 17 66
  98765. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98766. +188 17 66 189 17 66 182 16 64 77 7 27 0 0 0 0 0 0
  98767. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2
  98768. +99 9 35 185 17 65 189 17 66 188 17 66 188 17 66 188 17 66
  98769. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  98770. +177 16 62 56 5 19 0 0 0 0 0 0 13 1 5 151 14 53
  98771. +190 17 67 188 17 66 188 17 66 188 17 66 185 17 65 56 5 19
  98772. +0 0 0 0 0 0 0 0 0
  98773. +0 0 0 0 0 0 0 0 0 99 9 35 191 17 67 188 17 66
  98774. +188 17 66 188 17 66 186 17 65 65 6 23 0 0 0 0 0 0
  98775. +0 0 0 0 0 0 79 7 28 182 16 64 190 17 67 188 17 66
  98776. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98777. +191 17 67 177 16 62 83 8 29 4 0 1 0 0 0 0 0 0
  98778. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98779. +8 1 3 89 8 31 175 16 62 191 17 67 189 17 66 188 17 66
  98780. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 181 16 63
  98781. +85 8 30 3 0 1 0 0 0 0 0 0 1 0 0 118 13 41
  98782. +191 17 67 188 17 66 188 17 66 189 17 66 173 16 61 34 3 12
  98783. +0 0 0 0 0 0 0 0 0
  98784. +0 0 0 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  98785. +188 17 66 189 17 66 169 15 59 30 3 10 0 0 0 0 0 0
  98786. +0 0 0 0 0 0 5 0 2 83 8 29 173 16 61 191 17 67
  98787. +190 17 67 189 17 66 189 17 66 190 17 67 191 17 67 187 17 66
  98788. +151 14 53 56 5 19 3 0 1 0 0 0 16 1 6 50 5 17
  98789. +79 7 28 95 9 33 95 9 33 75 7 26 41 4 14 10 1 4
  98790. +0 0 0 2 0 1 50 5 17 132 12 46 178 16 62 190 17 67
  98791. +191 17 67 191 17 67 191 17 67 186 17 65 154 14 54 68 6 24
  98792. +4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  98793. +187 17 66 188 17 66 188 17 66 191 17 67 141 13 49 9 1 3
  98794. +0 0 0 0 0 0 0 0 0
  98795. +0 0 0 0 0 0 0 0 0 14 1 5 151 14 53 190 17 67
  98796. +188 17 66 191 17 67 131 12 46 5 0 2 0 0 0 0 0 0
  98797. +0 0 0 0 0 0 0 0 0 2 0 1 44 4 15 113 10 40
  98798. +156 14 55 173 16 61 174 16 61 164 15 58 134 12 47 77 7 27
  98799. +18 2 6 0 0 0 16 1 6 85 8 30 151 14 53 182 16 64
  98800. +189 17 66 191 17 67 190 17 67 188 17 66 177 16 62 141 13 49
  98801. +68 6 24 8 1 3 0 0 0 8 1 3 44 4 15 88 8 31
  98802. +113 10 40 122 11 43 108 10 38 67 6 24 20 2 7 0 0 0
  98803. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 3 10
  98804. +166 15 58 190 17 67 188 17 66 187 17 66 79 7 28 0 0 0
  98805. +0 0 0 0 0 0 0 0 0
  98806. +0 0 0 0 0 0 0 0 0 0 0 0 73 7 26 185 17 65
  98807. +189 17 66 184 17 65 65 6 23 0 0 0 0 0 0 0 0 0
  98808. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
  98809. +17 2 6 32 3 11 34 3 12 22 2 8 6 1 2 0 0 0
  98810. +0 0 0 38 3 13 141 13 49 188 17 66 190 17 67 188 17 66
  98811. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  98812. +184 17 65 122 11 43 21 2 7 0 0 0 0 0 0 0 0 0
  98813. +0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98814. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  98815. +108 10 38 191 17 67 191 17 67 141 13 49 16 1 6 0 0 0
  98816. +0 0 0 0 0 0 0 0 0
  98817. +0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 112 10 39
  98818. +186 17 65 124 11 43 10 1 4 0 0 0 0 0 0 0 0 0
  98819. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98820. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98821. +36 3 13 156 14 55 191 17 67 188 17 66 188 17 66 188 17 66
  98822. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98823. +189 17 66 190 17 67 134 12 47 18 2 6 0 0 0 0 0 0
  98824. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98825. +0 0 0 7 1 2 41 4 14 75 7 26 66 5 23 19 2 7
  98826. +26 2 9 144 13 50 154 14 54 40 4 14 0 0 0 0 0 0
  98827. +0 0 0 0 0 0 0 0 0
  98828. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  98829. +56 5 19 19 2 7 0 0 0 7 1 2 29 3 10 35 3 12
  98830. +19 2 7 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  98831. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  98832. +134 12 47 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  98833. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98834. +188 17 66 188 17 66 189 17 67 108 10 38 3 0 1 0 0 0
  98835. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  98836. +40 4 14 124 11 43 177 16 62 188 17 66 187 17 66 144 13 50
  98837. +24 2 8 17 2 6 22 2 8 0 0 0 0 0 0 0 0 0
  98838. +0 0 0 0 0 0 0 0 0
  98839. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98840. +0 0 0 0 0 0 19 2 7 122 11 43 171 15 60 175 16 62
  98841. +159 14 56 112 10 39 40 4 14 2 0 1 0 0 0 0 0 0
  98842. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  98843. +186 17 65 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98844. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98845. +188 17 66 188 17 66 189 17 66 174 16 61 41 4 14 0 0 0
  98846. +0 0 0 0 0 0 0 0 0 0 0 0 3 0 1 72 7 25
  98847. +168 15 59 191 17 67 189 17 66 188 17 66 188 17 66 190 17 67
  98848. +95 9 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98849. +0 0 0 0 0 0 0 0 0
  98850. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98851. +0 0 0 0 0 0 95 9 33 191 17 67 189 17 66 189 17 66
  98852. +190 17 67 191 17 67 171 15 60 90 8 32 12 1 4 0 0 0
  98853. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 132 12 46
  98854. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98855. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98856. +188 17 66 188 17 66 188 17 66 190 17 67 98 9 34 0 0 0
  98857. +0 0 0 0 0 0 0 0 0 5 0 2 88 8 31 180 16 63
  98858. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 191 17 67
  98859. +146 13 51 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  98860. +0 0 0 0 0 0 0 0 0
  98861. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98862. +0 0 0 9 1 3 144 13 50 191 17 67 188 17 66 188 17 66
  98863. +188 17 66 188 17 66 189 17 66 187 17 66 123 11 43 20 2 7
  98864. +0 0 0 0 0 0 0 0 0 0 0 0 21 2 7 163 15 57
  98865. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98866. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98867. +188 17 66 188 17 66 188 17 66 191 17 67 134 12 47 5 0 2
  98868. +0 0 0 0 0 0 3 0 1 88 8 31 182 16 64 189 17 66
  98869. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  98870. +171 15 60 31 3 11 0 0 0 0 0 0 0 0 0 0 0 0
  98871. +0 0 0 0 0 0 0 0 0
  98872. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98873. +0 0 0 20 2 7 162 15 57 190 17 67 188 17 66 188 17 66
  98874. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 132 12 46
  98875. +20 2 7 0 0 0 0 0 0 0 0 0 32 3 11 173 16 61
  98876. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98877. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98878. +188 17 66 188 17 66 188 17 66 190 17 67 151 14 53 12 1 4
  98879. +0 0 0 0 0 0 72 7 25 180 16 63 189 17 66 188 17 66
  98880. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98881. +181 16 63 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  98882. +0 0 0 0 0 0 0 0 0
  98883. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98884. +0 0 0 21 2 7 163 15 57 190 17 67 188 17 66 188 17 66
  98885. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  98886. +122 11 43 9 1 3 0 0 0 0 0 0 30 3 10 171 15 60
  98887. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98888. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98889. +188 17 66 188 17 66 188 17 66 190 17 67 146 13 51 10 1 4
  98890. +0 0 0 38 3 13 166 15 58 190 17 67 188 17 66 188 17 66
  98891. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98892. +183 17 64 52 5 18 0 0 0 0 0 0 0 0 0 0 0 0
  98893. +0 0 0 0 0 0 0 0 0
  98894. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98895. +0 0 0 13 1 5 154 14 54 190 17 67 188 17 66 188 17 66
  98896. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98897. +186 17 65 79 7 28 0 0 0 0 0 0 14 1 5 156 14 54
  98898. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98899. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98900. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 2 0 1
  98901. +5 0 2 122 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  98902. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98903. +182 16 64 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  98904. +0 0 0 0 0 0 0 0 0
  98905. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98906. +0 0 0 3 0 1 126 14 44 191 17 67 188 17 66 188 17 66
  98907. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98908. +190 17 67 158 14 55 23 2 8 0 0 0 1 0 0 113 10 40
  98909. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98910. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98911. +188 17 66 188 17 66 188 17 66 188 17 66 78 7 27 0 0 0
  98912. +47 4 16 177 16 62 189 17 66 188 17 66 188 17 66 188 17 66
  98913. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  98914. +173 16 61 34 3 12 0 0 0 0 0 0 0 0 0 0 0 0
  98915. +0 0 0 0 0 0 0 0 0
  98916. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98917. +0 0 0 0 0 0 85 8 30 189 17 66 188 17 66 188 17 66
  98918. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98919. +188 17 66 188 17 66 79 7 28 0 0 0 0 0 0 47 4 16
  98920. +175 16 62 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98921. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98922. +188 17 66 188 17 66 190 17 67 156 14 55 22 2 8 0 0 0
  98923. +109 10 38 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  98924. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  98925. +151 14 53 13 1 5 0 0 0 0 0 0 0 0 0 0 0 0
  98926. +0 0 0 0 0 0 0 0 0
  98927. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98928. +0 0 0 0 0 0 35 3 12 173 16 61 189 17 66 188 17 66
  98929. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98930. +188 17 66 191 17 67 134 12 47 7 1 2 0 0 0 3 0 1
  98931. +99 9 35 188 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  98932. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98933. +188 17 66 189 17 66 181 16 63 68 6 24 0 0 0 18 2 6
  98934. +156 14 55 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  98935. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  98936. +101 9 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98937. +0 0 0 0 0 0 0 0 0
  98938. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98939. +0 0 0 0 0 0 3 0 1 118 13 41 191 17 67 188 17 66
  98940. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98941. +188 17 66 189 17 66 168 15 59 28 3 10 0 0 0 0 0 0
  98942. +12 1 4 113 10 40 187 17 66 189 17 67 188 17 66 188 17 66
  98943. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98944. +190 17 67 180 16 63 88 8 31 4 0 1 0 0 0 47 4 16
  98945. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98946. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 168 15 59
  98947. +36 3 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98948. +0 0 0 0 0 0 0 0 0
  98949. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98950. +0 0 0 0 0 0 0 0 0 38 3 13 164 15 58 190 17 67
  98951. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98952. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  98953. +0 0 0 11 1 4 90 8 32 169 15 59 190 17 67 190 17 67
  98954. +189 17 66 189 17 66 189 17 66 189 17 66 191 17 67 189 17 66
  98955. +158 14 55 68 6 24 4 0 1 0 0 0 0 0 0 73 7 26
  98956. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98957. +188 17 66 188 17 66 188 17 66 189 17 66 185 17 65 83 8 29
  98958. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98959. +0 0 0 0 0 0 0 0 0
  98960. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98961. +0 0 0 0 0 0 0 0 0 0 0 0 65 6 23 174 16 61
  98962. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98963. +188 17 66 188 17 66 185 17 65 56 5 19 0 0 0 0 0 0
  98964. +0 0 0 0 0 0 2 0 1 35 3 12 99 9 35 146 13 51
  98965. +170 15 60 177 16 62 177 16 62 166 15 58 141 13 49 85 8 30
  98966. +24 2 8 0 0 0 0 0 0 0 0 0 0 0 0 85 8 30
  98967. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98968. +188 17 66 188 17 66 188 17 66 189 17 66 112 10 39 8 1 3
  98969. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98970. +0 0 0 0 0 0 0 0 0
  98971. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98972. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 68 6 24
  98973. +170 15 60 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  98974. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  98975. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 11 1 4
  98976. +28 3 10 40 4 14 38 3 13 25 2 9 8 1 3 0 0 0
  98977. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 78 7 27
  98978. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98979. +188 17 66 189 17 66 187 17 66 113 10 40 14 1 5 0 0 0
  98980. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98981. +0 0 0 0 0 0 0 0 0
  98982. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98983. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  98984. +47 4 16 141 13 49 186 17 65 191 17 67 190 17 67 189 17 66
  98985. +189 17 66 191 17 67 156 14 55 20 2 7 0 0 0 0 0 0
  98986. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98987. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98988. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 4 15
  98989. +178 16 62 190 17 67 188 17 66 188 17 66 188 17 66 190 17 67
  98990. +191 17 67 173 16 61 90 8 32 10 1 4 0 0 0 0 0 0
  98991. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98992. +0 0 0 0 0 0 0 0 0
  98993. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98994. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98995. +0 0 0 14 1 5 68 6 24 131 12 46 162 15 57 174 16 61
  98996. +171 15 60 146 13 51 56 5 19 0 0 0 0 0 0 0 0 0
  98997. +0 0 0 0 0 0 0 0 0 3 0 1 14 1 5 29 3 10
  98998. +41 4 14 47 4 16 50 5 17 45 4 16 34 3 12 18 2 6
  98999. +5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  99000. +90 8 32 169 15 59 185 17 65 187 17 66 182 16 64 163 15 57
  99001. +113 10 40 41 4 14 2 0 1 0 0 0 0 0 0 0 0 0
  99002. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99003. +0 0 0 0 0 0 0 0 0
  99004. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99005. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99006. +0 0 0 0 0 0 0 0 0 5 0 2 21 2 7 34 3 12
  99007. +29 3 10 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  99008. +3 0 1 32 3 11 79 7 28 124 11 43 154 14 54 171 15 60
  99009. +180 16 63 182 16 64 182 16 64 180 16 63 174 16 61 159 14 56
  99010. +132 12 46 88 8 31 34 3 12 3 0 1 0 0 0 0 0 0
  99011. +3 0 1 29 3 10 56 5 19 65 6 23 50 5 17 23 2 8
  99012. +3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99013. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99014. +0 0 0 0 0 0 0 0 0
  99015. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99016. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99017. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99018. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 2 9
  99019. +109 10 38 169 15 59 189 17 66 191 17 67 190 17 67 189 17 66
  99020. +189 17 66 188 17 66 188 17 66 188 17 66 189 17 66 190 17 67
  99021. +191 17 67 190 17 67 171 15 60 98 9 34 10 1 3 0 0 0
  99022. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99023. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99024. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99025. +0 0 0 0 0 0 0 0 0
  99026. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99027. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99028. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99029. +0 0 0 0 0 0 0 0 0 0 0 0 14 1 5 141 13 49
  99030. +191 17 67 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99031. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99032. +188 17 66 188 17 66 189 17 67 186 17 65 65 6 23 0 0 0
  99033. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99034. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99035. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99036. +0 0 0 0 0 0 0 0 0
  99037. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99038. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99039. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99040. +0 0 0 0 0 0 0 0 0 0 0 0 23 2 8 166 15 58
  99041. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99042. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99043. +188 17 66 188 17 66 189 17 66 176 16 62 45 4 16 0 0 0
  99044. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99045. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99046. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99047. +0 0 0 0 0 0 0 0 0
  99048. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99049. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99050. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99051. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 83 8 29
  99052. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99053. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99054. +188 17 66 189 17 66 185 17 65 95 9 33 3 0 1 0 0 0
  99055. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99056. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99057. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99058. +0 0 0 0 0 0 0 0 0
  99059. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99060. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99061. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99062. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  99063. +85 8 30 176 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  99064. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99065. +191 17 67 180 16 63 95 9 33 7 1 3 0 0 0 0 0 0
  99066. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99067. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99068. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99069. +0 0 0 0 0 0 0 0 0
  99070. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99071. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99072. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99073. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99074. +2 0 1 52 5 18 141 13 49 185 17 65 191 17 67 189 17 67
  99075. +189 17 66 188 17 66 188 17 66 189 17 66 191 17 67 187 17 66
  99076. +146 13 51 56 5 19 4 0 1 0 0 0 0 0 0 0 0 0
  99077. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99078. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99079. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99080. +0 0 0 0 0 0 0 0 0
  99081. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99082. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99083. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99084. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99085. +0 0 0 0 0 0 14 1 5 68 6 24 131 12 46 166 15 58
  99086. +180 16 63 183 17 64 180 16 63 168 15 59 134 12 47 75 7 26
  99087. +17 2 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99088. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99089. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99090. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99091. +0 0 0 0 0 0 0 0 0
  99092. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99093. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99094. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99095. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99096. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 24 2 8
  99097. +44 4 15 52 5 18 45 4 16 26 2 9 6 1 2 0 0 0
  99098. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99099. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99100. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99101. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99102. +0 0 0 0 0 0 0 0 0
  99103. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99104. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99105. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99106. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99107. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99108. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99109. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99110. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99111. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99112. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99113. +0 0 0 0 0 0 0 0 0
  99114. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99115. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99116. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99117. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99118. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99119. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99120. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99121. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99122. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99123. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99124. +0 0 0 0 0 0 0 0 0
  99125. diff -Nur linux-3.12.18/drivers/video/Makefile linux-rpi/drivers/video/Makefile
  99126. --- linux-3.12.18/drivers/video/Makefile 2014-04-18 11:14:28.000000000 +0200
  99127. +++ linux-rpi/drivers/video/Makefile 2014-04-24 15:35:04.249566623 +0200
  99128. @@ -100,6 +100,7 @@
  99129. obj-$(CONFIG_FB_VOODOO1) += sstfb.o
  99130. obj-$(CONFIG_FB_ARMCLCD) += amba-clcd.o
  99131. obj-$(CONFIG_FB_GOLDFISH) += goldfishfb.o
  99132. +obj-$(CONFIG_FB_BCM2708) += bcm2708_fb.o
  99133. obj-$(CONFIG_FB_68328) += 68328fb.o
  99134. obj-$(CONFIG_FB_GBE) += gbefb.o
  99135. obj-$(CONFIG_FB_CIRRUS) += cirrusfb.o
  99136. diff -Nur linux-3.12.18/drivers/video/sh_mobile_lcdcfb.c linux-rpi/drivers/video/sh_mobile_lcdcfb.c
  99137. --- linux-3.12.18/drivers/video/sh_mobile_lcdcfb.c 2014-04-18 11:14:28.000000000 +0200
  99138. +++ linux-rpi/drivers/video/sh_mobile_lcdcfb.c 2014-04-24 15:35:04.325567469 +0200
  99139. @@ -574,9 +574,8 @@
  99140. switch (event) {
  99141. case SH_MOBILE_LCDC_EVENT_DISPLAY_CONNECT:
  99142. /* HDMI plug in */
  99143. - console_lock();
  99144. if (lock_fb_info(info)) {
  99145. -
  99146. + console_lock();
  99147. ch->display.width = monspec->max_x * 10;
  99148. ch->display.height = monspec->max_y * 10;
  99149. @@ -595,20 +594,19 @@
  99150. fb_set_suspend(info, 0);
  99151. }
  99152. -
  99153. + console_unlock();
  99154. unlock_fb_info(info);
  99155. }
  99156. - console_unlock();
  99157. break;
  99158. case SH_MOBILE_LCDC_EVENT_DISPLAY_DISCONNECT:
  99159. /* HDMI disconnect */
  99160. - console_lock();
  99161. if (lock_fb_info(info)) {
  99162. + console_lock();
  99163. fb_set_suspend(info, 1);
  99164. + console_unlock();
  99165. unlock_fb_info(info);
  99166. }
  99167. - console_unlock();
  99168. break;
  99169. case SH_MOBILE_LCDC_EVENT_DISPLAY_MODE:
  99170. diff -Nur linux-3.12.18/drivers/w1/masters/w1-gpio.c linux-rpi/drivers/w1/masters/w1-gpio.c
  99171. --- linux-3.12.18/drivers/w1/masters/w1-gpio.c 2014-04-18 11:14:28.000000000 +0200
  99172. +++ linux-rpi/drivers/w1/masters/w1-gpio.c 2014-04-24 16:04:39.951125530 +0200
  99173. @@ -22,6 +22,9 @@
  99174. #include "../w1.h"
  99175. #include "../w1_int.h"
  99176. +static int w1_gpio_pullup = 0;
  99177. +module_param_named(pullup, w1_gpio_pullup, int, 0);
  99178. +
  99179. static void w1_gpio_write_bit_dir(void *data, u8 bit)
  99180. {
  99181. struct w1_gpio_platform_data *pdata = data;
  99182. @@ -46,6 +49,16 @@
  99183. return gpio_get_value(pdata->pin) ? 1 : 0;
  99184. }
  99185. +static void w1_gpio_bitbang_pullup(void *data, u8 on)
  99186. +{
  99187. + struct w1_gpio_platform_data *pdata = data;
  99188. +
  99189. + if (on)
  99190. + gpio_direction_output(pdata->pin, 1);
  99191. + else
  99192. + gpio_direction_input(pdata->pin);
  99193. +}
  99194. +
  99195. #if defined(CONFIG_OF)
  99196. static struct of_device_id w1_gpio_dt_ids[] = {
  99197. { .compatible = "w1-gpio" },
  99198. @@ -127,6 +140,13 @@
  99199. master->write_bit = w1_gpio_write_bit_dir;
  99200. }
  99201. + if (w1_gpio_pullup)
  99202. + if (pdata->is_open_drain)
  99203. + printk(KERN_ERR "w1-gpio 'pullup' option "
  99204. + "doesn't work with open drain GPIO\n");
  99205. + else
  99206. + master->bitbang_pullup = w1_gpio_bitbang_pullup;
  99207. +
  99208. err = w1_add_master_device(master);
  99209. if (err) {
  99210. dev_err(&pdev->dev, "w1_add_master device failed\n");
  99211. diff -Nur linux-3.12.18/drivers/w1/w1.h linux-rpi/drivers/w1/w1.h
  99212. --- linux-3.12.18/drivers/w1/w1.h 2014-04-18 11:14:28.000000000 +0200
  99213. +++ linux-rpi/drivers/w1/w1.h 2014-04-24 15:35:04.349567736 +0200
  99214. @@ -148,6 +148,12 @@
  99215. */
  99216. u8 (*set_pullup)(void *, int);
  99217. + /**
  99218. + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
  99219. + * @return -1=Error, 0=completed
  99220. + */
  99221. + void (*bitbang_pullup) (void *, u8);
  99222. +
  99223. /** Really nice hardware can handles the different types of ROM search
  99224. * w1_master* is passed to the slave found callback.
  99225. */
  99226. diff -Nur linux-3.12.18/drivers/w1/w1_int.c linux-rpi/drivers/w1/w1_int.c
  99227. --- linux-3.12.18/drivers/w1/w1_int.c 2014-04-18 11:14:28.000000000 +0200
  99228. +++ linux-rpi/drivers/w1/w1_int.c 2014-04-24 16:04:39.955125569 +0200
  99229. @@ -130,6 +130,20 @@
  99230. master->set_pullup = NULL;
  99231. }
  99232. + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
  99233. + * and takes care of timing itself */
  99234. + if (!master->write_byte && !master->touch_bit && master->set_pullup) {
  99235. + printk(KERN_ERR "w1_add_master_device: set_pullup requires "
  99236. + "write_byte or touch_bit, disabling\n");
  99237. + master->set_pullup = NULL;
  99238. + }
  99239. +
  99240. + if (master->set_pullup && master->bitbang_pullup) {
  99241. + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
  99242. + "be set when bitbang_pullup is used, disabling\n");
  99243. + master->set_pullup = NULL;
  99244. + }
  99245. +
  99246. /* Lock until the device is added (or not) to w1_masters. */
  99247. mutex_lock(&w1_mlock);
  99248. /* Search for the first available id (starting at 1). */
  99249. diff -Nur linux-3.12.18/drivers/w1/w1_io.c linux-rpi/drivers/w1/w1_io.c
  99250. --- linux-3.12.18/drivers/w1/w1_io.c 2014-04-18 11:14:28.000000000 +0200
  99251. +++ linux-rpi/drivers/w1/w1_io.c 2014-04-24 15:35:04.349567736 +0200
  99252. @@ -127,10 +127,22 @@
  99253. static void w1_post_write(struct w1_master *dev)
  99254. {
  99255. if (dev->pullup_duration) {
  99256. - if (dev->enable_pullup && dev->bus_master->set_pullup)
  99257. - dev->bus_master->set_pullup(dev->bus_master->data, 0);
  99258. - else
  99259. + if (dev->enable_pullup) {
  99260. + if (dev->bus_master->set_pullup) {
  99261. + dev->bus_master->set_pullup(dev->
  99262. + bus_master->data,
  99263. + 0);
  99264. + } else if (dev->bus_master->bitbang_pullup) {
  99265. + dev->bus_master->
  99266. + bitbang_pullup(dev->bus_master->data, 1);
  99267. msleep(dev->pullup_duration);
  99268. + dev->bus_master->
  99269. + bitbang_pullup(dev->bus_master->data, 0);
  99270. + }
  99271. + } else {
  99272. + msleep(dev->pullup_duration);
  99273. + }
  99274. +
  99275. dev->pullup_duration = 0;
  99276. }
  99277. }
  99278. diff -Nur linux-3.12.18/drivers/watchdog/bcm2708_wdog.c linux-rpi/drivers/watchdog/bcm2708_wdog.c
  99279. --- linux-3.12.18/drivers/watchdog/bcm2708_wdog.c 1970-01-01 01:00:00.000000000 +0100
  99280. +++ linux-rpi/drivers/watchdog/bcm2708_wdog.c 2014-04-24 16:04:39.955125569 +0200
  99281. @@ -0,0 +1,384 @@
  99282. +/*
  99283. + * Broadcom BCM2708 watchdog driver.
  99284. + *
  99285. + * (c) Copyright 2010 Broadcom Europe Ltd
  99286. + *
  99287. + * This program is free software; you can redistribute it and/or
  99288. + * modify it under the terms of the GNU General Public License
  99289. + * as published by the Free Software Foundation; either version
  99290. + * 2 of the License, or (at your option) any later version.
  99291. + *
  99292. + * BCM2708 watchdog driver. Loosely based on wdt driver.
  99293. + */
  99294. +
  99295. +#include <linux/interrupt.h>
  99296. +#include <linux/module.h>
  99297. +#include <linux/moduleparam.h>
  99298. +#include <linux/types.h>
  99299. +#include <linux/miscdevice.h>
  99300. +#include <linux/watchdog.h>
  99301. +#include <linux/fs.h>
  99302. +#include <linux/ioport.h>
  99303. +#include <linux/notifier.h>
  99304. +#include <linux/reboot.h>
  99305. +#include <linux/init.h>
  99306. +#include <linux/io.h>
  99307. +#include <linux/uaccess.h>
  99308. +#include <mach/platform.h>
  99309. +
  99310. +#include <asm/system.h>
  99311. +
  99312. +#define SECS_TO_WDOG_TICKS(x) ((x) << 16)
  99313. +#define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
  99314. +
  99315. +static unsigned long wdog_is_open;
  99316. +static uint32_t wdog_ticks; /* Ticks to load into wdog timer */
  99317. +static char expect_close;
  99318. +
  99319. +/*
  99320. + * Module parameters
  99321. + */
  99322. +
  99323. +#define WD_TIMO 10 /* Default heartbeat = 60 seconds */
  99324. +static int heartbeat = WD_TIMO; /* Heartbeat in seconds */
  99325. +
  99326. +module_param(heartbeat, int, 0);
  99327. +MODULE_PARM_DESC(heartbeat,
  99328. + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  99329. + __MODULE_STRING(WD_TIMO) ")");
  99330. +
  99331. +static int nowayout = WATCHDOG_NOWAYOUT;
  99332. +module_param(nowayout, int, 0);
  99333. +MODULE_PARM_DESC(nowayout,
  99334. + "Watchdog cannot be stopped once started (default="
  99335. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  99336. +
  99337. +static DEFINE_SPINLOCK(wdog_lock);
  99338. +
  99339. +/**
  99340. + * Start the watchdog driver.
  99341. + */
  99342. +
  99343. +static int wdog_start(unsigned long timeout)
  99344. +{
  99345. + uint32_t cur;
  99346. + unsigned long flags;
  99347. + spin_lock_irqsave(&wdog_lock, flags);
  99348. +
  99349. + /* enable the watchdog */
  99350. + iowrite32(PM_PASSWORD | (timeout & PM_WDOG_TIME_SET),
  99351. + __io_address(PM_WDOG));
  99352. + cur = ioread32(__io_address(PM_RSTC));
  99353. + iowrite32(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) |
  99354. + PM_RSTC_WRCFG_FULL_RESET, __io_address(PM_RSTC));
  99355. +
  99356. + spin_unlock_irqrestore(&wdog_lock, flags);
  99357. + return 0;
  99358. +}
  99359. +
  99360. +/**
  99361. + * Stop the watchdog driver.
  99362. + */
  99363. +
  99364. +static int wdog_stop(void)
  99365. +{
  99366. + iowrite32(PM_PASSWORD | PM_RSTC_RESET, __io_address(PM_RSTC));
  99367. + printk(KERN_INFO "watchdog stopped\n");
  99368. + return 0;
  99369. +}
  99370. +
  99371. +/**
  99372. + * Reload counter one with the watchdog heartbeat. We don't bother
  99373. + * reloading the cascade counter.
  99374. + */
  99375. +
  99376. +static void wdog_ping(void)
  99377. +{
  99378. + wdog_start(wdog_ticks);
  99379. +}
  99380. +
  99381. +/**
  99382. + * @t: the new heartbeat value that needs to be set.
  99383. + *
  99384. + * Set a new heartbeat value for the watchdog device. If the heartbeat
  99385. + * value is incorrect we keep the old value and return -EINVAL. If
  99386. + * successful we return 0.
  99387. + */
  99388. +
  99389. +static int wdog_set_heartbeat(int t)
  99390. +{
  99391. + if (t < 1 || t > WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET))
  99392. + return -EINVAL;
  99393. +
  99394. + heartbeat = t;
  99395. + wdog_ticks = SECS_TO_WDOG_TICKS(t);
  99396. + return 0;
  99397. +}
  99398. +
  99399. +/**
  99400. + * @file: file handle to the watchdog
  99401. + * @buf: buffer to write (unused as data does not matter here
  99402. + * @count: count of bytes
  99403. + * @ppos: pointer to the position to write. No seeks allowed
  99404. + *
  99405. + * A write to a watchdog device is defined as a keepalive signal.
  99406. + *
  99407. + * if 'nowayout' is set then normally a close() is ignored. But
  99408. + * if you write 'V' first then the close() will stop the timer.
  99409. + */
  99410. +
  99411. +static ssize_t wdog_write(struct file *file, const char __user *buf,
  99412. + size_t count, loff_t *ppos)
  99413. +{
  99414. + if (count) {
  99415. + if (!nowayout) {
  99416. + size_t i;
  99417. +
  99418. + /* In case it was set long ago */
  99419. + expect_close = 0;
  99420. +
  99421. + for (i = 0; i != count; i++) {
  99422. + char c;
  99423. + if (get_user(c, buf + i))
  99424. + return -EFAULT;
  99425. + if (c == 'V')
  99426. + expect_close = 42;
  99427. + }
  99428. + }
  99429. + wdog_ping();
  99430. + }
  99431. + return count;
  99432. +}
  99433. +
  99434. +static int wdog_get_status(void)
  99435. +{
  99436. + unsigned long flags;
  99437. + int status = 0;
  99438. + spin_lock_irqsave(&wdog_lock, flags);
  99439. + /* FIXME: readback reset reason */
  99440. + spin_unlock_irqrestore(&wdog_lock, flags);
  99441. + return status;
  99442. +}
  99443. +
  99444. +static uint32_t wdog_get_remaining(void)
  99445. +{
  99446. + uint32_t ret = ioread32(__io_address(PM_WDOG));
  99447. + return ret & PM_WDOG_TIME_SET;
  99448. +}
  99449. +
  99450. +/**
  99451. + * @file: file handle to the device
  99452. + * @cmd: watchdog command
  99453. + * @arg: argument pointer
  99454. + *
  99455. + * The watchdog API defines a common set of functions for all watchdogs
  99456. + * according to their available features. We only actually usefully support
  99457. + * querying capabilities and current status.
  99458. + */
  99459. +
  99460. +static long wdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  99461. +{
  99462. + void __user *argp = (void __user *)arg;
  99463. + int __user *p = argp;
  99464. + int new_heartbeat;
  99465. + int status;
  99466. + int options;
  99467. + uint32_t remaining;
  99468. +
  99469. + struct watchdog_info ident = {
  99470. + .options = WDIOF_SETTIMEOUT|
  99471. + WDIOF_MAGICCLOSE|
  99472. + WDIOF_KEEPALIVEPING,
  99473. + .firmware_version = 1,
  99474. + .identity = "BCM2708",
  99475. + };
  99476. +
  99477. + switch (cmd) {
  99478. + case WDIOC_GETSUPPORT:
  99479. + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  99480. + case WDIOC_GETSTATUS:
  99481. + status = wdog_get_status();
  99482. + return put_user(status, p);
  99483. + case WDIOC_GETBOOTSTATUS:
  99484. + return put_user(0, p);
  99485. + case WDIOC_KEEPALIVE:
  99486. + wdog_ping();
  99487. + return 0;
  99488. + case WDIOC_SETTIMEOUT:
  99489. + if (get_user(new_heartbeat, p))
  99490. + return -EFAULT;
  99491. + if (wdog_set_heartbeat(new_heartbeat))
  99492. + return -EINVAL;
  99493. + wdog_ping();
  99494. + /* Fall */
  99495. + case WDIOC_GETTIMEOUT:
  99496. + return put_user(heartbeat, p);
  99497. + case WDIOC_GETTIMELEFT:
  99498. + remaining = WDOG_TICKS_TO_SECS(wdog_get_remaining());
  99499. + return put_user(remaining, p);
  99500. + case WDIOC_SETOPTIONS:
  99501. + if (get_user(options, p))
  99502. + return -EFAULT;
  99503. + if (options & WDIOS_DISABLECARD)
  99504. + wdog_stop();
  99505. + if (options & WDIOS_ENABLECARD)
  99506. + wdog_start(wdog_ticks);
  99507. + return 0;
  99508. + default:
  99509. + return -ENOTTY;
  99510. + }
  99511. +}
  99512. +
  99513. +/**
  99514. + * @inode: inode of device
  99515. + * @file: file handle to device
  99516. + *
  99517. + * The watchdog device has been opened. The watchdog device is single
  99518. + * open and on opening we load the counters.
  99519. + */
  99520. +
  99521. +static int wdog_open(struct inode *inode, struct file *file)
  99522. +{
  99523. + if (test_and_set_bit(0, &wdog_is_open))
  99524. + return -EBUSY;
  99525. + /*
  99526. + * Activate
  99527. + */
  99528. + wdog_start(wdog_ticks);
  99529. + return nonseekable_open(inode, file);
  99530. +}
  99531. +
  99532. +/**
  99533. + * @inode: inode to board
  99534. + * @file: file handle to board
  99535. + *
  99536. + * The watchdog has a configurable API. There is a religious dispute
  99537. + * between people who want their watchdog to be able to shut down and
  99538. + * those who want to be sure if the watchdog manager dies the machine
  99539. + * reboots. In the former case we disable the counters, in the latter
  99540. + * case you have to open it again very soon.
  99541. + */
  99542. +
  99543. +static int wdog_release(struct inode *inode, struct file *file)
  99544. +{
  99545. + if (expect_close == 42) {
  99546. + wdog_stop();
  99547. + } else {
  99548. + printk(KERN_CRIT
  99549. + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  99550. + wdog_ping();
  99551. + }
  99552. + clear_bit(0, &wdog_is_open);
  99553. + expect_close = 0;
  99554. + return 0;
  99555. +}
  99556. +
  99557. +/**
  99558. + * @this: our notifier block
  99559. + * @code: the event being reported
  99560. + * @unused: unused
  99561. + *
  99562. + * Our notifier is called on system shutdowns. Turn the watchdog
  99563. + * off so that it does not fire during the next reboot.
  99564. + */
  99565. +
  99566. +static int wdog_notify_sys(struct notifier_block *this, unsigned long code,
  99567. + void *unused)
  99568. +{
  99569. + if (code == SYS_DOWN || code == SYS_HALT)
  99570. + wdog_stop();
  99571. + return NOTIFY_DONE;
  99572. +}
  99573. +
  99574. +/*
  99575. + * Kernel Interfaces
  99576. + */
  99577. +
  99578. +
  99579. +static const struct file_operations wdog_fops = {
  99580. + .owner = THIS_MODULE,
  99581. + .llseek = no_llseek,
  99582. + .write = wdog_write,
  99583. + .unlocked_ioctl = wdog_ioctl,
  99584. + .open = wdog_open,
  99585. + .release = wdog_release,
  99586. +};
  99587. +
  99588. +static struct miscdevice wdog_miscdev = {
  99589. + .minor = WATCHDOG_MINOR,
  99590. + .name = "watchdog",
  99591. + .fops = &wdog_fops,
  99592. +};
  99593. +
  99594. +/*
  99595. + * The WDT card needs to learn about soft shutdowns in order to
  99596. + * turn the timebomb registers off.
  99597. + */
  99598. +
  99599. +static struct notifier_block wdog_notifier = {
  99600. + .notifier_call = wdog_notify_sys,
  99601. +};
  99602. +
  99603. +/**
  99604. + * cleanup_module:
  99605. + *
  99606. + * Unload the watchdog. You cannot do this with any file handles open.
  99607. + * If your watchdog is set to continue ticking on close and you unload
  99608. + * it, well it keeps ticking. We won't get the interrupt but the board
  99609. + * will not touch PC memory so all is fine. You just have to load a new
  99610. + * module in 60 seconds or reboot.
  99611. + */
  99612. +
  99613. +static void __exit wdog_exit(void)
  99614. +{
  99615. + misc_deregister(&wdog_miscdev);
  99616. + unregister_reboot_notifier(&wdog_notifier);
  99617. +}
  99618. +
  99619. +static int __init wdog_init(void)
  99620. +{
  99621. + int ret;
  99622. +
  99623. + /* Check that the heartbeat value is within it's range;
  99624. + if not reset to the default */
  99625. + if (wdog_set_heartbeat(heartbeat)) {
  99626. + wdog_set_heartbeat(WD_TIMO);
  99627. + printk(KERN_INFO "bcm2708_wdog: heartbeat value must be "
  99628. + "0 < heartbeat < %d, using %d\n",
  99629. + WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
  99630. + WD_TIMO);
  99631. + }
  99632. +
  99633. + ret = register_reboot_notifier(&wdog_notifier);
  99634. + if (ret) {
  99635. + printk(KERN_ERR
  99636. + "wdt: cannot register reboot notifier (err=%d)\n", ret);
  99637. + goto out_reboot;
  99638. + }
  99639. +
  99640. + ret = misc_register(&wdog_miscdev);
  99641. + if (ret) {
  99642. + printk(KERN_ERR
  99643. + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  99644. + WATCHDOG_MINOR, ret);
  99645. + goto out_misc;
  99646. + }
  99647. +
  99648. + printk(KERN_INFO "bcm2708 watchdog, heartbeat=%d sec (nowayout=%d)\n",
  99649. + heartbeat, nowayout);
  99650. + return 0;
  99651. +
  99652. +out_misc:
  99653. + unregister_reboot_notifier(&wdog_notifier);
  99654. +out_reboot:
  99655. + return ret;
  99656. +}
  99657. +
  99658. +module_init(wdog_init);
  99659. +module_exit(wdog_exit);
  99660. +
  99661. +MODULE_AUTHOR("Luke Diamand");
  99662. +MODULE_DESCRIPTION("Driver for BCM2708 watchdog");
  99663. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  99664. +MODULE_ALIAS_MISCDEV(TEMP_MINOR);
  99665. +MODULE_LICENSE("GPL");
  99666. diff -Nur linux-3.12.18/drivers/watchdog/Kconfig linux-rpi/drivers/watchdog/Kconfig
  99667. --- linux-3.12.18/drivers/watchdog/Kconfig 2014-04-18 11:14:28.000000000 +0200
  99668. +++ linux-rpi/drivers/watchdog/Kconfig 2014-04-24 16:04:39.955125569 +0200
  99669. @@ -392,6 +392,12 @@
  99670. To compile this driver as a module, choose M here: the
  99671. module will be called retu_wdt.
  99672. +config BCM2708_WDT
  99673. + tristate "BCM2708 Watchdog"
  99674. + depends on ARCH_BCM2708
  99675. + help
  99676. + Enables BCM2708 watchdog support.
  99677. +
  99678. # AVR32 Architecture
  99679. config AT32AP700X_WDT
  99680. diff -Nur linux-3.12.18/drivers/watchdog/Makefile linux-rpi/drivers/watchdog/Makefile
  99681. --- linux-3.12.18/drivers/watchdog/Makefile 2014-04-18 11:14:28.000000000 +0200
  99682. +++ linux-rpi/drivers/watchdog/Makefile 2014-04-24 16:04:39.955125569 +0200
  99683. @@ -54,6 +54,7 @@
  99684. obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
  99685. obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
  99686. obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
  99687. +obj-$(CONFIG_BCM2708_WDT) += bcm2708_wdog.o
  99688. obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
  99689. # AVR32 Architecture
  99690. diff -Nur linux-3.12.18/fs/ext4/inode.c linux-rpi/fs/ext4/inode.c
  99691. --- linux-3.12.18/fs/ext4/inode.c 2014-04-18 11:14:28.000000000 +0200
  99692. +++ linux-rpi/fs/ext4/inode.c 2014-04-24 16:04:40.039126380 +0200
  99693. @@ -4447,12 +4447,7 @@
  99694. return -EIO;
  99695. }
  99696. - /*
  99697. - * No need to force transaction in WB_SYNC_NONE mode. Also
  99698. - * ext4_sync_fs() will force the commit after everything is
  99699. - * written.
  99700. - */
  99701. - if (wbc->sync_mode != WB_SYNC_ALL || wbc->for_sync)
  99702. + if (wbc->sync_mode != WB_SYNC_ALL)
  99703. return 0;
  99704. err = ext4_force_commit(inode->i_sb);
  99705. @@ -4462,11 +4457,7 @@
  99706. err = __ext4_get_inode_loc(inode, &iloc, 0);
  99707. if (err)
  99708. return err;
  99709. - /*
  99710. - * sync(2) will flush the whole buffer cache. No need to do
  99711. - * it here separately for each inode.
  99712. - */
  99713. - if (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync)
  99714. + if (wbc->sync_mode == WB_SYNC_ALL)
  99715. sync_dirty_buffer(iloc.bh);
  99716. if (buffer_req(iloc.bh) && !buffer_uptodate(iloc.bh)) {
  99717. EXT4_ERROR_INODE_BLOCK(inode, iloc.bh->b_blocknr,
  99718. diff -Nur linux-3.12.18/fs/nfs/nfs3acl.c linux-rpi/fs/nfs/nfs3acl.c
  99719. --- linux-3.12.18/fs/nfs/nfs3acl.c 2014-04-18 11:14:28.000000000 +0200
  99720. +++ linux-rpi/fs/nfs/nfs3acl.c 2014-04-24 15:35:04.557570053 +0200
  99721. @@ -289,8 +289,8 @@
  99722. return acl;
  99723. }
  99724. -static int __nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
  99725. - struct posix_acl *dfacl)
  99726. +static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
  99727. + struct posix_acl *dfacl)
  99728. {
  99729. struct nfs_server *server = NFS_SERVER(inode);
  99730. struct nfs_fattr *fattr;
  99731. @@ -373,15 +373,6 @@
  99732. return status;
  99733. }
  99734. -int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
  99735. - struct posix_acl *dfacl)
  99736. -{
  99737. - int ret;
  99738. - ret = __nfs3_proc_setacls(inode, acl, dfacl);
  99739. - return (ret == -EOPNOTSUPP) ? 0 : ret;
  99740. -
  99741. -}
  99742. -
  99743. int nfs3_proc_setacl(struct inode *inode, int type, struct posix_acl *acl)
  99744. {
  99745. struct posix_acl *alloc = NULL, *dfacl = NULL;
  99746. @@ -415,7 +406,7 @@
  99747. if (IS_ERR(alloc))
  99748. goto fail;
  99749. }
  99750. - status = __nfs3_proc_setacls(inode, acl, dfacl);
  99751. + status = nfs3_proc_setacls(inode, acl, dfacl);
  99752. posix_acl_release(alloc);
  99753. return status;
  99754. diff -Nur linux-3.12.18/fs/nfs/nfs4xdr.c linux-rpi/fs/nfs/nfs4xdr.c
  99755. --- linux-3.12.18/fs/nfs/nfs4xdr.c 2014-04-18 11:14:28.000000000 +0200
  99756. +++ linux-rpi/fs/nfs/nfs4xdr.c 2014-04-24 16:04:40.091126883 +0200
  99757. @@ -3405,7 +3405,7 @@
  99758. {
  99759. __be32 *p;
  99760. - *res = 0;
  99761. + *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
  99762. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  99763. return -EIO;
  99764. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  99765. diff -Nur linux-3.12.18/include/drm/drm_crtc.h linux-rpi/include/drm/drm_crtc.h
  99766. --- linux-3.12.18/include/drm/drm_crtc.h 2014-04-18 11:14:28.000000000 +0200
  99767. +++ linux-rpi/include/drm/drm_crtc.h 2014-04-24 16:04:40.179127734 +0200
  99768. @@ -1108,8 +1108,6 @@
  99769. int GTF_2C, int GTF_K, int GTF_2J);
  99770. extern int drm_add_modes_noedid(struct drm_connector *connector,
  99771. int hdisplay, int vdisplay);
  99772. -extern void drm_set_preferred_mode(struct drm_connector *connector,
  99773. - int hpref, int vpref);
  99774. extern int drm_edid_header_is_valid(const u8 *raw_edid);
  99775. extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid);
  99776. diff -Nur linux-3.12.18/include/linux/broadcom/vc_cma.h linux-rpi/include/linux/broadcom/vc_cma.h
  99777. --- linux-3.12.18/include/linux/broadcom/vc_cma.h 1970-01-01 01:00:00.000000000 +0100
  99778. +++ linux-rpi/include/linux/broadcom/vc_cma.h 2014-04-24 16:04:40.687132644 +0200
  99779. @@ -0,0 +1,29 @@
  99780. +/*****************************************************************************
  99781. +* Copyright 2012 Broadcom Corporation. All rights reserved.
  99782. +*
  99783. +* Unless you and Broadcom execute a separate written software license
  99784. +* agreement governing use of this software, this software is licensed to you
  99785. +* under the terms of the GNU General Public License version 2, available at
  99786. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  99787. +*
  99788. +* Notwithstanding the above, under no circumstances may you combine this
  99789. +* software in any way with any other Broadcom software provided under a
  99790. +* license other than the GPL, without Broadcom's express prior written
  99791. +* consent.
  99792. +*****************************************************************************/
  99793. +
  99794. +#if !defined( VC_CMA_H )
  99795. +#define VC_CMA_H
  99796. +
  99797. +#include <linux/ioctl.h>
  99798. +
  99799. +#define VC_CMA_IOC_MAGIC 0xc5
  99800. +
  99801. +#define VC_CMA_IOC_RESERVE _IO(VC_CMA_IOC_MAGIC, 0)
  99802. +
  99803. +#ifdef __KERNEL__
  99804. +extern void __init vc_cma_early_init(void);
  99805. +extern void __init vc_cma_reserve(void);
  99806. +#endif
  99807. +
  99808. +#endif /* VC_CMA_H */
  99809. diff -Nur linux-3.12.18/include/linux/fb.h linux-rpi/include/linux/fb.h
  99810. --- linux-3.12.18/include/linux/fb.h 2014-04-18 11:14:28.000000000 +0200
  99811. +++ linux-rpi/include/linux/fb.h 2014-04-24 16:04:40.731133070 +0200
  99812. @@ -613,8 +613,8 @@
  99813. extern int register_framebuffer(struct fb_info *fb_info);
  99814. extern int unregister_framebuffer(struct fb_info *fb_info);
  99815. extern int unlink_framebuffer(struct fb_info *fb_info);
  99816. -extern int remove_conflicting_framebuffers(struct apertures_struct *a,
  99817. - const char *name, bool primary);
  99818. +extern void remove_conflicting_framebuffers(struct apertures_struct *a,
  99819. + const char *name, bool primary);
  99820. extern int fb_prepare_logo(struct fb_info *fb_info, int rotate);
  99821. extern int fb_show_logo(struct fb_info *fb_info, int rotate);
  99822. extern char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size);
  99823. diff -Nur linux-3.12.18/include/linux/futex.h linux-rpi/include/linux/futex.h
  99824. --- linux-3.12.18/include/linux/futex.h 2014-04-18 11:14:28.000000000 +0200
  99825. +++ linux-rpi/include/linux/futex.h 2014-04-24 16:04:40.751133263 +0200
  99826. @@ -55,11 +55,7 @@
  99827. #ifdef CONFIG_FUTEX
  99828. extern void exit_robust_list(struct task_struct *curr);
  99829. extern void exit_pi_state_list(struct task_struct *curr);
  99830. -#ifdef CONFIG_HAVE_FUTEX_CMPXCHG
  99831. -#define futex_cmpxchg_enabled 1
  99832. -#else
  99833. extern int futex_cmpxchg_enabled;
  99834. -#endif
  99835. #else
  99836. static inline void exit_robust_list(struct task_struct *curr)
  99837. {
  99838. diff -Nur linux-3.12.18/include/linux/mmc/host.h linux-rpi/include/linux/mmc/host.h
  99839. --- linux-3.12.18/include/linux/mmc/host.h 2014-04-18 11:14:28.000000000 +0200
  99840. +++ linux-rpi/include/linux/mmc/host.h 2014-04-24 16:04:40.819133921 +0200
  99841. @@ -281,6 +281,7 @@
  99842. MMC_CAP2_PACKED_WR)
  99843. #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */
  99844. #define MMC_CAP2_SANITIZE (1 << 15) /* Support Sanitize */
  99845. +#define MMC_CAP2_FORCE_MULTIBLOCK (1 << 31) /* Always use multiblock transfers */
  99846. mmc_pm_flag_t pm_caps; /* supported pm features */
  99847. diff -Nur linux-3.12.18/include/linux/mmc/sdhci.h linux-rpi/include/linux/mmc/sdhci.h
  99848. --- linux-3.12.18/include/linux/mmc/sdhci.h 2014-04-18 11:14:28.000000000 +0200
  99849. +++ linux-rpi/include/linux/mmc/sdhci.h 2014-04-24 16:04:40.819133921 +0200
  99850. @@ -100,6 +100,7 @@
  99851. #define SDHCI_QUIRK2_BROKEN_HOST_CONTROL (1<<5)
  99852. int irq; /* Device IRQ */
  99853. + int second_irq; /* Additional IRQ to disable/enable in low-latency mode */
  99854. void __iomem *ioaddr; /* Mapped address */
  99855. const struct sdhci_ops *ops; /* Low level hw interface */
  99856. @@ -131,6 +132,7 @@
  99857. #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  99858. #define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
  99859. #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
  99860. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  99861. unsigned int version; /* SDHCI spec. version */
  99862. @@ -146,6 +148,7 @@
  99863. struct mmc_request *mrq; /* Current request */
  99864. struct mmc_command *cmd; /* Current command */
  99865. + int last_cmdop; /* Opcode of last cmd sent */
  99866. struct mmc_data *data; /* Current data request */
  99867. unsigned int data_early:1; /* Data finished before cmd */
  99868. diff -Nur linux-3.12.18/include/linux/usb/usbnet.h linux-rpi/include/linux/usb/usbnet.h
  99869. --- linux-3.12.18/include/linux/usb/usbnet.h 2014-04-18 11:14:28.000000000 +0200
  99870. +++ linux-rpi/include/linux/usb/usbnet.h 2014-04-24 16:04:40.871134423 +0200
  99871. @@ -30,7 +30,7 @@
  99872. struct driver_info *driver_info;
  99873. const char *driver_name;
  99874. void *driver_priv;
  99875. - wait_queue_head_t wait;
  99876. + wait_queue_head_t *wait;
  99877. struct mutex phy_mutex;
  99878. unsigned char suspend_count;
  99879. unsigned char pkt_cnt, pkt_err;
  99880. diff -Nur linux-3.12.18/include/net/sock.h linux-rpi/include/net/sock.h
  99881. --- linux-3.12.18/include/net/sock.h 2014-04-18 11:14:28.000000000 +0200
  99882. +++ linux-rpi/include/net/sock.h 2014-04-24 16:04:41.511140609 +0200
  99883. @@ -1459,11 +1459,6 @@
  99884. */
  99885. #define sock_owned_by_user(sk) ((sk)->sk_lock.owned)
  99886. -static inline void sock_release_ownership(struct sock *sk)
  99887. -{
  99888. - sk->sk_lock.owned = 0;
  99889. -}
  99890. -
  99891. /*
  99892. * Macro so as to not evaluate some arguments when
  99893. * lockdep is not enabled.
  99894. diff -Nur linux-3.12.18/include/net/tcp.h linux-rpi/include/net/tcp.h
  99895. --- linux-3.12.18/include/net/tcp.h 2014-04-18 11:14:28.000000000 +0200
  99896. +++ linux-rpi/include/net/tcp.h 2014-04-24 16:04:41.511140609 +0200
  99897. @@ -484,21 +484,20 @@
  99898. #ifdef CONFIG_SYN_COOKIES
  99899. #include <linux/ktime.h>
  99900. -/* Syncookies use a monotonic timer which increments every 60 seconds.
  99901. +/* Syncookies use a monotonic timer which increments every 64 seconds.
  99902. * This counter is used both as a hash input and partially encoded into
  99903. * the cookie value. A cookie is only validated further if the delta
  99904. * between the current counter value and the encoded one is less than this,
  99905. - * i.e. a sent cookie is valid only at most for 2*60 seconds (or less if
  99906. + * i.e. a sent cookie is valid only at most for 128 seconds (or less if
  99907. * the counter advances immediately after a cookie is generated).
  99908. */
  99909. #define MAX_SYNCOOKIE_AGE 2
  99910. static inline u32 tcp_cookie_time(void)
  99911. {
  99912. - u64 val = get_jiffies_64();
  99913. -
  99914. - do_div(val, 60 * HZ);
  99915. - return val;
  99916. + struct timespec now;
  99917. + getnstimeofday(&now);
  99918. + return now.tv_sec >> 6; /* 64 seconds granularity */
  99919. }
  99920. extern u32 __cookie_v4_init_sequence(const struct iphdr *iph,
  99921. diff -Nur linux-3.12.18/include/sound/soc-dai.h linux-rpi/include/sound/soc-dai.h
  99922. --- linux-3.12.18/include/sound/soc-dai.h 2014-04-18 11:14:28.000000000 +0200
  99923. +++ linux-rpi/include/sound/soc-dai.h 2014-04-24 15:35:04.921574108 +0200
  99924. @@ -105,6 +105,8 @@
  99925. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  99926. int pll_id, int source, unsigned int freq_in, unsigned int freq_out);
  99927. +int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);
  99928. +
  99929. /* Digital Audio interface formatting */
  99930. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
  99931. @@ -131,6 +133,7 @@
  99932. int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
  99933. unsigned int freq_in, unsigned int freq_out);
  99934. int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
  99935. + int (*set_bclk_ratio)(struct snd_soc_dai *dai, unsigned int ratio);
  99936. /*
  99937. * DAI format configuration
  99938. diff -Nur linux-3.12.18/include/uapi/linux/fb.h linux-rpi/include/uapi/linux/fb.h
  99939. --- linux-3.12.18/include/uapi/linux/fb.h 2014-04-18 11:14:28.000000000 +0200
  99940. +++ linux-rpi/include/uapi/linux/fb.h 2014-04-24 15:35:04.941574330 +0200
  99941. @@ -34,6 +34,11 @@
  99942. #define FBIOPUT_MODEINFO 0x4617
  99943. #define FBIOGET_DISPINFO 0x4618
  99944. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  99945. +/*
  99946. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  99947. + * be concurrently added to the mainline kernel
  99948. + */
  99949. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  99950. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  99951. #define FB_TYPE_PLANES 1 /* Non interleaved planes */
  99952. diff -Nur linux-3.12.18/include/uapi/linux/fd.h linux-rpi/include/uapi/linux/fd.h
  99953. --- linux-3.12.18/include/uapi/linux/fd.h 2014-04-18 11:14:28.000000000 +0200
  99954. +++ linux-rpi/include/uapi/linux/fd.h 2014-04-24 15:35:04.945574375 +0200
  99955. @@ -185,8 +185,7 @@
  99956. * to clear media change status */
  99957. FD_UNUSED_BIT,
  99958. FD_DISK_CHANGED_BIT, /* disk has been changed since last i/o */
  99959. - FD_DISK_WRITABLE_BIT, /* disk is writable */
  99960. - FD_OPEN_SHOULD_FAIL_BIT
  99961. + FD_DISK_WRITABLE_BIT /* disk is writable */
  99962. };
  99963. #define FDSETDRVPRM _IOW(2, 0x90, struct floppy_drive_params)
  99964. diff -Nur linux-3.12.18/init/Kconfig linux-rpi/init/Kconfig
  99965. --- linux-3.12.18/init/Kconfig 2014-04-18 11:14:28.000000000 +0200
  99966. +++ linux-rpi/init/Kconfig 2014-04-24 16:04:41.543140918 +0200
  99967. @@ -1406,13 +1406,6 @@
  99968. support for "fast userspace mutexes". The resulting kernel may not
  99969. run glibc-based applications correctly.
  99970. -config HAVE_FUTEX_CMPXCHG
  99971. - bool
  99972. - help
  99973. - Architectures should select this if futex_atomic_cmpxchg_inatomic()
  99974. - is implemented and always working. This removes a couple of runtime
  99975. - checks.
  99976. -
  99977. config EPOLL
  99978. bool "Enable eventpoll support" if EXPERT
  99979. default y
  99980. diff -Nur linux-3.12.18/kernel/cgroup.c linux-rpi/kernel/cgroup.c
  99981. --- linux-3.12.18/kernel/cgroup.c 2014-04-18 11:14:28.000000000 +0200
  99982. +++ linux-rpi/kernel/cgroup.c 2014-04-24 16:04:41.547140957 +0200
  99983. @@ -5558,6 +5558,33 @@
  99984. }
  99985. __setup("cgroup_disable=", cgroup_disable);
  99986. +static int __init cgroup_enable(char *str)
  99987. +{
  99988. + struct cgroup_subsys *ss;
  99989. + char *token;
  99990. + int i;
  99991. +
  99992. + while ((token = strsep(&str, ",")) != NULL) {
  99993. + if (!*token)
  99994. + continue;
  99995. +
  99996. + /*
  99997. + * cgroup_disable, being at boot time, can't know about
  99998. + * module subsystems, so we don't worry about them.
  99999. + */
  100000. + for_each_builtin_subsys(ss, i) {
  100001. + if (!strcmp(token, ss->name)) {
  100002. + ss->disabled = 0;
  100003. + printk(KERN_INFO "Disabling %s control group"
  100004. + " subsystem\n", ss->name);
  100005. + break;
  100006. + }
  100007. + }
  100008. + }
  100009. + return 1;
  100010. +}
  100011. +__setup("cgroup_enable=", cgroup_enable);
  100012. +
  100013. /*
  100014. * Functons for CSS ID.
  100015. */
  100016. diff -Nur linux-3.12.18/kernel/futex.c linux-rpi/kernel/futex.c
  100017. --- linux-3.12.18/kernel/futex.c 2014-04-18 11:14:28.000000000 +0200
  100018. +++ linux-rpi/kernel/futex.c 2014-04-24 16:04:41.551140996 +0200
  100019. @@ -68,9 +68,7 @@
  100020. #include "rtmutex_common.h"
  100021. -#ifndef CONFIG_HAVE_FUTEX_CMPXCHG
  100022. int __read_mostly futex_cmpxchg_enabled;
  100023. -#endif
  100024. #define FUTEX_HASHBITS (CONFIG_BASE_SMALL ? 4 : 8)
  100025. @@ -2733,10 +2731,10 @@
  100026. return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
  100027. }
  100028. -static void __init futex_detect_cmpxchg(void)
  100029. +static int __init futex_init(void)
  100030. {
  100031. -#ifndef CONFIG_HAVE_FUTEX_CMPXCHG
  100032. u32 curval;
  100033. + int i;
  100034. /*
  100035. * This will fail and we want it. Some arch implementations do
  100036. @@ -2750,14 +2748,6 @@
  100037. */
  100038. if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
  100039. futex_cmpxchg_enabled = 1;
  100040. -#endif
  100041. -}
  100042. -
  100043. -static int __init futex_init(void)
  100044. -{
  100045. - int i;
  100046. -
  100047. - futex_detect_cmpxchg();
  100048. for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
  100049. plist_head_init(&futex_queues[i].chain);
  100050. diff -Nur linux-3.12.18/lib/nlattr.c linux-rpi/lib/nlattr.c
  100051. --- linux-3.12.18/lib/nlattr.c 2014-04-18 11:14:28.000000000 +0200
  100052. +++ linux-rpi/lib/nlattr.c 2014-04-24 16:04:41.611141576 +0200
  100053. @@ -303,15 +303,9 @@
  100054. */
  100055. int nla_strcmp(const struct nlattr *nla, const char *str)
  100056. {
  100057. - int len = strlen(str);
  100058. - char *buf = nla_data(nla);
  100059. - int attrlen = nla_len(nla);
  100060. - int d;
  100061. + int len = strlen(str) + 1;
  100062. + int d = nla_len(nla) - len;
  100063. - if (attrlen > 0 && buf[attrlen - 1] == '\0')
  100064. - attrlen--;
  100065. -
  100066. - d = attrlen - len;
  100067. if (d == 0)
  100068. d = memcmp(nla_data(nla), str, len);
  100069. diff -Nur linux-3.12.18/mm/memcontrol.c linux-rpi/mm/memcontrol.c
  100070. --- linux-3.12.18/mm/memcontrol.c 2014-04-18 11:14:28.000000000 +0200
  100071. +++ linux-rpi/mm/memcontrol.c 2014-04-24 16:04:41.619141653 +0200
  100072. @@ -7030,6 +7030,7 @@
  100073. .base_cftypes = mem_cgroup_files,
  100074. .early_init = 0,
  100075. .use_id = 1,
  100076. + .disabled = 1,
  100077. };
  100078. #ifdef CONFIG_MEMCG_SWAP
  100079. diff -Nur linux-3.12.18/net/8021q/vlan.c linux-rpi/net/8021q/vlan.c
  100080. --- linux-3.12.18/net/8021q/vlan.c 2014-04-18 11:14:28.000000000 +0200
  100081. +++ linux-rpi/net/8021q/vlan.c 2014-04-24 16:04:41.635141808 +0200
  100082. @@ -307,11 +307,9 @@
  100083. static void vlan_transfer_features(struct net_device *dev,
  100084. struct net_device *vlandev)
  100085. {
  100086. - struct vlan_dev_priv *vlan = vlan_dev_priv(vlandev);
  100087. -
  100088. vlandev->gso_max_size = dev->gso_max_size;
  100089. - if (vlan_hw_offload_capable(dev->features, vlan->vlan_proto))
  100090. + if (dev->features & NETIF_F_HW_VLAN_CTAG_TX)
  100091. vlandev->hard_header_len = dev->hard_header_len;
  100092. else
  100093. vlandev->hard_header_len = dev->hard_header_len + VLAN_HLEN;
  100094. diff -Nur linux-3.12.18/net/8021q/vlan_dev.c linux-rpi/net/8021q/vlan_dev.c
  100095. --- linux-3.12.18/net/8021q/vlan_dev.c 2014-04-18 11:14:28.000000000 +0200
  100096. +++ linux-rpi/net/8021q/vlan_dev.c 2014-04-24 16:04:41.635141808 +0200
  100097. @@ -557,9 +557,6 @@
  100098. struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
  100099. struct net_device *real_dev = vlan->real_dev;
  100100. - if (saddr == NULL)
  100101. - saddr = dev->dev_addr;
  100102. -
  100103. return dev_hard_header(skb, real_dev, type, daddr, saddr, len);
  100104. }
  100105. @@ -611,8 +608,7 @@
  100106. #endif
  100107. dev->needed_headroom = real_dev->needed_headroom;
  100108. - if (vlan_hw_offload_capable(real_dev->features,
  100109. - vlan_dev_priv(dev)->vlan_proto)) {
  100110. + if (real_dev->features & NETIF_F_HW_VLAN_CTAG_TX) {
  100111. dev->header_ops = &vlan_passthru_header_ops;
  100112. dev->hard_header_len = real_dev->hard_header_len;
  100113. } else {
  100114. diff -Nur linux-3.12.18/net/bridge/br_multicast.c linux-rpi/net/bridge/br_multicast.c
  100115. --- linux-3.12.18/net/bridge/br_multicast.c 2014-04-18 11:14:28.000000000 +0200
  100116. +++ linux-rpi/net/bridge/br_multicast.c 2014-04-24 16:04:41.647141924 +0200
  100117. @@ -1129,10 +1129,9 @@
  100118. struct net_bridge_port *port,
  100119. struct bridge_mcast_querier *querier,
  100120. int saddr,
  100121. - bool is_general_query,
  100122. unsigned long max_delay)
  100123. {
  100124. - if (saddr && is_general_query)
  100125. + if (saddr)
  100126. br_multicast_update_querier_timer(br, querier, max_delay);
  100127. else if (timer_pending(&querier->timer))
  100128. return;
  100129. @@ -1184,16 +1183,8 @@
  100130. IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1;
  100131. }
  100132. - /* RFC2236+RFC3376 (IGMPv2+IGMPv3) require the multicast link layer
  100133. - * all-systems destination addresses (224.0.0.1) for general queries
  100134. - */
  100135. - if (!group && iph->daddr != htonl(INADDR_ALLHOSTS_GROUP)) {
  100136. - err = -EINVAL;
  100137. - goto out;
  100138. - }
  100139. -
  100140. br_multicast_query_received(br, port, &br->ip4_querier, !!iph->saddr,
  100141. - !group, max_delay);
  100142. + max_delay);
  100143. if (!group)
  100144. goto out;
  100145. @@ -1239,7 +1230,6 @@
  100146. unsigned long max_delay;
  100147. unsigned long now = jiffies;
  100148. const struct in6_addr *group = NULL;
  100149. - bool is_general_query;
  100150. int err = 0;
  100151. u16 vid = 0;
  100152. @@ -1248,12 +1238,6 @@
  100153. (port && port->state == BR_STATE_DISABLED))
  100154. goto out;
  100155. - /* RFC2710+RFC3810 (MLDv1+MLDv2) require link-local source addresses */
  100156. - if (!(ipv6_addr_type(&ip6h->saddr) & IPV6_ADDR_LINKLOCAL)) {
  100157. - err = -EINVAL;
  100158. - goto out;
  100159. - }
  100160. -
  100161. if (skb->len == sizeof(*mld)) {
  100162. if (!pskb_may_pull(skb, sizeof(*mld))) {
  100163. err = -EINVAL;
  100164. @@ -1275,19 +1259,8 @@
  100165. max_delay = max(msecs_to_jiffies(mldv2_mrc(mld2q)), 1UL);
  100166. }
  100167. - is_general_query = group && ipv6_addr_any(group);
  100168. -
  100169. - /* RFC2710+RFC3810 (MLDv1+MLDv2) require the multicast link layer
  100170. - * all-nodes destination address (ff02::1) for general queries
  100171. - */
  100172. - if (is_general_query && !ipv6_addr_is_ll_all_nodes(&ip6h->daddr)) {
  100173. - err = -EINVAL;
  100174. - goto out;
  100175. - }
  100176. -
  100177. br_multicast_query_received(br, port, &br->ip6_querier,
  100178. - !ipv6_addr_any(&ip6h->saddr),
  100179. - is_general_query, max_delay);
  100180. + !ipv6_addr_any(&ip6h->saddr), max_delay);
  100181. if (!group)
  100182. goto out;
  100183. diff -Nur linux-3.12.18/net/core/netpoll.c linux-rpi/net/core/netpoll.c
  100184. --- linux-3.12.18/net/core/netpoll.c 2014-04-18 11:14:28.000000000 +0200
  100185. +++ linux-rpi/net/core/netpoll.c 2014-04-24 16:04:41.659142040 +0200
  100186. @@ -740,7 +740,7 @@
  100187. struct nd_msg *msg;
  100188. struct ipv6hdr *hdr;
  100189. - if (skb->protocol != htons(ETH_P_IPV6))
  100190. + if (skb->protocol != htons(ETH_P_ARP))
  100191. return false;
  100192. if (!pskb_may_pull(skb, sizeof(struct ipv6hdr) + sizeof(struct nd_msg)))
  100193. return false;
  100194. diff -Nur linux-3.12.18/net/core/rtnetlink.c linux-rpi/net/core/rtnetlink.c
  100195. --- linux-3.12.18/net/core/rtnetlink.c 2014-04-18 11:14:28.000000000 +0200
  100196. +++ linux-rpi/net/core/rtnetlink.c 2014-04-24 16:04:41.659142040 +0200
  100197. @@ -2014,13 +2014,12 @@
  100198. static int nlmsg_populate_fdb_fill(struct sk_buff *skb,
  100199. struct net_device *dev,
  100200. u8 *addr, u32 pid, u32 seq,
  100201. - int type, unsigned int flags,
  100202. - int nlflags)
  100203. + int type, unsigned int flags)
  100204. {
  100205. struct nlmsghdr *nlh;
  100206. struct ndmsg *ndm;
  100207. - nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), nlflags);
  100208. + nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), NLM_F_MULTI);
  100209. if (!nlh)
  100210. return -EMSGSIZE;
  100211. @@ -2058,7 +2057,7 @@
  100212. if (!skb)
  100213. goto errout;
  100214. - err = nlmsg_populate_fdb_fill(skb, dev, addr, 0, 0, type, NTF_SELF, 0);
  100215. + err = nlmsg_populate_fdb_fill(skb, dev, addr, 0, 0, type, NTF_SELF);
  100216. if (err < 0) {
  100217. kfree_skb(skb);
  100218. goto errout;
  100219. @@ -2283,8 +2282,7 @@
  100220. err = nlmsg_populate_fdb_fill(skb, dev, ha->addr,
  100221. portid, seq,
  100222. - RTM_NEWNEIGH, NTF_SELF,
  100223. - NLM_F_MULTI);
  100224. + RTM_NEWNEIGH, NTF_SELF);
  100225. if (err < 0)
  100226. return err;
  100227. skip:
  100228. diff -Nur linux-3.12.18/net/core/sock.c linux-rpi/net/core/sock.c
  100229. --- linux-3.12.18/net/core/sock.c 2014-04-18 11:14:28.000000000 +0200
  100230. +++ linux-rpi/net/core/sock.c 2014-04-24 16:04:41.659142040 +0200
  100231. @@ -2359,13 +2359,10 @@
  100232. if (sk->sk_backlog.tail)
  100233. __release_sock(sk);
  100234. - /* Warning : release_cb() might need to release sk ownership,
  100235. - * ie call sock_release_ownership(sk) before us.
  100236. - */
  100237. if (sk->sk_prot->release_cb)
  100238. sk->sk_prot->release_cb(sk);
  100239. - sock_release_ownership(sk);
  100240. + sk->sk_lock.owned = 0;
  100241. if (waitqueue_active(&sk->sk_lock.wq))
  100242. wake_up(&sk->sk_lock.wq);
  100243. spin_unlock_bh(&sk->sk_lock.slock);
  100244. diff -Nur linux-3.12.18/net/ipv4/gre_demux.c linux-rpi/net/ipv4/gre_demux.c
  100245. --- linux-3.12.18/net/ipv4/gre_demux.c 2014-04-18 11:14:28.000000000 +0200
  100246. +++ linux-rpi/net/ipv4/gre_demux.c 2014-04-24 16:04:41.667142117 +0200
  100247. @@ -211,14 +211,6 @@
  100248. int i;
  100249. bool csum_err = false;
  100250. -#ifdef CONFIG_NET_IPGRE_BROADCAST
  100251. - if (ipv4_is_multicast(ip_hdr(skb)->daddr)) {
  100252. - /* Looped back packet, drop it! */
  100253. - if (rt_is_output_route(skb_rtable(skb)))
  100254. - goto drop;
  100255. - }
  100256. -#endif
  100257. -
  100258. if (parse_gre_header(skb, &tpi, &csum_err) < 0)
  100259. goto drop;
  100260. diff -Nur linux-3.12.18/net/ipv4/inet_fragment.c linux-rpi/net/ipv4/inet_fragment.c
  100261. --- linux-3.12.18/net/ipv4/inet_fragment.c 2014-04-18 11:14:28.000000000 +0200
  100262. +++ linux-rpi/net/ipv4/inet_fragment.c 2014-04-24 16:04:41.667142117 +0200
  100263. @@ -211,7 +211,7 @@
  100264. }
  100265. work = frag_mem_limit(nf) - nf->low_thresh;
  100266. - while (work > 0 || force) {
  100267. + while (work > 0) {
  100268. spin_lock(&nf->lru_lock);
  100269. if (list_empty(&nf->lru_list)) {
  100270. @@ -281,10 +281,9 @@
  100271. atomic_inc(&qp->refcnt);
  100272. hlist_add_head(&qp->list, &hb->chain);
  100273. - inet_frag_lru_add(nf, qp);
  100274. spin_unlock(&hb->chain_lock);
  100275. read_unlock(&f->lock);
  100276. -
  100277. + inet_frag_lru_add(nf, qp);
  100278. return qp;
  100279. }
  100280. diff -Nur linux-3.12.18/net/ipv4/ipmr.c linux-rpi/net/ipv4/ipmr.c
  100281. --- linux-3.12.18/net/ipv4/ipmr.c 2014-04-18 11:14:28.000000000 +0200
  100282. +++ linux-rpi/net/ipv4/ipmr.c 2014-04-24 16:04:41.671142156 +0200
  100283. @@ -2253,14 +2253,13 @@
  100284. }
  100285. static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
  100286. - u32 portid, u32 seq, struct mfc_cache *c, int cmd,
  100287. - int flags)
  100288. + u32 portid, u32 seq, struct mfc_cache *c, int cmd)
  100289. {
  100290. struct nlmsghdr *nlh;
  100291. struct rtmsg *rtm;
  100292. int err;
  100293. - nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), flags);
  100294. + nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), NLM_F_MULTI);
  100295. if (nlh == NULL)
  100296. return -EMSGSIZE;
  100297. @@ -2328,7 +2327,7 @@
  100298. if (skb == NULL)
  100299. goto errout;
  100300. - err = ipmr_fill_mroute(mrt, skb, 0, 0, mfc, cmd, 0);
  100301. + err = ipmr_fill_mroute(mrt, skb, 0, 0, mfc, cmd);
  100302. if (err < 0)
  100303. goto errout;
  100304. @@ -2367,8 +2366,7 @@
  100305. if (ipmr_fill_mroute(mrt, skb,
  100306. NETLINK_CB(cb->skb).portid,
  100307. cb->nlh->nlmsg_seq,
  100308. - mfc, RTM_NEWROUTE,
  100309. - NLM_F_MULTI) < 0)
  100310. + mfc, RTM_NEWROUTE) < 0)
  100311. goto done;
  100312. next_entry:
  100313. e++;
  100314. @@ -2382,8 +2380,7 @@
  100315. if (ipmr_fill_mroute(mrt, skb,
  100316. NETLINK_CB(cb->skb).portid,
  100317. cb->nlh->nlmsg_seq,
  100318. - mfc, RTM_NEWROUTE,
  100319. - NLM_F_MULTI) < 0) {
  100320. + mfc, RTM_NEWROUTE) < 0) {
  100321. spin_unlock_bh(&mfc_unres_lock);
  100322. goto done;
  100323. }
  100324. diff -Nur linux-3.12.18/net/ipv4/ip_tunnel.c linux-rpi/net/ipv4/ip_tunnel.c
  100325. --- linux-3.12.18/net/ipv4/ip_tunnel.c 2014-04-18 11:14:28.000000000 +0200
  100326. +++ linux-rpi/net/ipv4/ip_tunnel.c 2014-04-24 16:04:41.667142117 +0200
  100327. @@ -411,6 +411,9 @@
  100328. #ifdef CONFIG_NET_IPGRE_BROADCAST
  100329. if (ipv4_is_multicast(iph->daddr)) {
  100330. + /* Looped back packet, drop it! */
  100331. + if (rt_is_output_route(skb_rtable(skb)))
  100332. + goto drop;
  100333. tunnel->dev->stats.multicast++;
  100334. skb->pkt_type = PACKET_BROADCAST;
  100335. }
  100336. diff -Nur linux-3.12.18/net/ipv4/ip_tunnel_core.c linux-rpi/net/ipv4/ip_tunnel_core.c
  100337. --- linux-3.12.18/net/ipv4/ip_tunnel_core.c 2014-04-18 11:14:28.000000000 +0200
  100338. +++ linux-rpi/net/ipv4/ip_tunnel_core.c 2014-04-24 16:04:41.671142156 +0200
  100339. @@ -109,7 +109,6 @@
  100340. secpath_reset(skb);
  100341. if (!skb->l4_rxhash)
  100342. skb->rxhash = 0;
  100343. - skb_dst_drop(skb);
  100344. skb->vlan_tci = 0;
  100345. skb_set_queue_mapping(skb, 0);
  100346. skb->pkt_type = PACKET_HOST;
  100347. diff -Nur linux-3.12.18/net/ipv4/tcp_output.c linux-rpi/net/ipv4/tcp_output.c
  100348. --- linux-3.12.18/net/ipv4/tcp_output.c 2014-04-18 11:14:28.000000000 +0200
  100349. +++ linux-rpi/net/ipv4/tcp_output.c 2014-04-24 16:04:41.683142272 +0200
  100350. @@ -765,17 +765,6 @@
  100351. if (flags & (1UL << TCP_TSQ_DEFERRED))
  100352. tcp_tsq_handler(sk);
  100353. - /* Here begins the tricky part :
  100354. - * We are called from release_sock() with :
  100355. - * 1) BH disabled
  100356. - * 2) sk_lock.slock spinlock held
  100357. - * 3) socket owned by us (sk->sk_lock.owned == 1)
  100358. - *
  100359. - * But following code is meant to be called from BH handlers,
  100360. - * so we should keep BH disabled, but early release socket ownership
  100361. - */
  100362. - sock_release_ownership(sk);
  100363. -
  100364. if (flags & (1UL << TCP_WRITE_TIMER_DEFERRED)) {
  100365. tcp_write_timer_handler(sk);
  100366. __sock_put(sk);
  100367. diff -Nur linux-3.12.18/net/ipv6/addrconf.c linux-rpi/net/ipv6/addrconf.c
  100368. --- linux-3.12.18/net/ipv6/addrconf.c 2014-04-18 11:14:28.000000000 +0200
  100369. +++ linux-rpi/net/ipv6/addrconf.c 2014-04-24 16:04:41.687142311 +0200
  100370. @@ -1079,11 +1079,8 @@
  100371. * Lifetime is greater than REGEN_ADVANCE time units. In particular,
  100372. * an implementation must not create a temporary address with a zero
  100373. * Preferred Lifetime.
  100374. - * Use age calculation as in addrconf_verify to avoid unnecessary
  100375. - * temporary addresses being generated.
  100376. */
  100377. - age = (now - tmp_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ;
  100378. - if (tmp_prefered_lft <= regen_advance + age) {
  100379. + if (tmp_prefered_lft <= regen_advance) {
  100380. in6_ifa_put(ifp);
  100381. in6_dev_put(idev);
  100382. ret = -1;
  100383. diff -Nur linux-3.12.18/net/ipv6/exthdrs_offload.c linux-rpi/net/ipv6/exthdrs_offload.c
  100384. --- linux-3.12.18/net/ipv6/exthdrs_offload.c 2014-04-18 11:14:28.000000000 +0200
  100385. +++ linux-rpi/net/ipv6/exthdrs_offload.c 2014-04-24 16:04:41.687142311 +0200
  100386. @@ -25,11 +25,11 @@
  100387. int ret;
  100388. ret = inet6_add_offload(&rthdr_offload, IPPROTO_ROUTING);
  100389. - if (ret)
  100390. + if (!ret)
  100391. goto out;
  100392. ret = inet6_add_offload(&dstopt_offload, IPPROTO_DSTOPTS);
  100393. - if (ret)
  100394. + if (!ret)
  100395. goto out_rt;
  100396. out:
  100397. diff -Nur linux-3.12.18/net/ipv6/icmp.c linux-rpi/net/ipv6/icmp.c
  100398. --- linux-3.12.18/net/ipv6/icmp.c 2014-04-18 11:14:28.000000000 +0200
  100399. +++ linux-rpi/net/ipv6/icmp.c 2014-04-24 16:04:41.687142311 +0200
  100400. @@ -516,7 +516,7 @@
  100401. np->tclass, NULL, &fl6, (struct rt6_info *)dst,
  100402. MSG_DONTWAIT, np->dontfrag);
  100403. if (err) {
  100404. - ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTERRORS);
  100405. + ICMP6_INC_STATS_BH(net, idev, ICMP6_MIB_OUTERRORS);
  100406. ip6_flush_pending_frames(sk);
  100407. } else {
  100408. err = icmpv6_push_pending_frames(sk, &fl6, &tmp_hdr,
  100409. diff -Nur linux-3.12.18/net/ipv6/ip6mr.c linux-rpi/net/ipv6/ip6mr.c
  100410. --- linux-3.12.18/net/ipv6/ip6mr.c 2014-04-18 11:14:28.000000000 +0200
  100411. +++ linux-rpi/net/ipv6/ip6mr.c 2014-04-24 16:04:41.691142349 +0200
  100412. @@ -2349,14 +2349,13 @@
  100413. }
  100414. static int ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb,
  100415. - u32 portid, u32 seq, struct mfc6_cache *c, int cmd,
  100416. - int flags)
  100417. + u32 portid, u32 seq, struct mfc6_cache *c, int cmd)
  100418. {
  100419. struct nlmsghdr *nlh;
  100420. struct rtmsg *rtm;
  100421. int err;
  100422. - nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), flags);
  100423. + nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), NLM_F_MULTI);
  100424. if (nlh == NULL)
  100425. return -EMSGSIZE;
  100426. @@ -2424,7 +2423,7 @@
  100427. if (skb == NULL)
  100428. goto errout;
  100429. - err = ip6mr_fill_mroute(mrt, skb, 0, 0, mfc, cmd, 0);
  100430. + err = ip6mr_fill_mroute(mrt, skb, 0, 0, mfc, cmd);
  100431. if (err < 0)
  100432. goto errout;
  100433. @@ -2463,8 +2462,7 @@
  100434. if (ip6mr_fill_mroute(mrt, skb,
  100435. NETLINK_CB(cb->skb).portid,
  100436. cb->nlh->nlmsg_seq,
  100437. - mfc, RTM_NEWROUTE,
  100438. - NLM_F_MULTI) < 0)
  100439. + mfc, RTM_NEWROUTE) < 0)
  100440. goto done;
  100441. next_entry:
  100442. e++;
  100443. @@ -2478,8 +2476,7 @@
  100444. if (ip6mr_fill_mroute(mrt, skb,
  100445. NETLINK_CB(cb->skb).portid,
  100446. cb->nlh->nlmsg_seq,
  100447. - mfc, RTM_NEWROUTE,
  100448. - NLM_F_MULTI) < 0) {
  100449. + mfc, RTM_NEWROUTE) < 0) {
  100450. spin_unlock_bh(&mfc_unres_lock);
  100451. goto done;
  100452. }
  100453. diff -Nur linux-3.12.18/net/ipv6/ip6_output.c linux-rpi/net/ipv6/ip6_output.c
  100454. --- linux-3.12.18/net/ipv6/ip6_output.c 2014-04-18 11:14:28.000000000 +0200
  100455. +++ linux-rpi/net/ipv6/ip6_output.c 2014-04-24 16:04:41.691142349 +0200
  100456. @@ -1088,19 +1088,21 @@
  100457. unsigned int fragheaderlen,
  100458. struct sk_buff *skb,
  100459. struct rt6_info *rt,
  100460. - unsigned int orig_mtu)
  100461. + bool pmtuprobe)
  100462. {
  100463. if (!(rt->dst.flags & DST_XFRM_TUNNEL)) {
  100464. if (skb == NULL) {
  100465. /* first fragment, reserve header_len */
  100466. - *mtu = orig_mtu - rt->dst.header_len;
  100467. + *mtu = *mtu - rt->dst.header_len;
  100468. } else {
  100469. /*
  100470. * this fragment is not first, the headers
  100471. * space is regarded as data space.
  100472. */
  100473. - *mtu = orig_mtu;
  100474. + *mtu = min(*mtu, pmtuprobe ?
  100475. + rt->dst.dev->mtu :
  100476. + dst_mtu(rt->dst.path));
  100477. }
  100478. *maxfraglen = ((*mtu - fragheaderlen) & ~7)
  100479. + fragheaderlen - sizeof(struct frag_hdr);
  100480. @@ -1117,7 +1119,7 @@
  100481. struct ipv6_pinfo *np = inet6_sk(sk);
  100482. struct inet_cork *cork;
  100483. struct sk_buff *skb, *skb_prev = NULL;
  100484. - unsigned int maxfraglen, fragheaderlen, mtu, orig_mtu;
  100485. + unsigned int maxfraglen, fragheaderlen, mtu;
  100486. int exthdrlen;
  100487. int dst_exthdrlen;
  100488. int hh_len;
  100489. @@ -1199,7 +1201,6 @@
  100490. dst_exthdrlen = 0;
  100491. mtu = cork->fragsize;
  100492. }
  100493. - orig_mtu = mtu;
  100494. hh_len = LL_RESERVED_SPACE(rt->dst.dev);
  100495. @@ -1279,7 +1280,8 @@
  100496. if (skb == NULL || skb_prev == NULL)
  100497. ip6_append_data_mtu(&mtu, &maxfraglen,
  100498. fragheaderlen, skb, rt,
  100499. - orig_mtu);
  100500. + np->pmtudisc ==
  100501. + IPV6_PMTUDISC_PROBE);
  100502. skb_prev = skb;
  100503. @@ -1535,8 +1537,8 @@
  100504. if (proto == IPPROTO_ICMPV6) {
  100505. struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
  100506. - ICMP6MSGOUT_INC_STATS(net, idev, icmp6_hdr(skb)->icmp6_type);
  100507. - ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTMSGS);
  100508. + ICMP6MSGOUT_INC_STATS_BH(net, idev, icmp6_hdr(skb)->icmp6_type);
  100509. + ICMP6_INC_STATS_BH(net, idev, ICMP6_MIB_OUTMSGS);
  100510. }
  100511. err = ip6_local_out(skb);
  100512. diff -Nur linux-3.12.18/net/ipv6/mcast.c linux-rpi/net/ipv6/mcast.c
  100513. --- linux-3.12.18/net/ipv6/mcast.c 2014-04-18 11:14:28.000000000 +0200
  100514. +++ linux-rpi/net/ipv6/mcast.c 2014-04-24 16:04:41.691142349 +0200
  100515. @@ -1620,12 +1620,11 @@
  100516. dst_output);
  100517. out:
  100518. if (!err) {
  100519. - ICMP6MSGOUT_INC_STATS(net, idev, ICMPV6_MLD2_REPORT);
  100520. - ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTMSGS);
  100521. - IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUTMCAST, payload_len);
  100522. - } else {
  100523. - IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS);
  100524. - }
  100525. + ICMP6MSGOUT_INC_STATS_BH(net, idev, ICMPV6_MLD2_REPORT);
  100526. + ICMP6_INC_STATS_BH(net, idev, ICMP6_MIB_OUTMSGS);
  100527. + IP6_UPD_PO_STATS_BH(net, idev, IPSTATS_MIB_OUTMCAST, payload_len);
  100528. + } else
  100529. + IP6_INC_STATS_BH(net, idev, IPSTATS_MIB_OUTDISCARDS);
  100530. rcu_read_unlock();
  100531. return;
  100532. diff -Nur linux-3.12.18/net/ipv6/ping.c linux-rpi/net/ipv6/ping.c
  100533. --- linux-3.12.18/net/ipv6/ping.c 2014-04-18 11:14:28.000000000 +0200
  100534. +++ linux-rpi/net/ipv6/ping.c 2014-04-24 16:04:41.695142388 +0200
  100535. @@ -182,8 +182,8 @@
  100536. MSG_DONTWAIT, np->dontfrag);
  100537. if (err) {
  100538. - ICMP6_INC_STATS(sock_net(sk), rt->rt6i_idev,
  100539. - ICMP6_MIB_OUTERRORS);
  100540. + ICMP6_INC_STATS_BH(sock_net(sk), rt->rt6i_idev,
  100541. + ICMP6_MIB_OUTERRORS);
  100542. ip6_flush_pending_frames(sk);
  100543. } else {
  100544. err = icmpv6_push_pending_frames(sk, &fl6,
  100545. diff -Nur linux-3.12.18/net/ipv6/route.c linux-rpi/net/ipv6/route.c
  100546. --- linux-3.12.18/net/ipv6/route.c 2014-04-18 11:14:28.000000000 +0200
  100547. +++ linux-rpi/net/ipv6/route.c 2014-04-24 16:04:41.699142427 +0200
  100548. @@ -1500,7 +1500,7 @@
  100549. if (!table)
  100550. goto out;
  100551. - rt = ip6_dst_alloc(net, NULL, (cfg->fc_flags & RTF_ADDRCONF) ? 0 : DST_NOCOUNT, table);
  100552. + rt = ip6_dst_alloc(net, NULL, DST_NOCOUNT, table);
  100553. if (!rt) {
  100554. err = -ENOMEM;
  100555. diff -Nur linux-3.12.18/net/rds/iw.c linux-rpi/net/rds/iw.c
  100556. --- linux-3.12.18/net/rds/iw.c 2014-04-18 11:14:28.000000000 +0200
  100557. +++ linux-rpi/net/rds/iw.c 2014-04-24 16:04:42.255147800 +0200
  100558. @@ -239,8 +239,7 @@
  100559. ret = rdma_bind_addr(cm_id, (struct sockaddr *)&sin);
  100560. /* due to this, we will claim to support IB devices unless we
  100561. check node_type. */
  100562. - if (ret || !cm_id->device ||
  100563. - cm_id->device->node_type != RDMA_NODE_RNIC)
  100564. + if (ret || cm_id->device->node_type != RDMA_NODE_RNIC)
  100565. ret = -EADDRNOTAVAIL;
  100566. rdsdebug("addr %pI4 ret %d node type %d\n",
  100567. diff -Nur linux-3.12.18/net/sched/sch_fq.c linux-rpi/net/sched/sch_fq.c
  100568. --- linux-3.12.18/net/sched/sch_fq.c 2014-04-18 11:14:28.000000000 +0200
  100569. +++ linux-rpi/net/sched/sch_fq.c 2014-04-24 16:04:42.255147800 +0200
  100570. @@ -577,11 +577,9 @@
  100571. q->stat_gc_flows += fcnt;
  100572. }
  100573. -static int fq_resize(struct Qdisc *sch, u32 log)
  100574. +static int fq_resize(struct fq_sched_data *q, u32 log)
  100575. {
  100576. - struct fq_sched_data *q = qdisc_priv(sch);
  100577. struct rb_root *array;
  100578. - void *old_fq_root;
  100579. u32 idx;
  100580. if (q->fq_root && log == q->fq_trees_log)
  100581. @@ -594,19 +592,13 @@
  100582. for (idx = 0; idx < (1U << log); idx++)
  100583. array[idx] = RB_ROOT;
  100584. - sch_tree_lock(sch);
  100585. -
  100586. - old_fq_root = q->fq_root;
  100587. - if (old_fq_root)
  100588. - fq_rehash(q, old_fq_root, q->fq_trees_log, array, log);
  100589. -
  100590. + if (q->fq_root) {
  100591. + fq_rehash(q, q->fq_root, q->fq_trees_log, array, log);
  100592. + kfree(q->fq_root);
  100593. + }
  100594. q->fq_root = array;
  100595. q->fq_trees_log = log;
  100596. - sch_tree_unlock(sch);
  100597. -
  100598. - kfree(old_fq_root);
  100599. -
  100600. return 0;
  100601. }
  100602. @@ -682,11 +674,9 @@
  100603. q->flow_refill_delay = usecs_to_jiffies(usecs_delay);
  100604. }
  100605. - if (!err) {
  100606. - sch_tree_unlock(sch);
  100607. - err = fq_resize(sch, fq_log);
  100608. - sch_tree_lock(sch);
  100609. - }
  100610. + if (!err)
  100611. + err = fq_resize(q, fq_log);
  100612. +
  100613. while (sch->q.qlen > sch->limit) {
  100614. struct sk_buff *skb = fq_dequeue(sch);
  100615. @@ -732,7 +722,7 @@
  100616. if (opt)
  100617. err = fq_change(sch, opt);
  100618. else
  100619. - err = fq_resize(sch, q->fq_trees_log);
  100620. + err = fq_resize(q, q->fq_trees_log);
  100621. return err;
  100622. }
  100623. diff -Nur linux-3.12.18/net/sctp/sm_make_chunk.c linux-rpi/net/sctp/sm_make_chunk.c
  100624. --- linux-3.12.18/net/sctp/sm_make_chunk.c 2014-04-18 11:14:28.000000000 +0200
  100625. +++ linux-rpi/net/sctp/sm_make_chunk.c 2014-04-24 16:04:42.263147878 +0200
  100626. @@ -1433,8 +1433,8 @@
  100627. BUG_ON(!list_empty(&chunk->list));
  100628. list_del_init(&chunk->transmitted_list);
  100629. - consume_skb(chunk->skb);
  100630. - consume_skb(chunk->auth_chunk);
  100631. + /* Free the chunk skb data and the SCTP_chunk stub itself. */
  100632. + dev_kfree_skb(chunk->skb);
  100633. SCTP_DBG_OBJCNT_DEC(chunk);
  100634. kmem_cache_free(sctp_chunk_cachep, chunk);
  100635. diff -Nur linux-3.12.18/net/sctp/sm_statefuns.c linux-rpi/net/sctp/sm_statefuns.c
  100636. --- linux-3.12.18/net/sctp/sm_statefuns.c 2014-04-18 11:14:28.000000000 +0200
  100637. +++ linux-rpi/net/sctp/sm_statefuns.c 2014-04-24 16:04:42.263147878 +0200
  100638. @@ -761,6 +761,7 @@
  100639. /* Make sure that we and the peer are AUTH capable */
  100640. if (!net->sctp.auth_enable || !new_asoc->peer.auth_capable) {
  100641. + kfree_skb(chunk->auth_chunk);
  100642. sctp_association_free(new_asoc);
  100643. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  100644. }
  100645. @@ -775,6 +776,10 @@
  100646. auth.transport = chunk->transport;
  100647. ret = sctp_sf_authenticate(net, ep, new_asoc, type, &auth);
  100648. +
  100649. + /* We can now safely free the auth_chunk clone */
  100650. + kfree_skb(chunk->auth_chunk);
  100651. +
  100652. if (ret != SCTP_IERROR_NO_ERROR) {
  100653. sctp_association_free(new_asoc);
  100654. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  100655. diff -Nur linux-3.12.18/net/socket.c linux-rpi/net/socket.c
  100656. --- linux-3.12.18/net/socket.c 2014-04-18 11:14:28.000000000 +0200
  100657. +++ linux-rpi/net/socket.c 2014-04-24 16:04:42.275147994 +0200
  100658. @@ -1972,10 +1972,6 @@
  100659. {
  100660. if (copy_from_user(kmsg, umsg, sizeof(struct msghdr)))
  100661. return -EFAULT;
  100662. -
  100663. - if (kmsg->msg_namelen < 0)
  100664. - return -EINVAL;
  100665. -
  100666. if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
  100667. kmsg->msg_namelen = sizeof(struct sockaddr_storage);
  100668. return 0;
  100669. diff -Nur linux-3.12.18/net/sunrpc/backchannel_rqst.c linux-rpi/net/sunrpc/backchannel_rqst.c
  100670. --- linux-3.12.18/net/sunrpc/backchannel_rqst.c 2014-04-18 11:14:28.000000000 +0200
  100671. +++ linux-rpi/net/sunrpc/backchannel_rqst.c 2014-04-24 15:35:05.273578028 +0200
  100672. @@ -64,6 +64,7 @@
  100673. free_page((unsigned long)xbufp->head[0].iov_base);
  100674. xbufp = &req->rq_snd_buf;
  100675. free_page((unsigned long)xbufp->head[0].iov_base);
  100676. + list_del(&req->rq_bc_pa_list);
  100677. kfree(req);
  100678. }
  100679. @@ -167,10 +168,8 @@
  100680. /*
  100681. * Memory allocation failed, free the temporary list
  100682. */
  100683. - list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list) {
  100684. - list_del(&req->rq_bc_pa_list);
  100685. + list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list)
  100686. xprt_free_allocation(req);
  100687. - }
  100688. dprintk("RPC: setup backchannel transport failed\n");
  100689. return -ENOMEM;
  100690. @@ -199,7 +198,6 @@
  100691. xprt_dec_alloc_count(xprt, max_reqs);
  100692. list_for_each_entry_safe(req, tmp, &xprt->bc_pa_list, rq_bc_pa_list) {
  100693. dprintk("RPC: req=%p\n", req);
  100694. - list_del(&req->rq_bc_pa_list);
  100695. xprt_free_allocation(req);
  100696. if (--max_reqs == 0)
  100697. break;
  100698. diff -Nur linux-3.12.18/net/tipc/config.c linux-rpi/net/tipc/config.c
  100699. --- linux-3.12.18/net/tipc/config.c 2014-04-18 11:14:28.000000000 +0200
  100700. +++ linux-rpi/net/tipc/config.c 2014-04-24 16:04:42.275147994 +0200
  100701. @@ -376,6 +376,7 @@
  100702. struct tipc_cfg_msg_hdr *req_hdr;
  100703. struct tipc_cfg_msg_hdr *rep_hdr;
  100704. struct sk_buff *rep_buf;
  100705. + int ret;
  100706. /* Validate configuration message header (ignore invalid message) */
  100707. req_hdr = (struct tipc_cfg_msg_hdr *)buf;
  100708. @@ -397,8 +398,12 @@
  100709. memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
  100710. rep_hdr->tcm_len = htonl(rep_buf->len);
  100711. rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
  100712. - tipc_conn_sendmsg(&cfgsrv, conid, addr, rep_buf->data,
  100713. - rep_buf->len);
  100714. +
  100715. + ret = tipc_conn_sendmsg(&cfgsrv, conid, addr, rep_buf->data,
  100716. + rep_buf->len);
  100717. + if (ret < 0)
  100718. + pr_err("Sending cfg reply message failed, no memory\n");
  100719. +
  100720. kfree_skb(rep_buf);
  100721. }
  100722. }
  100723. diff -Nur linux-3.12.18/net/tipc/handler.c linux-rpi/net/tipc/handler.c
  100724. --- linux-3.12.18/net/tipc/handler.c 2014-04-18 11:14:28.000000000 +0200
  100725. +++ linux-rpi/net/tipc/handler.c 2014-04-24 15:35:05.285578162 +0200
  100726. @@ -57,6 +57,7 @@
  100727. struct queue_item *item;
  100728. if (!handler_enabled) {
  100729. + pr_err("Signal request ignored by handler\n");
  100730. return -ENOPROTOOPT;
  100731. }
  100732. diff -Nur linux-3.12.18/net/tipc/name_table.c linux-rpi/net/tipc/name_table.c
  100733. --- linux-3.12.18/net/tipc/name_table.c 2014-04-18 11:14:28.000000000 +0200
  100734. +++ linux-rpi/net/tipc/name_table.c 2014-04-24 16:04:42.275147994 +0200
  100735. @@ -942,51 +942,20 @@
  100736. return 0;
  100737. }
  100738. -/**
  100739. - * tipc_purge_publications - remove all publications for a given type
  100740. - *
  100741. - * tipc_nametbl_lock must be held when calling this function
  100742. - */
  100743. -static void tipc_purge_publications(struct name_seq *seq)
  100744. -{
  100745. - struct publication *publ, *safe;
  100746. - struct sub_seq *sseq;
  100747. - struct name_info *info;
  100748. -
  100749. - if (!seq->sseqs) {
  100750. - nameseq_delete_empty(seq);
  100751. - return;
  100752. - }
  100753. - sseq = seq->sseqs;
  100754. - info = sseq->info;
  100755. - list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) {
  100756. - tipc_nametbl_remove_publ(publ->type, publ->lower, publ->node,
  100757. - publ->ref, publ->key);
  100758. - }
  100759. -}
  100760. -
  100761. void tipc_nametbl_stop(void)
  100762. {
  100763. u32 i;
  100764. - struct name_seq *seq;
  100765. - struct hlist_head *seq_head;
  100766. - struct hlist_node *safe;
  100767. if (!table.types)
  100768. return;
  100769. - /* Verify name table is empty and purge any lingering
  100770. - * publications, then release the name table
  100771. - */
  100772. + /* Verify name table is empty, then release it */
  100773. write_lock_bh(&tipc_nametbl_lock);
  100774. for (i = 0; i < TIPC_NAMETBL_SIZE; i++) {
  100775. if (hlist_empty(&table.types[i]))
  100776. continue;
  100777. - seq_head = &table.types[i];
  100778. - hlist_for_each_entry_safe(seq, safe, seq_head, ns_list) {
  100779. - tipc_purge_publications(seq);
  100780. - }
  100781. - continue;
  100782. + pr_err("nametbl_stop(): orphaned hash chain detected\n");
  100783. + break;
  100784. }
  100785. kfree(table.types);
  100786. table.types = NULL;
  100787. diff -Nur linux-3.12.18/net/tipc/server.c linux-rpi/net/tipc/server.c
  100788. --- linux-3.12.18/net/tipc/server.c 2014-04-18 11:14:28.000000000 +0200
  100789. +++ linux-rpi/net/tipc/server.c 2014-04-24 16:04:42.279148031 +0200
  100790. @@ -87,6 +87,7 @@
  100791. static void tipc_conn_kref_release(struct kref *kref)
  100792. {
  100793. struct tipc_conn *con = container_of(kref, struct tipc_conn, kref);
  100794. + struct tipc_server *s = con->server;
  100795. if (con->sock) {
  100796. tipc_sock_release_local(con->sock);
  100797. @@ -94,6 +95,10 @@
  100798. }
  100799. tipc_clean_outqueues(con);
  100800. +
  100801. + if (con->conid)
  100802. + s->tipc_conn_shutdown(con->conid, con->usr_data);
  100803. +
  100804. kfree(con);
  100805. }
  100806. @@ -176,9 +181,6 @@
  100807. struct tipc_server *s = con->server;
  100808. if (test_and_clear_bit(CF_CONNECTED, &con->flags)) {
  100809. - if (con->conid)
  100810. - s->tipc_conn_shutdown(con->conid, con->usr_data);
  100811. -
  100812. spin_lock_bh(&s->idr_lock);
  100813. idr_remove(&s->conn_idr, con->conid);
  100814. s->idr_in_use--;
  100815. @@ -427,12 +429,10 @@
  100816. list_add_tail(&e->list, &con->outqueue);
  100817. spin_unlock_bh(&con->outqueue_lock);
  100818. - if (test_bit(CF_CONNECTED, &con->flags)) {
  100819. + if (test_bit(CF_CONNECTED, &con->flags))
  100820. if (!queue_work(s->send_wq, &con->swork))
  100821. conn_put(con);
  100822. - } else {
  100823. - conn_put(con);
  100824. - }
  100825. +
  100826. return 0;
  100827. }
  100828. diff -Nur linux-3.12.18/net/tipc/subscr.c linux-rpi/net/tipc/subscr.c
  100829. --- linux-3.12.18/net/tipc/subscr.c 2014-04-18 11:14:28.000000000 +0200
  100830. +++ linux-rpi/net/tipc/subscr.c 2014-04-24 16:04:42.279148031 +0200
  100831. @@ -96,16 +96,20 @@
  100832. {
  100833. struct tipc_subscriber *subscriber = sub->subscriber;
  100834. struct kvec msg_sect;
  100835. + int ret;
  100836. msg_sect.iov_base = (void *)&sub->evt;
  100837. msg_sect.iov_len = sizeof(struct tipc_event);
  100838. +
  100839. sub->evt.event = htohl(event, sub->swap);
  100840. sub->evt.found_lower = htohl(found_lower, sub->swap);
  100841. sub->evt.found_upper = htohl(found_upper, sub->swap);
  100842. sub->evt.port.ref = htohl(port_ref, sub->swap);
  100843. sub->evt.port.node = htohl(node, sub->swap);
  100844. - tipc_conn_sendmsg(&topsrv, subscriber->conid, NULL, msg_sect.iov_base,
  100845. - msg_sect.iov_len);
  100846. + ret = tipc_conn_sendmsg(&topsrv, subscriber->conid, NULL,
  100847. + msg_sect.iov_base, msg_sect.iov_len);
  100848. + if (ret < 0)
  100849. + pr_err("Sending subscription event failed, no memory\n");
  100850. }
  100851. /**
  100852. @@ -149,6 +153,14 @@
  100853. /* The spin lock per subscriber is used to protect its members */
  100854. spin_lock_bh(&subscriber->lock);
  100855. + /* Validate if the connection related to the subscriber is
  100856. + * closed (in case subscriber is terminating)
  100857. + */
  100858. + if (subscriber->conid == 0) {
  100859. + spin_unlock_bh(&subscriber->lock);
  100860. + return;
  100861. + }
  100862. +
  100863. /* Validate timeout (in case subscription is being cancelled) */
  100864. if (sub->timeout == TIPC_WAIT_FOREVER) {
  100865. spin_unlock_bh(&subscriber->lock);
  100866. @@ -203,6 +215,9 @@
  100867. spin_lock_bh(&subscriber->lock);
  100868. + /* Invalidate subscriber reference */
  100869. + subscriber->conid = 0;
  100870. +
  100871. /* Destroy any existing subscriptions for subscriber */
  100872. list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list,
  100873. subscription_list) {
  100874. @@ -263,9 +278,9 @@
  100875. *
  100876. * Called with subscriber lock held.
  100877. */
  100878. -static int subscr_subscribe(struct tipc_subscr *s,
  100879. - struct tipc_subscriber *subscriber,
  100880. - struct tipc_subscription **sub_p) {
  100881. +static struct tipc_subscription *subscr_subscribe(struct tipc_subscr *s,
  100882. + struct tipc_subscriber *subscriber)
  100883. +{
  100884. struct tipc_subscription *sub;
  100885. int swap;
  100886. @@ -276,21 +291,23 @@
  100887. if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) {
  100888. s->filter &= ~htohl(TIPC_SUB_CANCEL, swap);
  100889. subscr_cancel(s, subscriber);
  100890. - return 0;
  100891. + return NULL;
  100892. }
  100893. /* Refuse subscription if global limit exceeded */
  100894. if (atomic_read(&subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) {
  100895. pr_warn("Subscription rejected, limit reached (%u)\n",
  100896. TIPC_MAX_SUBSCRIPTIONS);
  100897. - return -EINVAL;
  100898. + subscr_terminate(subscriber);
  100899. + return NULL;
  100900. }
  100901. /* Allocate subscription object */
  100902. sub = kmalloc(sizeof(*sub), GFP_ATOMIC);
  100903. if (!sub) {
  100904. pr_warn("Subscription rejected, no memory\n");
  100905. - return -ENOMEM;
  100906. + subscr_terminate(subscriber);
  100907. + return NULL;
  100908. }
  100909. /* Initialize subscription object */
  100910. @@ -304,7 +321,8 @@
  100911. (sub->seq.lower > sub->seq.upper)) {
  100912. pr_warn("Subscription rejected, illegal request\n");
  100913. kfree(sub);
  100914. - return -EINVAL;
  100915. + subscr_terminate(subscriber);
  100916. + return NULL;
  100917. }
  100918. INIT_LIST_HEAD(&sub->nameseq_list);
  100919. list_add(&sub->subscription_list, &subscriber->subscription_list);
  100920. @@ -317,8 +335,8 @@
  100921. (Handler)subscr_timeout, (unsigned long)sub);
  100922. k_start_timer(&sub->timer, sub->timeout);
  100923. }
  100924. - *sub_p = sub;
  100925. - return 0;
  100926. +
  100927. + return sub;
  100928. }
  100929. /* Handle one termination request for the subscriber */
  100930. @@ -332,14 +350,10 @@
  100931. void *usr_data, void *buf, size_t len)
  100932. {
  100933. struct tipc_subscriber *subscriber = usr_data;
  100934. - struct tipc_subscription *sub = NULL;
  100935. + struct tipc_subscription *sub;
  100936. spin_lock_bh(&subscriber->lock);
  100937. - if (subscr_subscribe((struct tipc_subscr *)buf, subscriber, &sub) < 0) {
  100938. - spin_unlock_bh(&subscriber->lock);
  100939. - subscr_terminate(subscriber);
  100940. - return;
  100941. - }
  100942. + sub = subscr_subscribe((struct tipc_subscr *)buf, subscriber);
  100943. if (sub)
  100944. tipc_nametbl_subscribe(sub);
  100945. spin_unlock_bh(&subscriber->lock);
  100946. diff -Nur linux-3.12.18/net/unix/af_unix.c linux-rpi/net/unix/af_unix.c
  100947. --- linux-3.12.18/net/unix/af_unix.c 2014-04-18 11:14:28.000000000 +0200
  100948. +++ linux-rpi/net/unix/af_unix.c 2014-04-24 16:04:42.279148031 +0200
  100949. @@ -1785,11 +1785,8 @@
  100950. goto out;
  100951. err = mutex_lock_interruptible(&u->readlock);
  100952. - if (unlikely(err)) {
  100953. - /* recvmsg() in non blocking mode is supposed to return -EAGAIN
  100954. - * sk_rcvtimeo is not honored by mutex_lock_interruptible()
  100955. - */
  100956. - err = noblock ? -EAGAIN : -ERESTARTSYS;
  100957. + if (err) {
  100958. + err = sock_intr_errno(sock_rcvtimeo(sk, noblock));
  100959. goto out;
  100960. }
  100961. @@ -1914,7 +1911,6 @@
  100962. struct unix_sock *u = unix_sk(sk);
  100963. struct sockaddr_un *sunaddr = msg->msg_name;
  100964. int copied = 0;
  100965. - int noblock = flags & MSG_DONTWAIT;
  100966. int check_creds = 0;
  100967. int target;
  100968. int err = 0;
  100969. @@ -1930,7 +1926,7 @@
  100970. goto out;
  100971. target = sock_rcvlowat(sk, flags&MSG_WAITALL, size);
  100972. - timeo = sock_rcvtimeo(sk, noblock);
  100973. + timeo = sock_rcvtimeo(sk, flags&MSG_DONTWAIT);
  100974. /* Lock the socket to prevent queue disordering
  100975. * while sleeps in memcpy_tomsg
  100976. @@ -1942,11 +1938,8 @@
  100977. }
  100978. err = mutex_lock_interruptible(&u->readlock);
  100979. - if (unlikely(err)) {
  100980. - /* recvmsg() in non blocking mode is supposed to return -EAGAIN
  100981. - * sk_rcvtimeo is not honored by mutex_lock_interruptible()
  100982. - */
  100983. - err = noblock ? -EAGAIN : -ERESTARTSYS;
  100984. + if (err) {
  100985. + err = sock_intr_errno(timeo);
  100986. goto out;
  100987. }
  100988. diff -Nur linux-3.12.18/security/selinux/hooks.c linux-rpi/security/selinux/hooks.c
  100989. --- linux-3.12.18/security/selinux/hooks.c 2014-04-18 11:14:28.000000000 +0200
  100990. +++ linux-rpi/security/selinux/hooks.c 2014-04-24 16:04:42.731152400 +0200
  100991. @@ -1386,33 +1386,15 @@
  100992. isec->sid = sbsec->sid;
  100993. if ((sbsec->flags & SE_SBPROC) && !S_ISLNK(inode->i_mode)) {
  100994. - /* We must have a dentry to determine the label on
  100995. - * procfs inodes */
  100996. - if (opt_dentry)
  100997. - /* Called from d_instantiate or
  100998. - * d_splice_alias. */
  100999. - dentry = dget(opt_dentry);
  101000. - else
  101001. - /* Called from selinux_complete_init, try to
  101002. - * find a dentry. */
  101003. - dentry = d_find_alias(inode);
  101004. - /*
  101005. - * This can be hit on boot when a file is accessed
  101006. - * before the policy is loaded. When we load policy we
  101007. - * may find inodes that have no dentry on the
  101008. - * sbsec->isec_head list. No reason to complain as
  101009. - * these will get fixed up the next time we go through
  101010. - * inode_doinit() with a dentry, before these inodes
  101011. - * could be used again by userspace.
  101012. - */
  101013. - if (!dentry)
  101014. - goto out_unlock;
  101015. - isec->sclass = inode_mode_to_security_class(inode->i_mode);
  101016. - rc = selinux_proc_get_sid(dentry, isec->sclass, &sid);
  101017. - dput(dentry);
  101018. - if (rc)
  101019. - goto out_unlock;
  101020. - isec->sid = sid;
  101021. + if (opt_dentry) {
  101022. + isec->sclass = inode_mode_to_security_class(inode->i_mode);
  101023. + rc = selinux_proc_get_sid(opt_dentry,
  101024. + isec->sclass,
  101025. + &sid);
  101026. + if (rc)
  101027. + goto out_unlock;
  101028. + isec->sid = sid;
  101029. + }
  101030. }
  101031. break;
  101032. }
  101033. diff -Nur linux-3.12.18/sound/arm/bcm2835.c linux-rpi/sound/arm/bcm2835.c
  101034. --- linux-3.12.18/sound/arm/bcm2835.c 1970-01-01 01:00:00.000000000 +0100
  101035. +++ linux-rpi/sound/arm/bcm2835.c 2014-04-24 16:04:42.735152438 +0200
  101036. @@ -0,0 +1,420 @@
  101037. +/*****************************************************************************
  101038. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  101039. +*
  101040. +* Unless you and Broadcom execute a separate written software license
  101041. +* agreement governing use of this software, this software is licensed to you
  101042. +* under the terms of the GNU General Public License version 2, available at
  101043. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  101044. +*
  101045. +* Notwithstanding the above, under no circumstances may you combine this
  101046. +* software in any way with any other Broadcom software provided under a
  101047. +* license other than the GPL, without Broadcom's express prior written
  101048. +* consent.
  101049. +*****************************************************************************/
  101050. +
  101051. +#include <linux/platform_device.h>
  101052. +
  101053. +#include <linux/init.h>
  101054. +#include <linux/slab.h>
  101055. +#include <linux/module.h>
  101056. +
  101057. +#include "bcm2835.h"
  101058. +
  101059. +/* module parameters (see "Module Parameters") */
  101060. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  101061. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  101062. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  101063. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  101064. +
  101065. +/* HACKY global pointers needed for successive probes to work : ssp
  101066. + * But compared against the changes we will have to do in VC audio_ipc code
  101067. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  101068. + * four devices in a thread, this gets things done quickly and should be easier
  101069. + * to debug if we run into issues
  101070. + */
  101071. +
  101072. +static struct snd_card *g_card = NULL;
  101073. +static bcm2835_chip_t *g_chip = NULL;
  101074. +
  101075. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  101076. +{
  101077. + kfree(chip);
  101078. + return 0;
  101079. +}
  101080. +
  101081. +/* component-destructor
  101082. + * (see "Management of Cards and Components")
  101083. + */
  101084. +static int snd_bcm2835_dev_free(struct snd_device *device)
  101085. +{
  101086. + return snd_bcm2835_free(device->device_data);
  101087. +}
  101088. +
  101089. +/* chip-specific constructor
  101090. + * (see "Management of Cards and Components")
  101091. + */
  101092. +static int snd_bcm2835_create(struct snd_card *card,
  101093. + struct platform_device *pdev,
  101094. + bcm2835_chip_t ** rchip)
  101095. +{
  101096. + bcm2835_chip_t *chip;
  101097. + int err;
  101098. + static struct snd_device_ops ops = {
  101099. + .dev_free = snd_bcm2835_dev_free,
  101100. + };
  101101. +
  101102. + *rchip = NULL;
  101103. +
  101104. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  101105. + if (chip == NULL)
  101106. + return -ENOMEM;
  101107. +
  101108. + chip->card = card;
  101109. +
  101110. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  101111. + if (err < 0) {
  101112. + snd_bcm2835_free(chip);
  101113. + return err;
  101114. + }
  101115. +
  101116. + *rchip = chip;
  101117. + return 0;
  101118. +}
  101119. +
  101120. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  101121. +{
  101122. + static int dev;
  101123. + bcm2835_chip_t *chip;
  101124. + struct snd_card *card;
  101125. + int err;
  101126. +
  101127. + if (dev >= MAX_SUBSTREAMS)
  101128. + return -ENODEV;
  101129. +
  101130. + if (!enable[dev]) {
  101131. + dev++;
  101132. + return -ENOENT;
  101133. + }
  101134. +
  101135. + if (dev > 0)
  101136. + goto add_register_map;
  101137. +
  101138. + err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &g_card);
  101139. + if (err < 0)
  101140. + goto out;
  101141. +
  101142. + snd_card_set_dev(g_card, &pdev->dev);
  101143. + strcpy(g_card->driver, "bcm2835");
  101144. + strcpy(g_card->shortname, "bcm2835 ALSA");
  101145. + sprintf(g_card->longname, "%s", g_card->shortname);
  101146. +
  101147. + err = snd_bcm2835_create(g_card, pdev, &chip);
  101148. + if (err < 0) {
  101149. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  101150. + goto out_bcm2835_create;
  101151. + }
  101152. +
  101153. + g_chip = chip;
  101154. + err = snd_bcm2835_new_pcm(chip);
  101155. + if (err < 0) {
  101156. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  101157. + goto out_bcm2835_new_pcm;
  101158. + }
  101159. +
  101160. + err = snd_bcm2835_new_spdif_pcm(chip);
  101161. + if (err < 0) {
  101162. + dev_err(&pdev->dev, "Failed to create new BCM2835 spdif pcm device\n");
  101163. + goto out_bcm2835_new_spdif;
  101164. + }
  101165. +
  101166. + err = snd_bcm2835_new_ctl(chip);
  101167. + if (err < 0) {
  101168. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  101169. + goto out_bcm2835_new_ctl;
  101170. + }
  101171. +
  101172. +add_register_map:
  101173. + card = g_card;
  101174. + chip = g_chip;
  101175. +
  101176. + BUG_ON(!(card && chip));
  101177. +
  101178. + chip->avail_substreams |= (1 << dev);
  101179. + chip->pdev[dev] = pdev;
  101180. +
  101181. + if (dev == 0) {
  101182. + err = snd_card_register(card);
  101183. + if (err < 0) {
  101184. + dev_err(&pdev->dev,
  101185. + "Failed to register bcm2835 ALSA card \n");
  101186. + goto out_card_register;
  101187. + }
  101188. + platform_set_drvdata(pdev, card);
  101189. + audio_info("bcm2835 ALSA card created!\n");
  101190. + } else {
  101191. + audio_info("bcm2835 ALSA chip created!\n");
  101192. + platform_set_drvdata(pdev, (void *)dev);
  101193. + }
  101194. +
  101195. + dev++;
  101196. +
  101197. + return 0;
  101198. +
  101199. +out_card_register:
  101200. +out_bcm2835_new_ctl:
  101201. +out_bcm2835_new_spdif:
  101202. +out_bcm2835_new_pcm:
  101203. +out_bcm2835_create:
  101204. + BUG_ON(!g_card);
  101205. + if (snd_card_free(g_card))
  101206. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  101207. + g_card = NULL;
  101208. +out:
  101209. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  101210. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  101211. + return err;
  101212. +}
  101213. +
  101214. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  101215. +{
  101216. + uint32_t idx;
  101217. + void *drv_data;
  101218. +
  101219. + drv_data = platform_get_drvdata(pdev);
  101220. +
  101221. + if (drv_data == (void *)g_card) {
  101222. + /* This is the card device */
  101223. + snd_card_free((struct snd_card *)drv_data);
  101224. + g_card = NULL;
  101225. + g_chip = NULL;
  101226. + } else {
  101227. + idx = (uint32_t) drv_data;
  101228. + if (g_card != NULL) {
  101229. + BUG_ON(!g_chip);
  101230. + /* We pass chip device numbers in audio ipc devices
  101231. + * other than the one we registered our card with
  101232. + */
  101233. + idx = (uint32_t) drv_data;
  101234. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  101235. + g_chip->avail_substreams &= ~(1 << idx);
  101236. + /* There should be atleast one substream registered
  101237. + * after we are done here, as it wil be removed when
  101238. + * the *remove* is called for the card device
  101239. + */
  101240. + BUG_ON(!g_chip->avail_substreams);
  101241. + }
  101242. + }
  101243. +
  101244. + platform_set_drvdata(pdev, NULL);
  101245. +
  101246. + return 0;
  101247. +}
  101248. +
  101249. +#ifdef CONFIG_PM
  101250. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  101251. + pm_message_t state)
  101252. +{
  101253. + return 0;
  101254. +}
  101255. +
  101256. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  101257. +{
  101258. + return 0;
  101259. +}
  101260. +
  101261. +#endif
  101262. +
  101263. +static struct platform_driver bcm2835_alsa0_driver = {
  101264. + .probe = snd_bcm2835_alsa_probe,
  101265. + .remove = snd_bcm2835_alsa_remove,
  101266. +#ifdef CONFIG_PM
  101267. + .suspend = snd_bcm2835_alsa_suspend,
  101268. + .resume = snd_bcm2835_alsa_resume,
  101269. +#endif
  101270. + .driver = {
  101271. + .name = "bcm2835_AUD0",
  101272. + .owner = THIS_MODULE,
  101273. + },
  101274. +};
  101275. +
  101276. +static struct platform_driver bcm2835_alsa1_driver = {
  101277. + .probe = snd_bcm2835_alsa_probe,
  101278. + .remove = snd_bcm2835_alsa_remove,
  101279. +#ifdef CONFIG_PM
  101280. + .suspend = snd_bcm2835_alsa_suspend,
  101281. + .resume = snd_bcm2835_alsa_resume,
  101282. +#endif
  101283. + .driver = {
  101284. + .name = "bcm2835_AUD1",
  101285. + .owner = THIS_MODULE,
  101286. + },
  101287. +};
  101288. +
  101289. +static struct platform_driver bcm2835_alsa2_driver = {
  101290. + .probe = snd_bcm2835_alsa_probe,
  101291. + .remove = snd_bcm2835_alsa_remove,
  101292. +#ifdef CONFIG_PM
  101293. + .suspend = snd_bcm2835_alsa_suspend,
  101294. + .resume = snd_bcm2835_alsa_resume,
  101295. +#endif
  101296. + .driver = {
  101297. + .name = "bcm2835_AUD2",
  101298. + .owner = THIS_MODULE,
  101299. + },
  101300. +};
  101301. +
  101302. +static struct platform_driver bcm2835_alsa3_driver = {
  101303. + .probe = snd_bcm2835_alsa_probe,
  101304. + .remove = snd_bcm2835_alsa_remove,
  101305. +#ifdef CONFIG_PM
  101306. + .suspend = snd_bcm2835_alsa_suspend,
  101307. + .resume = snd_bcm2835_alsa_resume,
  101308. +#endif
  101309. + .driver = {
  101310. + .name = "bcm2835_AUD3",
  101311. + .owner = THIS_MODULE,
  101312. + },
  101313. +};
  101314. +
  101315. +static struct platform_driver bcm2835_alsa4_driver = {
  101316. + .probe = snd_bcm2835_alsa_probe,
  101317. + .remove = snd_bcm2835_alsa_remove,
  101318. +#ifdef CONFIG_PM
  101319. + .suspend = snd_bcm2835_alsa_suspend,
  101320. + .resume = snd_bcm2835_alsa_resume,
  101321. +#endif
  101322. + .driver = {
  101323. + .name = "bcm2835_AUD4",
  101324. + .owner = THIS_MODULE,
  101325. + },
  101326. +};
  101327. +
  101328. +static struct platform_driver bcm2835_alsa5_driver = {
  101329. + .probe = snd_bcm2835_alsa_probe,
  101330. + .remove = snd_bcm2835_alsa_remove,
  101331. +#ifdef CONFIG_PM
  101332. + .suspend = snd_bcm2835_alsa_suspend,
  101333. + .resume = snd_bcm2835_alsa_resume,
  101334. +#endif
  101335. + .driver = {
  101336. + .name = "bcm2835_AUD5",
  101337. + .owner = THIS_MODULE,
  101338. + },
  101339. +};
  101340. +
  101341. +static struct platform_driver bcm2835_alsa6_driver = {
  101342. + .probe = snd_bcm2835_alsa_probe,
  101343. + .remove = snd_bcm2835_alsa_remove,
  101344. +#ifdef CONFIG_PM
  101345. + .suspend = snd_bcm2835_alsa_suspend,
  101346. + .resume = snd_bcm2835_alsa_resume,
  101347. +#endif
  101348. + .driver = {
  101349. + .name = "bcm2835_AUD6",
  101350. + .owner = THIS_MODULE,
  101351. + },
  101352. +};
  101353. +
  101354. +static struct platform_driver bcm2835_alsa7_driver = {
  101355. + .probe = snd_bcm2835_alsa_probe,
  101356. + .remove = snd_bcm2835_alsa_remove,
  101357. +#ifdef CONFIG_PM
  101358. + .suspend = snd_bcm2835_alsa_suspend,
  101359. + .resume = snd_bcm2835_alsa_resume,
  101360. +#endif
  101361. + .driver = {
  101362. + .name = "bcm2835_AUD7",
  101363. + .owner = THIS_MODULE,
  101364. + },
  101365. +};
  101366. +
  101367. +static int bcm2835_alsa_device_init(void)
  101368. +{
  101369. + int err;
  101370. + err = platform_driver_register(&bcm2835_alsa0_driver);
  101371. + if (err) {
  101372. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101373. + goto out;
  101374. + }
  101375. +
  101376. + err = platform_driver_register(&bcm2835_alsa1_driver);
  101377. + if (err) {
  101378. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101379. + goto unregister_0;
  101380. + }
  101381. +
  101382. + err = platform_driver_register(&bcm2835_alsa2_driver);
  101383. + if (err) {
  101384. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101385. + goto unregister_1;
  101386. + }
  101387. +
  101388. + err = platform_driver_register(&bcm2835_alsa3_driver);
  101389. + if (err) {
  101390. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101391. + goto unregister_2;
  101392. + }
  101393. +
  101394. + err = platform_driver_register(&bcm2835_alsa4_driver);
  101395. + if (err) {
  101396. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101397. + goto unregister_3;
  101398. + }
  101399. +
  101400. + err = platform_driver_register(&bcm2835_alsa5_driver);
  101401. + if (err) {
  101402. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101403. + goto unregister_4;
  101404. + }
  101405. +
  101406. + err = platform_driver_register(&bcm2835_alsa6_driver);
  101407. + if (err) {
  101408. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101409. + goto unregister_5;
  101410. + }
  101411. +
  101412. + err = platform_driver_register(&bcm2835_alsa7_driver);
  101413. + if (err) {
  101414. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101415. + goto unregister_6;
  101416. + }
  101417. +
  101418. + return 0;
  101419. +
  101420. +unregister_6:
  101421. + platform_driver_unregister(&bcm2835_alsa6_driver);
  101422. +unregister_5:
  101423. + platform_driver_unregister(&bcm2835_alsa5_driver);
  101424. +unregister_4:
  101425. + platform_driver_unregister(&bcm2835_alsa4_driver);
  101426. +unregister_3:
  101427. + platform_driver_unregister(&bcm2835_alsa3_driver);
  101428. +unregister_2:
  101429. + platform_driver_unregister(&bcm2835_alsa2_driver);
  101430. +unregister_1:
  101431. + platform_driver_unregister(&bcm2835_alsa1_driver);
  101432. +unregister_0:
  101433. + platform_driver_unregister(&bcm2835_alsa0_driver);
  101434. +out:
  101435. + return err;
  101436. +}
  101437. +
  101438. +static void bcm2835_alsa_device_exit(void)
  101439. +{
  101440. + platform_driver_unregister(&bcm2835_alsa0_driver);
  101441. + platform_driver_unregister(&bcm2835_alsa1_driver);
  101442. + platform_driver_unregister(&bcm2835_alsa2_driver);
  101443. + platform_driver_unregister(&bcm2835_alsa3_driver);
  101444. + platform_driver_unregister(&bcm2835_alsa4_driver);
  101445. + platform_driver_unregister(&bcm2835_alsa5_driver);
  101446. + platform_driver_unregister(&bcm2835_alsa6_driver);
  101447. + platform_driver_unregister(&bcm2835_alsa7_driver);
  101448. +}
  101449. +
  101450. +late_initcall(bcm2835_alsa_device_init);
  101451. +module_exit(bcm2835_alsa_device_exit);
  101452. +
  101453. +MODULE_AUTHOR("Dom Cobley");
  101454. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  101455. +MODULE_LICENSE("GPL");
  101456. +MODULE_ALIAS("platform:bcm2835_alsa");
  101457. diff -Nur linux-3.12.18/sound/arm/bcm2835-ctl.c linux-rpi/sound/arm/bcm2835-ctl.c
  101458. --- linux-3.12.18/sound/arm/bcm2835-ctl.c 1970-01-01 01:00:00.000000000 +0100
  101459. +++ linux-rpi/sound/arm/bcm2835-ctl.c 2014-04-24 16:04:42.735152438 +0200
  101460. @@ -0,0 +1,323 @@
  101461. +/*****************************************************************************
  101462. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  101463. +*
  101464. +* Unless you and Broadcom execute a separate written software license
  101465. +* agreement governing use of this software, this software is licensed to you
  101466. +* under the terms of the GNU General Public License version 2, available at
  101467. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  101468. +*
  101469. +* Notwithstanding the above, under no circumstances may you combine this
  101470. +* software in any way with any other Broadcom software provided under a
  101471. +* license other than the GPL, without Broadcom's express prior written
  101472. +* consent.
  101473. +*****************************************************************************/
  101474. +
  101475. +#include <linux/platform_device.h>
  101476. +#include <linux/init.h>
  101477. +#include <linux/io.h>
  101478. +#include <linux/jiffies.h>
  101479. +#include <linux/slab.h>
  101480. +#include <linux/time.h>
  101481. +#include <linux/wait.h>
  101482. +#include <linux/delay.h>
  101483. +#include <linux/moduleparam.h>
  101484. +#include <linux/sched.h>
  101485. +
  101486. +#include <sound/core.h>
  101487. +#include <sound/control.h>
  101488. +#include <sound/pcm.h>
  101489. +#include <sound/pcm_params.h>
  101490. +#include <sound/rawmidi.h>
  101491. +#include <sound/initval.h>
  101492. +#include <sound/tlv.h>
  101493. +#include <sound/asoundef.h>
  101494. +
  101495. +#include "bcm2835.h"
  101496. +
  101497. +/* volume maximum and minimum in terms of 0.01dB */
  101498. +#define CTRL_VOL_MAX 400
  101499. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  101500. +
  101501. +
  101502. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  101503. + struct snd_ctl_elem_info *uinfo)
  101504. +{
  101505. + audio_info(" ... IN\n");
  101506. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  101507. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  101508. + uinfo->count = 1;
  101509. + uinfo->value.integer.min = CTRL_VOL_MIN;
  101510. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  101511. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  101512. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  101513. + uinfo->count = 1;
  101514. + uinfo->value.integer.min = 0;
  101515. + uinfo->value.integer.max = 1;
  101516. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  101517. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  101518. + uinfo->count = 1;
  101519. + uinfo->value.integer.min = 0;
  101520. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  101521. + }
  101522. + audio_info(" ... OUT\n");
  101523. + return 0;
  101524. +}
  101525. +
  101526. +/* toggles mute on or off depending on the value of nmute, and returns
  101527. + * 1 if the mute value was changed, otherwise 0
  101528. + */
  101529. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  101530. +{
  101531. + /* if settings are ok, just return 0 */
  101532. + if(chip->mute == nmute)
  101533. + return 0;
  101534. +
  101535. + /* if the sound is muted then we need to unmute */
  101536. + if(chip->mute == CTRL_VOL_MUTE)
  101537. + {
  101538. + chip->volume = chip->old_volume; /* copy the old volume back */
  101539. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  101540. + }
  101541. + else /* otherwise we mute */
  101542. + {
  101543. + chip->old_volume = chip->volume;
  101544. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  101545. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  101546. + }
  101547. +
  101548. + chip->mute = nmute;
  101549. + return 1;
  101550. +}
  101551. +
  101552. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  101553. + struct snd_ctl_elem_value *ucontrol)
  101554. +{
  101555. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101556. +
  101557. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  101558. +
  101559. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  101560. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  101561. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  101562. + ucontrol->value.integer.value[0] = chip->mute;
  101563. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  101564. + ucontrol->value.integer.value[0] = chip->dest;
  101565. +
  101566. + return 0;
  101567. +}
  101568. +
  101569. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  101570. + struct snd_ctl_elem_value *ucontrol)
  101571. +{
  101572. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101573. + int changed = 0;
  101574. +
  101575. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  101576. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  101577. + if (chip->mute == CTRL_VOL_MUTE) {
  101578. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  101579. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  101580. + }
  101581. + if (changed
  101582. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  101583. +
  101584. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  101585. + changed = 1;
  101586. + }
  101587. +
  101588. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  101589. + /* Now implemented */
  101590. + audio_info(" Mute attempted\n");
  101591. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  101592. +
  101593. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  101594. + if (ucontrol->value.integer.value[0] != chip->dest) {
  101595. + chip->dest = ucontrol->value.integer.value[0];
  101596. + changed = 1;
  101597. + }
  101598. + }
  101599. +
  101600. + if (changed) {
  101601. + if (bcm2835_audio_set_ctls(chip))
  101602. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  101603. + }
  101604. +
  101605. + return changed;
  101606. +}
  101607. +
  101608. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  101609. +
  101610. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  101611. + {
  101612. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  101613. + .name = "PCM Playback Volume",
  101614. + .index = 0,
  101615. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  101616. + .private_value = PCM_PLAYBACK_VOLUME,
  101617. + .info = snd_bcm2835_ctl_info,
  101618. + .get = snd_bcm2835_ctl_get,
  101619. + .put = snd_bcm2835_ctl_put,
  101620. + .count = 1,
  101621. + .tlv = {.p = snd_bcm2835_db_scale}
  101622. + },
  101623. + {
  101624. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  101625. + .name = "PCM Playback Switch",
  101626. + .index = 0,
  101627. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  101628. + .private_value = PCM_PLAYBACK_MUTE,
  101629. + .info = snd_bcm2835_ctl_info,
  101630. + .get = snd_bcm2835_ctl_get,
  101631. + .put = snd_bcm2835_ctl_put,
  101632. + .count = 1,
  101633. + },
  101634. + {
  101635. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  101636. + .name = "PCM Playback Route",
  101637. + .index = 0,
  101638. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  101639. + .private_value = PCM_PLAYBACK_DEVICE,
  101640. + .info = snd_bcm2835_ctl_info,
  101641. + .get = snd_bcm2835_ctl_get,
  101642. + .put = snd_bcm2835_ctl_put,
  101643. + .count = 1,
  101644. + },
  101645. +};
  101646. +
  101647. +static int snd_bcm2835_spdif_default_info(struct snd_kcontrol *kcontrol,
  101648. + struct snd_ctl_elem_info *uinfo)
  101649. +{
  101650. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  101651. + uinfo->count = 1;
  101652. + return 0;
  101653. +}
  101654. +
  101655. +static int snd_bcm2835_spdif_default_get(struct snd_kcontrol *kcontrol,
  101656. + struct snd_ctl_elem_value *ucontrol)
  101657. +{
  101658. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101659. + int i;
  101660. +
  101661. + for (i = 0; i < 4; i++)
  101662. + ucontrol->value.iec958.status[i] =
  101663. + (chip->spdif_status >> (i * 8)) && 0xff;
  101664. +
  101665. + return 0;
  101666. +}
  101667. +
  101668. +static int snd_bcm2835_spdif_default_put(struct snd_kcontrol *kcontrol,
  101669. + struct snd_ctl_elem_value *ucontrol)
  101670. +{
  101671. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101672. + unsigned int val = 0;
  101673. + int i, change;
  101674. +
  101675. + for (i = 0; i < 4; i++)
  101676. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  101677. +
  101678. + change = val != chip->spdif_status;
  101679. + chip->spdif_status = val;
  101680. +
  101681. + return change;
  101682. +}
  101683. +
  101684. +static int snd_bcm2835_spdif_mask_info(struct snd_kcontrol *kcontrol,
  101685. + struct snd_ctl_elem_info *uinfo)
  101686. +{
  101687. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  101688. + uinfo->count = 1;
  101689. + return 0;
  101690. +}
  101691. +
  101692. +static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol,
  101693. + struct snd_ctl_elem_value *ucontrol)
  101694. +{
  101695. + /* bcm2835 supports only consumer mode and sets all other format flags
  101696. + * automatically. So the only thing left is signalling non-audio
  101697. + * content */
  101698. + ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO;
  101699. + return 0;
  101700. +}
  101701. +
  101702. +static int snd_bcm2835_spdif_stream_info(struct snd_kcontrol *kcontrol,
  101703. + struct snd_ctl_elem_info *uinfo)
  101704. +{
  101705. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  101706. + uinfo->count = 1;
  101707. + return 0;
  101708. +}
  101709. +
  101710. +static int snd_bcm2835_spdif_stream_get(struct snd_kcontrol *kcontrol,
  101711. + struct snd_ctl_elem_value *ucontrol)
  101712. +{
  101713. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101714. + int i;
  101715. +
  101716. + for (i = 0; i < 4; i++)
  101717. + ucontrol->value.iec958.status[i] =
  101718. + (chip->spdif_status >> (i * 8)) & 0xff;
  101719. + return 0;
  101720. +}
  101721. +
  101722. +static int snd_bcm2835_spdif_stream_put(struct snd_kcontrol *kcontrol,
  101723. + struct snd_ctl_elem_value *ucontrol)
  101724. +{
  101725. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101726. + unsigned int val = 0;
  101727. + int i, change;
  101728. +
  101729. + for (i = 0; i < 4; i++)
  101730. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  101731. + change = val != chip->spdif_status;
  101732. + chip->spdif_status = val;
  101733. +
  101734. + return change;
  101735. +}
  101736. +
  101737. +static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
  101738. + {
  101739. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  101740. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  101741. + .info = snd_bcm2835_spdif_default_info,
  101742. + .get = snd_bcm2835_spdif_default_get,
  101743. + .put = snd_bcm2835_spdif_default_put
  101744. + },
  101745. + {
  101746. + .access = SNDRV_CTL_ELEM_ACCESS_READ,
  101747. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  101748. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
  101749. + .info = snd_bcm2835_spdif_mask_info,
  101750. + .get = snd_bcm2835_spdif_mask_get,
  101751. + },
  101752. + {
  101753. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  101754. + SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  101755. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  101756. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  101757. + .info = snd_bcm2835_spdif_stream_info,
  101758. + .get = snd_bcm2835_spdif_stream_get,
  101759. + .put = snd_bcm2835_spdif_stream_put,
  101760. + },
  101761. +};
  101762. +
  101763. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  101764. +{
  101765. + int err;
  101766. + unsigned int idx;
  101767. +
  101768. + strcpy(chip->card->mixername, "Broadcom Mixer");
  101769. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  101770. + err =
  101771. + snd_ctl_add(chip->card,
  101772. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  101773. + if (err < 0)
  101774. + return err;
  101775. + }
  101776. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
  101777. + err = snd_ctl_add(chip->card,
  101778. + snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
  101779. + if (err < 0)
  101780. + return err;
  101781. + }
  101782. + return 0;
  101783. +}
  101784. diff -Nur linux-3.12.18/sound/arm/bcm2835.h linux-rpi/sound/arm/bcm2835.h
  101785. --- linux-3.12.18/sound/arm/bcm2835.h 1970-01-01 01:00:00.000000000 +0100
  101786. +++ linux-rpi/sound/arm/bcm2835.h 2014-04-24 16:04:42.735152438 +0200
  101787. @@ -0,0 +1,166 @@
  101788. +/*****************************************************************************
  101789. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  101790. +*
  101791. +* Unless you and Broadcom execute a separate written software license
  101792. +* agreement governing use of this software, this software is licensed to you
  101793. +* under the terms of the GNU General Public License version 2, available at
  101794. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  101795. +*
  101796. +* Notwithstanding the above, under no circumstances may you combine this
  101797. +* software in any way with any other Broadcom software provided under a
  101798. +* license other than the GPL, without Broadcom's express prior written
  101799. +* consent.
  101800. +*****************************************************************************/
  101801. +
  101802. +#ifndef __SOUND_ARM_BCM2835_H
  101803. +#define __SOUND_ARM_BCM2835_H
  101804. +
  101805. +#include <linux/device.h>
  101806. +#include <linux/list.h>
  101807. +#include <linux/interrupt.h>
  101808. +#include <linux/wait.h>
  101809. +#include <sound/core.h>
  101810. +#include <sound/initval.h>
  101811. +#include <sound/pcm.h>
  101812. +#include <sound/pcm_params.h>
  101813. +#include <sound/pcm-indirect.h>
  101814. +#include <linux/workqueue.h>
  101815. +
  101816. +/*
  101817. +#define AUDIO_DEBUG_ENABLE
  101818. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  101819. +*/
  101820. +
  101821. +/* Debug macros */
  101822. +
  101823. +#ifdef AUDIO_DEBUG_ENABLE
  101824. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  101825. +
  101826. +#define audio_debug(fmt, arg...) \
  101827. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  101828. +
  101829. +#define audio_info(fmt, arg...) \
  101830. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  101831. +
  101832. +#else
  101833. +
  101834. +#define audio_debug(fmt, arg...)
  101835. +
  101836. +#define audio_info(fmt, arg...)
  101837. +
  101838. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  101839. +
  101840. +#else
  101841. +
  101842. +#define audio_debug(fmt, arg...)
  101843. +
  101844. +#define audio_info(fmt, arg...)
  101845. +
  101846. +#endif /* AUDIO_DEBUG_ENABLE */
  101847. +
  101848. +#define audio_error(fmt, arg...) \
  101849. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  101850. +
  101851. +#define audio_warning(fmt, arg...) \
  101852. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  101853. +
  101854. +#define audio_alert(fmt, arg...) \
  101855. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  101856. +
  101857. +#define MAX_SUBSTREAMS (8)
  101858. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  101859. +enum {
  101860. + CTRL_VOL_MUTE,
  101861. + CTRL_VOL_UNMUTE
  101862. +};
  101863. +
  101864. +/* macros for alsa2chip and chip2alsa, instead of functions */
  101865. +
  101866. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  101867. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  101868. +
  101869. +/* Some constants for values .. */
  101870. +typedef enum {
  101871. + AUDIO_DEST_AUTO = 0,
  101872. + AUDIO_DEST_HEADPHONES = 1,
  101873. + AUDIO_DEST_HDMI = 2,
  101874. + AUDIO_DEST_MAX,
  101875. +} SND_BCM2835_ROUTE_T;
  101876. +
  101877. +typedef enum {
  101878. + PCM_PLAYBACK_VOLUME,
  101879. + PCM_PLAYBACK_MUTE,
  101880. + PCM_PLAYBACK_DEVICE,
  101881. +} SND_BCM2835_CTRL_T;
  101882. +
  101883. +/* definition of the chip-specific record */
  101884. +typedef struct bcm2835_chip {
  101885. + struct snd_card *card;
  101886. + struct snd_pcm *pcm;
  101887. + struct snd_pcm *pcm_spdif;
  101888. + /* Bitmat for valid reg_base and irq numbers */
  101889. + uint32_t avail_substreams;
  101890. + struct platform_device *pdev[MAX_SUBSTREAMS];
  101891. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  101892. +
  101893. + int volume;
  101894. + int old_volume; /* stores the volume value whist muted */
  101895. + int dest;
  101896. + int mute;
  101897. +
  101898. + unsigned int opened;
  101899. + unsigned int spdif_status;
  101900. +} bcm2835_chip_t;
  101901. +
  101902. +typedef struct bcm2835_alsa_stream {
  101903. + bcm2835_chip_t *chip;
  101904. + struct snd_pcm_substream *substream;
  101905. + struct snd_pcm_indirect pcm_indirect;
  101906. +
  101907. + struct semaphore buffers_update_sem;
  101908. + struct semaphore control_sem;
  101909. + spinlock_t lock;
  101910. + volatile uint32_t control;
  101911. + volatile uint32_t status;
  101912. +
  101913. + int open;
  101914. + int running;
  101915. + int draining;
  101916. +
  101917. + int channels;
  101918. + int params_rate;
  101919. + int pcm_format_width;
  101920. +
  101921. + unsigned int pos;
  101922. + unsigned int buffer_size;
  101923. + unsigned int period_size;
  101924. +
  101925. + uint32_t enable_fifo_irq;
  101926. + irq_handler_t fifo_irq_handler;
  101927. +
  101928. + atomic_t retrieved;
  101929. + struct opaque_AUDIO_INSTANCE_T *instance;
  101930. + struct workqueue_struct *my_wq;
  101931. + int idx;
  101932. +} bcm2835_alsa_stream_t;
  101933. +
  101934. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  101935. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  101936. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip);
  101937. +
  101938. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  101939. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  101940. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  101941. + uint32_t channels, uint32_t samplerate,
  101942. + uint32_t bps);
  101943. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  101944. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  101945. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  101946. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  101947. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  101948. + void *src);
  101949. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  101950. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  101951. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  101952. +
  101953. +#endif /* __SOUND_ARM_BCM2835_H */
  101954. diff -Nur linux-3.12.18/sound/arm/bcm2835-pcm.c linux-rpi/sound/arm/bcm2835-pcm.c
  101955. --- linux-3.12.18/sound/arm/bcm2835-pcm.c 1970-01-01 01:00:00.000000000 +0100
  101956. +++ linux-rpi/sound/arm/bcm2835-pcm.c 2014-04-24 16:04:42.735152438 +0200
  101957. @@ -0,0 +1,518 @@
  101958. +/*****************************************************************************
  101959. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  101960. +*
  101961. +* Unless you and Broadcom execute a separate written software license
  101962. +* agreement governing use of this software, this software is licensed to you
  101963. +* under the terms of the GNU General Public License version 2, available at
  101964. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  101965. +*
  101966. +* Notwithstanding the above, under no circumstances may you combine this
  101967. +* software in any way with any other Broadcom software provided under a
  101968. +* license other than the GPL, without Broadcom's express prior written
  101969. +* consent.
  101970. +*****************************************************************************/
  101971. +
  101972. +#include <linux/interrupt.h>
  101973. +#include <linux/slab.h>
  101974. +
  101975. +#include <sound/asoundef.h>
  101976. +
  101977. +#include "bcm2835.h"
  101978. +
  101979. +/* hardware definition */
  101980. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  101981. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  101982. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  101983. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  101984. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  101985. + .rate_min = 8000,
  101986. + .rate_max = 48000,
  101987. + .channels_min = 1,
  101988. + .channels_max = 2,
  101989. + .buffer_bytes_max = 128 * 1024,
  101990. + .period_bytes_min = 1 * 1024,
  101991. + .period_bytes_max = 128 * 1024,
  101992. + .periods_min = 1,
  101993. + .periods_max = 128,
  101994. +};
  101995. +
  101996. +static struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
  101997. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  101998. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  101999. + .formats = SNDRV_PCM_FMTBIT_S16_LE,
  102000. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
  102001. + SNDRV_PCM_RATE_48000,
  102002. + .rate_min = 44100,
  102003. + .rate_max = 48000,
  102004. + .channels_min = 2,
  102005. + .channels_max = 2,
  102006. + .buffer_bytes_max = 128 * 1024,
  102007. + .period_bytes_min = 1 * 1024,
  102008. + .period_bytes_max = 128 * 1024,
  102009. + .periods_min = 1,
  102010. + .periods_max = 128,
  102011. +};
  102012. +
  102013. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  102014. +{
  102015. + audio_info("Freeing up alsa stream here ..\n");
  102016. + if (runtime->private_data)
  102017. + kfree(runtime->private_data);
  102018. + runtime->private_data = NULL;
  102019. +}
  102020. +
  102021. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  102022. +{
  102023. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  102024. + uint32_t consumed = 0;
  102025. + int new_period = 0;
  102026. +
  102027. + audio_info(" .. IN\n");
  102028. +
  102029. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  102030. + alsa_stream ? alsa_stream->substream : 0);
  102031. +
  102032. + if (alsa_stream->open)
  102033. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  102034. +
  102035. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  102036. + * each iteration are the buffers that have been played out already
  102037. + */
  102038. +
  102039. + if (alsa_stream->period_size) {
  102040. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  102041. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  102042. + new_period = 1;
  102043. + }
  102044. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  102045. + alsa_stream->pos,
  102046. + consumed,
  102047. + alsa_stream->buffer_size,
  102048. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  102049. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  102050. + new_period);
  102051. + if (alsa_stream->buffer_size) {
  102052. + alsa_stream->pos += consumed &~ (1<<30);
  102053. + alsa_stream->pos %= alsa_stream->buffer_size;
  102054. + }
  102055. +
  102056. + if (alsa_stream->substream) {
  102057. + if (new_period)
  102058. + snd_pcm_period_elapsed(alsa_stream->substream);
  102059. + } else {
  102060. + audio_warning(" unexpected NULL substream\n");
  102061. + }
  102062. + audio_info(" .. OUT\n");
  102063. +
  102064. + return IRQ_HANDLED;
  102065. +}
  102066. +
  102067. +/* open callback */
  102068. +static int snd_bcm2835_playback_open_generic(
  102069. + struct snd_pcm_substream *substream, int spdif)
  102070. +{
  102071. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  102072. + struct snd_pcm_runtime *runtime = substream->runtime;
  102073. + bcm2835_alsa_stream_t *alsa_stream;
  102074. + int idx;
  102075. + int err;
  102076. +
  102077. + audio_info(" .. IN (%d)\n", substream->number);
  102078. +
  102079. + audio_info("Alsa open (%d)\n", substream->number);
  102080. + idx = substream->number;
  102081. +
  102082. + if (spdif && chip->opened != 0)
  102083. + return -EBUSY;
  102084. + else if (!spdif && (chip->opened & (1 << idx)))
  102085. + return -EBUSY;
  102086. +
  102087. + if (idx > MAX_SUBSTREAMS) {
  102088. + audio_error
  102089. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  102090. + idx, MAX_SUBSTREAMS);
  102091. + err = -ENODEV;
  102092. + goto out;
  102093. + }
  102094. +
  102095. + /* Check if we are ready */
  102096. + if (!(chip->avail_substreams & (1 << idx))) {
  102097. + /* We are not ready yet */
  102098. + audio_error("substream(%d) device is not ready yet\n", idx);
  102099. + err = -EAGAIN;
  102100. + goto out;
  102101. + }
  102102. +
  102103. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  102104. + if (alsa_stream == NULL) {
  102105. + return -ENOMEM;
  102106. + }
  102107. +
  102108. + /* Initialise alsa_stream */
  102109. + alsa_stream->chip = chip;
  102110. + alsa_stream->substream = substream;
  102111. + alsa_stream->idx = idx;
  102112. +
  102113. + sema_init(&alsa_stream->buffers_update_sem, 0);
  102114. + sema_init(&alsa_stream->control_sem, 0);
  102115. + spin_lock_init(&alsa_stream->lock);
  102116. +
  102117. + /* Enabled in start trigger, called on each "fifo irq" after that */
  102118. + alsa_stream->enable_fifo_irq = 0;
  102119. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  102120. +
  102121. + runtime->private_data = alsa_stream;
  102122. + runtime->private_free = snd_bcm2835_playback_free;
  102123. + if (spdif) {
  102124. + runtime->hw = snd_bcm2835_playback_spdif_hw;
  102125. + } else {
  102126. + /* clear spdif status, as we are not in spdif mode */
  102127. + chip->spdif_status = 0;
  102128. + runtime->hw = snd_bcm2835_playback_hw;
  102129. + }
  102130. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  102131. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  102132. + 16);
  102133. +
  102134. + err = bcm2835_audio_open(alsa_stream);
  102135. + if (err != 0) {
  102136. + kfree(alsa_stream);
  102137. + return err;
  102138. + }
  102139. + chip->alsa_stream[idx] = alsa_stream;
  102140. +
  102141. + chip->opened |= (1 << idx);
  102142. + alsa_stream->open = 1;
  102143. + alsa_stream->draining = 1;
  102144. +
  102145. +out:
  102146. + audio_info(" .. OUT =%d\n", err);
  102147. +
  102148. + return err;
  102149. +}
  102150. +
  102151. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  102152. +{
  102153. + return snd_bcm2835_playback_open_generic(substream, 0);
  102154. +}
  102155. +
  102156. +static int snd_bcm2835_playback_spdif_open(struct snd_pcm_substream *substream)
  102157. +{
  102158. + return snd_bcm2835_playback_open_generic(substream, 1);
  102159. +}
  102160. +
  102161. +/* close callback */
  102162. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  102163. +{
  102164. + /* the hardware-specific codes will be here */
  102165. +
  102166. + struct snd_pcm_runtime *runtime = substream->runtime;
  102167. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  102168. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  102169. +
  102170. + audio_info(" .. IN\n");
  102171. + audio_info("Alsa close\n");
  102172. +
  102173. + /*
  102174. + * Call stop if it's still running. This happens when app
  102175. + * is force killed and we don't get a stop trigger.
  102176. + */
  102177. + if (alsa_stream->running) {
  102178. + int err;
  102179. + err = bcm2835_audio_stop(alsa_stream);
  102180. + alsa_stream->running = 0;
  102181. + if (err != 0)
  102182. + audio_error(" Failed to STOP alsa device\n");
  102183. + }
  102184. +
  102185. + alsa_stream->period_size = 0;
  102186. + alsa_stream->buffer_size = 0;
  102187. +
  102188. + if (alsa_stream->open) {
  102189. + alsa_stream->open = 0;
  102190. + bcm2835_audio_close(alsa_stream);
  102191. + }
  102192. + if (alsa_stream->chip)
  102193. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  102194. + /*
  102195. + * Do not free up alsa_stream here, it will be freed up by
  102196. + * runtime->private_free callback we registered in *_open above
  102197. + */
  102198. +
  102199. + chip->opened &= ~(1 << substream->number);
  102200. +
  102201. + audio_info(" .. OUT\n");
  102202. +
  102203. + return 0;
  102204. +}
  102205. +
  102206. +/* hw_params callback */
  102207. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  102208. + struct snd_pcm_hw_params *params)
  102209. +{
  102210. + struct snd_pcm_runtime *runtime = substream->runtime;
  102211. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  102212. + int err;
  102213. +
  102214. + audio_info(" .. IN\n");
  102215. +
  102216. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  102217. + if (err < 0) {
  102218. + audio_error
  102219. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  102220. + return err;
  102221. + }
  102222. +
  102223. + alsa_stream->channels = params_channels(params);
  102224. + alsa_stream->params_rate = params_rate(params);
  102225. + alsa_stream->pcm_format_width = snd_pcm_format_width(params_format (params));
  102226. + audio_info(" .. OUT\n");
  102227. +
  102228. + return err;
  102229. +}
  102230. +
  102231. +/* hw_free callback */
  102232. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  102233. +{
  102234. + audio_info(" .. IN\n");
  102235. + return snd_pcm_lib_free_pages(substream);
  102236. +}
  102237. +
  102238. +/* prepare callback */
  102239. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  102240. +{
  102241. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  102242. + struct snd_pcm_runtime *runtime = substream->runtime;
  102243. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  102244. + int channels;
  102245. + int err;
  102246. +
  102247. + audio_info(" .. IN\n");
  102248. +
  102249. + /* notify the vchiq that it should enter spdif passthrough mode by
  102250. + * setting channels=0 (see
  102251. + * https://github.com/raspberrypi/linux/issues/528) */
  102252. + if (chip->spdif_status & IEC958_AES0_NONAUDIO)
  102253. + channels = 0;
  102254. + else
  102255. + channels = alsa_stream->channels;
  102256. +
  102257. + err = bcm2835_audio_set_params(alsa_stream, channels,
  102258. + alsa_stream->params_rate,
  102259. + alsa_stream->pcm_format_width);
  102260. + if (err < 0) {
  102261. + audio_error(" error setting hw params\n");
  102262. + }
  102263. +
  102264. + bcm2835_audio_setup(alsa_stream);
  102265. +
  102266. + /* in preparation of the stream, set the controls (volume level) of the stream */
  102267. + bcm2835_audio_set_ctls(alsa_stream->chip);
  102268. +
  102269. +
  102270. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  102271. +
  102272. + alsa_stream->pcm_indirect.hw_buffer_size =
  102273. + alsa_stream->pcm_indirect.sw_buffer_size =
  102274. + snd_pcm_lib_buffer_bytes(substream);
  102275. +
  102276. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  102277. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  102278. + alsa_stream->pos = 0;
  102279. +
  102280. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  102281. + alsa_stream->buffer_size, alsa_stream->period_size,
  102282. + alsa_stream->pos, runtime->frame_bits);
  102283. +
  102284. + audio_info(" .. OUT\n");
  102285. + return 0;
  102286. +}
  102287. +
  102288. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  102289. + struct snd_pcm_indirect *rec, size_t bytes)
  102290. +{
  102291. + struct snd_pcm_runtime *runtime = substream->runtime;
  102292. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  102293. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  102294. + int err;
  102295. +
  102296. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  102297. + if (err)
  102298. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  102299. +
  102300. +}
  102301. +
  102302. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  102303. +{
  102304. + struct snd_pcm_runtime *runtime = substream->runtime;
  102305. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  102306. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  102307. +
  102308. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  102309. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  102310. + snd_bcm2835_pcm_transfer);
  102311. + return 0;
  102312. +}
  102313. +
  102314. +/* trigger callback */
  102315. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  102316. +{
  102317. + struct snd_pcm_runtime *runtime = substream->runtime;
  102318. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  102319. + int err = 0;
  102320. +
  102321. + audio_info(" .. IN\n");
  102322. +
  102323. + switch (cmd) {
  102324. + case SNDRV_PCM_TRIGGER_START:
  102325. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  102326. + alsa_stream->running);
  102327. + if (!alsa_stream->running) {
  102328. + err = bcm2835_audio_start(alsa_stream);
  102329. + if (err == 0) {
  102330. + alsa_stream->pcm_indirect.hw_io =
  102331. + alsa_stream->pcm_indirect.hw_data =
  102332. + bytes_to_frames(runtime,
  102333. + alsa_stream->pos);
  102334. + substream->ops->ack(substream);
  102335. + alsa_stream->running = 1;
  102336. + alsa_stream->draining = 1;
  102337. + } else {
  102338. + audio_error(" Failed to START alsa device (%d)\n", err);
  102339. + }
  102340. + }
  102341. + break;
  102342. + case SNDRV_PCM_TRIGGER_STOP:
  102343. + audio_debug
  102344. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  102345. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  102346. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  102347. + audio_info("DRAINING\n");
  102348. + alsa_stream->draining = 1;
  102349. + } else {
  102350. + audio_info("DROPPING\n");
  102351. + alsa_stream->draining = 0;
  102352. + }
  102353. + if (alsa_stream->running) {
  102354. + err = bcm2835_audio_stop(alsa_stream);
  102355. + if (err != 0)
  102356. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  102357. + alsa_stream->running = 0;
  102358. + }
  102359. + break;
  102360. + default:
  102361. + err = -EINVAL;
  102362. + }
  102363. +
  102364. + audio_info(" .. OUT\n");
  102365. + return err;
  102366. +}
  102367. +
  102368. +/* pointer callback */
  102369. +static snd_pcm_uframes_t
  102370. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  102371. +{
  102372. + struct snd_pcm_runtime *runtime = substream->runtime;
  102373. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  102374. +
  102375. + audio_info(" .. IN\n");
  102376. +
  102377. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  102378. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  102379. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  102380. + alsa_stream->pos);
  102381. +
  102382. + audio_info(" .. OUT\n");
  102383. + return snd_pcm_indirect_playback_pointer(substream,
  102384. + &alsa_stream->pcm_indirect,
  102385. + alsa_stream->pos);
  102386. +}
  102387. +
  102388. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  102389. + unsigned int cmd, void *arg)
  102390. +{
  102391. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  102392. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  102393. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  102394. + return ret;
  102395. +}
  102396. +
  102397. +/* operators */
  102398. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  102399. + .open = snd_bcm2835_playback_open,
  102400. + .close = snd_bcm2835_playback_close,
  102401. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  102402. + .hw_params = snd_bcm2835_pcm_hw_params,
  102403. + .hw_free = snd_bcm2835_pcm_hw_free,
  102404. + .prepare = snd_bcm2835_pcm_prepare,
  102405. + .trigger = snd_bcm2835_pcm_trigger,
  102406. + .pointer = snd_bcm2835_pcm_pointer,
  102407. + .ack = snd_bcm2835_pcm_ack,
  102408. +};
  102409. +
  102410. +static struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = {
  102411. + .open = snd_bcm2835_playback_spdif_open,
  102412. + .close = snd_bcm2835_playback_close,
  102413. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  102414. + .hw_params = snd_bcm2835_pcm_hw_params,
  102415. + .hw_free = snd_bcm2835_pcm_hw_free,
  102416. + .prepare = snd_bcm2835_pcm_prepare,
  102417. + .trigger = snd_bcm2835_pcm_trigger,
  102418. + .pointer = snd_bcm2835_pcm_pointer,
  102419. + .ack = snd_bcm2835_pcm_ack,
  102420. +};
  102421. +
  102422. +/* create a pcm device */
  102423. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  102424. +{
  102425. + struct snd_pcm *pcm;
  102426. + int err;
  102427. +
  102428. + audio_info(" .. IN\n");
  102429. + err =
  102430. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  102431. + if (err < 0)
  102432. + return err;
  102433. + pcm->private_data = chip;
  102434. + strcpy(pcm->name, "bcm2835 ALSA");
  102435. + chip->pcm = pcm;
  102436. + chip->dest = AUDIO_DEST_AUTO;
  102437. + chip->volume = alsa2chip(0);
  102438. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  102439. + /* set operators */
  102440. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  102441. + &snd_bcm2835_playback_ops);
  102442. +
  102443. + /* pre-allocation of buffers */
  102444. + /* NOTE: this may fail */
  102445. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  102446. + snd_dma_continuous_data
  102447. + (GFP_KERNEL), 64 * 1024,
  102448. + 64 * 1024);
  102449. +
  102450. + audio_info(" .. OUT\n");
  102451. +
  102452. + return 0;
  102453. +}
  102454. +
  102455. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip)
  102456. +{
  102457. + struct snd_pcm *pcm;
  102458. + int err;
  102459. +
  102460. + err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
  102461. + if (err < 0)
  102462. + return err;
  102463. +
  102464. + pcm->private_data = chip;
  102465. + strcpy(pcm->name, "bcm2835 IEC958/HDMI");
  102466. + chip->pcm_spdif = pcm;
  102467. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  102468. + &snd_bcm2835_playback_spdif_ops);
  102469. +
  102470. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  102471. + snd_dma_continuous_data (GFP_KERNEL),
  102472. + 64 * 1024, 64 * 1024);
  102473. +
  102474. + return 0;
  102475. +}
  102476. diff -Nur linux-3.12.18/sound/arm/bcm2835-vchiq.c linux-rpi/sound/arm/bcm2835-vchiq.c
  102477. --- linux-3.12.18/sound/arm/bcm2835-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  102478. +++ linux-rpi/sound/arm/bcm2835-vchiq.c 2014-04-24 16:04:42.735152438 +0200
  102479. @@ -0,0 +1,879 @@
  102480. +/*****************************************************************************
  102481. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  102482. +*
  102483. +* Unless you and Broadcom execute a separate written software license
  102484. +* agreement governing use of this software, this software is licensed to you
  102485. +* under the terms of the GNU General Public License version 2, available at
  102486. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  102487. +*
  102488. +* Notwithstanding the above, under no circumstances may you combine this
  102489. +* software in any way with any other Broadcom software provided under a
  102490. +* license other than the GPL, without Broadcom's express prior written
  102491. +* consent.
  102492. +*****************************************************************************/
  102493. +
  102494. +#include <linux/device.h>
  102495. +#include <sound/core.h>
  102496. +#include <sound/initval.h>
  102497. +#include <sound/pcm.h>
  102498. +#include <linux/io.h>
  102499. +#include <linux/interrupt.h>
  102500. +#include <linux/fs.h>
  102501. +#include <linux/file.h>
  102502. +#include <linux/mm.h>
  102503. +#include <linux/syscalls.h>
  102504. +#include <asm/uaccess.h>
  102505. +#include <linux/slab.h>
  102506. +#include <linux/delay.h>
  102507. +#include <linux/atomic.h>
  102508. +#include <linux/module.h>
  102509. +#include <linux/completion.h>
  102510. +
  102511. +#include "bcm2835.h"
  102512. +
  102513. +/* ---- Include Files -------------------------------------------------------- */
  102514. +
  102515. +#include "interface/vchi/vchi.h"
  102516. +#include "vc_vchi_audioserv_defs.h"
  102517. +
  102518. +/* ---- Private Constants and Types ------------------------------------------ */
  102519. +
  102520. +#define BCM2835_AUDIO_STOP 0
  102521. +#define BCM2835_AUDIO_START 1
  102522. +#define BCM2835_AUDIO_WRITE 2
  102523. +
  102524. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  102525. +#ifdef AUDIO_DEBUG_ENABLE
  102526. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102527. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102528. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102529. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102530. +#else
  102531. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102532. + #define LOG_WARN( fmt, arg... )
  102533. + #define LOG_INFO( fmt, arg... )
  102534. + #define LOG_DBG( fmt, arg... )
  102535. +#endif
  102536. +
  102537. +typedef struct opaque_AUDIO_INSTANCE_T {
  102538. + uint32_t num_connections;
  102539. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  102540. + struct completion msg_avail_comp;
  102541. + struct mutex vchi_mutex;
  102542. + bcm2835_alsa_stream_t *alsa_stream;
  102543. + int32_t result;
  102544. + short peer_version;
  102545. +} AUDIO_INSTANCE_T;
  102546. +
  102547. +bool force_bulk = false;
  102548. +
  102549. +/* ---- Private Variables ---------------------------------------------------- */
  102550. +
  102551. +/* ---- Private Function Prototypes ------------------------------------------ */
  102552. +
  102553. +/* ---- Private Functions ---------------------------------------------------- */
  102554. +
  102555. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  102556. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  102557. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  102558. + uint32_t count, void *src);
  102559. +
  102560. +typedef struct {
  102561. + struct work_struct my_work;
  102562. + bcm2835_alsa_stream_t *alsa_stream;
  102563. + int cmd;
  102564. + void *src;
  102565. + uint32_t count;
  102566. +} my_work_t;
  102567. +
  102568. +static void my_wq_function(struct work_struct *work)
  102569. +{
  102570. + my_work_t *w = (my_work_t *) work;
  102571. + int ret = -9;
  102572. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  102573. + switch (w->cmd) {
  102574. + case BCM2835_AUDIO_START:
  102575. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  102576. + break;
  102577. + case BCM2835_AUDIO_STOP:
  102578. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  102579. + break;
  102580. + case BCM2835_AUDIO_WRITE:
  102581. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  102582. + w->src);
  102583. + break;
  102584. + default:
  102585. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  102586. + break;
  102587. + }
  102588. + kfree((void *)work);
  102589. + LOG_DBG(" .. OUT %d\n", ret);
  102590. +}
  102591. +
  102592. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  102593. +{
  102594. + int ret = -1;
  102595. + LOG_DBG(" .. IN\n");
  102596. + if (alsa_stream->my_wq) {
  102597. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  102598. + /*--- Queue some work (item 1) ---*/
  102599. + if (work) {
  102600. + INIT_WORK((struct work_struct *)work, my_wq_function);
  102601. + work->alsa_stream = alsa_stream;
  102602. + work->cmd = BCM2835_AUDIO_START;
  102603. + if (queue_work
  102604. + (alsa_stream->my_wq, (struct work_struct *)work))
  102605. + ret = 0;
  102606. + } else
  102607. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  102608. + }
  102609. + LOG_DBG(" .. OUT %d\n", ret);
  102610. + return ret;
  102611. +}
  102612. +
  102613. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  102614. +{
  102615. + int ret = -1;
  102616. + LOG_DBG(" .. IN\n");
  102617. + if (alsa_stream->my_wq) {
  102618. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  102619. + /*--- Queue some work (item 1) ---*/
  102620. + if (work) {
  102621. + INIT_WORK((struct work_struct *)work, my_wq_function);
  102622. + work->alsa_stream = alsa_stream;
  102623. + work->cmd = BCM2835_AUDIO_STOP;
  102624. + if (queue_work
  102625. + (alsa_stream->my_wq, (struct work_struct *)work))
  102626. + ret = 0;
  102627. + } else
  102628. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  102629. + }
  102630. + LOG_DBG(" .. OUT %d\n", ret);
  102631. + return ret;
  102632. +}
  102633. +
  102634. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  102635. + uint32_t count, void *src)
  102636. +{
  102637. + int ret = -1;
  102638. + LOG_DBG(" .. IN\n");
  102639. + if (alsa_stream->my_wq) {
  102640. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  102641. + /*--- Queue some work (item 1) ---*/
  102642. + if (work) {
  102643. + INIT_WORK((struct work_struct *)work, my_wq_function);
  102644. + work->alsa_stream = alsa_stream;
  102645. + work->cmd = BCM2835_AUDIO_WRITE;
  102646. + work->src = src;
  102647. + work->count = count;
  102648. + if (queue_work
  102649. + (alsa_stream->my_wq, (struct work_struct *)work))
  102650. + ret = 0;
  102651. + } else
  102652. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  102653. + }
  102654. + LOG_DBG(" .. OUT %d\n", ret);
  102655. + return ret;
  102656. +}
  102657. +
  102658. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  102659. +{
  102660. + alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1);
  102661. + return;
  102662. +}
  102663. +
  102664. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  102665. +{
  102666. + if (alsa_stream->my_wq) {
  102667. + flush_workqueue(alsa_stream->my_wq);
  102668. + destroy_workqueue(alsa_stream->my_wq);
  102669. + alsa_stream->my_wq = NULL;
  102670. + }
  102671. + return;
  102672. +}
  102673. +
  102674. +static void audio_vchi_callback(void *param,
  102675. + const VCHI_CALLBACK_REASON_T reason,
  102676. + void *msg_handle)
  102677. +{
  102678. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  102679. + int32_t status;
  102680. + int32_t msg_len;
  102681. + VC_AUDIO_MSG_T m;
  102682. + bcm2835_alsa_stream_t *alsa_stream = 0;
  102683. + LOG_DBG(" .. IN instance=%p, param=%p, reason=%d, handle=%p\n",
  102684. + instance, param, reason, msg_handle);
  102685. +
  102686. + if (!instance || reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  102687. + return;
  102688. + }
  102689. + alsa_stream = instance->alsa_stream;
  102690. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  102691. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  102692. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  102693. + LOG_DBG
  102694. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  102695. + instance, m.u.result.success);
  102696. + instance->result = m.u.result.success;
  102697. + complete(&instance->msg_avail_comp);
  102698. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  102699. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  102700. + LOG_DBG
  102701. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  102702. + instance, m.u.complete.count);
  102703. + if (alsa_stream && callback) {
  102704. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  102705. + callback(0, alsa_stream);
  102706. + } else {
  102707. + LOG_DBG(" .. unexpected alsa_stream=%p, callback=%p\n",
  102708. + alsa_stream, callback);
  102709. + }
  102710. + } else {
  102711. + LOG_DBG(" .. unexpected m.type=%d\n", m.type);
  102712. + }
  102713. + LOG_DBG(" .. OUT\n");
  102714. +}
  102715. +
  102716. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  102717. + VCHI_CONNECTION_T **
  102718. + vchi_connections,
  102719. + uint32_t num_connections)
  102720. +{
  102721. + uint32_t i;
  102722. + AUDIO_INSTANCE_T *instance;
  102723. + int status;
  102724. +
  102725. + LOG_DBG("%s: start", __func__);
  102726. +
  102727. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  102728. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  102729. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  102730. +
  102731. + return NULL;
  102732. + }
  102733. + /* Allocate memory for this instance */
  102734. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  102735. +
  102736. + memset(instance, 0, sizeof(*instance));
  102737. + instance->num_connections = num_connections;
  102738. +
  102739. + /* Create a lock for exclusive, serialized VCHI connection access */
  102740. + mutex_init(&instance->vchi_mutex);
  102741. + /* Open the VCHI service connections */
  102742. + for (i = 0; i < num_connections; i++) {
  102743. + SERVICE_CREATION_T params = {
  102744. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  102745. + VC_AUDIO_SERVER_NAME, // 4cc service code
  102746. + vchi_connections[i], // passed in fn pointers
  102747. + 0, // rx fifo size (unused)
  102748. + 0, // tx fifo size (unused)
  102749. + audio_vchi_callback, // service callback
  102750. + instance, // service callback parameter
  102751. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  102752. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  102753. + 0 // want crc check on bulk transfers
  102754. + };
  102755. +
  102756. + status = vchi_service_open(vchi_instance, &params,
  102757. + &instance->vchi_handle[i]);
  102758. + if (status) {
  102759. + LOG_ERR
  102760. + ("%s: failed to open VCHI service connection (status=%d)\n",
  102761. + __func__, status);
  102762. +
  102763. + goto err_close_services;
  102764. + }
  102765. + /* Finished with the service for now */
  102766. + vchi_service_release(instance->vchi_handle[i]);
  102767. + }
  102768. +
  102769. + return instance;
  102770. +
  102771. +err_close_services:
  102772. + for (i = 0; i < instance->num_connections; i++) {
  102773. + vchi_service_close(instance->vchi_handle[i]);
  102774. + }
  102775. +
  102776. + kfree(instance);
  102777. +
  102778. + return NULL;
  102779. +}
  102780. +
  102781. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  102782. +{
  102783. + uint32_t i;
  102784. +
  102785. + LOG_DBG(" .. IN\n");
  102786. +
  102787. + if (instance == NULL) {
  102788. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  102789. +
  102790. + return -1;
  102791. + }
  102792. +
  102793. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  102794. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102795. + {
  102796. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102797. + return -EINTR;
  102798. + }
  102799. +
  102800. + /* Close all VCHI service connections */
  102801. + for (i = 0; i < instance->num_connections; i++) {
  102802. + int32_t success;
  102803. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  102804. + vchi_service_use(instance->vchi_handle[i]);
  102805. +
  102806. + success = vchi_service_close(instance->vchi_handle[i]);
  102807. + if (success != 0) {
  102808. + LOG_ERR
  102809. + ("%s: failed to close VCHI service connection (status=%d)\n",
  102810. + __func__, success);
  102811. + }
  102812. + }
  102813. +
  102814. + mutex_unlock(&instance->vchi_mutex);
  102815. +
  102816. + kfree(instance);
  102817. +
  102818. + LOG_DBG(" .. OUT\n");
  102819. +
  102820. + return 0;
  102821. +}
  102822. +
  102823. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  102824. +{
  102825. + static VCHI_INSTANCE_T vchi_instance;
  102826. + static VCHI_CONNECTION_T *vchi_connection;
  102827. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102828. + int ret;
  102829. + LOG_DBG(" .. IN\n");
  102830. +
  102831. + LOG_INFO("%s: start", __func__);
  102832. + //BUG_ON(instance);
  102833. + if (instance) {
  102834. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  102835. + __func__, instance);
  102836. + instance->alsa_stream = alsa_stream;
  102837. + alsa_stream->instance = instance;
  102838. + ret = 0; // xxx todo -1;
  102839. + goto err_free_mem;
  102840. + }
  102841. +
  102842. + /* Initialize and create a VCHI connection */
  102843. + ret = vchi_initialise(&vchi_instance);
  102844. + if (ret != 0) {
  102845. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  102846. + __func__, ret);
  102847. +
  102848. + ret = -EIO;
  102849. + goto err_free_mem;
  102850. + }
  102851. + ret = vchi_connect(NULL, 0, vchi_instance);
  102852. + if (ret != 0) {
  102853. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  102854. + __func__, ret);
  102855. +
  102856. + ret = -EIO;
  102857. + goto err_free_mem;
  102858. + }
  102859. +
  102860. + /* Initialize an instance of the audio service */
  102861. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  102862. +
  102863. + if (instance == NULL /*|| audio_handle != instance */ ) {
  102864. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  102865. +
  102866. + ret = -EPERM;
  102867. + goto err_free_mem;
  102868. + }
  102869. +
  102870. + instance->alsa_stream = alsa_stream;
  102871. + alsa_stream->instance = instance;
  102872. +
  102873. + LOG_DBG(" success !\n");
  102874. +err_free_mem:
  102875. + LOG_DBG(" .. OUT\n");
  102876. +
  102877. + return ret;
  102878. +}
  102879. +
  102880. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  102881. +{
  102882. + AUDIO_INSTANCE_T *instance;
  102883. + VC_AUDIO_MSG_T m;
  102884. + int32_t success;
  102885. + int ret;
  102886. + LOG_DBG(" .. IN\n");
  102887. +
  102888. + my_workqueue_init(alsa_stream);
  102889. +
  102890. + ret = bcm2835_audio_open_connection(alsa_stream);
  102891. + if (ret != 0) {
  102892. + ret = -1;
  102893. + goto exit;
  102894. + }
  102895. + instance = alsa_stream->instance;
  102896. +
  102897. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102898. + {
  102899. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102900. + return -EINTR;
  102901. + }
  102902. + vchi_service_use(instance->vchi_handle[0]);
  102903. +
  102904. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  102905. +
  102906. + /* Send the message to the videocore */
  102907. + success = vchi_msg_queue(instance->vchi_handle[0],
  102908. + &m, sizeof m,
  102909. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102910. +
  102911. + if (success != 0) {
  102912. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  102913. + __func__, success);
  102914. +
  102915. + ret = -1;
  102916. + goto unlock;
  102917. + }
  102918. +
  102919. + ret = 0;
  102920. +
  102921. +unlock:
  102922. + vchi_service_release(instance->vchi_handle[0]);
  102923. + mutex_unlock(&instance->vchi_mutex);
  102924. +exit:
  102925. + LOG_DBG(" .. OUT\n");
  102926. + return ret;
  102927. +}
  102928. +
  102929. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  102930. + bcm2835_chip_t * chip)
  102931. +{
  102932. + VC_AUDIO_MSG_T m;
  102933. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102934. + int32_t success;
  102935. + int ret;
  102936. + LOG_DBG(" .. IN\n");
  102937. +
  102938. + LOG_INFO
  102939. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  102940. +
  102941. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102942. + {
  102943. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102944. + return -EINTR;
  102945. + }
  102946. + vchi_service_use(instance->vchi_handle[0]);
  102947. +
  102948. + instance->result = -1;
  102949. +
  102950. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  102951. + m.u.control.dest = chip->dest;
  102952. + m.u.control.volume = chip->volume;
  102953. +
  102954. + /* Create the message available completion */
  102955. + init_completion(&instance->msg_avail_comp);
  102956. +
  102957. + /* Send the message to the videocore */
  102958. + success = vchi_msg_queue(instance->vchi_handle[0],
  102959. + &m, sizeof m,
  102960. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102961. +
  102962. + if (success != 0) {
  102963. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  102964. + __func__, success);
  102965. +
  102966. + ret = -1;
  102967. + goto unlock;
  102968. + }
  102969. +
  102970. + /* We are expecting a reply from the videocore */
  102971. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  102972. + if (ret) {
  102973. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  102974. + __func__, success);
  102975. + goto unlock;
  102976. + }
  102977. +
  102978. + if (instance->result != 0) {
  102979. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  102980. +
  102981. + ret = -1;
  102982. + goto unlock;
  102983. + }
  102984. +
  102985. + ret = 0;
  102986. +
  102987. +unlock:
  102988. + vchi_service_release(instance->vchi_handle[0]);
  102989. + mutex_unlock(&instance->vchi_mutex);
  102990. +
  102991. + LOG_DBG(" .. OUT\n");
  102992. + return ret;
  102993. +}
  102994. +
  102995. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  102996. +{
  102997. + int i;
  102998. + int ret = 0;
  102999. + LOG_DBG(" .. IN\n");
  103000. +
  103001. + /* change ctls for all substreams */
  103002. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  103003. + if (chip->avail_substreams & (1 << i)) {
  103004. + if (!chip->alsa_stream[i])
  103005. + {
  103006. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  103007. + ret = 0;
  103008. + }
  103009. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  103010. + (chip->alsa_stream[i], chip) != 0)
  103011. + {
  103012. + LOG_DBG("Couldn't set the controls for stream %d\n", i);
  103013. + ret = -1;
  103014. + }
  103015. + else LOG_DBG(" Controls set for stream %d\n", i);
  103016. + }
  103017. + }
  103018. + LOG_DBG(" .. OUT ret=%d\n", ret);
  103019. + return ret;
  103020. +}
  103021. +
  103022. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  103023. + uint32_t channels, uint32_t samplerate,
  103024. + uint32_t bps)
  103025. +{
  103026. + VC_AUDIO_MSG_T m;
  103027. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  103028. + int32_t success;
  103029. + int ret;
  103030. + LOG_DBG(" .. IN\n");
  103031. +
  103032. + LOG_INFO
  103033. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  103034. + channels, samplerate, bps);
  103035. +
  103036. + /* resend ctls - alsa_stream may not have been open when first send */
  103037. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  103038. + if (ret != 0) {
  103039. + LOG_ERR(" Alsa controls not supported\n");
  103040. + return -EINVAL;
  103041. + }
  103042. +
  103043. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  103044. + {
  103045. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  103046. + return -EINTR;
  103047. + }
  103048. + vchi_service_use(instance->vchi_handle[0]);
  103049. +
  103050. + instance->result = -1;
  103051. +
  103052. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  103053. + m.u.config.channels = channels;
  103054. + m.u.config.samplerate = samplerate;
  103055. + m.u.config.bps = bps;
  103056. +
  103057. + /* Create the message available completion */
  103058. + init_completion(&instance->msg_avail_comp);
  103059. +
  103060. + /* Send the message to the videocore */
  103061. + success = vchi_msg_queue(instance->vchi_handle[0],
  103062. + &m, sizeof m,
  103063. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  103064. +
  103065. + if (success != 0) {
  103066. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  103067. + __func__, success);
  103068. +
  103069. + ret = -1;
  103070. + goto unlock;
  103071. + }
  103072. +
  103073. + /* We are expecting a reply from the videocore */
  103074. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  103075. + if (ret) {
  103076. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  103077. + __func__, success);
  103078. + goto unlock;
  103079. + }
  103080. +
  103081. + if (instance->result != 0) {
  103082. + LOG_ERR("%s: result=%d", __func__, instance->result);
  103083. +
  103084. + ret = -1;
  103085. + goto unlock;
  103086. + }
  103087. +
  103088. + ret = 0;
  103089. +
  103090. +unlock:
  103091. + vchi_service_release(instance->vchi_handle[0]);
  103092. + mutex_unlock(&instance->vchi_mutex);
  103093. +
  103094. + LOG_DBG(" .. OUT\n");
  103095. + return ret;
  103096. +}
  103097. +
  103098. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  103099. +{
  103100. + LOG_DBG(" .. IN\n");
  103101. +
  103102. + LOG_DBG(" .. OUT\n");
  103103. +
  103104. + return 0;
  103105. +}
  103106. +
  103107. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  103108. +{
  103109. + VC_AUDIO_MSG_T m;
  103110. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  103111. + int32_t success;
  103112. + int ret;
  103113. + LOG_DBG(" .. IN\n");
  103114. +
  103115. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  103116. + {
  103117. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  103118. + return -EINTR;
  103119. + }
  103120. + vchi_service_use(instance->vchi_handle[0]);
  103121. +
  103122. + m.type = VC_AUDIO_MSG_TYPE_START;
  103123. +
  103124. + /* Send the message to the videocore */
  103125. + success = vchi_msg_queue(instance->vchi_handle[0],
  103126. + &m, sizeof m,
  103127. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  103128. +
  103129. + if (success != 0) {
  103130. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  103131. + __func__, success);
  103132. +
  103133. + ret = -1;
  103134. + goto unlock;
  103135. + }
  103136. +
  103137. + ret = 0;
  103138. +
  103139. +unlock:
  103140. + vchi_service_release(instance->vchi_handle[0]);
  103141. + mutex_unlock(&instance->vchi_mutex);
  103142. + LOG_DBG(" .. OUT\n");
  103143. + return ret;
  103144. +}
  103145. +
  103146. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  103147. +{
  103148. + VC_AUDIO_MSG_T m;
  103149. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  103150. + int32_t success;
  103151. + int ret;
  103152. + LOG_DBG(" .. IN\n");
  103153. +
  103154. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  103155. + {
  103156. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  103157. + return -EINTR;
  103158. + }
  103159. + vchi_service_use(instance->vchi_handle[0]);
  103160. +
  103161. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  103162. + m.u.stop.draining = alsa_stream->draining;
  103163. +
  103164. + /* Send the message to the videocore */
  103165. + success = vchi_msg_queue(instance->vchi_handle[0],
  103166. + &m, sizeof m,
  103167. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  103168. +
  103169. + if (success != 0) {
  103170. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  103171. + __func__, success);
  103172. +
  103173. + ret = -1;
  103174. + goto unlock;
  103175. + }
  103176. +
  103177. + ret = 0;
  103178. +
  103179. +unlock:
  103180. + vchi_service_release(instance->vchi_handle[0]);
  103181. + mutex_unlock(&instance->vchi_mutex);
  103182. + LOG_DBG(" .. OUT\n");
  103183. + return ret;
  103184. +}
  103185. +
  103186. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  103187. +{
  103188. + VC_AUDIO_MSG_T m;
  103189. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  103190. + int32_t success;
  103191. + int ret;
  103192. + LOG_DBG(" .. IN\n");
  103193. +
  103194. + my_workqueue_quit(alsa_stream);
  103195. +
  103196. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  103197. + {
  103198. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  103199. + return -EINTR;
  103200. + }
  103201. + vchi_service_use(instance->vchi_handle[0]);
  103202. +
  103203. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  103204. +
  103205. + /* Create the message available completion */
  103206. + init_completion(&instance->msg_avail_comp);
  103207. +
  103208. + /* Send the message to the videocore */
  103209. + success = vchi_msg_queue(instance->vchi_handle[0],
  103210. + &m, sizeof m,
  103211. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  103212. +
  103213. + if (success != 0) {
  103214. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  103215. + __func__, success);
  103216. + ret = -1;
  103217. + goto unlock;
  103218. + }
  103219. +
  103220. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  103221. + if (ret) {
  103222. + LOG_ERR("%s: failed on waiting for event (status=%d)",
  103223. + __func__, success);
  103224. + goto unlock;
  103225. + }
  103226. + if (instance->result != 0) {
  103227. + LOG_ERR("%s: failed result (status=%d)",
  103228. + __func__, instance->result);
  103229. +
  103230. + ret = -1;
  103231. + goto unlock;
  103232. + }
  103233. +
  103234. + ret = 0;
  103235. +
  103236. +unlock:
  103237. + vchi_service_release(instance->vchi_handle[0]);
  103238. + mutex_unlock(&instance->vchi_mutex);
  103239. +
  103240. + /* Stop the audio service */
  103241. + if (instance) {
  103242. + vc_vchi_audio_deinit(instance);
  103243. + alsa_stream->instance = NULL;
  103244. + }
  103245. + LOG_DBG(" .. OUT\n");
  103246. + return ret;
  103247. +}
  103248. +
  103249. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  103250. + uint32_t count, void *src)
  103251. +{
  103252. + VC_AUDIO_MSG_T m;
  103253. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  103254. + int32_t success;
  103255. + int ret;
  103256. +
  103257. + LOG_DBG(" .. IN\n");
  103258. +
  103259. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  103260. +
  103261. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  103262. + {
  103263. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  103264. + return -EINTR;
  103265. + }
  103266. + vchi_service_use(instance->vchi_handle[0]);
  103267. +
  103268. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  103269. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  103270. + }
  103271. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  103272. + m.u.write.count = count;
  103273. + // old version uses bulk, new version uses control
  103274. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  103275. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  103276. + m.u.write.cookie = alsa_stream;
  103277. + m.u.write.silence = src == NULL;
  103278. +
  103279. + /* Send the message to the videocore */
  103280. + success = vchi_msg_queue(instance->vchi_handle[0],
  103281. + &m, sizeof m,
  103282. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  103283. +
  103284. + if (success != 0) {
  103285. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  103286. + __func__, success);
  103287. +
  103288. + ret = -1;
  103289. + goto unlock;
  103290. + }
  103291. + if (!m.u.write.silence) {
  103292. + if (m.u.write.max_packet == 0) {
  103293. + /* Send the message to the videocore */
  103294. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  103295. + src, count,
  103296. + 0 *
  103297. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  103298. + +
  103299. + 1 *
  103300. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  103301. + NULL);
  103302. + } else {
  103303. + while (count > 0) {
  103304. + int bytes = min((int)m.u.write.max_packet, (int)count);
  103305. + success = vchi_msg_queue(instance->vchi_handle[0],
  103306. + src, bytes,
  103307. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  103308. + src = (char *)src + bytes;
  103309. + count -= bytes;
  103310. + }
  103311. + }
  103312. + if (success != 0) {
  103313. + LOG_ERR
  103314. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)",
  103315. + __func__, success);
  103316. +
  103317. + ret = -1;
  103318. + goto unlock;
  103319. + }
  103320. + }
  103321. + ret = 0;
  103322. +
  103323. +unlock:
  103324. + vchi_service_release(instance->vchi_handle[0]);
  103325. + mutex_unlock(&instance->vchi_mutex);
  103326. + LOG_DBG(" .. OUT\n");
  103327. + return ret;
  103328. +}
  103329. +
  103330. +/**
  103331. + * Returns all buffers from arm->vc
  103332. + */
  103333. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  103334. +{
  103335. + LOG_DBG(" .. IN\n");
  103336. + LOG_DBG(" .. OUT\n");
  103337. + return;
  103338. +}
  103339. +
  103340. +/**
  103341. + * Forces VC to flush(drop) its filled playback buffers and
  103342. + * return them the us. (VC->ARM)
  103343. + */
  103344. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  103345. +{
  103346. + LOG_DBG(" .. IN\n");
  103347. + LOG_DBG(" .. OUT\n");
  103348. +}
  103349. +
  103350. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  103351. +{
  103352. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  103353. + atomic_sub(count, &alsa_stream->retrieved);
  103354. + return count;
  103355. +}
  103356. +
  103357. +module_param(force_bulk, bool, 0444);
  103358. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  103359. diff -Nur linux-3.12.18/sound/arm/Kconfig linux-rpi/sound/arm/Kconfig
  103360. --- linux-3.12.18/sound/arm/Kconfig 2014-04-18 11:14:28.000000000 +0200
  103361. +++ linux-rpi/sound/arm/Kconfig 2014-04-24 15:35:05.357578964 +0200
  103362. @@ -39,5 +39,12 @@
  103363. Say Y or M if you want to support any AC97 codec attached to
  103364. the PXA2xx AC97 interface.
  103365. +config SND_BCM2835
  103366. + tristate "BCM2835 ALSA driver"
  103367. + depends on ARCH_BCM2708 && BCM2708_VCHIQ && SND
  103368. + select SND_PCM
  103369. + help
  103370. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  103371. +
  103372. endif # SND_ARM
  103373. diff -Nur linux-3.12.18/sound/arm/Makefile linux-rpi/sound/arm/Makefile
  103374. --- linux-3.12.18/sound/arm/Makefile 2014-04-18 11:14:28.000000000 +0200
  103375. +++ linux-rpi/sound/arm/Makefile 2014-04-24 16:04:42.735152438 +0200
  103376. @@ -14,3 +14,8 @@
  103377. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  103378. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  103379. +
  103380. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  103381. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  103382. +
  103383. +ccflags-y += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  103384. diff -Nur linux-3.12.18/sound/arm/vc_vchi_audioserv_defs.h linux-rpi/sound/arm/vc_vchi_audioserv_defs.h
  103385. --- linux-3.12.18/sound/arm/vc_vchi_audioserv_defs.h 1970-01-01 01:00:00.000000000 +0100
  103386. +++ linux-rpi/sound/arm/vc_vchi_audioserv_defs.h 2014-04-24 15:35:05.365579053 +0200
  103387. @@ -0,0 +1,116 @@
  103388. +/*****************************************************************************
  103389. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  103390. +*
  103391. +* Unless you and Broadcom execute a separate written software license
  103392. +* agreement governing use of this software, this software is licensed to you
  103393. +* under the terms of the GNU General Public License version 2, available at
  103394. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  103395. +*
  103396. +* Notwithstanding the above, under no circumstances may you combine this
  103397. +* software in any way with any other Broadcom software provided under a
  103398. +* license other than the GPL, without Broadcom's express prior written
  103399. +* consent.
  103400. +*****************************************************************************/
  103401. +
  103402. +#ifndef _VC_AUDIO_DEFS_H_
  103403. +#define _VC_AUDIO_DEFS_H_
  103404. +
  103405. +#define VC_AUDIOSERV_MIN_VER 1
  103406. +#define VC_AUDIOSERV_VER 2
  103407. +
  103408. +// FourCC code used for VCHI connection
  103409. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  103410. +
  103411. +// Maximum message length
  103412. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  103413. +
  103414. +// List of screens that are currently supported
  103415. +// All message types supported for HOST->VC direction
  103416. +typedef enum {
  103417. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  103418. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  103419. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  103420. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  103421. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  103422. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  103423. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  103424. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  103425. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  103426. + VC_AUDIO_MSG_TYPE_MAX
  103427. +} VC_AUDIO_MSG_TYPE;
  103428. +
  103429. +// configure the audio
  103430. +typedef struct {
  103431. + uint32_t channels;
  103432. + uint32_t samplerate;
  103433. + uint32_t bps;
  103434. +
  103435. +} VC_AUDIO_CONFIG_T;
  103436. +
  103437. +typedef struct {
  103438. + uint32_t volume;
  103439. + uint32_t dest;
  103440. +
  103441. +} VC_AUDIO_CONTROL_T;
  103442. +
  103443. +// audio
  103444. +typedef struct {
  103445. + uint32_t dummy;
  103446. +
  103447. +} VC_AUDIO_OPEN_T;
  103448. +
  103449. +// audio
  103450. +typedef struct {
  103451. + uint32_t dummy;
  103452. +
  103453. +} VC_AUDIO_CLOSE_T;
  103454. +// audio
  103455. +typedef struct {
  103456. + uint32_t dummy;
  103457. +
  103458. +} VC_AUDIO_START_T;
  103459. +// audio
  103460. +typedef struct {
  103461. + uint32_t draining;
  103462. +
  103463. +} VC_AUDIO_STOP_T;
  103464. +
  103465. +// configure the write audio samples
  103466. +typedef struct {
  103467. + uint32_t count; // in bytes
  103468. + void *callback;
  103469. + void *cookie;
  103470. + uint16_t silence;
  103471. + uint16_t max_packet;
  103472. +} VC_AUDIO_WRITE_T;
  103473. +
  103474. +// Generic result for a request (VC->HOST)
  103475. +typedef struct {
  103476. + int32_t success; // Success value
  103477. +
  103478. +} VC_AUDIO_RESULT_T;
  103479. +
  103480. +// Generic result for a request (VC->HOST)
  103481. +typedef struct {
  103482. + int32_t count; // Success value
  103483. + void *callback;
  103484. + void *cookie;
  103485. +} VC_AUDIO_COMPLETE_T;
  103486. +
  103487. +// Message header for all messages in HOST->VC direction
  103488. +typedef struct {
  103489. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  103490. + union {
  103491. + VC_AUDIO_CONFIG_T config;
  103492. + VC_AUDIO_CONTROL_T control;
  103493. + VC_AUDIO_OPEN_T open;
  103494. + VC_AUDIO_CLOSE_T close;
  103495. + VC_AUDIO_START_T start;
  103496. + VC_AUDIO_STOP_T stop;
  103497. + VC_AUDIO_WRITE_T write;
  103498. + VC_AUDIO_RESULT_T result;
  103499. + VC_AUDIO_COMPLETE_T complete;
  103500. + } u;
  103501. +} VC_AUDIO_MSG_T;
  103502. +
  103503. +#endif // _VC_AUDIO_DEFS_H_
  103504. diff -Nur linux-3.12.18/sound/soc/bcm/bcm2708-i2s.c linux-rpi/sound/soc/bcm/bcm2708-i2s.c
  103505. --- linux-3.12.18/sound/soc/bcm/bcm2708-i2s.c 1970-01-01 01:00:00.000000000 +0100
  103506. +++ linux-rpi/sound/soc/bcm/bcm2708-i2s.c 2014-04-24 16:04:43.363158508 +0200
  103507. @@ -0,0 +1,945 @@
  103508. +/*
  103509. + * ALSA SoC I2S Audio Layer for Broadcom BCM2708 SoC
  103510. + *
  103511. + * Author: Florian Meier <florian.meier@koalo.de>
  103512. + * Copyright 2013
  103513. + *
  103514. + * Based on
  103515. + * Raspberry Pi PCM I2S ALSA Driver
  103516. + * Copyright (c) by Phil Poole 2013
  103517. + *
  103518. + * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
  103519. + * Vladimir Barinov, <vbarinov@embeddedalley.com>
  103520. + * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  103521. + *
  103522. + * OMAP ALSA SoC DAI driver using McBSP port
  103523. + * Copyright (C) 2008 Nokia Corporation
  103524. + * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  103525. + * Peter Ujfalusi <peter.ujfalusi@ti.com>
  103526. + *
  103527. + * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  103528. + * Author: Timur Tabi <timur@freescale.com>
  103529. + * Copyright 2007-2010 Freescale Semiconductor, Inc.
  103530. + *
  103531. + * This program is free software; you can redistribute it and/or
  103532. + * modify it under the terms of the GNU General Public License
  103533. + * version 2 as published by the Free Software Foundation.
  103534. + *
  103535. + * This program is distributed in the hope that it will be useful, but
  103536. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  103537. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  103538. + * General Public License for more details.
  103539. + */
  103540. +
  103541. +#include <linux/init.h>
  103542. +#include <linux/module.h>
  103543. +#include <linux/device.h>
  103544. +#include <linux/slab.h>
  103545. +#include <linux/delay.h>
  103546. +#include <linux/io.h>
  103547. +#include <linux/clk.h>
  103548. +
  103549. +#include <sound/core.h>
  103550. +#include <sound/pcm.h>
  103551. +#include <sound/pcm_params.h>
  103552. +#include <sound/initval.h>
  103553. +#include <sound/soc.h>
  103554. +#include <sound/dmaengine_pcm.h>
  103555. +
  103556. +/* Clock registers */
  103557. +#define BCM2708_CLK_PCMCTL_REG 0x00
  103558. +#define BCM2708_CLK_PCMDIV_REG 0x04
  103559. +
  103560. +/* Clock register settings */
  103561. +#define BCM2708_CLK_PASSWD (0x5a000000)
  103562. +#define BCM2708_CLK_PASSWD_MASK (0xff000000)
  103563. +#define BCM2708_CLK_MASH(v) ((v) << 9)
  103564. +#define BCM2708_CLK_FLIP BIT(8)
  103565. +#define BCM2708_CLK_BUSY BIT(7)
  103566. +#define BCM2708_CLK_KILL BIT(5)
  103567. +#define BCM2708_CLK_ENAB BIT(4)
  103568. +#define BCM2708_CLK_SRC(v) (v)
  103569. +
  103570. +#define BCM2708_CLK_SHIFT (12)
  103571. +#define BCM2708_CLK_DIVI(v) ((v) << BCM2708_CLK_SHIFT)
  103572. +#define BCM2708_CLK_DIVF(v) (v)
  103573. +#define BCM2708_CLK_DIVF_MASK (0xFFF)
  103574. +
  103575. +enum {
  103576. + BCM2708_CLK_MASH_0 = 0,
  103577. + BCM2708_CLK_MASH_1,
  103578. + BCM2708_CLK_MASH_2,
  103579. + BCM2708_CLK_MASH_3,
  103580. +};
  103581. +
  103582. +enum {
  103583. + BCM2708_CLK_SRC_GND = 0,
  103584. + BCM2708_CLK_SRC_OSC,
  103585. + BCM2708_CLK_SRC_DBG0,
  103586. + BCM2708_CLK_SRC_DBG1,
  103587. + BCM2708_CLK_SRC_PLLA,
  103588. + BCM2708_CLK_SRC_PLLC,
  103589. + BCM2708_CLK_SRC_PLLD,
  103590. + BCM2708_CLK_SRC_HDMI,
  103591. +};
  103592. +
  103593. +/* Most clocks are not useable (freq = 0) */
  103594. +static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
  103595. + [BCM2708_CLK_SRC_GND] = 0,
  103596. + [BCM2708_CLK_SRC_OSC] = 19200000,
  103597. + [BCM2708_CLK_SRC_DBG0] = 0,
  103598. + [BCM2708_CLK_SRC_DBG1] = 0,
  103599. + [BCM2708_CLK_SRC_PLLA] = 0,
  103600. + [BCM2708_CLK_SRC_PLLC] = 0,
  103601. + [BCM2708_CLK_SRC_PLLD] = 500000000,
  103602. + [BCM2708_CLK_SRC_HDMI] = 0,
  103603. +};
  103604. +
  103605. +/* I2S registers */
  103606. +#define BCM2708_I2S_CS_A_REG 0x00
  103607. +#define BCM2708_I2S_FIFO_A_REG 0x04
  103608. +#define BCM2708_I2S_MODE_A_REG 0x08
  103609. +#define BCM2708_I2S_RXC_A_REG 0x0c
  103610. +#define BCM2708_I2S_TXC_A_REG 0x10
  103611. +#define BCM2708_I2S_DREQ_A_REG 0x14
  103612. +#define BCM2708_I2S_INTEN_A_REG 0x18
  103613. +#define BCM2708_I2S_INTSTC_A_REG 0x1c
  103614. +#define BCM2708_I2S_GRAY_REG 0x20
  103615. +
  103616. +/* I2S register settings */
  103617. +#define BCM2708_I2S_STBY BIT(25)
  103618. +#define BCM2708_I2S_SYNC BIT(24)
  103619. +#define BCM2708_I2S_RXSEX BIT(23)
  103620. +#define BCM2708_I2S_RXF BIT(22)
  103621. +#define BCM2708_I2S_TXE BIT(21)
  103622. +#define BCM2708_I2S_RXD BIT(20)
  103623. +#define BCM2708_I2S_TXD BIT(19)
  103624. +#define BCM2708_I2S_RXR BIT(18)
  103625. +#define BCM2708_I2S_TXW BIT(17)
  103626. +#define BCM2708_I2S_CS_RXERR BIT(16)
  103627. +#define BCM2708_I2S_CS_TXERR BIT(15)
  103628. +#define BCM2708_I2S_RXSYNC BIT(14)
  103629. +#define BCM2708_I2S_TXSYNC BIT(13)
  103630. +#define BCM2708_I2S_DMAEN BIT(9)
  103631. +#define BCM2708_I2S_RXTHR(v) ((v) << 7)
  103632. +#define BCM2708_I2S_TXTHR(v) ((v) << 5)
  103633. +#define BCM2708_I2S_RXCLR BIT(4)
  103634. +#define BCM2708_I2S_TXCLR BIT(3)
  103635. +#define BCM2708_I2S_TXON BIT(2)
  103636. +#define BCM2708_I2S_RXON BIT(1)
  103637. +#define BCM2708_I2S_EN (1)
  103638. +
  103639. +#define BCM2708_I2S_CLKDIS BIT(28)
  103640. +#define BCM2708_I2S_PDMN BIT(27)
  103641. +#define BCM2708_I2S_PDME BIT(26)
  103642. +#define BCM2708_I2S_FRXP BIT(25)
  103643. +#define BCM2708_I2S_FTXP BIT(24)
  103644. +#define BCM2708_I2S_CLKM BIT(23)
  103645. +#define BCM2708_I2S_CLKI BIT(22)
  103646. +#define BCM2708_I2S_FSM BIT(21)
  103647. +#define BCM2708_I2S_FSI BIT(20)
  103648. +#define BCM2708_I2S_FLEN(v) ((v) << 10)
  103649. +#define BCM2708_I2S_FSLEN(v) (v)
  103650. +
  103651. +#define BCM2708_I2S_CHWEX BIT(15)
  103652. +#define BCM2708_I2S_CHEN BIT(14)
  103653. +#define BCM2708_I2S_CHPOS(v) ((v) << 4)
  103654. +#define BCM2708_I2S_CHWID(v) (v)
  103655. +#define BCM2708_I2S_CH1(v) ((v) << 16)
  103656. +#define BCM2708_I2S_CH2(v) (v)
  103657. +
  103658. +#define BCM2708_I2S_TX_PANIC(v) ((v) << 24)
  103659. +#define BCM2708_I2S_RX_PANIC(v) ((v) << 16)
  103660. +#define BCM2708_I2S_TX(v) ((v) << 8)
  103661. +#define BCM2708_I2S_RX(v) (v)
  103662. +
  103663. +#define BCM2708_I2S_INT_RXERR BIT(3)
  103664. +#define BCM2708_I2S_INT_TXERR BIT(2)
  103665. +#define BCM2708_I2S_INT_RXR BIT(1)
  103666. +#define BCM2708_I2S_INT_TXW BIT(0)
  103667. +
  103668. +/* I2S DMA interface */
  103669. +#define BCM2708_I2S_FIFO_PHYSICAL_ADDR 0x7E203004
  103670. +#define BCM2708_DMA_DREQ_PCM_TX 2
  103671. +#define BCM2708_DMA_DREQ_PCM_RX 3
  103672. +
  103673. +/* General device struct */
  103674. +struct bcm2708_i2s_dev {
  103675. + struct device *dev;
  103676. + struct snd_dmaengine_dai_dma_data dma_data[2];
  103677. + unsigned int fmt;
  103678. + unsigned int bclk_ratio;
  103679. +
  103680. + struct regmap *i2s_regmap;
  103681. + struct regmap *clk_regmap;
  103682. +};
  103683. +
  103684. +static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
  103685. +{
  103686. + /* Start the clock if in master mode */
  103687. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  103688. +
  103689. + switch (master) {
  103690. + case SND_SOC_DAIFMT_CBS_CFS:
  103691. + case SND_SOC_DAIFMT_CBS_CFM:
  103692. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  103693. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  103694. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  103695. + break;
  103696. + default:
  103697. + break;
  103698. + }
  103699. +}
  103700. +
  103701. +static void bcm2708_i2s_stop_clock(struct bcm2708_i2s_dev *dev)
  103702. +{
  103703. + uint32_t clkreg;
  103704. + int timeout = 1000;
  103705. +
  103706. + /* Stop clock */
  103707. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  103708. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  103709. + BCM2708_CLK_PASSWD);
  103710. +
  103711. + /* Wait for the BUSY flag going down */
  103712. + while (--timeout) {
  103713. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  103714. + if (!(clkreg & BCM2708_CLK_BUSY))
  103715. + break;
  103716. + }
  103717. +
  103718. + if (!timeout) {
  103719. + /* KILL the clock */
  103720. + dev_err(dev->dev, "I2S clock didn't stop. Kill the clock!\n");
  103721. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  103722. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD_MASK,
  103723. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD);
  103724. + }
  103725. +}
  103726. +
  103727. +static void bcm2708_i2s_clear_fifos(struct bcm2708_i2s_dev *dev,
  103728. + bool tx, bool rx)
  103729. +{
  103730. + int timeout = 1000;
  103731. + uint32_t syncval;
  103732. + uint32_t csreg;
  103733. + uint32_t i2s_active_state;
  103734. + uint32_t clkreg;
  103735. + uint32_t clk_active_state;
  103736. + uint32_t off;
  103737. + uint32_t clr;
  103738. +
  103739. + off = tx ? BCM2708_I2S_TXON : 0;
  103740. + off |= rx ? BCM2708_I2S_RXON : 0;
  103741. +
  103742. + clr = tx ? BCM2708_I2S_TXCLR : 0;
  103743. + clr |= rx ? BCM2708_I2S_RXCLR : 0;
  103744. +
  103745. + /* Backup the current state */
  103746. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  103747. + i2s_active_state = csreg & (BCM2708_I2S_RXON | BCM2708_I2S_TXON);
  103748. +
  103749. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  103750. + clk_active_state = clkreg & BCM2708_CLK_ENAB;
  103751. +
  103752. + /* Start clock if not running */
  103753. + if (!clk_active_state) {
  103754. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  103755. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  103756. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  103757. + }
  103758. +
  103759. + /* Stop I2S module */
  103760. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, off, 0);
  103761. +
  103762. + /*
  103763. + * Clear the FIFOs
  103764. + * Requires at least 2 PCM clock cycles to take effect
  103765. + */
  103766. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, clr, clr);
  103767. +
  103768. + /* Wait for 2 PCM clock cycles */
  103769. +
  103770. + /*
  103771. + * Toggle the SYNC flag. After 2 PCM clock cycles it can be read back
  103772. + * FIXME: This does not seem to work for slave mode!
  103773. + */
  103774. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &syncval);
  103775. + syncval &= BCM2708_I2S_SYNC;
  103776. +
  103777. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  103778. + BCM2708_I2S_SYNC, ~syncval);
  103779. +
  103780. + /* Wait for the SYNC flag changing it's state */
  103781. + while (--timeout) {
  103782. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  103783. + if ((csreg & BCM2708_I2S_SYNC) != syncval)
  103784. + break;
  103785. + }
  103786. +
  103787. + if (!timeout)
  103788. + dev_err(dev->dev, "I2S SYNC error!\n");
  103789. +
  103790. + /* Stop clock if it was not running before */
  103791. + if (!clk_active_state)
  103792. + bcm2708_i2s_stop_clock(dev);
  103793. +
  103794. + /* Restore I2S state */
  103795. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  103796. + BCM2708_I2S_RXON | BCM2708_I2S_TXON, i2s_active_state);
  103797. +}
  103798. +
  103799. +static int bcm2708_i2s_set_dai_fmt(struct snd_soc_dai *dai,
  103800. + unsigned int fmt)
  103801. +{
  103802. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103803. + dev->fmt = fmt;
  103804. + return 0;
  103805. +}
  103806. +
  103807. +static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
  103808. + unsigned int ratio)
  103809. +{
  103810. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103811. + dev->bclk_ratio = ratio;
  103812. + return 0;
  103813. +}
  103814. +
  103815. +static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
  103816. + struct snd_pcm_hw_params *params,
  103817. + struct snd_soc_dai *dai)
  103818. +{
  103819. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103820. +
  103821. + unsigned int sampling_rate = params_rate(params);
  103822. + unsigned int data_length, data_delay, bclk_ratio;
  103823. + unsigned int ch1pos, ch2pos, mode, format;
  103824. + unsigned int mash = BCM2708_CLK_MASH_1;
  103825. + unsigned int divi, divf, target_frequency;
  103826. + int clk_src = -1;
  103827. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  103828. + bool bit_master = (master == SND_SOC_DAIFMT_CBS_CFS
  103829. + || master == SND_SOC_DAIFMT_CBS_CFM);
  103830. +
  103831. + bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
  103832. + || master == SND_SOC_DAIFMT_CBM_CFS);
  103833. + uint32_t csreg;
  103834. +
  103835. + /*
  103836. + * If a stream is already enabled,
  103837. + * the registers are already set properly.
  103838. + */
  103839. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  103840. +
  103841. + if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
  103842. + return 0;
  103843. +
  103844. + /*
  103845. + * Adjust the data length according to the format.
  103846. + * We prefill the half frame length with an integer
  103847. + * divider of 2400 as explained at the clock settings.
  103848. + * Maybe it is overwritten there, if the Integer mode
  103849. + * does not apply.
  103850. + */
  103851. + switch (params_format(params)) {
  103852. + case SNDRV_PCM_FORMAT_S16_LE:
  103853. + data_length = 16;
  103854. + bclk_ratio = 40;
  103855. + break;
  103856. + case SNDRV_PCM_FORMAT_S24_LE:
  103857. + data_length = 24;
  103858. + bclk_ratio = 40;
  103859. + break;
  103860. + case SNDRV_PCM_FORMAT_S32_LE:
  103861. + data_length = 32;
  103862. + bclk_ratio = 80;
  103863. + break;
  103864. + default:
  103865. + return -EINVAL;
  103866. + }
  103867. +
  103868. + /* If bclk_ratio already set, use that one. */
  103869. + if (dev->bclk_ratio)
  103870. + bclk_ratio = dev->bclk_ratio;
  103871. +
  103872. + /*
  103873. + * Clock Settings
  103874. + *
  103875. + * The target frequency of the bit clock is
  103876. + * sampling rate * frame length
  103877. + *
  103878. + * Integer mode:
  103879. + * Sampling rates that are multiples of 8000 kHz
  103880. + * can be driven by the oscillator of 19.2 MHz
  103881. + * with an integer divider as long as the frame length
  103882. + * is an integer divider of 19200000/8000=2400 as set up above.
  103883. + * This is no longer possible if the sampling rate
  103884. + * is too high (e.g. 192 kHz), because the oscillator is too slow.
  103885. + *
  103886. + * MASH mode:
  103887. + * For all other sampling rates, it is not possible to
  103888. + * have an integer divider. Approximate the clock
  103889. + * with the MASH module that induces a slight frequency
  103890. + * variance. To minimize that it is best to have the fastest
  103891. + * clock here. That is PLLD with 500 MHz.
  103892. + */
  103893. + target_frequency = sampling_rate * bclk_ratio;
  103894. + clk_src = BCM2708_CLK_SRC_OSC;
  103895. + mash = BCM2708_CLK_MASH_0;
  103896. +
  103897. + if (bcm2708_clk_freq[clk_src] % target_frequency == 0
  103898. + && bit_master && frame_master) {
  103899. + divi = bcm2708_clk_freq[clk_src] / target_frequency;
  103900. + divf = 0;
  103901. + } else {
  103902. + uint64_t dividend;
  103903. +
  103904. + if (!dev->bclk_ratio) {
  103905. + /*
  103906. + * Overwrite bclk_ratio, because the
  103907. + * above trick is not needed or can
  103908. + * not be used.
  103909. + */
  103910. + bclk_ratio = 2 * data_length;
  103911. + }
  103912. +
  103913. + target_frequency = sampling_rate * bclk_ratio;
  103914. +
  103915. + clk_src = BCM2708_CLK_SRC_PLLD;
  103916. + mash = BCM2708_CLK_MASH_1;
  103917. +
  103918. + dividend = bcm2708_clk_freq[clk_src];
  103919. + dividend <<= BCM2708_CLK_SHIFT;
  103920. + do_div(dividend, target_frequency);
  103921. + divi = dividend >> BCM2708_CLK_SHIFT;
  103922. + divf = dividend & BCM2708_CLK_DIVF_MASK;
  103923. + }
  103924. +
  103925. + /* Set clock divider */
  103926. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
  103927. + | BCM2708_CLK_DIVI(divi)
  103928. + | BCM2708_CLK_DIVF(divf));
  103929. +
  103930. + /* Setup clock, but don't start it yet */
  103931. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
  103932. + | BCM2708_CLK_MASH(mash)
  103933. + | BCM2708_CLK_SRC(clk_src));
  103934. +
  103935. + /* Setup the frame format */
  103936. + format = BCM2708_I2S_CHEN;
  103937. +
  103938. + if (data_length >= 24)
  103939. + format |= BCM2708_I2S_CHWEX;
  103940. +
  103941. + format |= BCM2708_I2S_CHWID((data_length-8)&0xf);
  103942. +
  103943. + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  103944. + case SND_SOC_DAIFMT_I2S:
  103945. + data_delay = 1;
  103946. + break;
  103947. + default:
  103948. + /*
  103949. + * TODO
  103950. + * Others are possible but are not implemented at the moment.
  103951. + */
  103952. + dev_err(dev->dev, "%s:bad format\n", __func__);
  103953. + return -EINVAL;
  103954. + }
  103955. +
  103956. + ch1pos = data_delay;
  103957. + ch2pos = bclk_ratio / 2 + data_delay;
  103958. +
  103959. + switch (params_channels(params)) {
  103960. + case 2:
  103961. + format = BCM2708_I2S_CH1(format) | BCM2708_I2S_CH2(format);
  103962. + format |= BCM2708_I2S_CH1(BCM2708_I2S_CHPOS(ch1pos));
  103963. + format |= BCM2708_I2S_CH2(BCM2708_I2S_CHPOS(ch2pos));
  103964. + break;
  103965. + default:
  103966. + return -EINVAL;
  103967. + }
  103968. +
  103969. + /*
  103970. + * Set format for both streams.
  103971. + * We cannot set another frame length
  103972. + * (and therefore word length) anyway,
  103973. + * so the format will be the same.
  103974. + */
  103975. + regmap_write(dev->i2s_regmap, BCM2708_I2S_RXC_A_REG, format);
  103976. + regmap_write(dev->i2s_regmap, BCM2708_I2S_TXC_A_REG, format);
  103977. +
  103978. + /* Setup the I2S mode */
  103979. + mode = 0;
  103980. +
  103981. + if (data_length <= 16) {
  103982. + /*
  103983. + * Use frame packed mode (2 channels per 32 bit word)
  103984. + * We cannot set another frame length in the second stream
  103985. + * (and therefore word length) anyway,
  103986. + * so the format will be the same.
  103987. + */
  103988. + mode |= BCM2708_I2S_FTXP | BCM2708_I2S_FRXP;
  103989. + }
  103990. +
  103991. + mode |= BCM2708_I2S_FLEN(bclk_ratio - 1);
  103992. + mode |= BCM2708_I2S_FSLEN(bclk_ratio / 2);
  103993. +
  103994. + /* Master or slave? */
  103995. + switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  103996. + case SND_SOC_DAIFMT_CBS_CFS:
  103997. + /* CPU is master */
  103998. + break;
  103999. + case SND_SOC_DAIFMT_CBM_CFS:
  104000. + /*
  104001. + * CODEC is bit clock master
  104002. + * CPU is frame master
  104003. + */
  104004. + mode |= BCM2708_I2S_CLKM;
  104005. + break;
  104006. + case SND_SOC_DAIFMT_CBS_CFM:
  104007. + /*
  104008. + * CODEC is frame master
  104009. + * CPU is bit clock master
  104010. + */
  104011. + mode |= BCM2708_I2S_FSM;
  104012. + break;
  104013. + case SND_SOC_DAIFMT_CBM_CFM:
  104014. + /* CODEC is master */
  104015. + mode |= BCM2708_I2S_CLKM;
  104016. + mode |= BCM2708_I2S_FSM;
  104017. + break;
  104018. + default:
  104019. + dev_err(dev->dev, "%s:bad master\n", __func__);
  104020. + return -EINVAL;
  104021. + }
  104022. +
  104023. + /*
  104024. + * Invert clocks?
  104025. + *
  104026. + * The BCM approach seems to be inverted to the classical I2S approach.
  104027. + */
  104028. + switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
  104029. + case SND_SOC_DAIFMT_NB_NF:
  104030. + /* None. Therefore, both for BCM */
  104031. + mode |= BCM2708_I2S_CLKI;
  104032. + mode |= BCM2708_I2S_FSI;
  104033. + break;
  104034. + case SND_SOC_DAIFMT_IB_IF:
  104035. + /* Both. Therefore, none for BCM */
  104036. + break;
  104037. + case SND_SOC_DAIFMT_NB_IF:
  104038. + /*
  104039. + * Invert only frame sync. Therefore,
  104040. + * invert only bit clock for BCM
  104041. + */
  104042. + mode |= BCM2708_I2S_CLKI;
  104043. + break;
  104044. + case SND_SOC_DAIFMT_IB_NF:
  104045. + /*
  104046. + * Invert only bit clock. Therefore,
  104047. + * invert only frame sync for BCM
  104048. + */
  104049. + mode |= BCM2708_I2S_FSI;
  104050. + break;
  104051. + default:
  104052. + return -EINVAL;
  104053. + }
  104054. +
  104055. + regmap_write(dev->i2s_regmap, BCM2708_I2S_MODE_A_REG, mode);
  104056. +
  104057. + /* Setup the DMA parameters */
  104058. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  104059. + BCM2708_I2S_RXTHR(1)
  104060. + | BCM2708_I2S_TXTHR(1)
  104061. + | BCM2708_I2S_DMAEN, 0xffffffff);
  104062. +
  104063. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_DREQ_A_REG,
  104064. + BCM2708_I2S_TX_PANIC(0x10)
  104065. + | BCM2708_I2S_RX_PANIC(0x30)
  104066. + | BCM2708_I2S_TX(0x30)
  104067. + | BCM2708_I2S_RX(0x20), 0xffffffff);
  104068. +
  104069. + /* Clear FIFOs */
  104070. + bcm2708_i2s_clear_fifos(dev, true, true);
  104071. +
  104072. + return 0;
  104073. +}
  104074. +
  104075. +static int bcm2708_i2s_prepare(struct snd_pcm_substream *substream,
  104076. + struct snd_soc_dai *dai)
  104077. +{
  104078. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  104079. + uint32_t cs_reg;
  104080. +
  104081. + bcm2708_i2s_start_clock(dev);
  104082. +
  104083. + /*
  104084. + * Clear both FIFOs if the one that should be started
  104085. + * is not empty at the moment. This should only happen
  104086. + * after overrun. Otherwise, hw_params would have cleared
  104087. + * the FIFO.
  104088. + */
  104089. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &cs_reg);
  104090. +
  104091. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
  104092. + && !(cs_reg & BCM2708_I2S_TXE))
  104093. + bcm2708_i2s_clear_fifos(dev, true, false);
  104094. + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
  104095. + && (cs_reg & BCM2708_I2S_RXD))
  104096. + bcm2708_i2s_clear_fifos(dev, false, true);
  104097. +
  104098. + return 0;
  104099. +}
  104100. +
  104101. +static void bcm2708_i2s_stop(struct bcm2708_i2s_dev *dev,
  104102. + struct snd_pcm_substream *substream,
  104103. + struct snd_soc_dai *dai)
  104104. +{
  104105. + uint32_t mask;
  104106. +
  104107. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  104108. + mask = BCM2708_I2S_RXON;
  104109. + else
  104110. + mask = BCM2708_I2S_TXON;
  104111. +
  104112. + regmap_update_bits(dev->i2s_regmap,
  104113. + BCM2708_I2S_CS_A_REG, mask, 0);
  104114. +
  104115. + /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
  104116. + if (!dai->active && !(dev->fmt & SND_SOC_DAIFMT_CONT))
  104117. + bcm2708_i2s_stop_clock(dev);
  104118. +}
  104119. +
  104120. +static int bcm2708_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  104121. + struct snd_soc_dai *dai)
  104122. +{
  104123. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  104124. + uint32_t mask;
  104125. +
  104126. + switch (cmd) {
  104127. + case SNDRV_PCM_TRIGGER_START:
  104128. + case SNDRV_PCM_TRIGGER_RESUME:
  104129. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  104130. + bcm2708_i2s_start_clock(dev);
  104131. +
  104132. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  104133. + mask = BCM2708_I2S_RXON;
  104134. + else
  104135. + mask = BCM2708_I2S_TXON;
  104136. +
  104137. + regmap_update_bits(dev->i2s_regmap,
  104138. + BCM2708_I2S_CS_A_REG, mask, mask);
  104139. + break;
  104140. +
  104141. + case SNDRV_PCM_TRIGGER_STOP:
  104142. + case SNDRV_PCM_TRIGGER_SUSPEND:
  104143. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  104144. + bcm2708_i2s_stop(dev, substream, dai);
  104145. + break;
  104146. + default:
  104147. + return -EINVAL;
  104148. + }
  104149. +
  104150. + return 0;
  104151. +}
  104152. +
  104153. +static int bcm2708_i2s_startup(struct snd_pcm_substream *substream,
  104154. + struct snd_soc_dai *dai)
  104155. +{
  104156. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  104157. +
  104158. + if (dai->active)
  104159. + return 0;
  104160. +
  104161. + /* Should this still be running stop it */
  104162. + bcm2708_i2s_stop_clock(dev);
  104163. +
  104164. + /* Enable PCM block */
  104165. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  104166. + BCM2708_I2S_EN, BCM2708_I2S_EN);
  104167. +
  104168. + /*
  104169. + * Disable STBY.
  104170. + * Requires at least 4 PCM clock cycles to take effect.
  104171. + */
  104172. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  104173. + BCM2708_I2S_STBY, BCM2708_I2S_STBY);
  104174. +
  104175. + return 0;
  104176. +}
  104177. +
  104178. +static void bcm2708_i2s_shutdown(struct snd_pcm_substream *substream,
  104179. + struct snd_soc_dai *dai)
  104180. +{
  104181. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  104182. +
  104183. + bcm2708_i2s_stop(dev, substream, dai);
  104184. +
  104185. + /* If both streams are stopped, disable module and clock */
  104186. + if (dai->active)
  104187. + return;
  104188. +
  104189. + /* Disable the module */
  104190. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  104191. + BCM2708_I2S_EN, 0);
  104192. +
  104193. + /*
  104194. + * Stopping clock is necessary, because stop does
  104195. + * not stop the clock when SND_SOC_DAIFMT_CONT
  104196. + */
  104197. + bcm2708_i2s_stop_clock(dev);
  104198. +}
  104199. +
  104200. +static const struct snd_soc_dai_ops bcm2708_i2s_dai_ops = {
  104201. + .startup = bcm2708_i2s_startup,
  104202. + .shutdown = bcm2708_i2s_shutdown,
  104203. + .prepare = bcm2708_i2s_prepare,
  104204. + .trigger = bcm2708_i2s_trigger,
  104205. + .hw_params = bcm2708_i2s_hw_params,
  104206. + .set_fmt = bcm2708_i2s_set_dai_fmt,
  104207. + .set_bclk_ratio = bcm2708_i2s_set_dai_bclk_ratio
  104208. +};
  104209. +
  104210. +static int bcm2708_i2s_dai_probe(struct snd_soc_dai *dai)
  104211. +{
  104212. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  104213. +
  104214. + dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
  104215. + dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
  104216. +
  104217. + return 0;
  104218. +}
  104219. +
  104220. +static struct snd_soc_dai_driver bcm2708_i2s_dai = {
  104221. + .name = "bcm2708-i2s",
  104222. + .probe = bcm2708_i2s_dai_probe,
  104223. + .playback = {
  104224. + .channels_min = 2,
  104225. + .channels_max = 2,
  104226. + .rates = SNDRV_PCM_RATE_8000_192000,
  104227. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  104228. + // | SNDRV_PCM_FMTBIT_S24_LE : disable for now, it causes white noise with xbmc
  104229. + | SNDRV_PCM_FMTBIT_S32_LE
  104230. + },
  104231. + .capture = {
  104232. + .channels_min = 2,
  104233. + .channels_max = 2,
  104234. + .rates = SNDRV_PCM_RATE_8000_192000,
  104235. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  104236. + | SNDRV_PCM_FMTBIT_S24_LE
  104237. + | SNDRV_PCM_FMTBIT_S32_LE
  104238. + },
  104239. + .ops = &bcm2708_i2s_dai_ops,
  104240. + .symmetric_rates = 1
  104241. +};
  104242. +
  104243. +static bool bcm2708_i2s_volatile_reg(struct device *dev, unsigned int reg)
  104244. +{
  104245. + switch (reg) {
  104246. + case BCM2708_I2S_CS_A_REG:
  104247. + case BCM2708_I2S_FIFO_A_REG:
  104248. + case BCM2708_I2S_INTSTC_A_REG:
  104249. + case BCM2708_I2S_GRAY_REG:
  104250. + return true;
  104251. + default:
  104252. + return false;
  104253. + };
  104254. +}
  104255. +
  104256. +static bool bcm2708_i2s_precious_reg(struct device *dev, unsigned int reg)
  104257. +{
  104258. + switch (reg) {
  104259. + case BCM2708_I2S_FIFO_A_REG:
  104260. + return true;
  104261. + default:
  104262. + return false;
  104263. + };
  104264. +}
  104265. +
  104266. +static bool bcm2708_clk_volatile_reg(struct device *dev, unsigned int reg)
  104267. +{
  104268. + switch (reg) {
  104269. + case BCM2708_CLK_PCMCTL_REG:
  104270. + return true;
  104271. + default:
  104272. + return false;
  104273. + };
  104274. +}
  104275. +
  104276. +static const struct regmap_config bcm2708_regmap_config[] = {
  104277. + {
  104278. + .reg_bits = 32,
  104279. + .reg_stride = 4,
  104280. + .val_bits = 32,
  104281. + .max_register = BCM2708_I2S_GRAY_REG,
  104282. + .precious_reg = bcm2708_i2s_precious_reg,
  104283. + .volatile_reg = bcm2708_i2s_volatile_reg,
  104284. + .cache_type = REGCACHE_RBTREE,
  104285. + },
  104286. + {
  104287. + .reg_bits = 32,
  104288. + .reg_stride = 4,
  104289. + .val_bits = 32,
  104290. + .max_register = BCM2708_CLK_PCMDIV_REG,
  104291. + .volatile_reg = bcm2708_clk_volatile_reg,
  104292. + .cache_type = REGCACHE_RBTREE,
  104293. + },
  104294. +};
  104295. +
  104296. +static const struct snd_soc_component_driver bcm2708_i2s_component = {
  104297. + .name = "bcm2708-i2s-comp",
  104298. +};
  104299. +
  104300. +
  104301. +static void bcm2708_i2s_setup_gpio(void)
  104302. +{
  104303. + /*
  104304. + * This is the common way to handle the GPIO pins for
  104305. + * the Raspberry Pi.
  104306. + * TODO Better way would be to handle
  104307. + * this in the device tree!
  104308. + */
  104309. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  104310. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  104311. +
  104312. + unsigned int *gpio;
  104313. + int pin;
  104314. + gpio = ioremap(GPIO_BASE, SZ_16K);
  104315. +
  104316. + /* SPI is on GPIO 7..11 */
  104317. + for (pin = 28; pin <= 31; pin++) {
  104318. + INP_GPIO(pin); /* set mode to GPIO input first */
  104319. + SET_GPIO_ALT(pin, 2); /* set mode to ALT 0 */
  104320. + }
  104321. +#undef INP_GPIO
  104322. +#undef SET_GPIO_ALT
  104323. +}
  104324. +
  104325. +static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  104326. + .info = SNDRV_PCM_INFO_INTERLEAVED |
  104327. + SNDRV_PCM_INFO_JOINT_DUPLEX,
  104328. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  104329. + SNDRV_PCM_FMTBIT_S24_LE |
  104330. + SNDRV_PCM_FMTBIT_S32_LE,
  104331. + .period_bytes_min = 32,
  104332. + .period_bytes_max = 64 * PAGE_SIZE,
  104333. + .periods_min = 2,
  104334. + .periods_max = 255,
  104335. + .buffer_bytes_max = 128 * PAGE_SIZE,
  104336. +};
  104337. +
  104338. +static const struct snd_dmaengine_pcm_config bcm2708_dmaengine_pcm_config = {
  104339. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  104340. + .pcm_hardware = &bcm2708_pcm_hardware,
  104341. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  104342. +};
  104343. +
  104344. +
  104345. +static int bcm2708_i2s_probe(struct platform_device *pdev)
  104346. +{
  104347. + struct bcm2708_i2s_dev *dev;
  104348. + int i;
  104349. + int ret;
  104350. + struct regmap *regmap[2];
  104351. + struct resource *mem[2];
  104352. +
  104353. + /* Request both ioareas */
  104354. + for (i = 0; i <= 1; i++) {
  104355. + void __iomem *base;
  104356. +
  104357. + mem[i] = platform_get_resource(pdev, IORESOURCE_MEM, i);
  104358. + base = devm_ioremap_resource(&pdev->dev, mem[i]);
  104359. + if (IS_ERR(base))
  104360. + return PTR_ERR(base);
  104361. +
  104362. + regmap[i] = devm_regmap_init_mmio(&pdev->dev, base,
  104363. + &bcm2708_regmap_config[i]);
  104364. + if (IS_ERR(regmap[i])) {
  104365. + dev_err(&pdev->dev, "I2S probe: regmap init failed\n");
  104366. + return PTR_ERR(regmap[i]);
  104367. + }
  104368. + }
  104369. +
  104370. + dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
  104371. + GFP_KERNEL);
  104372. + if (IS_ERR(dev))
  104373. + return PTR_ERR(dev);
  104374. +
  104375. + bcm2708_i2s_setup_gpio();
  104376. +
  104377. + dev->i2s_regmap = regmap[0];
  104378. + dev->clk_regmap = regmap[1];
  104379. +
  104380. + /* Set the DMA address */
  104381. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
  104382. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  104383. +
  104384. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
  104385. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  104386. +
  104387. + /* Set the DREQ */
  104388. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].slave_id =
  104389. + BCM2708_DMA_DREQ_PCM_TX;
  104390. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].slave_id =
  104391. + BCM2708_DMA_DREQ_PCM_RX;
  104392. +
  104393. + /* Set the bus width */
  104394. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
  104395. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  104396. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width =
  104397. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  104398. +
  104399. + /* Set burst */
  104400. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2;
  104401. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2;
  104402. +
  104403. + /* BCLK ratio - use default */
  104404. + dev->bclk_ratio = 0;
  104405. +
  104406. + /* Store the pdev */
  104407. + dev->dev = &pdev->dev;
  104408. + dev_set_drvdata(&pdev->dev, dev);
  104409. +
  104410. + ret = snd_soc_register_component(&pdev->dev,
  104411. + &bcm2708_i2s_component, &bcm2708_i2s_dai, 1);
  104412. +
  104413. + if (ret) {
  104414. + dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  104415. + ret = -ENOMEM;
  104416. + return ret;
  104417. + }
  104418. +
  104419. + ret = snd_dmaengine_pcm_register(&pdev->dev,
  104420. + &bcm2708_dmaengine_pcm_config,
  104421. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  104422. + if (ret) {
  104423. + dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  104424. + snd_soc_unregister_component(&pdev->dev);
  104425. + return ret;
  104426. + }
  104427. +
  104428. + return 0;
  104429. +}
  104430. +
  104431. +static int bcm2708_i2s_remove(struct platform_device *pdev)
  104432. +{
  104433. + snd_dmaengine_pcm_unregister(&pdev->dev);
  104434. + snd_soc_unregister_component(&pdev->dev);
  104435. + return 0;
  104436. +}
  104437. +
  104438. +static struct platform_driver bcm2708_i2s_driver = {
  104439. + .probe = bcm2708_i2s_probe,
  104440. + .remove = bcm2708_i2s_remove,
  104441. + .driver = {
  104442. + .name = "bcm2708-i2s",
  104443. + .owner = THIS_MODULE,
  104444. + },
  104445. +};
  104446. +
  104447. +module_platform_driver(bcm2708_i2s_driver);
  104448. +
  104449. +MODULE_ALIAS("platform:bcm2708-i2s");
  104450. +MODULE_DESCRIPTION("BCM2708 I2S interface");
  104451. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104452. +MODULE_LICENSE("GPL v2");
  104453. diff -Nur linux-3.12.18/sound/soc/bcm/hifiberry_dac.c linux-rpi/sound/soc/bcm/hifiberry_dac.c
  104454. --- linux-3.12.18/sound/soc/bcm/hifiberry_dac.c 1970-01-01 01:00:00.000000000 +0100
  104455. +++ linux-rpi/sound/soc/bcm/hifiberry_dac.c 2014-04-24 15:35:05.481580345 +0200
  104456. @@ -0,0 +1,100 @@
  104457. +/*
  104458. + * ASoC Driver for HifiBerry DAC
  104459. + *
  104460. + * Author: Florian Meier <florian.meier@koalo.de>
  104461. + * Copyright 2013
  104462. + *
  104463. + * This program is free software; you can redistribute it and/or
  104464. + * modify it under the terms of the GNU General Public License
  104465. + * version 2 as published by the Free Software Foundation.
  104466. + *
  104467. + * This program is distributed in the hope that it will be useful, but
  104468. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104469. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104470. + * General Public License for more details.
  104471. + */
  104472. +
  104473. +#include <linux/module.h>
  104474. +#include <linux/platform_device.h>
  104475. +
  104476. +#include <sound/core.h>
  104477. +#include <sound/pcm.h>
  104478. +#include <sound/pcm_params.h>
  104479. +#include <sound/soc.h>
  104480. +#include <sound/jack.h>
  104481. +
  104482. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  104483. +{
  104484. + return 0;
  104485. +}
  104486. +
  104487. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  104488. + struct snd_pcm_hw_params *params)
  104489. +{
  104490. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104491. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  104492. +
  104493. + unsigned int sample_bits =
  104494. + snd_pcm_format_physical_width(params_format(params));
  104495. +
  104496. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  104497. +}
  104498. +
  104499. +/* machine stream operations */
  104500. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  104501. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  104502. +};
  104503. +
  104504. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  104505. +{
  104506. + .name = "HifiBerry DAC",
  104507. + .stream_name = "HifiBerry DAC HiFi",
  104508. + .cpu_dai_name = "bcm2708-i2s.0",
  104509. + .codec_dai_name = "pcm5102a-hifi",
  104510. + .platform_name = "bcm2708-i2s.0",
  104511. + .codec_name = "pcm5102a-codec",
  104512. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104513. + SND_SOC_DAIFMT_CBS_CFS,
  104514. + .ops = &snd_rpi_hifiberry_dac_ops,
  104515. + .init = snd_rpi_hifiberry_dac_init,
  104516. +},
  104517. +};
  104518. +
  104519. +/* audio machine driver */
  104520. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  104521. + .name = "snd_rpi_hifiberry_dac",
  104522. + .dai_link = snd_rpi_hifiberry_dac_dai,
  104523. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  104524. +};
  104525. +
  104526. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  104527. +{
  104528. + int ret = 0;
  104529. +
  104530. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  104531. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  104532. + if (ret)
  104533. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  104534. +
  104535. + return ret;
  104536. +}
  104537. +
  104538. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  104539. +{
  104540. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  104541. +}
  104542. +
  104543. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  104544. + .driver = {
  104545. + .name = "snd-hifiberry-dac",
  104546. + .owner = THIS_MODULE,
  104547. + },
  104548. + .probe = snd_rpi_hifiberry_dac_probe,
  104549. + .remove = snd_rpi_hifiberry_dac_remove,
  104550. +};
  104551. +
  104552. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  104553. +
  104554. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104555. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  104556. +MODULE_LICENSE("GPL v2");
  104557. diff -Nur linux-3.12.18/sound/soc/bcm/hifiberry_digi.c linux-rpi/sound/soc/bcm/hifiberry_digi.c
  104558. --- linux-3.12.18/sound/soc/bcm/hifiberry_digi.c 1970-01-01 01:00:00.000000000 +0100
  104559. +++ linux-rpi/sound/soc/bcm/hifiberry_digi.c 2014-04-24 16:04:43.363158508 +0200
  104560. @@ -0,0 +1,153 @@
  104561. +/*
  104562. + * ASoC Driver for HifiBerry Digi
  104563. + *
  104564. + * Author: Daniel Matuschek <info@crazy-audio.com>
  104565. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  104566. + * Copyright 2013
  104567. + *
  104568. + * This program is free software; you can redistribute it and/or
  104569. + * modify it under the terms of the GNU General Public License
  104570. + * version 2 as published by the Free Software Foundation.
  104571. + *
  104572. + * This program is distributed in the hope that it will be useful, but
  104573. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104574. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104575. + * General Public License for more details.
  104576. + */
  104577. +
  104578. +#include <linux/module.h>
  104579. +#include <linux/platform_device.h>
  104580. +
  104581. +#include <sound/core.h>
  104582. +#include <sound/pcm.h>
  104583. +#include <sound/pcm_params.h>
  104584. +#include <sound/soc.h>
  104585. +#include <sound/jack.h>
  104586. +
  104587. +#include "../codecs/wm8804.h"
  104588. +
  104589. +static int samplerate=44100;
  104590. +
  104591. +static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  104592. +{
  104593. + struct snd_soc_codec *codec = rtd->codec;
  104594. +
  104595. + /* enable TX output */
  104596. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  104597. +
  104598. + return 0;
  104599. +}
  104600. +
  104601. +static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
  104602. + struct snd_pcm_hw_params *params)
  104603. +{
  104604. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104605. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  104606. + struct snd_soc_codec *codec = rtd->codec;
  104607. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  104608. +
  104609. + int sysclk = 27000000; /* This is fixed on this board */
  104610. +
  104611. + long mclk_freq=0;
  104612. + int mclk_div=1;
  104613. +
  104614. + int ret;
  104615. +
  104616. + samplerate = params_rate(params);
  104617. +
  104618. + switch (samplerate) {
  104619. + case 44100:
  104620. + case 48000:
  104621. + case 88200:
  104622. + case 96000:
  104623. + mclk_freq=samplerate*256;
  104624. + mclk_div=WM8804_MCLKDIV_256FS;
  104625. + break;
  104626. + case 176400:
  104627. + case 192000:
  104628. + mclk_freq=samplerate*128;
  104629. + mclk_div=WM8804_MCLKDIV_128FS;
  104630. + break;
  104631. + default:
  104632. + dev_err(substream->pcm->dev,
  104633. + "Failed to set WM8804 SYSCLK, unsupported samplerate\n");
  104634. + }
  104635. +
  104636. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  104637. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  104638. +
  104639. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  104640. + sysclk, SND_SOC_CLOCK_OUT);
  104641. + if (ret < 0) {
  104642. + dev_err(substream->pcm->dev,
  104643. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  104644. + return ret;
  104645. + }
  104646. +
  104647. + /* Enable TX output */
  104648. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  104649. +
  104650. + /* Power on */
  104651. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  104652. +
  104653. + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
  104654. +}
  104655. +
  104656. +/* machine stream operations */
  104657. +static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
  104658. + .hw_params = snd_rpi_hifiberry_digi_hw_params,
  104659. +};
  104660. +
  104661. +static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {
  104662. +{
  104663. + .name = "HifiBerry Digi",
  104664. + .stream_name = "HifiBerry Digi HiFi",
  104665. + .cpu_dai_name = "bcm2708-i2s.0",
  104666. + .codec_dai_name = "wm8804-spdif",
  104667. + .platform_name = "bcm2708-i2s.0",
  104668. + .codec_name = "wm8804.1-003b",
  104669. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104670. + SND_SOC_DAIFMT_CBM_CFM,
  104671. + .ops = &snd_rpi_hifiberry_digi_ops,
  104672. + .init = snd_rpi_hifiberry_digi_init,
  104673. +},
  104674. +};
  104675. +
  104676. +/* audio machine driver */
  104677. +static struct snd_soc_card snd_rpi_hifiberry_digi = {
  104678. + .name = "snd_rpi_hifiberry_digi",
  104679. + .dai_link = snd_rpi_hifiberry_digi_dai,
  104680. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_digi_dai),
  104681. +};
  104682. +
  104683. +static int snd_rpi_hifiberry_digi_probe(struct platform_device *pdev)
  104684. +{
  104685. + int ret = 0;
  104686. +
  104687. + snd_rpi_hifiberry_digi.dev = &pdev->dev;
  104688. + ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
  104689. + if (ret)
  104690. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  104691. +
  104692. + return ret;
  104693. +}
  104694. +
  104695. +static int snd_rpi_hifiberry_digi_remove(struct platform_device *pdev)
  104696. +{
  104697. + return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
  104698. +}
  104699. +
  104700. +static struct platform_driver snd_rpi_hifiberry_digi_driver = {
  104701. + .driver = {
  104702. + .name = "snd-hifiberry-digi",
  104703. + .owner = THIS_MODULE,
  104704. + },
  104705. + .probe = snd_rpi_hifiberry_digi_probe,
  104706. + .remove = snd_rpi_hifiberry_digi_remove,
  104707. +};
  104708. +
  104709. +module_platform_driver(snd_rpi_hifiberry_digi_driver);
  104710. +
  104711. +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
  104712. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry Digi");
  104713. +MODULE_LICENSE("GPL v2");
  104714. diff -Nur linux-3.12.18/sound/soc/bcm/iqaudio-dac.c linux-rpi/sound/soc/bcm/iqaudio-dac.c
  104715. --- linux-3.12.18/sound/soc/bcm/iqaudio-dac.c 1970-01-01 01:00:00.000000000 +0100
  104716. +++ linux-rpi/sound/soc/bcm/iqaudio-dac.c 2014-04-24 16:04:43.363158508 +0200
  104717. @@ -0,0 +1,111 @@
  104718. +/*
  104719. + * ASoC Driver for IQaudIO DAC
  104720. + *
  104721. + * Author: Florian Meier <florian.meier@koalo.de>
  104722. + * Copyright 2013
  104723. + *
  104724. + * This program is free software; you can redistribute it and/or
  104725. + * modify it under the terms of the GNU General Public License
  104726. + * version 2 as published by the Free Software Foundation.
  104727. + *
  104728. + * This program is distributed in the hope that it will be useful, but
  104729. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104730. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104731. + * General Public License for more details.
  104732. + */
  104733. +
  104734. +#include <linux/module.h>
  104735. +#include <linux/platform_device.h>
  104736. +
  104737. +#include <sound/core.h>
  104738. +#include <sound/pcm.h>
  104739. +#include <sound/pcm_params.h>
  104740. +#include <sound/soc.h>
  104741. +#include <sound/jack.h>
  104742. +
  104743. +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
  104744. +{
  104745. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  104746. +
  104747. + return 0;
  104748. +}
  104749. +
  104750. +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
  104751. + struct snd_pcm_hw_params *params)
  104752. +{
  104753. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104754. +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai;
  104755. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  104756. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  104757. +
  104758. + unsigned int sample_bits =
  104759. + snd_pcm_format_physical_width(params_format(params));
  104760. +
  104761. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  104762. +}
  104763. +
  104764. +/* machine stream operations */
  104765. +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
  104766. + .hw_params = snd_rpi_iqaudio_dac_hw_params,
  104767. +};
  104768. +
  104769. +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
  104770. +{
  104771. + .name = "IQaudIO DAC",
  104772. + .stream_name = "IQaudIO DAC HiFi",
  104773. + .cpu_dai_name = "bcm2708-i2s.0",
  104774. + .codec_dai_name = "pcm512x-hifi",
  104775. + .platform_name = "bcm2708-i2s.0",
  104776. + .codec_name = "pcm512x.1-004c",
  104777. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104778. + SND_SOC_DAIFMT_CBS_CFS,
  104779. + .ops = &snd_rpi_iqaudio_dac_ops,
  104780. + .init = snd_rpi_iqaudio_dac_init,
  104781. +},
  104782. +};
  104783. +
  104784. +/* audio machine driver */
  104785. +static struct snd_soc_card snd_rpi_iqaudio_dac = {
  104786. + .name = "snd_rpi_iqaudio_dac",
  104787. + .dai_link = snd_rpi_iqaudio_dac_dai,
  104788. + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
  104789. +};
  104790. +
  104791. +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
  104792. +{
  104793. + int ret = 0;
  104794. +
  104795. + snd_rpi_iqaudio_dac.dev = &pdev->dev;
  104796. + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
  104797. + if (ret)
  104798. + dev_err(&pdev->dev,
  104799. + "snd_soc_register_card() failed: %d\n", ret);
  104800. +
  104801. + return ret;
  104802. +}
  104803. +
  104804. +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
  104805. +{
  104806. + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
  104807. +}
  104808. +
  104809. +static const struct of_device_id iqaudio_of_match[] = {
  104810. + { .compatible = "iqaudio,iqaudio-dac", },
  104811. + {},
  104812. +};
  104813. +
  104814. +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
  104815. + .driver = {
  104816. + .name = "snd-rpi-iqaudio-dac",
  104817. + .owner = THIS_MODULE,
  104818. + .of_match_table = iqaudio_of_match,
  104819. + },
  104820. + .probe = snd_rpi_iqaudio_dac_probe,
  104821. + .remove = snd_rpi_iqaudio_dac_remove,
  104822. +};
  104823. +
  104824. +module_platform_driver(snd_rpi_iqaudio_dac_driver);
  104825. +
  104826. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104827. +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
  104828. +MODULE_LICENSE("GPL v2");
  104829. diff -Nur linux-3.12.18/sound/soc/bcm/Kconfig linux-rpi/sound/soc/bcm/Kconfig
  104830. --- linux-3.12.18/sound/soc/bcm/Kconfig 1970-01-01 01:00:00.000000000 +0100
  104831. +++ linux-rpi/sound/soc/bcm/Kconfig 2014-04-24 15:35:05.481580345 +0200
  104832. @@ -0,0 +1,38 @@
  104833. +config SND_BCM2708_SOC_I2S
  104834. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  104835. + depends on MACH_BCM2708
  104836. + select REGMAP_MMIO
  104837. + select SND_SOC_DMAENGINE_PCM
  104838. + select SND_SOC_GENERIC_DMAENGINE_PCM
  104839. + help
  104840. + Say Y or M if you want to add support for codecs attached to
  104841. + the BCM2708 I2S interface. You will also need
  104842. + to select the audio interfaces to support below.
  104843. +
  104844. +config SND_BCM2708_SOC_HIFIBERRY_DAC
  104845. + tristate "Support for HifiBerry DAC"
  104846. + depends on SND_BCM2708_SOC_I2S
  104847. + select SND_SOC_PCM5102A
  104848. + help
  104849. + Say Y or M if you want to add support for HifiBerry DAC.
  104850. +
  104851. +config SND_BCM2708_SOC_HIFIBERRY_DIGI
  104852. + tristate "Support for HifiBerry Digi"
  104853. + depends on SND_BCM2708_SOC_I2S
  104854. + select SND_SOC_WM8804
  104855. + help
  104856. + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
  104857. +
  104858. +config SND_BCM2708_SOC_RPI_DAC
  104859. + tristate "Support for RPi-DAC"
  104860. + depends on SND_BCM2708_SOC_I2S
  104861. + select SND_SOC_PCM1794A
  104862. + help
  104863. + Say Y or M if you want to add support for RPi-DAC.
  104864. +
  104865. +config SND_BCM2708_SOC_IQAUDIO_DAC
  104866. + tristate "Support for IQaudIO-DAC"
  104867. + depends on SND_BCM2708_SOC_I2S
  104868. + select SND_SOC_PCM512x
  104869. + help
  104870. + Say Y or M if you want to add support for IQaudIO-DAC.
  104871. diff -Nur linux-3.12.18/sound/soc/bcm/Makefile linux-rpi/sound/soc/bcm/Makefile
  104872. --- linux-3.12.18/sound/soc/bcm/Makefile 1970-01-01 01:00:00.000000000 +0100
  104873. +++ linux-rpi/sound/soc/bcm/Makefile 2014-04-24 16:04:43.363158508 +0200
  104874. @@ -0,0 +1,15 @@
  104875. +# BCM2708 Platform Support
  104876. +snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  104877. +
  104878. +obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  104879. +
  104880. +# BCM2708 Machine Support
  104881. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  104882. +snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  104883. +snd-soc-rpi-dac-objs := rpi-dac.o
  104884. +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  104885. +
  104886. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  104887. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  104888. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  104889. +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  104890. diff -Nur linux-3.12.18/sound/soc/bcm/rpi-dac.c linux-rpi/sound/soc/bcm/rpi-dac.c
  104891. --- linux-3.12.18/sound/soc/bcm/rpi-dac.c 1970-01-01 01:00:00.000000000 +0100
  104892. +++ linux-rpi/sound/soc/bcm/rpi-dac.c 2014-04-24 15:35:05.481580345 +0200
  104893. @@ -0,0 +1,97 @@
  104894. +/*
  104895. + * ASoC Driver for RPi-DAC.
  104896. + *
  104897. + * Author: Florian Meier <florian.meier@koalo.de>
  104898. + * Copyright 2013
  104899. + *
  104900. + * This program is free software; you can redistribute it and/or
  104901. + * modify it under the terms of the GNU General Public License
  104902. + * version 2 as published by the Free Software Foundation.
  104903. + *
  104904. + * This program is distributed in the hope that it will be useful, but
  104905. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104906. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104907. + * General Public License for more details.
  104908. + */
  104909. +
  104910. +#include <linux/module.h>
  104911. +#include <linux/platform_device.h>
  104912. +
  104913. +#include <sound/core.h>
  104914. +#include <sound/pcm.h>
  104915. +#include <sound/pcm_params.h>
  104916. +#include <sound/soc.h>
  104917. +#include <sound/jack.h>
  104918. +
  104919. +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
  104920. +{
  104921. + return 0;
  104922. +}
  104923. +
  104924. +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
  104925. + struct snd_pcm_hw_params *params)
  104926. +{
  104927. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104928. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  104929. +
  104930. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
  104931. +}
  104932. +
  104933. +/* machine stream operations */
  104934. +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
  104935. + .hw_params = snd_rpi_rpi_dac_hw_params,
  104936. +};
  104937. +
  104938. +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
  104939. +{
  104940. + .name = "HifiBerry Mini",
  104941. + .stream_name = "HifiBerry Mini HiFi",
  104942. + .cpu_dai_name = "bcm2708-i2s.0",
  104943. + .codec_dai_name = "pcm1794a-hifi",
  104944. + .platform_name = "bcm2708-i2s.0",
  104945. + .codec_name = "pcm1794a-codec",
  104946. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104947. + SND_SOC_DAIFMT_CBS_CFS,
  104948. + .ops = &snd_rpi_rpi_dac_ops,
  104949. + .init = snd_rpi_rpi_dac_init,
  104950. +},
  104951. +};
  104952. +
  104953. +/* audio machine driver */
  104954. +static struct snd_soc_card snd_rpi_rpi_dac = {
  104955. + .name = "snd_rpi_rpi_dac",
  104956. + .dai_link = snd_rpi_rpi_dac_dai,
  104957. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  104958. +};
  104959. +
  104960. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  104961. +{
  104962. + int ret = 0;
  104963. +
  104964. + snd_rpi_rpi_dac.dev = &pdev->dev;
  104965. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  104966. + if (ret)
  104967. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  104968. +
  104969. + return ret;
  104970. +}
  104971. +
  104972. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  104973. +{
  104974. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  104975. +}
  104976. +
  104977. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  104978. + .driver = {
  104979. + .name = "snd-rpi-dac",
  104980. + .owner = THIS_MODULE,
  104981. + },
  104982. + .probe = snd_rpi_rpi_dac_probe,
  104983. + .remove = snd_rpi_rpi_dac_remove,
  104984. +};
  104985. +
  104986. +module_platform_driver(snd_rpi_rpi_dac_driver);
  104987. +
  104988. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104989. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  104990. +MODULE_LICENSE("GPL v2");
  104991. diff -Nur linux-3.12.18/sound/soc/codecs/Kconfig linux-rpi/sound/soc/codecs/Kconfig
  104992. --- linux-3.12.18/sound/soc/codecs/Kconfig 2014-04-18 11:14:28.000000000 +0200
  104993. +++ linux-rpi/sound/soc/codecs/Kconfig 2014-04-24 16:04:43.367158547 +0200
  104994. @@ -59,6 +59,9 @@
  104995. select SND_SOC_PCM1681 if I2C
  104996. select SND_SOC_PCM1792A if SPI_MASTER
  104997. select SND_SOC_PCM3008
  104998. + select SND_SOC_PCM1794A
  104999. + select SND_SOC_PCM5102A
  105000. + select SND_SOC_PCM512x if SND_SOC_I2C_AND_SPI
  105001. select SND_SOC_RT5631 if I2C
  105002. select SND_SOC_RT5640 if I2C
  105003. select SND_SOC_SGTL5000 if I2C
  105004. @@ -311,6 +314,15 @@
  105005. config SND_SOC_PCM3008
  105006. tristate
  105007. +config SND_SOC_PCM1794A
  105008. + tristate
  105009. +
  105010. +config SND_SOC_PCM5102A
  105011. + tristate
  105012. +
  105013. +config SND_SOC_PCM512x
  105014. + tristate
  105015. +
  105016. config SND_SOC_RT5631
  105017. tristate
  105018. diff -Nur linux-3.12.18/sound/soc/codecs/Makefile linux-rpi/sound/soc/codecs/Makefile
  105019. --- linux-3.12.18/sound/soc/codecs/Makefile 2014-04-18 11:14:28.000000000 +0200
  105020. +++ linux-rpi/sound/soc/codecs/Makefile 2014-04-24 16:04:43.367158547 +0200
  105021. @@ -46,6 +46,9 @@
  105022. snd-soc-pcm1681-objs := pcm1681.o
  105023. snd-soc-pcm1792a-codec-objs := pcm1792a.o
  105024. snd-soc-pcm3008-objs := pcm3008.o
  105025. +snd-soc-pcm1794a-objs := pcm1794a.o
  105026. +snd-soc-pcm5102a-objs := pcm5102a.o
  105027. +snd-soc-pcm512x-objs := pcm512x.o
  105028. snd-soc-rt5631-objs := rt5631.o
  105029. snd-soc-rt5640-objs := rt5640.o
  105030. snd-soc-sgtl5000-objs := sgtl5000.o
  105031. @@ -179,6 +182,9 @@
  105032. obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o
  105033. obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
  105034. obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
  105035. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  105036. +obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
  105037. +obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
  105038. obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
  105039. obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
  105040. obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
  105041. diff -Nur linux-3.12.18/sound/soc/codecs/pcm1794a.c linux-rpi/sound/soc/codecs/pcm1794a.c
  105042. --- linux-3.12.18/sound/soc/codecs/pcm1794a.c 1970-01-01 01:00:00.000000000 +0100
  105043. +++ linux-rpi/sound/soc/codecs/pcm1794a.c 2014-04-24 15:35:05.493580478 +0200
  105044. @@ -0,0 +1,62 @@
  105045. +/*
  105046. + * Driver for the PCM1794A codec
  105047. + *
  105048. + * Author: Florian Meier <florian.meier@koalo.de>
  105049. + * Copyright 2013
  105050. + *
  105051. + * This program is free software; you can redistribute it and/or
  105052. + * modify it under the terms of the GNU General Public License
  105053. + * version 2 as published by the Free Software Foundation.
  105054. + *
  105055. + * This program is distributed in the hope that it will be useful, but
  105056. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  105057. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  105058. + * General Public License for more details.
  105059. + */
  105060. +
  105061. +
  105062. +#include <linux/init.h>
  105063. +#include <linux/module.h>
  105064. +#include <linux/platform_device.h>
  105065. +
  105066. +#include <sound/soc.h>
  105067. +
  105068. +static struct snd_soc_dai_driver pcm1794a_dai = {
  105069. + .name = "pcm1794a-hifi",
  105070. + .playback = {
  105071. + .channels_min = 2,
  105072. + .channels_max = 2,
  105073. + .rates = SNDRV_PCM_RATE_8000_192000,
  105074. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  105075. + SNDRV_PCM_FMTBIT_S24_LE
  105076. + },
  105077. +};
  105078. +
  105079. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  105080. +
  105081. +static int pcm1794a_probe(struct platform_device *pdev)
  105082. +{
  105083. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  105084. + &pcm1794a_dai, 1);
  105085. +}
  105086. +
  105087. +static int pcm1794a_remove(struct platform_device *pdev)
  105088. +{
  105089. + snd_soc_unregister_codec(&pdev->dev);
  105090. + return 0;
  105091. +}
  105092. +
  105093. +static struct platform_driver pcm1794a_codec_driver = {
  105094. + .probe = pcm1794a_probe,
  105095. + .remove = pcm1794a_remove,
  105096. + .driver = {
  105097. + .name = "pcm1794a-codec",
  105098. + .owner = THIS_MODULE,
  105099. + },
  105100. +};
  105101. +
  105102. +module_platform_driver(pcm1794a_codec_driver);
  105103. +
  105104. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  105105. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  105106. +MODULE_LICENSE("GPL v2");
  105107. diff -Nur linux-3.12.18/sound/soc/codecs/pcm5102a.c linux-rpi/sound/soc/codecs/pcm5102a.c
  105108. --- linux-3.12.18/sound/soc/codecs/pcm5102a.c 1970-01-01 01:00:00.000000000 +0100
  105109. +++ linux-rpi/sound/soc/codecs/pcm5102a.c 2014-04-24 15:35:05.493580478 +0200
  105110. @@ -0,0 +1,63 @@
  105111. +/*
  105112. + * Driver for the PCM5102A codec
  105113. + *
  105114. + * Author: Florian Meier <florian.meier@koalo.de>
  105115. + * Copyright 2013
  105116. + *
  105117. + * This program is free software; you can redistribute it and/or
  105118. + * modify it under the terms of the GNU General Public License
  105119. + * version 2 as published by the Free Software Foundation.
  105120. + *
  105121. + * This program is distributed in the hope that it will be useful, but
  105122. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  105123. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  105124. + * General Public License for more details.
  105125. + */
  105126. +
  105127. +
  105128. +#include <linux/init.h>
  105129. +#include <linux/module.h>
  105130. +#include <linux/platform_device.h>
  105131. +
  105132. +#include <sound/soc.h>
  105133. +
  105134. +static struct snd_soc_dai_driver pcm5102a_dai = {
  105135. + .name = "pcm5102a-hifi",
  105136. + .playback = {
  105137. + .channels_min = 2,
  105138. + .channels_max = 2,
  105139. + .rates = SNDRV_PCM_RATE_8000_192000,
  105140. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  105141. + // SNDRV_PCM_FMTBIT_S24_LE | : disable for now, it causes white noise with xbmc
  105142. + SNDRV_PCM_FMTBIT_S32_LE
  105143. + },
  105144. +};
  105145. +
  105146. +static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
  105147. +
  105148. +static int pcm5102a_probe(struct platform_device *pdev)
  105149. +{
  105150. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
  105151. + &pcm5102a_dai, 1);
  105152. +}
  105153. +
  105154. +static int pcm5102a_remove(struct platform_device *pdev)
  105155. +{
  105156. + snd_soc_unregister_codec(&pdev->dev);
  105157. + return 0;
  105158. +}
  105159. +
  105160. +static struct platform_driver pcm5102a_codec_driver = {
  105161. + .probe = pcm5102a_probe,
  105162. + .remove = pcm5102a_remove,
  105163. + .driver = {
  105164. + .name = "pcm5102a-codec",
  105165. + .owner = THIS_MODULE,
  105166. + },
  105167. +};
  105168. +
  105169. +module_platform_driver(pcm5102a_codec_driver);
  105170. +
  105171. +MODULE_DESCRIPTION("ASoC PCM5102A codec driver");
  105172. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  105173. +MODULE_LICENSE("GPL v2");
  105174. diff -Nur linux-3.12.18/sound/soc/codecs/pcm512x.c linux-rpi/sound/soc/codecs/pcm512x.c
  105175. --- linux-3.12.18/sound/soc/codecs/pcm512x.c 1970-01-01 01:00:00.000000000 +0100
  105176. +++ linux-rpi/sound/soc/codecs/pcm512x.c 2014-04-24 16:04:43.375158625 +0200
  105177. @@ -0,0 +1,678 @@
  105178. +/*
  105179. + * Driver for the PCM512x CODECs
  105180. + *
  105181. + * Author: Mark Brown <broonie@linaro.org>
  105182. + * Copyright 2014 Linaro Ltd
  105183. + *
  105184. + * This program is free software; you can redistribute it and/or
  105185. + * modify it under the terms of the GNU General Public License
  105186. + * version 2 as published by the Free Software Foundation.
  105187. + *
  105188. + * This program is distributed in the hope that it will be useful, but
  105189. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  105190. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  105191. + * General Public License for more details.
  105192. + */
  105193. +
  105194. +
  105195. +#include <linux/init.h>
  105196. +#include <linux/module.h>
  105197. +#include <linux/clk.h>
  105198. +#include <linux/i2c.h>
  105199. +#include <linux/pm_runtime.h>
  105200. +#include <linux/regmap.h>
  105201. +#include <linux/regulator/consumer.h>
  105202. +#include <linux/spi/spi.h>
  105203. +#include <sound/soc.h>
  105204. +#include <sound/soc-dapm.h>
  105205. +#include <sound/tlv.h>
  105206. +
  105207. +#include "pcm512x.h"
  105208. +
  105209. +#define PCM512x_NUM_SUPPLIES 3
  105210. +static const char *pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {
  105211. + "AVDD",
  105212. + "DVDD",
  105213. + "CPVDD",
  105214. +};
  105215. +
  105216. +struct pcm512x_priv {
  105217. + struct regmap *regmap;
  105218. + struct clk *sclk;
  105219. + struct regulator_bulk_data supplies[PCM512x_NUM_SUPPLIES];
  105220. + struct notifier_block supply_nb[PCM512x_NUM_SUPPLIES];
  105221. +};
  105222. +
  105223. +/*
  105224. + * We can't use the same notifier block for more than one supply and
  105225. + * there's no way I can see to get from a callback to the caller
  105226. + * except container_of().
  105227. + */
  105228. +#define PCM512x_REGULATOR_EVENT(n) \
  105229. +static int pcm512x_regulator_event_##n(struct notifier_block *nb, \
  105230. + unsigned long event, void *data) \
  105231. +{ \
  105232. + struct pcm512x_priv *pcm512x = container_of(nb, struct pcm512x_priv, \
  105233. + supply_nb[n]); \
  105234. + if (event & REGULATOR_EVENT_DISABLE) { \
  105235. + regcache_mark_dirty(pcm512x->regmap); \
  105236. + regcache_cache_only(pcm512x->regmap, true); \
  105237. + } \
  105238. + return 0; \
  105239. +}
  105240. +
  105241. +PCM512x_REGULATOR_EVENT(0)
  105242. +PCM512x_REGULATOR_EVENT(1)
  105243. +PCM512x_REGULATOR_EVENT(2)
  105244. +
  105245. +static const struct reg_default pcm512x_reg_defaults[] = {
  105246. + { PCM512x_RESET, 0x00 },
  105247. + { PCM512x_POWER, 0x00 },
  105248. + { PCM512x_MUTE, 0x00 },
  105249. + { PCM512x_DSP, 0x00 },
  105250. + { PCM512x_PLL_REF, 0x00 },
  105251. + { PCM512x_DAC_ROUTING, 0x11 },
  105252. + { PCM512x_DSP_PROGRAM, 0x01 },
  105253. + { PCM512x_CLKDET, 0x00 },
  105254. + { PCM512x_AUTO_MUTE, 0x00 },
  105255. + { PCM512x_ERROR_DETECT, 0x00 },
  105256. + { PCM512x_DIGITAL_VOLUME_1, 0x00 },
  105257. + { PCM512x_DIGITAL_VOLUME_2, 0x30 },
  105258. + { PCM512x_DIGITAL_VOLUME_3, 0x30 },
  105259. + { PCM512x_DIGITAL_MUTE_1, 0x22 },
  105260. + { PCM512x_DIGITAL_MUTE_2, 0x00 },
  105261. + { PCM512x_DIGITAL_MUTE_3, 0x07 },
  105262. +};
  105263. +
  105264. +static bool pcm512x_readable(struct device *dev, unsigned int reg)
  105265. +{
  105266. + switch (reg) {
  105267. + case PCM512x_RESET:
  105268. + case PCM512x_POWER:
  105269. + case PCM512x_MUTE:
  105270. + case PCM512x_PLL_EN:
  105271. + case PCM512x_SPI_MISO_FUNCTION:
  105272. + case PCM512x_DSP:
  105273. + case PCM512x_GPIO_EN:
  105274. + case PCM512x_BCLK_LRCLK_CFG:
  105275. + case PCM512x_DSP_GPIO_INPUT:
  105276. + case PCM512x_MASTER_MODE:
  105277. + case PCM512x_PLL_REF:
  105278. + case PCM512x_PLL_COEFF_0:
  105279. + case PCM512x_PLL_COEFF_1:
  105280. + case PCM512x_PLL_COEFF_2:
  105281. + case PCM512x_PLL_COEFF_3:
  105282. + case PCM512x_PLL_COEFF_4:
  105283. + case PCM512x_DSP_CLKDIV:
  105284. + case PCM512x_DAC_CLKDIV:
  105285. + case PCM512x_NCP_CLKDIV:
  105286. + case PCM512x_OSR_CLKDIV:
  105287. + case PCM512x_MASTER_CLKDIV_1:
  105288. + case PCM512x_MASTER_CLKDIV_2:
  105289. + case PCM512x_FS_SPEED_MODE:
  105290. + case PCM512x_IDAC_1:
  105291. + case PCM512x_IDAC_2:
  105292. + case PCM512x_ERROR_DETECT:
  105293. + case PCM512x_I2S_1:
  105294. + case PCM512x_I2S_2:
  105295. + case PCM512x_DAC_ROUTING:
  105296. + case PCM512x_DSP_PROGRAM:
  105297. + case PCM512x_CLKDET:
  105298. + case PCM512x_AUTO_MUTE:
  105299. + case PCM512x_DIGITAL_VOLUME_1:
  105300. + case PCM512x_DIGITAL_VOLUME_2:
  105301. + case PCM512x_DIGITAL_VOLUME_3:
  105302. + case PCM512x_DIGITAL_MUTE_1:
  105303. + case PCM512x_DIGITAL_MUTE_2:
  105304. + case PCM512x_DIGITAL_MUTE_3:
  105305. + case PCM512x_GPIO_OUTPUT_1:
  105306. + case PCM512x_GPIO_OUTPUT_2:
  105307. + case PCM512x_GPIO_OUTPUT_3:
  105308. + case PCM512x_GPIO_OUTPUT_4:
  105309. + case PCM512x_GPIO_OUTPUT_5:
  105310. + case PCM512x_GPIO_OUTPUT_6:
  105311. + case PCM512x_GPIO_CONTROL_1:
  105312. + case PCM512x_GPIO_CONTROL_2:
  105313. + case PCM512x_OVERFLOW:
  105314. + case PCM512x_RATE_DET_1:
  105315. + case PCM512x_RATE_DET_2:
  105316. + case PCM512x_RATE_DET_3:
  105317. + case PCM512x_RATE_DET_4:
  105318. + case PCM512x_ANALOG_MUTE_DET:
  105319. + case PCM512x_GPIN:
  105320. + case PCM512x_DIGITAL_MUTE_DET:
  105321. + return true;
  105322. + default:
  105323. + return false;
  105324. + }
  105325. +}
  105326. +
  105327. +static bool pcm512x_volatile(struct device *dev, unsigned int reg)
  105328. +{
  105329. + switch (reg) {
  105330. + case PCM512x_PLL_EN:
  105331. + case PCM512x_OVERFLOW:
  105332. + case PCM512x_RATE_DET_1:
  105333. + case PCM512x_RATE_DET_2:
  105334. + case PCM512x_RATE_DET_3:
  105335. + case PCM512x_RATE_DET_4:
  105336. + case PCM512x_ANALOG_MUTE_DET:
  105337. + case PCM512x_GPIN:
  105338. + case PCM512x_DIGITAL_MUTE_DET:
  105339. + return true;
  105340. + default:
  105341. + return false;
  105342. + }
  105343. +}
  105344. +
  105345. +static const DECLARE_TLV_DB_SCALE(digital_tlv, -10350, 50, 1);
  105346. +
  105347. +static const char *pcm512x_dsp_program_texts[] = {
  105348. + "FIR interpolation with de-emphasis",
  105349. + "Low latency IIR with de-emphasis",
  105350. + "High attenuation with de-emphasis",
  105351. + "Ringing-less low latency FIR",
  105352. +};
  105353. +
  105354. +static const unsigned int pcm512x_dsp_program_values[] = {
  105355. + 1,
  105356. + 2,
  105357. + 3,
  105358. + 5,
  105359. + 7,
  105360. +};
  105361. +
  105362. +static const SOC_VALUE_ENUM_SINGLE_DECL(pcm512x_dsp_program,
  105363. + PCM512x_DSP_PROGRAM, 0, 0x1f,
  105364. + pcm512x_dsp_program_texts,
  105365. + pcm512x_dsp_program_values);
  105366. +
  105367. +static const char *pcm512x_clk_missing_text[] = {
  105368. + "1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s"
  105369. +};
  105370. +
  105371. +static const struct soc_enum pcm512x_clk_missing =
  105372. + SOC_ENUM_SINGLE(PCM512x_CLKDET, 0, 7, pcm512x_clk_missing_text);
  105373. +
  105374. +static const char *pcm512x_autom_text[] = {
  105375. + "21ms", "106ms", "213ms", "533ms", "1.07s", "2.13s", "5.33s", "10.66s"
  105376. +};
  105377. +
  105378. +static const struct soc_enum pcm512x_autom_l =
  105379. + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATML_SHIFT, 7,
  105380. + pcm512x_autom_text);
  105381. +
  105382. +static const struct soc_enum pcm512x_autom_r =
  105383. + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATMR_SHIFT, 7,
  105384. + pcm512x_autom_text);
  105385. +
  105386. +static const char *pcm512x_ramp_rate_text[] = {
  105387. + "1 sample/update", "2 samples/update", "4 samples/update",
  105388. + "Immediate"
  105389. +};
  105390. +
  105391. +static const struct soc_enum pcm512x_vndf =
  105392. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNDF_SHIFT, 4,
  105393. + pcm512x_ramp_rate_text);
  105394. +
  105395. +static const struct soc_enum pcm512x_vnuf =
  105396. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNUF_SHIFT, 4,
  105397. + pcm512x_ramp_rate_text);
  105398. +
  105399. +static const struct soc_enum pcm512x_vedf =
  105400. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDF_SHIFT, 4,
  105401. + pcm512x_ramp_rate_text);
  105402. +
  105403. +static const char *pcm512x_ramp_step_text[] = {
  105404. + "4dB/step", "2dB/step", "1dB/step", "0.5dB/step"
  105405. +};
  105406. +
  105407. +static const struct soc_enum pcm512x_vnds =
  105408. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNDS_SHIFT, 4,
  105409. + pcm512x_ramp_step_text);
  105410. +
  105411. +static const struct soc_enum pcm512x_vnus =
  105412. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNUS_SHIFT, 4,
  105413. + pcm512x_ramp_step_text);
  105414. +
  105415. +static const struct soc_enum pcm512x_veds =
  105416. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDS_SHIFT, 4,
  105417. + pcm512x_ramp_step_text);
  105418. +
  105419. +/* Don't let the DAC go into clipping by limiting the alsa volume control range */
  105420. +static const struct snd_kcontrol_new pcm512x_controls[] = {
  105421. +SOC_DOUBLE_R_RANGE_TLV("Playback Digital Volume", PCM512x_DIGITAL_VOLUME_2,
  105422. + PCM512x_DIGITAL_VOLUME_3, 0, 40, 255, 1, digital_tlv),
  105423. +SOC_DOUBLE("Playback Digital Switch", PCM512x_MUTE, PCM512x_RQML_SHIFT,
  105424. + PCM512x_RQMR_SHIFT, 1, 1),
  105425. +
  105426. +SOC_SINGLE("Deemphasis Switch", PCM512x_DSP, PCM512x_DEMP_SHIFT, 1, 1),
  105427. +SOC_VALUE_ENUM("DSP Program", pcm512x_dsp_program),
  105428. +
  105429. +SOC_ENUM("Clock Missing Period", pcm512x_clk_missing),
  105430. +SOC_ENUM("Auto Mute Time Left", pcm512x_autom_l),
  105431. +SOC_ENUM("Auto Mute Time Right", pcm512x_autom_r),
  105432. +SOC_SINGLE("Auto Mute Mono Switch", PCM512x_DIGITAL_MUTE_3,
  105433. + PCM512x_ACTL_SHIFT, 1, 0),
  105434. +SOC_DOUBLE("Auto Mute Switch", PCM512x_DIGITAL_MUTE_3, PCM512x_AMLE_SHIFT,
  105435. + PCM512x_AMLR_SHIFT, 1, 0),
  105436. +
  105437. +SOC_ENUM("Volume Ramp Down Rate", pcm512x_vndf),
  105438. +SOC_ENUM("Volume Ramp Down Step", pcm512x_vnds),
  105439. +SOC_ENUM("Volume Ramp Up Rate", pcm512x_vnuf),
  105440. +SOC_ENUM("Volume Ramp Up Step", pcm512x_vnus),
  105441. +SOC_ENUM("Volume Ramp Down Emergency Rate", pcm512x_vedf),
  105442. +SOC_ENUM("Volume Ramp Down Emergency Step", pcm512x_veds),
  105443. +};
  105444. +
  105445. +static const struct snd_soc_dapm_widget pcm512x_dapm_widgets[] = {
  105446. +SND_SOC_DAPM_DAC("DACL", NULL, SND_SOC_NOPM, 0, 0),
  105447. +SND_SOC_DAPM_DAC("DACR", NULL, SND_SOC_NOPM, 0, 0),
  105448. +
  105449. +SND_SOC_DAPM_OUTPUT("OUTL"),
  105450. +SND_SOC_DAPM_OUTPUT("OUTR"),
  105451. +};
  105452. +
  105453. +static const struct snd_soc_dapm_route pcm512x_dapm_routes[] = {
  105454. + { "DACL", NULL, "Playback" },
  105455. + { "DACR", NULL, "Playback" },
  105456. +
  105457. + { "OUTL", NULL, "DACL" },
  105458. + { "OUTR", NULL, "DACR" },
  105459. +};
  105460. +
  105461. +static int pcm512x_set_bias_level(struct snd_soc_codec *codec,
  105462. + enum snd_soc_bias_level level)
  105463. +{
  105464. + struct pcm512x_priv *pcm512x = dev_get_drvdata(codec->dev);
  105465. + int ret;
  105466. +
  105467. + switch (level) {
  105468. + case SND_SOC_BIAS_ON:
  105469. + case SND_SOC_BIAS_PREPARE:
  105470. + break;
  105471. +
  105472. + case SND_SOC_BIAS_STANDBY:
  105473. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  105474. + PCM512x_RQST, 0);
  105475. + if (ret != 0) {
  105476. + dev_err(codec->dev, "Failed to remove standby: %d\n",
  105477. + ret);
  105478. + return ret;
  105479. + }
  105480. + break;
  105481. +
  105482. + case SND_SOC_BIAS_OFF:
  105483. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  105484. + PCM512x_RQST, PCM512x_RQST);
  105485. + if (ret != 0) {
  105486. + dev_err(codec->dev, "Failed to request standby: %d\n",
  105487. + ret);
  105488. + return ret;
  105489. + }
  105490. + break;
  105491. + }
  105492. +
  105493. + codec->dapm.bias_level = level;
  105494. +
  105495. + return 0;
  105496. +}
  105497. +
  105498. +static struct snd_soc_dai_driver pcm512x_dai = {
  105499. + .name = "pcm512x-hifi",
  105500. + .playback = {
  105501. + .stream_name = "Playback",
  105502. + .channels_min = 2,
  105503. + .channels_max = 2,
  105504. + .rates = SNDRV_PCM_RATE_8000_192000,
  105505. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  105506. + SNDRV_PCM_FMTBIT_S24_LE |
  105507. + SNDRV_PCM_FMTBIT_S32_LE
  105508. + },
  105509. +};
  105510. +
  105511. +static struct snd_soc_codec_driver pcm512x_codec_driver = {
  105512. + .set_bias_level = pcm512x_set_bias_level,
  105513. + .idle_bias_off = true,
  105514. +
  105515. + .controls = pcm512x_controls,
  105516. + .num_controls = ARRAY_SIZE(pcm512x_controls),
  105517. + .dapm_widgets = pcm512x_dapm_widgets,
  105518. + .num_dapm_widgets = ARRAY_SIZE(pcm512x_dapm_widgets),
  105519. + .dapm_routes = pcm512x_dapm_routes,
  105520. + .num_dapm_routes = ARRAY_SIZE(pcm512x_dapm_routes),
  105521. +};
  105522. +
  105523. +static const struct regmap_config pcm512x_regmap = {
  105524. + .reg_bits = 8,
  105525. + .val_bits = 8,
  105526. +
  105527. + .readable_reg = pcm512x_readable,
  105528. + .volatile_reg = pcm512x_volatile,
  105529. +
  105530. + .max_register = PCM512x_MAX_REGISTER,
  105531. + .reg_defaults = pcm512x_reg_defaults,
  105532. + .num_reg_defaults = ARRAY_SIZE(pcm512x_reg_defaults),
  105533. + .cache_type = REGCACHE_RBTREE,
  105534. +};
  105535. +
  105536. +static const struct of_device_id pcm512x_of_match[] = {
  105537. + { .compatible = "ti,pcm5121", },
  105538. + { .compatible = "ti,pcm5122", },
  105539. + { }
  105540. +};
  105541. +MODULE_DEVICE_TABLE(of, pcm512x_of_match);
  105542. +
  105543. +static int pcm512x_probe(struct device *dev, struct regmap *regmap)
  105544. +{
  105545. + struct pcm512x_priv *pcm512x;
  105546. + int i, ret;
  105547. +
  105548. + pcm512x = devm_kzalloc(dev, sizeof(struct pcm512x_priv), GFP_KERNEL);
  105549. + if (!pcm512x)
  105550. + return -ENOMEM;
  105551. +
  105552. + dev_set_drvdata(dev, pcm512x);
  105553. + pcm512x->regmap = regmap;
  105554. +
  105555. + for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++)
  105556. + pcm512x->supplies[i].supply = pcm512x_supply_names[i];
  105557. +
  105558. + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pcm512x->supplies),
  105559. + pcm512x->supplies);
  105560. + if (ret != 0) {
  105561. + dev_err(dev, "Failed to get supplies: %d\n", ret);
  105562. + return ret;
  105563. + }
  105564. +
  105565. + pcm512x->supply_nb[0].notifier_call = pcm512x_regulator_event_0;
  105566. + pcm512x->supply_nb[1].notifier_call = pcm512x_regulator_event_1;
  105567. + pcm512x->supply_nb[2].notifier_call = pcm512x_regulator_event_2;
  105568. +
  105569. + for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++) {
  105570. + ret = regulator_register_notifier(pcm512x->supplies[i].consumer,
  105571. + &pcm512x->supply_nb[i]);
  105572. + if (ret != 0) {
  105573. + dev_err(dev,
  105574. + "Failed to register regulator notifier: %d\n",
  105575. + ret);
  105576. + }
  105577. + }
  105578. +
  105579. + ret = regulator_bulk_enable(ARRAY_SIZE(pcm512x->supplies),
  105580. + pcm512x->supplies);
  105581. + if (ret != 0) {
  105582. + dev_err(dev, "Failed to enable supplies: %d\n", ret);
  105583. + return ret;
  105584. + }
  105585. +
  105586. + /* Reset the device, verifying I/O in the process for I2C */
  105587. + ret = regmap_write(regmap, PCM512x_RESET,
  105588. + PCM512x_RSTM | PCM512x_RSTR);
  105589. + if (ret != 0) {
  105590. + dev_err(dev, "Failed to reset device: %d\n", ret);
  105591. + goto err;
  105592. + }
  105593. +
  105594. + ret = regmap_write(regmap, PCM512x_RESET, 0);
  105595. + if (ret != 0) {
  105596. + dev_err(dev, "Failed to reset device: %d\n", ret);
  105597. + goto err;
  105598. + }
  105599. +
  105600. + pcm512x->sclk = devm_clk_get(dev, NULL);
  105601. + if (IS_ERR(pcm512x->sclk)) {
  105602. + if (PTR_ERR(pcm512x->sclk) == -EPROBE_DEFER)
  105603. + return -EPROBE_DEFER;
  105604. +
  105605. + dev_info(dev, "No SCLK, using BCLK: %ld\n",
  105606. + PTR_ERR(pcm512x->sclk));
  105607. +
  105608. + /* Disable reporting of missing SCLK as an error */
  105609. + regmap_update_bits(regmap, PCM512x_ERROR_DETECT,
  105610. + PCM512x_IDCH, PCM512x_IDCH);
  105611. +
  105612. + /* Switch PLL input to BCLK */
  105613. + regmap_update_bits(regmap, PCM512x_PLL_REF,
  105614. + PCM512x_SREF, PCM512x_SREF);
  105615. + } else {
  105616. + ret = clk_prepare_enable(pcm512x->sclk);
  105617. + if (ret != 0) {
  105618. + dev_err(dev, "Failed to enable SCLK: %d\n", ret);
  105619. + return ret;
  105620. + }
  105621. + }
  105622. +
  105623. + /* Default to standby mode */
  105624. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  105625. + PCM512x_RQST, PCM512x_RQST);
  105626. + if (ret != 0) {
  105627. + dev_err(dev, "Failed to request standby: %d\n",
  105628. + ret);
  105629. + goto err_clk;
  105630. + }
  105631. +
  105632. + pm_runtime_set_active(dev);
  105633. + pm_runtime_enable(dev);
  105634. + pm_runtime_idle(dev);
  105635. +
  105636. + ret = snd_soc_register_codec(dev, &pcm512x_codec_driver,
  105637. + &pcm512x_dai, 1);
  105638. + if (ret != 0) {
  105639. + dev_err(dev, "Failed to register CODEC: %d\n", ret);
  105640. + goto err_pm;
  105641. + }
  105642. +
  105643. + dev_info(dev, "Completed initialisation - pcm512x_probe");
  105644. +
  105645. + return 0;
  105646. +
  105647. +err_pm:
  105648. + pm_runtime_disable(dev);
  105649. +err_clk:
  105650. + if (!IS_ERR(pcm512x->sclk))
  105651. + clk_disable_unprepare(pcm512x->sclk);
  105652. +err:
  105653. + regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  105654. + pcm512x->supplies);
  105655. + return ret;
  105656. +}
  105657. +
  105658. +static void pcm512x_remove(struct device *dev)
  105659. +{
  105660. + struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  105661. +
  105662. + snd_soc_unregister_codec(dev);
  105663. + pm_runtime_disable(dev);
  105664. + if (!IS_ERR(pcm512x->sclk))
  105665. + clk_disable_unprepare(pcm512x->sclk);
  105666. + regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  105667. + pcm512x->supplies);
  105668. +}
  105669. +
  105670. +/* TODO
  105671. +static int pcm512x_suspend(struct device *dev)
  105672. +{
  105673. + struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  105674. + int ret;
  105675. +
  105676. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  105677. + PCM512x_RQPD, PCM512x_RQPD);
  105678. + if (ret != 0) {
  105679. + dev_err(dev, "Failed to request power down: %d\n", ret);
  105680. + return ret;
  105681. + }
  105682. +
  105683. + ret = regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  105684. + pcm512x->supplies);
  105685. + if (ret != 0) {
  105686. + dev_err(dev, "Failed to disable supplies: %d\n", ret);
  105687. + return ret;
  105688. + }
  105689. +
  105690. + if (!IS_ERR(pcm512x->sclk))
  105691. + clk_disable_unprepare(pcm512x->sclk);
  105692. +
  105693. + return 0;
  105694. +}
  105695. +
  105696. +static int pcm512x_resume(struct device *dev)
  105697. +{
  105698. + struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  105699. + int ret;
  105700. +
  105701. + if (!IS_ERR(pcm512x->sclk)) {
  105702. + ret = clk_prepare_enable(pcm512x->sclk);
  105703. + if (ret != 0) {
  105704. + dev_err(dev, "Failed to enable SCLK: %d\n", ret);
  105705. + return ret;
  105706. + }
  105707. + }
  105708. +
  105709. + ret = regulator_bulk_enable(ARRAY_SIZE(pcm512x->supplies),
  105710. + pcm512x->supplies);
  105711. + if (ret != 0) {
  105712. + dev_err(dev, "Failed to enable supplies: %d\n", ret);
  105713. + return ret;
  105714. + }
  105715. +
  105716. + regcache_cache_only(pcm512x->regmap, false);
  105717. + ret = regcache_sync(pcm512x->regmap);
  105718. + if (ret != 0) {
  105719. + dev_err(dev, "Failed to sync cache: %d\n", ret);
  105720. + return ret;
  105721. + }
  105722. +
  105723. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  105724. + PCM512x_RQPD, 0);
  105725. + if (ret != 0) {
  105726. + dev_err(dev, "Failed to remove power down: %d\n", ret);
  105727. + return ret;
  105728. + }
  105729. +
  105730. + return 0;
  105731. +}
  105732. +
  105733. +// END OF PCM512x_suspend and resume calls TODO
  105734. +*/
  105735. +
  105736. +static const struct dev_pm_ops pcm512x_pm_ops = {
  105737. + SET_RUNTIME_PM_OPS(pcm512x_suspend, pcm512x_resume, NULL)
  105738. +};
  105739. +
  105740. +#if IS_ENABLED(CONFIG_I2C)
  105741. +static int pcm512x_i2c_probe(struct i2c_client *i2c,
  105742. + const struct i2c_device_id *id)
  105743. +{
  105744. + struct regmap *regmap;
  105745. +
  105746. + regmap = devm_regmap_init_i2c(i2c, &pcm512x_regmap);
  105747. + if (IS_ERR(regmap))
  105748. + return PTR_ERR(regmap);
  105749. +
  105750. + return pcm512x_probe(&i2c->dev, regmap);
  105751. +}
  105752. +
  105753. +static int pcm512x_i2c_remove(struct i2c_client *i2c)
  105754. +{
  105755. + pcm512x_remove(&i2c->dev);
  105756. + return 0;
  105757. +}
  105758. +
  105759. +static const struct i2c_device_id pcm512x_i2c_id[] = {
  105760. + { "pcm5121", },
  105761. + { "pcm5122", },
  105762. + { }
  105763. +};
  105764. +MODULE_DEVICE_TABLE(i2c, pcm512x_i2c_id);
  105765. +
  105766. +static struct i2c_driver pcm512x_i2c_driver = {
  105767. + .probe = pcm512x_i2c_probe,
  105768. + .remove = pcm512x_i2c_remove,
  105769. + .id_table = pcm512x_i2c_id,
  105770. + .driver = {
  105771. + .name = "pcm512x",
  105772. + .owner = THIS_MODULE,
  105773. + .of_match_table = pcm512x_of_match,
  105774. + .pm = &pcm512x_pm_ops,
  105775. + },
  105776. +};
  105777. +#endif
  105778. +
  105779. +#if defined(CONFIG_SPI_MASTER)
  105780. +static int pcm512x_spi_probe(struct spi_device *spi)
  105781. +{
  105782. + struct regmap *regmap;
  105783. + int ret;
  105784. +
  105785. + regmap = devm_regmap_init_spi(spi, &pcm512x_regmap);
  105786. + if (IS_ERR(regmap)) {
  105787. + ret = PTR_ERR(regmap);
  105788. + return ret;
  105789. + }
  105790. +
  105791. + return pcm512x_probe(&spi->dev, regmap);
  105792. +}
  105793. +
  105794. +static int pcm512x_spi_remove(struct spi_device *spi)
  105795. +{
  105796. + pcm512x_remove(&spi->dev);
  105797. + return 0;
  105798. +}
  105799. +
  105800. +static const struct spi_device_id pcm512x_spi_id[] = {
  105801. + { "pcm5121", },
  105802. + { "pcm5122", },
  105803. + { },
  105804. +};
  105805. +MODULE_DEVICE_TABLE(spi, pcm512x_spi_id);
  105806. +
  105807. +static struct spi_driver pcm512x_spi_driver = {
  105808. + .probe = pcm512x_spi_probe,
  105809. + .remove = pcm512x_spi_remove,
  105810. + .id_table = pcm512x_spi_id,
  105811. + .driver = {
  105812. + .name = "pcm512x",
  105813. + .owner = THIS_MODULE,
  105814. + .of_match_table = pcm512x_of_match,
  105815. + .pm = &pcm512x_pm_ops,
  105816. + },
  105817. +};
  105818. +#endif
  105819. +
  105820. +static int __init pcm512x_modinit(void)
  105821. +{
  105822. + int ret = 0;
  105823. +
  105824. +#if IS_ENABLED(CONFIG_I2C)
  105825. + ret = i2c_add_driver(&pcm512x_i2c_driver);
  105826. + if (ret) {
  105827. + printk(KERN_ERR "Failed to register pcm512x I2C driver: %d\n",
  105828. + ret);
  105829. + }
  105830. +#endif
  105831. +#if defined(CONFIG_SPI_MASTER)
  105832. + ret = spi_register_driver(&pcm512x_spi_driver);
  105833. + if (ret != 0) {
  105834. + printk(KERN_ERR "Failed to register pcm512x SPI driver: %d\n",
  105835. + ret);
  105836. + }
  105837. +#endif
  105838. + return ret;
  105839. +}
  105840. +module_init(pcm512x_modinit);
  105841. +
  105842. +static void __exit pcm512x_exit(void)
  105843. +{
  105844. +#if IS_ENABLED(CONFIG_I2C)
  105845. + i2c_del_driver(&pcm512x_i2c_driver);
  105846. +#endif
  105847. +#if defined(CONFIG_SPI_MASTER)
  105848. + spi_unregister_driver(&pcm512x_spi_driver);
  105849. +#endif
  105850. +}
  105851. +module_exit(pcm512x_exit);
  105852. +
  105853. +MODULE_DESCRIPTION("ASoC PCM512x codec driver");
  105854. +MODULE_AUTHOR("Mark Brown <broonie@linaro.org>");
  105855. +MODULE_LICENSE("GPL v2");
  105856. diff -Nur linux-3.12.18/sound/soc/codecs/pcm512x.h linux-rpi/sound/soc/codecs/pcm512x.h
  105857. --- linux-3.12.18/sound/soc/codecs/pcm512x.h 1970-01-01 01:00:00.000000000 +0100
  105858. +++ linux-rpi/sound/soc/codecs/pcm512x.h 2014-04-24 15:35:05.493580478 +0200
  105859. @@ -0,0 +1,142 @@
  105860. +/*
  105861. + * Driver for the PCM512x CODECs
  105862. + *
  105863. + * Author: Mark Brown <broonie@linaro.org>
  105864. + * Copyright 2014 Linaro Ltd
  105865. + *
  105866. + * This program is free software; you can redistribute it and/or
  105867. + * modify it under the terms of the GNU General Public License
  105868. + * version 2 as published by the Free Software Foundation.
  105869. + *
  105870. + * This program is distributed in the hope that it will be useful, but
  105871. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  105872. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  105873. + * General Public License for more details.
  105874. + */
  105875. +
  105876. +#ifndef _SND_SOC_PCM512X
  105877. +#define _SND_SOC_PCM512X
  105878. +
  105879. +#define PCM512x_PAGE_0_BASE 0
  105880. +
  105881. +#define PCM512x_PAGE 0
  105882. +
  105883. +#define PCM512x_RESET (PCM512x_PAGE_0_BASE + 1)
  105884. +#define PCM512x_POWER (PCM512x_PAGE_0_BASE + 2)
  105885. +#define PCM512x_MUTE (PCM512x_PAGE_0_BASE + 3)
  105886. +#define PCM512x_PLL_EN (PCM512x_PAGE_0_BASE + 4)
  105887. +#define PCM512x_SPI_MISO_FUNCTION (PCM512x_PAGE_0_BASE + 6)
  105888. +#define PCM512x_DSP (PCM512x_PAGE_0_BASE + 7)
  105889. +#define PCM512x_GPIO_EN (PCM512x_PAGE_0_BASE + 8)
  105890. +#define PCM512x_BCLK_LRCLK_CFG (PCM512x_PAGE_0_BASE + 9)
  105891. +#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_0_BASE + 10)
  105892. +#define PCM512x_MASTER_MODE (PCM512x_PAGE_0_BASE + 12)
  105893. +#define PCM512x_PLL_REF (PCM512x_PAGE_0_BASE + 13)
  105894. +#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_0_BASE + 20)
  105895. +#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_0_BASE + 21)
  105896. +#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_0_BASE + 22)
  105897. +#define PCM512x_PLL_COEFF_3 (PCM512x_PAGE_0_BASE + 23)
  105898. +#define PCM512x_PLL_COEFF_4 (PCM512x_PAGE_0_BASE + 24)
  105899. +#define PCM512x_DSP_CLKDIV (PCM512x_PAGE_0_BASE + 27)
  105900. +#define PCM512x_DAC_CLKDIV (PCM512x_PAGE_0_BASE + 28)
  105901. +#define PCM512x_NCP_CLKDIV (PCM512x_PAGE_0_BASE + 29)
  105902. +#define PCM512x_OSR_CLKDIV (PCM512x_PAGE_0_BASE + 30)
  105903. +#define PCM512x_MASTER_CLKDIV_1 (PCM512x_PAGE_0_BASE + 32)
  105904. +#define PCM512x_MASTER_CLKDIV_2 (PCM512x_PAGE_0_BASE + 33)
  105905. +#define PCM512x_FS_SPEED_MODE (PCM512x_PAGE_0_BASE + 34)
  105906. +#define PCM512x_IDAC_1 (PCM512x_PAGE_0_BASE + 35)
  105907. +#define PCM512x_IDAC_2 (PCM512x_PAGE_0_BASE + 36)
  105908. +#define PCM512x_ERROR_DETECT (PCM512x_PAGE_0_BASE + 37)
  105909. +#define PCM512x_I2S_1 (PCM512x_PAGE_0_BASE + 40)
  105910. +#define PCM512x_I2S_2 (PCM512x_PAGE_0_BASE + 41)
  105911. +#define PCM512x_DAC_ROUTING (PCM512x_PAGE_0_BASE + 42)
  105912. +#define PCM512x_DSP_PROGRAM (PCM512x_PAGE_0_BASE + 43)
  105913. +#define PCM512x_CLKDET (PCM512x_PAGE_0_BASE + 44)
  105914. +#define PCM512x_AUTO_MUTE (PCM512x_PAGE_0_BASE + 59)
  105915. +#define PCM512x_DIGITAL_VOLUME_1 (PCM512x_PAGE_0_BASE + 60)
  105916. +#define PCM512x_DIGITAL_VOLUME_2 (PCM512x_PAGE_0_BASE + 61)
  105917. +#define PCM512x_DIGITAL_VOLUME_3 (PCM512x_PAGE_0_BASE + 62)
  105918. +#define PCM512x_DIGITAL_MUTE_1 (PCM512x_PAGE_0_BASE + 63)
  105919. +#define PCM512x_DIGITAL_MUTE_2 (PCM512x_PAGE_0_BASE + 64)
  105920. +#define PCM512x_DIGITAL_MUTE_3 (PCM512x_PAGE_0_BASE + 65)
  105921. +#define PCM512x_GPIO_OUTPUT_1 (PCM512x_PAGE_0_BASE + 80)
  105922. +#define PCM512x_GPIO_OUTPUT_2 (PCM512x_PAGE_0_BASE + 81)
  105923. +#define PCM512x_GPIO_OUTPUT_3 (PCM512x_PAGE_0_BASE + 82)
  105924. +#define PCM512x_GPIO_OUTPUT_4 (PCM512x_PAGE_0_BASE + 83)
  105925. +#define PCM512x_GPIO_OUTPUT_5 (PCM512x_PAGE_0_BASE + 84)
  105926. +#define PCM512x_GPIO_OUTPUT_6 (PCM512x_PAGE_0_BASE + 85)
  105927. +#define PCM512x_GPIO_CONTROL_1 (PCM512x_PAGE_0_BASE + 86)
  105928. +#define PCM512x_GPIO_CONTROL_2 (PCM512x_PAGE_0_BASE + 87)
  105929. +#define PCM512x_OVERFLOW (PCM512x_PAGE_0_BASE + 90)
  105930. +#define PCM512x_RATE_DET_1 (PCM512x_PAGE_0_BASE + 91)
  105931. +#define PCM512x_RATE_DET_2 (PCM512x_PAGE_0_BASE + 92)
  105932. +#define PCM512x_RATE_DET_3 (PCM512x_PAGE_0_BASE + 93)
  105933. +#define PCM512x_RATE_DET_4 (PCM512x_PAGE_0_BASE + 94)
  105934. +#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_0_BASE + 108)
  105935. +#define PCM512x_GPIN (PCM512x_PAGE_0_BASE + 119)
  105936. +#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_0_BASE + 120)
  105937. +
  105938. +#define PCM512x_MAX_REGISTER (PCM512x_PAGE_0_BASE + 120)
  105939. +
  105940. +/* Page 0, Register 1 - reset */
  105941. +#define PCM512x_RSTR (1 << 0)
  105942. +#define PCM512x_RSTM (1 << 4)
  105943. +
  105944. +/* Page 0, Register 2 - power */
  105945. +#define PCM512x_RQPD (1 << 0)
  105946. +#define PCM512x_RQPD_SHIFT 0
  105947. +#define PCM512x_RQST (1 << 4)
  105948. +#define PCM512x_RQST_SHIFT 4
  105949. +
  105950. +/* Page 0, Register 3 - mute */
  105951. +#define PCM512x_RQMR_SHIFT 0
  105952. +#define PCM512x_RQML_SHIFT 4
  105953. +
  105954. +/* Page 0, Register 4 - PLL */
  105955. +#define PCM512x_PLCE (1 << 0)
  105956. +#define PCM512x_RLCE_SHIFT 0
  105957. +#define PCM512x_PLCK (1 << 4)
  105958. +#define PCM512x_PLCK_SHIFT 4
  105959. +
  105960. +/* Page 0, Register 7 - DSP */
  105961. +#define PCM512x_SDSL (1 << 0)
  105962. +#define PCM512x_SDSL_SHIFT 0
  105963. +#define PCM512x_DEMP (1 << 4)
  105964. +#define PCM512x_DEMP_SHIFT 4
  105965. +
  105966. +/* Page 0, Register 13 - PLL reference */
  105967. +#define PCM512x_SREF (1 << 4)
  105968. +
  105969. +/* Page 0, Register 37 - Error detection */
  105970. +#define PCM512x_IPLK (1 << 0)
  105971. +#define PCM512x_DCAS (1 << 1)
  105972. +#define PCM512x_IDCM (1 << 2)
  105973. +#define PCM512x_IDCH (1 << 3)
  105974. +#define PCM512x_IDSK (1 << 4)
  105975. +#define PCM512x_IDBK (1 << 5)
  105976. +#define PCM512x_IDFS (1 << 6)
  105977. +
  105978. +/* Page 0, Register 42 - DAC routing */
  105979. +#define PCM512x_AUPR_SHIFT 0
  105980. +#define PCM512x_AUPL_SHIFT 4
  105981. +
  105982. +/* Page 0, Register 59 - auto mute */
  105983. +#define PCM512x_ATMR_SHIFT 0
  105984. +#define PCM512x_ATML_SHIFT 4
  105985. +
  105986. +/* Page 0, Register 63 - ramp rates */
  105987. +#define PCM512x_VNDF_SHIFT 6
  105988. +#define PCM512x_VNDS_SHIFT 4
  105989. +#define PCM512x_VNUF_SHIFT 2
  105990. +#define PCM512x_VNUS_SHIFT 0
  105991. +
  105992. +/* Page 0, Register 64 - emergency ramp rates */
  105993. +#define PCM512x_VEDF_SHIFT 6
  105994. +#define PCM512x_VEDS_SHIFT 4
  105995. +
  105996. +/* Page 0, Register 65 - Digital mute enables */
  105997. +#define PCM512x_ACTL_SHIFT 2
  105998. +#define PCM512x_AMLE_SHIFT 1
  105999. +#define PCM512x_AMLR_SHIFT 0
  106000. +
  106001. +#endif
  106002. diff -Nur linux-3.12.18/sound/soc/codecs/wm8804.c linux-rpi/sound/soc/codecs/wm8804.c
  106003. --- linux-3.12.18/sound/soc/codecs/wm8804.c 2014-04-18 11:14:28.000000000 +0200
  106004. +++ linux-rpi/sound/soc/codecs/wm8804.c 2014-04-24 15:35:05.509580657 +0200
  106005. @@ -63,6 +63,7 @@
  106006. struct regmap *regmap;
  106007. struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES];
  106008. struct notifier_block disable_nb[WM8804_NUM_SUPPLIES];
  106009. + int mclk_div;
  106010. };
  106011. static int txsrc_get(struct snd_kcontrol *kcontrol,
  106012. @@ -277,6 +278,7 @@
  106013. blen = 0x1;
  106014. break;
  106015. case SNDRV_PCM_FORMAT_S24_LE:
  106016. + case SNDRV_PCM_FORMAT_S32_LE:
  106017. blen = 0x2;
  106018. break;
  106019. default:
  106020. @@ -318,7 +320,7 @@
  106021. #define FIXED_PLL_SIZE ((1ULL << 22) * 10)
  106022. static int pll_factors(struct pll_div *pll_div, unsigned int target,
  106023. - unsigned int source)
  106024. + unsigned int source, unsigned int mclk_div)
  106025. {
  106026. u64 Kpart;
  106027. unsigned long int K, Ndiv, Nmod, tmp;
  106028. @@ -330,7 +332,8 @@
  106029. */
  106030. for (i = 0; i < ARRAY_SIZE(post_table); i++) {
  106031. tmp = target * post_table[i].div;
  106032. - if (tmp >= 90000000 && tmp <= 100000000) {
  106033. + if ((tmp >= 90000000 && tmp <= 100000000) &&
  106034. + (mclk_div == post_table[i].mclkdiv)) {
  106035. pll_div->freqmode = post_table[i].freqmode;
  106036. pll_div->mclkdiv = post_table[i].mclkdiv;
  106037. target *= post_table[i].div;
  106038. @@ -387,8 +390,11 @@
  106039. } else {
  106040. int ret;
  106041. struct pll_div pll_div;
  106042. + struct wm8804_priv *wm8804;
  106043. - ret = pll_factors(&pll_div, freq_out, freq_in);
  106044. + wm8804 = snd_soc_codec_get_drvdata(codec);
  106045. +
  106046. + ret = pll_factors(&pll_div, freq_out, freq_in, wm8804->mclk_div);
  106047. if (ret)
  106048. return ret;
  106049. @@ -452,6 +458,7 @@
  106050. int div_id, int div)
  106051. {
  106052. struct snd_soc_codec *codec;
  106053. + struct wm8804_priv *wm8804;
  106054. codec = dai->codec;
  106055. switch (div_id) {
  106056. @@ -459,6 +466,10 @@
  106057. snd_soc_update_bits(codec, WM8804_PLL5, 0x30,
  106058. (div & 0x3) << 4);
  106059. break;
  106060. + case WM8804_MCLK_DIV:
  106061. + wm8804 = snd_soc_codec_get_drvdata(codec);
  106062. + wm8804->mclk_div = div;
  106063. + break;
  106064. default:
  106065. dev_err(dai->dev, "Unknown clock divider: %d\n", div_id);
  106066. return -EINVAL;
  106067. @@ -641,7 +652,7 @@
  106068. };
  106069. #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  106070. - SNDRV_PCM_FMTBIT_S24_LE)
  106071. + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  106072. #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  106073. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
  106074. @@ -674,7 +685,7 @@
  106075. .suspend = wm8804_suspend,
  106076. .resume = wm8804_resume,
  106077. .set_bias_level = wm8804_set_bias_level,
  106078. - .idle_bias_off = true,
  106079. + .idle_bias_off = false,
  106080. .controls = wm8804_snd_controls,
  106081. .num_controls = ARRAY_SIZE(wm8804_snd_controls),
  106082. diff -Nur linux-3.12.18/sound/soc/codecs/wm8804.h linux-rpi/sound/soc/codecs/wm8804.h
  106083. --- linux-3.12.18/sound/soc/codecs/wm8804.h 2014-04-18 11:14:28.000000000 +0200
  106084. +++ linux-rpi/sound/soc/codecs/wm8804.h 2014-04-24 15:35:05.509580657 +0200
  106085. @@ -57,5 +57,9 @@
  106086. #define WM8804_CLKOUT_SRC_OSCCLK 4
  106087. #define WM8804_CLKOUT_DIV 1
  106088. +#define WM8804_MCLK_DIV 2
  106089. +
  106090. +#define WM8804_MCLKDIV_256FS 0
  106091. +#define WM8804_MCLKDIV_128FS 1
  106092. #endif /* _WM8804_H */
  106093. diff -Nur linux-3.12.18/sound/soc/Kconfig linux-rpi/sound/soc/Kconfig
  106094. --- linux-3.12.18/sound/soc/Kconfig 2014-04-18 11:14:28.000000000 +0200
  106095. +++ linux-rpi/sound/soc/Kconfig 2014-04-24 16:04:42.783152901 +0200
  106096. @@ -33,6 +33,7 @@
  106097. # All the supported SoCs
  106098. source "sound/soc/atmel/Kconfig"
  106099. source "sound/soc/au1x/Kconfig"
  106100. +source "sound/soc/bcm/Kconfig"
  106101. source "sound/soc/blackfin/Kconfig"
  106102. source "sound/soc/cirrus/Kconfig"
  106103. source "sound/soc/davinci/Kconfig"
  106104. diff -Nur linux-3.12.18/sound/soc/Makefile linux-rpi/sound/soc/Makefile
  106105. --- linux-3.12.18/sound/soc/Makefile 2014-04-18 11:14:28.000000000 +0200
  106106. +++ linux-rpi/sound/soc/Makefile 2014-04-24 16:04:42.783152901 +0200
  106107. @@ -10,6 +10,7 @@
  106108. obj-$(CONFIG_SND_SOC) += generic/
  106109. obj-$(CONFIG_SND_SOC) += atmel/
  106110. obj-$(CONFIG_SND_SOC) += au1x/
  106111. +obj-$(CONFIG_SND_SOC) += bcm/
  106112. obj-$(CONFIG_SND_SOC) += blackfin/
  106113. obj-$(CONFIG_SND_SOC) += cirrus/
  106114. obj-$(CONFIG_SND_SOC) += davinci/
  106115. diff -Nur linux-3.12.18/sound/soc/soc-core.c linux-rpi/sound/soc/soc-core.c
  106116. --- linux-3.12.18/sound/soc/soc-core.c 2014-04-18 11:14:28.000000000 +0200
  106117. +++ linux-rpi/sound/soc/soc-core.c 2014-04-24 16:04:54.819269165 +0200
  106118. @@ -3038,8 +3038,8 @@
  106119. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  106120. uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
  106121. - uinfo->value.integer.min = 0;
  106122. - uinfo->value.integer.max = platform_max - min;
  106123. + uinfo->value.integer.min = min;
  106124. + uinfo->value.integer.max = platform_max;
  106125. return 0;
  106126. }
  106127. @@ -3070,9 +3070,10 @@
  106128. unsigned int val, val_mask;
  106129. int ret;
  106130. - val = ((ucontrol->value.integer.value[0] + min) & mask);
  106131. if (invert)
  106132. - val = max - val;
  106133. + val = ((max - ucontrol->value.integer.value[0] + min) & mask);
  106134. + else
  106135. + val = (ucontrol->value.integer.value[0] & mask);
  106136. val_mask = mask << shift;
  106137. val = val << shift;
  106138. @@ -3081,9 +3082,10 @@
  106139. return ret;
  106140. if (snd_soc_volsw_is_stereo(mc)) {
  106141. - val = ((ucontrol->value.integer.value[1] + min) & mask);
  106142. if (invert)
  106143. - val = max - val;
  106144. + val = ((max - ucontrol->value.integer.value[1] + min) & mask);
  106145. + else
  106146. + val = (ucontrol->value.integer.value[1] & mask);
  106147. val_mask = mask << shift;
  106148. val = val << shift;
  106149. @@ -3121,18 +3123,14 @@
  106150. (snd_soc_read(codec, reg) >> shift) & mask;
  106151. if (invert)
  106152. ucontrol->value.integer.value[0] =
  106153. - max - ucontrol->value.integer.value[0];
  106154. - ucontrol->value.integer.value[0] =
  106155. - ucontrol->value.integer.value[0] - min;
  106156. + max - ucontrol->value.integer.value[0] + min;
  106157. if (snd_soc_volsw_is_stereo(mc)) {
  106158. ucontrol->value.integer.value[1] =
  106159. (snd_soc_read(codec, rreg) >> shift) & mask;
  106160. if (invert)
  106161. ucontrol->value.integer.value[1] =
  106162. - max - ucontrol->value.integer.value[1];
  106163. - ucontrol->value.integer.value[1] =
  106164. - ucontrol->value.integer.value[1] - min;
  106165. + max - ucontrol->value.integer.value[1] + min;
  106166. }
  106167. return 0;
  106168. @@ -3576,6 +3574,22 @@
  106169. EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
  106170. /**
  106171. + * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
  106172. + * @dai: DAI
  106173. + * @ratio Ratio of BCLK to Sample rate.
  106174. + *
  106175. + * Configures the DAI for a preset BCLK to sample rate ratio.
  106176. + */
  106177. +int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
  106178. +{
  106179. + if (dai->driver && dai->driver->ops->set_bclk_ratio)
  106180. + return dai->driver->ops->set_bclk_ratio(dai, ratio);
  106181. + else
  106182. + return -EINVAL;
  106183. +}
  106184. +EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
  106185. +
  106186. +/**
  106187. * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  106188. * @dai: DAI
  106189. * @fmt: SND_SOC_DAIFMT_ format value.