016-m5445x_usb_initial_port.patch 205 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360
  1. From 6694c72448723499ce8a8603b4830bbd9d2fa0df Mon Sep 17 00:00:00 2001
  2. From: Bruce Schmid <[email protected]>
  3. Date: Tue, 20 Nov 2007 11:06:14 -0700
  4. Subject: [PATCH] USB: initial port
  5. LTIBName: m5445x-usb-initial-port
  6. Signed-off-by: Duck <[email protected]>
  7. ---
  8. arch/m68k/coldfire/usb.c | 182 +++
  9. arch/m68k/coldfire/usb/Makefile | 28 +
  10. arch/m68k/coldfire/usb/otg_cmn.c | 106 ++
  11. arch/m68k/coldfire/usb/otg_device.c | 89 ++
  12. arch/m68k/coldfire/usb/otg_host.c | 68 +
  13. arch/m68k/coldfire/usb/otg_otg.c | 96 ++
  14. arch/m68k/coldfire/usb/xcvr.c | 156 ++
  15. drivers/usb/Kconfig | 1 +
  16. drivers/usb/Makefile | 2 +
  17. drivers/usb/core/usb.c | 2 +-
  18. drivers/usb/gadget/Kconfig | 43 +-
  19. drivers/usb/gadget/Makefile | 1 +
  20. drivers/usb/gadget/ether.c | 3 +
  21. drivers/usb/gadget/fsl_usb2_udc.h | 194 +---
  22. drivers/usb/gadget/gadget_chips.h | 7 +
  23. drivers/usb/gadget/mcf5445x_udc.c | 2758 +++++++++++++++++++++++++++++++++++
  24. drivers/usb/host/Kconfig | 21 +-
  25. drivers/usb/host/ehci-arc.c | 431 ++++++
  26. drivers/usb/host/ehci-fsl.h | 28 +-
  27. drivers/usb/host/ehci-hcd.c | 5 +
  28. drivers/usb/host/ehci-mem.c | 9 +-
  29. drivers/usb/host/ehci.h | 22 +
  30. drivers/usb/otg/Makefile | 5 +
  31. drivers/usb/otg/fsl_otg.c | 1515 +++++++++++++++++++
  32. drivers/usb/otg/fsl_otg.h | 139 ++
  33. drivers/usb/otg/otg_fsm.c | 381 +++++
  34. drivers/usb/otg/otg_fsm.h | 170 +++
  35. include/asm-m68k/mcf5445x_usb.h | 3 +-
  36. include/linux/fsl_devices.h | 42 +-
  37. include/linux/usb/fsl_usb2.h | 464 ++++++
  38. include/linux/usb/fsl_xcvr.h | 42 +
  39. 31 files changed, 6809 insertions(+), 204 deletions(-)
  40. create mode 100644 arch/m68k/coldfire/usb.c
  41. create mode 100644 arch/m68k/coldfire/usb/Makefile
  42. create mode 100644 arch/m68k/coldfire/usb/otg_cmn.c
  43. create mode 100644 arch/m68k/coldfire/usb/otg_device.c
  44. create mode 100644 arch/m68k/coldfire/usb/otg_host.c
  45. create mode 100644 arch/m68k/coldfire/usb/otg_otg.c
  46. create mode 100644 arch/m68k/coldfire/usb/xcvr.c
  47. create mode 100644 drivers/usb/gadget/mcf5445x_udc.c
  48. create mode 100644 drivers/usb/host/ehci-arc.c
  49. create mode 100644 drivers/usb/otg/Makefile
  50. create mode 100644 drivers/usb/otg/fsl_otg.c
  51. create mode 100644 drivers/usb/otg/fsl_otg.h
  52. create mode 100644 drivers/usb/otg/otg_fsm.c
  53. create mode 100644 drivers/usb/otg/otg_fsm.h
  54. create mode 100644 include/linux/usb/fsl_usb2.h
  55. create mode 100644 include/linux/usb/fsl_xcvr.h
  56. --- /dev/null
  57. +++ b/arch/m68k/coldfire/usb.c
  58. @@ -0,0 +1,182 @@
  59. +/*
  60. + *
  61. + * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  62. + *
  63. + * otg_{get,set}_transceiver() are from arm/plat-omap/usb.c.
  64. + * which is Copyright (C) 2004 Texas Instruments, Inc.
  65. + */
  66. +
  67. +/*
  68. + * The code contained herein is licensed under the GNU General Public
  69. + * License. You may obtain a copy of the GNU General Public License
  70. + * Version 2 or later at the following locations:
  71. + *
  72. + * http://www.opensource.org/licenses/gpl-license.html
  73. + * http://www.gnu.org/copyleft/gpl.html
  74. + */
  75. +
  76. +#include <linux/module.h>
  77. +#include <linux/kernel.h>
  78. +#include <linux/types.h>
  79. +#include <linux/errno.h>
  80. +#include <linux/init.h>
  81. +#include <linux/io.h>
  82. +#include <linux/err.h>
  83. +#include <linux/platform_device.h>
  84. +#include <linux/usb/otg.h>
  85. +#include <linux/delay.h>
  86. +#include <linux/fsl_devices.h>
  87. +#include <linux/usb/fsl_xcvr.h>
  88. +
  89. +
  90. +/* The dmamask must be set for EHCI to work */
  91. +static u64 ehci_dmamask = ~(u32) 0;
  92. +
  93. +struct fsl_xcvr_ops *xc_ops[3] = { NULL };
  94. +
  95. +void fsl_usb_enable_clk(void)
  96. +{
  97. +}
  98. +EXPORT_SYMBOL(fsl_usb_enable_clk);
  99. +
  100. +void fsl_usb_disable_clk(void)
  101. +{
  102. +}
  103. +EXPORT_SYMBOL(fsl_usb_disable_clk);
  104. +
  105. +void fsl_usb_xcvr_register(struct fsl_xcvr_ops *xcvr_ops)
  106. +{
  107. + pr_debug("%s ctrlr=%d\n", __FUNCTION__, xcvr_ops->ctrlr);
  108. + xc_ops[xcvr_ops->ctrlr] = xcvr_ops;
  109. +
  110. +}
  111. +EXPORT_SYMBOL(fsl_usb_xcvr_register);
  112. +
  113. +void fsl_usb_xcvr_unregister(enum fsl_usb_ctrlr ctrlr)
  114. +{
  115. + pr_debug("%s ctrlr=%d\n", __FUNCTION__, ctrlr);
  116. + xc_ops[ctrlr] = NULL;
  117. +}
  118. +EXPORT_SYMBOL(fsl_usb_xcvr_unregister);
  119. +
  120. +/*!
  121. + * Register an instance of a USB host platform device.
  122. + *
  123. + * @param res: resource pointer
  124. + * @param n_res: number of resources
  125. + * @param config: config pointer
  126. + *
  127. + * @return newly-registered platform_device
  128. + *
  129. + * DDD fix this comment:
  130. + * The USB controller supports 3 host interfaces, and the
  131. + * kernel can be configured to support some number of them.
  132. + * Each supported host interface is registered as an instance
  133. + * of the "fsl-ehci" device. Call this function multiple times
  134. + * to register each host interface.
  135. + */
  136. +static int instance_id;
  137. +struct platform_device *host_pdev_register(struct resource *res, int n_res,
  138. + struct fsl_usb2_platform_data *config)
  139. +{
  140. + struct platform_device *pdev;
  141. +
  142. + pr_debug("register host res=0x%p, size=%d\n", res, n_res);
  143. +
  144. + pdev = platform_device_register_simple("fsl-ehci",
  145. + instance_id, res, n_res);
  146. + if (IS_ERR(pdev)) {
  147. + printk(KERN_ERR "usb: can't register %s Host, %ld\n",
  148. + config->name, PTR_ERR(pdev));
  149. + return NULL;
  150. + }
  151. +
  152. + pdev->dev.coherent_dma_mask = 0xffffffff;
  153. + pdev->dev.dma_mask = &ehci_dmamask;
  154. +
  155. + /*
  156. + * platform_device_add_data() makes a copy of
  157. + * the platform_data passed in. That makes it
  158. + * impossible to share the same config struct for
  159. + * all OTG devices (host,gadget,otg). So, just
  160. + * set the platform_data pointer ourselves.
  161. + */
  162. + pdev->dev.platform_data = config;
  163. +
  164. + printk(KERN_INFO "usb: %s Host registered\n", config->name);
  165. + pr_debug("pdev=0x%p dev=0x%p resources=0x%p pdata=0x%p\n",
  166. + pdev, &pdev->dev, pdev->resource, pdev->dev.platform_data);
  167. +
  168. + instance_id++;
  169. +
  170. + return pdev;
  171. +}
  172. +
  173. +
  174. +int fsl_usb_mem_init(struct platform_device *pdev)
  175. +{
  176. + struct resource *res;
  177. + struct fsl_usb2_platform_data *pdata;
  178. +
  179. + pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data;
  180. +
  181. + pr_debug("%s: pdev=0x%p pdata=0x%p\n", __FUNCTION__, pdev, pdata);
  182. +
  183. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  184. + if (!res) {
  185. + dev_err(&pdev->dev, "no MEM resource.\n");
  186. + return -ENODEV;
  187. + }
  188. +
  189. + pdata->r_start = res->start;
  190. + pdata->r_len = res->end - res->start + 1;
  191. + pr_debug("%s: MEM resource start=0x%x len=0x%x\n", pdata->name,
  192. + res->start, pdata->r_len);
  193. +
  194. + if (!request_mem_region(pdata->r_start, pdata->r_len, "OTG")) {
  195. + dev_err(&pdev->dev, "request_mem_region failed\n");
  196. + return -EBUSY;
  197. + }
  198. + pdata->regs = ioremap(pdata->r_start, pdata->r_len);
  199. + pr_debug("ioremapped to 0x%p\n", pdata->regs);
  200. +
  201. + if (pdata->regs == NULL) {
  202. + dev_err(&pdev->dev, "ioremap failed\n");
  203. + release_mem_region(pdata->r_start, pdata->r_len);
  204. + return -EFAULT;
  205. + }
  206. +
  207. + pr_debug("%s: success\n", __FUNCTION__);
  208. + return 0;
  209. +}
  210. +
  211. +
  212. +#if defined(CONFIG_USB_OTG)
  213. +static struct otg_transceiver *xceiv;
  214. +
  215. +/**
  216. + * otg_get_transceiver - find the (single) OTG transceiver driver
  217. + *
  218. + * Returns the transceiver driver, after getting a refcount to it; or
  219. + * null if there is no such transceiver. The caller is responsible for
  220. + * releasing that count.
  221. + */
  222. +struct otg_transceiver *otg_get_transceiver(void)
  223. +{
  224. + pr_debug("%s xceiv=0x%p\n", __FUNCTION__, xceiv);
  225. + if (xceiv)
  226. + get_device(xceiv->dev);
  227. + return xceiv;
  228. +}
  229. +EXPORT_SYMBOL(otg_get_transceiver);
  230. +
  231. +int otg_set_transceiver(struct otg_transceiver *x)
  232. +{
  233. + pr_debug("%s xceiv=0x%p x=0x%p\n", __FUNCTION__, xceiv, x);
  234. + if (xceiv && x)
  235. + return -EBUSY;
  236. + xceiv = x;
  237. + return 0;
  238. +}
  239. +EXPORT_SYMBOL(otg_set_transceiver);
  240. +#endif
  241. --- /dev/null
  242. +++ b/arch/m68k/coldfire/usb/Makefile
  243. @@ -0,0 +1,28 @@
  244. +#
  245. +# Makefile for the linux kernel.
  246. +#
  247. +
  248. +# Object file lists.
  249. +
  250. +ifneq ($(CONFIG_USB_EHCI_HCD),)
  251. + obj-y += otg_host.o
  252. +endif
  253. +
  254. +ifneq ($(CONFIG_USB_GADGET_MCF5445X),)
  255. + obj-y += otg_device.o
  256. +endif
  257. +
  258. +ifneq ($(strip $(CONFIG_USB_GADGET_MCF5445X) $(CONFIG_USB_EHCI_HCD)),)
  259. + obj-y += otg_cmn.o
  260. +endif
  261. +
  262. +ifneq ($(CONFIG_USB_OTG),)
  263. + obj-y += otg_otg.o
  264. +endif
  265. +
  266. +
  267. +# USB Transceiver driver:
  268. +ifneq ($(strip $(CONFIG_USB) $(CONFIG_USB_GADGET_MCF5445X)),)
  269. + obj-y += xcvr.o
  270. +endif
  271. +
  272. --- /dev/null
  273. +++ b/arch/m68k/coldfire/usb/otg_cmn.c
  274. @@ -0,0 +1,106 @@
  275. +/*
  276. + * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  277. + */
  278. +
  279. +/*
  280. + * The code contained herein is licensed under the GNU General Public
  281. + * License. You may obtain a copy of the GNU General Public License
  282. + * Version 2 or later at the following locations:
  283. + *
  284. + * http://www.opensource.org/licenses/gpl-license.html
  285. + * http://www.gnu.org/copyleft/gpl.html
  286. + */
  287. +
  288. +#include <linux/module.h>
  289. +#include <linux/kernel.h>
  290. +#include <linux/types.h>
  291. +#include <linux/err.h>
  292. +#include <linux/errno.h>
  293. +#include <linux/init.h>
  294. +#include <linux/io.h>
  295. +#include <linux/irq.h>
  296. +#include <linux/platform_device.h>
  297. +#include <linux/delay.h>
  298. +#include <linux/fsl_devices.h>
  299. +#include <linux/usb/fsl_xcvr.h>
  300. +
  301. +#include <asm/system.h>
  302. +#include <asm/coldfire.h>
  303. +
  304. +extern void fsl_usb_enable_clk(void);
  305. +extern void fsl_usb_disable_clk(void);
  306. +extern int fsl_usb_mem_init(struct platform_device *pdev);
  307. +
  308. +extern struct fsl_xcvr_ops *xc_ops[];
  309. +
  310. +static int otg_used;
  311. +
  312. +int usbotg_init(struct platform_device *pdev)
  313. +{
  314. + struct fsl_usb2_platform_data *pdata;
  315. + struct fsl_xcvr_ops *xops = xc_ops[USB_CTRLR_OTG];
  316. + int rc;
  317. +
  318. + pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data;
  319. +
  320. + pr_debug("%s: pdev=0x%p pdata=0x%p\n", __FUNCTION__, pdev, pdata);
  321. +
  322. + if (!xops) {
  323. + printk(KERN_ERR "OTG transceiver ops missing\n");
  324. + return -EINVAL;
  325. + }
  326. + pdata->xcvr_ops = xops;
  327. + pdata->xcvr_type = xops->xcvr_type;
  328. +
  329. + if (!otg_used) {
  330. + /* request_mem_region and ioremap registers */
  331. + rc = fsl_usb_mem_init(pdev);
  332. + if (rc)
  333. + return rc;
  334. +
  335. + fsl_usb_enable_clk();
  336. +
  337. + if (xops->init)
  338. + xops->init(pdev);
  339. + }
  340. +
  341. + otg_used++;
  342. + pr_debug("%s: success\n", __FUNCTION__);
  343. + return 0;
  344. +}
  345. +
  346. +void usbotg_uninit(struct platform_device *pdev)
  347. +{
  348. + struct fsl_usb2_platform_data *pdata;
  349. + pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data;
  350. +
  351. + pr_debug("%s\n", __FUNCTION__);
  352. +
  353. + otg_used--;
  354. + if (!otg_used) {
  355. + if (pdata->xcvr_ops && pdata->xcvr_ops->uninit)
  356. + pdata->xcvr_ops->uninit(pdev);
  357. +
  358. + iounmap(pdata->regs);
  359. + release_mem_region(pdata->r_start, pdata->r_len);
  360. +
  361. + pdata->regs = NULL;
  362. + pdata->r_start = pdata->r_len = 0;
  363. +
  364. + fsl_usb_disable_clk();
  365. + }
  366. +}
  367. +
  368. +struct fsl_usb2_platform_data mxc_otg_config = {
  369. + .name = "OTG",
  370. + .platform_init = usbotg_init,
  371. + .platform_uninit = usbotg_uninit,
  372. + .es = 1,
  373. + .big_endian_mmio = 1,
  374. + .big_endian_desc = 1,
  375. + .le_setup_buf = 1,
  376. + .does_otg = 1,
  377. + .power_budget = 500, /* 500 mA max power */
  378. + .max_ep_nr = 4, /* DDD read from a register ? */
  379. + .phy_mode = FSL_USB2_PHY_ULPI, /* DDD redundant with xcvr_type */
  380. +};
  381. --- /dev/null
  382. +++ b/arch/m68k/coldfire/usb/otg_device.c
  383. @@ -0,0 +1,89 @@
  384. +/*
  385. + * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  386. + */
  387. +
  388. +/*
  389. + * The code contained herein is licensed under the GNU General Public
  390. + * License. You may obtain a copy of the GNU General Public License
  391. + * Version 2 or later at the following locations:
  392. + *
  393. + * http://www.opensource.org/licenses/gpl-license.html
  394. + * http://www.gnu.org/copyleft/gpl.html
  395. + */
  396. +
  397. +#include <linux/module.h>
  398. +#include <linux/kernel.h>
  399. +#include <linux/types.h>
  400. +#include <linux/errno.h>
  401. +#include <linux/init.h>
  402. +#include <linux/io.h>
  403. +#include <linux/irq.h>
  404. +#include <linux/err.h>
  405. +#include <linux/platform_device.h>
  406. +#include <linux/usb/otg.h>
  407. +#include <linux/delay.h>
  408. +#include <linux/fsl_devices.h>
  409. +#include <linux/usb/fsl_xcvr.h>
  410. +
  411. +#include <asm/system.h>
  412. +#include <asm/coldfire.h>
  413. +
  414. +#define USB_OTGREGS_BASE MCF_REG32(0xFC0B0000)
  415. +#define INT_USB (64 + 64 + 47) /* INTC1:47 16.2.9.1 */
  416. +#define INT_UOCSR (64 + 64 + 53) /* INTC1:53 16.2.9.1 */
  417. +
  418. +extern int usbotg_init(struct platform_device *pdev);
  419. +extern void usbotg_uninit(struct fsl_usb2_platform_data *pdata);
  420. +extern struct fsl_usb2_platform_data mxc_otg_config;
  421. +
  422. +struct platform_device otg_udc_device;
  423. +
  424. +/*!
  425. + * OTG Gadget device
  426. + */
  427. +
  428. +static void usb_release(struct device *dev)
  429. +{
  430. + /* normally not freed */
  431. +}
  432. +
  433. +static u64 udc_dmamask = ~(u32) 0;
  434. +static struct resource otg_udc_resources[] = {
  435. + [0] = {
  436. + .start = (u32) (&USB_OTGREGS_BASE),
  437. + .end = (u32) (&USB_OTGREGS_BASE + 0x1ff),
  438. + .flags = IORESOURCE_MEM,
  439. + },
  440. + [1] = {
  441. + .start = INT_USB,
  442. + .flags = IORESOURCE_IRQ,
  443. + },
  444. +};
  445. +
  446. +
  447. +struct platform_device otg_udc_device = {
  448. + .name = "fsl-usb2-udc",
  449. + .id = -1,
  450. + .dev = {
  451. + .release = usb_release,
  452. + .dma_mask = &udc_dmamask,
  453. + .coherent_dma_mask = 0xffffffff,
  454. + .platform_data = &mxc_otg_config,
  455. + },
  456. + .resource = otg_udc_resources,
  457. + .num_resources = ARRAY_SIZE(otg_udc_resources),
  458. +};
  459. +
  460. +static int __init udc_init(void)
  461. +{
  462. + int rc __attribute((unused));
  463. +
  464. + rc = platform_device_register(&otg_udc_device);
  465. + if (rc)
  466. + printk(KERN_ERR "usb: can't register OTG Gadget, rc=%d\n", rc);
  467. + else
  468. + printk(KERN_INFO "usb: OTG Gadget registered\n");
  469. + return rc;
  470. +}
  471. +
  472. +subsys_initcall(udc_init);
  473. --- /dev/null
  474. +++ b/arch/m68k/coldfire/usb/otg_host.c
  475. @@ -0,0 +1,68 @@
  476. +/*
  477. + * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  478. + */
  479. +
  480. +/*
  481. + * The code contained herein is licensed under the GNU General Public
  482. + * License. You may obtain a copy of the GNU General Public License
  483. + * Version 2 or later at the following locations:
  484. + *
  485. + * http://www.opensource.org/licenses/gpl-license.html
  486. + * http://www.gnu.org/copyleft/gpl.html
  487. + */
  488. +
  489. +#include <linux/module.h>
  490. +#include <linux/kernel.h>
  491. +#include <linux/types.h>
  492. +#include <linux/errno.h>
  493. +#include <linux/init.h>
  494. +#include <linux/io.h>
  495. +#include <linux/irq.h>
  496. +#include <linux/err.h>
  497. +#include <linux/platform_device.h>
  498. +#include <linux/delay.h>
  499. +#include <linux/fsl_devices.h>
  500. +#include <linux/usb/fsl_xcvr.h>
  501. +
  502. +#include <asm/system.h>
  503. +#include <asm/mcfsim.h>
  504. +
  505. +#define USB_OTGREGS_BASE MCF_REG32(0xFC0B0000)
  506. +#define INT_USB (64 + 64 + 47) /* INTC1:47 16.2.9.1 */
  507. +#define INT_UOCSR (64 + 64 + 53) /* INTC1:53 16.2.9.1 */
  508. +
  509. +struct platform_device *otg_host_device;
  510. +
  511. +extern struct platform_device *host_pdev_register(struct resource *res,
  512. + int n_res,
  513. + struct fsl_usb2_platform_data
  514. + *config);
  515. +
  516. +extern int usbotg_init(struct platform_device *pdev);
  517. +extern void usbotg_uninit(struct fsl_usb2_platform_data *pdata);
  518. +extern struct fsl_usb2_platform_data mxc_otg_config;
  519. +
  520. +/*!
  521. + * OTG host config
  522. + */
  523. +static struct resource otg_host_resources[] = {
  524. + [0] = {
  525. + .start = (u32) (&USB_OTGREGS_BASE),
  526. + .end = (u32) (&USB_OTGREGS_BASE + 0x1ff),
  527. + .flags = IORESOURCE_MEM,
  528. + },
  529. + [1] = {
  530. + .start = INT_USB,
  531. + .flags = IORESOURCE_IRQ,
  532. + },
  533. +};
  534. +
  535. +static int __init otg_host_init(void)
  536. +{
  537. + otg_host_device = host_pdev_register(otg_host_resources,
  538. + ARRAY_SIZE(otg_host_resources),
  539. + &mxc_otg_config);
  540. + return 0;
  541. +}
  542. +
  543. +subsys_initcall(otg_host_init);
  544. --- /dev/null
  545. +++ b/arch/m68k/coldfire/usb/otg_otg.c
  546. @@ -0,0 +1,96 @@
  547. +/*
  548. + * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  549. + */
  550. +
  551. +/*
  552. + * The code contained herein is licensed under the GNU General Public
  553. + * License. You may obtain a copy of the GNU General Public License
  554. + * Version 2 or later at the following locations:
  555. + *
  556. + * http://www.opensource.org/licenses/gpl-license.html
  557. + * http://www.gnu.org/copyleft/gpl.html
  558. + */
  559. +
  560. +/*
  561. + * platform_device registration for ULPI OTG device
  562. + */
  563. +
  564. +#include <linux/module.h>
  565. +#include <linux/kernel.h>
  566. +#include <linux/types.h>
  567. +#include <linux/errno.h>
  568. +#include <linux/init.h>
  569. +#include <linux/err.h>
  570. +#include <linux/platform_device.h>
  571. +#include <linux/fsl_devices.h>
  572. +
  573. +#include <asm/mcfsim.h>
  574. +
  575. +#define USB_OTGREGS_BASE MCF_REG32(0xFC0B0000)
  576. +#define INT_USB (64 + 64 + 47) /* INTC1:47 16.2.9.1 */
  577. +#define INT_UOCSR (64 + 64 + 53) /* INTC1:53 16.2.9.1 */
  578. +
  579. +extern int usbotg_init(struct platform_device *pdev);
  580. +extern void usbotg_uninit(struct fsl_usb2_platform_data *pdata);
  581. +extern struct fsl_usb2_platform_data mxc_otg_config;
  582. +
  583. +static void otg_otg_release(struct device *dev)
  584. +{
  585. + /* normally not freed */
  586. +}
  587. +
  588. +/* *INDENT-OFF* */
  589. +static struct resource otg_otg_resources[] = {
  590. + [0] = {
  591. + .start = (u32) (&USB_OTGREGS_BASE),
  592. + .end = (u32) (&USB_OTGREGS_BASE + 0x1ff),
  593. + .flags = IORESOURCE_MEM,
  594. + },
  595. + [1] = {
  596. + .start = INT_USB,
  597. + .flags = IORESOURCE_IRQ,
  598. + },
  599. +};
  600. +
  601. +/*!
  602. + * OTG device
  603. + */
  604. +static u64 otg_otg_dmamask = ~(u32) 0;
  605. +static struct platform_device otg_otg_device = {
  606. + .name = "fsl-usb2-otg",
  607. + .id = -1,
  608. + .dev = {
  609. + .release = otg_otg_release,
  610. + .dma_mask = &otg_otg_dmamask,
  611. + .coherent_dma_mask = 0xffffffff,
  612. + .platform_data = &mxc_otg_config,
  613. + },
  614. + .resource = otg_otg_resources,
  615. + .num_resources = ARRAY_SIZE(otg_otg_resources),
  616. +};
  617. +/* *INDENT-ON* */
  618. +
  619. +static int __init mx31_otg_otg_init(void)
  620. +{
  621. + int rc = 0;
  622. +
  623. + pr_debug("register OTG otg res=0x%p, size=%d\n",
  624. + otg_otg_device.resource, otg_otg_device.num_resources);
  625. +
  626. + rc = platform_device_register(&otg_otg_device);
  627. + if (rc) {
  628. + pr_debug("can't register ULPI OTG dvc, %d\n", rc);
  629. + } else {
  630. + printk(KERN_INFO "usb: OTG ULPI transceiver registered\n");
  631. + pr_debug("otg_otg_device=0x%p resources=0x%p.\n",
  632. + &otg_otg_device, otg_otg_device.resource);
  633. + }
  634. +
  635. + return rc;
  636. +}
  637. +
  638. +subsys_initcall(mx31_otg_otg_init);
  639. +
  640. +MODULE_AUTHOR("Freescale Semiconductor, Inc.");
  641. +MODULE_DESCRIPTION("ULPI OTG device registration");
  642. +MODULE_LICENSE("GPL");
  643. --- /dev/null
  644. +++ b/arch/m68k/coldfire/usb/xcvr.c
  645. @@ -0,0 +1,156 @@
  646. +/*
  647. + * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  648. + */
  649. +
  650. +/*
  651. + * The code contained herein is licensed under the GNU General Public
  652. + * License. You may obtain a copy of the GNU General Public License
  653. + * Version 2 or later at the following locations:
  654. + *
  655. + * http://www.opensource.org/licenses/gpl-license.html
  656. + * http://www.gnu.org/copyleft/gpl.html
  657. + */
  658. +
  659. +#include <linux/module.h>
  660. +#include <linux/kernel.h>
  661. +#include <linux/types.h>
  662. +#include <linux/errno.h>
  663. +#include <linux/init.h>
  664. +#include <linux/err.h>
  665. +#include <linux/platform_device.h>
  666. +#include <linux/delay.h>
  667. +#include <linux/fsl_devices.h>
  668. +#include <linux/usb/fsl_xcvr.h>
  669. +#include <linux/usb/fsl_usb2.h>
  670. +
  671. +#include <asm/mcfsim.h>
  672. +
  673. +extern void fsl_usb_xcvr_register(struct fsl_xcvr_ops *xcvr_ops);
  674. +extern void fsl_usb_xcvr_unregister(enum fsl_usb_ctrlr ctrlr);
  675. +
  676. +#define MCF_SCM_BCR MCF_REG32(0xFC040024)
  677. +#define MCF_SCM_BCR_GBR (1 << 9) /* global bursts for read */
  678. +#define MCF_SCM_BCR_GBW (1 << 8) /* global bursts for write */
  679. +#define MCF_SCM_BCR_SBE_ALL (0xff << 0) /* slave burst enable */
  680. +
  681. +
  682. +#ifdef ULPI_DEBUG
  683. +void print_ulpi_regs(void)
  684. +{
  685. + pr_debug("MCF_SCM_BCR=0x%08lx MCF_CCM_MISCCR=0x%08x "
  686. + "MCF_GPIO_PAR_DMA=0x%08x MCF_GPIO_PAR_USB=08%08x "
  687. + "MCF_GPIO_PAR_FEC=08%08x\n",
  688. + MCF_SCM_BCR, MCF_CCM_MISCCR, MCF_GPIO_PAR_DMA,
  689. + MCF_GPIO_PAR_USB, MCF_GPIO_PAR_FEC);
  690. +}
  691. +EXPORT_SYMBOL(print_ulpi_regs);
  692. +#endif
  693. +
  694. +
  695. +static void xcvr_init(struct platform_device *pdev)
  696. +{
  697. + struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
  698. + struct fsl_xcvr_ops *this = pdata->xcvr_ops;
  699. + struct fsl_usb_host_regs *regs = pdata->regs;
  700. +
  701. + pr_debug("%s: ctrlr=%d pdata=0x%p regs=0x%p\n", __FUNCTION__,
  702. + this->ctrlr, pdata, pdata->regs);
  703. +
  704. + /* enable USB read, write and slave bursts */
  705. + MCF_SCM_BCR = MCF_SCM_BCR_GBR | MCF_SCM_BCR_GBW | MCF_SCM_BCR_SBE_ALL;
  706. +
  707. + /* Use external clock source if PLL isn't a multiple of 60MHz */
  708. + MCF_CCM_MISCCR &= ~MCF_CCM_MISCCR_USBSRC;
  709. +
  710. + /* Initialize the USB Clock: use USB input clock */
  711. + MCF_GPIO_PAR_DMA = (MCF_GPIO_PAR_DMA & MCF_GPIO_PAR_DMA_DREQ1_MASK) |
  712. + MCF_GPIO_PAR_DMA_DREQ1_USB_CLKIN;
  713. +
  714. + switch (this->xcvr_type) {
  715. + case PORTSCX_PTS_ULPI:
  716. + /* Enable the required ULPI signals */
  717. + MCF_GPIO_PAR_DMA = (MCF_GPIO_PAR_DMA &
  718. + MCF_GPIO_PAR_DMA_DACK1_MASK) |
  719. + MCF_GPIO_PAR_DMA_DACK1_ULPI_DIR;
  720. +
  721. + MCF_GPIO_PAR_USB = MCF_GPIO_PAR_USB_VBUSEN_ULPI_NXT |
  722. + MCF_GPIO_PAR_USB_VBUSOC_ULPI_STP;
  723. +
  724. + MCF_GPIO_PAR_FEC = (MCF_GPIO_PAR_FEC &
  725. + MCF_GPIO_PAR_FEC_FEC0_MASK) |
  726. + MCF_GPIO_PAR_FEC_FEC0_RMII_ULPI;
  727. + break;
  728. + case PORTSCX_PTS_ONCHIP:
  729. + /* Enable VBUS_EN and VBUS_OC signals */
  730. + MCF_GPIO_PAR_USB = MCF_GPIO_PAR_USB_VBUSEN_VBUSEN |
  731. + MCF_GPIO_PAR_USB_VBUSOC_VBUSOC;
  732. +
  733. + /* Setup USB_VBUS_OC signal to be active-low */
  734. + MCF_CCM_MISCCR |= MCF_CCM_MISCCR_USBOC;
  735. +
  736. + break;
  737. + }
  738. +
  739. + pr_debug("&regs->portsc1=0x%p old portsc1=0x%x \n", &regs->portsc1,
  740. + regs->portsc1);
  741. +
  742. + regs->portsc1 &= ~PORTSCX_PTS_MASK;
  743. + regs->portsc1 |= this->xcvr_type;
  744. +
  745. + /*
  746. + * need to reset the controller here so that the ID pin
  747. + * is correctly detected.
  748. + */
  749. + regs->usbcmd |= USB_CMD_CTRL_RESET;
  750. +
  751. + /*
  752. + * allow controller to reset, and leave time for
  753. + * the ULPI transceiver to reset too.
  754. + */
  755. + mdelay(10);
  756. +
  757. + pr_debug("DDD %s: done. portsc1=0x%x\n", __FUNCTION__, regs->portsc1);
  758. +}
  759. +
  760. +static void xcvr_uninit(struct platform_device *pdev)
  761. +{
  762. + pr_debug("%s: pdev=0x%p\n", __FUNCTION__, pdev);
  763. +}
  764. +
  765. +
  766. +struct fsl_xcvr_ops xcvr_ops_otg = {
  767. + .ctrlr = USB_CTRLR_OTG,
  768. + .init = xcvr_init,
  769. + .uninit = xcvr_uninit,
  770. +
  771. +#ifdef CONFIG_USB_M5445X_ULPI
  772. + .xcvr_type = PORTSCX_PTS_ULPI,
  773. +#elif defined CONFIG_USB_M5445X_FSLS
  774. + .xcvr_type = PORTSCX_PTS_ONCHIP,
  775. +#else
  776. +#error "Invalid USB transceiver selection."
  777. +#endif
  778. +};
  779. +
  780. +static int __init usb_xcvr_init(void)
  781. +{
  782. + pr_debug("%s\n", __FUNCTION__);
  783. +
  784. + fsl_usb_xcvr_register(&xcvr_ops_otg);
  785. +
  786. + pr_debug("%s done\n", __FUNCTION__);
  787. + return 0;
  788. +}
  789. +
  790. +static void __exit usb_xcvr_exit(void)
  791. +{
  792. + fsl_usb_xcvr_unregister(USB_CTRLR_OTG);
  793. +}
  794. +
  795. +module_init(usb_xcvr_init);
  796. +module_exit(usb_xcvr_exit);
  797. +
  798. +MODULE_AUTHOR("Freescale Semiconductor, Inc.");
  799. +MODULE_DESCRIPTION("External ULPI xcvr driver");
  800. +MODULE_LICENSE("GPL");
  801. +
  802. --- a/drivers/usb/Kconfig
  803. +++ b/drivers/usb/Kconfig
  804. @@ -55,6 +55,7 @@ config USB_ARCH_HAS_EHCI
  805. default y if PPC_83xx
  806. default y if SOC_AU1200
  807. default y if ARCH_IXP4XX
  808. + default y if M54455
  809. default PCI
  810. # ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface.
  811. --- a/drivers/usb/Makefile
  812. +++ b/drivers/usb/Makefile
  813. @@ -32,3 +32,5 @@ obj-$(CONFIG_USB) += misc/
  814. obj-$(CONFIG_USB_ATM) += atm/
  815. obj-$(CONFIG_USB_SPEEDTOUCH) += atm/
  816. +
  817. +obj-$(CONFIG_USB_OTG) += otg/
  818. --- a/drivers/usb/core/usb.c
  819. +++ b/drivers/usb/core/usb.c
  820. @@ -52,7 +52,7 @@ static int nousb; /* Disable USB when bu
  821. struct workqueue_struct *ksuspend_usb_wq;
  822. #ifdef CONFIG_USB_SUSPEND
  823. -static int usb_autosuspend_delay = 2; /* Default delay value,
  824. +static int usb_autosuspend_delay = -1; /* Default delay value,
  825. * in seconds */
  826. module_param_named(autosuspend, usb_autosuspend_delay, int, 0644);
  827. MODULE_PARM_DESC(autosuspend, "default autosuspend delay");
  828. --- a/drivers/usb/gadget/Kconfig
  829. +++ b/drivers/usb/gadget/Kconfig
  830. @@ -231,6 +231,26 @@ config SUPERH_BUILT_IN_M66592
  831. However, this problem is improved if change a value of
  832. NET_IP_ALIGN to 4.
  833. +config USB_GADGET_MCF5445X
  834. + boolean "MCF5445X USB Device Controller"
  835. + depends on M54455 && USB_M5445X_ULPI
  836. + select USB_GADGET_DUALSPEED
  837. + help
  838. + Freescale's MCF5445X processors include
  839. + an integrated device controller (as part of the OTG module).
  840. + It has four programmable, bidirectional endpoints,
  841. + including endpoint 0.
  842. +
  843. + Say "y" to link the driver statically, or "m" to build a
  844. + dynamically linked module called "mcf5445_udc" and force all
  845. + gadget drivers to also be dynamically linked.
  846. +
  847. +config USB_MCF5445X
  848. + tristate
  849. + depends on USB_GADGET_MCF5445X
  850. + default USB_GADGET
  851. + select USB_GADGET_SELECTED
  852. +
  853. config USB_GADGET_GOKU
  854. boolean "Toshiba TC86C001 'Goku-S'"
  855. depends on PCI
  856. @@ -285,17 +305,6 @@ config USB_OMAP
  857. default USB_GADGET
  858. select USB_GADGET_SELECTED
  859. -config USB_OTG
  860. - boolean "OTG Support"
  861. - depends on USB_GADGET_OMAP && ARCH_OMAP_OTG && USB_OHCI_HCD
  862. - help
  863. - The most notable feature of USB OTG is support for a
  864. - "Dual-Role" device, which can act as either a device
  865. - or a host. The initial role choice can be changed
  866. - later, when two dual-role devices talk to each other.
  867. -
  868. - Select this only if your OMAP board has a Mini-AB connector.
  869. -
  870. config USB_GADGET_S3C2410
  871. boolean "S3C2410 USB Device Controller"
  872. depends on ARCH_S3C2410
  873. @@ -369,6 +378,18 @@ config USB_DUMMY_HCD
  874. endchoice
  875. +config USB_OTG
  876. + boolean "OTG Support"
  877. + depends on (USB_GADGET_OMAP && ARCH_OMAP_OTG && USB_OHCI_HCD) || \
  878. + (USB_GADGET_MCF5445X && USB_M5445X_ULPI)
  879. + help
  880. + The most notable feature of USB OTG is support for a
  881. + "Dual-Role" device, which can act as either a device
  882. + or a host. The initial role choice can be changed
  883. + later, when two dual-role devices talk to each other.
  884. +
  885. + Select this only if your OMAP board has a Mini-AB connector.
  886. +
  887. config USB_GADGET_DUALSPEED
  888. bool
  889. depends on USB_GADGET
  890. --- a/drivers/usb/gadget/Makefile
  891. +++ b/drivers/usb/gadget/Makefile
  892. @@ -17,6 +17,7 @@ obj-$(CONFIG_USB_AT91) += at91_udc.o
  893. obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o
  894. obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o
  895. obj-$(CONFIG_USB_M66592) += m66592-udc.o
  896. +obj-$(CONFIG_USB_MCF5445X) += mcf5445x_udc.o
  897. #
  898. # USB gadget drivers
  899. --- a/drivers/usb/gadget/ether.c
  900. +++ b/drivers/usb/gadget/ether.c
  901. @@ -287,6 +287,9 @@ MODULE_PARM_DESC(host_addr, "Host Ethern
  902. #define DEV_CONFIG_CDC
  903. #endif
  904. +#ifdef CONFIG_USB_GADGET_MCF5445X
  905. +#define DEV_CONFIG_CDC
  906. +#endif
  907. /*-------------------------------------------------------------------------*/
  908. --- a/drivers/usb/gadget/fsl_usb2_udc.h
  909. +++ b/drivers/usb/gadget/fsl_usb2_udc.h
  910. @@ -83,16 +83,6 @@ struct usb_dr_host {
  911. u32 endptctrl[6]; /* Endpoint Control Registers */
  912. };
  913. - /* non-EHCI USB system interface registers (Big Endian) */
  914. -struct usb_sys_interface {
  915. - u32 snoop1;
  916. - u32 snoop2;
  917. - u32 age_cnt_thresh; /* Age Count Threshold Register */
  918. - u32 pri_ctrl; /* Priority Control Register */
  919. - u32 si_ctrl; /* System Interface Control Register */
  920. - u8 res[236];
  921. - u32 control; /* General Purpose Control Register */
  922. -};
  923. /* ep0 transfer state */
  924. #define WAIT_FOR_SETUP 0
  925. @@ -101,10 +91,6 @@ struct usb_sys_interface {
  926. #define WAIT_FOR_OUT_STATUS 3
  927. #define DATA_STATE_RECV 4
  928. -/* Device Controller Capability Parameter register */
  929. -#define DCCPARAMS_DC 0x00000080
  930. -#define DCCPARAMS_DEN_MASK 0x0000001f
  931. -
  932. /* Frame Index Register Bit Masks */
  933. #define USB_FRINDEX_MASKS 0x3fff
  934. /* USB CMD Register Bit Masks */
  935. @@ -180,172 +166,6 @@ struct usb_sys_interface {
  936. /* endpoint list address bit masks */
  937. #define USB_EP_LIST_ADDRESS_MASK 0xfffff800
  938. -/* PORTSCX Register Bit Masks */
  939. -#define PORTSCX_CURRENT_CONNECT_STATUS 0x00000001
  940. -#define PORTSCX_CONNECT_STATUS_CHANGE 0x00000002
  941. -#define PORTSCX_PORT_ENABLE 0x00000004
  942. -#define PORTSCX_PORT_EN_DIS_CHANGE 0x00000008
  943. -#define PORTSCX_OVER_CURRENT_ACT 0x00000010
  944. -#define PORTSCX_OVER_CURRENT_CHG 0x00000020
  945. -#define PORTSCX_PORT_FORCE_RESUME 0x00000040
  946. -#define PORTSCX_PORT_SUSPEND 0x00000080
  947. -#define PORTSCX_PORT_RESET 0x00000100
  948. -#define PORTSCX_LINE_STATUS_BITS 0x00000C00
  949. -#define PORTSCX_PORT_POWER 0x00001000
  950. -#define PORTSCX_PORT_INDICTOR_CTRL 0x0000C000
  951. -#define PORTSCX_PORT_TEST_CTRL 0x000F0000
  952. -#define PORTSCX_WAKE_ON_CONNECT_EN 0x00100000
  953. -#define PORTSCX_WAKE_ON_CONNECT_DIS 0x00200000
  954. -#define PORTSCX_WAKE_ON_OVER_CURRENT 0x00400000
  955. -#define PORTSCX_PHY_LOW_POWER_SPD 0x00800000
  956. -#define PORTSCX_PORT_FORCE_FULL_SPEED 0x01000000
  957. -#define PORTSCX_PORT_SPEED_MASK 0x0C000000
  958. -#define PORTSCX_PORT_WIDTH 0x10000000
  959. -#define PORTSCX_PHY_TYPE_SEL 0xC0000000
  960. -
  961. -/* bit 11-10 are line status */
  962. -#define PORTSCX_LINE_STATUS_SE0 0x00000000
  963. -#define PORTSCX_LINE_STATUS_JSTATE 0x00000400
  964. -#define PORTSCX_LINE_STATUS_KSTATE 0x00000800
  965. -#define PORTSCX_LINE_STATUS_UNDEF 0x00000C00
  966. -#define PORTSCX_LINE_STATUS_BIT_POS 10
  967. -
  968. -/* bit 15-14 are port indicator control */
  969. -#define PORTSCX_PIC_OFF 0x00000000
  970. -#define PORTSCX_PIC_AMBER 0x00004000
  971. -#define PORTSCX_PIC_GREEN 0x00008000
  972. -#define PORTSCX_PIC_UNDEF 0x0000C000
  973. -#define PORTSCX_PIC_BIT_POS 14
  974. -
  975. -/* bit 19-16 are port test control */
  976. -#define PORTSCX_PTC_DISABLE 0x00000000
  977. -#define PORTSCX_PTC_JSTATE 0x00010000
  978. -#define PORTSCX_PTC_KSTATE 0x00020000
  979. -#define PORTSCX_PTC_SEQNAK 0x00030000
  980. -#define PORTSCX_PTC_PACKET 0x00040000
  981. -#define PORTSCX_PTC_FORCE_EN 0x00050000
  982. -#define PORTSCX_PTC_BIT_POS 16
  983. -
  984. -/* bit 27-26 are port speed */
  985. -#define PORTSCX_PORT_SPEED_FULL 0x00000000
  986. -#define PORTSCX_PORT_SPEED_LOW 0x04000000
  987. -#define PORTSCX_PORT_SPEED_HIGH 0x08000000
  988. -#define PORTSCX_PORT_SPEED_UNDEF 0x0C000000
  989. -#define PORTSCX_SPEED_BIT_POS 26
  990. -
  991. -/* bit 28 is parallel transceiver width for UTMI interface */
  992. -#define PORTSCX_PTW 0x10000000
  993. -#define PORTSCX_PTW_8BIT 0x00000000
  994. -#define PORTSCX_PTW_16BIT 0x10000000
  995. -
  996. -/* bit 31-30 are port transceiver select */
  997. -#define PORTSCX_PTS_UTMI 0x00000000
  998. -#define PORTSCX_PTS_ULPI 0x80000000
  999. -#define PORTSCX_PTS_FSLS 0xC0000000
  1000. -#define PORTSCX_PTS_BIT_POS 30
  1001. -
  1002. -/* otgsc Register Bit Masks */
  1003. -#define OTGSC_CTRL_VUSB_DISCHARGE 0x00000001
  1004. -#define OTGSC_CTRL_VUSB_CHARGE 0x00000002
  1005. -#define OTGSC_CTRL_OTG_TERM 0x00000008
  1006. -#define OTGSC_CTRL_DATA_PULSING 0x00000010
  1007. -#define OTGSC_STS_USB_ID 0x00000100
  1008. -#define OTGSC_STS_A_VBUS_VALID 0x00000200
  1009. -#define OTGSC_STS_A_SESSION_VALID 0x00000400
  1010. -#define OTGSC_STS_B_SESSION_VALID 0x00000800
  1011. -#define OTGSC_STS_B_SESSION_END 0x00001000
  1012. -#define OTGSC_STS_1MS_TOGGLE 0x00002000
  1013. -#define OTGSC_STS_DATA_PULSING 0x00004000
  1014. -#define OTGSC_INTSTS_USB_ID 0x00010000
  1015. -#define OTGSC_INTSTS_A_VBUS_VALID 0x00020000
  1016. -#define OTGSC_INTSTS_A_SESSION_VALID 0x00040000
  1017. -#define OTGSC_INTSTS_B_SESSION_VALID 0x00080000
  1018. -#define OTGSC_INTSTS_B_SESSION_END 0x00100000
  1019. -#define OTGSC_INTSTS_1MS 0x00200000
  1020. -#define OTGSC_INTSTS_DATA_PULSING 0x00400000
  1021. -#define OTGSC_INTR_USB_ID 0x01000000
  1022. -#define OTGSC_INTR_A_VBUS_VALID 0x02000000
  1023. -#define OTGSC_INTR_A_SESSION_VALID 0x04000000
  1024. -#define OTGSC_INTR_B_SESSION_VALID 0x08000000
  1025. -#define OTGSC_INTR_B_SESSION_END 0x10000000
  1026. -#define OTGSC_INTR_1MS_TIMER 0x20000000
  1027. -#define OTGSC_INTR_DATA_PULSING 0x40000000
  1028. -
  1029. -/* USB MODE Register Bit Masks */
  1030. -#define USB_MODE_CTRL_MODE_IDLE 0x00000000
  1031. -#define USB_MODE_CTRL_MODE_DEVICE 0x00000002
  1032. -#define USB_MODE_CTRL_MODE_HOST 0x00000003
  1033. -#define USB_MODE_CTRL_MODE_RSV 0x00000001
  1034. -#define USB_MODE_SETUP_LOCK_OFF 0x00000008
  1035. -#define USB_MODE_STREAM_DISABLE 0x00000010
  1036. -/* Endpoint Flush Register */
  1037. -#define EPFLUSH_TX_OFFSET 0x00010000
  1038. -#define EPFLUSH_RX_OFFSET 0x00000000
  1039. -
  1040. -/* Endpoint Setup Status bit masks */
  1041. -#define EP_SETUP_STATUS_MASK 0x0000003F
  1042. -#define EP_SETUP_STATUS_EP0 0x00000001
  1043. -
  1044. -/* ENDPOINTCTRLx Register Bit Masks */
  1045. -#define EPCTRL_TX_ENABLE 0x00800000
  1046. -#define EPCTRL_TX_DATA_TOGGLE_RST 0x00400000 /* Not EP0 */
  1047. -#define EPCTRL_TX_DATA_TOGGLE_INH 0x00200000 /* Not EP0 */
  1048. -#define EPCTRL_TX_TYPE 0x000C0000
  1049. -#define EPCTRL_TX_DATA_SOURCE 0x00020000 /* Not EP0 */
  1050. -#define EPCTRL_TX_EP_STALL 0x00010000
  1051. -#define EPCTRL_RX_ENABLE 0x00000080
  1052. -#define EPCTRL_RX_DATA_TOGGLE_RST 0x00000040 /* Not EP0 */
  1053. -#define EPCTRL_RX_DATA_TOGGLE_INH 0x00000020 /* Not EP0 */
  1054. -#define EPCTRL_RX_TYPE 0x0000000C
  1055. -#define EPCTRL_RX_DATA_SINK 0x00000002 /* Not EP0 */
  1056. -#define EPCTRL_RX_EP_STALL 0x00000001
  1057. -
  1058. -/* bit 19-18 and 3-2 are endpoint type */
  1059. -#define EPCTRL_EP_TYPE_CONTROL 0
  1060. -#define EPCTRL_EP_TYPE_ISO 1
  1061. -#define EPCTRL_EP_TYPE_BULK 2
  1062. -#define EPCTRL_EP_TYPE_INTERRUPT 3
  1063. -#define EPCTRL_TX_EP_TYPE_SHIFT 18
  1064. -#define EPCTRL_RX_EP_TYPE_SHIFT 2
  1065. -
  1066. -/* SNOOPn Register Bit Masks */
  1067. -#define SNOOP_ADDRESS_MASK 0xFFFFF000
  1068. -#define SNOOP_SIZE_ZERO 0x00 /* snooping disable */
  1069. -#define SNOOP_SIZE_4KB 0x0B /* 4KB snoop size */
  1070. -#define SNOOP_SIZE_8KB 0x0C
  1071. -#define SNOOP_SIZE_16KB 0x0D
  1072. -#define SNOOP_SIZE_32KB 0x0E
  1073. -#define SNOOP_SIZE_64KB 0x0F
  1074. -#define SNOOP_SIZE_128KB 0x10
  1075. -#define SNOOP_SIZE_256KB 0x11
  1076. -#define SNOOP_SIZE_512KB 0x12
  1077. -#define SNOOP_SIZE_1MB 0x13
  1078. -#define SNOOP_SIZE_2MB 0x14
  1079. -#define SNOOP_SIZE_4MB 0x15
  1080. -#define SNOOP_SIZE_8MB 0x16
  1081. -#define SNOOP_SIZE_16MB 0x17
  1082. -#define SNOOP_SIZE_32MB 0x18
  1083. -#define SNOOP_SIZE_64MB 0x19
  1084. -#define SNOOP_SIZE_128MB 0x1A
  1085. -#define SNOOP_SIZE_256MB 0x1B
  1086. -#define SNOOP_SIZE_512MB 0x1C
  1087. -#define SNOOP_SIZE_1GB 0x1D
  1088. -#define SNOOP_SIZE_2GB 0x1E /* 2GB snoop size */
  1089. -
  1090. -/* pri_ctrl Register Bit Masks */
  1091. -#define PRI_CTRL_PRI_LVL1 0x0000000C
  1092. -#define PRI_CTRL_PRI_LVL0 0x00000003
  1093. -
  1094. -/* si_ctrl Register Bit Masks */
  1095. -#define SI_CTRL_ERR_DISABLE 0x00000010
  1096. -#define SI_CTRL_IDRC_DISABLE 0x00000008
  1097. -#define SI_CTRL_RD_SAFE_EN 0x00000004
  1098. -#define SI_CTRL_RD_PREFETCH_DISABLE 0x00000002
  1099. -#define SI_CTRL_RD_PREFEFETCH_VAL 0x00000001
  1100. -
  1101. -/* control Register Bit Masks */
  1102. -#define USB_CTRL_IOENB 0x00000004
  1103. -#define USB_CTRL_ULPI_INT0EN 0x00000001
  1104. /* Endpoint Queue Head data struct
  1105. * Rem: all the variables of qh are LittleEndian Mode
  1106. @@ -477,7 +297,10 @@ struct fsl_udc {
  1107. unsigned int irq;
  1108. struct usb_ctrlrequest local_setup_buff;
  1109. - spinlock_t lock;
  1110. + spinlock_t lock; /* udc lock */
  1111. + struct fsl_usb2_platform_data *pdata;
  1112. + u32 xcvr_type;
  1113. +
  1114. struct otg_transceiver *transceiver;
  1115. unsigned softconnect:1;
  1116. unsigned vbus_active:1;
  1117. @@ -514,7 +337,7 @@ struct fsl_udc {
  1118. #define DBG(fmt, args...) printk(KERN_DEBUG "[%s] " fmt "\n", \
  1119. __FUNCTION__, ## args)
  1120. #else
  1121. -#define DBG(fmt, args...) do{}while(0)
  1122. +#define DBG(fmt, args...) do {} while (0)
  1123. #endif
  1124. #if 0
  1125. @@ -548,7 +371,7 @@ static void dump_msg(const char *label,
  1126. #ifdef VERBOSE
  1127. #define VDBG DBG
  1128. #else
  1129. -#define VDBG(stuff...) do{}while(0)
  1130. +#define VDBG(stuff...) do {} while (0)
  1131. #endif
  1132. #define ERR(stuff...) pr_err("udc: " stuff)
  1133. @@ -573,11 +396,14 @@ static void dump_msg(const char *label,
  1134. #define ep_maxpacket(EP) ((EP)->ep.maxpacket)
  1135. #define ep_is_in(EP) ( (ep_index(EP) == 0) ? (EP->udc->ep0_dir == \
  1136. USB_DIR_IN ):((EP)->desc->bEndpointAddress \
  1137. - & USB_DIR_IN)==USB_DIR_IN)
  1138. + & USB_DIR_IN) == USB_DIR_IN)
  1139. #define get_ep_by_pipe(udc, pipe) ((pipe == 1)? &udc->eps[0]: \
  1140. &udc->eps[pipe])
  1141. #define get_pipe_by_windex(windex) ((windex & USB_ENDPOINT_NUMBER_MASK) \
  1142. * 2 + ((windex & USB_DIR_IN) ? 1 : 0))
  1143. #define get_pipe_by_ep(EP) (ep_index(EP) * 2 + ep_is_in(EP))
  1144. +/* Bulk only class request */
  1145. +#define USB_BULK_RESET_REQUEST 0xff
  1146. +
  1147. #endif
  1148. --- a/drivers/usb/gadget/gadget_chips.h
  1149. +++ b/drivers/usb/gadget/gadget_chips.h
  1150. @@ -147,6 +147,11 @@
  1151. #define gadget_is_m66592(g) 0
  1152. #endif
  1153. +#ifdef CONFIG_USB_GADGET_MCF5445X
  1154. +#define gadget_is_mcf5445x(g) !strcmp("fsl-usb2-udc", (g)->name)
  1155. +#else
  1156. +#define gadget_is_mcf5445x(g) 0
  1157. +#endif
  1158. // CONFIG_USB_GADGET_SX2
  1159. // CONFIG_USB_GADGET_AU1X00
  1160. @@ -212,5 +217,7 @@ static inline int usb_gadget_controller_
  1161. return 0x20;
  1162. else if (gadget_is_m66592(gadget))
  1163. return 0x21;
  1164. + else if (gadget_is_mcf5445x(gadget))
  1165. + return 0x22;
  1166. return -ENOENT;
  1167. }
  1168. --- /dev/null
  1169. +++ b/drivers/usb/gadget/mcf5445x_udc.c
  1170. @@ -0,0 +1,2758 @@
  1171. +/*
  1172. + * Copyright Freescale Semiconductor, Inc. 2006-2007
  1173. + *
  1174. + * Based on mpc_udc.c code
  1175. + * of Li Yang and Jiang Bo (Freescale Semiconductor, Inc.)
  1176. + *
  1177. + *
  1178. + * This program is free software; you can redistribute it and/or modify it
  1179. + * under the terms of the GNU General Public License as published by the
  1180. + * Free Software Foundation; either version 2 of the License, or (at your
  1181. + * option) any later version.
  1182. + *
  1183. + * This program is distributed in the hope that it will be useful,
  1184. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1185. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1186. + * GNU General Public License for more details.
  1187. + *
  1188. + * You should have received a copy of the GNU General Public License
  1189. + * along with this program; if not, write to the Free Software
  1190. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  1191. + *
  1192. + ***************************************************************************
  1193. + * Changes:
  1194. + * v0.004 30 July 2007 Duck
  1195. + * mcf5445x port
  1196. + * v0.003 27 October 2006 Andrey Butok
  1197. + * Added M5329EVB support (without external transceiver).
  1198. + * v0.002 29 September 2006 Andrey Butok
  1199. + * Some little changes. Added OTG support.
  1200. + * v0.001 12 July 2006 Andrey Butok
  1201. + * Initial Release - developed on uClinux with 2.6.17.1 kernel.
  1202. + * Based on mpc_udc.c code
  1203. + * of Li Yang and Jiang Bo (Freescale Semiconductor, Inc.)
  1204. + *
  1205. + */
  1206. +
  1207. +#define DEBUG
  1208. +#undef VERBOSE
  1209. +
  1210. +#include <linux/module.h>
  1211. +#include <linux/kernel.h>
  1212. +#include <linux/ioport.h>
  1213. +#include <linux/types.h>
  1214. +#include <linux/errno.h>
  1215. +#include <linux/delay.h>
  1216. +#include <linux/sched.h>
  1217. +#include <linux/slab.h>
  1218. +#include <linux/init.h>
  1219. +#include <linux/io.h>
  1220. +#include <linux/irq.h>
  1221. +#include <linux/timer.h>
  1222. +#include <linux/list.h>
  1223. +#include <linux/interrupt.h>
  1224. +#include <linux/proc_fs.h>
  1225. +#include <linux/mm.h>
  1226. +#include <linux/platform_device.h>
  1227. +#include <linux/moduleparam.h>
  1228. +#include <linux/device.h>
  1229. +#include <linux/usb/ch9.h>
  1230. +#include <linux/usb_gadget.h>
  1231. +#include <linux/usb/otg.h>
  1232. +#include <linux/dma-mapping.h>
  1233. +#include <linux/dmapool.h>
  1234. +#include <linux/fsl_devices.h>
  1235. +#include <linux/usb/fsl_xcvr.h>
  1236. +#include <linux/usb/fsl_usb2.h>
  1237. +#include <linux/pm.h>
  1238. +
  1239. +#include <asm/byteorder.h>
  1240. +#include <asm/system.h>
  1241. +#include <asm/unaligned.h>
  1242. +#include <asm/dma.h>
  1243. +
  1244. +#include <asm/mcfsim.h>
  1245. +#include <asm/cacheflush.h>
  1246. +
  1247. +#include "fsl_usb2_udc.h"
  1248. +
  1249. +#define DRIVER_DESC "Freescale High-Speed USB SoC Device Controller driver"
  1250. +#define DRIVER_AUTHOR "Freescale Semiconductor Inc."
  1251. +#define DRIVER_VERSION "30 July 2007"
  1252. +
  1253. +#define cpu_to_hc32(x) (x)
  1254. +#define hc32_to_cpu(x) (x)
  1255. +
  1256. +static int udc_suspend(struct fsl_udc *udc);
  1257. +
  1258. +#define DMA_ADDR_INVALID (~(dma_addr_t)0)
  1259. +
  1260. +static const char driver_name[] = "fsl-usb2-udc";
  1261. +static const char driver_desc[] = DRIVER_DESC;
  1262. +
  1263. +volatile static struct fsl_usb_device_regs *dr_regs;
  1264. +volatile static struct usb_sys_interface *usb_sys_regs;
  1265. +
  1266. +/* it is initialized in probe() */
  1267. +static struct fsl_udc *udc_controller;
  1268. +
  1269. +static const struct usb_endpoint_descriptor
  1270. +fsl_ep0_desc = {
  1271. + .bLength = USB_DT_ENDPOINT_SIZE,
  1272. + .bDescriptorType = USB_DT_ENDPOINT,
  1273. + .bEndpointAddress = 0,
  1274. + .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
  1275. + .wMaxPacketSize = USB_MAX_CTRL_PAYLOAD,
  1276. +};
  1277. +
  1278. +static int fsl_udc_suspend(struct device *dev, pm_message_t state);
  1279. +static int fsl_udc_resume(struct device *dev);
  1280. +static void fsl_ep_fifo_flush(struct usb_ep *_ep);
  1281. +
  1282. +/********************************************************************
  1283. + * Internal Used Function
  1284. +********************************************************************/
  1285. +/*-----------------------------------------------------------------
  1286. + * done() - retire a request; caller blocked irqs
  1287. + * @status : request status to be set, only works when
  1288. + * request is still in progress.
  1289. + *--------------------------------------------------------------*/
  1290. +static void done(struct fsl_ep *ep, struct fsl_req *req, int status)
  1291. +{
  1292. + struct fsl_udc *udc = NULL;
  1293. + unsigned char stopped = ep->stopped;
  1294. +
  1295. + udc = (struct fsl_udc *)ep->udc;
  1296. +
  1297. + pr_debug("udc: req=0x%p\n", req);
  1298. + if (req->head) {
  1299. + pr_debug("udc: freeing head=0x%p\n", req->head);
  1300. + dma_pool_free(udc->td_pool, req->head, req->head->td_dma);
  1301. + }
  1302. +
  1303. + /* the req->queue pointer is used by ep_queue() func, in which
  1304. + * the request will be added into a udc_ep->queue 'd tail
  1305. + * so here the req will be dropped from the ep->queue
  1306. + */
  1307. + list_del_init(&req->queue);
  1308. +
  1309. + /* req.status should be set as -EINPROGRESS in ep_queue() */
  1310. + if (req->req.status == -EINPROGRESS)
  1311. + req->req.status = status;
  1312. + else
  1313. + status = req->req.status;
  1314. +
  1315. + pr_debug("udc: req=0x%p mapped=%x\n", req, req->mapped);
  1316. +
  1317. + if (req->mapped) {
  1318. + pr_debug("udc: calling dma_unmap_single(buf,%s) req=0x%p "
  1319. + "a=0x%x len=%d\n",
  1320. + ep_is_in(ep) ? "to_dvc" : "from_dvc",
  1321. + req, req->req.dma, req->req.length);
  1322. +
  1323. + dma_unmap_single(ep->udc->gadget.dev.parent,
  1324. + req->req.dma, req->req.length, ep_is_in(ep) ?
  1325. + DMA_TO_DEVICE : DMA_FROM_DEVICE);
  1326. +
  1327. + req->req.dma = DMA_ADDR_INVALID;
  1328. + req->mapped = 0;
  1329. + pr_debug("udc: req=0x%p set req.dma=0x%x\n", req, req->req.dma);
  1330. + } else {
  1331. + if ((req->req.length != 0)
  1332. + && (req->req.dma != DMA_ADDR_INVALID)) {
  1333. + pr_debug("udc: calling dma_sync_single_for_cpu(buf,%s) "
  1334. + "req=0x%p dma=0x%x len=%d\n",
  1335. + ep_is_in(ep) ? "to_dvc" : "from_dvc", req,
  1336. + req->req.dma, req->req.length);
  1337. +
  1338. + dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
  1339. + req->req.dma, req->req.length,
  1340. + ep_is_in(ep) ? DMA_TO_DEVICE :
  1341. + DMA_FROM_DEVICE);
  1342. + }
  1343. + }
  1344. +
  1345. + if (status && (status != -ESHUTDOWN)) {
  1346. + pr_debug("udc: complete %s req 0c%p stat %d len %u/%u\n",
  1347. + ep->ep.name, &req->req, status,
  1348. + req->req.actual, req->req.length);
  1349. + }
  1350. +
  1351. + /* don't modify queue heads during completion callback */
  1352. + ep->stopped = 1;
  1353. +
  1354. + spin_unlock(&ep->udc->lock);
  1355. +
  1356. + /* this complete() should a func implemented by gadget layer,
  1357. + * eg fsg->bulk_in_complete() */
  1358. + if (req->req.complete) {
  1359. + pr_debug("udc: calling gadget's complete() req=0x%p\n", req);
  1360. + req->req.complete(&ep->ep, &req->req);
  1361. + pr_debug("udc: back from gadget's complete()\n");
  1362. + }
  1363. +
  1364. + spin_lock(&ep->udc->lock);
  1365. + ep->stopped = stopped;
  1366. +}
  1367. +
  1368. +/*
  1369. + * nuke(): delete all requests related to this ep
  1370. + * called with spinlock held
  1371. + *--------------------------------------------------------------*/
  1372. +static void nuke(struct fsl_ep *ep, int status)
  1373. +{
  1374. + ep->stopped = 1;
  1375. +
  1376. + /* Flush fifo */
  1377. + fsl_ep_fifo_flush(&ep->ep);
  1378. +
  1379. + /* Whether this eq has request linked */
  1380. + while (!list_empty(&ep->queue)) {
  1381. + struct fsl_req *req = NULL;
  1382. +
  1383. + req = list_entry(ep->queue.next, struct fsl_req, queue);
  1384. + done(ep, req, status);
  1385. + }
  1386. +}
  1387. +
  1388. +/*------------------------------------------------------------------
  1389. + Internal Hardware related function
  1390. + ------------------------------------------------------------------*/
  1391. +
  1392. +static int dr_controller_setup(struct fsl_udc *udc)
  1393. +{
  1394. + unsigned int tmp;
  1395. + unsigned int __attribute((unused)) ctrl = 0;
  1396. + unsigned long timeout;
  1397. + struct fsl_usb2_platform_data *pdata;
  1398. +
  1399. +#define FSL_UDC_RESET_TIMEOUT 1000
  1400. +
  1401. + /* before here, make sure dr_regs has been initialized */
  1402. + if (!udc)
  1403. + return -EINVAL;
  1404. + pdata = udc->pdata;
  1405. +
  1406. + /* Stop and reset the usb controller */
  1407. + tmp = fsl_readl(&dr_regs->usbcmd);
  1408. + tmp &= ~USB_CMD_RUN_STOP;
  1409. + fsl_writel(tmp, &dr_regs->usbcmd);
  1410. +
  1411. + tmp = fsl_readl(&dr_regs->usbcmd);
  1412. + tmp |= USB_CMD_CTRL_RESET;
  1413. + fsl_writel(tmp, &dr_regs->usbcmd);
  1414. +
  1415. + /* Wait for reset to complete */
  1416. + timeout = jiffies + FSL_UDC_RESET_TIMEOUT;
  1417. + while (fsl_readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) {
  1418. + if (time_after(jiffies, timeout)) {
  1419. + ERR("udc reset timeout! \n");
  1420. + return -ETIMEDOUT;
  1421. + }
  1422. + cpu_relax();
  1423. + }
  1424. +
  1425. + tmp = fsl_readl(&dr_regs->usbmode);
  1426. + tmp &= ~0x3; /* clear mode bits */
  1427. + tmp |= USB_MODE_CTRL_MODE_DEVICE;
  1428. + /* Disable Setup Lockout */
  1429. + tmp |= USB_MODE_SETUP_LOCK_OFF;
  1430. + if (pdata->es)
  1431. + tmp |= USBMODE_ES;
  1432. + fsl_writel(tmp, &dr_regs->usbmode);
  1433. +
  1434. + if (pdata->xcvr_ops && pdata->xcvr_ops->set_device)
  1435. + pdata->xcvr_ops->set_device();
  1436. +
  1437. + /* Clear the setup status */
  1438. + fsl_writel(0, &dr_regs->usbsts);
  1439. +
  1440. + tmp = udc->ep_qh_dma;
  1441. + tmp &= USB_EP_LIST_ADDRESS_MASK;
  1442. + fsl_writel(tmp, &dr_regs->endpointlistaddr);
  1443. +
  1444. + /*
  1445. + VDBG("vir[qh_base] is %p phy[qh_base] is 0x%8x reg is 0x%8x",
  1446. + (int)udc->ep_qh, (int)tmp,
  1447. + fsl_readl(&dr_regs->endpointlistaddr));
  1448. + */
  1449. +
  1450. +
  1451. + if (pdata->have_sysif_regs) {
  1452. + /* Config control enable i/o output, cpu endian register */
  1453. + ctrl = __raw_readl(&usb_sys_regs->control);
  1454. + ctrl |= USB_CTRL_IOENB;
  1455. + __raw_writel(ctrl, &usb_sys_regs->control);
  1456. + }
  1457. +
  1458. +#if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
  1459. + /* Turn on cache snooping hardware, since some PowerPC platforms
  1460. + * wholly rely on hardware to deal with cache coherent. */
  1461. +
  1462. + if (pdata->have_sysif_regs) {
  1463. + /* Setup Snooping for all the 4GB space */
  1464. + tmp = SNOOP_SIZE_2GB; /* starts from 0x0, size 2G */
  1465. + __raw_writel(tmp, &usb_sys_regs->snoop1);
  1466. + tmp |= 0x80000000; /* starts from 0x8000000, size 2G */
  1467. + __raw_writel(tmp, &usb_sys_regs->snoop2);
  1468. + }
  1469. +#endif
  1470. +
  1471. + return 0;
  1472. +}
  1473. +
  1474. +static void pullup_enable(struct fsl_udc *udc)
  1475. +{
  1476. + u32 temp;
  1477. +
  1478. + unsigned short ccm = fsl_readw(&MCF_CCM_UOCSR);
  1479. + ccm |= MCF_CCM_UOCSR_BVLD;
  1480. + ccm &= ~MCF_CCM_UOCSR_SEND;
  1481. + fsl_writew(ccm, &MCF_CCM_UOCSR);
  1482. +
  1483. + /* Enable DR irq reg */
  1484. + temp = USB_INTR_INT_EN | USB_INTR_ERR_INT_EN
  1485. + | USB_INTR_PTC_DETECT_EN | USB_INTR_RESET_EN
  1486. + | USB_INTR_DEVICE_SUSPEND | USB_INTR_SYS_ERR_EN;
  1487. +
  1488. + fsl_writel(temp, &dr_regs->usbintr);
  1489. +
  1490. + /* Set controller to Run */
  1491. + temp = fsl_readl(&dr_regs->usbcmd);
  1492. + temp |= USB_CMD_RUN_STOP;
  1493. + fsl_writel(temp, &dr_regs->usbcmd);
  1494. +
  1495. +#ifdef NEVER /* DDD FIXME: we want this? */
  1496. + if (!udc->transceiver)
  1497. + *((u16 *)(MCF_FBCS1_CSAR)) &= ~0x1; /* Enable pullup register */
  1498. +#endif
  1499. +}
  1500. +
  1501. +static void pullup_disable(struct fsl_udc *udc)
  1502. +{
  1503. + unsigned int tmp;
  1504. + unsigned short ccm;
  1505. +
  1506. + VDBG();
  1507. + /* disable all INTRs */
  1508. + fsl_writel(0, &dr_regs->usbintr);
  1509. +
  1510. + ccm = fsl_readw(&MCF_CCM_UOCSR);
  1511. + ccm &= ~MCF_CCM_UOCSR_BVLD;
  1512. + fsl_writew(ccm, &MCF_CCM_UOCSR);
  1513. +
  1514. + /* set controller to Stop */
  1515. + tmp = fsl_readl(&dr_regs->usbcmd);
  1516. + tmp &= ~USB_CMD_RUN_STOP;
  1517. + fsl_writel(tmp, &dr_regs->usbcmd);
  1518. +
  1519. +#ifdef NEVER /* DDD FIXME: we want this? */
  1520. + if (!udc->transceiver)
  1521. + *((u16 *)(MCF_FBCS1_CSAR)) |= 0x1; /* Disable pullup register */
  1522. +#endif
  1523. +
  1524. +}
  1525. +
  1526. +static void dr_controller_run(struct fsl_udc *udc)
  1527. +{
  1528. + VDBG();
  1529. + pullup_enable(udc);
  1530. + udc->stopped = 0;
  1531. +}
  1532. +
  1533. +static void dr_controller_stop(struct fsl_udc *udc)
  1534. +{
  1535. + pullup_disable(udc);
  1536. + udc->stopped = 1;
  1537. + udc->gadget.b_hnp_enable = 0;
  1538. + udc->gadget.a_hnp_support = 0;
  1539. + udc->gadget.a_alt_hnp_support = 0;
  1540. +}
  1541. +
  1542. +void dr_ep_setup(unsigned char ep_num, unsigned char dir, unsigned char ep_type)
  1543. +{
  1544. + unsigned int tmp_epctrl = 0;
  1545. +
  1546. + tmp_epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
  1547. + if (dir) {
  1548. + if (ep_num)
  1549. + tmp_epctrl |= EPCTRL_TX_DATA_TOGGLE_RST;
  1550. + tmp_epctrl |= EPCTRL_TX_ENABLE;
  1551. + tmp_epctrl |= ((unsigned int)(ep_type)
  1552. + << EPCTRL_TX_EP_TYPE_SHIFT);
  1553. + } else {
  1554. + if (ep_num)
  1555. + tmp_epctrl |= EPCTRL_RX_DATA_TOGGLE_RST;
  1556. + tmp_epctrl |= EPCTRL_RX_ENABLE;
  1557. + tmp_epctrl |= ((unsigned int)(ep_type)
  1558. + << EPCTRL_RX_EP_TYPE_SHIFT);
  1559. + }
  1560. +
  1561. + fsl_writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
  1562. +}
  1563. +
  1564. +static void dr_ep_change_stall(unsigned char ep_num, unsigned char dir,
  1565. + int value)
  1566. +{
  1567. + u32 tmp_epctrl = 0;
  1568. +
  1569. + tmp_epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
  1570. +
  1571. + if (value) {
  1572. + /* set the stall bit */
  1573. + if (dir)
  1574. + tmp_epctrl |= EPCTRL_TX_EP_STALL;
  1575. + else
  1576. + tmp_epctrl |= EPCTRL_RX_EP_STALL;
  1577. + } else {
  1578. + /* clear the stall bit and reset data toggle */
  1579. + if (dir) {
  1580. + tmp_epctrl &= ~EPCTRL_TX_EP_STALL;
  1581. + tmp_epctrl |= EPCTRL_TX_DATA_TOGGLE_RST;
  1582. + } else {
  1583. + tmp_epctrl &= ~EPCTRL_RX_EP_STALL;
  1584. + tmp_epctrl |= EPCTRL_RX_DATA_TOGGLE_RST;
  1585. + }
  1586. + }
  1587. + fsl_writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
  1588. +}
  1589. +
  1590. +/* Get stall status of a specific ep
  1591. + Return: 0: not stalled; 1:stalled */
  1592. +static int dr_ep_get_stall(unsigned char ep_num, unsigned char dir)
  1593. +{
  1594. + u32 epctrl;
  1595. +
  1596. + epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
  1597. + if (dir)
  1598. + return (epctrl & EPCTRL_TX_EP_STALL) ? 1 : 0;
  1599. + else
  1600. + return (epctrl & EPCTRL_RX_EP_STALL) ? 1 : 0;
  1601. +}
  1602. +
  1603. +/********************************************************************
  1604. + Internal Structure Build up functions
  1605. +********************************************************************/
  1606. +
  1607. +/*------------------------------------------------------------------
  1608. +* struct_ep_qh_setup(): set the Endpoint Capabilites field of QH
  1609. + * @zlt: Zero Length Termination Select (1: disable; 0: enable)
  1610. + * @mult: Mult field
  1611. + ------------------------------------------------------------------*/
  1612. +static void struct_ep_qh_setup(struct fsl_udc *udc, unsigned char ep_num,
  1613. + unsigned char dir, unsigned char ep_type,
  1614. + unsigned int max_pkt_len,
  1615. + unsigned int zlt, unsigned char mult)
  1616. +{
  1617. + struct ep_queue_head *p_QH = &udc->ep_qh[2 * ep_num + dir];
  1618. + unsigned int tmp = 0;
  1619. +
  1620. + /* set the Endpoint Capabilites in QH */
  1621. + switch (ep_type) {
  1622. + case USB_ENDPOINT_XFER_CONTROL:
  1623. + /* Interrupt On Setup (IOS). for control ep */
  1624. + tmp = (max_pkt_len << EP_QUEUE_HEAD_MAX_PKT_LEN_POS)
  1625. + | EP_QUEUE_HEAD_IOS;
  1626. + break;
  1627. + case USB_ENDPOINT_XFER_ISOC:
  1628. + tmp = (max_pkt_len << EP_QUEUE_HEAD_MAX_PKT_LEN_POS)
  1629. + | (mult << EP_QUEUE_HEAD_MULT_POS);
  1630. + break;
  1631. + case USB_ENDPOINT_XFER_BULK:
  1632. + case USB_ENDPOINT_XFER_INT:
  1633. + tmp = max_pkt_len << EP_QUEUE_HEAD_MAX_PKT_LEN_POS;
  1634. + break;
  1635. + default:
  1636. + VDBG("error ep type is %d", ep_type);
  1637. + return;
  1638. + }
  1639. + if (zlt)
  1640. + tmp |= EP_QUEUE_HEAD_ZLT_SEL;
  1641. + p_QH->max_pkt_length = cpu_to_hc32(tmp);
  1642. +
  1643. + return;
  1644. +}
  1645. +
  1646. +/* Setup qh structure and ep register for ep0. */
  1647. +static void ep0_setup(struct fsl_udc *udc)
  1648. +{
  1649. + /* the intialization of an ep includes: fields in QH, Regs,
  1650. + * fsl_ep struct */
  1651. + struct_ep_qh_setup(udc, 0, USB_RECV, USB_ENDPOINT_XFER_CONTROL,
  1652. + USB_MAX_CTRL_PAYLOAD, 0, 0);
  1653. + struct_ep_qh_setup(udc, 0, USB_SEND, USB_ENDPOINT_XFER_CONTROL,
  1654. + USB_MAX_CTRL_PAYLOAD, 0, 0);
  1655. + dr_ep_setup(0, USB_RECV, USB_ENDPOINT_XFER_CONTROL);
  1656. + dr_ep_setup(0, USB_SEND, USB_ENDPOINT_XFER_CONTROL);
  1657. +
  1658. + return;
  1659. +
  1660. +}
  1661. +
  1662. +/***********************************************************************
  1663. + Endpoint Management Functions
  1664. +***********************************************************************/
  1665. +
  1666. +/*-------------------------------------------------------------------------
  1667. + * when configurations are set, or when interface settings change
  1668. + * for example the do_set_interface() in gadget layer,
  1669. + * the driver will enable or disable the relevant endpoints
  1670. + * ep0 doesn't use this routine. It is always enabled.
  1671. +-------------------------------------------------------------------------*/
  1672. +static int fsl_ep_enable(struct usb_ep *_ep,
  1673. + const struct usb_endpoint_descriptor *desc)
  1674. +{
  1675. + struct fsl_udc *udc = NULL;
  1676. + struct fsl_ep *ep = NULL;
  1677. + unsigned short max = 0;
  1678. + unsigned char mult = 0, zlt;
  1679. + int retval = -EINVAL;
  1680. + unsigned long flags = 0;
  1681. +
  1682. + ep = container_of(_ep, struct fsl_ep, ep);
  1683. +
  1684. + /* catch various bogus parameters */
  1685. + if (!_ep || !desc || ep->desc
  1686. + || (desc->bDescriptorType != USB_DT_ENDPOINT))
  1687. + return -EINVAL;
  1688. +
  1689. + udc = ep->udc;
  1690. +
  1691. + if (!udc->driver || (udc->gadget.speed == USB_SPEED_UNKNOWN))
  1692. + return -ESHUTDOWN;
  1693. +
  1694. + max = le16_to_cpu(desc->wMaxPacketSize);
  1695. +
  1696. + /* Disable automatic zlp generation. Driver is reponsible to indicate
  1697. + * explicitly through req->req.zero. This is needed to enable multi-td
  1698. + * request. */
  1699. + zlt = 1;
  1700. +
  1701. + /* Assume the max packet size from gadget is always correct */
  1702. + switch (desc->bmAttributes & 0x03) {
  1703. + case USB_ENDPOINT_XFER_CONTROL:
  1704. + case USB_ENDPOINT_XFER_BULK:
  1705. + case USB_ENDPOINT_XFER_INT:
  1706. + /* mult = 0. Execute N Transactions as demonstrated by
  1707. + * the USB variable length packet protocol where N is
  1708. + * computed using the Maximum Packet Length (dQH) and
  1709. + * the Total Bytes field (dTD) */
  1710. + mult = 0;
  1711. + break;
  1712. + case USB_ENDPOINT_XFER_ISOC:
  1713. + /* Calculate transactions needed for high bandwidth iso */
  1714. + mult = (unsigned char)(1 + ((max >> 11) & 0x03));
  1715. + max = max & 0x8ff; /* bit 0~10 */
  1716. + /* 3 transactions at most */
  1717. + if (mult > 3)
  1718. + goto en_done;
  1719. + break;
  1720. + default:
  1721. + goto en_done;
  1722. + }
  1723. +
  1724. + spin_lock_irqsave(&udc->lock, flags);
  1725. + ep->ep.maxpacket = max;
  1726. + ep->desc = desc;
  1727. + ep->stopped = 0;
  1728. +
  1729. + /* Controller related setup */
  1730. + /* Init EPx Queue Head (Ep Capabilites field in QH
  1731. + * according to max, zlt, mult) */
  1732. + struct_ep_qh_setup(udc, (unsigned char) ep_index(ep),
  1733. + (unsigned char) ((desc->bEndpointAddress & USB_DIR_IN)
  1734. + ? USB_SEND : USB_RECV),
  1735. + (unsigned char) (desc->bmAttributes
  1736. + & USB_ENDPOINT_XFERTYPE_MASK),
  1737. + max, zlt, mult);
  1738. +
  1739. + /* Init endpoint ctrl register */
  1740. + dr_ep_setup((unsigned char) ep_index(ep),
  1741. + (unsigned char) ((desc->bEndpointAddress & USB_DIR_IN)
  1742. + ? USB_SEND : USB_RECV),
  1743. + (unsigned char) (desc->bmAttributes
  1744. + & USB_ENDPOINT_XFERTYPE_MASK));
  1745. +
  1746. + spin_unlock_irqrestore(&udc->lock, flags);
  1747. + retval = 0;
  1748. +
  1749. + VDBG("enabled %s (ep%d%s) maxpacket %d", ep->ep.name,
  1750. + ep->desc->bEndpointAddress & 0x0f,
  1751. + (desc->bEndpointAddress & USB_DIR_IN)
  1752. + ? "in" : "out", max);
  1753. +en_done:
  1754. + return retval;
  1755. +}
  1756. +
  1757. +/*---------------------------------------------------------------------
  1758. + * @ep : the ep being unconfigured. May not be ep0
  1759. + * Any pending and uncomplete req will complete with status (-ESHUTDOWN)
  1760. +*---------------------------------------------------------------------*/
  1761. +static int fsl_ep_disable(struct usb_ep *_ep)
  1762. +{
  1763. + struct fsl_udc *udc = NULL;
  1764. + struct fsl_ep *ep = NULL;
  1765. + unsigned long flags = 0;
  1766. + u32 epctrl;
  1767. + int ep_num;
  1768. +
  1769. + ep = container_of(_ep, struct fsl_ep, ep);
  1770. + if (!_ep || !ep->desc) {
  1771. + pr_debug("udc: %s not enabled\n", _ep ? ep->ep.name : NULL);
  1772. + return -EINVAL;
  1773. + }
  1774. +
  1775. + /* disable ep on controller */
  1776. + ep_num = ep_index(ep);
  1777. + epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
  1778. + if (ep_is_in(ep))
  1779. + epctrl &= ~EPCTRL_TX_ENABLE;
  1780. + else
  1781. + epctrl &= ~EPCTRL_RX_ENABLE;
  1782. + fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
  1783. +
  1784. + udc = (struct fsl_udc *)ep->udc;
  1785. + spin_lock_irqsave(&udc->lock, flags);
  1786. +
  1787. + /* nuke all pending requests (does flush) */
  1788. + nuke(ep, -ESHUTDOWN);
  1789. +
  1790. + ep->desc = 0;
  1791. + ep->stopped = 1;
  1792. + spin_unlock_irqrestore(&udc->lock, flags);
  1793. +
  1794. + pr_debug("udc: disabled %s OK\n", _ep->name);
  1795. + return 0;
  1796. +}
  1797. +
  1798. +/*---------------------------------------------------------------------
  1799. + * allocate a request object used by this endpoint
  1800. + * the main operation is to insert the req->queue to the eq->queue
  1801. + * Returns the request, or null if one could not be allocated
  1802. +*---------------------------------------------------------------------*/
  1803. +static struct usb_request *
  1804. +fsl_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
  1805. +{
  1806. + struct fsl_req *req = NULL;
  1807. +
  1808. + req = kzalloc(sizeof *req, gfp_flags);
  1809. + if (!req)
  1810. + return NULL;
  1811. +
  1812. + req->req.dma = DMA_ADDR_INVALID;
  1813. + pr_debug("udc: req=0x%p set req.dma=0x%x\n", req, req->req.dma);
  1814. + INIT_LIST_HEAD(&req->queue);
  1815. +
  1816. + return &req->req;
  1817. +}
  1818. +
  1819. +static void fsl_free_request(struct usb_ep *_ep, struct usb_request *_req)
  1820. +{
  1821. + struct fsl_req *req;
  1822. +
  1823. + req = container_of(_req, struct fsl_req, req);
  1824. + pr_debug("udc: req=0x%p\n", req);
  1825. +
  1826. + if (_req)
  1827. + kfree(req);
  1828. +}
  1829. +
  1830. +/*-------------------------------------------------------------------------*/
  1831. +static int fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
  1832. +{
  1833. + int i = ep_index(ep) * 2 + ep_is_in(ep);
  1834. + u32 temp, bitmask, tmp_stat;
  1835. + struct ep_queue_head *dQH = &ep->udc->ep_qh[i];
  1836. +
  1837. + pr_debug("udc: queue req=0x%p to ep index %d\n", req, i);
  1838. +
  1839. + bitmask = ep_is_in(ep)
  1840. + ? (1 << (ep_index(ep) + 16))
  1841. + : (1 << (ep_index(ep)));
  1842. +
  1843. + /* check if the pipe is empty */
  1844. + if (!(list_empty(&ep->queue))) {
  1845. + /* Add td to the end */
  1846. + struct fsl_req *lastreq;
  1847. + lastreq = list_entry(ep->queue.prev, struct fsl_req, queue);
  1848. + lastreq->tail->next_td_ptr =
  1849. + cpu_to_hc32(req->head->td_dma & DTD_ADDR_MASK);
  1850. + /* Read prime bit, if 1 goto done */
  1851. + if (fsl_readl(&dr_regs->endpointprime) & bitmask)
  1852. + goto out;
  1853. +
  1854. + do {
  1855. + /* Set ATDTW bit in USBCMD */
  1856. + temp = fsl_readl(&dr_regs->usbcmd);
  1857. + fsl_writel(temp | USB_CMD_ATDTW, &dr_regs->usbcmd);
  1858. +
  1859. + /* Read correct status bit */
  1860. + tmp_stat = fsl_readl(&dr_regs->endptstatus) & bitmask;
  1861. +
  1862. + } while (!(fsl_readl(&dr_regs->usbcmd) & USB_CMD_ATDTW));
  1863. +
  1864. + /* Write ATDTW bit to 0 */
  1865. + temp = fsl_readl(&dr_regs->usbcmd);
  1866. + fsl_writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd);
  1867. +
  1868. + if (tmp_stat)
  1869. + goto out;
  1870. + }
  1871. +
  1872. + /* Write dQH next pointer and terminate bit to 0 */
  1873. + temp = req->head->td_dma & EP_QUEUE_HEAD_NEXT_POINTER_MASK;
  1874. + dQH->next_dtd_ptr = cpu_to_hc32(temp);
  1875. +
  1876. + /* Clear active and halt bit */
  1877. + temp = cpu_to_hc32(~(EP_QUEUE_HEAD_STATUS_ACTIVE
  1878. + | EP_QUEUE_HEAD_STATUS_HALT));
  1879. + dQH->size_ioc_int_sts &= temp;
  1880. +
  1881. + /* Prime endpoint by writing 1 to ENDPTPRIME */
  1882. + temp = ep_is_in(ep)
  1883. + ? (1 << (ep_index(ep) + 16))
  1884. + : (1 << (ep_index(ep)));
  1885. + fsl_writel(temp, &dr_regs->endpointprime);
  1886. +out:
  1887. + return 0;
  1888. +}
  1889. +
  1890. +/* Fill in the dTD structure
  1891. + * @req: request that the transfer belongs to
  1892. + * @length: return actually data length of the dTD
  1893. + * @dma: return dma address of the dTD
  1894. + * @is_last: return flag if it is the last dTD of the request
  1895. + * return: pointer to the built dTD */
  1896. +static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
  1897. + dma_addr_t *dma, int *is_last)
  1898. +{
  1899. + u32 swap_temp;
  1900. + struct ep_td_struct *dtd;
  1901. +
  1902. + /* how big will this transfer be? */
  1903. + *length = min(req->req.length - req->req.actual,
  1904. + (unsigned)EP_MAX_LENGTH_TRANSFER);
  1905. +
  1906. + dtd = dma_pool_alloc(udc_controller->td_pool, GFP_KERNEL, dma);
  1907. + if (dtd == NULL)
  1908. + return dtd;
  1909. +
  1910. + dtd->td_dma = *dma;
  1911. + /* Clear reserved field */
  1912. + swap_temp = hc32_to_cpu(dtd->size_ioc_sts);
  1913. + swap_temp &= ~DTD_RESERVED_FIELDS;
  1914. + dtd->size_ioc_sts = cpu_to_hc32(swap_temp);
  1915. +
  1916. + /* Init all of buffer page pointers */
  1917. + swap_temp = (u32) (req->req.dma + req->req.actual);
  1918. + dtd->buff_ptr0 = cpu_to_hc32(swap_temp);
  1919. + dtd->buff_ptr1 = cpu_to_hc32(swap_temp + 0x1000);
  1920. + dtd->buff_ptr2 = cpu_to_hc32(swap_temp + 0x2000);
  1921. + dtd->buff_ptr3 = cpu_to_hc32(swap_temp + 0x3000);
  1922. + dtd->buff_ptr4 = cpu_to_hc32(swap_temp + 0x4000);
  1923. +
  1924. + req->req.actual += *length;
  1925. +
  1926. + /* zlp is needed if req->req.zero is set */
  1927. + if (req->req.zero) {
  1928. + if (*length == 0 || (*length % req->ep->ep.maxpacket) != 0)
  1929. + *is_last = 1;
  1930. + else
  1931. + *is_last = 0;
  1932. + } else if (req->req.length == req->req.actual)
  1933. + *is_last = 1;
  1934. + else
  1935. + *is_last = 0;
  1936. +
  1937. + if ((*is_last) == 0)
  1938. + VDBG("multi-dtd request!\n");
  1939. + /* Fill in the transfer size; set active bit */
  1940. + swap_temp = ((*length << DTD_LENGTH_BIT_POS) | DTD_STATUS_ACTIVE);
  1941. +
  1942. + /* Enable interrupt for the last dtd of a request */
  1943. + if (*is_last && !req->req.no_interrupt)
  1944. + swap_temp |= DTD_IOC;
  1945. +
  1946. + dtd->size_ioc_sts = cpu_to_hc32(swap_temp);
  1947. +
  1948. + mb();
  1949. +
  1950. + VDBG("length = %d address= 0x%x", *length, (int)*dma);
  1951. +
  1952. + return dtd;
  1953. +}
  1954. +
  1955. +/* Generate dtd chain for a request */
  1956. +static int fsl_req_to_dtd(struct fsl_req *req)
  1957. +{
  1958. + unsigned count;
  1959. + int is_last;
  1960. + int is_first = 1;
  1961. + struct ep_td_struct *last_dtd = NULL, *dtd;
  1962. + dma_addr_t dma;
  1963. +
  1964. + do {
  1965. + dtd = fsl_build_dtd(req, &count, &dma, &is_last);
  1966. + if (dtd == NULL)
  1967. + return -ENOMEM;
  1968. +
  1969. + if (is_first) {
  1970. + is_first = 0;
  1971. + req->head = dtd;
  1972. + } else {
  1973. + last_dtd->next_td_ptr = hc32_to_cpu(dma);
  1974. + last_dtd->next_td_virt = dtd;
  1975. + }
  1976. + last_dtd = dtd;
  1977. +
  1978. + req->dtd_count++;
  1979. + } while (!is_last);
  1980. +
  1981. + dtd->next_td_ptr = cpu_to_hc32(DTD_NEXT_TERMINATE);
  1982. +
  1983. + req->tail = dtd;
  1984. +
  1985. + return 0;
  1986. +}
  1987. +
  1988. +/* queues (submits) an I/O request to an endpoint */
  1989. +static int
  1990. +fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
  1991. +{
  1992. + struct fsl_ep *ep = container_of(_ep, struct fsl_ep, ep);
  1993. + struct fsl_req *req = container_of(_req, struct fsl_req, req);
  1994. + struct fsl_udc *udc;
  1995. + unsigned long flags;
  1996. + int is_iso = 0;
  1997. +
  1998. + /* catch various bogus parameters */
  1999. + if (!_req || !req->req.complete || !req->req.buf
  2000. + || !list_empty(&req->queue)) {
  2001. + VDBG("%s, bad params\n", __FUNCTION__);
  2002. + return -EINVAL;
  2003. + }
  2004. + if (!_ep || (!ep->desc && ep_index(ep))) {
  2005. + VDBG("%s, bad ep\n", __FUNCTION__);
  2006. + return -EINVAL;
  2007. + }
  2008. + if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
  2009. + if (req->req.length > ep->ep.maxpacket)
  2010. + return -EMSGSIZE;
  2011. + is_iso = 1;
  2012. + }
  2013. +
  2014. + udc = ep->udc;
  2015. + if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN)
  2016. + return -ESHUTDOWN;
  2017. +
  2018. + req->ep = ep;
  2019. +
  2020. + /* map virtual address to hardware */
  2021. + if (req->req.dma == DMA_ADDR_INVALID) {
  2022. + req->req.dma = dma_map_single(ep->udc->gadget.dev.parent,
  2023. + req->req.buf,
  2024. + req->req.length, ep_is_in(ep)
  2025. + ? DMA_TO_DEVICE
  2026. + : DMA_FROM_DEVICE);
  2027. + req->mapped = 1;
  2028. + } else {
  2029. + dma_sync_single_for_device(ep->udc->gadget.dev.parent,
  2030. + req->req.dma, req->req.length,
  2031. + ep_is_in(ep)
  2032. + ? DMA_TO_DEVICE
  2033. + : DMA_FROM_DEVICE);
  2034. + req->mapped = 0;
  2035. + }
  2036. +
  2037. + req->req.status = -EINPROGRESS;
  2038. + req->req.actual = 0;
  2039. + req->dtd_count = 0;
  2040. +
  2041. + spin_lock_irqsave(&udc->lock, flags);
  2042. +
  2043. + /* build dtds and push them to device queue */
  2044. + if (!fsl_req_to_dtd(req)) {
  2045. + fsl_queue_td(ep, req);
  2046. + } else {
  2047. + spin_unlock_irqrestore(&udc->lock, flags);
  2048. + return -ENOMEM;
  2049. + }
  2050. +
  2051. + /* Update ep0 state */
  2052. + if ((ep_index(ep) == 0))
  2053. + udc->ep0_state = DATA_STATE_XMIT;
  2054. +
  2055. + /* irq handler advances the queue */
  2056. + if (req != NULL)
  2057. + list_add_tail(&req->queue, &ep->queue);
  2058. + spin_unlock_irqrestore(&udc->lock, flags);
  2059. +
  2060. + return 0;
  2061. +}
  2062. +
  2063. +/* dequeues (cancels, unlinks) an I/O request from an endpoint */
  2064. +static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
  2065. +{
  2066. + struct fsl_ep *ep = container_of(_ep, struct fsl_ep, ep);
  2067. + struct fsl_req *req;
  2068. + unsigned long flags;
  2069. + int ep_num, stopped, ret = 0;
  2070. + u32 epctrl;
  2071. +
  2072. + if (!_ep || !_req)
  2073. + return -EINVAL;
  2074. +
  2075. + spin_lock_irqsave(&ep->udc->lock, flags);
  2076. + stopped = ep->stopped;
  2077. +
  2078. + /* Stop the ep before we deal with the queue */
  2079. + ep->stopped = 1;
  2080. + ep_num = ep_index(ep);
  2081. + epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
  2082. + if (ep_is_in(ep))
  2083. + epctrl &= ~EPCTRL_TX_ENABLE;
  2084. + else
  2085. + epctrl &= ~EPCTRL_RX_ENABLE;
  2086. + fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
  2087. +
  2088. + /* make sure it's actually queued on this endpoint */
  2089. + list_for_each_entry(req, &ep->queue, queue) {
  2090. + if (&req->req == _req)
  2091. + break;
  2092. + }
  2093. + if (&req->req != _req) {
  2094. + ret = -EINVAL;
  2095. + goto out;
  2096. + }
  2097. +
  2098. + /* The request is in progress, or completed but not dequeued */
  2099. + if (ep->queue.next == &req->queue) {
  2100. + _req->status = -ECONNRESET;
  2101. + fsl_ep_fifo_flush(_ep); /* flush current transfer */
  2102. +
  2103. + /* The request isn't the last request in this ep queue */
  2104. + if (req->queue.next != &ep->queue) {
  2105. + struct ep_queue_head *qh;
  2106. + struct fsl_req *next_req;
  2107. +
  2108. + qh = ep->qh;
  2109. + next_req = list_entry(req->queue.next, struct fsl_req,
  2110. + queue);
  2111. +
  2112. + /* Point the QH to the first TD of next request */
  2113. + fsl_writel((u32) next_req->head, &qh->curr_dtd_ptr);
  2114. + }
  2115. +
  2116. + /* The request hasn't been processed, patch up the TD chain */
  2117. + } else {
  2118. + struct fsl_req *prev_req;
  2119. +
  2120. + prev_req = list_entry(req->queue.prev, struct fsl_req, queue);
  2121. + fsl_writel(fsl_readl(&req->tail->next_td_ptr),
  2122. + &prev_req->tail->next_td_ptr);
  2123. +
  2124. + }
  2125. +
  2126. + done(ep, req, -ECONNRESET);
  2127. +
  2128. + /* Enable EP */
  2129. +out: epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
  2130. + if (ep_is_in(ep))
  2131. + epctrl |= EPCTRL_TX_ENABLE;
  2132. + else
  2133. + epctrl |= EPCTRL_RX_ENABLE;
  2134. + fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
  2135. + ep->stopped = stopped;
  2136. +
  2137. + spin_unlock_irqrestore(&ep->udc->lock, flags);
  2138. + return ret;
  2139. +}
  2140. +
  2141. +/*-------------------------------------------------------------------------*/
  2142. +
  2143. +/*-----------------------------------------------------------------
  2144. + * modify the endpoint halt feature
  2145. + * @ep: the non-isochronous endpoint being stalled
  2146. + * @value: 1--set halt 0--clear halt
  2147. + * Returns zero, or a negative error code.
  2148. +*----------------------------------------------------------------*/
  2149. +static int fsl_ep_set_halt(struct usb_ep *_ep, int value)
  2150. +{
  2151. + struct fsl_ep *ep = NULL;
  2152. + unsigned long flags = 0;
  2153. + int status = -EOPNOTSUPP; /* operation not supported */
  2154. + unsigned char ep_dir = 0, ep_num = 0;
  2155. + struct fsl_udc *udc = NULL;
  2156. +
  2157. + ep = container_of(_ep, struct fsl_ep, ep);
  2158. + udc = ep->udc;
  2159. + if (!_ep || !ep->desc) {
  2160. + status = -EINVAL;
  2161. + goto out;
  2162. + }
  2163. +
  2164. + if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
  2165. + status = -EOPNOTSUPP;
  2166. + goto out;
  2167. + }
  2168. +
  2169. + /* Attempt to halt IN ep will fail if any transfer requests
  2170. + * are still queue */
  2171. + if (value && ep_is_in(ep) && !list_empty(&ep->queue)) {
  2172. + status = -EAGAIN;
  2173. + goto out;
  2174. + }
  2175. +
  2176. + status = 0;
  2177. + ep_dir = ep_is_in(ep) ? USB_SEND : USB_RECV;
  2178. + ep_num = (unsigned char)(ep_index(ep));
  2179. + spin_lock_irqsave(&ep->udc->lock, flags);
  2180. + dr_ep_change_stall(ep_num, ep_dir, value);
  2181. + spin_unlock_irqrestore(&ep->udc->lock, flags);
  2182. +
  2183. + if (ep_index(ep) == 0) {
  2184. + udc->ep0_state = WAIT_FOR_SETUP;
  2185. + udc->ep0_dir = 0;
  2186. + }
  2187. +out:
  2188. + VDBG(" %s %s halt stat %d", ep->ep.name,
  2189. + value ? "set" : "clear", status);
  2190. +
  2191. + return status;
  2192. +}
  2193. +
  2194. +static void fsl_ep_fifo_flush(struct usb_ep *_ep)
  2195. +{
  2196. + struct fsl_ep *ep;
  2197. + int ep_num, ep_dir;
  2198. + u32 bits;
  2199. + unsigned long timeout;
  2200. +#define FSL_UDC_FLUSH_TIMEOUT 1000
  2201. +
  2202. + if (!_ep) {
  2203. + return;
  2204. + } else {
  2205. + ep = container_of(_ep, struct fsl_ep, ep);
  2206. + if (!ep->desc)
  2207. + return;
  2208. + }
  2209. + ep_num = ep_index(ep);
  2210. + ep_dir = ep_is_in(ep) ? USB_SEND : USB_RECV;
  2211. +
  2212. + if (ep_num == 0)
  2213. + bits = (1 << 16) | 1;
  2214. + else if (ep_dir == USB_SEND)
  2215. + bits = 1 << (16 + ep_num);
  2216. + else
  2217. + bits = 1 << ep_num;
  2218. +
  2219. + timeout = jiffies + FSL_UDC_FLUSH_TIMEOUT;
  2220. + do {
  2221. + fsl_writel(bits, &dr_regs->endptflush);
  2222. +
  2223. + /* Wait until flush complete */
  2224. + while (fsl_readl(&dr_regs->endptflush)) {
  2225. + if (time_after(jiffies, timeout)) {
  2226. + ERR("ep flush timeout\n");
  2227. + return;
  2228. + }
  2229. + cpu_relax();
  2230. + }
  2231. + /* See if we need to flush again */
  2232. + } while (fsl_readl(&dr_regs->endptstatus) & bits);
  2233. +}
  2234. +
  2235. +static struct usb_ep_ops fsl_ep_ops = {
  2236. + .enable = fsl_ep_enable,
  2237. + .disable = fsl_ep_disable,
  2238. +
  2239. + .alloc_request = fsl_alloc_request,
  2240. + .free_request = fsl_free_request,
  2241. +
  2242. + .queue = fsl_ep_queue,
  2243. + .dequeue = fsl_ep_dequeue,
  2244. +
  2245. + .set_halt = fsl_ep_set_halt,
  2246. + .fifo_flush = fsl_ep_fifo_flush, /* flush fifo */
  2247. +};
  2248. +
  2249. +/*-------------------------------------------------------------------------
  2250. + Gadget Driver Layer Operations
  2251. +-------------------------------------------------------------------------*/
  2252. +
  2253. +/*----------------------------------------------------------------------
  2254. + * Get the current frame number (from DR frame_index Reg )
  2255. + *----------------------------------------------------------------------*/
  2256. +static int fsl_get_frame(struct usb_gadget *gadget)
  2257. +{
  2258. + return (int)(fsl_readl(&dr_regs->frindex) & USB_FRINDEX_MASKS);
  2259. +}
  2260. +
  2261. +/*-----------------------------------------------------------------------
  2262. + * Tries to wake up the host connected to this gadget
  2263. + -----------------------------------------------------------------------*/
  2264. +static int fsl_wakeup(struct usb_gadget *gadget)
  2265. +{
  2266. + struct fsl_udc *udc = container_of(gadget, struct fsl_udc, gadget);
  2267. + u32 portsc;
  2268. +
  2269. + /* Remote wakeup feature not enabled by host */
  2270. + if (!udc->remote_wakeup)
  2271. + return -ENOTSUPP;
  2272. +
  2273. + portsc = fsl_readl(&dr_regs->portsc1);
  2274. + /* not suspended? */
  2275. + if (!(portsc & PORTSCX_PORT_SUSPEND))
  2276. + return 0;
  2277. + /* trigger force resume */
  2278. + portsc |= PORTSCX_PORT_FORCE_RESUME;
  2279. + fsl_writel(portsc, &dr_regs->portsc1);
  2280. + return 0;
  2281. +}
  2282. +
  2283. +static int can_pullup(struct fsl_udc *udc)
  2284. +{
  2285. + return udc->driver && udc->softconnect && udc->vbus_active;
  2286. +}
  2287. +
  2288. +/*
  2289. + * Notify controller that VBUS is powered, Called by whatever
  2290. + * detects VBUS sessions
  2291. + * @param gadger gadger pointer
  2292. + * @param is_active is active?
  2293. + * @return Returns zero on success , or a negative error code
  2294. + */
  2295. +static int fsl_vbus_session(struct usb_gadget *gadget, int is_active)
  2296. +{
  2297. + struct fsl_udc *udc;
  2298. + unsigned long flags;
  2299. +
  2300. + udc = container_of(gadget, struct fsl_udc, gadget);
  2301. + spin_lock_irqsave(&udc->lock, flags);
  2302. +
  2303. + pr_debug("udc: VBUS %s\n", is_active ? "on" : "off");
  2304. + udc->vbus_active = (is_active != 0);
  2305. +
  2306. + if (can_pullup(udc)) {
  2307. + pullup_enable(udc);
  2308. + udc_controller->usb_state = USB_STATE_ATTACHED;
  2309. + } else {
  2310. + pullup_disable(udc);
  2311. + udc_controller->usb_state = USB_STATE_NOTATTACHED;
  2312. + }
  2313. + udc_controller->ep0_state = WAIT_FOR_SETUP;
  2314. + udc_controller->ep0_dir = 0;
  2315. +
  2316. + spin_unlock_irqrestore(&udc->lock, flags);
  2317. + return 0;
  2318. +}
  2319. +
  2320. +/* constrain controller's VBUS power usage
  2321. + * This call is used by gadget drivers during SET_CONFIGURATION calls,
  2322. + * reporting how much power the device may consume. For example, this
  2323. + * could affect how quickly batteries are recharged.
  2324. + *
  2325. + * Returns zero on success, else negative errno.
  2326. + */
  2327. +static int fsl_vbus_draw(struct usb_gadget *gadget, unsigned mA)
  2328. +{
  2329. +#ifdef CONFIG_USB_OTG
  2330. + struct fsl_udc *udc;
  2331. +
  2332. + udc = container_of(gadget, struct fsl_udc, gadget);
  2333. +
  2334. + if (udc->transceiver)
  2335. + return otg_set_power(udc->transceiver, mA);
  2336. +#endif
  2337. + return -ENOTSUPP;
  2338. +}
  2339. +
  2340. +/*
  2341. + * Change Data+ pullup status
  2342. + * this func is used by usb_gadget_connect/disconnet
  2343. + */
  2344. +static int fsl_pullup(struct usb_gadget *gadget, int is_on)
  2345. +{
  2346. + struct fsl_udc *udc;
  2347. +
  2348. + udc = container_of(gadget, struct fsl_udc, gadget);
  2349. + udc->softconnect = (is_on != 0);
  2350. + if (can_pullup(udc))
  2351. + fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
  2352. + &dr_regs->usbcmd);
  2353. + else
  2354. + fsl_writel((fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
  2355. + &dr_regs->usbcmd);
  2356. +
  2357. + return 0;
  2358. +}
  2359. +
  2360. +/* defined in usb_gadget.h */
  2361. +static struct usb_gadget_ops fsl_gadget_ops = {
  2362. + .get_frame = fsl_get_frame,
  2363. + .wakeup = fsl_wakeup,
  2364. + .vbus_session = fsl_vbus_session,
  2365. + .vbus_draw = fsl_vbus_draw,
  2366. + .pullup = fsl_pullup,
  2367. +};
  2368. +
  2369. +/* Set protocol stall on ep0, protocol stall will automatically be cleared
  2370. + on new transaction */
  2371. +static void ep0stall(struct fsl_udc *udc)
  2372. +{
  2373. + u32 tmp;
  2374. +
  2375. + /* must set tx and rx to stall at the same time */
  2376. + tmp = fsl_readl(&dr_regs->endptctrl[0]);
  2377. + tmp |= EPCTRL_TX_EP_STALL | EPCTRL_RX_EP_STALL;
  2378. + fsl_writel(tmp, &dr_regs->endptctrl[0]);
  2379. + udc->ep0_state = WAIT_FOR_SETUP;
  2380. + udc->ep0_dir = 0;
  2381. +}
  2382. +
  2383. +/* Prime a status phase for ep0 */
  2384. +static int ep0_prime_status(struct fsl_udc *udc, int direction)
  2385. +{
  2386. + struct fsl_req *req = udc->status_req;
  2387. + struct fsl_ep *ep;
  2388. + int status = 0;
  2389. +
  2390. + if (direction == EP_DIR_IN)
  2391. + udc->ep0_dir = USB_DIR_IN;
  2392. + else
  2393. + udc->ep0_dir = USB_DIR_OUT;
  2394. +
  2395. + ep = &udc->eps[0];
  2396. + udc->ep0_state = WAIT_FOR_OUT_STATUS;
  2397. +
  2398. + req->ep = ep;
  2399. + req->req.length = 0;
  2400. + req->req.status = -EINPROGRESS;
  2401. + req->req.actual = 0;
  2402. + req->req.complete = NULL;
  2403. + req->dtd_count = 0;
  2404. +
  2405. + if (fsl_req_to_dtd(req) == 0)
  2406. + status = fsl_queue_td(ep, req);
  2407. + else
  2408. + return -ENOMEM;
  2409. +
  2410. + if (status)
  2411. + ERR("Can't queue ep0 status request \n");
  2412. + list_add_tail(&req->queue, &ep->queue);
  2413. +
  2414. + return status;
  2415. +}
  2416. +
  2417. +static inline int udc_reset_ep_queue(struct fsl_udc *udc, u8 pipe)
  2418. +{
  2419. + struct fsl_ep *ep = get_ep_by_pipe(udc, pipe);
  2420. +
  2421. + if (!ep->name)
  2422. + return 0;
  2423. +
  2424. + nuke(ep, -ESHUTDOWN);
  2425. +
  2426. + return 0;
  2427. +}
  2428. +
  2429. +/*
  2430. + * ch9 Set address
  2431. + */
  2432. +static void ch9setaddress(struct fsl_udc *udc, u16 value, u16 index, u16 length)
  2433. +{
  2434. + /* Save the new address to device struct */
  2435. + udc->device_address = (u8) value;
  2436. + /* Update usb state */
  2437. + udc->usb_state = USB_STATE_ADDRESS;
  2438. + /* Status phase */
  2439. + if (ep0_prime_status(udc, EP_DIR_IN))
  2440. + ep0stall(udc);
  2441. +}
  2442. +
  2443. +/*
  2444. + * ch9 Get status
  2445. + */
  2446. +static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
  2447. + u16 index, u16 length)
  2448. +{
  2449. + u16 tmp = 0; /* Status, cpu endian */
  2450. +
  2451. + struct fsl_req *req;
  2452. + struct fsl_ep *ep;
  2453. + int status = 0;
  2454. +
  2455. + ep = &udc->eps[0];
  2456. +
  2457. + if ((request_type & USB_RECIP_MASK) == USB_RECIP_DEVICE) {
  2458. + /* Get device status */
  2459. + tmp = 1 << USB_DEVICE_SELF_POWERED;
  2460. + tmp |= udc->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP;
  2461. + } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_INTERFACE) {
  2462. + /* Get interface status */
  2463. + /* We don't have interface information in udc driver */
  2464. + tmp = 0;
  2465. + } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_ENDPOINT) {
  2466. + /* Get endpoint status */
  2467. + struct fsl_ep *target_ep;
  2468. +
  2469. + target_ep = get_ep_by_pipe(udc, get_pipe_by_windex(index));
  2470. +
  2471. + /* stall if endpoint doesn't exist */
  2472. + if (!target_ep->desc)
  2473. + goto stall;
  2474. + tmp = dr_ep_get_stall(ep_index(target_ep), ep_is_in(target_ep))
  2475. + << USB_ENDPOINT_HALT;
  2476. + }
  2477. +
  2478. + udc->ep0_dir = USB_DIR_IN;
  2479. + /* Borrow the per device status_req */
  2480. + req = udc->status_req;
  2481. + /* Fill in the reqest structure */
  2482. + *((u16 *) req->req.buf) = cpu_to_le16(tmp);
  2483. + req->ep = ep;
  2484. + req->req.length = 2;
  2485. + req->req.status = -EINPROGRESS;
  2486. + req->req.actual = 0;
  2487. + req->req.complete = NULL;
  2488. + req->dtd_count = 0;
  2489. +
  2490. + /* prime the data phase */
  2491. + if ((fsl_req_to_dtd(req) == 0))
  2492. + status = fsl_queue_td(ep, req);
  2493. + else /* no mem */
  2494. + goto stall;
  2495. +
  2496. + if (status) {
  2497. + ERR("Can't respond to getstatus request \n");
  2498. + goto stall;
  2499. + }
  2500. + list_add_tail(&req->queue, &ep->queue);
  2501. + udc->ep0_state = DATA_STATE_XMIT;
  2502. + return;
  2503. +stall:
  2504. + ep0stall(udc);
  2505. +}
  2506. +
  2507. +static void ch9setconfig(struct fsl_udc *udc, u16 value, u16 index,
  2508. + u16 length)
  2509. +{
  2510. + pr_debug("udc: 1 calling gadget driver->setup\n");
  2511. + udc->ep0_dir = USB_DIR_IN;
  2512. + if (udc->driver->setup(&udc->gadget, &udc->local_setup_buff) >= 0) {
  2513. + /* gadget layer deal with the status phase */
  2514. + udc->usb_state = USB_STATE_CONFIGURED;
  2515. + udc->ep0_state = WAIT_FOR_OUT_STATUS;
  2516. + pr_debug("udc: ep0_state now WAIT_FOR_OUT_STATUS\n");
  2517. + }
  2518. +}
  2519. +
  2520. +static void setup_received_irq(struct fsl_udc *udc,
  2521. + struct usb_ctrlrequest *setup)
  2522. +{
  2523. + u32 tmp;
  2524. + u16 ptc = 0; /* port test control */
  2525. + int handled = 1; /* set to zero if we do not handle the message,
  2526. + and should pass it to the gadget driver */
  2527. +
  2528. + /*
  2529. + * gadget drivers expect the setup pkt to be in wire format,
  2530. + * so leave it alone and make local copies of stuff we need.
  2531. + */
  2532. + u16 wValue = le16_to_cpu(setup->wValue);
  2533. + u16 wIndex = le16_to_cpu(setup->wIndex);
  2534. + u16 wLength = le16_to_cpu(setup->wLength);
  2535. +
  2536. +
  2537. + pr_debug("udc: request=0x%x\n", setup->bRequest);
  2538. +
  2539. + udc_reset_ep_queue(udc, 0);
  2540. +
  2541. + /* We asume setup only occurs on EP0 */
  2542. + if (setup->bRequestType & USB_DIR_IN)
  2543. + udc->ep0_dir = USB_DIR_IN;
  2544. + else
  2545. + udc->ep0_dir = USB_DIR_OUT;
  2546. +
  2547. + if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS) {
  2548. + /* handle class requests */
  2549. + switch (setup->bRequest) {
  2550. +
  2551. + case USB_BULK_RESET_REQUEST:
  2552. + udc->ep0_dir = USB_DIR_IN;
  2553. + if (udc->driver->setup(&udc->gadget,
  2554. + &udc->local_setup_buff) >= 0) {
  2555. + udc->ep0_state = WAIT_FOR_SETUP;
  2556. + pr_debug("udc: ep0_state now WAIT_FOR_SETUP\n");
  2557. + }
  2558. + break;
  2559. +
  2560. + default:
  2561. + handled = 0;
  2562. + break;
  2563. + }
  2564. + } else if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
  2565. + /* handle standard requests */
  2566. + switch (setup->bRequest) {
  2567. +
  2568. + case USB_REQ_GET_STATUS:
  2569. + if ((setup->
  2570. + bRequestType & (USB_DIR_IN | USB_TYPE_STANDARD))
  2571. + != (USB_DIR_IN | USB_TYPE_STANDARD))
  2572. + break;
  2573. + ch9getstatus(udc, setup->bRequestType, wValue, wIndex,
  2574. + wLength);
  2575. + break;
  2576. +
  2577. + case USB_REQ_SET_ADDRESS:
  2578. + if (setup->bRequestType !=
  2579. + (USB_DIR_OUT | USB_TYPE_STANDARD |
  2580. + USB_RECIP_DEVICE))
  2581. + break;
  2582. + ch9setaddress(udc, wValue, wIndex, wLength);
  2583. + break;
  2584. +
  2585. + case USB_REQ_SET_CONFIGURATION:
  2586. + if (setup->bRequestType !=
  2587. + (USB_DIR_OUT | USB_TYPE_STANDARD |
  2588. + USB_RECIP_DEVICE))
  2589. + break;
  2590. + /* gadget layer take over the status phase */
  2591. + ch9setconfig(udc, wValue, wIndex, wLength);
  2592. + break;
  2593. + case USB_REQ_SET_INTERFACE:
  2594. + if (setup->bRequestType !=
  2595. + (USB_DIR_OUT | USB_TYPE_STANDARD |
  2596. + USB_RECIP_INTERFACE))
  2597. + break;
  2598. + udc->ep0_dir = USB_DIR_IN;
  2599. + if (udc->driver->setup(&udc->gadget,
  2600. + &udc->local_setup_buff) >= 0)
  2601. + /* gadget layer take over the status phase */
  2602. + break;
  2603. + /* Requests with no data phase */
  2604. + case USB_REQ_CLEAR_FEATURE:
  2605. + case USB_REQ_SET_FEATURE:
  2606. + { /* status transaction */
  2607. + int rc = -EOPNOTSUPP;
  2608. +
  2609. + if ((setup->bRequestType & USB_TYPE_MASK) !=
  2610. + USB_TYPE_STANDARD)
  2611. + break;
  2612. +
  2613. + /* we only support set/clear feature for
  2614. + * endpoint */
  2615. + if (setup->bRequestType == USB_RECIP_ENDPOINT) {
  2616. + int dir = (wIndex & 0x0080) ?
  2617. + EP_DIR_IN : EP_DIR_OUT;
  2618. + int num = (wIndex & 0x000f);
  2619. + struct fsl_ep *ep;
  2620. +
  2621. + if (wValue != 0
  2622. + || wLength != 0
  2623. + || (num * 2 + dir) > udc->max_ep)
  2624. + break;
  2625. + ep = &udc->eps[num * 2 + dir];
  2626. +
  2627. + if (setup->bRequest ==
  2628. + USB_REQ_SET_FEATURE) {
  2629. + pr_debug("udc: udc: SET_FEATURE"
  2630. + " doing set_halt\n");
  2631. + rc = fsl_ep_set_halt(&ep-> ep,
  2632. + 1);
  2633. + } else {
  2634. + pr_debug("udc: CLEAR_FEATURE"
  2635. + " doing clear_halt\n");
  2636. + rc = fsl_ep_set_halt(&ep-> ep,
  2637. + 0);
  2638. + }
  2639. +
  2640. + } else if (setup->bRequestType ==
  2641. + USB_RECIP_DEVICE) {
  2642. + if (setup->bRequest ==
  2643. + USB_REQ_SET_FEATURE) {
  2644. + ptc = wIndex >> 8;
  2645. + rc = 0;
  2646. + }
  2647. + if (!udc->gadget.is_otg)
  2648. + break;
  2649. + else if (setup->bRequest ==
  2650. + USB_DEVICE_B_HNP_ENABLE)
  2651. + udc->gadget.b_hnp_enable = 1;
  2652. + else if (setup->bRequest ==
  2653. + USB_DEVICE_A_HNP_SUPPORT)
  2654. + udc->gadget.a_hnp_support = 1;
  2655. + else if (setup->bRequest ==
  2656. + USB_DEVICE_A_ALT_HNP_SUPPORT)
  2657. + udc->gadget.a_alt_hnp_support =
  2658. + 1;
  2659. + rc = 0;
  2660. + }
  2661. + if (rc == 0) {
  2662. + /* send status only if
  2663. + * fsl_ep_set_halt success */
  2664. + if (ep0_prime_status(udc, EP_DIR_IN))
  2665. + ep0stall(udc);
  2666. + }
  2667. + break;
  2668. + }
  2669. + default:
  2670. + handled = 0;
  2671. + break;
  2672. + }
  2673. + } else {
  2674. + /* vendor requests */
  2675. + handled = 0;
  2676. + }
  2677. +
  2678. + if (!handled) {
  2679. + if (udc->driver->setup(&udc->gadget, &udc->local_setup_buff)
  2680. + != 0) {
  2681. + ep0stall(udc);
  2682. + } else if (setup->bRequestType & USB_DIR_IN) {
  2683. + udc->ep0_state = DATA_STATE_XMIT;
  2684. + pr_debug("udc: ep0_state now DATA_STATE_XMIT\n");
  2685. + } else {
  2686. + udc->ep0_state = DATA_STATE_RECV;
  2687. + pr_debug("udc: ep0_state now DATA_STATE_RECV\n");
  2688. + }
  2689. + }
  2690. +
  2691. + if (ptc) {
  2692. + tmp =fsl_readl(&dr_regs->portsc1) | ptc << 16;
  2693. + fsl_writel(tmp, &dr_regs->portsc1);
  2694. + pr_debug("udc: switch to test mode.\n");
  2695. + }
  2696. +}
  2697. +
  2698. +/* Process request for Data or Status phase of ep0
  2699. + * prime status phase if needed */
  2700. +static void ep0_req_complete(struct fsl_udc *udc, struct fsl_ep *ep0,
  2701. + struct fsl_req *req)
  2702. +{
  2703. + if (udc->usb_state == USB_STATE_ADDRESS) {
  2704. + /* Set the new address */
  2705. + u32 new_address = (u32) udc->device_address;
  2706. + fsl_writel(new_address << USB_DEVICE_ADDRESS_BIT_POS,
  2707. + &dr_regs->deviceaddr);
  2708. + }
  2709. +
  2710. + done(ep0, req, 0);
  2711. +
  2712. + switch (udc->ep0_state) {
  2713. + case DATA_STATE_XMIT:
  2714. + /* receive status phase */
  2715. + if (ep0_prime_status(udc, EP_DIR_OUT))
  2716. + ep0stall(udc);
  2717. + break;
  2718. + case DATA_STATE_RECV:
  2719. + /* send status phase */
  2720. + if (ep0_prime_status(udc, EP_DIR_IN))
  2721. + ep0stall(udc);
  2722. + break;
  2723. + case WAIT_FOR_OUT_STATUS:
  2724. + udc->ep0_state = WAIT_FOR_SETUP;
  2725. + break;
  2726. + case WAIT_FOR_SETUP:
  2727. + ERR("Unexpect ep0 packets \n");
  2728. + break;
  2729. + default:
  2730. + ep0stall(udc);
  2731. + break;
  2732. + }
  2733. +}
  2734. +
  2735. +/* Tripwire mechanism to ensure a setup packet payload is extracted without
  2736. + * being corrupted by another incoming setup packet */
  2737. +static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
  2738. +{
  2739. + u32 temp;
  2740. + struct ep_queue_head *qh;
  2741. + struct fsl_usb2_platform_data *pdata = udc->pdata;
  2742. +
  2743. + qh = &udc->ep_qh[ep_num * 2 + EP_DIR_OUT];
  2744. +
  2745. + /* Clear bit in ENDPTSETUPSTAT */
  2746. + temp = fsl_readl(&dr_regs->endptsetupstat);
  2747. + fsl_writel(temp | (1 << ep_num), &dr_regs->endptsetupstat);
  2748. +
  2749. + /* while a hazard exists when setup package arrives */
  2750. + do {
  2751. + /* Set Setup Tripwire */
  2752. + temp = fsl_readl(&dr_regs->usbcmd);
  2753. + fsl_writel(temp | USB_CMD_SUTW, &dr_regs->usbcmd);
  2754. +
  2755. + /* Copy the setup packet to local buffer */
  2756. + if (pdata->le_setup_buf) {
  2757. + u32 *p = (u32 *)buffer_ptr;
  2758. + u32 *s = (u32 *)qh->setup_buffer;
  2759. +
  2760. + /* Convert little endian setup buffer to CPU endian */
  2761. + *p++ = le32_to_cpu(*s++);
  2762. + *p = le32_to_cpu(*s);
  2763. + } else {
  2764. + memcpy(buffer_ptr, (u8 *) qh->setup_buffer, 8);
  2765. + }
  2766. + } while (!(fsl_readl(&dr_regs->usbcmd) & USB_CMD_SUTW));
  2767. +
  2768. + /* Clear Setup Tripwire */
  2769. + temp = fsl_readl(&dr_regs->usbcmd);
  2770. + fsl_writel(temp & ~USB_CMD_SUTW, &dr_regs->usbcmd);
  2771. +}
  2772. +
  2773. +/* process-ep_req(): free the completed Tds for this req */
  2774. +static int process_ep_req(struct fsl_udc *udc, int pipe,
  2775. + struct fsl_req *curr_req)
  2776. +{
  2777. + struct ep_td_struct *curr_td;
  2778. + int td_complete, actual, remaining_length, j, tmp;
  2779. + int status = 0;
  2780. + int errors = 0;
  2781. + struct ep_queue_head *curr_qh = &udc->ep_qh[pipe];
  2782. + int direction = pipe % 2;
  2783. +
  2784. + curr_td = curr_req->head;
  2785. + td_complete = 0;
  2786. + actual = curr_req->req.length;
  2787. +
  2788. + for (j = 0; j < curr_req->dtd_count; j++) {
  2789. + remaining_length = (hc32_to_cpu(curr_td->size_ioc_sts)
  2790. + & DTD_PACKET_SIZE)
  2791. + >> DTD_LENGTH_BIT_POS;
  2792. + actual -= remaining_length;
  2793. +
  2794. + (errors = hc32_to_cpu(curr_td->size_ioc_sts) & DTD_ERROR_MASK);
  2795. + if (errors) {
  2796. + if (errors & DTD_STATUS_HALTED) {
  2797. + ERR("dTD error %08x QH=%d\n", errors, pipe);
  2798. + /* Clear the errors and Halt condition */
  2799. + tmp = hc32_to_cpu(curr_qh->size_ioc_int_sts);
  2800. + tmp &= ~errors;
  2801. + curr_qh->size_ioc_int_sts = cpu_to_hc32(tmp);
  2802. + status = -EPIPE;
  2803. + /* FIXME: continue with next queued TD? */
  2804. +
  2805. + break;
  2806. + }
  2807. + if (errors & DTD_STATUS_DATA_BUFF_ERR) {
  2808. + VDBG("Transfer overflow");
  2809. + status = -EPROTO;
  2810. + break;
  2811. + } else if (errors & DTD_STATUS_TRANSACTION_ERR) {
  2812. + VDBG("ISO error");
  2813. + status = -EILSEQ;
  2814. + break;
  2815. + } else
  2816. + ERR("Unknown error has occured (0x%x)!\r\n",
  2817. + errors);
  2818. +
  2819. + } else if (hc32_to_cpu(curr_td->size_ioc_sts) &
  2820. + DTD_STATUS_ACTIVE) {
  2821. + VDBG("Request not complete");
  2822. + status = REQ_UNCOMPLETE;
  2823. + return status;
  2824. + } else if (remaining_length) {
  2825. + if (direction) {
  2826. + VDBG("Transmit dTD remaining length not zero");
  2827. + status = -EPROTO;
  2828. + break;
  2829. + } else {
  2830. + td_complete++;
  2831. + break;
  2832. + }
  2833. + } else {
  2834. + td_complete++;
  2835. + VDBG("dTD transmitted successful ");
  2836. + }
  2837. +
  2838. + if (j != curr_req->dtd_count - 1)
  2839. + curr_td = curr_td->next_td_virt;
  2840. + }
  2841. +
  2842. + if (status)
  2843. + return status;
  2844. +
  2845. + curr_req->req.actual = actual;
  2846. +
  2847. + return 0;
  2848. +}
  2849. +
  2850. +/* Process a DTD completion interrupt */
  2851. +static void dtd_complete_irq(struct fsl_udc *udc)
  2852. +{
  2853. + u32 bit_pos;
  2854. + int i, ep_num, direction, bit_mask, status;
  2855. + struct fsl_ep *curr_ep;
  2856. + struct fsl_req *curr_req, *temp_req;
  2857. +
  2858. + /* Clear the bits in the register */
  2859. + bit_pos = fsl_readl(&dr_regs->endptcomplete);
  2860. + fsl_writel(bit_pos, &dr_regs->endptcomplete);
  2861. +
  2862. + if (!bit_pos)
  2863. + return;
  2864. +
  2865. + for (i = 0; i < udc->max_ep * 2; i++) {
  2866. + ep_num = i >> 1;
  2867. + direction = i % 2;
  2868. +
  2869. + bit_mask = 1 << (ep_num + 16 * direction);
  2870. +
  2871. + if (!(bit_pos & bit_mask))
  2872. + continue;
  2873. +
  2874. + curr_ep = get_ep_by_pipe(udc, i);
  2875. +
  2876. + /* If the ep is configured */
  2877. + if (curr_ep->name == NULL) {
  2878. + WARN("Invalid EP?");
  2879. + continue;
  2880. + }
  2881. +
  2882. + /* process the req queue until an uncomplete request */
  2883. + list_for_each_entry_safe(curr_req, temp_req, &curr_ep->queue,
  2884. + queue) {
  2885. + status = process_ep_req(udc, i, curr_req);
  2886. +
  2887. + VDBG("status of process_ep_req= %d, ep = %d",
  2888. + status, ep_num);
  2889. + if (status == REQ_UNCOMPLETE)
  2890. + break;
  2891. + /* write back status to req */
  2892. + curr_req->req.status = status;
  2893. +
  2894. + if (ep_num == 0) {
  2895. + ep0_req_complete(udc, curr_ep, curr_req);
  2896. + break;
  2897. + } else {
  2898. + done(curr_ep, curr_req, status);
  2899. + }
  2900. + }
  2901. + }
  2902. +}
  2903. +
  2904. +/* Process a port change interrupt */
  2905. +static void port_change_irq(struct fsl_udc *udc)
  2906. +{
  2907. + u32 speed;
  2908. +
  2909. + VDBG("portsc=0x%x", fsl_readl(&dr_regs->portsc1) );
  2910. + if (udc->bus_reset)
  2911. + udc->bus_reset = 0;
  2912. +
  2913. + /* Bus resetting is finished */
  2914. + if (!(fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET)) {
  2915. + /* Get the speed */
  2916. + speed = fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_SPEED_MASK;
  2917. + switch (speed) {
  2918. + case PORTSCX_PORT_SPEED_HIGH:
  2919. + udc->gadget.speed = USB_SPEED_HIGH;
  2920. + break;
  2921. + case PORTSCX_PORT_SPEED_FULL:
  2922. + udc->gadget.speed = USB_SPEED_FULL;
  2923. + break;
  2924. + case PORTSCX_PORT_SPEED_LOW:
  2925. + udc->gadget.speed = USB_SPEED_LOW;
  2926. + break;
  2927. + default:
  2928. + udc->gadget.speed = USB_SPEED_UNKNOWN;
  2929. + break;
  2930. + }
  2931. + }
  2932. +
  2933. + /* Update USB state */
  2934. + if (!udc->resume_state)
  2935. + udc->usb_state = USB_STATE_DEFAULT;
  2936. +}
  2937. +
  2938. +/* Process suspend interrupt */
  2939. +static void suspend_irq(struct fsl_udc *udc)
  2940. +{
  2941. + udc->resume_state = udc->usb_state;
  2942. + udc->usb_state = USB_STATE_SUSPENDED;
  2943. +
  2944. + /* report suspend to the driver, serial.c does not support this */
  2945. + if (udc->driver->suspend)
  2946. + udc->driver->suspend(&udc->gadget);
  2947. +}
  2948. +
  2949. +static void bus_resume(struct fsl_udc *udc)
  2950. +{
  2951. + udc->usb_state = udc->resume_state;
  2952. + udc->resume_state = 0;
  2953. +
  2954. + /* report resume to the driver, serial.c does not support this */
  2955. + if (udc->driver->resume)
  2956. + udc->driver->resume(&udc->gadget);
  2957. +}
  2958. +
  2959. +/* Clear up all ep queues */
  2960. +static int reset_queues(struct fsl_udc *udc)
  2961. +{
  2962. + u8 pipe;
  2963. +
  2964. + for (pipe = 0; pipe < udc->max_pipes; pipe++)
  2965. + udc_reset_ep_queue(udc, pipe);
  2966. +
  2967. + /* report disconnect; the driver is already quiesced */
  2968. + udc->driver->disconnect(&udc->gadget);
  2969. +
  2970. + return 0;
  2971. +}
  2972. +
  2973. +/* Process reset interrupt */
  2974. +static void reset_irq(struct fsl_udc *udc)
  2975. +{
  2976. + u32 temp;
  2977. + unsigned long timeout;
  2978. +
  2979. + /* Clear the device address */
  2980. + temp = fsl_readl(&dr_regs->deviceaddr);
  2981. + fsl_writel(temp & ~USB_DEVICE_ADDRESS_MASK, &dr_regs->deviceaddr);
  2982. +
  2983. + udc->device_address = 0;
  2984. +
  2985. + /* Clear usb state */
  2986. + udc->resume_state = 0;
  2987. + udc->ep0_dir = 0;
  2988. + udc->ep0_state = WAIT_FOR_SETUP;
  2989. + udc->remote_wakeup = 0; /* default to 0 on reset */
  2990. + udc->gadget.b_hnp_enable = 0;
  2991. + udc->gadget.a_hnp_support = 0;
  2992. + udc->gadget.a_alt_hnp_support = 0;
  2993. +
  2994. + /* Clear all the setup token semaphores */
  2995. + temp = fsl_readl(&dr_regs->endptsetupstat);
  2996. + fsl_writel(temp, &dr_regs->endptsetupstat);
  2997. +
  2998. + /* Clear all the endpoint complete status bits */
  2999. + temp = fsl_readl(&dr_regs->endptcomplete);
  3000. + fsl_writel(temp, &dr_regs->endptcomplete);
  3001. +
  3002. + timeout = jiffies + 100;
  3003. + while (fsl_readl(&dr_regs->endpointprime)) {
  3004. + /* Wait until all endptprime bits cleared */
  3005. + if (time_after(jiffies, timeout)) {
  3006. + ERR("Timeout for reset\n");
  3007. + break;
  3008. + }
  3009. + cpu_relax();
  3010. + }
  3011. +
  3012. + /* Write 1s to the flush register */
  3013. + fsl_writel(0xffffffff, &dr_regs->endptflush);
  3014. +
  3015. + if (fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) {
  3016. + VDBG("Bus reset");
  3017. + /* Bus is reseting */
  3018. + udc->bus_reset = 1;
  3019. + /* Reset all the queues, include XD, dTD, EP queue
  3020. + * head and TR Queue */
  3021. + reset_queues(udc);
  3022. + udc->usb_state = USB_STATE_DEFAULT;
  3023. + } else {
  3024. + VDBG("Controller reset");
  3025. + /* initialize usb hw reg except for regs for EP, not
  3026. + * touch usbintr reg */
  3027. + dr_controller_setup(udc);
  3028. +
  3029. + /* Reset all internal used Queues */
  3030. + reset_queues(udc);
  3031. +
  3032. + ep0_setup(udc);
  3033. +
  3034. + /* Enable DR IRQ reg, Set Run bit, change udc state */
  3035. + dr_controller_run(udc);
  3036. + udc->usb_state = USB_STATE_ATTACHED;
  3037. + }
  3038. +}
  3039. +
  3040. +/*
  3041. + * USB device controller interrupt handler
  3042. + */
  3043. +static irqreturn_t fsl_udc_irq(int irq, void *_udc)
  3044. +{
  3045. + struct fsl_udc *udc = _udc;
  3046. + u32 irq_src;
  3047. + irqreturn_t status = IRQ_NONE;
  3048. + unsigned long flags;
  3049. +
  3050. + /* Disable ISR for OTG host mode */
  3051. + if (udc->stopped)
  3052. + return IRQ_NONE;
  3053. + spin_lock_irqsave(&udc->lock, flags);
  3054. + irq_src = fsl_readl(&dr_regs->usbsts) & fsl_readl(&dr_regs->usbintr);
  3055. + /* Clear notification bits */
  3056. + fsl_writel(irq_src, &dr_regs->usbsts);
  3057. +
  3058. + VDBG("irq_src [0x%8x] portsc=0x%x", irq_src,
  3059. + fsl_readl(&dr_regs->portsc1));
  3060. +
  3061. + /* Need to resume? */
  3062. + if (udc->usb_state == USB_STATE_SUSPENDED)
  3063. + if ((fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_SUSPEND) == 0)
  3064. + bus_resume(udc);
  3065. +
  3066. + /* USB Interrupt */
  3067. + if (irq_src & USB_STS_INT) {
  3068. + VDBG("Packet int");
  3069. + /* Setup package, we only support ep0 as control ep */
  3070. + if (fsl_readl(&dr_regs->endptsetupstat) & EP_SETUP_STATUS_EP0) {
  3071. + tripwire_handler(udc, 0,
  3072. + (u8 *) (&udc->local_setup_buff));
  3073. + setup_received_irq(udc, &udc->local_setup_buff);
  3074. + status = IRQ_HANDLED;
  3075. + }
  3076. +
  3077. + /* completion of dtd */
  3078. + if (fsl_readl(&dr_regs->endptcomplete)) {
  3079. + dtd_complete_irq(udc);
  3080. + status = IRQ_HANDLED;
  3081. + }
  3082. + }
  3083. +
  3084. + /* SOF (for ISO transfer) */
  3085. + if (irq_src & USB_STS_SOF) {
  3086. + status = IRQ_HANDLED;
  3087. + }
  3088. +
  3089. + /* Port Change */
  3090. + if (irq_src & USB_STS_PORT_CHANGE) {
  3091. + port_change_irq(udc);
  3092. + status = IRQ_HANDLED;
  3093. + }
  3094. +
  3095. + /* Reset Received */
  3096. + if (irq_src & USB_STS_RESET) {
  3097. + reset_irq(udc);
  3098. + status = IRQ_HANDLED;
  3099. + }
  3100. +
  3101. + /* Sleep Enable (Suspend) */
  3102. + if (irq_src & USB_STS_SUSPEND) {
  3103. + suspend_irq(udc);
  3104. + status = IRQ_HANDLED;
  3105. + }
  3106. +
  3107. + if (irq_src & (USB_STS_ERR | USB_STS_SYS_ERR)) {
  3108. + VDBG("Error IRQ %x ", irq_src);
  3109. + }
  3110. +
  3111. + spin_unlock_irqrestore(&udc->lock, flags);
  3112. + return status;
  3113. +}
  3114. +
  3115. +/*----------------------------------------------------------------*
  3116. + * Hook to gadget drivers
  3117. + * Called by initialization code of gadget drivers
  3118. +*----------------------------------------------------------------*/
  3119. +int usb_gadget_register_driver(struct usb_gadget_driver *driver)
  3120. +{
  3121. + int retval = -ENODEV;
  3122. + unsigned long flags = 0;
  3123. + struct fsl_udc *udc = udc_controller;
  3124. +
  3125. + pr_debug("udc: udc=0x%p\n", udc);
  3126. +
  3127. + if (!udc)
  3128. + return -ENODEV;
  3129. +
  3130. + if (!driver || (driver->speed != USB_SPEED_FULL
  3131. + && driver->speed != USB_SPEED_HIGH)
  3132. + || !driver->bind || !driver->disconnect
  3133. + || !driver->setup)
  3134. + return -EINVAL;
  3135. +
  3136. + if (udc->driver)
  3137. + return -EBUSY;
  3138. +
  3139. + /* lock is needed but whether should use this lock or another */
  3140. + spin_lock_irqsave(&udc->lock, flags);
  3141. +
  3142. + driver->driver.bus = 0;
  3143. + udc->softconnect = 1;
  3144. + /* hook up the driver */
  3145. + udc->driver = driver;
  3146. + udc->gadget.dev.driver = &driver->driver;
  3147. + spin_unlock_irqrestore(&udc->lock, flags);
  3148. +
  3149. + /* bind udc driver to gadget driver */
  3150. + retval = driver->bind(&udc->gadget);
  3151. + if (retval) {
  3152. + pr_debug("bind to %s --> %d\n", driver->driver.name, retval);
  3153. + udc->gadget.dev.driver = 0;
  3154. + udc->driver = 0;
  3155. + goto out;
  3156. + }
  3157. +
  3158. + /* Enable DR IRQ reg and Set usbcmd reg Run bit */
  3159. + if (udc->transceiver) {
  3160. + /* Suspend the controller until OTG enables it */
  3161. + udc_suspend(udc);
  3162. + pr_debug("udc: suspend udc for OTG auto detect \n");
  3163. +
  3164. + /* Export udc suspend/resume call to OTG */
  3165. + udc->gadget.dev.parent->driver->suspend = fsl_udc_suspend;
  3166. + udc->gadget.dev.parent->driver->resume = fsl_udc_resume;
  3167. +
  3168. + retval = otg_set_peripheral(udc->transceiver, &udc->gadget);
  3169. + if (retval < 0) {
  3170. + printk(KERN_ERR "can't bind to transceiver\n");
  3171. + driver->unbind(&udc->gadget);
  3172. + udc->gadget.dev.driver = 0;
  3173. + udc->driver = 0;
  3174. + return retval;
  3175. + }
  3176. + } else {
  3177. + /* Enable DR IRQ reg and Set usbcmd reg Run bit */
  3178. + dr_controller_run(udc);
  3179. + udc->usb_state = USB_STATE_ATTACHED;
  3180. + udc->ep0_state = WAIT_FOR_SETUP;
  3181. + pr_debug("udc: ep0_state now WAIT_FOR_SETUP\n");
  3182. + udc->ep0_dir = 0;
  3183. + }
  3184. +
  3185. + printk(KERN_INFO "%s: bind to driver %s \n", udc->gadget.name,
  3186. + driver->driver.name);
  3187. +
  3188. +out:
  3189. + return retval;
  3190. +}
  3191. +EXPORT_SYMBOL(usb_gadget_register_driver);
  3192. +
  3193. +/* Disconnect from gadget driver */
  3194. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  3195. +{
  3196. + struct fsl_ep *loop_ep;
  3197. + unsigned long flags;
  3198. +
  3199. + if (!udc_controller)
  3200. + return -ENODEV;
  3201. +
  3202. + if (!driver || driver != udc_controller->driver || !driver->unbind)
  3203. + return -EINVAL;
  3204. +
  3205. +#ifdef CONFIG_USB_OTG
  3206. + if (udc_controller->transceiver)
  3207. + (void)otg_set_peripheral(udc_controller->transceiver, 0);
  3208. +#endif
  3209. +
  3210. + /* stop DR, disable intr */
  3211. + dr_controller_stop(udc_controller);
  3212. +
  3213. + /* in fact, no needed */
  3214. + udc_controller->usb_state = USB_STATE_ATTACHED;
  3215. + udc_controller->ep0_state = WAIT_FOR_SETUP;
  3216. + udc_controller->ep0_dir = 0;
  3217. +
  3218. + /* stand operation */
  3219. + spin_lock_irqsave(&udc_controller->lock, flags);
  3220. + udc_controller->gadget.speed = USB_SPEED_UNKNOWN;
  3221. + nuke(&udc_controller->eps[0], -ESHUTDOWN);
  3222. + list_for_each_entry(loop_ep, &udc_controller->gadget.ep_list,
  3223. + ep.ep_list)
  3224. + nuke(loop_ep, -ESHUTDOWN);
  3225. + spin_unlock_irqrestore(&udc_controller->lock, flags);
  3226. +
  3227. + /* unbind gadget and unhook driver. */
  3228. + driver->unbind(&udc_controller->gadget);
  3229. + udc_controller->gadget.dev.driver = 0;
  3230. + udc_controller->driver = 0;
  3231. +
  3232. + printk(KERN_INFO "unregistered gadget '%s'\n", driver->driver.name);
  3233. + return 0;
  3234. +}
  3235. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  3236. +
  3237. +/*-------------------------------------------------------------------------
  3238. + PROC File System Support
  3239. +-------------------------------------------------------------------------*/
  3240. +#ifdef CONFIG_USB_GADGET_DEBUG_FILES
  3241. +
  3242. +#include <linux/seq_file.h>
  3243. +
  3244. +static const char proc_filename[] = "driver/fsl_usb2_udc";
  3245. +
  3246. +static int fsl_proc_read(char *page, char **start, off_t off, int count,
  3247. + int *eof, void *_dev)
  3248. +{
  3249. + char *buf = page;
  3250. + char *next = buf;
  3251. + unsigned size = count;
  3252. + unsigned long flags;
  3253. + int t, i;
  3254. + u32 tmp_reg;
  3255. + struct fsl_ep *ep = NULL;
  3256. + struct fsl_req *req;
  3257. +
  3258. + struct fsl_udc *udc = udc_controller;
  3259. + if (off != 0)
  3260. + return 0;
  3261. +
  3262. + spin_lock_irqsave(&udc->lock, flags);
  3263. +
  3264. + /* ------basic driver infomation ---- */
  3265. + t = scnprintf(next, size,
  3266. + DRIVER_DESC "\n"
  3267. + "%s version: %s\n"
  3268. + "Gadget driver: %s\n\n",
  3269. + driver_name, DRIVER_VERSION,
  3270. + udc->driver ? udc->driver->driver.name : "(none)");
  3271. + size -= t;
  3272. + next += t;
  3273. +
  3274. + /* ------ DR Registers ----- */
  3275. + tmp_reg = fsl_readl(&dr_regs->usbcmd);
  3276. + t = scnprintf(next, size,
  3277. + "USBCMD reg: 0x%08x\n"
  3278. + "\tSetupTW: %d\n"
  3279. + "\tRun/Stop: %s\n\n",
  3280. + tmp_reg,
  3281. + (tmp_reg & USB_CMD_SUTW) ? 1 : 0,
  3282. + (tmp_reg & USB_CMD_RUN_STOP) ? "Run" : "Stop");
  3283. + size -= t;
  3284. + next += t;
  3285. +
  3286. + tmp_reg = fsl_readl(&dr_regs->usbsts);
  3287. + t = scnprintf(next, size,
  3288. + "USB Status Reg: 0x%08x\n"
  3289. + "\tDr Suspend: %d Reset Received: %d "
  3290. + "System Error: %s USB Error Interrupt: %s\n\n",
  3291. + tmp_reg,
  3292. + (tmp_reg & USB_STS_SUSPEND) ? 1 : 0,
  3293. + (tmp_reg & USB_STS_RESET) ? 1 : 0,
  3294. + (tmp_reg & USB_STS_SYS_ERR) ? "Err" : "Normal",
  3295. + (tmp_reg & USB_STS_ERR) ? "Err detected" : "No err");
  3296. + size -= t;
  3297. + next += t;
  3298. +
  3299. + tmp_reg = fsl_readl(&dr_regs->usbintr);
  3300. + t = scnprintf(next, size,
  3301. + "USB Interrupt Enable Reg: 0x%08x\n"
  3302. + "\tSleep Enable: %d SOF Received Enable: %d "
  3303. + "Reset Enable: %d\n"
  3304. + "\tSystem Error Enable: %d "
  3305. + "Port Change Dectected Enable: %d\n"
  3306. + "\tUSB Error Intr Enable: %d USB Intr Enable: %d\n\n",
  3307. + tmp_reg,
  3308. + (tmp_reg & USB_INTR_DEVICE_SUSPEND) ? 1 : 0,
  3309. + (tmp_reg & USB_INTR_SOF_EN) ? 1 : 0,
  3310. + (tmp_reg & USB_INTR_RESET_EN) ? 1 : 0,
  3311. + (tmp_reg & USB_INTR_SYS_ERR_EN) ? 1 : 0,
  3312. + (tmp_reg & USB_INTR_PTC_DETECT_EN) ? 1 : 0,
  3313. + (tmp_reg & USB_INTR_ERR_INT_EN) ? 1 : 0,
  3314. + (tmp_reg & USB_INTR_INT_EN) ? 1 : 0);
  3315. + size -= t;
  3316. + next += t;
  3317. +
  3318. + tmp_reg = fsl_readl(&dr_regs->frindex);
  3319. + t = scnprintf(next, size,
  3320. + "USB Frame Index Reg: Frame Number is 0x%x\n\n",
  3321. + (tmp_reg & USB_FRINDEX_MASKS));
  3322. + size -= t;
  3323. + next += t;
  3324. +
  3325. + tmp_reg = fsl_readl(&dr_regs->deviceaddr);
  3326. + t = scnprintf(next, size,
  3327. + "USB Device Address Reg: Device Addr is 0x%x\n\n",
  3328. + (tmp_reg & USB_DEVICE_ADDRESS_MASK));
  3329. + size -= t;
  3330. + next += t;
  3331. +
  3332. + tmp_reg = fsl_readl(&dr_regs->endpointlistaddr);
  3333. + t = scnprintf(next, size,
  3334. + "USB Endpoint List Address Reg:"
  3335. + "Device Addr is 0x%x\n\n",
  3336. + (tmp_reg & USB_EP_LIST_ADDRESS_MASK));
  3337. + size -= t;
  3338. + next += t;
  3339. +
  3340. + tmp_reg = fsl_readl(&dr_regs->portsc1);
  3341. + t = scnprintf(next, size,
  3342. + "USB Port Status&Control Reg:\n"
  3343. + "\tPort Transceiver Type : %s" "Port Speed: %s \n"
  3344. + "\tPHY Low Power Suspend: %s" "Port Reset: %s "
  3345. + "Port Suspend Mode: %s \n" "\tOver-current Change: %s "
  3346. + "Port Enable/Disable Change: %s\n"
  3347. + "\tPort Enabled/Disabled: %s"
  3348. + "Current Connect Status: %s\n\n", ( {
  3349. + char *s;
  3350. + switch (tmp_reg & PORTSCX_PTS_FSLS) {
  3351. + case PORTSCX_PTS_UTMI:
  3352. + s = "UTMI"; break;
  3353. + case PORTSCX_PTS_ULPI:
  3354. + s = "ULPI "; break;
  3355. + case PORTSCX_PTS_FSLS:
  3356. + s = "FS/LS Serial"; break;
  3357. + default:
  3358. + s = "None"; break;
  3359. + }
  3360. + s; } ), ( {
  3361. + char *s;
  3362. + switch (tmp_reg & PORTSCX_PORT_SPEED_UNDEF) {
  3363. + case PORTSCX_PORT_SPEED_FULL:
  3364. + s = "Full Speed"; break;
  3365. + case PORTSCX_PORT_SPEED_LOW:
  3366. + s = "Low Speed"; break;
  3367. + case PORTSCX_PORT_SPEED_HIGH:
  3368. + s = "High Speed"; break;
  3369. + default:
  3370. + s = "Undefined"; break;
  3371. + }
  3372. + s;
  3373. + } ),
  3374. + (tmp_reg & PORTSCX_PHY_LOW_POWER_SPD) ?
  3375. + "Normal PHY mode" : "Low power mode",
  3376. + (tmp_reg & PORTSCX_PORT_RESET) ? "In Reset" :
  3377. + "Not in Reset",
  3378. + (tmp_reg & PORTSCX_PORT_SUSPEND) ? "In " : "Not in",
  3379. + (tmp_reg & PORTSCX_OVER_CURRENT_CHG) ? "Dected" :
  3380. + "No",
  3381. + (tmp_reg & PORTSCX_PORT_EN_DIS_CHANGE) ? "Disable" :
  3382. + "Not change",
  3383. + (tmp_reg & PORTSCX_PORT_ENABLE) ? "Enable" :
  3384. + "Not correct",
  3385. + (tmp_reg & PORTSCX_CURRENT_CONNECT_STATUS) ?
  3386. + "Attached" : "Not-Att");
  3387. + size -= t;
  3388. + next += t;
  3389. +
  3390. + tmp_reg = fsl_readl(&dr_regs->usbmode);
  3391. + t = scnprintf(next, size,
  3392. + "USB Mode Reg:" "Controller Mode is : %s\n\n", ( {
  3393. + char *s;
  3394. + switch (tmp_reg & USB_MODE_CTRL_MODE_HOST) {
  3395. + case USB_MODE_CTRL_MODE_IDLE:
  3396. + s = "Idle"; break;
  3397. + case USB_MODE_CTRL_MODE_DEVICE:
  3398. + s = "Device Controller"; break;
  3399. + case USB_MODE_CTRL_MODE_HOST:
  3400. + s = "Host Controller"; break;
  3401. + default:
  3402. + s = "None"; break;
  3403. + }
  3404. + s;
  3405. + } ));
  3406. + size -= t;
  3407. + next += t;
  3408. +
  3409. + tmp_reg = fsl_readl(&dr_regs->endptsetupstat);
  3410. + t = scnprintf(next, size,
  3411. + "Endpoint Setup Status Reg:" "SETUP on ep 0x%x\n\n",
  3412. + (tmp_reg & EP_SETUP_STATUS_MASK));
  3413. + size -= t;
  3414. + next += t;
  3415. +
  3416. + for (i = 0; i < udc->max_ep / 2; i++) {
  3417. + tmp_reg = fsl_readl(&dr_regs->endptctrl[i]);
  3418. + t = scnprintf(next, size, "EP Ctrl Reg [0x%x]: = [0x%x]\n",
  3419. + i, tmp_reg);
  3420. + size -= t;
  3421. + next += t;
  3422. + }
  3423. + tmp_reg = fsl_readl(&dr_regs->endpointprime);
  3424. + t = scnprintf(next, size, "EP Prime Reg = [0x%x]\n", tmp_reg);
  3425. + size -= t;
  3426. + next += t;
  3427. +
  3428. +#ifdef HAVE_SYS_REGS
  3429. + tmp_reg = usb_sys_regs->snoop1;
  3430. + t = scnprintf(next, size, "\nSnoop1 Reg : = [0x%x]\n\n", tmp_reg);
  3431. + size -= t;
  3432. + next += t;
  3433. +
  3434. + tmp_reg = usb_sys_regs->control;
  3435. + t = scnprintf(next, size, "General Control Reg : = [0x%x]\n\n",
  3436. + tmp_reg);
  3437. + size -= t;
  3438. + next += t;
  3439. +#endif
  3440. +
  3441. + /* ------fsl_udc, fsl_ep, fsl_request structure information ----- */
  3442. + ep = &udc->eps[0];
  3443. + t = scnprintf(next, size, "For %s Maxpkt is 0x%x index is 0x%x\n",
  3444. + ep->ep.name, ep_maxpacket(ep), ep_index(ep));
  3445. + size -= t;
  3446. + next += t;
  3447. +
  3448. + if (list_empty(&ep->queue)) {
  3449. + t = scnprintf(next, size, "its req queue is empty\n\n");
  3450. + size -= t;
  3451. + next += t;
  3452. + } else {
  3453. + list_for_each_entry(req, &ep->queue, queue) {
  3454. + t = scnprintf(next, size,
  3455. + "req %p actual 0x%x length 0x%x buf %p\n",
  3456. + &req->req, req->req.actual,
  3457. + req->req.length, req->req.buf);
  3458. + size -= t;
  3459. + next += t;
  3460. + }
  3461. + }
  3462. + /* other gadget->eplist ep */
  3463. + list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
  3464. + if (ep->desc) {
  3465. + t = scnprintf(next, size,
  3466. + "\nFor %s Maxpkt is 0x%x "
  3467. + "index is 0x%x\n",
  3468. + ep->ep.name, ep_maxpacket(ep),
  3469. + ep_index(ep));
  3470. + size -= t;
  3471. + next += t;
  3472. +
  3473. + if (list_empty(&ep->queue)) {
  3474. + t = scnprintf(next, size,
  3475. + "its req queue is empty\n\n");
  3476. + size -= t;
  3477. + next += t;
  3478. + } else {
  3479. + list_for_each_entry(req, &ep->queue, queue) {
  3480. + t = scnprintf(next, size,
  3481. + "req %p actual 0x%x length"
  3482. + "0x%x buf %p\n",
  3483. + &req->req, req->req.actual,
  3484. + req->req.length, req->req.buf);
  3485. + size -= t;
  3486. + next += t;
  3487. + } /* end for each_entry of ep req */
  3488. + } /* end for else */
  3489. + } /* end for if(ep->queue) */
  3490. + } /* end (ep->desc) */
  3491. +
  3492. + spin_unlock_irqrestore(&udc->lock, flags);
  3493. +
  3494. + *eof = 1;
  3495. + return count - size;
  3496. +}
  3497. +
  3498. +#define create_proc_file() create_proc_read_entry(proc_filename, \
  3499. + 0, NULL, fsl_proc_read, NULL)
  3500. +
  3501. +#define remove_proc_file() remove_proc_entry(proc_filename, NULL)
  3502. +
  3503. +#else /* !CONFIG_USB_GADGET_DEBUG_FILES */
  3504. +
  3505. +#define create_proc_file() do {} while (0)
  3506. +#define remove_proc_file() do {} while (0)
  3507. +
  3508. +#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
  3509. +
  3510. +/*-------------------------------------------------------------------------*/
  3511. +
  3512. +/* Release udc structures */
  3513. +static void fsl_udc_release(struct device *dev)
  3514. +{
  3515. + complete(udc_controller->done);
  3516. + dma_free_coherent(dev, udc_controller->ep_qh_size,
  3517. + udc_controller->ep_qh, udc_controller->ep_qh_dma);
  3518. + kfree(udc_controller);
  3519. +}
  3520. +
  3521. +/******************************************************************
  3522. + Internal structure setup functions
  3523. +*******************************************************************/
  3524. +/*------------------------------------------------------------------
  3525. + * init resource for globle controller
  3526. + * Return the udc handle on success or NULL on failure
  3527. + ------------------------------------------------------------------*/
  3528. +static struct fsl_udc *__init struct_udc_setup(struct platform_device *pdev)
  3529. +{
  3530. + struct fsl_udc *udc;
  3531. + struct fsl_usb2_platform_data *pdata;
  3532. + size_t size;
  3533. +
  3534. + udc = kzalloc(sizeof(struct fsl_udc), GFP_KERNEL);
  3535. + if (udc == NULL) {
  3536. + ERR("malloc udc failed\n");
  3537. + return NULL;
  3538. + }
  3539. +
  3540. + pdata = pdev->dev.platform_data;
  3541. + udc->phy_mode = pdata->phy_mode; /* DDD FIXME */
  3542. +
  3543. + /* max_ep_nr is bidirectional ep number, max_ep doubles the number */
  3544. + udc->max_ep = pdata->max_ep_nr * 2;
  3545. +
  3546. + udc->eps = kzalloc(sizeof(struct fsl_ep) * udc->max_ep, GFP_KERNEL);
  3547. + if (!udc->eps) {
  3548. + ERR("malloc fsl_ep failed\n");
  3549. + goto cleanup;
  3550. + }
  3551. +
  3552. + /* initialized QHs, take care of alignment */
  3553. + size = udc->max_ep * sizeof(struct ep_queue_head);
  3554. + if (size < QH_ALIGNMENT)
  3555. + size = QH_ALIGNMENT;
  3556. + else if ((size % QH_ALIGNMENT) != 0) {
  3557. + size += QH_ALIGNMENT + 1;
  3558. + size &= ~(QH_ALIGNMENT - 1);
  3559. + }
  3560. + udc->ep_qh = dma_alloc_coherent(&pdev->dev, size,
  3561. + &udc->ep_qh_dma, GFP_KERNEL);
  3562. + if (!udc->ep_qh) {
  3563. + ERR("malloc QHs for udc failed\n");
  3564. + kfree(udc->eps);
  3565. + goto cleanup;
  3566. + }
  3567. +
  3568. + udc->ep_qh_size = size;
  3569. +
  3570. + /* Initialize ep0 status request structure */
  3571. + udc->status_req = container_of(fsl_alloc_request(NULL, GFP_KERNEL),
  3572. + struct fsl_req, req);
  3573. + /* allocate a small amount of memory to get valid address */
  3574. + udc->status_req->req.buf = kmalloc(8, GFP_KERNEL);
  3575. + udc->status_req->req.dma = virt_to_phys(udc->status_req->req.buf);
  3576. +
  3577. + udc->resume_state = USB_STATE_NOTATTACHED;
  3578. + udc->usb_state = USB_STATE_POWERED;
  3579. + udc->ep0_dir = 0;
  3580. + udc->remote_wakeup = 0; /* default to 0 on reset */
  3581. + spin_lock_init(&udc->lock);
  3582. +
  3583. + return udc;
  3584. +
  3585. +cleanup:
  3586. + kfree(udc);
  3587. + return NULL;
  3588. +}
  3589. +
  3590. +/*----------------------------------------------------------------
  3591. + * Setup the fsl_ep struct for eps
  3592. + * Link fsl_ep->ep to gadget->ep_list
  3593. + * ep0out is not used so do nothing here
  3594. + * ep0in should be taken care
  3595. + *--------------------------------------------------------------*/
  3596. +static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index,
  3597. + char *name, int link)
  3598. +{
  3599. + struct fsl_ep *ep = &udc->eps[index];
  3600. +
  3601. + ep->udc = udc;
  3602. + strcpy(ep->name, name);
  3603. + ep->ep.name = ep->name;
  3604. +
  3605. + ep->ep.ops = &fsl_ep_ops;
  3606. + ep->stopped = 0;
  3607. +
  3608. + /* for ep0: maxP defined in desc
  3609. + * for other eps, maxP is set by epautoconfig() called by gadget layer
  3610. + */
  3611. + ep->ep.maxpacket = (unsigned short) ~0;
  3612. +
  3613. + /* the queue lists any req for this ep */
  3614. + INIT_LIST_HEAD(&ep->queue);
  3615. +
  3616. + /* gagdet.ep_list used for ep_autoconfig so no ep0 */
  3617. + if (link)
  3618. + list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
  3619. + ep->gadget = &udc->gadget;
  3620. + ep->qh = &udc->ep_qh[index];
  3621. +
  3622. + return 0;
  3623. +}
  3624. +
  3625. +static int board_init(struct platform_device *pdev)
  3626. +{
  3627. + struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
  3628. +
  3629. + pr_debug("udc: pdev=0x%p pdata=0x%p\n", pdev, pdata);
  3630. +
  3631. + /*
  3632. + * do platform specific init: check the clock, grab/config pins, etc.
  3633. + */
  3634. + if (pdata->platform_init && pdata->platform_init(pdev) != 0)
  3635. + return -EINVAL;
  3636. +
  3637. + return 0;
  3638. +}
  3639. +
  3640. +/* Driver probe functions */
  3641. +
  3642. +static int __init fsl_udc_probe(struct platform_device *pdev)
  3643. +{
  3644. + struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
  3645. + struct fsl_udc *udc;
  3646. + unsigned int i;
  3647. + struct otg_transceiver *transceiver = NULL;
  3648. + int status = -ENODEV;
  3649. + u32 id;
  3650. + int irq_number;
  3651. + u64 rsrc_start, rsrc_len;
  3652. + int ret = -ENODEV;
  3653. +
  3654. + pr_debug("udc: pdev=0x%p pdata=0x%p\n", pdev, pdata);
  3655. +
  3656. + if (board_init(pdev) != 0)
  3657. + return -EINVAL;
  3658. +
  3659. + /* Initialize the udc structure including QH member and other member */
  3660. + udc = (struct fsl_udc *) struct_udc_setup(pdev);
  3661. + udc_controller = udc;
  3662. +
  3663. + if (!udc) {
  3664. + ERR("udc is NULL \n");
  3665. + return -ENOMEM;
  3666. + }
  3667. + dev_set_drvdata(&pdev->dev, udc);
  3668. + pr_debug("udc_controller=0x%p", udc_controller);
  3669. +
  3670. + udc->pdata = pdata;
  3671. + udc->xcvr_type = pdata->xcvr_type;
  3672. +
  3673. +#ifdef CONFIG_USB_OTG
  3674. + udc->transceiver = otg_get_transceiver();
  3675. + pr_debug("udc: otg_get_transceiver returns 0x%p", udc->transceiver);
  3676. +#endif
  3677. +
  3678. + if (pdev->resource[1].flags != IORESOURCE_IRQ)
  3679. + return -ENODEV;
  3680. +
  3681. + rsrc_start = pdev->resource[0].start;
  3682. + rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  3683. +
  3684. + pr_debug(" start=0x%ux end=0x%ux\n",
  3685. + pdev->resource[0].start, pdev->resource[0].end);
  3686. + pr_debug("rsrc_start=0x%llx rsrc_len=0x%llx\n", rsrc_start, rsrc_len);
  3687. +
  3688. + dr_regs = (struct fsl_usb_device_regs *)pdata->regs;
  3689. +
  3690. + pr_debug("udc: pdate=0x%p dr_regs=0x%p\n", pdata, dr_regs);
  3691. + pr_debug("udc: hci_version=0x%x\n", dr_regs->hciversion);
  3692. + pr_debug("udc: otgsc at 0x%p\n", &dr_regs->otgsc);
  3693. +
  3694. + id = fsl_readl(&dr_regs->id);
  3695. + printk(KERN_INFO "FSL2 USBOTG h/w ID=0x%x revision=0x%x\n",
  3696. + id & 0x3f, id >> 16);
  3697. +
  3698. + /* USB OTG module IRQ */
  3699. + irq_number = platform_get_irq(pdev, 0);
  3700. + if (irq_number > 128) {
  3701. + status = request_irq(irq_number, fsl_udc_irq, IRQF_SHARED,
  3702. + driver_name, udc);
  3703. + if (status) {
  3704. + ERR("can't get irq %d, err=%d\n", irq_number, status);
  3705. + goto err2;
  3706. + }
  3707. + } else {
  3708. + status = -ENODEV;
  3709. + goto err2;
  3710. + }
  3711. +
  3712. + if (!udc->transceiver) {
  3713. + /* initialize usb hw reg except for regs for EP,
  3714. + * leave usbintr reg untouched*/
  3715. + dr_controller_setup(udc);
  3716. + }
  3717. +
  3718. + /* here comes the stand operations for probe
  3719. + * set the fsl_udc->gadget.xxx
  3720. + */
  3721. + udc->gadget.ops = &fsl_gadget_ops;
  3722. +
  3723. + /* gadget.ep0 is a pointer */
  3724. + udc->gadget.ep0 = &udc->eps[0].ep;
  3725. + INIT_LIST_HEAD(&udc->gadget.ep_list);
  3726. + udc->gadget.speed = USB_SPEED_UNKNOWN;
  3727. + udc->gadget.name = driver_name;
  3728. +
  3729. + /* Setup gadget.dev and register with kernel */
  3730. + strcpy(udc->gadget.dev.bus_id, "gadget");
  3731. + udc->gadget.dev.release = fsl_udc_release;
  3732. + udc->gadget.dev.parent = &pdev->dev;
  3733. +
  3734. + ret = device_register(&udc->gadget.dev);
  3735. + if (ret < 0)
  3736. + goto err3;
  3737. +
  3738. + if (udc->transceiver)
  3739. + udc->gadget.is_otg = 1;
  3740. +
  3741. + /* setup QH and epctrl for ep0 */
  3742. + ep0_setup(udc);
  3743. +
  3744. + /* setup udc->eps[] for ep0 */
  3745. + struct_ep_setup(udc_controller, 0, "ep0", 0);
  3746. + /* for ep0: the desc defined here;
  3747. + * for other eps, gadget layer called ep_enable with defined desc
  3748. + */
  3749. + udc->eps[0].desc = &fsl_ep0_desc;
  3750. + udc->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD;
  3751. +
  3752. + /* setup the udc->eps[] for non-control endpoints and link
  3753. + * to gadget.ep_list */
  3754. + for (i = 1; i < (int)(udc->max_ep / 2); i++) {
  3755. + char name[14];
  3756. +
  3757. + sprintf(name, "ep%dout", i);
  3758. + struct_ep_setup(udc, i * 2, name, 1);
  3759. + sprintf(name, "ep%din", i);
  3760. + struct_ep_setup(udc, i * 2 + 1, name, 1);
  3761. + }
  3762. +
  3763. + /* use dma_pool for TD management */
  3764. + udc_controller->td_pool = dma_pool_create("udc_td", &pdev->dev,
  3765. + sizeof(struct ep_td_struct),
  3766. + DTD_ALIGNMENT, UDC_DMA_BOUNDARY);
  3767. + if (udc->td_pool == NULL) {
  3768. + ret = -ENOMEM;
  3769. + goto err4;
  3770. + }
  3771. +#if 0 // DDD why this? hoarks OTG host
  3772. + pullup_disable(udc);
  3773. +#endif
  3774. +
  3775. + create_proc_file();
  3776. + return 0;
  3777. +
  3778. +err4:
  3779. + device_unregister(&udc_controller->gadget.dev);
  3780. +err3:
  3781. + free_irq(udc_controller->irq, udc_controller);
  3782. +err2:
  3783. + kfree(udc);
  3784. + if (transceiver)
  3785. + put_device(transceiver->dev);
  3786. + release_mem_region(pdev->resource[0].start,
  3787. + pdev->resource[0].end - pdev->resource[0].start + 1);
  3788. + return status;
  3789. +
  3790. +}
  3791. +
  3792. +/* Driver removal functions
  3793. + * Free resources
  3794. + * Finish pending transaction
  3795. + */
  3796. +static int __exit fsl_udc_remove(struct platform_device *pdev)
  3797. +{
  3798. + struct device *dev = &pdev->dev;
  3799. + struct fsl_udc *udc = (struct fsl_udc *)dev_get_drvdata(dev);
  3800. + struct fsl_usb2_platform_data *pdata;
  3801. + int irq_number;
  3802. +
  3803. + DECLARE_COMPLETION(done);
  3804. +
  3805. + pdata = pdev->dev.platform_data;
  3806. +
  3807. + if (!udc)
  3808. + return -ENODEV;
  3809. +
  3810. + udc->done = &done;
  3811. +
  3812. + /* DR has been stopped in usb_gadget_unregister_driver() */
  3813. +
  3814. + if (udc->transceiver) {
  3815. + put_device(udc->transceiver->dev);
  3816. + udc->transceiver = NULL;
  3817. + }
  3818. +
  3819. + /* remove proc */
  3820. + remove_proc_file();
  3821. +
  3822. + /* free irq */
  3823. + irq_number = udc->irq;
  3824. + free_irq(pdev->resource[1].start, udc);
  3825. + udc->irq = 0;
  3826. +
  3827. + /* Free allocated memory */
  3828. + kfree(udc->status_req->req.buf);
  3829. + kfree(udc->status_req);
  3830. + kfree(udc_controller->eps);
  3831. +
  3832. + dma_pool_destroy(udc_controller->td_pool);
  3833. + /* deinitlaize all ep: strcut */
  3834. + /* deinitialize ep0: reg and QH */
  3835. +
  3836. + device_unregister(&udc->gadget.dev);
  3837. + /* free udc --wait for the release() finished */
  3838. + wait_for_completion(&done);
  3839. +
  3840. + /*
  3841. + * do platform specific un-initialization:
  3842. + * release iomux pins, etc.
  3843. + */
  3844. + if (pdata->platform_uninit)
  3845. + pdata->platform_uninit(pdev);
  3846. +
  3847. + return 0;
  3848. +}
  3849. +
  3850. +static int udc_suspend(struct fsl_udc *udc)
  3851. +{
  3852. + udc->stopped = 1;
  3853. + return 0;
  3854. +}
  3855. +
  3856. +/*
  3857. + * Modify Power management attributes
  3858. + * Used by OTG statemachine to disable gadget temporarily
  3859. + * Here we stop the DR controller and disable the irq
  3860. + * @param dev device controller pointer
  3861. + * @param state current state
  3862. + * @return The function returns 0 on success or -1 if failed
  3863. + */
  3864. +static int fsl_udc_suspend(struct device *dev, pm_message_t state)
  3865. +{
  3866. + struct fsl_udc *udc = (struct fsl_udc *)dev_get_drvdata(dev);
  3867. + pr_debug("udc: Suspend. state=%d\n", state.event);
  3868. + return udc_suspend(udc);
  3869. +}
  3870. +
  3871. +static int udc_resume(struct fsl_udc *udc)
  3872. +{
  3873. + /*Enable DR irq reg and set controller Run */
  3874. + if (udc->stopped) {
  3875. + dr_controller_setup(udc);
  3876. + dr_controller_run(udc);
  3877. + }
  3878. + udc->usb_state = USB_STATE_ATTACHED;
  3879. + udc->ep0_state = WAIT_FOR_SETUP;
  3880. + udc->ep0_dir = 0;
  3881. + return 0;
  3882. +}
  3883. +
  3884. +/*
  3885. + * Invoked on USB resume. May be called in_interrupt.
  3886. + * Here we start the DR controller and enable the irq
  3887. + * @param dev device controller pointer
  3888. + * @return The function returns 0 on success or -1 if failed
  3889. + */
  3890. +static int fsl_udc_resume(struct device *dev)
  3891. +{
  3892. + struct fsl_udc *udc = (struct fsl_udc *)dev_get_drvdata(dev);
  3893. + pr_debug("udc: Resume dev=0x%p udc=0x%p\n", dev, udc);
  3894. +
  3895. + return udc_resume(udc);
  3896. +}
  3897. +
  3898. +/*-------------------------------------------------------------------------
  3899. + Register entry point for the peripheral controller driver
  3900. +--------------------------------------------------------------------------*/
  3901. +static struct platform_driver udc_driver = {
  3902. + .probe = fsl_udc_probe,
  3903. + .remove = __exit_p(fsl_udc_remove),
  3904. + .driver = {
  3905. + .name = (char *)driver_name,
  3906. + .owner = THIS_MODULE,
  3907. + },
  3908. +};
  3909. +
  3910. +static int __init udc_init(void)
  3911. +{
  3912. + printk(KERN_INFO "%s version %s init \n", driver_desc, DRIVER_VERSION);
  3913. + return platform_driver_register(&udc_driver);
  3914. +}
  3915. +
  3916. +module_init(udc_init);
  3917. +
  3918. +static void __exit udc_exit(void)
  3919. +{
  3920. + platform_driver_unregister(&udc_driver);
  3921. + printk(KERN_INFO "%s unregistered \n", driver_desc);
  3922. +}
  3923. +
  3924. +module_exit(udc_exit);
  3925. +
  3926. +MODULE_DESCRIPTION(DRIVER_DESC);
  3927. +MODULE_AUTHOR(DRIVER_AUTHOR);
  3928. +MODULE_LICENSE("GPL");
  3929. --- a/drivers/usb/host/Kconfig
  3930. +++ b/drivers/usb/host/Kconfig
  3931. @@ -32,6 +32,7 @@ config USB_EHCI_HCD
  3932. config USB_EHCI_ROOT_HUB_TT
  3933. bool "Root Hub Transaction Translators (EXPERIMENTAL)"
  3934. depends on USB_EHCI_HCD && EXPERIMENTAL
  3935. + default y if M54455
  3936. ---help---
  3937. Some EHCI chips have vendor-specific extensions to integrate
  3938. transaction translators, so that no OHCI or UHCI companion
  3939. @@ -60,12 +61,12 @@ config USB_EHCI_TT_NEWSCHED
  3940. config USB_EHCI_BIG_ENDIAN_MMIO
  3941. bool
  3942. - depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || ARCH_IXP4XX)
  3943. + depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || ARCH_IXP4XX || M54455)
  3944. default y
  3945. config USB_EHCI_BIG_ENDIAN_DESC
  3946. bool
  3947. - depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX)
  3948. + depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX || M54455)
  3949. default y
  3950. config USB_EHCI_FSL
  3951. @@ -260,3 +261,19 @@ config USB_R8A66597_HCD
  3952. To compile this driver as a module, choose M here: the
  3953. module will be called r8a66597-hcd.
  3954. +choice
  3955. + prompt "Select transceiver"
  3956. + depends on M54455
  3957. + default USB_M5445X_ULPI
  3958. +
  3959. +config USB_M5445X_ULPI
  3960. + bool "External ULPI"
  3961. + ---help---
  3962. + Enable support for the external HS ULPI transceiver.
  3963. +
  3964. +config USB_M5445X_FSLS
  3965. + bool "On-chip (FL/LS only)"
  3966. + ---help---
  3967. + Enable support for the on-chip FL/LS transceiver.
  3968. +endchoice
  3969. +
  3970. --- /dev/null
  3971. +++ b/drivers/usb/host/ehci-arc.c
  3972. @@ -0,0 +1,431 @@
  3973. +/*
  3974. + * drivers/usb/host/ehci-arc.c
  3975. + *
  3976. + * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  3977. + */
  3978. +
  3979. +/*
  3980. + * The code contained herein is licensed under the GNU General Public
  3981. + * License. You may obtain a copy of the GNU General Public License
  3982. + * Version 2 or later at the following locations:
  3983. + *
  3984. + * http://www.opensource.org/licenses/gpl-license.html
  3985. + * http://www.gnu.org/copyleft/gpl.html
  3986. + */
  3987. +
  3988. +/* Note: this file is #included by ehci-hcd.c */
  3989. +
  3990. +#include <linux/platform_device.h>
  3991. +#include <linux/usb/fsl_usb2.h>
  3992. +#include <linux/fsl_devices.h>
  3993. +#include <linux/usb/otg.h>
  3994. +
  3995. +#include "ehci-fsl.h"
  3996. +
  3997. +
  3998. +/* FIXME: Power Managment is un-ported so temporarily disable it */
  3999. +#undef CONFIG_PM
  4000. +
  4001. +/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
  4002. +
  4003. +/* configure so an HC device and id are always provided */
  4004. +/* always called with process context; sleeping is OK */
  4005. +
  4006. +/**
  4007. + * usb_hcd_fsl_probe - initialize FSL-based HCDs
  4008. + * @drvier: Driver to be used for this HCD
  4009. + * @pdev: USB Host Controller being probed
  4010. + * Context: !in_interrupt()
  4011. + *
  4012. + * Allocates basic resources for this USB host controller.
  4013. + *
  4014. + */
  4015. +static int usb_hcd_fsl_probe(const struct hc_driver *driver,
  4016. + struct platform_device *pdev)
  4017. +{
  4018. + struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
  4019. + struct usb_hcd *hcd;
  4020. + struct resource *res;
  4021. + int irq;
  4022. + int retval;
  4023. +
  4024. + pr_debug("initializing FSL-SOC USB Controller\n");
  4025. +
  4026. + /* Need platform data for setup */
  4027. + if (!pdata) {
  4028. + dev_err(&pdev->dev,
  4029. + "No platform data for %s.\n", pdev->dev.bus_id);
  4030. + return -ENODEV;
  4031. + }
  4032. +
  4033. + retval = fsl_platform_verify(pdev);
  4034. + if (retval)
  4035. + return retval;
  4036. +
  4037. + /*
  4038. + * do platform specific init: check the clock, grab/config pins, etc.
  4039. + */
  4040. + if (pdata->platform_init && pdata->platform_init(pdev)) {
  4041. + retval = -ENODEV;
  4042. + goto err1;
  4043. + }
  4044. +
  4045. + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  4046. + if (!res) {
  4047. + dev_err(&pdev->dev,
  4048. + "Found HC with no IRQ. Check %s setup!\n",
  4049. + pdev->dev.bus_id);
  4050. + return -ENODEV;
  4051. + }
  4052. + irq = res->start;
  4053. +
  4054. + fsl_platform_set_vbus_power(pdev, 1);
  4055. +
  4056. + hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
  4057. + if (!hcd) {
  4058. + retval = -ENOMEM;
  4059. + goto err1;
  4060. + }
  4061. +
  4062. + if (pdata->regs) {
  4063. + pr_debug("REGS: using pdata->regs (0x%p)\n", pdata->regs);
  4064. + hcd->regs = pdata->regs;
  4065. + hcd->rsrc_start = pdata->r_start;
  4066. + hcd->rsrc_len = pdata->r_len;
  4067. + } else {
  4068. + pr_debug("REGS: NO pdata->regs\n");
  4069. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  4070. + if (!res) {
  4071. + dev_err(&pdev->dev, "Found HC with no register addr. "
  4072. + "Check %s setup!\n", pdev->dev.bus_id);
  4073. + retval = -ENODEV;
  4074. + goto err2;
  4075. + }
  4076. + hcd->rsrc_start = res->start;
  4077. + hcd->rsrc_len = res->end - res->start + 1;
  4078. +
  4079. + /*
  4080. + printk("DDD %s(): rsrc_start=0x%llx rsrc_len=0x%llx "
  4081. + "pdata=0x%p\n", __FUNCTION__,
  4082. + hcd->rsrc_start, hcd->rsrc_len, pdata);
  4083. + */
  4084. +
  4085. + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  4086. + driver->description)) {
  4087. + dev_dbg(&pdev->dev, "request_mem_region failed\n");
  4088. + retval = -EBUSY;
  4089. + goto err2;
  4090. + }
  4091. + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  4092. +
  4093. + if (hcd->regs == NULL) {
  4094. + dev_dbg(&pdev->dev, "error mapping memory\n");
  4095. + retval = -EFAULT;
  4096. + goto err3;
  4097. + }
  4098. + }
  4099. + hcd->power_budget = pdata->power_budget;
  4100. +
  4101. + /* DDD
  4102. + * the following must be done by this point, otherwise the OTG
  4103. + * host port doesn't make it thru initializtion.
  4104. + * ehci_halt(), called by ehci_fsl_setup() returns -ETIMEDOUT
  4105. + */
  4106. + fsl_platform_set_host_mode(hcd);
  4107. +
  4108. + retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  4109. + if (retval != 0)
  4110. + goto err4;
  4111. +
  4112. +#if defined(CONFIG_USB_OTG)
  4113. + if (pdata->does_otg) {
  4114. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  4115. +
  4116. + ehci->transceiver = otg_get_transceiver();
  4117. +
  4118. + if (ehci->transceiver) {
  4119. + retval = otg_set_host(ehci->transceiver,
  4120. + &ehci_to_hcd(ehci)->self);
  4121. + if (retval) {
  4122. + if (ehci->transceiver)
  4123. + put_device(ehci->transceiver->dev);
  4124. + goto err3;
  4125. + }
  4126. + } else {
  4127. + printk(KERN_ERR "can't find transceiver\n");
  4128. + retval = -ENODEV;
  4129. + goto err3;
  4130. + }
  4131. + }
  4132. +#endif
  4133. +
  4134. + return retval;
  4135. +
  4136. +err4:
  4137. + /* DDD only if we did the iomap() iounmap(hcd->regs); */
  4138. +err3:
  4139. + /* DDD only if we did a request_
  4140. + * release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  4141. + */
  4142. +err2:
  4143. + usb_put_hcd(hcd);
  4144. +err1:
  4145. + dev_err(&pdev->dev, "init %s fail, %d\n", pdev->dev.bus_id, retval);
  4146. + if (pdata->platform_uninit)
  4147. + pdata->platform_uninit(pdev);
  4148. + return retval;
  4149. +}
  4150. +
  4151. +/* may be called without controller electrically present */
  4152. +/* may be called with controller, bus, and devices active */
  4153. +
  4154. +/**
  4155. + * usb_hcd_fsl_remove - shutdown processing for FSL-based HCDs
  4156. + * @dev: USB Host Controller being removed
  4157. + * Context: !in_interrupt()
  4158. + *
  4159. + * Reverses the effect of usb_hcd_fsl_probe().
  4160. + *
  4161. + */
  4162. +static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
  4163. + struct platform_device *pdev)
  4164. +{
  4165. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  4166. + struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
  4167. +
  4168. + /* DDD shouldn't we turn off the power here? */
  4169. + fsl_platform_set_vbus_power(pdev, 0);
  4170. +
  4171. + usb_remove_hcd(hcd);
  4172. +
  4173. + if (ehci->transceiver) {
  4174. + (void)otg_set_host(ehci->transceiver, 0);
  4175. + put_device(ehci->transceiver->dev);
  4176. + }
  4177. + usb_put_hcd(hcd);
  4178. +
  4179. + /*
  4180. + * do platform specific un-initialization:
  4181. + * release iomux pins, etc.
  4182. + */
  4183. + if (pdata->platform_uninit)
  4184. + pdata->platform_uninit(pdev);
  4185. +}
  4186. +
  4187. +/* called after powerup, by probe or system-pm "wakeup" */
  4188. +static int ehci_fsl_reinit(struct ehci_hcd *ehci)
  4189. +{
  4190. + fsl_platform_usb_setup(ehci_to_hcd(ehci));
  4191. + ehci_port_power(ehci, 0);
  4192. +
  4193. + return 0;
  4194. +}
  4195. +
  4196. +/* called during probe() after chip reset completes */
  4197. +static int ehci_fsl_setup(struct usb_hcd *hcd)
  4198. +{
  4199. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  4200. + int retval;
  4201. + struct fsl_usb2_platform_data *pdata;
  4202. + pdata = hcd->self.controller-> platform_data;
  4203. +
  4204. + ehci->big_endian_desc = pdata->big_endian_desc;
  4205. + ehci->big_endian_mmio = pdata->big_endian_mmio;
  4206. +
  4207. + /* EHCI registers start at offset 0x100 */
  4208. + ehci->caps = hcd->regs + 0x100;
  4209. + ehci->regs = hcd->regs + 0x100 +
  4210. + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  4211. +
  4212. + pr_debug("%s(): ehci->caps=0x%p ehci->regs=0x%p\n", __FUNCTION__,
  4213. + ehci->caps, ehci->regs);
  4214. +
  4215. + dbg_hcs_params(ehci, "reset");
  4216. + dbg_hcc_params(ehci, "reset");
  4217. +
  4218. + /* cache this readonly data; minimize chip reads */
  4219. + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  4220. +
  4221. + retval = ehci_halt(ehci);
  4222. + if (retval)
  4223. + return retval;
  4224. +
  4225. + /* data structure init */
  4226. + retval = ehci_init(hcd);
  4227. + if (retval)
  4228. + return retval;
  4229. +
  4230. + ehci->is_tdi_rh_tt = 1;
  4231. +
  4232. + ehci->sbrn = 0x20;
  4233. +
  4234. + ehci_reset(ehci);
  4235. +
  4236. + retval = ehci_fsl_reinit(ehci);
  4237. + return retval;
  4238. +}
  4239. +
  4240. +static const struct hc_driver ehci_fsl_hc_driver = {
  4241. + .description = hcd_name,
  4242. + .product_desc = "Freescale On-Chip EHCI Host Controller",
  4243. + .hcd_priv_size = sizeof(struct ehci_hcd),
  4244. +
  4245. + /*
  4246. + * generic hardware linkage
  4247. + */
  4248. + .irq = ehci_irq,
  4249. + .flags = FSL_PLATFORM_HC_FLAGS,
  4250. +
  4251. + /*
  4252. + * basic lifecycle operations
  4253. + */
  4254. + .reset = ehci_fsl_setup,
  4255. + .start = ehci_run,
  4256. + .stop = ehci_stop,
  4257. + .shutdown = ehci_shutdown,
  4258. +
  4259. + /*
  4260. + * managing i/o requests and associated device resources
  4261. + */
  4262. + .urb_enqueue = ehci_urb_enqueue,
  4263. + .urb_dequeue = ehci_urb_dequeue,
  4264. + .endpoint_disable = ehci_endpoint_disable,
  4265. +
  4266. + /*
  4267. + * scheduling support
  4268. + */
  4269. + .get_frame_number = ehci_get_frame,
  4270. +
  4271. + /*
  4272. + * root hub support
  4273. + */
  4274. + .hub_status_data = ehci_hub_status_data,
  4275. + .hub_control = ehci_hub_control,
  4276. + .bus_suspend = ehci_bus_suspend,
  4277. + .bus_resume = ehci_bus_resume,
  4278. +};
  4279. +
  4280. +#ifdef CONFIG_USB_OTG
  4281. +/*
  4282. + * Holding pen for all the EHCI registers except port_status,
  4283. + * which is a zero element array and hence takes no space.
  4284. + * The port_status register is saved in usb_ehci_portsc.
  4285. + */
  4286. +volatile static struct ehci_regs usb_ehci_regs;
  4287. +static u32 usb_ehci_portsc;
  4288. +
  4289. +/* suspend/resume, section 4.3 */
  4290. +
  4291. +/* These routines rely on the bus (pci, platform, etc)
  4292. + * to handle powerdown and wakeup, and currently also on
  4293. + * transceivers that don't need any software attention to set up
  4294. + * the right sort of wakeup.
  4295. + *
  4296. + * They're also used for turning on/off the port when doing OTG.
  4297. + */
  4298. +static int ehci_fsl_drv_suspend(struct platform_device *pdev,
  4299. + pm_message_t message)
  4300. +{
  4301. + struct usb_hcd *hcd = platform_get_drvdata(pdev);
  4302. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  4303. + u32 tmp;
  4304. +
  4305. + pr_debug("%s pdev=0x%p ehci=0x%p hcd=0x%p\n",
  4306. + __FUNCTION__, pdev, ehci, hcd);
  4307. + pr_debug("%s ehci->regs=0x%p hcd->regs=0x%p hcd->state=%d\n",
  4308. + __FUNCTION__, ehci->regs, hcd->regs, hcd->state);
  4309. +
  4310. + hcd->state = HC_STATE_SUSPENDED;
  4311. + pdev->dev.power.power_state = PMSG_SUSPEND;
  4312. +
  4313. + if (hcd->driver->suspend)
  4314. + return hcd->driver->suspend(hcd, message);
  4315. +
  4316. + /* ignore non-host interrupts */
  4317. + clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  4318. +
  4319. + tmp = ehci_readl(ehci, &ehci->regs->command);
  4320. + tmp &= ~CMD_RUN;
  4321. + ehci_writel(ehci, tmp, &ehci->regs->command);
  4322. +
  4323. + memcpy((void *)&usb_ehci_regs, ehci->regs, sizeof(struct ehci_regs));
  4324. + usb_ehci_portsc = ehci_readl(ehci, &ehci->regs->port_status[0]);
  4325. +
  4326. + /* clear the W1C bits */
  4327. + usb_ehci_portsc &= cpu_to_hc32(ehci, ~PORT_RWC_BITS);
  4328. +
  4329. + fsl_platform_set_vbus_power(pdev, 0);
  4330. + /* clear PP to cut power to the port */
  4331. + tmp = ehci_readl(ehci, &ehci->regs->port_status[0]);
  4332. + tmp &= ~PORT_POWER;
  4333. + ehci_writel(ehci, tmp, &ehci->regs->port_status[0]);
  4334. +
  4335. + return 0;
  4336. +}
  4337. +
  4338. +static int ehci_fsl_drv_resume(struct platform_device *pdev)
  4339. +{
  4340. + struct usb_hcd *hcd = platform_get_drvdata(pdev);
  4341. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  4342. + u32 tmp;
  4343. + struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
  4344. +
  4345. + pr_debug("%s pdev=0x%p pdata=0x%p ehci=0x%p hcd=0x%p\n",
  4346. + __FUNCTION__, pdev, pdata, ehci, hcd);
  4347. +
  4348. + pr_debug("%s ehci->regs=0x%p hcd->regs=0x%p",
  4349. + __FUNCTION__, ehci->regs, hcd->regs);
  4350. +
  4351. + memcpy(ehci->regs, (void *)&usb_ehci_regs, sizeof(struct ehci_regs));
  4352. + ehci_writel(ehci, usb_ehci_portsc, &ehci->regs->port_status[0]);
  4353. +
  4354. + tmp = USBMODE_CM_HOST | (pdata->es ? USBMODE_ES : 0);
  4355. + ehci_writel(ehci, tmp, hcd->regs + FSL_SOC_USB_USBMODE);
  4356. +
  4357. + set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  4358. + hcd->state = HC_STATE_RUNNING;
  4359. + pdev->dev.power.power_state = PMSG_ON;
  4360. +
  4361. + tmp = ehci_readl(ehci, &ehci->regs->command);
  4362. + tmp |= CMD_RUN;
  4363. + ehci_writel(ehci, tmp, &ehci->regs->command);
  4364. +
  4365. + fsl_platform_set_vbus_power(pdev, 1);
  4366. +
  4367. + usb_hcd_resume_root_hub(hcd);
  4368. +
  4369. + return 0;
  4370. +}
  4371. +#endif /* CONFIG_USB_OTG */
  4372. +
  4373. +static int ehci_fsl_drv_probe(struct platform_device *pdev)
  4374. +{
  4375. + if (usb_disabled())
  4376. + return -ENODEV;
  4377. +
  4378. + return usb_hcd_fsl_probe(&ehci_fsl_hc_driver, pdev);
  4379. +}
  4380. +
  4381. +static int ehci_fsl_drv_remove(struct platform_device *pdev)
  4382. +{
  4383. + struct usb_hcd *hcd = platform_get_drvdata(pdev);
  4384. +
  4385. + usb_hcd_fsl_remove(hcd, pdev);
  4386. +
  4387. + return 0;
  4388. +}
  4389. +
  4390. +MODULE_ALIAS("fsl-ehci");
  4391. +
  4392. +static struct platform_driver ehci_fsl_driver = {
  4393. + .probe = ehci_fsl_drv_probe,
  4394. + .remove = ehci_fsl_drv_remove,
  4395. + .shutdown = usb_hcd_platform_shutdown,
  4396. +#ifdef CONFIG_USB_OTG
  4397. + .suspend = ehci_fsl_drv_suspend,
  4398. + .resume = ehci_fsl_drv_resume,
  4399. +#endif
  4400. + .driver = {
  4401. + .name = "fsl-ehci",
  4402. + },
  4403. +};
  4404. --- a/drivers/usb/host/ehci-fsl.h
  4405. +++ b/drivers/usb/host/ehci-fsl.h
  4406. @@ -18,6 +18,8 @@
  4407. #ifndef _EHCI_FSL_H
  4408. #define _EHCI_FSL_H
  4409. +#include <linux/usb/fsl_xcvr.h>
  4410. +
  4411. /* offsets for the non-ehci registers in the FSL SOC USB controller */
  4412. #define FSL_SOC_USB_ULPIVP 0x170
  4413. #define FSL_SOC_USB_PORTSC1 0x184
  4414. @@ -34,5 +36,29 @@
  4415. #define FSL_SOC_USB_PRICTRL 0x40c /* NOTE: big-endian */
  4416. #define FSL_SOC_USB_SICTRL 0x410 /* NOTE: big-endian */
  4417. #define FSL_SOC_USB_CTRL 0x500 /* NOTE: big-endian */
  4418. -#define SNOOP_SIZE_2GB 0x1e
  4419. +
  4420. +#ifdef CONFIG_MPC834x
  4421. +#include <sysdev/fsl_usb.h>
  4422. +#endif
  4423. +
  4424. +#ifdef CONFIG_ARCH_MX3
  4425. +#include <asm/arch/mx31_usb.h>
  4426. +#endif
  4427. +
  4428. +#ifdef CONFIG_ARCH_MX27
  4429. +#include <asm/arch/mx27_usb.h>
  4430. +#endif
  4431. +
  4432. +#ifdef CONFIG_M54455
  4433. +#include <asm-m68k/mcf5445x_usb.h>
  4434. +#endif
  4435. +
  4436. +
  4437. +static void fsl_platform_set_vbus_power(struct platform_device *pdev, int on)
  4438. +{
  4439. + struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
  4440. +
  4441. + if (pdata->xcvr_ops && pdata->xcvr_ops->set_vbus_power)
  4442. + pdata->xcvr_ops->set_vbus_power(pdata, on);
  4443. +}
  4444. #endif /* _EHCI_FSL_H */
  4445. --- a/drivers/usb/host/ehci-hcd.c
  4446. +++ b/drivers/usb/host/ehci-hcd.c
  4447. @@ -1043,6 +1043,11 @@ MODULE_LICENSE ("GPL");
  4448. #define PLATFORM_DRIVER ixp4xx_ehci_driver
  4449. #endif
  4450. +#ifdef CONFIG_M54455
  4451. +#include "ehci-arc.c"
  4452. +#define PLATFORM_DRIVER ehci_fsl_driver
  4453. +#endif
  4454. +
  4455. #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
  4456. !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER)
  4457. #error "missing bus glue for ehci-hcd"
  4458. --- a/drivers/usb/host/ehci-mem.c
  4459. +++ b/drivers/usb/host/ehci-mem.c
  4460. @@ -40,7 +40,8 @@ static inline void ehci_qtd_init(struct
  4461. {
  4462. memset (qtd, 0, sizeof *qtd);
  4463. qtd->qtd_dma = dma;
  4464. - qtd->hw_token = cpu_to_le32 (QTD_STS_HALT);
  4465. + // DDD official code` has: qtd->hw_token = cpu_to_le32 (QTD_STS_HALT);
  4466. + qtd->hw_token = cpu_to_hc32 (ehci, QTD_STS_HALT);
  4467. qtd->hw_next = EHCI_LIST_END(ehci);
  4468. qtd->hw_alt_next = EHCI_LIST_END(ehci);
  4469. INIT_LIST_HEAD (&qtd->qtd_list);
  4470. @@ -211,9 +212,11 @@ static int ehci_mem_init (struct ehci_hc
  4471. }
  4472. /* Hardware periodic table */
  4473. - ehci->periodic = (__le32 *)
  4474. + // DDD official code has: ehci->periodic = (__le32 *)
  4475. + ehci->periodic = (__hc32 *)
  4476. dma_alloc_coherent (ehci_to_hcd(ehci)->self.controller,
  4477. - ehci->periodic_size * sizeof(__le32),
  4478. + // DDD official: ehci->periodic_size * sizeof(__le32),
  4479. + ehci->periodic_size * sizeof(__hc32),
  4480. &ehci->periodic_dma, 0);
  4481. if (ehci->periodic == NULL) {
  4482. goto fail;
  4483. --- a/drivers/usb/host/ehci.h
  4484. +++ b/drivers/usb/host/ehci.h
  4485. @@ -122,6 +122,12 @@ struct ehci_hcd { /* one per controlle
  4486. u8 sbrn; /* packed release number */
  4487. + /*
  4488. + * OTG controllers and transceivers need software interaction;
  4489. + * other external transceivers should be software-transparent
  4490. + */
  4491. + struct otg_transceiver *transceiver;
  4492. +
  4493. /* irq statistics */
  4494. #ifdef EHCI_STATS
  4495. struct ehci_stats stats;
  4496. @@ -753,6 +759,22 @@ ehci_port_speed(struct ehci_hcd *ehci, u
  4497. #define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr)
  4498. #endif
  4499. +#if defined(CONFIG_COLDFIRE)
  4500. +/*
  4501. + * Sorry, include/asm-m68k/io.h is messed up. It will give you a
  4502. + * BE readl or a LE readl depending on whether or not CONFIG_PCI is set.
  4503. + * how broken is that? Do the right thing here.
  4504. + */
  4505. +#undef readl
  4506. +#undef writel
  4507. +
  4508. +#define readl(addr) in_le32((__force unsigned *)(addr))
  4509. +#define writel(val,addr) out_le32((__force unsigned *)(addr),(val))
  4510. +
  4511. +#define readl_be(addr) in_be32((__force unsigned *)(addr))
  4512. +#define writel_be(val, addr) out_be32((__force unsigned *)(addr), (val))
  4513. +#endif
  4514. +
  4515. static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
  4516. __u32 __iomem * regs)
  4517. {
  4518. --- /dev/null
  4519. +++ b/drivers/usb/otg/Makefile
  4520. @@ -0,0 +1,5 @@
  4521. +#
  4522. +# Makefile for USB OTG controller driver
  4523. +#
  4524. +fsl_usb2_otg-objs := fsl_otg.o otg_fsm.o
  4525. +obj-y += fsl_usb2_otg.o
  4526. --- /dev/null
  4527. +++ b/drivers/usb/otg/fsl_otg.c
  4528. @@ -0,0 +1,1515 @@
  4529. +/*
  4530. + * Copyright (c) Freescale Semiconductor, Inc. 2006-2007
  4531. + *
  4532. + * USB OTG ULPI driver
  4533. + *
  4534. + * Based on code for MPC from:
  4535. + * Leo Li<[email protected]>
  4536. + * Jerry Huang<[email protected]>
  4537. + *
  4538. + * and M5329 code from
  4539. + * Yaroslav Vinogradov [email protected]
  4540. + * Andrey Butok
  4541. + *
  4542. + * Initialization based on code from Shlomi Gridish.
  4543. + *
  4544. + * This program is free software; you can redistribute it and/or modify
  4545. + * it under the terms of the GNU General Public License as published by
  4546. + * the Free Software Foundation; either version 2 of the License, or
  4547. + * (at your option) any later version.
  4548. + *
  4549. + * This program is distributed in the hope that it will be useful, but
  4550. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  4551. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  4552. + * General Public License for more details.
  4553. + *
  4554. + * You should have received a copy of the GNU General Public License along
  4555. + * with this program; if not, write to the Free Software Foundation, Inc.,
  4556. + * 675 Mass Ave, Cambridge, MA 02139, USA.
  4557. + ***************************************************************************
  4558. + * Changes:
  4559. + * v0.3 08 August 2007 Duck
  4560. + * v0.2 20 October 2006 Andrey Butok
  4561. + * Issues fixing and some changes.
  4562. + * v0.1 September 2006 Yaroslav Vinogradov
  4563. + * Initial version.
  4564. + *
  4565. + */
  4566. +
  4567. +#include <linux/module.h>
  4568. +#include <linux/moduleparam.h>
  4569. +#include <linux/kernel.h>
  4570. +#include <linux/delay.h>
  4571. +#include <linux/ioport.h>
  4572. +#include <linux/sched.h>
  4573. +#include <linux/slab.h>
  4574. +#include <linux/smp_lock.h>
  4575. +#include <linux/proc_fs.h>
  4576. +#include <linux/errno.h>
  4577. +#include <linux/init.h>
  4578. +#include <linux/reboot.h>
  4579. +#include <linux/timer.h>
  4580. +#include <linux/list.h>
  4581. +#include <linux/interrupt.h>
  4582. +#include <linux/usb.h>
  4583. +#include <linux/device.h>
  4584. +#include <linux/platform_device.h>
  4585. +#include <linux/usb/ch9.h>
  4586. +#include <linux/usb_gadget.h>
  4587. +#include <linux/workqueue.h>
  4588. +#include <linux/time.h>
  4589. +#include <linux/fsl_devices.h>
  4590. +#include <linux/usb/fsl_usb2.h>
  4591. +
  4592. +#include <linux/io.h>
  4593. +
  4594. +#if defined CONFIG_M54455
  4595. +#include <asm/mcfsim.h>
  4596. +#endif
  4597. +
  4598. +#define USE_WORK_QUEUES
  4599. +#include "fsl_otg.h"
  4600. +
  4601. +#define CONFIG_USB_OTG_DEBUG_FILES
  4602. +#define DRIVER_VERSION "Revision: 1.56"
  4603. +#define DRIVER_AUTHOR "Freescale Semiconductor Inc."
  4604. +#define DRIVER_DESC "Freescale USB OTG ULPI Driver"
  4605. +#define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
  4606. +
  4607. +MODULE_DESCRIPTION("Freescale USB OTG Controller Driver");
  4608. +
  4609. +static const char driver_name[] = "fsl-usb2-otg";
  4610. +
  4611. +static spinlock_t usb_dr_regs_lock;
  4612. +
  4613. +/*#define HA_DATA_PULSE 1*/
  4614. +
  4615. +volatile static struct fsl_usb_device_regs *usb_dr_regs;
  4616. +static struct fsl_otg *fsl_otg_dev;
  4617. +static int srp_wait_done;
  4618. +
  4619. +/* Driver specific timers */
  4620. +struct fsl_otg_timer *b_data_pulse_tmr, *b_vbus_pulse_tmr, *b_srp_fail_tmr,
  4621. + *b_srp_wait_tmr, *a_wait_enum_tmr;
  4622. +
  4623. +static struct list_head active_timers;
  4624. +
  4625. +static struct fsl_otg_config fsl_otg_initdata = {
  4626. + .otg_port = 1,
  4627. +};
  4628. +
  4629. +static void dump_state(const char *string, struct otg_fsm *fsm)
  4630. +{
  4631. + printk(KERN_DEBUG "%s\n\tOTG state: %s\n", string,
  4632. + state_string(fsl_otg_dev->otg.state));
  4633. + printk(KERN_DEBUG "\tFSM protocol=%s\n", fsm->protocol ?
  4634. + (fsm->protocol == PROTO_HOST ? "Host" : "Gadget")
  4635. + : "None");
  4636. +
  4637. + /* regs */
  4638. + printk(KERN_DEBUG "\t OTGSC 0x%08x\n",
  4639. + fsl_readl(&usb_dr_regs->otgsc));
  4640. + printk(KERN_DEBUG "\tPORTSC1 0x%08x\n",
  4641. + fsl_readl(&usb_dr_regs->portsc1));
  4642. + printk(KERN_DEBUG "\tUSBMODE 0x%08x\n",
  4643. + fsl_readl(&usb_dr_regs->usbmode));
  4644. + printk(KERN_DEBUG "\t USBCMD 0x%08x\n",
  4645. + fsl_readl(&usb_dr_regs->usbcmd));
  4646. + printk(KERN_DEBUG "\t USBSTS 0x%08x\n",
  4647. + fsl_readl(&usb_dr_regs->usbsts));
  4648. +
  4649. + /* ------ State Machine Variables ----- */
  4650. + printk(KERN_DEBUG "\ta_bus_req: %d\n", fsm->a_bus_req);
  4651. + printk(KERN_DEBUG "\tb_bus_req: %d\n", fsm->b_bus_req);
  4652. + printk(KERN_DEBUG "\ta_bus_resume: %d\n", fsm->a_bus_resume);
  4653. + printk(KERN_DEBUG "\ta_bus_suspend: %d\n", fsm->a_bus_suspend);
  4654. + printk(KERN_DEBUG "\ta_conn: %d\n", fsm->a_conn);
  4655. + printk(KERN_DEBUG "\ta_sess_vld: %d\n", fsm->a_sess_vld);
  4656. + printk(KERN_DEBUG "\ta_srp_det: %d\n", fsm->a_srp_det);
  4657. + printk(KERN_DEBUG "\ta_vbus_vld: %d\n", fsm->a_vbus_vld);
  4658. + printk(KERN_DEBUG "\tb_bus_resume: %d\n", fsm->b_bus_resume);
  4659. + printk(KERN_DEBUG "\tb_bus_suspend: %d\n", fsm->b_bus_suspend);
  4660. + printk(KERN_DEBUG "\tb_conn: %d\n", fsm->b_conn);
  4661. + printk(KERN_DEBUG "\tb_se0_srp: %d\n", fsm->b_se0_srp);
  4662. + printk(KERN_DEBUG "\tb_sess_end: %d\n", fsm->b_sess_end);
  4663. + printk(KERN_DEBUG "\tb_sess_vld: %d\n", fsm->b_sess_vld);
  4664. + printk(KERN_DEBUG "\tid: %d\n", fsm->id);
  4665. +}
  4666. +
  4667. +
  4668. +/* Routines to access transceiver ULPI registers */
  4669. +u8 view_ulpi(u8 addr)
  4670. +{
  4671. + u32 temp;
  4672. +
  4673. + temp = 0x40000000 | (addr << 16);
  4674. + fsl_writel(temp, &usb_dr_regs->ulpiview);
  4675. +
  4676. + udelay(1000);
  4677. +
  4678. + /* DDD timeout this loop: */
  4679. + do {
  4680. + temp = fsl_readl(&usb_dr_regs->ulpiview);
  4681. + } while (temp & 0x40000000);
  4682. +
  4683. + return (temp & 0x0000ff00) >> 8;
  4684. +}
  4685. +
  4686. +int write_ulpi(u8 addr, u8 data)
  4687. +{
  4688. + u32 temp;
  4689. +
  4690. + temp = 0x60000000 | (addr << 16) | data;
  4691. + fsl_writel(temp, &usb_dr_regs->ulpiview);
  4692. + return 0;
  4693. +}
  4694. +
  4695. +/* prototype declaration */
  4696. +void fsl_otg_add_timer(void *timer);
  4697. +void fsl_otg_del_timer(void *timer);
  4698. +
  4699. +/* -------------------------------------------------------------*/
  4700. +/* Operations that will be called from OTG Finite State Machine */
  4701. +
  4702. +/* Charge vbus for vbus pulsing in SRP */
  4703. +void fsl_otg_chrg_vbus(int on)
  4704. +{
  4705. + u32 tmp;
  4706. +
  4707. + VDBG(" %d\n", on);
  4708. +
  4709. + tmp = fsl_readl(&usb_dr_regs->otgsc) & ~OTGSC_INTSTS_MASK;
  4710. +
  4711. + if (on) {
  4712. + tmp &= ~OTGSC_CTRL_VBUS_DISCHARGE;
  4713. + tmp |= OTGSC_CTRL_VBUS_CHARGE;
  4714. + } else {
  4715. + tmp &= ~OTGSC_CTRL_VBUS_CHARGE;
  4716. + }
  4717. + fsl_writel(tmp, &usb_dr_regs->otgsc);
  4718. +}
  4719. +
  4720. +/* Discharge vbus through a resistor to ground */
  4721. +void fsl_otg_dischrg_vbus(int on)
  4722. +{
  4723. + u32 tmp;
  4724. +
  4725. + VDBG(" %d\n", on);
  4726. +
  4727. + tmp = fsl_readl(&usb_dr_regs->otgsc) & ~OTGSC_INTSTS_MASK;
  4728. +
  4729. + if (on)
  4730. + tmp |= OTGSC_CTRL_VBUS_DISCHARGE;
  4731. + else
  4732. + tmp &= ~OTGSC_CTRL_VBUS_DISCHARGE;
  4733. +
  4734. + fsl_writel(tmp, &usb_dr_regs->otgsc);
  4735. +}
  4736. +
  4737. +/* A-device driver vbus, controlled through PP bit in PORTSC */
  4738. +void fsl_otg_drv_vbus(int on)
  4739. +{
  4740. + u32 tmp;
  4741. +
  4742. + VDBG(" %d\n", on);
  4743. +
  4744. + tmp = fsl_readl(&usb_dr_regs->portsc1) & ~PORTSCX_W1C_BITS;
  4745. +
  4746. + if (on)
  4747. + tmp |= PORTSCX_PORT_POWER;
  4748. + else
  4749. + tmp &= ~PORTSCX_PORT_POWER;
  4750. +
  4751. + fsl_writel(tmp, &usb_dr_regs->portsc1);
  4752. +}
  4753. +
  4754. +/* Pull-up D+, signalling connect by periperal. Also used in
  4755. + * data-line pulsing in SRP */
  4756. +void fsl_otg_loc_conn(int on)
  4757. +{
  4758. + u32 tmp;
  4759. +
  4760. + VDBG(" %d\n", on);
  4761. +
  4762. + tmp = fsl_readl(&usb_dr_regs->otgsc) & ~OTGSC_INTSTS_MASK;
  4763. +
  4764. + if (on)
  4765. + tmp |= OTGSC_CTRL_DATA_PULSING;
  4766. + else
  4767. + tmp &= ~OTGSC_CTRL_DATA_PULSING;
  4768. +
  4769. + fsl_writel(tmp, &usb_dr_regs->otgsc);
  4770. +}
  4771. +
  4772. +/* Generate SOF by host. This is controlled through suspend/resume the
  4773. + * port. In host mode, controller will automatically send SOF.
  4774. + * Suspend will block the data on the port.
  4775. + */
  4776. +void fsl_otg_loc_sof(int on)
  4777. +{
  4778. + u32 tmp;
  4779. +
  4780. + VDBG(" %d\n", on);
  4781. +
  4782. + tmp = fsl_readl(&usb_dr_regs->portsc1) & ~PORTSCX_W1C_BITS;
  4783. +
  4784. + if (on)
  4785. + tmp |= PORTSCX_PORT_FORCE_RESUME;
  4786. + else
  4787. + tmp |= PORTSCX_PORT_SUSPEND;
  4788. +
  4789. + fsl_writel(tmp, &usb_dr_regs->portsc1);
  4790. +}
  4791. +
  4792. +/* Start SRP pulsing by data-line pulsing, followed with v-bus pulsing. */
  4793. +void fsl_otg_start_pulse(void)
  4794. +{
  4795. + u32 __attribute__ ((unused)) tmp;
  4796. +
  4797. + VDBG("\n");
  4798. + srp_wait_done = 0;
  4799. +
  4800. +#ifdef HA_DATA_PULSE
  4801. + tmp = fsl_readl(&usb_dr_regs->otgsc) &= ~OTGSC_INTSTS_MASK;
  4802. + tmp |= OTGSC_HA_DATA_PULSE;
  4803. + fsl_writel(tmp, &usb_dr_regs->otgsc);
  4804. +#else
  4805. + fsl_otg_loc_conn(1);
  4806. +#endif
  4807. +
  4808. + fsl_otg_add_timer(b_data_pulse_tmr);
  4809. +}
  4810. +
  4811. +void fsl_otg_pulse_vbus(void);
  4812. +
  4813. +void b_data_pulse_end(unsigned long foo)
  4814. +{
  4815. +#ifdef HA_DATA_PULSE
  4816. +#else
  4817. + fsl_otg_loc_conn(0);
  4818. +#endif
  4819. +
  4820. + /* Do VBUS pulse after data pulse */
  4821. + fsl_otg_pulse_vbus();
  4822. +}
  4823. +
  4824. +void fsl_otg_pulse_vbus(void)
  4825. +{
  4826. + srp_wait_done = 0;
  4827. + fsl_otg_chrg_vbus(1);
  4828. + /* start the timer to end vbus charge */
  4829. + fsl_otg_add_timer(b_vbus_pulse_tmr);
  4830. +}
  4831. +
  4832. +void b_vbus_pulse_end(unsigned long foo)
  4833. +{
  4834. + fsl_otg_chrg_vbus(0);
  4835. +
  4836. + /* As USB3300 using the same a_sess_vld and b_sess_vld voltage
  4837. + * we need to discharge the bus for a while to distinguish
  4838. + * residual voltage of vbus pulsing and A device pull up */
  4839. + fsl_otg_dischrg_vbus(1);
  4840. + fsl_otg_add_timer(b_srp_wait_tmr);
  4841. +}
  4842. +
  4843. +void b_srp_end(unsigned long foo)
  4844. +{
  4845. + fsl_otg_dischrg_vbus(0);
  4846. + srp_wait_done = 1;
  4847. +
  4848. + if ((fsl_otg_dev->otg.state == OTG_STATE_B_SRP_INIT) &&
  4849. + fsl_otg_dev->fsm.b_sess_vld)
  4850. + fsl_otg_dev->fsm.b_srp_done = 1;
  4851. +}
  4852. +
  4853. +/* Workaround for a_host suspending too fast. When a_bus_req=0,
  4854. + * a_host will start by SRP. It needs to set b_hnp_enable before
  4855. + * actually suspending to start HNP
  4856. + */
  4857. +void a_wait_enum(unsigned long foo)
  4858. +{
  4859. + VDBG("a_wait_enum timeout\n");
  4860. + if (!fsl_otg_dev->otg.host->b_hnp_enable)
  4861. + fsl_otg_add_timer(a_wait_enum_tmr);
  4862. + else
  4863. + otg_statemachine(&fsl_otg_dev->fsm);
  4864. +}
  4865. +
  4866. +/* ------------------------------------------------------*/
  4867. +
  4868. +/* The timeout callback function to set time out bit */
  4869. +void set_tmout(unsigned long indicator)
  4870. +{
  4871. + *(int *)indicator = 1;
  4872. +}
  4873. +
  4874. +/* Initialize timers */
  4875. +void fsl_otg_init_timers(struct otg_fsm *fsm)
  4876. +{
  4877. + /* FSM used timers */
  4878. + fsm->a_wait_vrise_tmr = otg_timer_initializer(&set_tmout, TA_WAIT_VRISE,
  4879. + (unsigned long)&fsm->a_wait_vrise_tmout);
  4880. + fsm->a_wait_bcon_tmr = otg_timer_initializer(&set_tmout, TA_WAIT_BCON,
  4881. + (unsigned long)&fsm->a_wait_bcon_tmout);
  4882. + fsm->a_aidl_bdis_tmr = otg_timer_initializer(&set_tmout, TA_AIDL_BDIS,
  4883. + (unsigned long)&fsm->a_aidl_bdis_tmout);
  4884. + fsm->b_ase0_brst_tmr = otg_timer_initializer(&set_tmout, TB_ASE0_BRST,
  4885. + (unsigned long)&fsm->b_ase0_brst_tmout);
  4886. + fsm->b_se0_srp_tmr = otg_timer_initializer(&set_tmout, TB_SE0_SRP,
  4887. + (unsigned long)&fsm->b_se0_srp);
  4888. + fsm->b_srp_fail_tmr = otg_timer_initializer(&set_tmout, TB_SRP_FAIL,
  4889. + (unsigned long)&fsm->b_srp_done);
  4890. + fsm->a_wait_enum_tmr = otg_timer_initializer(&a_wait_enum, 10,
  4891. + (unsigned long)&fsm);
  4892. +
  4893. + /* device driver used timers */
  4894. + b_srp_wait_tmr = otg_timer_initializer(&b_srp_end, TB_SRP_WAIT, 0);
  4895. + b_data_pulse_tmr = otg_timer_initializer(&b_data_pulse_end,
  4896. + TB_DATA_PLS, 0);
  4897. + b_vbus_pulse_tmr = otg_timer_initializer(&b_vbus_pulse_end,
  4898. + TB_VBUS_PLS, 0);
  4899. +
  4900. +}
  4901. +
  4902. +/* Add timer to timer list */
  4903. +void fsl_otg_add_timer(void *gtimer)
  4904. +{
  4905. + struct fsl_otg_timer *timer = (struct fsl_otg_timer *)gtimer;
  4906. + struct fsl_otg_timer *tmp_timer;
  4907. +
  4908. + /* Check if the timer is already in the active list,
  4909. + * if so update timer count
  4910. + */
  4911. + list_for_each_entry(tmp_timer, &active_timers, list)
  4912. + if (tmp_timer == timer) {
  4913. + timer->count = timer->expires;
  4914. + return;
  4915. + }
  4916. + timer->count = timer->expires;
  4917. + list_add_tail(&timer->list, &active_timers);
  4918. +}
  4919. +
  4920. +/* Remove timer from the timer list; clear timeout status */
  4921. +void fsl_otg_del_timer(void *gtimer)
  4922. +{
  4923. + struct fsl_otg_timer *timer = (struct fsl_otg_timer *)gtimer;
  4924. + struct fsl_otg_timer *tmp_timer, *del_tmp;
  4925. +
  4926. + list_for_each_entry_safe(tmp_timer, del_tmp, &active_timers, list)
  4927. + if (tmp_timer == timer)
  4928. + list_del(&timer->list);
  4929. +}
  4930. +
  4931. +/*
  4932. + * Reduce timer count by 1, and find timeout conditions.
  4933. + * Called by fsl_otg 1ms timer interrupt
  4934. + */
  4935. +int fsl_otg_tick_timer(void)
  4936. +{
  4937. + struct fsl_otg_timer *tmp_timer, *del_tmp;
  4938. + int expired = 0;
  4939. +
  4940. + list_for_each_entry_safe(tmp_timer, del_tmp, &active_timers, list) {
  4941. + tmp_timer->count--;
  4942. + /* check if timer expires */
  4943. + if (!tmp_timer->count) {
  4944. + list_del(&tmp_timer->list);
  4945. + tmp_timer->function(tmp_timer->data);
  4946. + expired = 1;
  4947. + }
  4948. + }
  4949. +
  4950. + return expired;
  4951. +}
  4952. +
  4953. +/* Reset controller, not reset the bus */
  4954. +void otg_reset_controller(void)
  4955. +{
  4956. + u32 command;
  4957. + unsigned long flags;
  4958. + int timeout;
  4959. +
  4960. + VDBG("\n");
  4961. +
  4962. + spin_lock_irqsave(&usb_dr_regs_lock, flags);
  4963. +
  4964. + command = fsl_readl(&usb_dr_regs->usbcmd);
  4965. + command |= USB_CMD_CTRL_RESET;
  4966. + fsl_writel(command, &usb_dr_regs->usbcmd);
  4967. + spin_unlock_irqrestore(&usb_dr_regs_lock, flags);
  4968. +
  4969. + /* Wait reset completed */
  4970. + timeout = 500;
  4971. + while (fsl_readl(&usb_dr_regs->usbcmd) & USB_CMD_CTRL_RESET)
  4972. + udelay(1);
  4973. + if (timeout <= 0)
  4974. + ERR("%s - USBCMD_RST never clear. Timeout is %d \n",
  4975. + __FUNCTION__, timeout);
  4976. +}
  4977. +
  4978. +/* Call suspend/resume routines in host driver */
  4979. +int fsl_otg_start_host(struct otg_fsm *fsm, int on)
  4980. +{
  4981. + struct otg_transceiver *xceiv = fsm->transceiver;
  4982. + struct device *dev;
  4983. + struct fsl_otg *otg_dev = container_of(xceiv, struct fsl_otg, otg);
  4984. + u32 retval = 0;
  4985. +
  4986. + if (!xceiv->host)
  4987. + return -ENODEV;
  4988. +
  4989. + dev = xceiv->host->controller;
  4990. +
  4991. + /*
  4992. + * Update a_vbus_vld state as a_vbus_vld int is disabled
  4993. + * in device mode
  4994. + */
  4995. + fsm->a_vbus_vld =
  4996. + !!(fsl_readl(&usb_dr_regs->otgsc) & OTGSC_STS_A_VBUS_VALID);
  4997. + if (on) {
  4998. + /* start fsl usb host controller */
  4999. + if (otg_dev->host_working)
  5000. + goto end;
  5001. + else {
  5002. + otg_reset_controller();
  5003. + VDBG("host on......\n");
  5004. + if (dev->driver->resume) {
  5005. + retval = dev->driver->resume(dev);
  5006. + if (fsm->id) {
  5007. + /* default-b */
  5008. + fsl_otg_drv_vbus(1);
  5009. + /* Workaround: b_host can't driver
  5010. + * vbus, but PP in PORTSC needs to
  5011. + * be 1 for host to work.
  5012. + * So we set drv_vbus bit in
  5013. + * transceiver to 0 thru ULPI. */
  5014. + write_ulpi(0x0c, 0x20);
  5015. + }
  5016. + }
  5017. +
  5018. + otg_dev->host_working = 1;
  5019. + }
  5020. + } else {
  5021. + /* stop fsl usb host controller */
  5022. + if (!otg_dev->host_working)
  5023. + goto end;
  5024. + else {
  5025. + VDBG("host off......\n");
  5026. + if (dev && dev->driver) {
  5027. + retval = dev->driver->suspend(dev, PMSG_SUSPEND);
  5028. + if (fsm->id)
  5029. + /* default-b */
  5030. + fsl_otg_drv_vbus(0);
  5031. + }
  5032. + otg_dev->host_working = 0;
  5033. + }
  5034. + }
  5035. +end:
  5036. + return retval;
  5037. +}
  5038. +
  5039. +/*
  5040. + * Call suspend and resume function in udc driver
  5041. + * to stop and start udc driver.
  5042. + */
  5043. +int fsl_otg_start_gadget(struct otg_fsm *fsm, int on)
  5044. +{
  5045. + struct otg_transceiver *xceiv = fsm->transceiver;
  5046. + struct device *dev;
  5047. +
  5048. + VDBG("DDD fsm=%p xceiv=%p\n", fsm, xceiv);
  5049. + if (!xceiv->gadget || !xceiv->gadget->dev.parent)
  5050. + return -ENODEV;
  5051. +
  5052. + VDBG("DDD xceiv=%p xceiv->gadget=%p parent=%p\n", xceiv, xceiv->gadget,
  5053. + xceiv->gadget->dev.parent);
  5054. +
  5055. + VDBG("gadget %s\n", on ? "on" : "off");
  5056. + /* DDD dump_state("starting gadget", fsm); */
  5057. +
  5058. + dev = xceiv->gadget->dev.parent;
  5059. +
  5060. + if (on)
  5061. + dev->driver->resume(dev);
  5062. + else
  5063. + dev->driver->suspend(dev, PMSG_SUSPEND);
  5064. +
  5065. + return 0;
  5066. +}
  5067. +
  5068. +static void fsl_otg_enable(struct otg_transceiver *otg_p)
  5069. +{
  5070. + struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg);
  5071. + struct otg_fsm *fsm = &(otg_dev)->fsm;
  5072. + u32 otg_sc;
  5073. +
  5074. + /* DDD VDBG(""); */
  5075. + /* enable OTG interrupt */
  5076. + otg_sc = fsl_readl(&usb_dr_regs->otgsc);
  5077. + otg_sc |= OTGSC_INTERRUPT_ENABLE_BITS_MASK;
  5078. + otg_sc &= ~OTGSC_IE_1ms_TIMER;
  5079. + otg_sc &= ~OTGSC_CTRL_VBUS_DISCHARGE;
  5080. + otg_sc |= OTGSC_IE_USB_ID; /* DDD added this */
  5081. + fsl_writel(otg_sc, &usb_dr_regs->otgsc);
  5082. +
  5083. + fsm->id = (otg_sc & OTGSC_STS_USB_ID) ? 1 : 0;
  5084. +
  5085. + if (fsm->id) {
  5086. + otg_p->state = OTG_STATE_UNDEFINED;
  5087. + } else {
  5088. + otg_p->state = OTG_STATE_A_IDLE;
  5089. + }
  5090. +
  5091. + otg_p->default_a = (fsm->id == 0);
  5092. + otg_p->host->is_b_host = fsm->id;
  5093. + otg_p->gadget->is_a_peripheral = !fsm->id;
  5094. +
  5095. + fsm->a_vbus_vld = 1;
  5096. +
  5097. + fsm->b_sess_vld = (otg_sc & OTGSC_STS_B_SESSION_VALID) ? 1 : 0;
  5098. + fsm->a_sess_vld = (otg_sc & OTGSC_STS_A_SESSION_VALID) ? 1 : 0;
  5099. + fsm->b_sess_end = (otg_sc & OTGSC_STS_B_SESSION_END) ? 1 : 0;
  5100. +}
  5101. +
  5102. +/*
  5103. + * Called by initialization code of host driver. Register host controller
  5104. + * to the OTG. Suspend host for OTG role detection.
  5105. + */
  5106. +static int fsl_otg_set_host(struct otg_transceiver *otg_p, struct usb_bus *host)
  5107. +{
  5108. +#if 0 // DDD beta-final
  5109. + struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg);
  5110. + struct device *dev = host->controller;
  5111. +
  5112. + if (!otg_p || otg_dev != fsl_otg_dev)
  5113. + return -ENODEV;
  5114. +
  5115. + otg_p->host = host;
  5116. + otg_p->host->is_b_host = otg_dev->fsm.id;
  5117. +
  5118. + otg_dev->fsm.a_bus_drop = 0;
  5119. + otg_dev->fsm.a_bus_req = 1;
  5120. +
  5121. + otg_p->host->otg_port = fsl_otg_initdata.otg_port;
  5122. +
  5123. + if (dev && dev->driver) {
  5124. + VDBG("suspending host\n");
  5125. + dev->driver->suspend(dev, PMSG_SUSPEND);
  5126. + otg_dev->host_working = 0;
  5127. + VDBG("back\n");
  5128. + }
  5129. +
  5130. +
  5131. + /* dump_state("set_host running statemachine", &otg_dev->fsm); DDD */
  5132. + otg_statemachine(&otg_dev->fsm);
  5133. +
  5134. + return 0;
  5135. +#else
  5136. + struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg);
  5137. +
  5138. + if (!otg_p || otg_dev != fsl_otg_dev)
  5139. + return -ENODEV;
  5140. +
  5141. + otg_p->host = host;
  5142. +
  5143. + otg_dev->fsm.a_bus_drop = 0;
  5144. + otg_dev->fsm.a_bus_req = 1;
  5145. +
  5146. + if (host) {
  5147. + VDBG("host off......\n");
  5148. +
  5149. + otg_p->host->otg_port = fsl_otg_initdata.otg_port;
  5150. + otg_p->host->is_b_host = otg_dev->fsm.id;
  5151. + /* must leave time for khubd to finish its thing
  5152. + * before yanking the host driver out from under it,
  5153. + * so suspend the host after a short delay.
  5154. + */
  5155. + otg_dev->host_working = 1;
  5156. + schedule_delayed_work(&otg_dev->otg_event, 100);
  5157. + return 0;
  5158. + } else { /* host driver going away */
  5159. +
  5160. + if (!(le32_to_cpu(otg_dev->dr_mem_map->otgsc) &
  5161. + OTGSC_STS_USB_ID)) {
  5162. + /* Mini-A cable connected */
  5163. + struct otg_fsm *fsm = &otg_dev->fsm;
  5164. +
  5165. + otg_p->state = OTG_STATE_UNDEFINED;
  5166. + fsm->protocol = PROTO_UNDEF;
  5167. + }
  5168. + }
  5169. +
  5170. + otg_dev->host_working = 0;
  5171. +
  5172. + otg_statemachine(&otg_dev->fsm);
  5173. +
  5174. + return 0;
  5175. +#endif
  5176. +}
  5177. +
  5178. +/* Called by initialization code of udc. Register udc to OTG.*/
  5179. +static int fsl_otg_set_peripheral(struct otg_transceiver *otg_p,
  5180. + struct usb_gadget *gadget)
  5181. +{
  5182. + struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg);
  5183. +
  5184. + VDBG("\n");
  5185. +
  5186. + if (!otg_p || otg_dev != fsl_otg_dev)
  5187. + return -ENODEV;
  5188. +
  5189. + if (!gadget) {
  5190. + if (!otg_dev->otg.default_a)
  5191. + otg_p->gadget->ops->vbus_draw(otg_p->gadget, 0);
  5192. + usb_gadget_vbus_disconnect(otg_dev->otg.gadget);
  5193. + otg_dev->otg.gadget = 0;
  5194. + otg_dev->fsm.b_bus_req = 0;
  5195. + otg_statemachine(&otg_dev->fsm);
  5196. + return 0;
  5197. + }
  5198. +
  5199. + otg_p->gadget = gadget;
  5200. + otg_p->gadget->is_a_peripheral = !otg_dev->fsm.id;
  5201. +
  5202. + otg_dev->fsm.b_bus_req = 1;
  5203. +
  5204. +#if 0 /* DDD uClinux */
  5205. + if (otg_p->host) {
  5206. + fsl_otg_enable(otg_p);
  5207. + otg_statemachine(&otg_dev->fsm);
  5208. + }
  5209. +#endif
  5210. + /* start the gadget right away if the ID pin says Mini-B */
  5211. + DBG("ID pin=%d\n", otg_dev->fsm.id);
  5212. + if (otg_dev->fsm.id == 1) {
  5213. + fsl_otg_start_host(&otg_dev->fsm, 0);
  5214. + fsl_otg_drv_vbus(0);
  5215. + fsl_otg_start_gadget(&otg_dev->fsm, 1);
  5216. + }
  5217. +
  5218. + return 0;
  5219. +}
  5220. +
  5221. +/* Set OTG port power, only for B-device */
  5222. +static int fsl_otg_set_power(struct otg_transceiver *otg_p, unsigned mA)
  5223. +{
  5224. + if (!fsl_otg_dev)
  5225. + return -ENODEV;
  5226. + if (otg_p->state == OTG_STATE_B_PERIPHERAL)
  5227. + printk(KERN_DEBUG "FSL OTG:Draw %d mA\n", mA);
  5228. +
  5229. + return 0;
  5230. +}
  5231. +
  5232. +/* Delayed pin detect interrupt processing.
  5233. + *
  5234. + * When the Mini-A cable is disconnected from the board,
  5235. + * the pin-detect interrupt happens before the disconnnect
  5236. + * interrupts for the connected device(s). In order to
  5237. + * process the disconnect interrupt(s) prior to switching
  5238. + * roles, the pin-detect interrupts are delayed, and handled
  5239. + * by this routine.
  5240. + */
  5241. +static void fsl_otg_event(struct work_struct *work)
  5242. +{
  5243. + struct fsl_otg *og = container_of(work, struct fsl_otg, otg_event.work);
  5244. + struct otg_fsm *fsm = &og->fsm;
  5245. +
  5246. + VDBG("DDD fsm->id=%d\n", fsm->id);
  5247. + if (fsm->id) { /* switch to gadget */
  5248. + fsl_otg_start_host(fsm, 0);
  5249. + fsl_otg_drv_vbus(0);
  5250. + fsl_otg_start_gadget(fsm, 1);
  5251. + }
  5252. +}
  5253. +
  5254. +/* B-device start SRP */
  5255. +static int fsl_otg_start_srp(struct otg_transceiver *otg_p)
  5256. +{
  5257. + struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg);
  5258. +
  5259. + if (!otg_p || otg_dev != fsl_otg_dev
  5260. + || otg_p->state != OTG_STATE_B_IDLE)
  5261. + return -ENODEV;
  5262. +
  5263. + otg_dev->fsm.b_bus_req = 1;
  5264. + otg_statemachine(&otg_dev->fsm);
  5265. +
  5266. + return 0;
  5267. +}
  5268. +
  5269. +/* A_host suspend will call this function to start hnp */
  5270. +static int fsl_otg_start_hnp(struct otg_transceiver *otg_p)
  5271. +{
  5272. + struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg);
  5273. +
  5274. + if (!otg_p || otg_dev != fsl_otg_dev)
  5275. + return -ENODEV;
  5276. +
  5277. + VDBG("start_hnp.............\n");
  5278. + /* clear a_bus_req to enter a_suspend state */
  5279. + otg_dev->fsm.a_bus_req = 0;
  5280. + otg_statemachine(&otg_dev->fsm);
  5281. +
  5282. + return 0;
  5283. +}
  5284. +
  5285. +/*
  5286. + * Interrupt handler. OTG/host/peripheral share the same int line.
  5287. + * OTG driver clears OTGSC interrupts and leaves USB interrupts
  5288. + * intact. It needs to have knowledge of some USB interrupts
  5289. + * such as port change.
  5290. + */
  5291. +irqreturn_t fsl_otg_isr(int irq, void *dev_id)
  5292. +{
  5293. + struct otg_fsm *fsm = &((struct fsl_otg *)dev_id)->fsm;
  5294. + struct otg_transceiver *otg = &((struct fsl_otg *)dev_id)->otg;
  5295. + u32 otg_int_src, otg_sc;
  5296. +
  5297. + otg_sc = fsl_readl(&usb_dr_regs->otgsc);
  5298. + otg_int_src = otg_sc & OTGSC_INTSTS_MASK & (otg_sc >> 8);
  5299. +
  5300. + /* Only clear otg interrupts */
  5301. + fsl_writel(otg_sc, &usb_dr_regs->otgsc);
  5302. +
  5303. + /*FIXME: ID change not generate when init to 0 */
  5304. + fsm->id = (otg_sc & OTGSC_STS_USB_ID) ? 1 : 0;
  5305. + otg->default_a = (fsm->id == 0);
  5306. +
  5307. + /* process OTG interrupts */
  5308. + if (otg_int_src) {
  5309. + VDBG("\nOTG irq 0x%08x\n", otg_int_src);
  5310. +
  5311. + if (otg_int_src & OTGSC_INTSTS_USB_ID) {
  5312. + fsm->id = (otg_sc & OTGSC_STS_USB_ID) ? 1 : 0;
  5313. + otg->default_a = (fsm->id == 0);
  5314. + /* clear conn information */
  5315. + if (fsm->id)
  5316. + fsm->b_conn = 0;
  5317. + else
  5318. + fsm->a_conn = 0;
  5319. +
  5320. + if (otg->host)
  5321. + otg->host->is_b_host = fsm->id;
  5322. + if (otg->gadget)
  5323. + otg->gadget->is_a_peripheral = !fsm->id;
  5324. + VDBG("ID int (ID is %d)\n", fsm->id);
  5325. +
  5326. + if (fsm->id) { /* switch to gadget */
  5327. + schedule_delayed_work(&((struct fsl_otg *)
  5328. + dev_id)->otg_event, 25);
  5329. + } else { /* switch to host */
  5330. + cancel_delayed_work(&
  5331. + ((struct fsl_otg *)dev_id)->
  5332. + otg_event);
  5333. + fsl_otg_start_gadget(fsm, 0);
  5334. + fsl_otg_drv_vbus(1);
  5335. + fsl_otg_start_host(fsm, 1);
  5336. + }
  5337. +
  5338. + return IRQ_HANDLED;
  5339. + }
  5340. + }
  5341. +
  5342. + return IRQ_NONE;
  5343. +}
  5344. +
  5345. +
  5346. +#if 0 // DDD feta-final
  5347. +irqreturn_t foo_fsl_otg_isr(int irq, void *dev_id)
  5348. +{
  5349. + struct otg_fsm *fsm = &((struct fsl_otg *)dev_id)->fsm;
  5350. + struct otg_transceiver *otg = &((struct fsl_otg *)dev_id)->otg;
  5351. + u32 otg_int_src, usb_int_src, otg_sc;
  5352. + int trigger = 0;
  5353. + int tmp;
  5354. +
  5355. + usb_int_src = fsl_readl(&usb_dr_regs->usbsts);
  5356. + otg_sc = fsl_readl(&usb_dr_regs->otgsc);
  5357. + otg_int_src = otg_sc & OTGSC_INTSTS_MASK & (otg_sc >> 8);
  5358. +
  5359. + /* Only clear otg interrupts */
  5360. + fsl_writel(otg_sc, &usb_dr_regs->otgsc);
  5361. +
  5362. + /*FIXME: ID change not generate when init to 0 */
  5363. + /* process OTG interrupts */
  5364. + if (otg_int_src) {
  5365. + VDBG("\nOTG irq 0x%08x\n", otg_int_src);
  5366. + if (otg_int_src & OTGSC_INTSTS_1MS_TIMER)
  5367. + trigger = fsl_otg_tick_timer();
  5368. +
  5369. + if (otg_int_src & OTGSC_INTSTS_USB_ID) {
  5370. + fsm->id = (otg_sc & OTGSC_STS_USB_ID) ? 1 : 0;
  5371. + otg->default_a = (fsm->id == 0);
  5372. + if (otg->host)
  5373. + otg->host->is_b_host = fsm->id;
  5374. + if (otg->gadget)
  5375. + otg->gadget->is_a_peripheral = !fsm->id;
  5376. + VDBG("IRQ=ID now=%d\n", fsm->id);
  5377. +
  5378. + if (fsm->id) { /* switch to gadget */
  5379. + schedule_delayed_work(&((struct fsl_otg *)
  5380. + dev_id)->otg_event, 25);
  5381. + } else { /* switch to host */
  5382. + cancel_delayed_work(&
  5383. + ((struct fsl_otg *)dev_id)->
  5384. + otg_event);
  5385. + fsl_otg_start_gadget(fsm, 0);
  5386. + fsl_otg_drv_vbus(1);
  5387. + fsl_otg_start_host(fsm, 1);
  5388. + }
  5389. +
  5390. + return IRQ_HANDLED;
  5391. + }
  5392. + if (otg_int_src & OTGSC_INTSTS_DATA_PULSE) {
  5393. + fsm->a_srp_det = 1;
  5394. + trigger = 1;
  5395. + VDBG("!!!!Data pulse int\n");
  5396. + }
  5397. + if (otg_int_src & OTGSC_INTSTS_A_SESSION_VALID) {
  5398. + fsm->a_sess_vld =
  5399. + (otg_sc & OTGSC_STS_A_SESSION_VALID) ? 1 : 0;
  5400. + /* detect VBUS pulsing */
  5401. + if ((fsm->transceiver->state == OTG_STATE_A_IDLE)
  5402. + && fsm->a_sess_vld)
  5403. + fsm->a_srp_det = 1;
  5404. + trigger = 1;
  5405. + VDBG("!!!a_sess_vld int state=%d\n", fsm->a_sess_vld);
  5406. + }
  5407. + if (otg_int_src & OTGSC_INTSTS_A_VBUS_VALID) {
  5408. + fsm->a_vbus_vld = !!(otg_sc & OTGSC_STS_A_VBUS_VALID);
  5409. + trigger = 1;
  5410. + VDBG("!!!a_vbus_vld int state=%d\n", fsm->a_vbus_vld);
  5411. +
  5412. +#if 1
  5413. + if ((fsm->a_vbus_vld == 0) && (fsm->id == 0)) {
  5414. + if (fsm->transceiver->state != OTG_STATE_A_WAIT_VFALL)
  5415. + /* Warning insted of transfer to Error state. */
  5416. + printk(KERN_WARNING "ulpi: The USB Device is "
  5417. + "sinking too much current!!\n");
  5418. + fsm->a_vbus_vld = 1;
  5419. + }
  5420. +#endif
  5421. +
  5422. +
  5423. + }
  5424. + if (otg_int_src & OTGSC_INTSTS_B_SESSION_VALID) {
  5425. + fsm->b_sess_vld =
  5426. + (otg_sc & OTGSC_STS_B_SESSION_VALID) ? 1 : 0;
  5427. + trigger = 1;
  5428. + /* SRP done */
  5429. + if ((fsl_otg_dev->otg.state == OTG_STATE_B_SRP_INIT) &&
  5430. + fsm->b_sess_vld && srp_wait_done)
  5431. + fsm->b_srp_done = 1;
  5432. + VDBG("!!!!b_sess_vld int state=%d\n", fsm->b_sess_vld);
  5433. + }
  5434. + if (otg_int_src & OTGSC_INTSTS_B_SESSION_END) {
  5435. + fsm->b_sess_end =
  5436. + (otg_sc & OTGSC_STS_B_SESSION_END) ? 1 : 0;
  5437. + trigger = 1;
  5438. + VDBG("!!!!b_sess_end int state=%d\n", fsm->b_sess_end);
  5439. + }
  5440. + }
  5441. +
  5442. + /* process USB interrupts */
  5443. + if ((usb_int_src & USB_STS_PORT_CHANGE)
  5444. + && (fsm->protocol == PROTO_HOST)) {
  5445. + VDBG("\nUSB irq A 0x%08x\n", usb_int_src);
  5446. + /* Device resume do not generate statemachine change */
  5447. + if (fsl_readl(&usb_dr_regs->portsc1) &
  5448. + PORTSCX_PORT_FORCE_RESUME) {
  5449. + if (otg->default_a) {
  5450. + fsm->b_bus_resume = 1;
  5451. + trigger = 1;
  5452. + } else {
  5453. + fsm->a_bus_resume = 1;
  5454. + trigger = 1;
  5455. + }
  5456. + }
  5457. +
  5458. + tmp = (fsl_readl(&usb_dr_regs->portsc1) &
  5459. + PORTSCX_CURRENT_CONNECT_STATUS) ? 1 : 0;
  5460. + if (otg->default_a && (fsm->b_conn != tmp)) {
  5461. + fsm->b_conn = tmp;
  5462. + trigger = 1;
  5463. + } else if (!otg->default_a && (fsm->a_conn != tmp)) {
  5464. + fsm->a_conn = tmp;
  5465. + trigger = 1;
  5466. + }
  5467. + }
  5468. + /* Workaround: sometimes CSC bit will lost. We change to
  5469. + * polling CCS bit for connect change */
  5470. + if (fsm->protocol == PROTO_GADGET) {
  5471. + if (usb_int_src & USB_STS_SUSPEND) {
  5472. + VDBG("\nUSB irq B 0x%08x\n", usb_int_src);
  5473. + VDBG("peripheral detected suspend\n");
  5474. + if (otg->default_a)
  5475. + /* A-device detects B suspend */
  5476. + fsm->b_bus_suspend = 1;
  5477. + else
  5478. + /* B-device detects A suspend */
  5479. + fsm->a_bus_suspend = 1;
  5480. + trigger = 1;
  5481. + } else if (usb_int_src & USB_STS_PORT_CHANGE) {
  5482. + VDBG("\nUSB irq C 0x%08x\n", usb_int_src);
  5483. + VDBG("peripheral resumed\n");
  5484. + if (otg->default_a)
  5485. + fsm->b_bus_suspend = 0;
  5486. + else
  5487. + fsm->a_bus_suspend = 0;
  5488. + trigger = 1;
  5489. + }
  5490. + }
  5491. +
  5492. + /* Invoke statemachine until state is stable */
  5493. + while (trigger) {
  5494. + trigger = otg_statemachine(fsm);
  5495. + }
  5496. +
  5497. + return IRQ_HANDLED;
  5498. +}
  5499. +#endif
  5500. +
  5501. +
  5502. +static struct otg_fsm_ops fsl_otg_ops = {
  5503. + .chrg_vbus = fsl_otg_chrg_vbus,
  5504. + .drv_vbus = fsl_otg_drv_vbus,
  5505. + .loc_conn = fsl_otg_loc_conn,
  5506. + .loc_sof = fsl_otg_loc_sof,
  5507. + .start_pulse = fsl_otg_start_pulse,
  5508. +
  5509. + .add_timer = fsl_otg_add_timer,
  5510. + .del_timer = fsl_otg_del_timer,
  5511. +
  5512. + .start_host = fsl_otg_start_host,
  5513. + .start_gadget = fsl_otg_start_gadget,
  5514. +};
  5515. +
  5516. +/* Initialize the global variable fsl_otg_dev and request IRQ for OTG */
  5517. +int fsl_otg_cfg(struct platform_device *pdev)
  5518. +{
  5519. + int status;
  5520. + struct fsl_otg *fsl_otg_tc;
  5521. + struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
  5522. + struct resource *res;
  5523. +
  5524. + DBG("\n");
  5525. +
  5526. + if (fsl_otg_dev)
  5527. + return 0;
  5528. +
  5529. + /* allocate space to fsl otg device */
  5530. + fsl_otg_tc = kzalloc(sizeof(struct fsl_otg), GFP_KERNEL);
  5531. + if (!fsl_otg_tc)
  5532. + return -ENODEV;
  5533. +
  5534. +#if 1 // DDD
  5535. + if (pdata->regs) {
  5536. + fsl_otg_tc->dr_mem_map = pdata->regs;
  5537. + } else {
  5538. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  5539. + if (!res) {
  5540. + dev_err(&pdev->dev, "no register addr.\n");
  5541. + return -ENODEV;
  5542. + }
  5543. +
  5544. + printk("DDD %s(): rsrc_start=0x%x rsrc_len=0x%x\n",
  5545. + __FUNCTION__, res->start, res->end - res->start + 1);
  5546. +
  5547. + if (!request_mem_region(res->start, res->end - res->start + 1,
  5548. + "OTG")) {
  5549. + dev_dbg(&pdev->dev, "request_mem_region failed\n");
  5550. + return -EBUSY;
  5551. + }
  5552. + fsl_otg_tc->dr_mem_map = ioremap(res->start,
  5553. + res->end - res->start + 1);
  5554. + }
  5555. + DBG("set dr_mem_map to 0x%p\n", fsl_otg_tc->dr_mem_map);
  5556. +
  5557. +#endif
  5558. + INIT_DELAYED_WORK(&fsl_otg_tc->otg_event, fsl_otg_event);
  5559. +
  5560. + INIT_LIST_HEAD(&active_timers);
  5561. + fsl_otg_init_timers(&fsl_otg_tc->fsm);
  5562. +
  5563. + /* Set OTG state machine operations */
  5564. + fsl_otg_tc->fsm.ops = &fsl_otg_ops;
  5565. +
  5566. +#if 1 /* DDD */
  5567. + /* record initial state of ID pin */
  5568. + fsl_otg_tc->fsm.id = (fsl_otg_tc->dr_mem_map->otgsc & OTGSC_STS_USB_ID)
  5569. + ? 1 : 0;
  5570. + DBG("initial ID pin=%d\n", fsl_otg_tc->fsm.id);
  5571. +#endif
  5572. + /* initialize the otg structure */
  5573. + fsl_otg_tc->otg.label = DRIVER_DESC;
  5574. + fsl_otg_tc->otg.set_host = fsl_otg_set_host;
  5575. + fsl_otg_tc->otg.set_peripheral = fsl_otg_set_peripheral;
  5576. + fsl_otg_tc->otg.set_power = fsl_otg_set_power;
  5577. + fsl_otg_tc->otg.start_hnp = fsl_otg_start_hnp;
  5578. + fsl_otg_tc->otg.start_srp = fsl_otg_start_srp;
  5579. +
  5580. + fsl_otg_dev = fsl_otg_tc;
  5581. +
  5582. + /* Store the otg transceiver */
  5583. + status = otg_set_transceiver(&fsl_otg_tc->otg);
  5584. + if (status) {
  5585. + printk(KERN_WARNING ": unable to register OTG transceiver.\n");
  5586. + return status;
  5587. + }
  5588. +
  5589. + return 0;
  5590. +}
  5591. +
  5592. +/* OTG Initialization*/
  5593. +int usb_otg_start(struct platform_device *pdev)
  5594. +{
  5595. + struct fsl_otg *p_otg;
  5596. + struct otg_transceiver *otg_trans = otg_get_transceiver();
  5597. + struct otg_fsm *fsm;
  5598. + int status;
  5599. + u32 temp;
  5600. + struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
  5601. + int timeout;
  5602. +
  5603. + DBG("\n");
  5604. +
  5605. + p_otg = container_of(otg_trans, struct fsl_otg, otg);
  5606. + fsm = &p_otg->fsm;
  5607. +
  5608. + /* Initialize the state machine structure with default values */
  5609. + SET_OTG_STATE(otg_trans, OTG_STATE_UNDEFINED);
  5610. + fsm->transceiver = &p_otg->otg;
  5611. +
  5612. + usb_dr_regs = p_otg->dr_mem_map;
  5613. + DBG("set usb_dr_regs to 0x%p\n", usb_dr_regs);
  5614. +
  5615. + /* request irq */
  5616. + p_otg->irq = platform_get_irq(pdev, 0);
  5617. + status = request_irq(p_otg->irq, fsl_otg_isr,
  5618. + IRQF_SHARED, driver_name, p_otg);
  5619. + if (status) {
  5620. + dev_dbg(p_otg->otg.dev, "can't get IRQ %d, error %d\n",
  5621. + p_otg->irq, status);
  5622. + kfree(p_otg);
  5623. + return status;
  5624. + }
  5625. +
  5626. +
  5627. + /* stop the controller */
  5628. + temp = fsl_readl(&usb_dr_regs->usbcmd) & ~USB_CMD_RUN_STOP;
  5629. + fsl_writel(temp, &usb_dr_regs->usbcmd);
  5630. +
  5631. + /* reset the controller */
  5632. + temp = fsl_readl(&usb_dr_regs->usbcmd);
  5633. + temp |= USB_CMD_CTRL_RESET;
  5634. + fsl_writel(temp, &usb_dr_regs->usbcmd);
  5635. +
  5636. + /* wait reset completed */
  5637. + timeout = 500;
  5638. + while (timeout-- &&
  5639. + fsl_readl(&usb_dr_regs->usbcmd) & USB_CMD_CTRL_RESET)
  5640. + udelay(1);
  5641. + if (timeout <= 0)
  5642. + ERR("%s - USBCMD_RST never clear. Timeout is %d \n",
  5643. + __FUNCTION__, timeout);
  5644. +
  5645. + /* configure the VBUSHS as IDLE(both host and device) */
  5646. +#if 0
  5647. + /* DDD really have to check into setting the following */
  5648. + fsl_writel(USB_MODE_STREAM_DISABLE, &usb_dr_regs->usbmode);
  5649. +#else
  5650. + temp = USB_MODE_STREAM_DISABLE | (pdata->es ? USBMODE_ES : 0);
  5651. + fsl_writel(temp, &usb_dr_regs->usbmode);
  5652. +#endif
  5653. +
  5654. + /* configure PHY interface */
  5655. + temp = fsl_readl(&usb_dr_regs->portsc1);
  5656. + temp &= ~(PORTSCX_PHY_TYPE_SEL | PORTSCX_PTW_8BIT);
  5657. +
  5658. + /* DDD wrong xcvr setting stuff follows */
  5659. + temp |= PORTSCX_PTS_ULPI;
  5660. + fsl_writel(temp, &usb_dr_regs->portsc1);
  5661. +
  5662. +
  5663. + /* disable all interrupt and clear all OTGSC status */
  5664. + temp = fsl_readl(&usb_dr_regs->otgsc);
  5665. + temp &= ~OTGSC_INTERRUPT_ENABLE_BITS_MASK;
  5666. +#if 0 // DDD
  5667. + /* DDD only want ID int
  5668. + * temp |= OTGSC_INTERRUPT_STATUS_BITS_MASK | OTGSC_CTRL_VBUS_DISCHARGE;
  5669. + */
  5670. + temp |= OTGSC_IE_USB_ID; /* DDD added this */
  5671. + temp &= ~OTGSC_IE_1ms_TIMER; /* DDD added this */
  5672. +#else
  5673. + temp |= OTGSC_INTERRUPT_STATUS_BITS_MASK | OTGSC_CTRL_VBUS_DISCHARGE;
  5674. +#endif
  5675. + fsl_writel(temp, &usb_dr_regs->otgsc);
  5676. +
  5677. + fsl_otg_drv_vbus(0);
  5678. +
  5679. +#if 0 // DDD beta-final
  5680. + temp = fsl_readl(&usb_dr_regs->otgsc);
  5681. + temp |= OTGSC_IE_A_SESSION_VALID;
  5682. + fsl_writel(temp, &usb_dr_regs->otgsc);
  5683. +#else
  5684. + /*
  5685. + * The identification (id) input is FALSE when a Mini-A plug is inserted
  5686. + * in the devices Mini-AB receptacle. Otherwise, this input is TRUE.
  5687. + * Also: record initial state of ID pin
  5688. + */
  5689. + if (fsl_readl(&usb_dr_regs->otgsc) & OTGSC_STS_USB_ID) {
  5690. + p_otg->otg.state = OTG_STATE_UNDEFINED;
  5691. + p_otg->fsm.id = 1;
  5692. + } else {
  5693. + p_otg->otg.state = OTG_STATE_A_IDLE;
  5694. + p_otg->fsm.id = 0;
  5695. + }
  5696. +
  5697. + DBG("initial ID pin=%d\n", p_otg->fsm.id);
  5698. +
  5699. + /* enable OTG ID pin interrupt */
  5700. + temp = fsl_readl(&usb_dr_regs->otgsc);
  5701. + temp |= OTGSC_IE_USB_ID;
  5702. + temp &= ~(OTGSC_CTRL_VBUS_DISCHARGE | OTGSC_IE_1ms_TIMER);
  5703. + fsl_writel(temp, &usb_dr_regs->otgsc);
  5704. +#endif
  5705. +
  5706. + return 0;
  5707. +}
  5708. +
  5709. +/* Initialize board specific registers,PIB board,clock and pin multiplexing */
  5710. +static int board_init(struct platform_device *pdev)
  5711. +{
  5712. + struct fsl_usb2_platform_data *pdata;
  5713. + pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data;
  5714. +
  5715. + /*
  5716. + * do platform specific init: check the clock, grab/config pins, etc.
  5717. + */
  5718. + if (pdata->platform_init(pdev) != 0)
  5719. + return -EINVAL;
  5720. +
  5721. + return 0;
  5722. +}
  5723. +
  5724. +/*-------------------------------------------------------------------------
  5725. + PROC File System Support
  5726. +-------------------------------------------------------------------------*/
  5727. +#ifdef CONFIG_USB_OTG_DEBUG_FILES
  5728. +
  5729. +#include <linux/seq_file.h>
  5730. +
  5731. +static const char proc_filename[] = "driver/fsl_usb2_otg";
  5732. +
  5733. +static int otg_proc_read(char *page, char **start, off_t off, int count,
  5734. + int *eof, void *_dev)
  5735. +{
  5736. + struct otg_fsm *fsm = &fsl_otg_dev->fsm;
  5737. + char *buf = page;
  5738. + char *next = buf;
  5739. + unsigned size = count;
  5740. + unsigned long flags;
  5741. + int t;
  5742. + u32 tmp_reg;
  5743. +
  5744. + if (off != 0)
  5745. + return 0;
  5746. +
  5747. + spin_lock_irqsave(&fsm->lock, flags);
  5748. +
  5749. + /* ------basic driver infomation ---- */
  5750. + t = scnprintf(next, size,
  5751. + DRIVER_DESC "\n" "fsl_usb2_otg version: %s\n\n",
  5752. + DRIVER_VERSION);
  5753. + size -= t;
  5754. + next += t;
  5755. +
  5756. + /* ------ Registers ----- */
  5757. + /* tmp_reg = le32_to_cpu(usb_dr_regs->otgsc); */
  5758. + tmp_reg = fsl_readl(&usb_dr_regs->otgsc);
  5759. + t = scnprintf(next, size, "OTGSC reg: 0x%08x\n", tmp_reg);
  5760. + size -= t;
  5761. + next += t;
  5762. +
  5763. + /* tmp_reg = le32_to_cpu(usb_dr_regs->portsc); */
  5764. + tmp_reg = fsl_readl(&usb_dr_regs->portsc1);
  5765. + t = scnprintf(next, size, "PORTSC reg: 0x%08x\n", tmp_reg);
  5766. + size -= t;
  5767. + next += t;
  5768. +
  5769. + /* tmp_reg = le32_to_cpu(usb_dr_regs->usbmode); */
  5770. + tmp_reg = fsl_readl(&usb_dr_regs->usbmode);
  5771. + t = scnprintf(next, size, "USBMODE reg: 0x%08x\n", tmp_reg);
  5772. + size -= t;
  5773. + next += t;
  5774. +
  5775. + /* tmp_reg = le32_to_cpu(usb_dr_regs->usbcmd); */
  5776. + tmp_reg = fsl_readl(&usb_dr_regs->usbcmd);
  5777. + t = scnprintf(next, size, "USBCMD reg: 0x%08x\n", tmp_reg);
  5778. + size -= t;
  5779. + next += t;
  5780. +
  5781. + /* tmp_reg = le32_to_cpu(usb_dr_regs->usbsts); */
  5782. + tmp_reg = fsl_readl(&usb_dr_regs->usbsts);
  5783. + t = scnprintf(next, size, "USBSTS reg: 0x%08x\n", tmp_reg);
  5784. + size -= t;
  5785. + next += t;
  5786. +
  5787. + /* ------ State ----- */
  5788. + t = scnprintf(next, size, "FSM protocol=%d %s\n", fsm->protocol,
  5789. + fsm->protocol ?
  5790. + (fsm->protocol == PROTO_HOST ? "Host" : "Gadget")
  5791. + : "None");
  5792. + size -= t;
  5793. + next += t;
  5794. +
  5795. + t = scnprintf(next, size,
  5796. + "OTG state: %s\n\n",
  5797. + state_string(fsl_otg_dev->otg.state));
  5798. + size -= t;
  5799. + next += t;
  5800. +
  5801. + /* ------ State Machine Variables ----- */
  5802. + t = scnprintf(next, size, "a_bus_req: %d\n", fsm->a_bus_req);
  5803. + size -= t;
  5804. + next += t;
  5805. +
  5806. + t = scnprintf(next, size, "b_bus_req: %d\n", fsm->b_bus_req);
  5807. + size -= t;
  5808. + next += t;
  5809. +
  5810. + t = scnprintf(next, size, "a_bus_resume: %d\n", fsm->a_bus_resume);
  5811. + size -= t;
  5812. + next += t;
  5813. +
  5814. + t = scnprintf(next, size, "a_bus_suspend: %d\n", fsm->a_bus_suspend);
  5815. + size -= t;
  5816. + next += t;
  5817. +
  5818. + t = scnprintf(next, size, "a_conn: %d\n", fsm->a_conn);
  5819. + size -= t;
  5820. + next += t;
  5821. +
  5822. + t = scnprintf(next, size, "a_sess_vld: %d\n", fsm->a_sess_vld);
  5823. + size -= t;
  5824. + next += t;
  5825. +
  5826. + t = scnprintf(next, size, "a_srp_det: %d\n", fsm->a_srp_det);
  5827. + size -= t;
  5828. + next += t;
  5829. +
  5830. + t = scnprintf(next, size, "a_vbus_vld: %d\n", fsm->a_vbus_vld);
  5831. + size -= t;
  5832. + next += t;
  5833. +
  5834. + t = scnprintf(next, size, "b_bus_resume: %d\n", fsm->b_bus_resume);
  5835. + size -= t;
  5836. + next += t;
  5837. +
  5838. + t = scnprintf(next, size, "b_bus_suspend: %d\n", fsm->b_bus_suspend);
  5839. + size -= t;
  5840. + next += t;
  5841. +
  5842. + t = scnprintf(next, size, "b_conn: %d\n", fsm->b_conn);
  5843. + size -= t;
  5844. + next += t;
  5845. +
  5846. + t = scnprintf(next, size, "b_se0_srp: %d\n", fsm->b_se0_srp);
  5847. + size -= t;
  5848. + next += t;
  5849. +
  5850. + t = scnprintf(next, size, "b_sess_end: %d\n", fsm->b_sess_end);
  5851. + size -= t;
  5852. + next += t;
  5853. +
  5854. + t = scnprintf(next, size, "b_sess_vld: %d\n", fsm->b_sess_vld);
  5855. + size -= t;
  5856. + next += t;
  5857. +
  5858. + t = scnprintf(next, size, "id: %d\n", fsm->id);
  5859. + size -= t;
  5860. + next += t;
  5861. +
  5862. + spin_unlock_irqrestore(&fsm->lock, flags);
  5863. +
  5864. + *eof = 1;
  5865. + return count - size;
  5866. +}
  5867. +
  5868. +#define create_proc_file() create_proc_read_entry(proc_filename, \
  5869. + 0, NULL, otg_proc_read, NULL)
  5870. +
  5871. +#define remove_proc_file() remove_proc_entry(proc_filename, NULL)
  5872. +
  5873. +#else /* !CONFIG_USB_OTG_DEBUG_FILES */
  5874. +
  5875. +#define create_proc_file() do {} while (0)
  5876. +#define remove_proc_file() do {} while (0)
  5877. +
  5878. +#endif /*CONFIG_USB_OTG_DEBUG_FILES */
  5879. +
  5880. +/*----------------------------------------------------------*/
  5881. +/* Char driver interface to control some OTG input */
  5882. +
  5883. +/*
  5884. + * This function handle some ioctl command,such as get otg
  5885. + * status and set host suspend
  5886. + */
  5887. +static int fsl_otg_ioctl(struct inode *inode, struct file *file,
  5888. + unsigned int cmd, unsigned long arg)
  5889. +{
  5890. + u32 retval = 0;
  5891. +
  5892. + switch (cmd) {
  5893. + case GET_OTG_STATUS:
  5894. + retval = fsl_otg_dev->host_working;
  5895. + break;
  5896. +
  5897. + case SET_A_SUSPEND_REQ:
  5898. + fsl_otg_dev->fsm.a_suspend_req = arg;
  5899. + break;
  5900. +
  5901. + case SET_A_BUS_DROP:
  5902. + fsl_otg_dev->fsm.a_bus_drop = arg;
  5903. + break;
  5904. +
  5905. + case SET_A_BUS_REQ:
  5906. + fsl_otg_dev->fsm.a_bus_req = arg;
  5907. + break;
  5908. +
  5909. + case SET_B_BUS_REQ:
  5910. + fsl_otg_dev->fsm.b_bus_req = arg;
  5911. + break;
  5912. +
  5913. + default:
  5914. + break;
  5915. + }
  5916. +
  5917. + otg_statemachine(&fsl_otg_dev->fsm);
  5918. +
  5919. + return retval;
  5920. +}
  5921. +
  5922. +static int fsl_otg_open(struct inode *inode, struct file *file)
  5923. +{
  5924. +
  5925. + return 0;
  5926. +}
  5927. +
  5928. +static int fsl_otg_release(struct inode *inode, struct file *file)
  5929. +{
  5930. +
  5931. + return 0;
  5932. +}
  5933. +
  5934. +static struct file_operations otg_fops = {
  5935. + .owner = THIS_MODULE,
  5936. + .llseek = NULL,
  5937. + .read = NULL,
  5938. + .write = NULL,
  5939. + .ioctl = fsl_otg_ioctl,
  5940. + .open = fsl_otg_open,
  5941. + .release = fsl_otg_release,
  5942. +};
  5943. +
  5944. +static int __init fsl_otg_probe(struct platform_device *pdev)
  5945. +{
  5946. + int status;
  5947. + struct fsl_usb2_platform_data *pdata;
  5948. +
  5949. + DBG("pdev=0x%p\n", pdev);
  5950. +
  5951. + if (!pdev)
  5952. + return -ENODEV;
  5953. +
  5954. + if (!pdev->dev.platform_data)
  5955. + return -ENOMEM;
  5956. +
  5957. + pdata = pdev->dev.platform_data;
  5958. +#if 1 // DDD do this elsewhere
  5959. + /* Initialize the clock, multiplexing pin and PHY interface */
  5960. + board_init(pdev);
  5961. +#endif
  5962. +
  5963. + /* configure the OTG */
  5964. + status = fsl_otg_cfg(pdev);
  5965. + if (status) {
  5966. + printk(KERN_INFO "Couldn't init OTG module\n");
  5967. + return -status;
  5968. + }
  5969. +
  5970. + /* start OTG */
  5971. + status = usb_otg_start(pdev);
  5972. +
  5973. + if (register_chrdev(FSL_OTG_MAJOR, FSL_OTG_NAME, &otg_fops)) {
  5974. + printk(KERN_WARNING FSL_OTG_NAME
  5975. + ": unable to register FSL OTG device\n");
  5976. + return -EIO;
  5977. + }
  5978. +
  5979. + create_proc_file();
  5980. + return status;
  5981. +}
  5982. +
  5983. +static int fsl_otg_remove(struct platform_device *pdev)
  5984. +{
  5985. + u32 ie;
  5986. + struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
  5987. + unsigned long flags;
  5988. +
  5989. + DBG("pdev=0x%p pdata=0x%p\n", pdev, pdata);
  5990. +
  5991. + otg_set_transceiver(NULL);
  5992. +
  5993. + /* disable and clear OTGSC interrupts */
  5994. + spin_lock_irqsave(&usb_dr_regs_lock, flags);
  5995. + ie = fsl_readl(&usb_dr_regs->otgsc);
  5996. + ie &= ~OTGSC_INTERRUPT_ENABLE_BITS_MASK;
  5997. + ie |= OTGSC_INTERRUPT_STATUS_BITS_MASK;
  5998. + fsl_writel(ie, &usb_dr_regs->otgsc);
  5999. + spin_unlock_irqrestore(&usb_dr_regs_lock, flags);
  6000. +
  6001. + free_irq(fsl_otg_dev->irq, fsl_otg_dev);
  6002. +
  6003. + kfree(fsl_otg_dev);
  6004. +
  6005. + remove_proc_file();
  6006. +
  6007. + unregister_chrdev(FSL_OTG_MAJOR, FSL_OTG_NAME);
  6008. +
  6009. + if (pdata->platform_uninit)
  6010. + pdata->platform_uninit(pdev);
  6011. +
  6012. + fsl_otg_dev = NULL;
  6013. + return 0;
  6014. +}
  6015. +
  6016. +struct platform_driver fsl_otg_driver = {
  6017. + .probe = fsl_otg_probe,
  6018. + .remove = fsl_otg_remove,
  6019. + .driver = {
  6020. + .name = driver_name,
  6021. + .owner = THIS_MODULE,
  6022. + },
  6023. +};
  6024. +
  6025. +/*-------------------------------------------------------------------------*/
  6026. +
  6027. +static int __init fsl_usb_otg_init(void)
  6028. +{
  6029. + printk(KERN_INFO DRIVER_DESC " loaded, %s\n", DRIVER_VERSION);
  6030. + return platform_driver_register(&fsl_otg_driver);
  6031. +}
  6032. +
  6033. +static void __exit fsl_usb_otg_exit(void)
  6034. +{
  6035. + platform_driver_unregister(&fsl_otg_driver);
  6036. +}
  6037. +
  6038. +module_init(fsl_usb_otg_init);
  6039. +module_exit(fsl_usb_otg_exit);
  6040. +
  6041. +MODULE_DESCRIPTION(DRIVER_INFO);
  6042. +MODULE_AUTHOR(DRIVER_AUTHOR);
  6043. +MODULE_LICENSE("GPL");
  6044. --- /dev/null
  6045. +++ b/drivers/usb/otg/fsl_otg.h
  6046. @@ -0,0 +1,139 @@
  6047. +/*
  6048. + * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  6049. + */
  6050. +
  6051. +/*
  6052. + * The code contained herein is licensed under the GNU General Public
  6053. + * License. You may obtain a copy of the GNU General Public License
  6054. + * Version 2 or later at the following locations:
  6055. + *
  6056. + * http://www.opensource.org/licenses/gpl-license.html
  6057. + * http://www.gnu.org/copyleft/gpl.html
  6058. + */
  6059. +
  6060. +#ifndef FSL_OTG_H
  6061. +#define FSL_OTG_H
  6062. +#include <linux/usb/otg.h>
  6063. +#include "otg_fsm.h"
  6064. +#include <linux/ioctl.h>
  6065. +
  6066. +#define ERR(format, arg...) \
  6067. +printk(KERN_ERR "%s:%s: " format "\n" , __FILE__, __FUNCTION__ , ## arg)
  6068. +
  6069. +/*
  6070. + * A-DEVICE timing constants
  6071. + */
  6072. +
  6073. +/* Wait for VBUS Rise */
  6074. +#define TA_WAIT_VRISE (100) /* a_wait_vrise 100 ms, section: 6.6.5.1 */
  6075. +
  6076. +/* Wait for B-Connect */
  6077. +#define TA_WAIT_BCON (10000) /* a_wait_bcon > 1 sec, section: 6.6.5.2
  6078. + * This is only used to get out of
  6079. + * OTG_STATE_A_WAIT_BCON state if there was
  6080. + * no connection for these many milliseconds
  6081. + */
  6082. +
  6083. +/* A-Idle to B-Disconnect */
  6084. +/* It is necessary for this timer to be more than 750 ms because of a bug in OPT
  6085. + * test 5.4 in which B OPT disconnects after 750 ms instead of 75ms as stated
  6086. + * in the test description
  6087. + */
  6088. +#define TA_AIDL_BDIS (5000) /* a_suspend minimum 200 ms, section: 6.6.5.3 */
  6089. +
  6090. +/* B-Idle to A-Disconnect */
  6091. +#define TA_BIDL_ADIS (12) /* 3 to 200 ms */
  6092. +
  6093. +/* B-device timing constants */
  6094. +
  6095. +/* Data-Line Pulse Time*/
  6096. +#define TB_DATA_PLS (10) /* b_srp_init,continue 5~10ms, section:5.3.3 */
  6097. +#define TB_DATA_PLS_MIN (5) /* minimum 5 ms */
  6098. +#define TB_DATA_PLS_MAX (10) /* maximum 10 ms */
  6099. +
  6100. +/* SRP Initiate Time */
  6101. +#define TB_SRP_INIT (100) /* b_srp_init,maximum 100 ms, section:5.3.8 */
  6102. +
  6103. +/* SRP Fail Time */
  6104. +#define TB_SRP_FAIL (7000) /* b_srp_init,Fail time 5~30s, section:6.8.2.2 */
  6105. +
  6106. +/* SRP result wait time */
  6107. +#define TB_SRP_WAIT (60)
  6108. +
  6109. +/* VBus time */
  6110. +#define TB_VBUS_PLS (30) /* time to keep vbus pulsing asserted */
  6111. +
  6112. +/* Discharge time */
  6113. +/* This time should be less than 10ms. It varies from system to system. */
  6114. +#define TB_VBUS_DSCHRG (8)
  6115. +
  6116. +/* A-SE0 to B-Reset */
  6117. +#define TB_ASE0_BRST (20) /* b_wait_acon, mini 3.125 ms,section:6.8.2.4 */
  6118. +
  6119. +/* A bus suspend timer before we can switch to b_wait_aconn */
  6120. +#define TB_A_SUSPEND (7)
  6121. +#define TB_BUS_RESUME (12)
  6122. +
  6123. +/* SE0 Time Before SRP */
  6124. +#define TB_SE0_SRP (2) /* b_idle,minimum 2 ms, section:5.3.2 */
  6125. +
  6126. +#define SET_OTG_STATE(otg_ptr, newstate) ((otg_ptr)->state = newstate)
  6127. +
  6128. +
  6129. +struct fsl_otg_timer {
  6130. + unsigned long expires; /* Number of count increase to timeout */
  6131. + unsigned long count; /* Tick counter */
  6132. + void (*function) (unsigned long); /* Timeout function */
  6133. + unsigned long data; /* Data passed to function */
  6134. + struct list_head list;
  6135. +};
  6136. +
  6137. +struct fsl_otg_timer inline *otg_timer_initializer
  6138. + (void (*function) (unsigned long), unsigned long expires,
  6139. + unsigned long data) {
  6140. + struct fsl_otg_timer *timer;
  6141. + timer = kmalloc(sizeof(struct fsl_otg_timer), GFP_KERNEL);
  6142. + if (timer == NULL)
  6143. + return NULL;
  6144. + timer->function = function;
  6145. + timer->expires = expires;
  6146. + timer->data = data;
  6147. + return timer;
  6148. +}
  6149. +
  6150. +struct fsl_otg {
  6151. + struct otg_transceiver otg;
  6152. + struct otg_fsm fsm;
  6153. + struct fsl_usb_device_regs *dr_mem_map;
  6154. + struct delayed_work otg_event;
  6155. +
  6156. + /*used for usb host */
  6157. + u8 host_working;
  6158. + u8 on_off;
  6159. +
  6160. + int irq;
  6161. +};
  6162. +
  6163. +struct fsl_otg_config {
  6164. + u8 otg_port;
  6165. +};
  6166. +
  6167. +/*For SRP and HNP handle*/
  6168. +#define FSL_OTG_MAJOR 66
  6169. +#define FSL_OTG_NAME "fsl-otg"
  6170. +/*Command to OTG driver(ioctl)*/
  6171. +#define OTG_IOCTL_MAGIC FSL_OTG_MAJOR
  6172. +/*if otg work as host,it should return 1,otherwise it return 0*/
  6173. +#define GET_OTG_STATUS _IOR(OTG_IOCTL_MAGIC, 1, int)
  6174. +#define SET_A_SUSPEND_REQ _IOW(OTG_IOCTL_MAGIC, 2, int)
  6175. +#define SET_A_BUS_DROP _IOW(OTG_IOCTL_MAGIC, 3, int)
  6176. +#define SET_A_BUS_REQ _IOW(OTG_IOCTL_MAGIC, 4, int)
  6177. +#define SET_B_BUS_REQ _IOW(OTG_IOCTL_MAGIC, 5, int)
  6178. +#define GET_A_SUSPEND_REQ _IOR(OTG_IOCTL_MAGIC, 6, int)
  6179. +#define GET_A_BUS_DROP _IOR(OTG_IOCTL_MAGIC, 7, int)
  6180. +#define GET_A_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 8, int)
  6181. +#define GET_B_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 9, int)
  6182. +
  6183. +
  6184. +/********************************************************************/
  6185. +#endif
  6186. --- /dev/null
  6187. +++ b/drivers/usb/otg/otg_fsm.c
  6188. @@ -0,0 +1,381 @@
  6189. +/* OTG Finite State Machine from OTG spec
  6190. + *
  6191. + * Copyright (C) 2007 Freescale Semiconductor, Inc.
  6192. + *
  6193. + * Author: Li Yang <[email protected]>
  6194. + * Jerry Huang <[email protected]>
  6195. + *
  6196. + * This program is free software; you can redistribute it and/or modify it
  6197. + * under the terms of the GNU General Public License as published by the
  6198. + * Free Software Foundation; either version 2 of the License, or (at your
  6199. + * option) any later version.
  6200. + *
  6201. + * This program is distributed in the hope that it will be useful, but
  6202. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  6203. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6204. + * General Public License for more details.
  6205. + *
  6206. + * You should have received a copy of the GNU General Public License along
  6207. + * with this program; if not, write to the Free Software Foundation, Inc.,
  6208. + * 675 Mass Ave, Cambridge, MA 02139, USA.
  6209. + */
  6210. +
  6211. +#include <linux/kernel.h>
  6212. +#include <linux/types.h>
  6213. +#include <linux/usb/otg.h>
  6214. +#include <linux/spinlock.h>
  6215. +#include <linux/delay.h>
  6216. +#include <linux/usb.h>
  6217. +#include <linux/usb_gadget.h>
  6218. +
  6219. +#include "otg_fsm.h"
  6220. +
  6221. +
  6222. +/* Defined by device specific driver, for different timer implementation */
  6223. +extern void *a_wait_vrise_tmr, *a_wait_bcon_tmr, *a_aidl_bdis_tmr,
  6224. + *b_ase0_brst_tmr, *b_se0_srp_tmr, *b_srp_fail_tmr, *a_wait_enum_tmr;
  6225. +
  6226. +const char *state_string(enum usb_otg_state state)
  6227. +{
  6228. + switch (state) {
  6229. + case OTG_STATE_A_IDLE: return "a_idle";
  6230. + case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise";
  6231. + case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon";
  6232. + case OTG_STATE_A_HOST: return "a_host";
  6233. + case OTG_STATE_A_SUSPEND: return "a_suspend";
  6234. + case OTG_STATE_A_PERIPHERAL: return "a_peripheral";
  6235. + case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall";
  6236. + case OTG_STATE_A_VBUS_ERR: return "a_vbus_err";
  6237. + case OTG_STATE_B_IDLE: return "b_idle";
  6238. + case OTG_STATE_B_SRP_INIT: return "b_srp_init";
  6239. + case OTG_STATE_B_PERIPHERAL: return "b_peripheral";
  6240. + case OTG_STATE_B_WAIT_ACON: return "b_wait_acon";
  6241. + case OTG_STATE_B_HOST: return "b_host";
  6242. + default: return "UNDEFINED";
  6243. + }
  6244. +}
  6245. +EXPORT_SYMBOL(state_string);
  6246. +
  6247. +/* Change USB protocol when there is a protocol change */
  6248. +static int otg_set_protocol(struct otg_fsm *fsm, int protocol)
  6249. +{
  6250. + int ret = 0;
  6251. +
  6252. + VDBG("DDD old fsm->protocol= %d; new protocol= %d\n",
  6253. + fsm->protocol, protocol);
  6254. + if (fsm->protocol != protocol) {
  6255. + VDBG("Changing role fsm->protocol= %d; new protocol= %d\n",
  6256. + fsm->protocol, protocol);
  6257. + /* stop old protocol */
  6258. + if (fsm->protocol == PROTO_HOST)
  6259. + ret = fsm->ops->start_host(fsm, 0);
  6260. + else if (fsm->protocol == PROTO_GADGET)
  6261. + ret = fsm->ops->start_gadget(fsm, 0);
  6262. + if (ret)
  6263. + return ret;
  6264. +
  6265. + /* start new protocol */
  6266. + if (protocol == PROTO_HOST)
  6267. + ret = fsm->ops->start_host(fsm, 1);
  6268. + else if (protocol == PROTO_GADGET)
  6269. + ret = fsm->ops->start_gadget(fsm, 1);
  6270. + if (ret)
  6271. + return ret;
  6272. +
  6273. + fsm->protocol = protocol;
  6274. + return 0;
  6275. + }
  6276. +
  6277. + return 0;
  6278. +}
  6279. +
  6280. +static int state_changed;
  6281. +
  6282. +/* Called when leaving a state. Do state clean up jobs here */
  6283. +static void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state)
  6284. +{
  6285. + switch (old_state) {
  6286. + case OTG_STATE_B_IDLE:
  6287. + otg_del_timer(fsm, fsm->b_se0_srp_tmr);
  6288. + fsm->b_se0_srp = 0;
  6289. + break;
  6290. + case OTG_STATE_B_SRP_INIT:
  6291. + fsm->b_srp_done = 0;
  6292. + break;
  6293. + case OTG_STATE_B_PERIPHERAL:
  6294. + break;
  6295. + case OTG_STATE_B_WAIT_ACON:
  6296. + otg_del_timer(fsm, fsm->b_ase0_brst_tmr);
  6297. + fsm->b_ase0_brst_tmout = 0;
  6298. + break;
  6299. + case OTG_STATE_B_HOST:
  6300. + break;
  6301. + case OTG_STATE_A_IDLE:
  6302. + break;
  6303. + case OTG_STATE_A_WAIT_VRISE:
  6304. + otg_del_timer(fsm, fsm->a_wait_vrise_tmr);
  6305. + fsm->a_wait_vrise_tmout = 0;
  6306. + break;
  6307. + case OTG_STATE_A_WAIT_BCON:
  6308. + otg_del_timer(fsm, fsm->a_wait_bcon_tmr);
  6309. + fsm->a_wait_bcon_tmout = 0;
  6310. + break;
  6311. + case OTG_STATE_A_HOST:
  6312. + otg_del_timer(fsm, fsm->a_wait_enum_tmr);
  6313. + break;
  6314. + case OTG_STATE_A_SUSPEND:
  6315. + otg_del_timer(fsm, fsm->a_aidl_bdis_tmr);
  6316. + fsm->a_aidl_bdis_tmout = 0;
  6317. + fsm->a_suspend_req = 0;
  6318. + fsm->a_bus_req = 1; /* FIXME */
  6319. + break;
  6320. + case OTG_STATE_A_PERIPHERAL:
  6321. + break;
  6322. + case OTG_STATE_A_WAIT_VFALL:
  6323. + otg_del_timer(fsm, fsm->a_wait_vrise_tmr);
  6324. + break;
  6325. + case OTG_STATE_A_VBUS_ERR:
  6326. + break;
  6327. + default:
  6328. + break;
  6329. + }
  6330. +}
  6331. +
  6332. +/* Called when entering a state */
  6333. +static int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
  6334. +{
  6335. + state_changed = 1;
  6336. + VDBG("State: old=%s new=%s \n",
  6337. + state_string(fsm->transceiver->state), state_string(new_state));
  6338. +
  6339. + if (fsm->transceiver->state == new_state)
  6340. + return 0;
  6341. +
  6342. + otg_leave_state(fsm, fsm->transceiver->state);
  6343. + switch (new_state) {
  6344. + case OTG_STATE_B_IDLE:
  6345. + otg_drv_vbus(fsm, 0);
  6346. + otg_chrg_vbus(fsm, 0);
  6347. + otg_loc_conn(fsm, 0);
  6348. + otg_loc_sof(fsm, 0);
  6349. + otg_set_protocol(fsm, PROTO_UNDEF);
  6350. + otg_add_timer(fsm, fsm->b_se0_srp_tmr);
  6351. + break;
  6352. + case OTG_STATE_B_SRP_INIT:
  6353. + otg_start_pulse(fsm);
  6354. + otg_loc_sof(fsm, 0);
  6355. + otg_set_protocol(fsm, PROTO_UNDEF);
  6356. + otg_add_timer(fsm, fsm->b_srp_fail_tmr);
  6357. + break;
  6358. + case OTG_STATE_B_PERIPHERAL:
  6359. + otg_chrg_vbus(fsm, 0);
  6360. + otg_loc_conn(fsm, 1);
  6361. + otg_loc_sof(fsm, 0);
  6362. + otg_set_protocol(fsm, PROTO_GADGET);
  6363. + break;
  6364. + case OTG_STATE_B_WAIT_ACON:
  6365. + otg_chrg_vbus(fsm, 0);
  6366. + otg_loc_conn(fsm, 0);
  6367. + otg_loc_sof(fsm, 0);
  6368. + otg_set_protocol(fsm, PROTO_HOST);
  6369. + otg_add_timer(fsm, fsm->b_ase0_brst_tmr);
  6370. + fsm->a_bus_suspend = 0;
  6371. + break;
  6372. + case OTG_STATE_B_HOST:
  6373. + otg_chrg_vbus(fsm, 0);
  6374. + otg_loc_conn(fsm, 0);
  6375. + otg_loc_sof(fsm, 1);
  6376. + otg_set_protocol(fsm, PROTO_HOST);
  6377. + usb_bus_start_enum(fsm->transceiver->host,
  6378. + fsm->transceiver->host->otg_port);
  6379. + break;
  6380. + case OTG_STATE_A_IDLE:
  6381. + otg_drv_vbus(fsm, 0);
  6382. + otg_chrg_vbus(fsm, 0);
  6383. + otg_loc_conn(fsm, 0);
  6384. + otg_loc_sof(fsm, 0);
  6385. + otg_set_protocol(fsm, PROTO_HOST);
  6386. + break;
  6387. + case OTG_STATE_A_WAIT_VRISE:
  6388. + otg_drv_vbus(fsm, 1);
  6389. + otg_loc_conn(fsm, 0);
  6390. + otg_loc_sof(fsm, 0);
  6391. + otg_set_protocol(fsm, PROTO_HOST);
  6392. + otg_add_timer(fsm, fsm->a_wait_vrise_tmr);
  6393. + break;
  6394. + case OTG_STATE_A_WAIT_BCON:
  6395. + otg_drv_vbus(fsm, 1);
  6396. + otg_loc_conn(fsm, 0);
  6397. + otg_loc_sof(fsm, 0);
  6398. + otg_set_protocol(fsm, PROTO_HOST);
  6399. + otg_add_timer(fsm, fsm->a_wait_bcon_tmr);
  6400. + break;
  6401. + case OTG_STATE_A_HOST:
  6402. + otg_drv_vbus(fsm, 1);
  6403. + otg_loc_conn(fsm, 0);
  6404. + otg_loc_sof(fsm, 1);
  6405. + otg_set_protocol(fsm, PROTO_HOST);
  6406. + /*
  6407. + * When HNP is triggered while a_bus_req = 0, a_host will
  6408. + * suspend too fast to complete a_set_b_hnp_en
  6409. + */
  6410. + if (!fsm->a_bus_req || fsm->a_suspend_req)
  6411. + otg_add_timer(fsm, fsm->a_wait_enum_tmr);
  6412. + break;
  6413. + case OTG_STATE_A_SUSPEND:
  6414. + otg_drv_vbus(fsm, 1);
  6415. + otg_loc_conn(fsm, 0);
  6416. + otg_loc_sof(fsm, 0);
  6417. + otg_set_protocol(fsm, PROTO_HOST);
  6418. + otg_add_timer(fsm, fsm->a_aidl_bdis_tmr);
  6419. +
  6420. + break;
  6421. + case OTG_STATE_A_PERIPHERAL:
  6422. + otg_loc_conn(fsm, 1);
  6423. + otg_loc_sof(fsm, 0);
  6424. + otg_set_protocol(fsm, PROTO_GADGET);
  6425. + otg_drv_vbus(fsm, 1);
  6426. + break;
  6427. + case OTG_STATE_A_WAIT_VFALL:
  6428. + otg_drv_vbus(fsm, 0);
  6429. + otg_loc_conn(fsm, 0);
  6430. + otg_loc_sof(fsm, 0);
  6431. + otg_set_protocol(fsm, PROTO_HOST);
  6432. + break;
  6433. + case OTG_STATE_A_VBUS_ERR:
  6434. + otg_drv_vbus(fsm, 0);
  6435. + otg_loc_conn(fsm, 0);
  6436. + otg_loc_sof(fsm, 0);
  6437. + otg_set_protocol(fsm, PROTO_UNDEF);
  6438. + break;
  6439. + default:
  6440. + break;
  6441. + }
  6442. +
  6443. + fsm->transceiver->state = new_state;
  6444. + return 0;
  6445. +}
  6446. +
  6447. +/* State change judgement */
  6448. +int otg_statemachine(struct otg_fsm *fsm)
  6449. +{
  6450. + enum usb_otg_state state;
  6451. + unsigned long flags;
  6452. +
  6453. + spin_lock_irqsave(&fsm->lock, flags);
  6454. +
  6455. + state = fsm->transceiver->state;
  6456. + state_changed = 0;
  6457. + /* State machine state change judgement */
  6458. +
  6459. + VDBG(" State: %s \n", state_string(state));
  6460. +
  6461. + switch (state) {
  6462. + case OTG_STATE_UNDEFINED:
  6463. + if (fsm->id)
  6464. + otg_set_state(fsm, OTG_STATE_B_IDLE);
  6465. + else
  6466. + otg_set_state(fsm, OTG_STATE_A_IDLE);
  6467. + break;
  6468. + case OTG_STATE_B_IDLE:
  6469. + if (!fsm->id)
  6470. + otg_set_state(fsm, OTG_STATE_A_IDLE);
  6471. + else if (fsm->b_sess_vld && fsm->transceiver->gadget)
  6472. + otg_set_state(fsm, OTG_STATE_B_PERIPHERAL);
  6473. + else if (fsm->b_bus_req && fsm->b_sess_end && fsm->b_se0_srp)
  6474. + otg_set_state(fsm, OTG_STATE_B_SRP_INIT);
  6475. + break;
  6476. + case OTG_STATE_B_SRP_INIT:
  6477. + if (!fsm->id || fsm->b_srp_done)
  6478. + otg_set_state(fsm, OTG_STATE_B_IDLE);
  6479. + break;
  6480. + case OTG_STATE_B_PERIPHERAL:
  6481. + if (!fsm->id || !fsm->b_sess_vld)
  6482. + otg_set_state(fsm, OTG_STATE_B_IDLE);
  6483. + else if (fsm->b_bus_req &&
  6484. + fsm->transceiver->
  6485. + gadget->b_hnp_enable && fsm->a_bus_suspend)
  6486. + otg_set_state(fsm, OTG_STATE_B_WAIT_ACON);
  6487. + break;
  6488. + case OTG_STATE_B_WAIT_ACON:
  6489. + if (fsm->a_conn)
  6490. + otg_set_state(fsm, OTG_STATE_B_HOST);
  6491. + else if (!fsm->id || !fsm->b_sess_vld)
  6492. + otg_set_state(fsm, OTG_STATE_B_IDLE);
  6493. + else if (fsm->a_bus_resume || fsm->b_ase0_brst_tmout) {
  6494. + fsm->b_ase0_brst_tmout = 0;
  6495. + otg_set_state(fsm, OTG_STATE_B_PERIPHERAL);
  6496. + }
  6497. + break;
  6498. + case OTG_STATE_B_HOST:
  6499. + if (!fsm->id || !fsm->b_sess_vld)
  6500. + otg_set_state(fsm, OTG_STATE_B_IDLE);
  6501. + else if (!fsm->b_bus_req || !fsm->a_conn)
  6502. + otg_set_state(fsm, OTG_STATE_B_PERIPHERAL);
  6503. + break;
  6504. + case OTG_STATE_A_IDLE:
  6505. + if (fsm->id)
  6506. + otg_set_state(fsm, OTG_STATE_B_IDLE);
  6507. + else if (!fsm->a_bus_drop && (fsm->a_bus_req || fsm->a_srp_det))
  6508. + otg_set_state(fsm, OTG_STATE_A_WAIT_VRISE);
  6509. + break;
  6510. + case OTG_STATE_A_WAIT_VRISE:
  6511. + if (fsm->id || fsm->a_bus_drop || fsm->a_vbus_vld ||
  6512. + fsm->a_wait_vrise_tmout) {
  6513. + otg_set_state(fsm, OTG_STATE_A_WAIT_BCON);
  6514. + }
  6515. + break;
  6516. + case OTG_STATE_A_WAIT_BCON:
  6517. + if (!fsm->a_vbus_vld)
  6518. + otg_set_state(fsm, OTG_STATE_A_VBUS_ERR);
  6519. + else if (fsm->id | fsm->a_bus_drop | fsm->a_wait_bcon_tmout)
  6520. + otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
  6521. + else if (fsm->b_conn)
  6522. + otg_set_state(fsm, OTG_STATE_A_HOST);
  6523. + break;
  6524. + case OTG_STATE_A_HOST:
  6525. + if ((!fsm->a_bus_req || fsm->a_suspend_req) &&
  6526. + fsm->transceiver->host->b_hnp_enable)
  6527. + otg_set_state(fsm, OTG_STATE_A_SUSPEND);
  6528. + else if (fsm->id || !fsm->b_conn || fsm->a_bus_drop)
  6529. + otg_set_state(fsm, OTG_STATE_A_WAIT_BCON);
  6530. + else if (!fsm->a_vbus_vld)
  6531. + otg_set_state(fsm, OTG_STATE_A_VBUS_ERR);
  6532. + break;
  6533. + case OTG_STATE_A_SUSPEND:
  6534. + if (!fsm->b_conn && fsm->transceiver->host->b_hnp_enable)
  6535. + otg_set_state(fsm, OTG_STATE_A_PERIPHERAL);
  6536. + else if (!fsm->b_conn && !fsm->transceiver->host->b_hnp_enable)
  6537. + otg_set_state(fsm, OTG_STATE_A_WAIT_BCON);
  6538. + else if (fsm->a_bus_req || fsm->b_bus_resume)
  6539. + otg_set_state(fsm, OTG_STATE_A_HOST);
  6540. + else if (fsm->id || fsm->a_bus_drop || fsm->a_aidl_bdis_tmout)
  6541. + otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
  6542. + else if (!fsm->a_vbus_vld)
  6543. + otg_set_state(fsm, OTG_STATE_A_VBUS_ERR);
  6544. + break;
  6545. + case OTG_STATE_A_PERIPHERAL:
  6546. + if (fsm->id || fsm->a_bus_drop)
  6547. + otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
  6548. + else if (fsm->b_bus_suspend)
  6549. + otg_set_state(fsm, OTG_STATE_A_WAIT_BCON);
  6550. + else if (!fsm->a_vbus_vld)
  6551. + otg_set_state(fsm, OTG_STATE_A_VBUS_ERR);
  6552. + break;
  6553. + case OTG_STATE_A_WAIT_VFALL:
  6554. + if (fsm->id || fsm->a_bus_req || (!fsm->a_sess_vld &&
  6555. + !fsm->b_conn))
  6556. + otg_set_state(fsm, OTG_STATE_A_IDLE);
  6557. + break;
  6558. + case OTG_STATE_A_VBUS_ERR:
  6559. + if (fsm->id || fsm->a_bus_drop || fsm->a_clr_err)
  6560. + otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
  6561. + break;
  6562. + default:
  6563. + break;
  6564. + }
  6565. + spin_unlock_irqrestore(&fsm->lock, flags);
  6566. +
  6567. + return state_changed;
  6568. +}
  6569. +EXPORT_SYMBOL(otg_statemachine);
  6570. --- /dev/null
  6571. +++ b/drivers/usb/otg/otg_fsm.h
  6572. @@ -0,0 +1,170 @@
  6573. +/* Copyright (C) 2006-2007 Freescale Semiconductor, Inc.
  6574. + *
  6575. + * This program is free software; you can redistribute it and/or modify it
  6576. + * under the terms of the GNU General Public License as published by the
  6577. + * Free Software Foundation; either version 2 of the License, or (at your
  6578. + * option) any later version.
  6579. + *
  6580. + * This program is distributed in the hope that it will be useful, but
  6581. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  6582. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6583. + * General Public License for more details.
  6584. + *
  6585. + * You should have received a copy of the GNU General Public License along
  6586. + * with this program; if not, write to the Free Software Foundation, Inc.,
  6587. + * 675 Mass Ave, Cambridge, MA 02139, USA.
  6588. + */
  6589. +
  6590. +#ifndef OTG_FSM_H
  6591. +#define OTG_FSM_H
  6592. +
  6593. +#if 1
  6594. +#define DEBUG 1
  6595. +#define VERBOSE 1
  6596. +#endif
  6597. +
  6598. +#ifdef DEBUG
  6599. +#define DBG(fmt, args...) printk(KERN_DEBUG "[%s] " fmt , \
  6600. + __FUNCTION__, ## args)
  6601. +#else
  6602. +#define DBG(fmt, args...) do {} while (0)
  6603. +#endif
  6604. +
  6605. +#ifdef VERBOSE
  6606. +#define VDBG DBG
  6607. +#else
  6608. +#define VDBG(stuff...) do {} while (0)
  6609. +#endif
  6610. +
  6611. +#ifdef VERBOSE
  6612. +#define MPC_LOC printk("Current Location [%s]:[%d]\n", __FILE__, __LINE__)
  6613. +#else
  6614. +#define MPC_LOC do {} while (0)
  6615. +#endif
  6616. +
  6617. +#define PROTO_UNDEF 0
  6618. +#define PROTO_HOST 1
  6619. +#define PROTO_GADGET 2
  6620. +
  6621. +
  6622. +
  6623. +
  6624. +
  6625. +/* OTG state machine according to the OTG spec */
  6626. +struct otg_fsm {
  6627. + /* Input */
  6628. + int a_bus_resume;
  6629. + int a_bus_suspend;
  6630. + int a_conn;
  6631. + int a_sess_vld;
  6632. + int a_srp_det;
  6633. + int a_vbus_vld;
  6634. + int b_bus_resume;
  6635. + int b_bus_suspend;
  6636. + int b_conn;
  6637. + int b_se0_srp;
  6638. + int b_sess_end;
  6639. + int b_sess_vld;
  6640. + int id;
  6641. +
  6642. + /* Internal variables */
  6643. + int a_set_b_hnp_en;
  6644. + int b_srp_done;
  6645. + int b_hnp_enable;
  6646. +
  6647. + /* Timeout indicator for timers */
  6648. + int a_wait_vrise_tmout;
  6649. + int a_wait_bcon_tmout;
  6650. + int a_aidl_bdis_tmout;
  6651. + int b_ase0_brst_tmout;
  6652. +
  6653. + /* Informative variables */
  6654. + int a_bus_drop;
  6655. + int a_bus_req;
  6656. + int a_clr_err;
  6657. + int a_suspend_req;
  6658. + int b_bus_req;
  6659. +
  6660. + /* Output */
  6661. + int drv_vbus;
  6662. + int loc_conn;
  6663. + int loc_sof;
  6664. +
  6665. + struct otg_fsm_ops *ops;
  6666. + struct otg_transceiver *transceiver;
  6667. +
  6668. + void *a_wait_vrise_tmr;
  6669. + void *a_wait_bcon_tmr;
  6670. + void *a_aidl_bdis_tmr;
  6671. + void *b_ase0_brst_tmr;
  6672. + void *b_se0_srp_tmr;
  6673. + void *b_srp_fail_tmr;
  6674. + void *a_wait_enum_tmr;
  6675. +
  6676. + /* Current usb protocol used: 0:undefine; 1:host; 2:client */
  6677. + int protocol;
  6678. + spinlock_t lock; /* fsm lock */
  6679. +};
  6680. +
  6681. +struct otg_fsm_ops {
  6682. + void (*chrg_vbus)(int on);
  6683. + void (*drv_vbus)(int on);
  6684. + void (*loc_conn)(int on);
  6685. + void (*loc_sof)(int on);
  6686. + void (*start_pulse)(void);
  6687. + void (*add_timer)(void *timer);
  6688. + void (*del_timer)(void *timer);
  6689. + int (*start_host)(struct otg_fsm *fsm, int on);
  6690. + int (*start_gadget)(struct otg_fsm *fsm, int on);
  6691. +};
  6692. +
  6693. +
  6694. +static inline void otg_chrg_vbus(struct otg_fsm *fsm, int on)
  6695. +{
  6696. + fsm->ops->chrg_vbus(on);
  6697. +}
  6698. +
  6699. +static inline void otg_drv_vbus(struct otg_fsm *fsm, int on)
  6700. +{
  6701. + if (fsm->drv_vbus != on) {
  6702. + fsm->drv_vbus = on;
  6703. + fsm->ops->drv_vbus(on);
  6704. + }
  6705. +}
  6706. +
  6707. +static inline void otg_loc_conn(struct otg_fsm *fsm, int on)
  6708. +{
  6709. + if (fsm->loc_conn != on) {
  6710. + fsm->loc_conn = on;
  6711. + fsm->ops->loc_conn(on);
  6712. + }
  6713. +}
  6714. +
  6715. +static inline void otg_loc_sof(struct otg_fsm *fsm, int on)
  6716. +{
  6717. + if (fsm->loc_sof != on) {
  6718. + fsm->loc_sof = on;
  6719. + fsm->ops->loc_sof(on);
  6720. + }
  6721. +}
  6722. +
  6723. +static inline void otg_start_pulse(struct otg_fsm *fsm)
  6724. +{
  6725. + fsm->ops->start_pulse();
  6726. +}
  6727. +
  6728. +static inline void otg_add_timer(struct otg_fsm *fsm, void *timer)
  6729. +{
  6730. + fsm->ops->add_timer(timer);
  6731. +}
  6732. +
  6733. +static inline void otg_del_timer(struct otg_fsm *fsm, void *timer)
  6734. +{
  6735. + fsm->ops->del_timer(timer);
  6736. +}
  6737. +
  6738. +extern int otg_statemachine(struct otg_fsm *fsm);
  6739. +
  6740. +extern const char *state_string(enum usb_otg_state state);
  6741. +
  6742. +#endif
  6743. --- a/include/asm-m68k/mcf5445x_usb.h
  6744. +++ b/include/asm-m68k/mcf5445x_usb.h
  6745. @@ -41,7 +41,8 @@ static inline void fsl_platform_set_host
  6746. /* set host mode and select "big endian" */
  6747. temp = fsl_readl(&regs->usbmode);
  6748. - fsl_writel(temp | USBMODE_CM_HOST | USBMODE_ES, &regs->usbmode);
  6749. + temp |= USBMODE_CM_HOST | (pdata->es ? USBMODE_ES : 0);
  6750. + fsl_writel(temp, &regs->usbmode);
  6751. pr_debug("%s: set usbmode to 0x%x\n\n", __FUNCTION__,
  6752. fsl_readl(&regs->usbmode));
  6753. --- a/include/linux/fsl_devices.h
  6754. +++ b/include/linux/fsl_devices.h
  6755. @@ -91,6 +91,19 @@ enum fsl_usb2_operating_modes {
  6756. FSL_USB2_DR_OTG,
  6757. };
  6758. +/* DDD
  6759. + * replace _operating_modes with _controller
  6760. + *
  6761. + * the operating_mode tests in fsl_platform_verify() aren't needed,
  6762. + * since the ehci driver isn't going to be probe()d unless it's
  6763. + * "fsl-ehci" device anyway, and what we really need to know is
  6764. + * which controller (MPH/DR) we're dealing with
  6765. + */
  6766. +enum fsl_usb2_controller {
  6767. + FSL_USB2_MPH,
  6768. + FSL_USB2_DR,
  6769. +};
  6770. +
  6771. enum fsl_usb2_phy_modes {
  6772. FSL_USB2_PHY_NONE,
  6773. FSL_USB2_PHY_ULPI,
  6774. @@ -101,9 +114,36 @@ enum fsl_usb2_phy_modes {
  6775. struct fsl_usb2_platform_data {
  6776. /* board specific information */
  6777. - enum fsl_usb2_operating_modes operating_mode;
  6778. + /*
  6779. + * DDD see note above
  6780. + * enum fsl_usb2_operating_modes operating_mode;
  6781. + */
  6782. + enum fsl_usb2_controller controller;
  6783. enum fsl_usb2_phy_modes phy_mode;
  6784. unsigned int port_enables;
  6785. + /*
  6786. + * DDD this could arguably be moved to a separate
  6787. + * fsl usb2 device header file
  6788. + */
  6789. + char *name; /* pretty print */
  6790. + int (*platform_init) (struct platform_device *);
  6791. + void (*platform_uninit) (struct platform_device *);
  6792. + int (*platform_verify) (struct platform_device *);
  6793. + u32 xcvr_type; /* PORTSCX_PTS_* */
  6794. + u32 view; /* ULPI viewport register */
  6795. + u32 r_start; /* start of MEM resource */
  6796. + u32 r_len; /* length of MEM resource */
  6797. + void __iomem *regs; /* ioremap'd register base */
  6798. + unsigned big_endian_mmio : 1;
  6799. + unsigned big_endian_desc : 1;
  6800. + unsigned es : 1; /* need USBMODE:ES */
  6801. + unsigned have_sysif_regs : 1;
  6802. + unsigned le_setup_buf : 1;
  6803. + unsigned does_otg : 1; /* set IFF it's an OTG port */
  6804. +
  6805. + unsigned power_budget; /* for hcd->power_budget */
  6806. + struct fsl_xcvr_ops *xcvr_ops;
  6807. + int max_ep_nr; /* max # of endpoints */
  6808. };
  6809. /* Flags in fsl_usb2_mph_platform_data */
  6810. --- /dev/null
  6811. +++ b/include/linux/usb/fsl_usb2.h
  6812. @@ -0,0 +1,464 @@
  6813. +/*
  6814. + * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  6815. + */
  6816. +
  6817. +/*
  6818. + * The code contained herein is licensed under the GNU General Public
  6819. + * License. You may obtain a copy of the GNU General Public License
  6820. + * Version 2 or later at the following locations:
  6821. + *
  6822. + * http://www.opensource.org/licenses/gpl-license.html
  6823. + * http://www.gnu.org/copyleft/gpl.html
  6824. + */
  6825. +
  6826. +/*
  6827. + * Freescale USB device/endpoint management registers
  6828. + */
  6829. +#ifndef __FSL_USB2_H
  6830. +#define __FSL_USB2_H
  6831. +
  6832. +
  6833. + /* USB DR device mode registers (Little Endian) */
  6834. +struct fsl_usb_device_regs {
  6835. + /* Capability register */
  6836. + u32 id;
  6837. + u32 res1[63];
  6838. + u16 caplength; /* Capability Register Length */
  6839. + u16 hciversion; /* Host Controller Interface Version */
  6840. + u32 hcsparams; /* Host Controller Structual Parameters */
  6841. + u32 hccparams; /* Host Controller Capability Parameters */
  6842. + u32 res2[5];
  6843. + u32 dciversion; /* Device Controller Interface Version */
  6844. + u32 dccparams; /* Device Controller Capability Parameters */
  6845. + u32 res3[6];
  6846. + /* Operation register */
  6847. + u32 usbcmd; /* USB Command Register */
  6848. + u32 usbsts; /* USB Status Register */
  6849. + u32 usbintr; /* USB Interrupt Enable Register */
  6850. + u32 frindex; /* Frame Index Register */
  6851. + u32 res4;
  6852. + u32 deviceaddr; /* Device Address */
  6853. + u32 endpointlistaddr; /* Endpoint List Address Register */
  6854. + u32 res5;
  6855. + u32 burstsize; /* Master Interface Data Burst Size Register */
  6856. + u32 txttfilltuning; /* Transmit FIFO Tuning Controls Register */
  6857. + u32 res6[2];
  6858. + u32 ulpiview;
  6859. + u32 res7[3];
  6860. + u32 configflag; /* Configure Flag Register */
  6861. + u32 portsc1; /* Port 1 Status and Control Register */
  6862. + u32 res8[7];
  6863. + u32 otgsc; /* On-The-Go Status and Control */
  6864. + u32 usbmode; /* USB Mode Register */
  6865. + u32 endptsetupstat; /* Endpoint Setup Status Register */
  6866. + u32 endpointprime; /* Endpoint Initialization Register */
  6867. + u32 endptflush; /* Endpoint Flush Register */
  6868. + u32 endptstatus; /* Endpoint Status Register */
  6869. + u32 endptcomplete; /* Endpoint Complete Register */
  6870. +#if 0
  6871. + u32 endptctrl[USB_MAX_ENDPOINTS]; /* Endpoint Control Registers */
  6872. +#else
  6873. + // DDD see DCCPARAMS:DEN for the real number of device endpoints
  6874. + // DDD 16 is the max
  6875. + u32 endptctrl[16]; /* Endpoint Control Registers */
  6876. +#endif
  6877. +};
  6878. +
  6879. + /* USB DR host mode registers (Little Endian) */
  6880. +struct fsl_usb_host_regs {
  6881. + /* Capability register */
  6882. + u32 id;
  6883. + u32 res1[63];
  6884. + u16 caplength; /* Capability Register Length */
  6885. + u16 hciversion; /* Host Controller Interface Version */
  6886. + u32 hcsparams; /* Host Controller Structual Parameters */
  6887. + u32 hccparams; /* Host Controller Capability Parameters */
  6888. + u32 res2[5];
  6889. + u32 dciversion; /* Device Controller Interface Version */
  6890. + u32 dccparams; /* Device Controller Capability Parameters */
  6891. + u32 res3[6];
  6892. + /* Operation register */
  6893. + u32 usbcmd; /* USB Command Register */
  6894. + u32 usbsts; /* USB Status Register */
  6895. + u32 usbintr; /* USB Interrupt Enable Register */
  6896. + u32 frindex; /* Frame Index Register */
  6897. + u32 res4;
  6898. + u32 periodiclistbase; /* Periodic Frame List Base Address Register */
  6899. + u32 asynclistaddr; /* Current Asynchronous List Address Register */
  6900. + u32 res5;
  6901. + u32 burstsize; /* Master Interface Data Burst Size Register */
  6902. + u32 txttfilltuning; /* Transmit FIFO Tuning Controls Register */
  6903. + u32 res6[2];
  6904. + u32 ulpiview;
  6905. + u32 res7[3];
  6906. + u32 configflag; /* Configure Flag Register */
  6907. + u32 portsc1; /* Port 1 Status and Control Register */
  6908. + u32 res8[7];
  6909. + u32 otgsc; /* On-The-Go Status and Control */
  6910. + u32 usbmode; /* USB Mode Register */
  6911. + u32 endptsetupstat; /* Endpoint Setup Status Register */
  6912. + u32 endpointprime; /* Endpoint Initialization Register */
  6913. + u32 endptflush; /* Endpoint Flush Register */
  6914. + u32 endptstatus; /* Endpoint Status Register */
  6915. + u32 endptcomplete; /* Endpoint Complete Register */
  6916. +#if 0
  6917. + u32 endptctrl[USB_MAX_ENDPOINTS]; /* Endpoint Control Registers */
  6918. +#else
  6919. + // DDD: do these exits in the host register set??
  6920. + // DDD see DCCPARAMS:DEN for the real number of device endpoints
  6921. + // DDD 16 is the max
  6922. + u32 endptctrl[16]; /* Endpoint Control Registers */
  6923. +#endif
  6924. +};
  6925. +
  6926. + /* non-EHCI USB system interface registers (Big Endian) */
  6927. +struct usb_sys_interface {
  6928. + u32 snoop1;
  6929. + u32 snoop2;
  6930. + u32 age_cnt_thresh; /* Age Count Threshold Register */
  6931. + u32 pri_ctrl; /* Priority Control Register */
  6932. + u32 si_ctrl; /* System Interface Control Register */
  6933. + u32 res[59];
  6934. + u32 control; /* General Purpose Control Register */
  6935. +};
  6936. +
  6937. +/* ep0 transfer state */
  6938. +#define WAIT_FOR_SETUP 0
  6939. +#define DATA_STATE_XMIT 1
  6940. +#define DATA_STATE_NEED_ZLP 2
  6941. +#define WAIT_FOR_OUT_STATUS 3
  6942. +#define DATA_STATE_RECV 4
  6943. +
  6944. +/* Frame Index Register Bit Masks */
  6945. +#define USB_FRINDEX_MASKS 0x3fff
  6946. +
  6947. +
  6948. +
  6949. +/* USBCMD Register Bit Masks */
  6950. +#define USB_CMD_RUN_STOP 0x00000001
  6951. +#define USB_CMD_CTRL_RESET 0x00000002
  6952. +#define USB_CMD_PERIODIC_SCHEDULE_EN 0x00000010
  6953. +#define USB_CMD_ASYNC_SCHEDULE_EN 0x00000020
  6954. +#define USB_CMD_INT_AA_DOORBELL 0x00000040
  6955. +#define USB_CMD_ASP 0x00000300
  6956. +#define USB_CMD_ASYNC_SCH_PARK_EN 0x00000800
  6957. +#define USB_CMD_SUTW 0x00002000
  6958. +#define USB_CMD_ATDTW 0x00004000
  6959. +#define USB_CMD_ITC 0x00FF0000
  6960. +
  6961. +/* bit 15,3,2 are frame list size */
  6962. +#define USB_CMD_FRAME_SIZE_1024 0x00000000
  6963. +#define USB_CMD_FRAME_SIZE_512 0x00000004
  6964. +#define USB_CMD_FRAME_SIZE_256 0x00000008
  6965. +#define USB_CMD_FRAME_SIZE_128 0x0000000C
  6966. +#define USB_CMD_FRAME_SIZE_64 0x00008000
  6967. +#define USB_CMD_FRAME_SIZE_32 0x00008004
  6968. +#define USB_CMD_FRAME_SIZE_16 0x00008008
  6969. +#define USB_CMD_FRAME_SIZE_8 0x0000800C
  6970. +
  6971. +/* bit 9-8 are async schedule park mode count */
  6972. +#define USB_CMD_ASP_00 0x00000000
  6973. +#define USB_CMD_ASP_01 0x00000100
  6974. +#define USB_CMD_ASP_10 0x00000200
  6975. +#define USB_CMD_ASP_11 0x00000300
  6976. +#define USB_CMD_ASP_BIT_POS 8
  6977. +
  6978. +/* bit 23-16 are interrupt threshold control */
  6979. +#define USB_CMD_ITC_NO_THRESHOLD 0x00000000
  6980. +#define USB_CMD_ITC_1_MICRO_FRM 0x00010000
  6981. +#define USB_CMD_ITC_2_MICRO_FRM 0x00020000
  6982. +#define USB_CMD_ITC_4_MICRO_FRM 0x00040000
  6983. +#define USB_CMD_ITC_8_MICRO_FRM 0x00080000
  6984. +#define USB_CMD_ITC_16_MICRO_FRM 0x00100000
  6985. +#define USB_CMD_ITC_32_MICRO_FRM 0x00200000
  6986. +#define USB_CMD_ITC_64_MICRO_FRM 0x00400000
  6987. +#define USB_CMD_ITC_BIT_POS 16
  6988. +
  6989. +
  6990. +
  6991. +
  6992. +/* USB STS Register Bit Masks */
  6993. +#define USB_STS_INT 0x00000001
  6994. +#define USB_STS_ERR 0x00000002
  6995. +#define USB_STS_PORT_CHANGE 0x00000004
  6996. +#define USB_STS_FRM_LST_ROLL 0x00000008
  6997. +#define USB_STS_SYS_ERR 0x00000010
  6998. +#define USB_STS_IAA 0x00000020
  6999. +#define USB_STS_RESET 0x00000040
  7000. +#define USB_STS_SOF 0x00000080
  7001. +#define USB_STS_SUSPEND 0x00000100
  7002. +#define USB_STS_HC_HALTED 0x00001000
  7003. +#define USB_STS_RCL 0x00002000
  7004. +#define USB_STS_PERIODIC_SCHEDULE 0x00004000
  7005. +#define USB_STS_ASYNC_SCHEDULE 0x00008000
  7006. +
  7007. +/* USB INTR Register Bit Masks */
  7008. +#define USB_INTR_INT_EN 0x00000001
  7009. +#define USB_INTR_ERR_INT_EN 0x00000002
  7010. +#define USB_INTR_PTC_DETECT_EN 0x00000004
  7011. +#define USB_INTR_FRM_LST_ROLL_EN 0x00000008
  7012. +#define USB_INTR_SYS_ERR_EN 0x00000010
  7013. +#define USB_INTR_ASYN_ADV_EN 0x00000020
  7014. +#define USB_INTR_RESET_EN 0x00000040
  7015. +#define USB_INTR_SOF_EN 0x00000080
  7016. +#define USB_INTR_DEVICE_SUSPEND 0x00000100
  7017. +
  7018. +/* Device Address bit masks */
  7019. +#define USB_DEVICE_ADDRESS_MASK 0xFE000000
  7020. +#define USB_DEVICE_ADDRESS_BIT_POS 25
  7021. +
  7022. +/* endpoint list address bit masks */
  7023. +#define USB_EP_LIST_ADDRESS_MASK 0xfffff800
  7024. +
  7025. +
  7026. +/* x_PORTSCx */
  7027. +/* bit 31-30 are port transceiver select */
  7028. +#define PORTSCX_PTS_MASK (3 << 30) /* parallel xcvr select mask */
  7029. +#define PORTSCX_PHY_TYPE_SEL PORTSCX_PTS_MASK
  7030. +#define PORTSCX_PTS_UTMI (0 << 30) /* UTMI/UTMI+ */
  7031. +#define PORTSCX_PTS_PHILIPS (1 << 30) /* Philips classic */
  7032. +#define PORTSCX_PTS_ULPI (2 << 30) /* ULPI */
  7033. +#define PORTSCX_PTS_SERIAL (3 << 30) /* serial */
  7034. +#define PORTSCX_PTS_FSLS PORTSCX_PTS_SERIAL
  7035. +#define PORTSCX_PTS_ONCHIP PORTSCX_PTS_FSLS
  7036. +
  7037. +#define PORTSCX_STS (1 << 29) /* serial xcvr select */
  7038. +
  7039. +/* bit 28 is parallel transceiver width for UTMI interface */
  7040. +#define PORTSCX_PTW_8BIT (0 << 28) /* 8 bit parallel xcvr */
  7041. +#define PORTSCX_PTW_16BIT (1 << 28) /* 16 bi parallel xcvr */
  7042. +
  7043. +/* bit 27-26 are port speed */
  7044. +#define PORTSCX_PORT_SPEED_FULL (0 << 26)
  7045. +#define PORTSCX_PORT_SPEED_LOW (1 << 26)
  7046. +#define PORTSCX_PORT_SPEED_HIGH (2 << 26)
  7047. +#define PORTSCX_PORT_SPEED_UNDEF (3 << 26)
  7048. +#define PORTSCX_PORT_SPEED_MASK (3 << 26)
  7049. +
  7050. +#define PORTSCX_PHY_LOW_POWER_SPD (1 << 23) /* phy low pwr suspend/clk disable */
  7051. +
  7052. +/* bit 19-16 are port test control */
  7053. +#define PORTSCX_PTC_DISABLE (0 << 16)
  7054. +#define PORTSCX_PTC_JSTATE (1 << 16)
  7055. +#define PORTSCX_PTC_KSTATE (2 << 16)
  7056. +#define PORTSCX_PTC_SEQNAK (3 << 16) /* SE0 (host) / NAK (device) */
  7057. +#define PORTSCX_PTC_PACKET (4 << 16)
  7058. +#define PORTSCX_PTC_FORCE_EN_HS (5 << 16)
  7059. +#define PORTSCX_PTC_FORCE_EN_FS (6 << 16)
  7060. +#define PORTSCX_PTC_FORCE_EN_LS (7 << 16)
  7061. +
  7062. +
  7063. +/* bit 15-14 are port indicator control */
  7064. +#define PORTSCX_PIC_OFF (0 << 14)
  7065. +#define PORTSCX_PIC_AMBER (1 << 14)
  7066. +#define PORTSCX_PIC_GREEN (2 << 14)
  7067. +#define PORTSCX_PIC_UNDEF (3 << 14)
  7068. +
  7069. +#define PORTSCX_PORT_POWER (1 << 12) /* port power */
  7070. +
  7071. +/* bit 11-10 are line status */
  7072. +#define PORTSCX_LS_MASK (3 << 10) /* Line State mask */
  7073. +#define PORTSCX_LS_SE0 (0 << 10) /* SE0 */
  7074. +#define PORTSCX_LS_K_STATE (1 << 10) /* K-state */
  7075. +#define PORTSCX_LS_J_STATE (2 << 10) /* J-state */
  7076. +
  7077. +#define PORTSCX_PORT_RESET (1 << 8) /* Port reset */
  7078. +#define PORTSCX_PORT_SUSPEND (1 << 7) /* Suspend */
  7079. +#define PORTSCX_PORT_FORCE_RESUME (1 << 6) /* Force port resume */
  7080. +#define PORTSCX_OVER_CURRENT_CHG (1 << 5) /* over current change */
  7081. +#define PORTSCX_OVER_CURRENT_ACT (1 << 4) /* over currrent active */
  7082. +#define PORTSCX_PORT_EN_DIS_CHANGE (1 << 3) /* port {en,dis}able change */
  7083. +#define PORTSCX_PORT_ENABLE (1 << 2) /* port enabled */
  7084. +#define PORTSCX_CONNECT_STATUS_CHANGE (1 << 1) /* connect status change */
  7085. +#define PORTSCX_CURRENT_CONNECT_STATUS (1 << 0) /* current connect status */
  7086. +
  7087. +#define PORTSCX_W1C_BITS \
  7088. + ( PORTSCX_CONNECT_STATUS_CHANGE | \
  7089. + PORTSCX_PORT_EN_DIS_CHANGE | \
  7090. + PORTSCX_OVER_CURRENT_CHG )
  7091. +
  7092. +
  7093. +
  7094. +/* UOG_OTGSC Register Bits */
  7095. +/* control bits: */
  7096. +#define OTGSC_CTRL_VBUS_DISCHARGE (1 << 0)
  7097. +#define OTGSC_CTRL_VBUS_CHARGE (1 << 1)
  7098. +#define OTGSC_CTRL_OTG_TERM (1 << 3) /* controls DM pulldown */
  7099. +#define OTGSC_CTRL_DATA_PULSING (1 << 4)
  7100. +#define OTGSC_CTRL_USB_ID_PU (1 << 5) /* enable ID pullup */
  7101. +/* current status: (R/O) */
  7102. +#define OTGSC_STS_USB_ID (1 << 8) /* 0=A-device 1=B-device */
  7103. +#define OTGSC_STS_A_VBUS_VALID (1 << 9)
  7104. +#define OTGSC_STS_A_SESSION_VALID (1 << 10)
  7105. +#define OTGSC_STS_B_SESSION_VALID (1 << 11)
  7106. +#define OTGSC_STS_B_SESSION_END (1 << 12)
  7107. +#define OTGSC_STS_1ms_TIMER (1 << 13)
  7108. +#define OTGSC_STS_DATA_PULSE (1 << 14)
  7109. +/* interrupt status: (write to clear) */
  7110. +#define OTGSC_INTSTS_MASK (0x7f << 16)
  7111. +#define OTGSC_INTSTS_USB_ID (1 << 16)
  7112. +#define OTGSC_INTSTS_A_VBUS_VALID (1 << 17)
  7113. +#define OTGSC_INTSTS_A_SESSION_VALID (1 << 18)
  7114. +#define OTGSC_INTSTS_B_SESSION_VALID (1 << 19)
  7115. +#define OTGSC_INTSTS_B_SESSION_END (1 << 20)
  7116. +#define OTGSC_INTSTS_1MS_TIMER (1 << 21)
  7117. +#define OTGSC_INTSTS_DATA_PULSE (1 << 22)
  7118. +/* interrupt enables: */
  7119. +#define OTGSC_IE_MASK (0x7f << 24)
  7120. +#define OTGSC_IE_USB_ID (1 << 24)
  7121. +#define OTGSC_IE_A_VBUS_VALID (1 << 25)
  7122. +#define OTGSC_IE_A_SESSION_VALID (1 << 26)
  7123. +#define OTGSC_IE_B_SESSION_VALID (1 << 27)
  7124. +#define OTGSC_IE_B_SESSION_END (1 << 28)
  7125. +#define OTGSC_IE_1ms_TIMER (1 << 29)
  7126. +#define OTGSC_IE_DATA_PULSE (1 << 30)
  7127. +
  7128. +#if 1 /* DDD FIXME these here for compatibility between my names and Leo's */
  7129. +/* OTG interrupt enable bit masks */
  7130. +#define OTGSC_INTERRUPT_ENABLE_BITS_MASK OTGSC_IE_MASK
  7131. +
  7132. +/* OTG interrupt status bit masks */
  7133. +#define OTGSC_INTERRUPT_STATUS_BITS_MASK OTGSC_INTSTS_MASK
  7134. +#endif // 1
  7135. +
  7136. +
  7137. +
  7138. +/* x_USBMODE */
  7139. +#undef USBMODE_SDIS /* defined as bit 3 in drivers/usb/host/ehci.h */
  7140. +#define USBMODE_SDIS (1 << 4) /* stream disable mode */
  7141. +#define USBMODE_SLOM (1 << 3) /* setup lockout mode */
  7142. +#define USBMODE_ES (1 << 2) /* (big) endian select */
  7143. +#define USBMODE_CM_MASK (3 << 0) /* controller mode mask */
  7144. +#define USBMODE_CM_HOST (3 << 0) /* host */
  7145. +#define USBMODE_CM_DEVICE (2 << 0) /* device */
  7146. +// DDD #define USBMODE_CM_IDLE (0 << 0) /* idle */
  7147. +
  7148. +/* DDD for compatibility for now */
  7149. +#define USB_MODE_CTRL_MODE_IDLE USBMODE_CM_IDLE
  7150. +#define USB_MODE_CTRL_MODE_DEVICE USBMODE_CM_DEVICE
  7151. +#define USB_MODE_CTRL_MODE_HOST USBMODE_CM_HOST
  7152. +#define USB_MODE_SETUP_LOCK_OFF USBMODE_SLOM
  7153. +#define USB_MODE_STREAM_DISABLE USBMODE_SDIS
  7154. +
  7155. +
  7156. +/* ULPIVIEW register bits */
  7157. +#define ULPIVW_WU (1 << 31) /* Wakeup */
  7158. +#define ULPIVW_RUN (1 << 30) /* read/write run */
  7159. +#define ULPIVW_WRITE (1 << 29) /* 0=read 1=write */
  7160. +#define ULPIVW_SS (1 << 27) /* SyncState */
  7161. +#define ULPIVW_PORT_MASK 0x07 /* Port field */
  7162. +#define ULPIVW_PORT_SHIFT 24
  7163. +#define ULPIVW_ADDR_MASK 0xFF /* data address field */
  7164. +#define ULPIVW_ADDR_SHIFT 16
  7165. +#define ULPIVW_RDATA_MASK 0xFF /* read data field */
  7166. +#define ULPIVW_RDATA_SHIFT 8
  7167. +#define ULPIVW_WDATA_MASK 0xFF /* write data field */
  7168. +#define ULPIVW_WDATA_SHIFT 0
  7169. +
  7170. +
  7171. +/* Endpoint Flush Register */
  7172. +#define EPFLUSH_TX_OFFSET 0x00010000
  7173. +#define EPFLUSH_RX_OFFSET 0x00000000
  7174. +
  7175. +/* Endpoint Setup Status bit masks */
  7176. +#define EP_SETUP_STATUS_MASK 0x0000003F
  7177. +#define EP_SETUP_STATUS_EP0 0x00000001
  7178. +
  7179. +/* ENDPOINTCTRLx Register Bit Masks */
  7180. +#define EPCTRL_TX_ENABLE 0x00800000
  7181. +#define EPCTRL_TX_DATA_TOGGLE_RST 0x00400000 /* Not EP0 */
  7182. +#define EPCTRL_TX_DATA_TOGGLE_INH 0x00200000 /* Not EP0 */
  7183. +#define EPCTRL_TX_TYPE 0x000C0000
  7184. +#define EPCTRL_TX_DATA_SOURCE 0x00020000 /* Not EP0 */
  7185. +#define EPCTRL_TX_EP_STALL 0x00010000
  7186. +#define EPCTRL_RX_ENABLE 0x00000080
  7187. +#define EPCTRL_RX_DATA_TOGGLE_RST 0x00000040 /* Not EP0 */
  7188. +#define EPCTRL_RX_DATA_TOGGLE_INH 0x00000020 /* Not EP0 */
  7189. +#define EPCTRL_RX_TYPE 0x0000000C
  7190. +#define EPCTRL_RX_DATA_SINK 0x00000002 /* Not EP0 */
  7191. +#define EPCTRL_RX_EP_STALL 0x00000001
  7192. +
  7193. +/* bit 19-18 and 3-2 are endpoint type */
  7194. +#define EPCTRL_EP_TYPE_CONTROL 0
  7195. +#define EPCTRL_EP_TYPE_ISO 1
  7196. +#define EPCTRL_EP_TYPE_BULK 2
  7197. +#define EPCTRL_EP_TYPE_INTERRUPT 3
  7198. +#define EPCTRL_TX_EP_TYPE_SHIFT 18
  7199. +#define EPCTRL_RX_EP_TYPE_SHIFT 2
  7200. +
  7201. +/* SNOOPn Register Bit Masks */
  7202. +#define SNOOP_ADDRESS_MASK 0xFFFFF000
  7203. +#define SNOOP_SIZE_ZERO 0x00 /* snooping disable */
  7204. +#define SNOOP_SIZE_4KB 0x0B /* 4KB snoop size */
  7205. +#define SNOOP_SIZE_8KB 0x0C
  7206. +#define SNOOP_SIZE_16KB 0x0D
  7207. +#define SNOOP_SIZE_32KB 0x0E
  7208. +#define SNOOP_SIZE_64KB 0x0F
  7209. +#define SNOOP_SIZE_128KB 0x10
  7210. +#define SNOOP_SIZE_256KB 0x11
  7211. +#define SNOOP_SIZE_512KB 0x12
  7212. +#define SNOOP_SIZE_1MB 0x13
  7213. +#define SNOOP_SIZE_2MB 0x14
  7214. +#define SNOOP_SIZE_4MB 0x15
  7215. +#define SNOOP_SIZE_8MB 0x16
  7216. +#define SNOOP_SIZE_16MB 0x17
  7217. +#define SNOOP_SIZE_32MB 0x18
  7218. +#define SNOOP_SIZE_64MB 0x19
  7219. +#define SNOOP_SIZE_128MB 0x1A
  7220. +#define SNOOP_SIZE_256MB 0x1B
  7221. +#define SNOOP_SIZE_512MB 0x1C
  7222. +#define SNOOP_SIZE_1GB 0x1D
  7223. +#define SNOOP_SIZE_2GB 0x1E /* 2GB snoop size */
  7224. +
  7225. +/* pri_ctrl Register Bit Masks */
  7226. +#define PRI_CTRL_PRI_LVL1 0x0000000C
  7227. +#define PRI_CTRL_PRI_LVL0 0x00000003
  7228. +
  7229. +/* si_ctrl Register Bit Masks */
  7230. +#define SI_CTRL_ERR_DISABLE 0x00000010
  7231. +#define SI_CTRL_IDRC_DISABLE 0x00000008
  7232. +#define SI_CTRL_RD_SAFE_EN 0x00000004
  7233. +#define SI_CTRL_RD_PREFETCH_DISABLE 0x00000002
  7234. +#define SI_CTRL_RD_PREFEFETCH_VAL 0x00000001
  7235. +
  7236. +
  7237. +/* control Register Bit Masks */
  7238. +#define USB_CTRL_IOENB 0x00000004
  7239. +#define USB_CTRL_ULPI_INT0EN 0x00000001
  7240. +
  7241. +
  7242. +/* Endpoint Transfer Descriptor bit Masks */
  7243. +#define DTD_NEXT_TERMINATE 0x00000001
  7244. +#define DTD_IOC 0x00008000
  7245. +#define DTD_STATUS_ACTIVE 0x00000080
  7246. +#define DTD_STATUS_HALTED 0x00000040
  7247. +#define DTD_STATUS_DATA_BUFF_ERR 0x00000020
  7248. +#define DTD_STATUS_TRANSACTION_ERR 0x00000008
  7249. +#define DTD_RESERVED_FIELDS 0x80007300
  7250. +#define DTD_ADDR_MASK 0xFFFFFFE0
  7251. +#define DTD_PACKET_SIZE 0x7FFF0000
  7252. +#define DTD_LENGTH_BIT_POS 16
  7253. +#define DTD_ERROR_MASK (DTD_STATUS_HALTED | \
  7254. + DTD_STATUS_DATA_BUFF_ERR | \
  7255. + DTD_STATUS_TRANSACTION_ERR)
  7256. +/* Alignment requirements; must be a power of two */
  7257. +#define DTD_ALIGNMENT 0x20
  7258. +#define QH_ALIGNMENT 2048
  7259. +
  7260. +/* Controller dma boundary */
  7261. +#define UDC_DMA_BOUNDARY 0x1000
  7262. +
  7263. +#if defined CONFIG_PPC32
  7264. +#define fsl_readl(addr) in_le32((addr))
  7265. +#define fsl_writel(addr, val32) out_le32((addr), (val32))
  7266. +#elif defined CONFIG_COLDFIRE
  7267. +#define fsl_readl(addr) in_be32((__force unsigned *)(addr))
  7268. +#define fsl_writel(val32, addr) out_be32((__force unsigned *)(addr), (val32))
  7269. +
  7270. +#define fsl_readw(addr) in_be16((__force unsigned *)(addr))
  7271. +#define fsl_writew(val16, addr) out_be16((__force unsigned *)(addr), (val16))
  7272. +#else
  7273. +#error fsl_{readl, writel} must be defined
  7274. +#endif
  7275. +
  7276. +#endif /* __FSL_USB2_H */
  7277. --- /dev/null
  7278. +++ b/include/linux/usb/fsl_xcvr.h
  7279. @@ -0,0 +1,42 @@
  7280. +/*
  7281. + * Copyright 2007 Freescale Semiconductor, Inc. All Rights Reserved.
  7282. + */
  7283. +
  7284. +/*
  7285. + * The code contained herein is licensed under the GNU General Public
  7286. + * License. You may obtain a copy of the GNU General Public License
  7287. + * Version 2 or later at the following locations:
  7288. + *
  7289. + * http://www.opensource.org/licenses/gpl-license.html
  7290. + * http://www.gnu.org/copyleft/gpl.html
  7291. + */
  7292. +
  7293. +enum fsl_usb_ctrlr {
  7294. + USB_CTRLR_H1 = 0,
  7295. + USB_CTRLR_H2 = 1,
  7296. + USB_CTRLR_OTG = 2,
  7297. +};
  7298. +
  7299. +
  7300. +/**
  7301. + * struct fsl_xcvr_ops - USB transceiver operations
  7302. + *
  7303. + * @xcvr_type: one of PORTSCX_PTS_{UTMI,SERIAL,ULPI}
  7304. + * @init: transceiver- and board-specific initialization function
  7305. + * @uninit: transceiver- and board-specific uninitialization function
  7306. + * @set_host:
  7307. + * @set_device:
  7308. + *
  7309. + */
  7310. +struct fsl_xcvr_ops {
  7311. + enum fsl_usb_ctrlr ctrlr; /* H1, H2, OTG */
  7312. + u32 xcvr_type;
  7313. +
  7314. + void (*init)(struct platform_device *pdev);
  7315. + void (*uninit)(struct platform_device *pdev);
  7316. + void (*set_host)(void); /* DDD combine set_host and _device ? */
  7317. + void (*set_device)(void);
  7318. + void (*set_vbus_power)(struct fsl_usb2_platform_data *pdata, int on);
  7319. +};
  7320. +
  7321. +