| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703 |
- /*
- * hcd.c - DesignWare HS OTG Controller host-mode routines
- *
- * Copyright (C) 2004-2013 Synopsys, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions, and the following disclaimer,
- * without modification.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The names of the above-listed copyright holders may not be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * ALTERNATIVELY, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any
- * later version.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- /*
- * This file contains the core HCD code, and implements the Linux hc_driver
- * API
- */
- #include "usb_os_adapter.h"
- #include "trace.h"
- #include <asm/dma-mapping.h>
- #include <linux/usb/ch9.h>
- #include <linux/usb/gadget.h>
- #include "cp15.h"
- #include "core.h"
- #include "hcd.h"
- int usb_urb_dir_in(struct urb *urb)
- {
- return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_IN;
- }
- static void dwc2_port_resume(struct dwc2_hsotg *hsotg);
- /*
- * =========================================================================
- * Host Core Layer Functions
- * =========================================================================
- */
- /**
- * dwc2_enable_common_interrupts() - Initializes the commmon interrupts,
- * used in both device and host modes
- *
- * @hsotg: Programming view of the DWC_otg controller
- */
- static void dwc2_enable_common_interrupts(struct dwc2_hsotg *hsotg)
- {
- u32 intmsk;
- /* Clear any pending OTG Interrupts */
- dwc2_writel(0xffffffff, hsotg->regs + GOTGINT);
- /* Clear any pending interrupts */
- dwc2_writel(0xffffffff, hsotg->regs + GINTSTS);
- /* Enable the interrupts in the GINTMSK */
- intmsk = GINTSTS_MODEMIS | GINTSTS_OTGINT;
- intmsk |= GINTSTS_RXFLVL;
- intmsk |= GINTSTS_CONIDSTSCHNG;
- intmsk |= GINTSTS_WKUPINT | GINTSTS_USBSUSP |
- GINTSTS_SESSREQINT;
- dwc2_writel(intmsk, hsotg->regs + GINTMSK);
- }
- /*
- * Initializes the FSLSPClkSel field of the HCFG register depending on the
- * PHY type
- */
- static void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg)
- {
- u32 hcfg, val;
- /* High speed PHY running at full speed or high speed */
- val = HCFG_FSLSPCLKSEL_30_60_MHZ;
- dev_dbg(hsotg->dev, "Initializing HCFG.FSLSPClkSel to %08x\n", val);
- hcfg = dwc2_readl(hsotg->regs + HCFG);
- hcfg &= ~HCFG_FSLSPCLKSEL_MASK;
- hcfg |= val << HCFG_FSLSPCLKSEL_SHIFT;
- dwc2_writel(hcfg, hsotg->regs + HCFG);
- }
- static int dwc2_fs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
- {
- u32 usbcfg, ggpio;
- int retval = 0;
- /*
- * core_init() is now called on every switch so only call the
- * following for the first time through
- */
- if (select_phy) {
- dev_dbg(hsotg->dev, "FS PHY selected\n");
- usbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
- if (!(usbcfg & GUSBCFG_PHYSEL)) {
- usbcfg |= GUSBCFG_PHYSEL;
- dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
- /* Reset after a PHY select */
- retval = dwc2_core_reset_and_force_dr_mode(hsotg);
- if (retval) {
- dev_err(hsotg->dev,
- "%s: Reset failed, aborting", __func__);
- return retval;
- }
- }
- if (hsotg->params.activate_stm_fs_transceiver) {
- ggpio = dwc2_readl(hsotg->regs + GGPIO);
- if (!(ggpio & GGPIO_STM32_OTG_GCCFG_PWRDWN)) {
- dev_dbg(hsotg->dev, "Activating transceiver\n");
- /*
- * STM32F4x9 uses the GGPIO register as general
- * core configuration register.
- */
- ggpio |= GGPIO_STM32_OTG_GCCFG_PWRDWN;
- dwc2_writel(ggpio, hsotg->regs + GGPIO);
- }
- }
- }
- /*
- * Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
- * do this on HNP Dev/Host mode switches (done in dev_init and
- * host_init).
- */
- if (dwc2_is_host_mode(hsotg))
- dwc2_init_fs_ls_pclk_sel(hsotg);
- return retval;
- }
- static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
- {
- u32 usbcfg, usbcfg_old;
- int retval = 0;
- if (!select_phy)
- return 0;
- usbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
- usbcfg_old = usbcfg;
- /*
- * HS PHY parameters. These parameters are preserved during soft reset
- * so only program the first time. Do a soft reset immediately after
- * setting phyif.
- */
- switch (hsotg->params.phy_type) {
- case DWC2_PHY_TYPE_PARAM_ULPI:
- /* ULPI interface */
- dev_dbg(hsotg->dev, "HS ULPI PHY selected\n");
- usbcfg |= GUSBCFG_ULPI_UTMI_SEL;
- usbcfg &= ~(GUSBCFG_PHYIF16 | GUSBCFG_DDRSEL);
- break;
- case DWC2_PHY_TYPE_PARAM_UTMI:
- /* UTMI+ interface */
- dev_dbg(hsotg->dev, "HS UTMI+ PHY selected\n");
- usbcfg &= ~(GUSBCFG_ULPI_UTMI_SEL | GUSBCFG_PHYIF16);
- if (hsotg->params.phy_utmi_width == 16)
- usbcfg |= GUSBCFG_PHYIF16;
- break;
- default:
- dev_err(hsotg->dev, "FS PHY selected at HS!\n");
- break;
- }
- if (usbcfg != usbcfg_old) {
- dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
- /* Reset after setting the PHY parameters */
- retval = dwc2_core_reset_and_force_dr_mode(hsotg);
- if (retval) {
- dev_err(hsotg->dev,
- "%s: Reset failed, aborting", __func__);
- return retval;
- }
- }
- return retval;
- }
- static int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
- {
- u32 usbcfg;
- int retval = 0;
- if ((hsotg->params.speed == DWC2_SPEED_PARAM_FULL ||
- hsotg->params.speed == DWC2_SPEED_PARAM_LOW) &&
- hsotg->params.phy_type == DWC2_PHY_TYPE_PARAM_FS) {
- /* If FS/LS mode with FS/LS PHY */
- retval = dwc2_fs_phy_init(hsotg, select_phy);
- if (retval)
- return retval;
- } else {
- /* High speed PHY */
- retval = dwc2_hs_phy_init(hsotg, select_phy);
- if (retval)
- return retval;
- }
- usbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
- usbcfg &= ~GUSBCFG_ULPI_FS_LS;
- usbcfg &= ~GUSBCFG_ULPI_CLK_SUSP_M;
- dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
- return retval;
- }
- static int dwc2_gahbcfg_init(struct dwc2_hsotg *hsotg)
- {
- u32 ahbcfg = dwc2_readl(hsotg->regs + GAHBCFG);
- if (hsotg->params.ahbcfg != -1) {
- ahbcfg &= GAHBCFG_CTRL_MASK;
- ahbcfg |= hsotg->params.ahbcfg &
- ~GAHBCFG_CTRL_MASK;
- }
- dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG);
- return 0;
- }
- static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg)
- {
- u32 usbcfg;
- usbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
- usbcfg &= ~(GUSBCFG_HNPCAP | GUSBCFG_SRPCAP);
- switch (hsotg->hw_params.op_mode) {
- case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
- if (hsotg->params.otg_cap ==
- DWC2_CAP_PARAM_HNP_SRP_CAPABLE)
- usbcfg |= GUSBCFG_HNPCAP;
- if (hsotg->params.otg_cap !=
- DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE)
- usbcfg |= GUSBCFG_SRPCAP;
- break;
- case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
- case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
- case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
- if (hsotg->params.otg_cap !=
- DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE)
- usbcfg |= GUSBCFG_SRPCAP;
- break;
- case GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE:
- case GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE:
- case GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST:
- default:
- break;
- }
- dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
- }
- /**
- * dwc2_enable_host_interrupts() - Enables the Host mode interrupts
- *
- * @hsotg: Programming view of DWC_otg controller
- */
- static void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg)
- {
- u32 intmsk;
- dev_dbg(hsotg->dev, "%s()\n", __func__);
- /* Disable all interrupts */
- dwc2_writel(0, hsotg->regs + GINTMSK);
- dwc2_writel(0, hsotg->regs + HAINTMSK);
- /* Enable the common interrupts */
- dwc2_enable_common_interrupts(hsotg);
- /* Enable host mode interrupts without disturbing common interrupts */
- intmsk = dwc2_readl(hsotg->regs + GINTMSK);
- intmsk |= GINTSTS_DISCONNINT | GINTSTS_PRTINT | GINTSTS_HCHINT;
- dwc2_writel(intmsk, hsotg->regs + GINTMSK);
- }
- /**
- * dwc2_disable_host_interrupts() - Disables the Host Mode interrupts
- *
- * @hsotg: Programming view of DWC_otg controller
- */
- static void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg)
- {
- u32 intmsk = dwc2_readl(hsotg->regs + GINTMSK);
- /* Disable host mode interrupts without disturbing common interrupts */
- intmsk &= ~(GINTSTS_SOF | GINTSTS_PRTINT | GINTSTS_HCHINT |
- GINTSTS_PTXFEMP | GINTSTS_NPTXFEMP | GINTSTS_DISCONNINT);
- dwc2_writel(intmsk, hsotg->regs + GINTMSK);
- }
- /*
- * dwc2_calculate_dynamic_fifo() - Calculates the default fifo size
- * For system that have a total fifo depth that is smaller than the default
- * RX + TX fifo size.
- *
- * @hsotg: Programming view of DWC_otg controller
- */
- static void dwc2_calculate_dynamic_fifo(struct dwc2_hsotg *hsotg)
- {
- struct dwc2_core_params *params = &hsotg->params;
- struct dwc2_hw_params *hw = &hsotg->hw_params;
- u32 rxfsiz, nptxfsiz, ptxfsiz, total_fifo_size;
- total_fifo_size = hw->total_fifo_size;
- rxfsiz = params->host_rx_fifo_size;
- nptxfsiz = params->host_nperio_tx_fifo_size;
- ptxfsiz = params->host_perio_tx_fifo_size;
- /*
- * Will use Method 2 defined in the DWC2 spec: minimum FIFO depth
- * allocation with support for high bandwidth endpoints. Synopsys
- * defines MPS(Max Packet size) for a periodic EP=1024, and for
- * non-periodic as 512.
- */
- if (total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz)) {
- /*
- * For Buffer DMA mode/Scatter Gather DMA mode
- * 2 * ((Largest Packet size / 4) + 1 + 1) + n
- * with n = number of host channel.
- * 2 * ((1024/4) + 2) = 516
- */
- rxfsiz = 516 + hw->host_channels;
- /*
- * min non-periodic tx fifo depth
- * 2 * (largest non-periodic USB packet used / 4)
- * 2 * (512/4) = 256
- */
- nptxfsiz = 256;
- /*
- * min periodic tx fifo depth
- * (largest packet size*MC)/4
- * (1024 * 3)/4 = 768
- */
- ptxfsiz = 768;
- params->host_rx_fifo_size = rxfsiz;
- params->host_nperio_tx_fifo_size = nptxfsiz;
- params->host_perio_tx_fifo_size = ptxfsiz;
- }
- /*
- * If the summation of RX, NPTX and PTX fifo sizes is still
- * bigger than the total_fifo_size, then we have a problem.
- *
- * We won't be able to allocate as many endpoints. Right now,
- * we're just printing an error message, but ideally this FIFO
- * allocation algorithm would be improved in the future.
- *
- * FIXME improve this FIFO allocation algorithm.
- */
- if (unlikely(total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz)))
- dev_err(hsotg->dev, "invalid fifo sizes\n");
- }
- static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
- {
- struct dwc2_core_params *params = &hsotg->params;
- u32 nptxfsiz, hptxfsiz, dfifocfg, grxfsiz;
- if (!params->enable_dynamic_fifo)
- return;
- dwc2_calculate_dynamic_fifo(hsotg);
- /* Rx FIFO */
- grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ);
- dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz);
- grxfsiz &= ~GRXFSIZ_DEPTH_MASK;
- grxfsiz |= params->host_rx_fifo_size <<
- GRXFSIZ_DEPTH_SHIFT & GRXFSIZ_DEPTH_MASK;
- dwc2_writel(grxfsiz, hsotg->regs + GRXFSIZ);
- dev_dbg(hsotg->dev, "new grxfsiz=%08x\n",
- dwc2_readl(hsotg->regs + GRXFSIZ));
- /* Non-periodic Tx FIFO */
- dev_dbg(hsotg->dev, "initial gnptxfsiz=%08x\n",
- dwc2_readl(hsotg->regs + GNPTXFSIZ));
- nptxfsiz = params->host_nperio_tx_fifo_size <<
- FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK;
- nptxfsiz |= params->host_rx_fifo_size <<
- FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK;
- dwc2_writel(nptxfsiz, hsotg->regs + GNPTXFSIZ);
- dev_dbg(hsotg->dev, "new gnptxfsiz=%08x\n",
- dwc2_readl(hsotg->regs + GNPTXFSIZ));
- /* Periodic Tx FIFO */
- dev_dbg(hsotg->dev, "initial hptxfsiz=%08x\n",
- dwc2_readl(hsotg->regs + HPTXFSIZ));
- hptxfsiz = params->host_perio_tx_fifo_size <<
- FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK;
- hptxfsiz |= (params->host_rx_fifo_size +
- params->host_nperio_tx_fifo_size) <<
- FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK;
- dwc2_writel(hptxfsiz, hsotg->regs + HPTXFSIZ);
- dev_dbg(hsotg->dev, "new hptxfsiz=%08x\n",
- dwc2_readl(hsotg->regs + HPTXFSIZ));
- if (hsotg->params.en_multiple_tx_fifo &&
- hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_91a) {
- /*
- * This feature was implemented in 2.91a version
- * Global DFIFOCFG calculation for Host mode -
- * include RxFIFO, NPTXFIFO and HPTXFIFO
- */
- dfifocfg = dwc2_readl(hsotg->regs + GDFIFOCFG);
- dfifocfg &= ~GDFIFOCFG_EPINFOBASE_MASK;
- dfifocfg |= (params->host_rx_fifo_size +
- params->host_nperio_tx_fifo_size +
- params->host_perio_tx_fifo_size) <<
- GDFIFOCFG_EPINFOBASE_SHIFT &
- GDFIFOCFG_EPINFOBASE_MASK;
- dwc2_writel(dfifocfg, hsotg->regs + GDFIFOCFG);
- }
- }
- /**
- * dwc2_calc_frame_interval() - Calculates the correct frame Interval value for
- * the HFIR register according to PHY type and speed
- *
- * @hsotg: Programming view of DWC_otg controller
- *
- * NOTE: The caller can modify the value of the HFIR register only after the
- * Port Enable bit of the Host Port Control and Status register (HPRT.EnaPort)
- * has been set
- */
- u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg)
- {
- u32 usbcfg;
- u32 hprt0;
- int clock = 60; /* default value */
- usbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
- hprt0 = dwc2_readl(hsotg->regs + HPRT0);
- if (!(usbcfg & GUSBCFG_PHYSEL) && (usbcfg & GUSBCFG_ULPI_UTMI_SEL) &&
- !(usbcfg & GUSBCFG_PHYIF16))
- clock = 60;
- if ((usbcfg & GUSBCFG_PHYSEL) && hsotg->hw_params.fs_phy_type ==
- GHWCFG2_FS_PHY_TYPE_SHARED_ULPI)
- clock = 48;
- if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) &&
- !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16))
- clock = 30;
- if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) &&
- !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && !(usbcfg & GUSBCFG_PHYIF16))
- clock = 60;
- if ((usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) &&
- !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16))
- clock = 48;
- if ((usbcfg & GUSBCFG_PHYSEL) && !(usbcfg & GUSBCFG_PHYIF16) &&
- hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_SHARED_UTMI)
- clock = 48;
- if ((usbcfg & GUSBCFG_PHYSEL) &&
- hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED)
- clock = 48;
- if ((hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT == HPRT0_SPD_HIGH_SPEED)
- /* High speed case */
- return 125 * clock - 1;
- /* FS/LS case */
- return 1000 * clock - 1;
- }
- /**
- * dwc2_read_packet() - Reads a packet from the Rx FIFO into the destination
- * buffer
- *
- * @core_if: Programming view of DWC_otg controller
- * @dest: Destination buffer for the packet
- * @bytes: Number of bytes to copy to the destination
- */
- void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes)
- {
- u32 __iomem *fifo = (u32 __iomem *)(hsotg->regs + HCFIFO(0));
- u32 *data_buf = (u32 *)dest;
- int word_count = (bytes + 3) / 4;
- int i;
- /*
- * Todo: Account for the case where dest is not dword aligned. This
- * requires reading data from the FIFO into a u32 temp buffer, then
- * moving it into the data buffer.
- */
- dev_vdbg(hsotg->dev, "%s(%p,%p,%d)\n", __func__, hsotg, dest, bytes);
- for (i = 0; i < word_count; i++, data_buf++)
- *data_buf = dwc2_readl((u32)fifo);
- }
- static int _dwc2_hcd_start(struct usb_hcd *hcd);
- void dwc2_host_start(struct dwc2_hsotg *hsotg)
- {
- struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg);
- hcd->self.is_b_host = dwc2_hcd_is_b_host(hsotg);
- _dwc2_hcd_start(hcd);
- }
- static void dwc2_host_disconnect(struct dwc2_hsotg *hsotg)
- {
- struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg);
- hcd->self.is_b_host = 0;
- }
- static void dwc2_host_hub_info(struct dwc2_hsotg *hsotg, void *context,
- int *hub_addr, int *hub_port)
- {
- }
- /*
- * =========================================================================
- * Low Level Host Channel Access Functions
- * =========================================================================
- */
- static void dwc2_hc_enable_slave_ints(struct dwc2_hsotg *hsotg,
- struct dwc2_host_chan *chan)
- {
- u32 hcintmsk = HCINTMSK_CHHLTD;
- switch (chan->ep_type) {
- case USB_ENDPOINT_XFER_CONTROL:
- case USB_ENDPOINT_XFER_BULK:
- dev_vdbg(hsotg->dev, "control/bulk\n");
- hcintmsk |= HCINTMSK_XFERCOMPL;
- hcintmsk |= HCINTMSK_STALL;
- hcintmsk |= HCINTMSK_XACTERR;
- hcintmsk |= HCINTMSK_DATATGLERR;
- if (chan->ep_is_in) {
- hcintmsk |= HCINTMSK_BBLERR;
- } else {
- hcintmsk |= HCINTMSK_NAK;
- hcintmsk |= HCINTMSK_NYET;
- if (chan->do_ping)
- hcintmsk |= HCINTMSK_ACK;
- }
- if (chan->do_split) {
- hcintmsk |= HCINTMSK_NAK;
- if (chan->complete_split)
- hcintmsk |= HCINTMSK_NYET;
- else
- hcintmsk |= HCINTMSK_ACK;
- }
- if (chan->error_state)
- hcintmsk |= HCINTMSK_ACK;
- break;
- default:
- dev_err(hsotg->dev, "## Unknown EP type ##\n");
- break;
- }
- dwc2_writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num));
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk);
- }
- static void dwc2_hc_enable_ints(struct dwc2_hsotg *hsotg,
- struct dwc2_host_chan *chan)
- {
- u32 intmsk;
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "DMA disabled\n");
- dwc2_hc_enable_slave_ints(hsotg, chan);
- /* Enable the top level host channel interrupt */
- intmsk = dwc2_readl(hsotg->regs + HAINTMSK);
- intmsk |= 1 << chan->hc_num;
- dwc2_writel(intmsk, hsotg->regs + HAINTMSK);
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "set HAINTMSK to %08x\n", intmsk);
- /* Make sure host channel interrupts are enabled */
- intmsk = dwc2_readl(hsotg->regs + GINTMSK);
- intmsk |= GINTSTS_HCHINT;
- dwc2_writel(intmsk, hsotg->regs + GINTMSK);
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "set GINTMSK to %08x\n", intmsk);
- }
- /**
- * dwc2_hc_init() - Prepares a host channel for transferring packets to/from
- * a specific endpoint
- *
- * @hsotg: Programming view of DWC_otg controller
- * @chan: Information needed to initialize the host channel
- *
- * The HCCHARn register is set up with the characteristics specified in chan.
- * Host channel interrupts that may need to be serviced while this transfer is
- * in progress are enabled.
- */
- static void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan)
- {
- u8 hc_num = chan->hc_num;
- u32 hcintmsk;
- u32 hcchar;
- u32 hcsplt = 0;
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "%s()\n", __func__);
- /* Clear old interrupt conditions for this host channel */
- hcintmsk = 0xffffffff;
- hcintmsk &= ~HCINTMSK_RESERVED14_31;
- dwc2_writel(hcintmsk, hsotg->regs + HCINT(hc_num));
- /* Enable channel interrupts required for this transfer */
- dwc2_hc_enable_ints(hsotg, chan);
- /*
- * Program the HCCHARn register with the endpoint characteristics for
- * the current transfer
- */
- hcchar = chan->dev_addr << HCCHAR_DEVADDR_SHIFT & HCCHAR_DEVADDR_MASK;
- hcchar |= chan->ep_num << HCCHAR_EPNUM_SHIFT & HCCHAR_EPNUM_MASK;
- if (chan->ep_is_in)
- hcchar |= HCCHAR_EPDIR;
- if (chan->speed == USB_SPEED_LOW)
- hcchar |= HCCHAR_LSPDDEV;
- hcchar |= chan->ep_type << HCCHAR_EPTYPE_SHIFT & HCCHAR_EPTYPE_MASK;
- hcchar |= chan->max_packet << HCCHAR_MPS_SHIFT & HCCHAR_MPS_MASK;
- dwc2_writel(hcchar, hsotg->regs + HCCHAR(hc_num));
- if (dbg_hc(chan)) {
- dev_vdbg(hsotg->dev, "set HCCHAR(%d) to %08x\n",
- hc_num, hcchar);
- dev_vdbg(hsotg->dev, "%s: Channel %d\n",
- __func__, hc_num);
- dev_vdbg(hsotg->dev, " Dev Addr: %d\n",
- chan->dev_addr);
- dev_vdbg(hsotg->dev, " Ep Num: %d\n",
- chan->ep_num);
- dev_vdbg(hsotg->dev, " Is In: %d\n",
- chan->ep_is_in);
- dev_vdbg(hsotg->dev, " Is Low Speed: %d\n",
- chan->speed == USB_SPEED_LOW);
- dev_vdbg(hsotg->dev, " Ep Type: %d\n",
- chan->ep_type);
- dev_vdbg(hsotg->dev, " Max Pkt: %d\n",
- chan->max_packet);
- }
- /* Program the HCSPLT register for SPLITs */
- if (chan->do_split) {
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev,
- "Programming HC %d with split --> %s\n",
- hc_num,
- chan->complete_split ? "CSPLIT" : "SSPLIT");
- if (chan->complete_split)
- hcsplt |= HCSPLT_COMPSPLT;
- hcsplt |= chan->xact_pos << HCSPLT_XACTPOS_SHIFT &
- HCSPLT_XACTPOS_MASK;
- hcsplt |= chan->hub_addr << HCSPLT_HUBADDR_SHIFT &
- HCSPLT_HUBADDR_MASK;
- hcsplt |= chan->hub_port << HCSPLT_PRTADDR_SHIFT &
- HCSPLT_PRTADDR_MASK;
- if (dbg_hc(chan)) {
- dev_vdbg(hsotg->dev, " comp split %d\n",
- chan->complete_split);
- dev_vdbg(hsotg->dev, " xact pos %d\n",
- chan->xact_pos);
- dev_vdbg(hsotg->dev, " hub addr %d\n",
- chan->hub_addr);
- dev_vdbg(hsotg->dev, " hub port %d\n",
- chan->hub_port);
- dev_vdbg(hsotg->dev, " is_in %d\n",
- chan->ep_is_in);
- dev_vdbg(hsotg->dev, " Max Pkt %d\n",
- chan->max_packet);
- dev_vdbg(hsotg->dev, " xferlen %d\n",
- chan->xfer_len);
- }
- }
- dwc2_writel(hcsplt, hsotg->regs + HCSPLT(hc_num));
- }
- /**
- * dwc2_hc_halt() - Attempts to halt a host channel
- *
- * @hsotg: Controller register interface
- * @chan: Host channel to halt
- * @halt_status: Reason for halting the channel
- *
- * This function should only be called in Slave mode or to abort a transfer in
- * either Slave mode or DMA mode. Under normal circumstances in DMA mode, the
- * controller halts the channel when the transfer is complete or a condition
- * occurs that requires application intervention.
- *
- * In slave mode, checks for a free request queue entry, then sets the Channel
- * Enable and Channel Disable bits of the Host Channel Characteristics
- * register of the specified channel to intiate the halt. If there is no free
- * request queue entry, sets only the Channel Disable bit of the HCCHARn
- * register to flush requests for this channel. In the latter case, sets a
- * flag to indicate that the host channel needs to be halted when a request
- * queue slot is open.
- *
- * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
- * HCCHARn register. The controller ensures there is space in the request
- * queue before submitting the halt request.
- *
- * Some time may elapse before the core flushes any posted requests for this
- * host channel and halts. The Channel Halted interrupt handler completes the
- * deactivation of the host channel.
- */
- void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
- enum dwc2_halt_status halt_status)
- {
- u32 nptxsts, hcchar;
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "%s()\n", __func__);
- if (halt_status == DWC2_HC_XFER_NO_HALT_STATUS)
- dev_err(hsotg->dev, "!!! halt_status = %d !!!\n", halt_status);
- if (halt_status == DWC2_HC_XFER_URB_DEQUEUE ||
- halt_status == DWC2_HC_XFER_AHB_ERR) {
- /*
- * Disable all channel interrupts except Ch Halted. The QTD
- * and QH state associated with this transfer has been cleared
- * (in the case of URB_DEQUEUE), so the channel needs to be
- * shut down carefully to prevent crashes.
- */
- u32 hcintmsk = HCINTMSK_CHHLTD;
- dev_vdbg(hsotg->dev, "dequeue/error\n");
- dwc2_writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num));
- /*
- * Make sure no other interrupts besides halt are currently
- * pending. Handling another interrupt could cause a crash due
- * to the QTD and QH state.
- */
- dwc2_writel(~hcintmsk, hsotg->regs + HCINT(chan->hc_num));
- /*
- * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
- * even if the channel was already halted for some other
- * reason
- */
- chan->halt_status = halt_status;
- hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num));
- if (!(hcchar & HCCHAR_CHENA)) {
- /*
- * The channel is either already halted or it hasn't
- * started yet. In DMA mode, the transfer may halt if
- * it finishes normally or a condition occurs that
- * requires driver intervention. Don't want to halt
- * the channel again. In either Slave or DMA mode,
- * it's possible that the transfer has been assigned
- * to a channel, but not started yet when an URB is
- * dequeued. Don't want to halt a channel that hasn't
- * started yet.
- */
- return;
- }
- }
- if (chan->halt_pending) {
- /*
- * A halt has already been issued for this channel. This might
- * happen when a transfer is aborted by a higher level in
- * the stack.
- */
- dev_vdbg(hsotg->dev,
- "*** %s: Channel %d, chan->halt_pending already set ***\n",
- __func__, chan->hc_num);
- return;
- }
- hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num));
- /* No need to set the bit in DDMA for disabling the channel */
- /* TODO check it everywhere channel is disabled */
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "desc DMA disabled\n");
- hcchar |= HCCHAR_CHENA;
- hcchar |= HCCHAR_CHDIS;
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "DMA not enabled\n");
- hcchar |= HCCHAR_CHENA;
- /* Check for space in the request queue to issue the halt */
- if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
- chan->ep_type == USB_ENDPOINT_XFER_BULK) {
- dev_vdbg(hsotg->dev, "control/bulk\n");
- nptxsts = dwc2_readl(hsotg->regs + GNPTXSTS);
- if ((nptxsts & TXSTS_QSPCAVAIL_MASK) == 0) {
- dev_vdbg(hsotg->dev, "Disabling channel\n");
- hcchar &= ~HCCHAR_CHENA;
- }
- }
- dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
- chan->halt_status = halt_status;
- if (hcchar & HCCHAR_CHENA) {
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "Channel enabled\n");
- chan->halt_pending = 1;
- chan->halt_on_queue = 0;
- } else {
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "Channel disabled\n");
- chan->halt_on_queue = 1;
- }
- if (dbg_hc(chan)) {
- dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__,
- chan->hc_num);
- dev_vdbg(hsotg->dev, " hcchar: 0x%08x\n",
- hcchar);
- dev_vdbg(hsotg->dev, " halt_pending: %d\n",
- chan->halt_pending);
- dev_vdbg(hsotg->dev, " halt_on_queue: %d\n",
- chan->halt_on_queue);
- dev_vdbg(hsotg->dev, " halt_status: %d\n",
- chan->halt_status);
- }
- }
- /**
- * dwc2_hc_cleanup() - Clears the transfer state for a host channel
- *
- * @hsotg: Programming view of DWC_otg controller
- * @chan: Identifies the host channel to clean up
- *
- * This function is normally called after a transfer is done and the host
- * channel is being released
- */
- void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan)
- {
- u32 hcintmsk;
- chan->xfer_started = 0;
- list_del_init(&chan->split_order_list_entry);
- /*
- * Clear channel interrupt enables and any unhandled channel interrupt
- * conditions
- */
- dwc2_writel(0, hsotg->regs + HCINTMSK(chan->hc_num));
- hcintmsk = 0xffffffff;
- hcintmsk &= ~HCINTMSK_RESERVED14_31;
- dwc2_writel(hcintmsk, hsotg->regs + HCINT(chan->hc_num));
- }
- /**
- * dwc2_hc_set_even_odd_frame() - Sets the channel property that indicates in
- * which frame a periodic transfer should occur
- *
- * @hsotg: Programming view of DWC_otg controller
- * @chan: Identifies the host channel to set up and its properties
- * @hcchar: Current value of the HCCHAR register for the specified host channel
- *
- * This function has no effect on non-periodic transfers
- */
- static void dwc2_hc_set_even_odd_frame(struct dwc2_hsotg *hsotg,
- struct dwc2_host_chan *chan, u32 *hcchar)
- {
- }
- /**
- * dwc2_hc_write_packet() - Writes a packet into the Tx FIFO associated with
- * the Host Channel
- *
- * @hsotg: Programming view of DWC_otg controller
- * @chan: Information needed to initialize the host channel
- *
- * This function should only be called in Slave mode. For a channel associated
- * with a non-periodic EP, the non-periodic Tx FIFO is written. For a channel
- * associated with a periodic EP, the periodic Tx FIFO is written.
- *
- * Upon return the xfer_buf and xfer_count fields in chan are incremented by
- * the number of bytes written to the Tx FIFO.
- */
- static void dwc2_hc_write_packet(struct dwc2_hsotg *hsotg,
- struct dwc2_host_chan *chan)
- {
- u32 i;
- u32 remaining_count;
- u32 byte_count;
- u32 dword_count;
- u32 __iomem *data_fifo;
- u32 *data_buf = (u32 *)chan->xfer_buf;
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "%s()\n", __func__);
- data_fifo = (u32 __iomem *)(hsotg->regs + HCFIFO(chan->hc_num));
- remaining_count = chan->xfer_len - chan->xfer_count;
- if (remaining_count > chan->max_packet)
- byte_count = chan->max_packet;
- else
- byte_count = remaining_count;
- dword_count = (byte_count + 3) / 4;
- if (((unsigned long)data_buf & 0x3) == 0) {
- /* xfer_buf is DWORD aligned */
- for (i = 0; i < dword_count; i++, data_buf++)
- dwc2_writel(*data_buf, (u32)data_fifo);
- } else {
- /* xfer_buf is not DWORD aligned */
- for (i = 0; i < dword_count; i++, data_buf++) {
- u32 data = data_buf[0] | data_buf[1] << 8 |
- data_buf[2] << 16 | data_buf[3] << 24;
- dwc2_writel(data, (u32)data_fifo);
- }
- }
- chan->xfer_count += byte_count;
- chan->xfer_buf += byte_count;
- }
- /**
- * dwc2_hc_do_ping() - Starts a PING transfer
- *
- * @hsotg: Programming view of DWC_otg controller
- * @chan: Information needed to initialize the host channel
- *
- * This function should only be called in Slave mode. The Do Ping bit is set in
- * the HCTSIZ register, then the channel is enabled.
- */
- static void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
- struct dwc2_host_chan *chan)
- {
- u32 hcchar;
- u32 hctsiz;
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__,
- chan->hc_num);
- hctsiz = TSIZ_DOPNG;
- hctsiz |= 1 << TSIZ_PKTCNT_SHIFT;
- dwc2_writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num));
- hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num));
- hcchar |= HCCHAR_CHENA;
- hcchar &= ~HCCHAR_CHDIS;
- dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
- }
- /**
- * dwc2_hc_start_transfer() - Does the setup for a data transfer for a host
- * channel and starts the transfer
- *
- * @hsotg: Programming view of DWC_otg controller
- * @chan: Information needed to initialize the host channel. The xfer_len value
- * may be reduced to accommodate the max widths of the XferSize and
- * PktCnt fields in the HCTSIZn register. The multi_count value may be
- * changed to reflect the final xfer_len value.
- *
- * This function may be called in either Slave mode or DMA mode. In Slave mode,
- * the caller must ensure that there is sufficient space in the request queue
- * and Tx Data FIFO.
- *
- * For an OUT transfer in Slave mode, it loads a data packet into the
- * appropriate FIFO. If necessary, additional data packets are loaded in the
- * Host ISR.
- *
- * For an IN transfer in Slave mode, a data packet is requested. The data
- * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
- * additional data packets are requested in the Host ISR.
- *
- * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
- * register along with a packet count of 1 and the channel is enabled. This
- * causes a single PING transaction to occur. Other fields in HCTSIZ are
- * simply set to 0 since no data transfer occurs in this case.
- *
- * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
- * all the information required to perform the subsequent data transfer. In
- * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
- * controller performs the entire PING protocol, then starts the data
- * transfer.
- */
- static void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
- struct dwc2_host_chan *chan)
- {
- u32 max_hc_xfer_size = hsotg->params.max_transfer_size;
- u16 max_hc_pkt_count = hsotg->params.max_packet_count;
- u32 hcchar;
- u32 hctsiz = 0;
- u16 num_packets;
- u32 ec_mc;
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "%s()\n", __func__);
- if (chan->do_ping) {
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "ping, no DMA\n");
- dwc2_hc_do_ping(hsotg, chan);
- chan->xfer_started = 1;
- return;
- }
- if (chan->do_split) {
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "split\n");
- num_packets = 1;
- if (chan->complete_split && !chan->ep_is_in)
- /*
- * For CSPLIT OUT Transfer, set the size to 0 so the
- * core doesn't expect any data written to the FIFO
- */
- chan->xfer_len = 0;
- else if (chan->ep_is_in || chan->xfer_len > chan->max_packet)
- chan->xfer_len = chan->max_packet;
- else if (!chan->ep_is_in && chan->xfer_len > 188)
- chan->xfer_len = 188;
- hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT &
- TSIZ_XFERSIZE_MASK;
- /* For split set ec_mc for immediate retries */
- ec_mc = 1;
- } else {
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "no split\n");
- /*
- * Ensure that the transfer length and packet count will fit
- * in the widths allocated for them in the HCTSIZn register
- */
- if (chan->xfer_len > max_hc_xfer_size) {
- /*
- * Make sure that xfer_len is a multiple of max packet
- * size
- */
- chan->xfer_len =
- max_hc_xfer_size - chan->max_packet + 1;
- }
- if (chan->xfer_len > 0) {
- num_packets = (chan->xfer_len + chan->max_packet - 1) /
- chan->max_packet;
- if (num_packets > max_hc_pkt_count) {
- num_packets = max_hc_pkt_count;
- chan->xfer_len = num_packets * chan->max_packet;
- }
- } else {
- /* Need 1 packet for transfer length of 0 */
- num_packets = 1;
- }
- if (chan->ep_is_in)
- /*
- * Always program an integral # of max packets for IN
- * transfers
- */
- chan->xfer_len = num_packets * chan->max_packet;
- hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT &
- TSIZ_XFERSIZE_MASK;
- /* The ec_mc gets the multi_count for non-split */
- ec_mc = chan->multi_count;
- }
- chan->start_pkt_count = num_packets;
- hctsiz |= num_packets << TSIZ_PKTCNT_SHIFT & TSIZ_PKTCNT_MASK;
- hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT &
- TSIZ_SC_MC_PID_MASK;
- dwc2_writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num));
- if (dbg_hc(chan)) {
- dev_vdbg(hsotg->dev, "Wrote %08x to HCTSIZ(%d)\n",
- hctsiz, chan->hc_num);
- dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__,
- chan->hc_num);
- dev_vdbg(hsotg->dev, " Xfer Size: %d\n",
- (hctsiz & TSIZ_XFERSIZE_MASK) >>
- TSIZ_XFERSIZE_SHIFT);
- dev_vdbg(hsotg->dev, " Num Pkts: %d\n",
- (hctsiz & TSIZ_PKTCNT_MASK) >>
- TSIZ_PKTCNT_SHIFT);
- dev_vdbg(hsotg->dev, " Start PID: %d\n",
- (hctsiz & TSIZ_SC_MC_PID_MASK) >>
- TSIZ_SC_MC_PID_SHIFT);
- }
- /* Start the split */
- if (chan->do_split) {
- u32 hcsplt = dwc2_readl(hsotg->regs + HCSPLT(chan->hc_num));
- hcsplt |= HCSPLT_SPLTENA;
- dwc2_writel(hcsplt, hsotg->regs + HCSPLT(chan->hc_num));
- }
- hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num));
- hcchar &= ~HCCHAR_MULTICNT_MASK;
- hcchar |= (ec_mc << HCCHAR_MULTICNT_SHIFT) & HCCHAR_MULTICNT_MASK;
- dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar);
- if (hcchar & HCCHAR_CHDIS)
- dev_warn(hsotg->dev,
- "%s: chdis set, channel %d, hcchar 0x%08x\n",
- __func__, chan->hc_num, hcchar);
- /* Set host channel enable after all other setup is complete */
- hcchar |= HCCHAR_CHENA;
- hcchar &= ~HCCHAR_CHDIS;
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, " Multi Cnt: %d\n",
- (hcchar & HCCHAR_MULTICNT_MASK) >>
- HCCHAR_MULTICNT_SHIFT);
- dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar,
- chan->hc_num);
- chan->xfer_started = 1;
- chan->requests++;
- if (!chan->ep_is_in && chan->xfer_len > 0)
- /* Load OUT packet into the appropriate Tx FIFO */
- dwc2_hc_write_packet(hsotg, chan);
- }
- /**
- * dwc2_hc_continue_transfer() - Continues a data transfer that was started by
- * a previous call to dwc2_hc_start_transfer()
- *
- * @hsotg: Programming view of DWC_otg controller
- * @chan: Information needed to initialize the host channel
- *
- * The caller must ensure there is sufficient space in the request queue and Tx
- * Data FIFO. This function should only be called in Slave mode. In DMA mode,
- * the controller acts autonomously to complete transfers programmed to a host
- * channel.
- *
- * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
- * if there is any data remaining to be queued. For an IN transfer, another
- * data packet is always requested. For the SETUP phase of a control transfer,
- * this function does nothing.
- *
- * Return: 1 if a new request is queued, 0 if no more requests are required
- * for this transfer
- */
- static int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
- struct dwc2_host_chan *chan)
- {
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__,
- chan->hc_num);
- if (chan->do_split)
- /* SPLITs always queue just once per channel */
- return 0;
- if (chan->data_pid_start == DWC2_HC_PID_SETUP)
- /* SETUPs are queued only once since they can't be NAK'd */
- return 0;
- if (chan->ep_is_in) {
- /*
- * Always queue another request for other IN transfers. If
- * back-to-back INs are issued and NAKs are received for both,
- * the driver may still be processing the first NAK when the
- * second NAK is received. When the interrupt handler clears
- * the NAK interrupt for the first NAK, the second NAK will
- * not be seen. So we can't depend on the NAK interrupt
- * handler to requeue a NAK'd request. Instead, IN requests
- * are issued each time this function is called. When the
- * transfer completes, the extra requests for the channel will
- * be flushed.
- */
- u32 hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num));
- dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar);
- hcchar |= HCCHAR_CHENA;
- hcchar &= ~HCCHAR_CHDIS;
- if (dbg_hc(chan))
- dev_vdbg(hsotg->dev, " IN xfer: hcchar = 0x%08x\n",
- hcchar);
- dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
- chan->requests++;
- return 1;
- }
- /* OUT transfers */
- if (chan->xfer_count < chan->xfer_len) {
- /* Load OUT packet into the appropriate Tx FIFO */
- dwc2_hc_write_packet(hsotg, chan);
- chan->requests++;
- return 1;
- }
- return 0;
- }
- /*
- * =========================================================================
- * HCD
- * =========================================================================
- */
- /*
- * Processes all the URBs in a single list of QHs. Completes them with
- * -ETIMEDOUT and frees the QTD.
- *
- * Must be called with interrupt disabled and spinlock held
- */
- static void dwc2_kill_urbs_in_qh_list(struct dwc2_hsotg *hsotg,
- List_t *qh_list)
- {
- struct dwc2_qh *qh;
- struct dwc2_qtd *qtd;
- ListItem_t *pxListItem, *nListItem;
- list_for_each_entry_safe(pxListItem, nListItem, qh, qh_list) {
- ListItem_t *pxListItem1, *nListItem1;
- list_for_each_entry_safe(pxListItem1, nListItem1, qtd, &qh->qtd_list) {
- dwc2_host_complete(hsotg, qtd, -ECONNRESET);
- dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
- }
- }
- }
- static void dwc2_qh_list_free(struct dwc2_hsotg *hsotg,
- List_t *qh_list)
- {
- struct dwc2_qtd *qtd;
- struct dwc2_qh *qh;
- unsigned long flags;
- if (!listLIST_IS_INITIALISED(qh_list))
- /* The list hasn't been initialized yet */
- return;
- spin_lock_irqsave(&hsotg->lock, flags);
- /* Ensure there are no QTDs or URBs left */
- dwc2_kill_urbs_in_qh_list(hsotg, qh_list);
-
- ListItem_t *pxListItem, *nListItem;
- list_for_each_entry_safe(pxListItem, nListItem, qh, qh_list) {
- dwc2_hcd_qh_unlink(hsotg, qh);
- /* Free each QTD in the QH's QTD list */
- ListItem_t *pxListItem1, *nListItem1;
- list_for_each_entry_safe(pxListItem1, nListItem1, qtd, &qh->qtd_list)
- dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
- if (qh->channel && qh->channel->qh == qh)
- qh->channel->qh = NULL;
- spin_unlock_irqrestore(&hsotg->lock, flags);
- dwc2_hcd_qh_free(hsotg, qh);
- spin_lock_irqsave(&hsotg->lock, flags);
- }
- spin_unlock_irqrestore(&hsotg->lock, flags);
- }
- /*
- * Responds with an error status of -ETIMEDOUT to all URBs in the non-periodic
- * and periodic schedules. The QTD associated with each URB is removed from
- * the schedule and freed. This function may be called when a disconnect is
- * detected or when the HCD is being stopped.
- *
- * Must be called with interrupt disabled and spinlock held
- */
- static void dwc2_kill_all_urbs(struct dwc2_hsotg *hsotg)
- {
- dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_inactive);
- dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_active);
- }
- /**
- * dwc2_hcd_start() - Starts the HCD when switching to Host mode
- *
- * @hsotg: Pointer to struct dwc2_hsotg
- */
- void dwc2_hcd_start(struct dwc2_hsotg *hsotg)
- {
- u32 hprt0;
- if (hsotg->op_state == OTG_STATE_B_HOST) {
- /*
- * Reset the port. During a HNP mode switch the reset
- * needs to occur within 1ms and have a duration of at
- * least 50ms.
- */
- hprt0 = dwc2_read_hprt0(hsotg);
- hprt0 |= HPRT0_RST;
- dwc2_writel(hprt0, hsotg->regs + HPRT0);
- }
- }
- void dwc2_hcd_start_isr(struct dwc2_hsotg *hsotg)
- {
- u32 hprt0;
- if (hsotg->op_state == OTG_STATE_B_HOST) {
- /*
- * Reset the port. During a HNP mode switch the reset
- * needs to occur within 1ms and have a duration of at
- * least 50ms.
- */
- hprt0 = dwc2_read_hprt0(hsotg);
- hprt0 |= HPRT0_RST;
- dwc2_writel(hprt0, hsotg->regs + HPRT0);
- }
- }
- /* Must be called with interrupt disabled and spinlock held */
- static void dwc2_hcd_cleanup_channels(struct dwc2_hsotg *hsotg)
- {
- int num_channels = hsotg->params.host_channels;
- struct dwc2_host_chan *channel;
- u32 hcchar;
- int i;
- /* Flush out any channel requests in slave mode */
- for (i = 0; i < num_channels; i++) {
- channel = hsotg->hc_ptr_array[i];
- //if (!list_empty(&channel->hc_list_entry))
- if (!list_item_empty(&channel->hc_list_entry))
- continue;
- hcchar = dwc2_readl(hsotg->regs + HCCHAR(i));
- if (hcchar & HCCHAR_CHENA) {
- hcchar &= ~(HCCHAR_CHENA | HCCHAR_EPDIR);
- hcchar |= HCCHAR_CHDIS;
- dwc2_writel(hcchar, hsotg->regs + HCCHAR(i));
- }
- }
- for (i = 0; i < num_channels; i++) {
- channel = hsotg->hc_ptr_array[i];
- //if (!list_empty(&channel->hc_list_entry))
- if (!list_item_empty(&channel->hc_list_entry))
- continue;
- hcchar = dwc2_readl(hsotg->regs + HCCHAR(i));
- if (hcchar & HCCHAR_CHENA) {
- /* Halt the channel */
- hcchar |= HCCHAR_CHDIS;
- dwc2_writel(hcchar, hsotg->regs + HCCHAR(i));
- }
- dwc2_hc_cleanup(hsotg, channel);
- list_add_tail(&channel->hc_list_entry, &hsotg->free_hc_list);
- /*
- * Added for Descriptor DMA to prevent channel double cleanup in
- * release_channel_ddma(), which is called from ep_disable when
- * device disconnects
- */
- channel->qh = NULL;
- }
- /* All channels have been freed, mark them available */
- hsotg->non_periodic_channels = 0;
- }
- /**
- * dwc2_hcd_connect() - Handles connect of the HCD
- *
- * @hsotg: Pointer to struct dwc2_hsotg
- *
- * Must be called with interrupt disabled and spinlock held
- */
- void dwc2_hcd_connect(struct dwc2_hsotg *hsotg)
- {
- if (hsotg->lx_state != DWC2_L0)
- usb_hcd_resume_root_hub(hsotg->priv);
- hsotg->flags.b.port_connect_status_change = 1;
- hsotg->flags.b.port_connect_status = 1;
- }
- /**
- * dwc2_hcd_disconnect() - Handles disconnect of the HCD
- *
- * @hsotg: Pointer to struct dwc2_hsotg
- * @force: If true, we won't try to reconnect even if we see device connected.
- *
- * Must be called with interrupt disabled and spinlock held
- */
- void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force)
- {
- u32 intr;
- u32 hprt0;
- /* Set status flags for the hub driver */
- hsotg->flags.b.port_connect_status_change = 1;
- hsotg->flags.b.port_connect_status = 0;
- /*
- * Shutdown any transfers in process by clearing the Tx FIFO Empty
- * interrupt mask and status bits and disabling subsequent host
- * channel interrupts.
- */
- intr = dwc2_readl(hsotg->regs + GINTMSK);
- intr &= ~(GINTSTS_NPTXFEMP | GINTSTS_PTXFEMP | GINTSTS_HCHINT);
- dwc2_writel(intr, hsotg->regs + GINTMSK);
- intr = GINTSTS_NPTXFEMP | GINTSTS_PTXFEMP | GINTSTS_HCHINT;
- dwc2_writel(intr, hsotg->regs + GINTSTS);
- /*
- * Turn off the vbus power only if the core has transitioned to device
- * mode. If still in host mode, need to keep power on to detect a
- * reconnection.
- */
- /* Respond with an error status to all URBs in the schedule */
- dwc2_kill_all_urbs(hsotg);
- if (dwc2_is_host_mode(hsotg))
- /* Clean up any host channels that were in use */
- dwc2_hcd_cleanup_channels(hsotg);
- dwc2_host_disconnect(hsotg);
- /*
- * Add an extra check here to see if we're actually connected but
- * we don't have a detection interrupt pending. This can happen if:
- * 1. hardware sees connect
- * 2. hardware sees disconnect
- * 3. hardware sees connect
- * 4. dwc2_port_intr() - clears connect interrupt
- * 5. dwc2_handle_common_intr() - calls here
- *
- * Without the extra check here we will end calling disconnect
- * and won't get any future interrupts to handle the connect.
- */
- if (!force) {
- hprt0 = dwc2_readl(hsotg->regs + HPRT0);
- if (!(hprt0 & HPRT0_CONNDET) && (hprt0 & HPRT0_CONNSTS))
- dwc2_hcd_connect(hsotg);
- }
- }
- #if 0
- /**
- * dwc2_hcd_rem_wakeup() - Handles Remote Wakeup
- *
- * @hsotg: Pointer to struct dwc2_hsotg
- */
- static void dwc2_hcd_rem_wakeup(struct dwc2_hsotg *hsotg)
- {
- if (hsotg->bus_suspended) {
- hsotg->flags.b.port_suspend_change = 1;
- usb_hcd_resume_root_hub(hsotg->priv);
- }
- if (hsotg->lx_state == DWC2_L1)
- hsotg->flags.b.port_l1_change = 1;
- }
- #endif
- /**
- * dwc2_hcd_stop() - Halts the DWC_otg host mode operations in a clean manner
- *
- * @hsotg: Pointer to struct dwc2_hsotg
- *
- * Must be called with interrupt disabled and spinlock held
- */
- void dwc2_hcd_stop(struct dwc2_hsotg *hsotg)
- {
- dev_dbg(hsotg->dev, "DWC OTG HCD STOP\n");
- /*
- * The root hub should be disconnected before this function is called.
- * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
- * and the QH lists (via ..._hcd_endpoint_disable).
- */
- /* Turn off all host-specific interrupts */
- dwc2_disable_host_interrupts(hsotg);
- /* Turn off the vbus power */
- dev_dbg(hsotg->dev, "PortPower off\n");
- dwc2_writel(0, hsotg->regs + HPRT0);
- }
- /* Caller must hold driver lock */
- static int dwc2_hcd_urb_enqueue(struct dwc2_hsotg *hsotg,
- struct dwc2_hcd_urb *urb, struct dwc2_qh *qh,
- struct dwc2_qtd *qtd)
- {
- u32 intr_mask;
- int retval;
- int dev_speed;
- if (!hsotg->flags.b.port_connect_status) {
- /* No longer connected */
- dev_err(hsotg->dev, "Not connected\n");
- return -ENODEV;
- }
- dev_speed = dwc2_host_get_speed(hsotg, urb->priv);
- /* Some configurations cannot support LS traffic on a FS root port */
- if ((dev_speed == USB_SPEED_LOW) &&
- (hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) &&
- (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI)) {
- u32 hprt0 = dwc2_readl(hsotg->regs + HPRT0);
- u32 prtspd = (hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT;
- if (prtspd == HPRT0_SPD_FULL_SPEED)
- return -ENODEV;
- }
- if (!qtd)
- return -EINVAL;
- dwc2_hcd_qtd_init(qtd, urb);
- retval = dwc2_hcd_qtd_add(hsotg, qtd, qh);
- if (retval) {
- dev_err(hsotg->dev,
- "DWC OTG HCD URB Enqueue failed adding QTD. Error status %d\n",
- retval);
- return retval;
- }
- intr_mask = dwc2_readl(hsotg->regs + GINTMSK);
- if (!(intr_mask & GINTSTS_SOF)) {
- enum dwc2_transaction_type tr_type;
- if (qtd->qh->ep_type == USB_ENDPOINT_XFER_BULK &&
- !(qtd->urb->flags & URB_GIVEBACK_ASAP))
- /*
- * Do not schedule SG transactions until qtd has
- * URB_GIVEBACK_ASAP set
- */
- return 0;
- tr_type = dwc2_hcd_select_transactions(hsotg);
- if (tr_type != DWC2_TRANSACTION_NONE)
- dwc2_hcd_queue_transactions(hsotg, tr_type);
- }
- return 0;
- }
- /* Must be called with interrupt disabled and spinlock held */
- static int dwc2_hcd_urb_dequeue(struct dwc2_hsotg *hsotg,
- struct dwc2_hcd_urb *urb)
- {
- struct dwc2_qh *qh;
- struct dwc2_qtd *urb_qtd;
- urb_qtd = urb->qtd;
- if (!urb_qtd) {
- dev_dbg(hsotg->dev, "## Urb QTD is NULL ##\n");
- return -EINVAL;
- }
- qh = urb_qtd->qh;
- if (!qh) {
- dev_dbg(hsotg->dev, "## Urb QTD QH is NULL ##\n");
- return -EINVAL;
- }
- urb->priv = NULL;
- if (urb_qtd->in_process && qh->channel) {
- /* The QTD is in process (it has been assigned to a channel) */
- if (hsotg->flags.b.port_connect_status)
- /*
- * If still connected (i.e. in host mode), halt the
- * channel so it can be used for other transfers. If
- * no longer connected, the host registers can't be
- * written to halt the channel since the core is in
- * device mode.
- */
- dwc2_hc_halt(hsotg, qh->channel,
- DWC2_HC_XFER_URB_DEQUEUE);
- }
- /*
- * Free the QTD and clean up the associated QH. Leave the QH in the
- * schedule if it has any remaining QTDs.
- */
- u8 in_process = urb_qtd->in_process;
- dwc2_hcd_qtd_unlink_and_free(hsotg, urb_qtd, qh);
- if (in_process) {
- dwc2_hcd_qh_deactivate(hsotg, qh, 0);
- qh->channel = NULL;
- } else if (list_empty(&qh->qtd_list)) {
- dwc2_hcd_qh_unlink(hsotg, qh);
- }
- return 0;
- }
- /* Must NOT be called with interrupt disabled or spinlock held */
- static int dwc2_hcd_endpoint_disable(struct dwc2_hsotg *hsotg,
- struct usb_host_endpoint *ep, int retry)
- {
- struct dwc2_qtd *qtd;//, *qtd_tmp;
- struct dwc2_qh *qh;
- unsigned long flags;
- int rc;
- spin_lock_irqsave(&hsotg->lock, flags);
- qh = ep->hcpriv;
- if (!qh) {
- rc = -EINVAL;
- goto err;
- }
- while (!list_empty(&qh->qtd_list) && retry--) {
- if (retry == 0) {
- dev_err(hsotg->dev,
- "## timeout in dwc2_hcd_endpoint_disable() ##\n");
- rc = -EBUSY;
- goto err;
- }
- spin_unlock_irqrestore(&hsotg->lock, flags);
- msleep(20);
- spin_lock_irqsave(&hsotg->lock, flags);
- qh = ep->hcpriv;
- if (!qh) {
- rc = -EINVAL;
- goto err;
- }
- }
- dwc2_hcd_qh_unlink(hsotg, qh);
- /* Free each QTD in the QH's QTD list */
- //list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry)
- ListItem_t *pxListItem, *nListItem;
- list_for_each_entry_safe(pxListItem, nListItem, qtd, &qh->qtd_list)
- dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
- ep->hcpriv = NULL;
- if (qh->channel && qh->channel->qh == qh)
- qh->channel->qh = NULL;
- spin_unlock_irqrestore(&hsotg->lock, flags);
- dwc2_hcd_qh_free(hsotg, qh);
- return 0;
- err:
- ep->hcpriv = NULL;
- spin_unlock_irqrestore(&hsotg->lock, flags);
- return rc;
- }
- /* Must be called with interrupt disabled and spinlock held */
- static int dwc2_hcd_endpoint_reset(struct dwc2_hsotg *hsotg,
- struct usb_host_endpoint *ep)
- {
- struct dwc2_qh *qh = ep->hcpriv;
- if (!qh)
- return -EINVAL;
- qh->data_toggle = DWC2_HC_PID_DATA0;
- return 0;
- }
- /**
- * dwc2_core_init() - Initializes the DWC_otg controller registers and
- * prepares the core for device mode or host mode operation
- *
- * @hsotg: Programming view of the DWC_otg controller
- * @initial_setup: If true then this is the first init for this instance.
- */
- static int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup)
- {
- u32 usbcfg, otgctl;
- int retval;
- dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg);
- usbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
- /* Set ULPI External VBUS bit if needed */
- usbcfg &= ~GUSBCFG_ULPI_EXT_VBUS_DRV;
- /* Set external TS Dline pulsing bit if needed */
- usbcfg &= ~GUSBCFG_TERMSELDLPULSE;
- dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
- /*
- * Reset the Controller
- *
- * We only need to reset the controller if this is a re-init.
- * For the first init we know for sure that earlier code reset us (it
- * needed to in order to properly detect various parameters).
- */
- if (!initial_setup) {
- retval = dwc2_core_reset_and_force_dr_mode(hsotg);
- if (retval) {
- dev_err(hsotg->dev, "%s(): Reset failed, aborting\n",
- __func__);
- return retval;
- }
- }
- /*
- * This needs to happen in FS mode before any other programming occurs
- */
- retval = dwc2_phy_init(hsotg, initial_setup);
- if (retval)
- return retval;
- /* Program the GAHBCFG Register */
- retval = dwc2_gahbcfg_init(hsotg);
- if (retval)
- return retval;
- /* Program the GUSBCFG register */
- dwc2_gusbcfg_init(hsotg);
- /* Program the GOTGCTL register */
- otgctl = dwc2_readl(hsotg->regs + GOTGCTL);
- otgctl &= ~GOTGCTL_OTGVER;
- dwc2_writel(otgctl, hsotg->regs + GOTGCTL);
- /* Clear the SRP success bit for FS-I2c */
- hsotg->srp_success = 0;
- /* Enable common interrupts */
- dwc2_enable_common_interrupts(hsotg);
- /*
- * Do device or host initialization based on mode during PCD and
- * HCD initialization
- */
- if (dwc2_is_host_mode(hsotg)) {
- dev_dbg(hsotg->dev, "Host Mode\n");
- hsotg->op_state = OTG_STATE_A_HOST;
- }
- return 0;
- }
- /**
- * dwc2_core_host_init() - Initializes the DWC_otg controller registers for
- * Host mode
- *
- * @hsotg: Programming view of DWC_otg controller
- *
- * This function flushes the Tx and Rx FIFOs and flushes any entries in the
- * request queues. Host channels are reset to ensure that they are ready for
- * performing transfers.
- */
- static void dwc2_core_host_init(struct dwc2_hsotg *hsotg)
- {
- u32 hcfg, hfir, otgctl, usbcfg;
- dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg);
- /* Set HS/FS Timeout Calibration to 7 (max available value).
- * The number of PHY clocks that the application programs in
- * this field is added to the high/full speed interpacket timeout
- * duration in the core to account for any additional delays
- * introduced by the PHY. This can be required, because the delay
- * introduced by the PHY in generating the linestate condition
- * can vary from one PHY to another.
- */
- usbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
- usbcfg |= GUSBCFG_TOUTCAL(7);
- dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
- /* Restart the Phy Clock */
- dwc2_writel(0, hsotg->regs + PCGCTL);
- /* Initialize Host Configuration Register */
- dwc2_init_fs_ls_pclk_sel(hsotg);
- if (hsotg->params.speed == DWC2_SPEED_PARAM_FULL ||
- hsotg->params.speed == DWC2_SPEED_PARAM_LOW) {
- hcfg = dwc2_readl(hsotg->regs + HCFG);
- hcfg |= HCFG_FSLSSUPP;
- dwc2_writel(hcfg, hsotg->regs + HCFG);
- }
- /*
- * This bit allows dynamic reloading of the HFIR register during
- * runtime. This bit needs to be programmed during initial configuration
- * and its value must not be changed during runtime.
- */
- if (hsotg->params.reload_ctl) {
- hfir = dwc2_readl(hsotg->regs + HFIR);
- hfir |= HFIR_RLDCTRL;
- dwc2_writel(hfir, hsotg->regs + HFIR);
- }
- /* Configure data FIFO sizes */
- dwc2_config_fifos(hsotg);
- /* TODO - check this */
- /* Clear Host Set HNP Enable in the OTG Control Register */
- otgctl = dwc2_readl(hsotg->regs + GOTGCTL);
- otgctl &= ~GOTGCTL_HSTSETHNPEN;
- dwc2_writel(otgctl, hsotg->regs + GOTGCTL);
- /* Make sure the FIFOs are flushed */
- dwc2_flush_tx_fifo(hsotg, 0x10 /* all TX FIFOs */);
- dwc2_flush_rx_fifo(hsotg);
- /* Clear Host Set HNP Enable in the OTG Control Register */
- otgctl = dwc2_readl(hsotg->regs + GOTGCTL);
- otgctl &= ~GOTGCTL_HSTSETHNPEN;
- dwc2_writel(otgctl, hsotg->regs + GOTGCTL);
- {
- int num_channels, i;
- u32 hcchar;
- /* Flush out any leftover queued requests */
- num_channels = hsotg->params.host_channels;
- for (i = 0; i < num_channels; i++) {
- hcchar = dwc2_readl(hsotg->regs + HCCHAR(i));
- hcchar &= ~HCCHAR_CHENA;
- hcchar |= HCCHAR_CHDIS;
- hcchar &= ~HCCHAR_EPDIR;
- dwc2_writel(hcchar, hsotg->regs + HCCHAR(i));
- }
- /* Halt all channels to put them into a known state */
- for (i = 0; i < num_channels; i++) {
- int count = 0;
- hcchar = dwc2_readl(hsotg->regs + HCCHAR(i));
- hcchar |= HCCHAR_CHENA | HCCHAR_CHDIS;
- hcchar &= ~HCCHAR_EPDIR;
- dwc2_writel(hcchar, hsotg->regs + HCCHAR(i));
- dev_dbg(hsotg->dev, "%s: Halt channel %d\n",
- __func__, i);
- do {
- hcchar = dwc2_readl(hsotg->regs + HCCHAR(i));
- if (++count > 1000) {
- dev_err(hsotg->dev,
- "Unable to clear enable on channel %d\n",
- i);
- break;
- }
- udelay(1);
- } while (hcchar & HCCHAR_CHENA);
- }
- }
- /* Turn on the vbus power */
- dev_dbg(hsotg->dev, "Init: Port Power? op_state=%d\n", hsotg->op_state);
- if (hsotg->op_state == OTG_STATE_A_HOST) {
- u32 hprt0 = dwc2_read_hprt0(hsotg);
- dev_dbg(hsotg->dev, "Init: Power Port (%d)\n",
- !!(hprt0 & HPRT0_PWR));
- if (!(hprt0 & HPRT0_PWR)) {
- hprt0 |= HPRT0_PWR;
- dwc2_writel(hprt0, hsotg->regs + HPRT0);
- }
- }
- dwc2_enable_host_interrupts(hsotg);
- }
- /*
- * Initializes dynamic portions of the DWC_otg HCD state
- *
- * Must be called with interrupt disabled and spinlock held
- */
- static void dwc2_hcd_reinit(struct dwc2_hsotg *hsotg)
- {
- struct dwc2_host_chan *chan;//, *chan_tmp;
- int num_channels;
- int i;
- #if 1
- hsotg->flags.d32 = 0;
- hsotg->non_periodic_qh_ptr = (ListItem_t *)listGET_END_MARKER(&hsotg->non_periodic_sched_active);
- //hsotg->non_periodic_qh_ptr = listGET_HEAD_ENTRY(&hsotg->non_periodic_sched_active);
- hsotg->non_periodic_channels = 0;
- /*
- * Put all channels in the free channel list and clean up channel
- * states
- */
- /*list_for_each_entry_safe(chan, chan_tmp, &hsotg->free_hc_list,
- hc_list_entry)*/
- ListItem_t *pxListItem, *nListItem;
- list_for_each_entry_safe(pxListItem, nListItem, chan, &hsotg->free_hc_list)
- list_del_init(&chan->hc_list_entry);
- num_channels = hsotg->params.host_channels;
- for (i = 0; i < num_channels; i++) {
- chan = hsotg->hc_ptr_array[i];
- list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list);
- dwc2_hc_cleanup(hsotg, chan);
- }
- #endif
- /* Initialize the DWC core for host mode operation */
- dwc2_core_host_init(hsotg);
- }
- static void dwc2_hc_init_split(struct dwc2_hsotg *hsotg,
- struct dwc2_host_chan *chan,
- struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb)
- {
- int hub_addr, hub_port;
- chan->do_split = 1;
- chan->xact_pos = qtd->isoc_split_pos;
- chan->complete_split = qtd->complete_split;
- dwc2_host_hub_info(hsotg, urb->priv, &hub_addr, &hub_port);
- chan->hub_addr = (u8)hub_addr;
- chan->hub_port = (u8)hub_port;
- }
- static void dwc2_hc_init_xfer(struct dwc2_hsotg *hsotg,
- struct dwc2_host_chan *chan,
- struct dwc2_qtd *qtd)
- {
- struct dwc2_hcd_urb *urb = qtd->urb;
- switch (dwc2_hcd_get_pipe_type(&urb->pipe_info)) {
- case USB_ENDPOINT_XFER_CONTROL:
- chan->ep_type = USB_ENDPOINT_XFER_CONTROL;
- switch (qtd->control_phase) {
- case DWC2_CONTROL_SETUP:
- dev_vdbg(hsotg->dev, " ##Control setup transaction\n");
- chan->do_ping = 0;
- chan->ep_is_in = 0;
- chan->data_pid_start = DWC2_HC_PID_SETUP;
- chan->xfer_buf = urb->setup_packet;
- chan->xfer_len = 8;
- //unsigned char *a = urb->setup_packet;
- //if (a)
- //printf("xfer setup-->%02x %02x %02x %02x %02x %02x %02x %02x\r\n", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
- break;
- case DWC2_CONTROL_DATA:
- dev_vdbg(hsotg->dev, " Control data transaction\n");
- chan->data_pid_start = qtd->data_toggle;
- break;
- case DWC2_CONTROL_STATUS:
- /*
- * Direction is opposite of data direction or IN if no
- * data
- */
- dev_vdbg(hsotg->dev, " Control status transaction\n");
- if (urb->length == 0)
- chan->ep_is_in = 1;
- else
- chan->ep_is_in =
- dwc2_hcd_is_pipe_out(&urb->pipe_info);
- if (chan->ep_is_in)
- chan->do_ping = 0;
- chan->data_pid_start = DWC2_HC_PID_DATA1;
- chan->xfer_len = 0;
- chan->xfer_buf = hsotg->status_buf;
- break;
- }
- break;
- case USB_ENDPOINT_XFER_BULK:
- chan->ep_type = USB_ENDPOINT_XFER_BULK;
- break;
- }
- }
- /**
- * dwc2_assign_and_init_hc() - Assigns transactions from a QTD to a free host
- * channel and initializes the host channel to perform the transactions. The
- * host channel is removed from the free list.
- *
- * @hsotg: The HCD state structure
- * @qh: Transactions from the first QTD for this QH are selected and assigned
- * to a free host channel
- */
- static int dwc2_assign_and_init_hc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
- {
- struct dwc2_host_chan *chan;
- struct dwc2_hcd_urb *urb;
- struct dwc2_qtd *qtd;
- if (dbg_qh(qh))
- dev_vdbg(hsotg->dev, "%s(%p,%p)\n", __func__, hsotg, qh);
- if (list_empty(&qh->qtd_list)) {
- dev_dbg(hsotg->dev, "No QTDs in QH list\n");
- return -ENOMEM;
- }
- if (list_empty(&hsotg->free_hc_list)) {
- dev_dbg(hsotg->dev, "No free channel to assign\n");
- return -ENOMEM;
- }
- chan = list_first_entry(&hsotg->free_hc_list);
- /* Remove host channel from free list */
- list_del_init(&chan->hc_list_entry);
- qtd = list_first_entry(&qh->qtd_list);
- urb = qtd->urb;
- qh->channel = chan;
- qtd->in_process = 1;
- /*
- * Use usb_pipedevice to determine device address. This address is
- * 0 before the SET_ADDRESS command and the correct address afterward.
- */
- chan->dev_addr = dwc2_hcd_get_dev_addr(&urb->pipe_info);
- chan->ep_num = dwc2_hcd_get_ep_num(&urb->pipe_info);
- chan->speed = qh->dev_speed;
- chan->max_packet = dwc2_max_packet(qh->maxp);
- chan->xfer_started = 0;
- chan->halt_status = DWC2_HC_XFER_NO_HALT_STATUS;
- chan->error_state = (qtd->error_count > 0);
- chan->halt_on_queue = 0;
- chan->halt_pending = 0;
- chan->requests = 0;
- /*
- * The following values may be modified in the transfer type section
- * below. The xfer_len value may be reduced when the transfer is
- * started to accommodate the max widths of the XferSize and PktCnt
- * fields in the HCTSIZn register.
- */
- chan->ep_is_in = (dwc2_hcd_is_pipe_in(&urb->pipe_info) != 0);
- if (chan->ep_is_in)
- chan->do_ping = 0;
- else
- chan->do_ping = qh->ping_state;
- chan->data_pid_start = qh->data_toggle;
- chan->multi_count = 1;
- if (urb->actual_length > urb->length &&
- !dwc2_hcd_is_pipe_in(&urb->pipe_info))
- urb->actual_length = urb->length;
- chan->xfer_buf = (u8 *)urb->buf + urb->actual_length;
- chan->xfer_len = urb->length - urb->actual_length;
- chan->xfer_count = 0;
- /* Set the split attributes if required */
- if (qh->do_split)
- dwc2_hc_init_split(hsotg, chan, qtd, urb);
- else
- chan->do_split = 0;
- /* Set the transfer attributes */
- dwc2_hc_init_xfer(hsotg, chan, qtd);
- /* For non-dword aligned buffers */
- /*
- * We assume that DMA is always aligned in non-split
- * case or split out case. Warn if not.
- */
- chan->align_buf = 0;
- dwc2_hc_init(hsotg, chan);
- chan->qh = qh;
- return 0;
- }
- /**
- * dwc2_hcd_select_transactions() - Selects transactions from the HCD transfer
- * schedule and assigns them to available host channels. Called from the HCD
- * interrupt handler functions.
- *
- * @hsotg: The HCD state structure
- *
- * Return: The types of new transactions that were assigned to host channels
- */
- enum dwc2_transaction_type dwc2_hcd_select_transactions(
- struct dwc2_hsotg *hsotg)
- {
- enum dwc2_transaction_type ret_val = DWC2_TRANSACTION_NONE;
- ListItem_t* qh_ptr;
- struct dwc2_qh *qh;
- int num_channels;
- #ifdef DWC2_DEBUG_SOF
- dev_vdbg(hsotg->dev, " Select Transactions\n");
- #endif
- /*
- * Process entries in the inactive portion of the non-periodic
- * schedule. Some free host channels may not be used if they are
- * reserved for periodic transfers.
- */
- num_channels = hsotg->params.host_channels;
- qh_ptr = listGET_HEAD_ENTRY(&hsotg->non_periodic_sched_inactive);
- while (qh_ptr != listGET_END_MARKER(&hsotg->non_periodic_sched_inactive)) {
- if (hsotg->non_periodic_channels >= num_channels)
- break;
- if (list_empty(&hsotg->free_hc_list))
- break;
- qh = list_entry(qh_ptr);
- if (dwc2_assign_and_init_hc(hsotg, qh))
- break;
- //printf("dwc2_hcd_select_transactions:2949\r\n");
- /*
- * Move the QH from the non-periodic inactive schedule to the
- * non-periodic active schedule
- */
- qh_ptr = listGET_NEXT(qh_ptr);
- list_move_tail(&qh->qh_list_entry,
- &hsotg->non_periodic_sched_active);
- if (ret_val == DWC2_TRANSACTION_NONE)
- ret_val = DWC2_TRANSACTION_NON_PERIODIC;
- else
- ret_val = DWC2_TRANSACTION_ALL;
- }
- return ret_val;
- }
- /**
- * dwc2_queue_transaction() - Attempts to queue a single transaction request for
- * a host channel associated with either a periodic or non-periodic transfer
- *
- * @hsotg: The HCD state structure
- * @chan: Host channel descriptor associated with either a periodic or
- * non-periodic transfer
- * @fifo_dwords_avail: Number of DWORDs available in the periodic Tx FIFO
- * for periodic transfers or the non-periodic Tx FIFO
- * for non-periodic transfers
- *
- * Return: 1 if a request is queued and more requests may be needed to
- * complete the transfer, 0 if no more requests are required for this
- * transfer, -1 if there is insufficient space in the Tx FIFO
- *
- * This function assumes that there is space available in the appropriate
- * request queue. For an OUT transfer or SETUP transaction in Slave mode,
- * it checks whether space is available in the appropriate Tx FIFO.
- *
- * Must be called with interrupt disabled and spinlock held
- */
- static int dwc2_queue_transaction(struct dwc2_hsotg *hsotg,
- struct dwc2_host_chan *chan,
- u16 fifo_dwords_avail)
- {
- int retval = 0;
- if (chan->do_split)
- /* Put ourselves on the list to keep order straight */
- list_move_tail(&chan->split_order_list_entry,
- &hsotg->split_order);
- if (chan->halt_pending) {
- /* Don't queue a request if the channel has been halted */
- } else if (chan->halt_on_queue) {
- dwc2_hc_halt(hsotg, chan, chan->halt_status);
- } else if (chan->do_ping) {
- if (!chan->xfer_started)
- dwc2_hc_start_transfer(hsotg, chan);
- } else if (!chan->ep_is_in ||
- chan->data_pid_start == DWC2_HC_PID_SETUP) {
- if ((fifo_dwords_avail * 4) >= chan->max_packet) {
- if (!chan->xfer_started) {
- dwc2_hc_start_transfer(hsotg, chan);
- retval = 1;
- } else {
- retval = dwc2_hc_continue_transfer(hsotg, chan);
- }
- } else {
- retval = -1;
- }
- } else {
- if (!chan->xfer_started) {
- dwc2_hc_start_transfer(hsotg, chan);
- retval = 1;
- } else {
- retval = dwc2_hc_continue_transfer(hsotg, chan);
- }
- }
- return retval;
- }
- /*
- * Processes active non-periodic channels and queues transactions for these
- * channels to the DWC_otg controller. After queueing transactions, the NP Tx
- * FIFO Empty interrupt is enabled if there are more transactions to queue as
- * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
- * FIFO Empty interrupt is disabled.
- *
- * Must be called with interrupt disabled and spinlock held
- */
- static void dwc2_process_non_periodic_channels(struct dwc2_hsotg *hsotg)
- {
- ListItem_t *orig_qh_ptr = NULL;
- struct dwc2_qh *qh;
- u32 tx_status;
- u32 qspcavail;
- u32 fspcavail;
- u32 gintmsk;
- int status;
- int no_queue_space = 0;
- int no_fifo_space = 0;
- int more_to_do = 0;
- dev_vdbg(hsotg->dev, "Queue non-periodic transactions\n");
- tx_status = dwc2_readl(hsotg->regs + GNPTXSTS);
- qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >>
- TXSTS_QSPCAVAIL_SHIFT;
- fspcavail = (tx_status & TXSTS_FSPCAVAIL_MASK) >>
- TXSTS_FSPCAVAIL_SHIFT;
- dev_vdbg(hsotg->dev, " NP Tx Req Queue Space Avail (before queue): %d\n",
- qspcavail);
- dev_vdbg(hsotg->dev, " NP Tx FIFO Space Avail (before queue): %d\n",
- fspcavail);
- /*
- * Keep track of the starting point. Skip over the start-of-list
- * entry.
- */
- if (hsotg->non_periodic_qh_ptr == listGET_END_MARKER(&hsotg->non_periodic_sched_active)) {
- hsotg->non_periodic_qh_ptr = listGET_HEAD_ENTRY(&hsotg->non_periodic_sched_active);
- }
- //orig_qh_ptr = hsotg->non_periodic_qh_ptr;
- orig_qh_ptr = hsotg->non_periodic_qh_ptr;
- /*
- * Process once through the active list or until no more space is
- * available in the request queue or the Tx FIFO
- */
- do {
- tx_status = dwc2_readl(hsotg->regs + GNPTXSTS);
- qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >>
- TXSTS_QSPCAVAIL_SHIFT;
- if (qspcavail == 0) {
- no_queue_space = 1;
- break;
- }
- qh = list_entry(hsotg->non_periodic_qh_ptr);
- if (!qh->channel)
- goto next;
- /* Make sure EP's TT buffer is clean before queueing qtds */
- if (qh->tt_buffer_dirty)
- goto next;
- fspcavail = (tx_status & TXSTS_FSPCAVAIL_MASK) >>
- TXSTS_FSPCAVAIL_SHIFT;//printf("%s:%d\r\n", __func__, __LINE__);
- status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail);
- //printf("%s:%d\r\n", __func__, __LINE__);
- if (status > 0) {
- more_to_do = 1;
- } else if (status < 0) {
- no_fifo_space = 1;
- break;
- }
- next:
- /* Advance to next QH, skipping start-of-list entry */
- hsotg->non_periodic_qh_ptr = listGET_NEXT(hsotg->non_periodic_qh_ptr);
- if (hsotg->non_periodic_qh_ptr ==
- listGET_END_MARKER(&hsotg->non_periodic_sched_active))
- hsotg->non_periodic_qh_ptr = listGET_NEXT(hsotg->non_periodic_qh_ptr);
- } while (hsotg->non_periodic_qh_ptr != orig_qh_ptr);
- tx_status = dwc2_readl(hsotg->regs + GNPTXSTS);
- qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >>
- TXSTS_QSPCAVAIL_SHIFT;
- fspcavail = (tx_status & TXSTS_FSPCAVAIL_MASK) >>
- TXSTS_FSPCAVAIL_SHIFT;
- dev_vdbg(hsotg->dev,
- " NP Tx Req Queue Space Avail (after queue): %d\n",
- qspcavail);
- dev_vdbg(hsotg->dev,
- " NP Tx FIFO Space Avail (after queue): %d\n",
- fspcavail);
- if (more_to_do || no_queue_space || no_fifo_space) {
- /*
- * May need to queue more transactions as the request
- * queue or Tx FIFO empties. Enable the non-periodic
- * Tx FIFO empty interrupt. (Always use the half-empty
- * level to ensure that new requests are loaded as
- * soon as possible.)
- */
- gintmsk = dwc2_readl(hsotg->regs + GINTMSK);
- gintmsk |= GINTSTS_NPTXFEMP;
- dwc2_writel(gintmsk, hsotg->regs + GINTMSK);
- } else {
- /*
- * Disable the Tx FIFO empty interrupt since there are
- * no more transactions that need to be queued right
- * now. This function is called from interrupt
- * handlers to queue more transactions as transfer
- * states change.
- */
- gintmsk = dwc2_readl(hsotg->regs + GINTMSK);
- gintmsk &= ~GINTSTS_NPTXFEMP;
- dwc2_writel(gintmsk, hsotg->regs + GINTMSK);
- }
- }
- /**
- * dwc2_hcd_queue_transactions() - Processes the currently active host channels
- * and queues transactions for these channels to the DWC_otg controller. Called
- * from the HCD interrupt handler functions.
- *
- * @hsotg: The HCD state structure
- * @tr_type: The type(s) of transactions to queue (non-periodic, periodic,
- * or both)
- *
- * Must be called with interrupt disabled and spinlock held
- */
- void dwc2_hcd_queue_transactions(struct dwc2_hsotg *hsotg,
- enum dwc2_transaction_type tr_type)
- {
- #ifdef DWC2_DEBUG_SOF
- dev_vdbg(hsotg->dev, "Queue Transactions\n");
- #endif
- /* Process host channels associated with non-periodic transfers */
- if (tr_type == DWC2_TRANSACTION_NON_PERIODIC ||
- tr_type == DWC2_TRANSACTION_ALL) {
- if (!list_empty(&hsotg->non_periodic_sched_active)) {
- dwc2_process_non_periodic_channels(hsotg);
- } else {
- /*
- * Ensure NP Tx FIFO empty interrupt is disabled when
- * there are no non-periodic transfers to process
- */
- u32 gintmsk = dwc2_readl(hsotg->regs + GINTMSK);
- gintmsk &= ~GINTSTS_NPTXFEMP;
- dwc2_writel(gintmsk, hsotg->regs + GINTMSK);
- }
- }
- }
- static int dwc2_host_is_b_hnp_enabled(struct dwc2_hsotg *hsotg)
- {
- struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg);
- return hcd->self.b_hnp_enable;
- }
- /* Must NOT be called with interrupt disabled or spinlock held */
- static void dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
- {
- unsigned long flags;
- u32 hprt0;
- u32 pcgctl;
- u32 gotgctl;
- dev_dbg(hsotg->dev, "%s()\n", __func__);
- spin_lock_irqsave(&hsotg->lock, flags);
- if (windex == hsotg->otg_port && dwc2_host_is_b_hnp_enabled(hsotg)) {
- gotgctl = dwc2_readl(hsotg->regs + GOTGCTL);
- gotgctl |= GOTGCTL_HSTSETHNPEN;
- dwc2_writel(gotgctl, hsotg->regs + GOTGCTL);
- hsotg->op_state = OTG_STATE_A_SUSPEND;
- }
- hprt0 = dwc2_read_hprt0(hsotg);
- hprt0 |= HPRT0_SUSP;
- dwc2_writel(hprt0, hsotg->regs + HPRT0);
- hsotg->bus_suspended = true;
- /*
- * If hibernation is supported, Phy clock will be suspended
- * after registers are backuped.
- */
- /* Suspend the Phy Clock */
- pcgctl = dwc2_readl(hsotg->regs + PCGCTL);
- pcgctl |= PCGCTL_STOPPCLK;
- dwc2_writel(pcgctl, hsotg->regs + PCGCTL);
- udelay(10);
- /* For HNP the bus must be suspended for at least 200ms */
- if (dwc2_host_is_b_hnp_enabled(hsotg)) {
- pcgctl = dwc2_readl(hsotg->regs + PCGCTL);
- pcgctl &= ~PCGCTL_STOPPCLK;
- dwc2_writel(pcgctl, hsotg->regs + PCGCTL);
- spin_unlock_irqrestore(&hsotg->lock, flags);
- msleep(200);
- } else {
- spin_unlock_irqrestore(&hsotg->lock, flags);
- }
- }
- /* Must NOT be called with interrupt disabled or spinlock held */
- static void dwc2_port_resume(struct dwc2_hsotg *hsotg)
- {
- unsigned long flags;
- u32 hprt0;
- u32 pcgctl;
- spin_lock_irqsave(&hsotg->lock, flags);
- /*
- * If hibernation is supported, Phy clock is already resumed
- * after registers restore.
- */
- pcgctl = dwc2_readl(hsotg->regs + PCGCTL);
- pcgctl &= ~PCGCTL_STOPPCLK;
- dwc2_writel(pcgctl, hsotg->regs + PCGCTL);
- spin_unlock_irqrestore(&hsotg->lock, flags);
- msleep(20);
- spin_lock_irqsave(&hsotg->lock, flags);
- hprt0 = dwc2_read_hprt0(hsotg);
- hprt0 |= HPRT0_RES;
- hprt0 &= ~HPRT0_SUSP;
- dwc2_writel(hprt0, hsotg->regs + HPRT0);
- spin_unlock_irqrestore(&hsotg->lock, flags);
- msleep(USB_RESUME_TIMEOUT);
- spin_lock_irqsave(&hsotg->lock, flags);
- hprt0 = dwc2_read_hprt0(hsotg);
- hprt0 &= ~(HPRT0_RES | HPRT0_SUSP);
- dwc2_writel(hprt0, hsotg->regs + HPRT0);
- hsotg->bus_suspended = false;
- spin_unlock_irqrestore(&hsotg->lock, flags);
- }
- /* Handles hub class-specific requests */
- static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq,
- u16 wvalue, u16 windex, char *buf, u16 wlength)
- {
- struct usb_hub_descriptor *hub_desc;
- int retval = 0;
- u32 hprt0;
- u32 port_status;
- u32 speed;
- u32 pcgctl;//printf("GetPortStatus:%x\n", GetPortStatus);
- switch (typereq) {
- case ClearHubFeature:
- dev_dbg(hsotg->dev, "ClearHubFeature %1xh\n", wvalue);
- switch (wvalue) {
- case C_HUB_LOCAL_POWER:
- case C_HUB_OVER_CURRENT:
- /* Nothing required here */
- break;
- default:
- retval = -EINVAL;
- dev_err(hsotg->dev,
- "ClearHubFeature request %1xh unknown\n",
- wvalue);
- }
- break;
- case ClearPortFeature:
- if (wvalue != USB_PORT_FEAT_L1)
- if (!windex || windex > 1)
- goto error;
- switch (wvalue) {
- case USB_PORT_FEAT_ENABLE:
- dev_dbg(hsotg->dev,
- "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
- hprt0 = dwc2_read_hprt0(hsotg);
- hprt0 |= HPRT0_ENA;
- dwc2_writel(hprt0, hsotg->regs + HPRT0);
- break;
- case USB_PORT_FEAT_SUSPEND:
- dev_dbg(hsotg->dev,
- "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
- if (hsotg->bus_suspended)
- dwc2_port_resume(hsotg);
- break;
- case USB_PORT_FEAT_POWER:
- dev_dbg(hsotg->dev,
- "ClearPortFeature USB_PORT_FEAT_POWER\n");
- hprt0 = dwc2_read_hprt0(hsotg);
- hprt0 &= ~HPRT0_PWR;
- dwc2_writel(hprt0, hsotg->regs + HPRT0);
- break;
- case USB_PORT_FEAT_INDICATOR:
- dev_dbg(hsotg->dev,
- "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
- /* Port indicator not supported */
- break;
- case USB_PORT_FEAT_C_CONNECTION:
- /*
- * Clears driver's internal Connect Status Change flag
- */
- dev_dbg(hsotg->dev,
- "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
- hsotg->flags.b.port_connect_status_change = 0;
- break;
- case USB_PORT_FEAT_C_RESET:
- /* Clears driver's internal Port Reset Change flag */
- dev_dbg(hsotg->dev,
- "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
- hsotg->flags.b.port_reset_change = 0;
- break;
- case USB_PORT_FEAT_C_ENABLE:
- /*
- * Clears the driver's internal Port Enable/Disable
- * Change flag
- */
- dev_dbg(hsotg->dev,
- "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
- hsotg->flags.b.port_enable_change = 0;
- break;
- case USB_PORT_FEAT_C_SUSPEND:
- /*
- * Clears the driver's internal Port Suspend Change
- * flag, which is set when resume signaling on the host
- * port is complete
- */
- dev_dbg(hsotg->dev,
- "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
- hsotg->flags.b.port_suspend_change = 0;
- break;
- case USB_PORT_FEAT_C_PORT_L1:
- dev_dbg(hsotg->dev,
- "ClearPortFeature USB_PORT_FEAT_C_PORT_L1\n");
- hsotg->flags.b.port_l1_change = 0;
- break;
- case USB_PORT_FEAT_C_OVER_CURRENT:
- dev_dbg(hsotg->dev,
- "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
- hsotg->flags.b.port_over_current_change = 0;
- break;
- default:
- retval = -EINVAL;
- dev_err(hsotg->dev,
- "ClearPortFeature request %1xh unknown or unsupported\n",
- wvalue);
- }
- break;
- case GetHubDescriptor:
- dev_dbg(hsotg->dev, "GetHubDescriptor\n");
- hub_desc = (struct usb_hub_descriptor *)buf;
- hub_desc->bLength = 9;
- hub_desc->bDescriptorType = USB_DT_HUB;
- hub_desc->bNbrPorts = 1;
- hub_desc->wHubCharacteristics =
- cpu_to_le16(HUB_CHAR_COMMON_LPSM |
- HUB_CHAR_INDV_PORT_OCPM);
- hub_desc->bPwrOn2PwrGood = 1;
- hub_desc->bHubContrCurrent = 0;
- hub_desc->u.hs.DeviceRemovable[0] = 0;
- hub_desc->u.hs.DeviceRemovable[1] = 0xff;
- break;
- case GetHubStatus:
- dev_dbg(hsotg->dev, "GetHubStatus\n");
- memset(buf, 0, 4);
- break;
- case GetPortStatus:
- dev_vdbg(hsotg->dev,
- "GetPortStatus wIndex=0x%04x flags=0x%08x\n", windex,
- hsotg->flags.d32);
- if (!windex || windex > 1)
- goto error;
- port_status = 0;
- if (hsotg->flags.b.port_connect_status_change)
- port_status |= USB_PORT_STAT_C_CONNECTION << 16;
- if (hsotg->flags.b.port_enable_change)
- port_status |= USB_PORT_STAT_C_ENABLE << 16;
- if (hsotg->flags.b.port_suspend_change)
- port_status |= USB_PORT_STAT_C_SUSPEND << 16;
- if (hsotg->flags.b.port_l1_change)
- port_status |= USB_PORT_STAT_C_L1 << 16;
- if (hsotg->flags.b.port_reset_change)
- port_status |= USB_PORT_STAT_C_RESET << 16;
- if (hsotg->flags.b.port_over_current_change) {
- dev_warn(hsotg->dev, "Overcurrent change detected\n");
- port_status |= USB_PORT_STAT_C_OVERCURRENT << 16;
- }
- if (!hsotg->flags.b.port_connect_status) {
- /*
- * The port is disconnected, which means the core is
- * either in device mode or it soon will be. Just
- * return 0's for the remainder of the port status
- * since the port register can't be read if the core
- * is in device mode.
- */
- *(__le32 *)buf = cpu_to_le32(port_status);
- break;
- }
- hprt0 = dwc2_readl(hsotg->regs + HPRT0);
- dev_vdbg(hsotg->dev, " HPRT0: 0x%08x\n", hprt0);
- if (hprt0 & HPRT0_CONNSTS)
- port_status |= USB_PORT_STAT_CONNECTION;
- if (hprt0 & HPRT0_ENA)
- port_status |= USB_PORT_STAT_ENABLE;
- if (hprt0 & HPRT0_SUSP)
- port_status |= USB_PORT_STAT_SUSPEND;
- if (hprt0 & HPRT0_OVRCURRACT)
- port_status |= USB_PORT_STAT_OVERCURRENT;
- if (hprt0 & HPRT0_RST)
- port_status |= USB_PORT_STAT_RESET;
- if (hprt0 & HPRT0_PWR)
- port_status |= USB_PORT_STAT_POWER;
- speed = (hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT;
- if (speed == HPRT0_SPD_HIGH_SPEED)
- port_status |= USB_PORT_STAT_HIGH_SPEED;
- else if (speed == HPRT0_SPD_LOW_SPEED)
- port_status |= USB_PORT_STAT_LOW_SPEED;
- if (hprt0 & HPRT0_TSTCTL_MASK)
- port_status |= USB_PORT_STAT_TEST;
- /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
- dev_vdbg(hsotg->dev, "port_status=%08x\n", port_status);
- *(__le32 *)buf = cpu_to_le32(port_status);
- break;
- case SetHubFeature:
- dev_dbg(hsotg->dev, "SetHubFeature\n");
- /* No HUB features supported */
- break;
- case SetPortFeature:
- dev_dbg(hsotg->dev, "SetPortFeature\n");
- if (wvalue != USB_PORT_FEAT_TEST && (!windex || windex > 1))
- goto error;
- if (!hsotg->flags.b.port_connect_status) {
- /*
- * The port is disconnected, which means the core is
- * either in device mode or it soon will be. Just
- * return without doing anything since the port
- * register can't be written if the core is in device
- * mode.
- */
- break;
- }
- switch (wvalue) {
- case USB_PORT_FEAT_SUSPEND:
- dev_dbg(hsotg->dev,
- "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
- if (windex != hsotg->otg_port)
- goto error;
- dwc2_port_suspend(hsotg, windex);
- break;
- case USB_PORT_FEAT_POWER:
- dev_dbg(hsotg->dev,
- "SetPortFeature - USB_PORT_FEAT_POWER\n");
- hprt0 = dwc2_read_hprt0(hsotg);
- hprt0 |= HPRT0_PWR;
- dwc2_writel(hprt0, hsotg->regs + HPRT0);
- break;
- case USB_PORT_FEAT_RESET:
- hprt0 = dwc2_read_hprt0(hsotg);
- dev_dbg(hsotg->dev,
- "SetPortFeature - USB_PORT_FEAT_RESET\n");
- pcgctl = dwc2_readl(hsotg->regs + PCGCTL);
- pcgctl &= ~(PCGCTL_ENBL_SLEEP_GATING | PCGCTL_STOPPCLK);
- dwc2_writel(pcgctl, hsotg->regs + PCGCTL);
- /* ??? Original driver does this */
- dwc2_writel(0, hsotg->regs + PCGCTL);
- hprt0 = dwc2_read_hprt0(hsotg);
- /* Clear suspend bit if resetting from suspend state */
- hprt0 &= ~HPRT0_SUSP;
- /*
- * When B-Host the Port reset bit is set in the Start
- * HCD Callback function, so that the reset is started
- * within 1ms of the HNP success interrupt
- */
- if (!dwc2_hcd_is_b_host(hsotg)) {
- hprt0 |= HPRT0_PWR | HPRT0_RST;
- dev_dbg(hsotg->dev,
- "In host mode, hprt0=%08x\n", hprt0);
- dwc2_writel(hprt0, hsotg->regs + HPRT0);
- }
- /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
- msleep(50);
- hprt0 &= ~HPRT0_RST;
- dwc2_writel(hprt0, hsotg->regs + HPRT0);
- hsotg->lx_state = DWC2_L0; /* Now back to On state */
- break;
- case USB_PORT_FEAT_INDICATOR:
- dev_dbg(hsotg->dev,
- "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
- /* Not supported */
- break;
- case USB_PORT_FEAT_TEST:
- hprt0 = dwc2_read_hprt0(hsotg);
- dev_dbg(hsotg->dev,
- "SetPortFeature - USB_PORT_FEAT_TEST\n");
- hprt0 &= ~HPRT0_TSTCTL_MASK;
- hprt0 |= (windex >> 8) << HPRT0_TSTCTL_SHIFT;
- dwc2_writel(hprt0, hsotg->regs + HPRT0);
- break;
- default:
- retval = -EINVAL;
- dev_err(hsotg->dev,
- "SetPortFeature %1xh unknown or unsupported\n",
- wvalue);
- break;
- }
- break;
- default:
- error:
- retval = -EINVAL;
- dev_dbg(hsotg->dev,
- "Unknown hub control request: %1xh wIndex: %1xh wValue: %1xh\n",
- typereq, windex, wvalue);
- break;
- }
- return retval;
- }
- static int dwc2_hcd_is_status_changed(struct dwc2_hsotg *hsotg, int port)
- {
- int retval;
- if (port != 1)
- return -EINVAL;
- retval = (hsotg->flags.b.port_connect_status_change ||
- hsotg->flags.b.port_reset_change ||
- hsotg->flags.b.port_enable_change ||
- hsotg->flags.b.port_suspend_change ||
- hsotg->flags.b.port_over_current_change);
- /*printf("%d %d %d %d %d\r\n", hsotg->flags.b.port_connect_status_change,
- hsotg->flags.b.port_reset_change ,
- hsotg->flags.b.port_enable_change ,
- hsotg->flags.b.port_suspend_change ,
- hsotg->flags.b.port_over_current_change);*/
- if (retval) {
- dev_dbg(hsotg->dev,
- "DWC OTG HCD HUB STATUS DATA: Root port status changed\n");
- dev_dbg(hsotg->dev, " port_connect_status_change: %d\n",
- hsotg->flags.b.port_connect_status_change);
- dev_dbg(hsotg->dev, " port_reset_change: %d\n",
- hsotg->flags.b.port_reset_change);
- dev_dbg(hsotg->dev, " port_enable_change: %d\n",
- hsotg->flags.b.port_enable_change);
- dev_dbg(hsotg->dev, " port_suspend_change: %d\n",
- hsotg->flags.b.port_suspend_change);
- dev_dbg(hsotg->dev, " port_over_current_change: %d\n",
- hsotg->flags.b.port_over_current_change);
- }
- return retval;
- }
- int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
- {
- u32 hfnum = dwc2_readl(hsotg->regs + HFNUM);
- #ifdef DWC2_DEBUG_SOF
- dev_vdbg(hsotg->dev, "DWC OTG HCD GET FRAME NUMBER %d\n",
- (hfnum & HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT);
- #endif
- return (hfnum & HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT;
- }
- int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us)
- {
- u32 hprt = dwc2_readl(hsotg->regs + HPRT0);
- u32 hfir = dwc2_readl(hsotg->regs + HFIR);
- u32 hfnum = dwc2_readl(hsotg->regs + HFNUM);
- unsigned int us_per_frame;
- unsigned int frame_number;
- unsigned int remaining;
- unsigned int interval;
- unsigned int phy_clks;
- /* High speed has 125 us per (micro) frame; others are 1 ms per */
- us_per_frame = (hprt & HPRT0_SPD_MASK) ? 1000 : 125;
- /* Extract fields */
- frame_number = (hfnum & HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT;
- remaining = (hfnum & HFNUM_FRREM_MASK) >> HFNUM_FRREM_SHIFT;
- interval = (hfir & HFIR_FRINT_MASK) >> HFIR_FRINT_SHIFT;
- /*
- * Number of phy clocks since the last tick of the frame number after
- * "us" has passed.
- */
- phy_clks = (interval - remaining) +
- DIV_ROUND_UP(interval * us, us_per_frame);
- return dwc2_frame_num_inc(frame_number, phy_clks / interval);
- }
- int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg)
- {
- return hsotg->op_state == OTG_STATE_B_HOST;
- }
- static struct dwc2_hcd_urb *dwc2_hcd_urb_alloc(struct dwc2_hsotg *hsotg,
- int iso_desc_count,
- gfp_t mem_flags)
- {
- struct dwc2_hcd_urb *urb;
- u32 size = sizeof(*urb) + iso_desc_count;
- ListItem_t *pxListItem = NULL;
- int found = 0, flags;
- spin_lock_irqsave(&hsotg->lock, flags);
- list_for_each_entry(pxListItem, urb, &hsotg->free_urb_list) {
- if (urb && urb->packet_count == iso_desc_count) {
- found = 1;
- break;
- }
- }
- if (found) {
- list_del_init(&urb->free_list_entry);
- spin_unlock_irqrestore(&hsotg->lock, flags);
- memset(urb, 0, sizeof(struct dwc2_hcd_urb));
- INIT_LIST_ITEM(&urb->free_list_entry);
- listSET_LIST_ITEM_OWNER(&urb->free_list_entry, urb);
- return urb;
- }
- spin_unlock_irqrestore(&hsotg->lock, flags);
- urb = (struct dwc2_hcd_urb *)kzalloc(size, mem_flags);
- if (urb)
- urb->packet_count = iso_desc_count;
- if (urb) {
- INIT_LIST_ITEM(&urb->free_list_entry);
- listSET_LIST_ITEM_OWNER(&urb->free_list_entry, urb);
- }
- return urb;
- }
- static struct dwc2_qtd *dwc2_hcd_qtd_alloc(struct dwc2_hsotg *hsotg,
- gfp_t mem_flags)
- {
- struct dwc2_qtd *qtd = NULL;
- if (!list_empty(&hsotg->free_qtd_list)) {
- qtd = listGET_OWNER_OF_HEAD_ENTRY(&hsotg->free_qtd_list);
- memset(qtd, 0, sizeof(struct dwc2_qtd));
- list_del_init(&qtd->qtd_list_entry);
- listSET_LIST_ITEM_OWNER(&qtd->qtd_list_entry, qtd);
- return qtd;
- }
- qtd = (struct dwc2_qtd *)kzalloc(sizeof(*qtd), mem_flags);
- if (qtd) {
- listSET_LIST_ITEM_OWNER(&qtd->qtd_list_entry, qtd);
- }
- return qtd;
- }
- static void dwc2_hcd_urb_set_pipeinfo(struct dwc2_hsotg *hsotg,
- struct dwc2_hcd_urb *urb, u8 dev_addr,
- u8 ep_num, u8 ep_type, u8 ep_dir, u16 mps)
- {
- if (dbg_perio() ||
- ep_type == USB_ENDPOINT_XFER_BULK ||
- ep_type == USB_ENDPOINT_XFER_CONTROL)
- dev_vdbg(hsotg->dev,
- "addr=%d, ep_num=%d, ep_dir=%1x, ep_type=%1x, mps=%d\n",
- dev_addr, ep_num, ep_dir, ep_type, mps);
- urb->pipe_info.dev_addr = dev_addr;
- urb->pipe_info.ep_num = ep_num;
- urb->pipe_info.pipe_type = ep_type;
- urb->pipe_info.pipe_dir = ep_dir;
- urb->pipe_info.mps = mps;
- }
- struct wrapper_priv_data {
- struct dwc2_hsotg *hsotg;
- };
- /* Gets the dwc2_hsotg from a usb_hcd */
- static struct dwc2_hsotg *dwc2_hcd_to_hsotg(struct usb_hcd *hcd)
- {
- struct wrapper_priv_data *p;
- p = (struct wrapper_priv_data *)hcd->hcd_priv;
- return p->hsotg;
- }
- /**
- * dwc2_host_get_tt_info() - Get the dwc2_tt associated with context
- *
- * This will get the dwc2_tt structure (and ttport) associated with the given
- * context (which is really just a struct urb pointer).
- *
- * The first time this is called for a given TT we allocate memory for our
- * structure. When everyone is done and has called dwc2_host_put_tt_info()
- * then the refcount for the structure will go to 0 and we'll free it.
- *
- * @hsotg: The HCD state structure for the DWC OTG controller.
- * @qh: The QH structure.
- * @context: The priv pointer from a struct dwc2_hcd_urb.
- * @mem_flags: Flags for allocating memory.
- * @ttport: We'll return this device's port number here. That's used to
- * reference into the bitmap if we're on a multi_tt hub.
- *
- * Return: a pointer to a struct dwc2_tt. Don't forget to call
- * dwc2_host_put_tt_info()! Returns NULL upon memory alloc failure.
- */
- struct dwc2_tt *dwc2_host_get_tt_info(struct dwc2_hsotg *hsotg, void *context,
- gfp_t mem_flags, int *ttport)
- {
- struct urb *urb = context;
- struct dwc2_tt *dwc_tt = NULL;
- if (urb->dev->tt) {
- *ttport = urb->dev->ttport;
- dwc_tt = urb->dev->tt->hcpriv;
- if (!dwc_tt) {
- size_t bitmap_size;
- /*
- * For single_tt we need one schedule. For multi_tt
- * we need one per port.
- */
- bitmap_size = DWC2_ELEMENTS_PER_LS_BITMAP *
- sizeof(dwc_tt->periodic_bitmaps[0]);
- if (urb->dev->tt->multi)
- bitmap_size *= urb->dev->tt->hub->maxchild;
- dwc_tt = (struct dwc2_tt *)kzalloc(sizeof(*dwc_tt) + bitmap_size,
- mem_flags);
- if (!dwc_tt)
- return NULL;
- dwc_tt->usb_tt = urb->dev->tt;
- dwc_tt->usb_tt->hcpriv = dwc_tt;
- }
- dwc_tt->refcount++;
- }
- return dwc_tt;
- }
- /**
- * dwc2_host_put_tt_info() - Put the dwc2_tt from dwc2_host_get_tt_info()
- *
- * Frees resources allocated by dwc2_host_get_tt_info() if all current holders
- * of the structure are done.
- *
- * It's OK to call this with NULL.
- *
- * @hsotg: The HCD state structure for the DWC OTG controller.
- * @dwc_tt: The pointer returned by dwc2_host_get_tt_info.
- */
- void dwc2_host_put_tt_info(struct dwc2_hsotg *hsotg, struct dwc2_tt *dwc_tt)
- {
- /* Model kfree and make put of NULL a no-op */
- if (!dwc_tt)
- return;
- WARN_ON(dwc_tt->refcount < 1);
- dwc_tt->refcount--;
- if (!dwc_tt->refcount) {
- dwc_tt->usb_tt->hcpriv = NULL;
- kfree(dwc_tt);
- }
- }
- int dwc2_host_get_speed(struct dwc2_hsotg *hsotg, void *context)
- {
- struct urb *urb = context;
- return urb->dev->speed;
- }
- static void dwc2_allocate_bus_bandwidth(struct usb_hcd *hcd, u16 bw,
- struct urb *urb)
- {
- struct usb_bus *bus = hcd_to_bus(hcd);
- if (urb->interval)
- bus->bandwidth_allocated += bw / urb->interval;
- bus->bandwidth_int_reqs++;
- }
- /*
- * Sets the final status of an URB and returns it to the upper layer. Any
- * required cleanup of the URB is performed.
- *
- * Must be called with interrupt disabled and spinlock held
- */
- void dwc2_host_complete(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
- int status)
- {
- struct urb *urb;
- if (!qtd) {
- dev_dbg(hsotg->dev, "## %s: qtd is NULL ##\n", __func__);
- return;
- }
- if (!qtd->urb) {
- dev_dbg(hsotg->dev, "## %s: qtd->urb is NULL ##\n", __func__);
- return;
- }
- urb = qtd->urb->priv;
- if (!urb) {
- dev_dbg(hsotg->dev, "## %s: urb->priv is NULL ##\n", __func__);
- return;
- }
- urb->actual_length = dwc2_hcd_urb_get_actual_length(qtd->urb);
- if (dbg_urb(urb))
- dev_vdbg(hsotg->dev,
- "%s: urb %p device %d ep %d-%s status %d actual %d\n",
- __func__, urb, usb_pipedevice(urb->pipe),
- usb_pipeendpoint(urb->pipe),
- usb_pipein(urb->pipe) ? "IN" : "OUT", status,
- urb->actual_length);
- urb->status = status;
- if (!status) {
- if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
- urb->actual_length < urb->transfer_buffer_length)
- urb->status = -EREMOTEIO;
- }
- usb_hcd_unlink_urb_from_ep(dwc2_hsotg_to_hcd(hsotg), urb);
- urb->hcpriv = NULL;
- list_add_tail(&qtd->urb->free_list_entry, &hsotg->free_urb_list);
- qtd->urb = NULL;
- usb_hcd_giveback_urb(dwc2_hsotg_to_hcd(hsotg), urb, status);
- }
- /*
- * =========================================================================
- * Linux HC Driver Functions
- * =========================================================================
- */
- /*
- * Initializes the DWC_otg controller and its root hub and prepares it for host
- * mode operation. Activates the root port. Returns 0 on success and a negative
- * error code on failure.
- */
- static int _dwc2_hcd_start(struct usb_hcd *hcd)
- {
- struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
- struct usb_bus *bus = hcd_to_bus(hcd);
- unsigned long flags;
- dev_dbg(hsotg->dev, "DWC OTG HCD START\n");
- spin_lock_irqsave(&hsotg->lock, flags);
- hsotg->lx_state = DWC2_L0;
- dwc2_hcd_reinit(hsotg);
- spin_unlock_irqrestore(&hsotg->lock, flags);
- return 0;
- }
- /*
- * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
- * stopped.
- */
- static void _dwc2_hcd_stop(struct usb_hcd *hcd)
- {
- struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
- unsigned long flags;
- /* Turn off all host-specific interrupts */
- dwc2_disable_host_interrupts(hsotg);
- spin_lock_irqsave(&hsotg->lock, flags);
- /* Ensure hcd is disconnected */
- dwc2_hcd_disconnect(hsotg, true);
- dwc2_hcd_stop(hsotg);
- hsotg->lx_state = DWC2_L3;
- spin_unlock_irqrestore(&hsotg->lock, flags);
- udelay(2000);
- }
- /* Returns the current frame number */
- static int _dwc2_hcd_get_frame_number(struct usb_hcd *hcd)
- {
- struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
- return dwc2_hcd_get_frame_number(hsotg);
- }
- /*
- * Starts processing a USB transfer request specified by a USB Request Block
- * (URB). mem_flags indicates the type of memory allocation to use while
- * processing this URB.
- */
- int dwc2_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
- gfp_t mem_flags)
- {
- struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
- struct usb_host_endpoint *ep = urb->ep;
- struct dwc2_hcd_urb *dwc2_urb;
- int retval;
- int alloc_bandwidth = 0;
- u8 ep_type = 0;
- u32 tflags = 0;
- void *buf;
- unsigned long flags;
- struct dwc2_qh *qh;
- bool qh_allocated = false;
- struct dwc2_qtd *qtd;
- if (dbg_urb(urb)) {
- dev_vdbg(hsotg->dev, "DWC OTG HCD URB Enqueue\n");
- }
- if (!ep)
- return -EINVAL;
- switch (usb_pipetype(urb->pipe)) {
- case PIPE_CONTROL:
- ep_type = USB_ENDPOINT_XFER_CONTROL;
- break;
- case PIPE_BULK:
- ep_type = USB_ENDPOINT_XFER_BULK;
- break;
- }
- /*if (usb_pipetype(urb->pipe) == PIPE_BULK && urb->transfer_buffer) {//dev_dbg(hsotg->dev, "data_toggle:%d\n", qh->data_toggle);
- char *tmpbuf = urb->transfer_buffer;
- for(i = 0; i < urb->transfer_buffer_length; i++) {
- printf("%02x ", tmpbuf[i]);
- }printf("\n");
- }*/
- dwc2_urb = dwc2_hcd_urb_alloc(hsotg, urb->number_of_packets,
- mem_flags);
- if (!dwc2_urb)
- return -ENOMEM;
- dwc2_hcd_urb_set_pipeinfo(hsotg, dwc2_urb, usb_pipedevice(urb->pipe),
- usb_pipeendpoint(urb->pipe), ep_type,
- usb_pipein(urb->pipe),
- usb_maxpacket(urb->dev, urb->pipe));
- buf = urb->transfer_buffer;
- if (hcd->self.uses_dma) {
- if (!buf && (urb->transfer_dma & 3)) {
- dev_err(hsotg->dev,
- "%s: unaligned transfer with no transfer_buffer",
- __func__);
- retval = -EINVAL;
- goto fail0;
- }
- }
- if (!(urb->transfer_flags & URB_NO_INTERRUPT))
- tflags |= URB_GIVEBACK_ASAP;
- if (urb->transfer_flags & URB_ZERO_PACKET)
- tflags |= URB_SEND_ZERO_PACKET;
- dwc2_urb->priv = urb;
- dwc2_urb->buf = buf;
- dwc2_urb->dma = urb->transfer_dma;
- dwc2_urb->length = urb->transfer_buffer_length;
- dwc2_urb->setup_packet = urb->setup_packet;
- dwc2_urb->setup_dma = urb->setup_dma;
- dwc2_urb->flags = tflags;
- dwc2_urb->interval = urb->interval;
- dwc2_urb->status = -EINPROGRESS;
- urb->hcpriv = dwc2_urb;
- qh = (struct dwc2_qh *)ep->hcpriv;
- /* Create QH for the endpoint if it doesn't exist */
- if (!qh) {
- qh = dwc2_hcd_qh_create(hsotg, dwc2_urb, mem_flags);
- if (!qh) {
- retval = -ENOMEM;
- goto fail0;
- }
- ep->hcpriv = qh;
- qh_allocated = true;
- }//dev_dbg(hsotg->dev, "data_toggle:%d qh:%x\n", qh->data_toggle, qh);
- spin_lock_irqsave(&hsotg->lock, flags);
- qtd = dwc2_hcd_qtd_alloc(hsotg, mem_flags);
- if (!qtd) {
- retval = -ENOMEM;
- goto fail1;
- }
- usb_hcd_link_urb_to_ep(hcd, urb);
- retval = dwc2_hcd_urb_enqueue(hsotg, dwc2_urb, qh, qtd);
- if (retval)
- goto fail3;
- if (alloc_bandwidth) {
- dwc2_allocate_bus_bandwidth(hcd,
- dwc2_hcd_get_ep_bandwidth(hsotg, ep),
- urb);
- }
- spin_unlock_irqrestore(&hsotg->lock, flags);
- return 0;
- fail3:
- dwc2_urb->priv = NULL;
- usb_hcd_unlink_urb_from_ep(hcd, urb);
- if (qh_allocated && qh->channel && qh->channel->qh == qh)
- qh->channel->qh = NULL;
- list_add_tail(&qtd->qtd_list_entry, &hsotg->free_qtd_list);
- spin_unlock_irqrestore(&hsotg->lock, flags);
- urb->hcpriv = NULL;
- fail1:
- if (qh_allocated) {
- struct dwc2_qtd *qtd2;//, *qtd2_tmp;
- ep->hcpriv = NULL;
- dwc2_hcd_qh_unlink(hsotg, qh);
- /* Free each QTD in the QH's QTD list */
- /*list_for_each_entry_safe(qtd2, qtd2_tmp, &qh->qtd_list,
- qtd_list_entry)*/
- ListItem_t *pxListItem, *nListItem;
- list_for_each_entry_safe(pxListItem, nListItem, qtd2, &qh->qtd_list)
- dwc2_hcd_qtd_unlink_and_free(hsotg, qtd2, qh);
- dwc2_hcd_qh_free(hsotg, qh);
- }
- fail0:
- spin_lock_irqsave(&hsotg->lock, flags);
- list_add_tail(&dwc2_urb->free_list_entry, &hsotg->free_urb_list);
- spin_unlock_irqrestore(&hsotg->lock, flags);
- return retval;
- }
- /*
- * Aborts/cancels a USB transfer request. Always returns 0 to indicate success.
- */
- int dwc2_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
- int status)
- {
- struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
- int rc;
- unsigned long flags;
- dev_dbg(hsotg->dev, "DWC OTG HCD URB Dequeue\n");
- spin_lock_irqsave(&hsotg->lock, flags);
- rc = usb_hcd_check_unlink_urb(hcd, urb, status);
- if (rc)
- goto out;
- if (!urb->hcpriv) {
- dev_dbg(hsotg->dev, "## urb->hcpriv is NULL ##\n");
- goto out;
- }
- rc = dwc2_hcd_urb_dequeue(hsotg, urb->hcpriv);
- usb_hcd_unlink_urb_from_ep(hcd, urb);
- kfree(urb->hcpriv);
- urb->hcpriv = NULL;
- /* Higher layer software sets URB status */
- spin_unlock(&hsotg->lock);
- usb_hcd_giveback_urb(hcd, urb, status);
- spin_lock(&hsotg->lock);
- dev_dbg(hsotg->dev, "Called usb_hcd_giveback_urb()\n");
- dev_dbg(hsotg->dev, " urb->status = %d\n", urb->status);
- out:
- spin_unlock_irqrestore(&hsotg->lock, flags);
- return rc;
- }
- /*
- * Frees resources in the DWC_otg controller related to a given endpoint. Also
- * clears state in the HCD related to the endpoint. Any URBs for the endpoint
- * must already be dequeued.
- */
- static void _dwc2_hcd_endpoint_disable(struct usb_hcd *hcd,
- struct usb_host_endpoint *ep)
- {
- struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
- dev_dbg(hsotg->dev,
- "DWC OTG HCD EP DISABLE: bEndpointAddress=0x%02x, ep->hcpriv=%p\n",
- ep->desc.bEndpointAddress, ep->hcpriv);
- dwc2_hcd_endpoint_disable(hsotg, ep, 250);
- }
- /*
- * Resets endpoint specific parameter values, in current version used to reset
- * the data toggle (as a WA). This function can be called from usb_clear_halt
- * routine.
- */
- static void _dwc2_hcd_endpoint_reset(struct usb_hcd *hcd,
- struct usb_host_endpoint *ep)
- {
- struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
- unsigned long flags;
- dev_dbg(hsotg->dev,
- "DWC OTG HCD EP RESET: bEndpointAddress=0x%02x\n",
- ep->desc.bEndpointAddress);
- spin_lock_irqsave(&hsotg->lock, flags);
- dwc2_hcd_endpoint_reset(hsotg, ep);
- spin_unlock_irqrestore(&hsotg->lock, flags);
- }
- /*
- * Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
- * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
- * interrupt.
- *
- * This function is called by the USB core when an interrupt occurs
- */
- static irqreturn_t _dwc2_hcd_irq(struct usb_hcd *hcd)
- {
- struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
- return dwc2_handle_hcd_intr(hsotg);
- }
- void dwc2_hcd_irq(struct dwc2_hsotg *hsotg)
- {
- dwc2_handle_hcd_intr(hsotg);
- }
- /*
- * Creates Status Change bitmap for the root hub and root port. The bitmap is
- * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
- * is the status change indicator for the single root port. Returns 1 if either
- * change indicator is 1, otherwise returns 0.
- */
- static int _dwc2_hcd_hub_status_data(struct usb_hcd *hcd, char *buf)
- {
- struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
- int ret;
- ret = (dwc2_hcd_is_status_changed(hsotg, 1) << 1);
- memcpy(buf, &hsotg->flags, sizeof(hsotg->flags));
- return ret;
- }
- /* Handles hub class-specific requests */
- static int _dwc2_hcd_hub_control(struct usb_hcd *hcd, u16 typereq, u16 wvalue,
- u16 windex, char *buf, u16 wlength)
- {
- int retval = dwc2_hcd_hub_control(dwc2_hcd_to_hsotg(hcd), typereq,
- wvalue, windex, buf, wlength);
- return retval;
- }
- static struct hc_driver dwc2_hc_driver = {
- .description = "dwc2_hsotg",
- .product_desc = "DWC OTG Controller",
- .hcd_priv_size = sizeof(struct wrapper_priv_data),
- .irq = _dwc2_hcd_irq,
- .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
- .start = _dwc2_hcd_start,
- .stop = _dwc2_hcd_stop,
- .urb_enqueue = dwc2_urb_enqueue,
- .urb_dequeue = dwc2_urb_dequeue,
- .endpoint_disable = _dwc2_hcd_endpoint_disable,
- .endpoint_reset = _dwc2_hcd_endpoint_reset,
- .get_frame_number = _dwc2_hcd_get_frame_number,
- .hub_status_data = _dwc2_hcd_hub_status_data,
- .hub_control = _dwc2_hcd_hub_control,
- };
- struct hc_driver* dwc2_get_driver()
- {
- return &dwc2_hc_driver;
- }
- /*
- * Frees secondary storage associated with the dwc2_hsotg structure contained
- * in the struct usb_hcd field
- */
- static void dwc2_hcd_free(struct dwc2_hsotg *hsotg)
- {
- u32 ahbcfg;
- u32 dctl;
- int i;
- dev_dbg(hsotg->dev, "DWC OTG HCD FREE\n");
- /* Free memory for QH/QTD lists */
- dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_inactive);
- dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_active);
- /* Free memory for the host channels */
- for (i = 0; i < MAX_EPS_CHANNELS; i++) {
- struct dwc2_host_chan *chan = hsotg->hc_ptr_array[i];
- if (chan) {
- dev_dbg(hsotg->dev, "HCD Free channel #%i, chan=%p\n",
- i, chan);
- hsotg->hc_ptr_array[i] = NULL;
- kfree(chan);
- }
- }
- kfree(hsotg->status_buf);
- hsotg->status_buf = NULL;
- ahbcfg = dwc2_readl(hsotg->regs + GAHBCFG);
- /* Disable all interrupts */
- ahbcfg &= ~GAHBCFG_GLBL_INTR_EN;
- dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG);
- dwc2_writel(0, hsotg->regs + GINTMSK);
- if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a) {
- dctl = dwc2_readl(hsotg->regs + DCTL);
- dctl |= DCTL_SFTDISCON;
- dwc2_writel(dctl, hsotg->regs + DCTL);
- }
- }
- static void dwc2_hcd_release(struct dwc2_hsotg *hsotg)
- {
- /* Turn off all host-specific interrupts */
- dwc2_disable_host_interrupts(hsotg);
- dwc2_hcd_free(hsotg);
- }
- void reset_hcd_reg(struct dwc2_hsotg *hsotg)
- {
- dwc2_writel(0x0024863E, hsotg->regs + 0x000);
- dwc2_writel(0x006086a3, hsotg->regs + 0x008);
- dwc2_writel(0x3a40170f, hsotg->regs + 0x00c);
- dwc2_writel(0x80000400, hsotg->regs + 0x010);
- dwc2_writel(0xFFFFFFFF, hsotg->regs + 0x018);
- dwc2_writel(0x00000634, hsotg->regs + 0x024);
- dwc2_writel(0x01800634, hsotg->regs + 0x028);
- dwc2_writel(0x00000000, hsotg->regs + 0x054);
- dwc2_writel(0x030007B4, hsotg->regs + 0x100);
- dwc2_writel(0x80008000, hsotg->regs + 0x400);
- dwc2_writel(0x0001EA60, hsotg->regs + 0x404);
- dwc2_writel(0x0000FFFF, hsotg->regs + 0x418);
- dwc2_writel(0x00001000, hsotg->regs + 0x440);
- dwc2_writel(0x00000000, hsotg->regs + 0x500);
- }
- /*
- * Initializes the HCD. This function allocates memory for and initializes the
- * static parts of the usb_hcd and dwc2_hsotg structures. It also registers the
- * USB bus with the core and calls the hc_driver->start() function. It returns
- * a negative error on failure.
- */
- int dwc2_hcd_init(struct dwc2_hsotg *hsotg, struct usb_hcd *hcd)
- {
- //struct usb_hcd *hcd;
- struct dwc2_host_chan *channel;
- u32 hcfg;
- int i, num_channels;
- int retval;
- dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n");
- retval = -ENOMEM;
- hcfg = dwc2_readl(hsotg->regs + HCFG);
- USB_UNUSED(hcfg);
- dev_dbg(hsotg->dev, "hcfg=%08x\n", hcfg);
- hsotg->last_frame_num = HFNUM_MAX_FRNUM;
- hcd->self.uses_dma = 0;
- hcd->has_tt = 1;
- struct wrapper_priv_data *hcd_pri = (struct wrapper_priv_data *)kmalloc(sizeof(struct wrapper_priv_data), __GFP_ZERO);
- hcd_pri->hsotg = hsotg;
- hcd->hcd_priv = hcd_pri;
- hsotg->priv = (void*)hcd;
- /*
- * Disable the global interrupt until all the interrupt handlers are
- * installed
- */
- dwc2_disable_global_interrupts(hsotg);
- /* Initialize the DWC_otg core, and select the Phy type */
- retval = dwc2_core_init(hsotg, true);
- if (retval)
- goto error2;
- /* Create new workqueue and init work */
- retval = -ENOMEM;
- /* Initialize the non-periodic schedule */
- INIT_LIST_HEAD(&hsotg->non_periodic_sched_inactive);
- INIT_LIST_HEAD(&hsotg->non_periodic_sched_active);
- INIT_LIST_HEAD(&hsotg->split_order);
- /*
- * Create a host channel descriptor for each host channel implemented
- * in the controller. Initialize the channel descriptor array.
- */
- INIT_LIST_HEAD(&hsotg->free_hc_list);
- num_channels = hsotg->params.host_channels;
- memset(&hsotg->hc_ptr_array[0], 0, sizeof(hsotg->hc_ptr_array));
- for (i = 0; i < num_channels; i++) {
- channel = kzalloc(sizeof(*channel), GFP_KERNEL);
- if (!channel)
- goto error3;
- channel->hc_num = i;
- INIT_LIST_ITEM(&channel->split_order_list_entry);
- //channel->split_order_list_entry.pvOwner = (void *)channel;
- listSET_LIST_ITEM_OWNER(&channel->split_order_list_entry, channel);
- //channel->hc_list_entry.pvOwner = (void *)channel;
- listSET_LIST_ITEM_OWNER(&channel->hc_list_entry, channel);
- hsotg->hc_ptr_array[i] = channel;
- }
- INIT_LIST_HEAD(&hsotg->free_qtd_list);
- INIT_LIST_HEAD(&hsotg->free_urb_list);
- /*
- * Allocate space for storing data on status transactions. Normally no
- * data is sent, but this space acts as a bit bucket. This must be
- * done after usb_add_hcd since that function allocates the DMA buffer
- * pool.
- */
- hsotg->status_buf = kzalloc(DWC2_HCD_STATUS_BUF_SIZE,
- GFP_KERNEL);
- if (!hsotg->status_buf)
- goto error3;
- hsotg->otg_port = 1;
- hsotg->frame_list = NULL;
- hsotg->frame_list_dma = 0;
- /* Initiate lx_state to L3 disconnected state */
- hsotg->lx_state = DWC2_L3;
- hcd->self.otg_port = hsotg->otg_port;
- /* Don't support SG list at this point */
- hcd->self.sg_tablesize = 0;
- //_dwc2_hcd_start(hcd);
- dwc2_host_start(hsotg);
- //reset_hcd_reg(hsotg);
- dwc2_enable_global_interrupts(hsotg);
- return 0;
- /* error4:
- kmem_cache_destroy(hsotg->unaligned_cache);
- kmem_cache_destroy(hsotg->desc_hsisoc_cache);
- kmem_cache_destroy(hsotg->desc_gen_cache); */
- error3:
- dwc2_hcd_release(hsotg);
- error2:
- //error1:
- dev_err(hsotg->dev, "%s() FAILED, returning %d\n", __func__, retval);
- return retval;
- }
- /*
- * Removes the HCD.
- * Frees memory and resources associated with the HCD and deregisters the bus.
- */
- void dwc2_hcd_remove(struct dwc2_hsotg *hsotg)
- {
- struct usb_hcd *hcd;
- dev_dbg(hsotg->dev, "DWC OTG HCD REMOVE\n");
- hcd = dwc2_hsotg_to_hcd(hsotg);
- dev_dbg(hsotg->dev, "hsotg->hcd = %p\n", hcd);
- if (!hcd) {
- dev_dbg(hsotg->dev, "%s: dwc2_hsotg_to_hcd(hsotg) NULL!\n",
- __func__);
- return;
- }
- hsotg->priv = NULL;
- dwc2_hcd_release(hsotg);
- }
|