s3c-hsotg.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423
  1. /* linux/drivers/usb/gadget/s3c-hsotg.c
  2. *
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * S3C USB2.0 High-speed / OtG driver
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #define DEBUG
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/dma-mapping.h>
  21. #include <linux/debugfs.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/delay.h>
  24. #include <linux/io.h>
  25. #include <linux/slab.h>
  26. #include <linux/clk.h>
  27. #include <linux/usb/ch9.h>
  28. #include <linux/usb/gadget.h>
  29. #include <mach/map.h>
  30. #include <plat/regs-usb-hsotg-phy.h>
  31. #include <plat/regs-usb-hsotg.h>
  32. #include <mach/regs-sys.h>
  33. #include <plat/udc-hs.h>
  34. #include <plat/cpu.h>
  35. #define DMA_ADDR_INVALID (~((dma_addr_t)0))
  36. /* EP0_MPS_LIMIT
  37. *
  38. * Unfortunately there seems to be a limit of the amount of data that can
  39. * be transfered by IN transactions on EP0. This is either 127 bytes or 3
  40. * packets (which practially means 1 packet and 63 bytes of data) when the
  41. * MPS is set to 64.
  42. *
  43. * This means if we are wanting to move >127 bytes of data, we need to
  44. * split the transactions up, but just doing one packet at a time does
  45. * not work (this may be an implicit DATA0 PID on first packet of the
  46. * transaction) and doing 2 packets is outside the controller's limits.
  47. *
  48. * If we try to lower the MPS size for EP0, then no transfers work properly
  49. * for EP0, and the system will fail basic enumeration. As no cause for this
  50. * has currently been found, we cannot support any large IN transfers for
  51. * EP0.
  52. */
  53. #define EP0_MPS_LIMIT 64
  54. struct s3c_hsotg;
  55. struct s3c_hsotg_req;
  56. /**
  57. * struct s3c_hsotg_ep - driver endpoint definition.
  58. * @ep: The gadget layer representation of the endpoint.
  59. * @name: The driver generated name for the endpoint.
  60. * @queue: Queue of requests for this endpoint.
  61. * @parent: Reference back to the parent device structure.
  62. * @req: The current request that the endpoint is processing. This is
  63. * used to indicate an request has been loaded onto the endpoint
  64. * and has yet to be completed (maybe due to data move, or simply
  65. * awaiting an ack from the core all the data has been completed).
  66. * @debugfs: File entry for debugfs file for this endpoint.
  67. * @lock: State lock to protect contents of endpoint.
  68. * @dir_in: Set to true if this endpoint is of the IN direction, which
  69. * means that it is sending data to the Host.
  70. * @index: The index for the endpoint registers.
  71. * @name: The name array passed to the USB core.
  72. * @halted: Set if the endpoint has been halted.
  73. * @periodic: Set if this is a periodic ep, such as Interrupt
  74. * @sent_zlp: Set if we've sent a zero-length packet.
  75. * @total_data: The total number of data bytes done.
  76. * @fifo_size: The size of the FIFO (for periodic IN endpoints)
  77. * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
  78. * @last_load: The offset of data for the last start of request.
  79. * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
  80. *
  81. * This is the driver's state for each registered enpoint, allowing it
  82. * to keep track of transactions that need doing. Each endpoint has a
  83. * lock to protect the state, to try and avoid using an overall lock
  84. * for the host controller as much as possible.
  85. *
  86. * For periodic IN endpoints, we have fifo_size and fifo_load to try
  87. * and keep track of the amount of data in the periodic FIFO for each
  88. * of these as we don't have a status register that tells us how much
  89. * is in each of them. (note, this may actually be useless information
  90. * as in shared-fifo mode periodic in acts like a single-frame packet
  91. * buffer than a fifo)
  92. */
  93. struct s3c_hsotg_ep {
  94. struct usb_ep ep;
  95. struct list_head queue;
  96. struct s3c_hsotg *parent;
  97. struct s3c_hsotg_req *req;
  98. struct dentry *debugfs;
  99. spinlock_t lock;
  100. unsigned long total_data;
  101. unsigned int size_loaded;
  102. unsigned int last_load;
  103. unsigned int fifo_load;
  104. unsigned short fifo_size;
  105. unsigned char dir_in;
  106. unsigned char index;
  107. unsigned int halted:1;
  108. unsigned int periodic:1;
  109. unsigned int sent_zlp:1;
  110. char name[10];
  111. };
  112. #define S3C_HSOTG_EPS (8+1) /* limit to 9 for the moment */
  113. /**
  114. * struct s3c_hsotg - driver state.
  115. * @dev: The parent device supplied to the probe function
  116. * @driver: USB gadget driver
  117. * @plat: The platform specific configuration data.
  118. * @regs: The memory area mapped for accessing registers.
  119. * @regs_res: The resource that was allocated when claiming register space.
  120. * @irq: The IRQ number we are using
  121. * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
  122. * @debug_root: root directrory for debugfs.
  123. * @debug_file: main status file for debugfs.
  124. * @debug_fifo: FIFO status file for debugfs.
  125. * @ep0_reply: Request used for ep0 reply.
  126. * @ep0_buff: Buffer for EP0 reply data, if needed.
  127. * @ctrl_buff: Buffer for EP0 control requests.
  128. * @ctrl_req: Request for EP0 control packets.
  129. * @eps: The endpoints being supplied to the gadget framework
  130. */
  131. struct s3c_hsotg {
  132. struct device *dev;
  133. struct usb_gadget_driver *driver;
  134. struct s3c_hsotg_plat *plat;
  135. void __iomem *regs;
  136. struct resource *regs_res;
  137. int irq;
  138. struct clk *clk;
  139. unsigned int dedicated_fifos:1;
  140. struct dentry *debug_root;
  141. struct dentry *debug_file;
  142. struct dentry *debug_fifo;
  143. struct usb_request *ep0_reply;
  144. struct usb_request *ctrl_req;
  145. u8 ep0_buff[8];
  146. u8 ctrl_buff[8];
  147. struct usb_gadget gadget;
  148. struct s3c_hsotg_ep eps[];
  149. };
  150. /**
  151. * struct s3c_hsotg_req - data transfer request
  152. * @req: The USB gadget request
  153. * @queue: The list of requests for the endpoint this is queued for.
  154. * @in_progress: Has already had size/packets written to core
  155. * @mapped: DMA buffer for this request has been mapped via dma_map_single().
  156. */
  157. struct s3c_hsotg_req {
  158. struct usb_request req;
  159. struct list_head queue;
  160. unsigned char in_progress;
  161. unsigned char mapped;
  162. };
  163. /* conversion functions */
  164. static inline struct s3c_hsotg_req *our_req(struct usb_request *req)
  165. {
  166. return container_of(req, struct s3c_hsotg_req, req);
  167. }
  168. static inline struct s3c_hsotg_ep *our_ep(struct usb_ep *ep)
  169. {
  170. return container_of(ep, struct s3c_hsotg_ep, ep);
  171. }
  172. static inline struct s3c_hsotg *to_hsotg(struct usb_gadget *gadget)
  173. {
  174. return container_of(gadget, struct s3c_hsotg, gadget);
  175. }
  176. static inline void __orr32(void __iomem *ptr, u32 val)
  177. {
  178. writel(readl(ptr) | val, ptr);
  179. }
  180. static inline void __bic32(void __iomem *ptr, u32 val)
  181. {
  182. writel(readl(ptr) & ~val, ptr);
  183. }
  184. /* forward decleration of functions */
  185. static void s3c_hsotg_dump(struct s3c_hsotg *hsotg);
  186. /**
  187. * using_dma - return the DMA status of the driver.
  188. * @hsotg: The driver state.
  189. *
  190. * Return true if we're using DMA.
  191. *
  192. * Currently, we have the DMA support code worked into everywhere
  193. * that needs it, but the AMBA DMA implementation in the hardware can
  194. * only DMA from 32bit aligned addresses. This means that gadgets such
  195. * as the CDC Ethernet cannot work as they often pass packets which are
  196. * not 32bit aligned.
  197. *
  198. * Unfortunately the choice to use DMA or not is global to the controller
  199. * and seems to be only settable when the controller is being put through
  200. * a core reset. This means we either need to fix the gadgets to take
  201. * account of DMA alignment, or add bounce buffers (yuerk).
  202. *
  203. * Until this issue is sorted out, we always return 'false'.
  204. */
  205. static inline bool using_dma(struct s3c_hsotg *hsotg)
  206. {
  207. return false; /* support is not complete */
  208. }
  209. /**
  210. * s3c_hsotg_en_gsint - enable one or more of the general interrupt
  211. * @hsotg: The device state
  212. * @ints: A bitmask of the interrupts to enable
  213. */
  214. static void s3c_hsotg_en_gsint(struct s3c_hsotg *hsotg, u32 ints)
  215. {
  216. u32 gsintmsk = readl(hsotg->regs + S3C_GINTMSK);
  217. u32 new_gsintmsk;
  218. new_gsintmsk = gsintmsk | ints;
  219. if (new_gsintmsk != gsintmsk) {
  220. dev_dbg(hsotg->dev, "gsintmsk now 0x%08x\n", new_gsintmsk);
  221. writel(new_gsintmsk, hsotg->regs + S3C_GINTMSK);
  222. }
  223. }
  224. /**
  225. * s3c_hsotg_disable_gsint - disable one or more of the general interrupt
  226. * @hsotg: The device state
  227. * @ints: A bitmask of the interrupts to enable
  228. */
  229. static void s3c_hsotg_disable_gsint(struct s3c_hsotg *hsotg, u32 ints)
  230. {
  231. u32 gsintmsk = readl(hsotg->regs + S3C_GINTMSK);
  232. u32 new_gsintmsk;
  233. new_gsintmsk = gsintmsk & ~ints;
  234. if (new_gsintmsk != gsintmsk)
  235. writel(new_gsintmsk, hsotg->regs + S3C_GINTMSK);
  236. }
  237. /**
  238. * s3c_hsotg_ctrl_epint - enable/disable an endpoint irq
  239. * @hsotg: The device state
  240. * @ep: The endpoint index
  241. * @dir_in: True if direction is in.
  242. * @en: The enable value, true to enable
  243. *
  244. * Set or clear the mask for an individual endpoint's interrupt
  245. * request.
  246. */
  247. static void s3c_hsotg_ctrl_epint(struct s3c_hsotg *hsotg,
  248. unsigned int ep, unsigned int dir_in,
  249. unsigned int en)
  250. {
  251. unsigned long flags;
  252. u32 bit = 1 << ep;
  253. u32 daint;
  254. if (!dir_in)
  255. bit <<= 16;
  256. local_irq_save(flags);
  257. daint = readl(hsotg->regs + S3C_DAINTMSK);
  258. if (en)
  259. daint |= bit;
  260. else
  261. daint &= ~bit;
  262. writel(daint, hsotg->regs + S3C_DAINTMSK);
  263. local_irq_restore(flags);
  264. }
  265. /**
  266. * s3c_hsotg_init_fifo - initialise non-periodic FIFOs
  267. * @hsotg: The device instance.
  268. */
  269. static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg)
  270. {
  271. unsigned int ep;
  272. unsigned int addr;
  273. unsigned int size;
  274. int timeout;
  275. u32 val;
  276. /* the ryu 2.6.24 release ahs
  277. writel(0x1C0, hsotg->regs + S3C_GRXFSIZ);
  278. writel(S3C_GNPTXFSIZ_NPTxFStAddr(0x200) |
  279. S3C_GNPTXFSIZ_NPTxFDep(0x1C0),
  280. hsotg->regs + S3C_GNPTXFSIZ);
  281. */
  282. /* set FIFO sizes to 2048/1024 */
  283. writel(2048, hsotg->regs + S3C_GRXFSIZ);
  284. writel(S3C_GNPTXFSIZ_NPTxFStAddr(2048) |
  285. S3C_GNPTXFSIZ_NPTxFDep(1024),
  286. hsotg->regs + S3C_GNPTXFSIZ);
  287. /* arange all the rest of the TX FIFOs, as some versions of this
  288. * block have overlapping default addresses. This also ensures
  289. * that if the settings have been changed, then they are set to
  290. * known values. */
  291. /* start at the end of the GNPTXFSIZ, rounded up */
  292. addr = 2048 + 1024;
  293. size = 768;
  294. /* currently we allocate TX FIFOs for all possible endpoints,
  295. * and assume that they are all the same size. */
  296. for (ep = 0; ep <= 15; ep++) {
  297. val = addr;
  298. val |= size << S3C_DPTXFSIZn_DPTxFSize_SHIFT;
  299. addr += size;
  300. writel(val, hsotg->regs + S3C_DPTXFSIZn(ep));
  301. }
  302. /* according to p428 of the design guide, we need to ensure that
  303. * all fifos are flushed before continuing */
  304. writel(S3C_GRSTCTL_TxFNum(0x10) | S3C_GRSTCTL_TxFFlsh |
  305. S3C_GRSTCTL_RxFFlsh, hsotg->regs + S3C_GRSTCTL);
  306. /* wait until the fifos are both flushed */
  307. timeout = 100;
  308. while (1) {
  309. val = readl(hsotg->regs + S3C_GRSTCTL);
  310. if ((val & (S3C_GRSTCTL_TxFFlsh | S3C_GRSTCTL_RxFFlsh)) == 0)
  311. break;
  312. if (--timeout == 0) {
  313. dev_err(hsotg->dev,
  314. "%s: timeout flushing fifos (GRSTCTL=%08x)\n",
  315. __func__, val);
  316. }
  317. udelay(1);
  318. }
  319. dev_dbg(hsotg->dev, "FIFOs reset, timeout at %d\n", timeout);
  320. }
  321. /**
  322. * @ep: USB endpoint to allocate request for.
  323. * @flags: Allocation flags
  324. *
  325. * Allocate a new USB request structure appropriate for the specified endpoint
  326. */
  327. static struct usb_request *s3c_hsotg_ep_alloc_request(struct usb_ep *ep,
  328. gfp_t flags)
  329. {
  330. struct s3c_hsotg_req *req;
  331. req = kzalloc(sizeof(struct s3c_hsotg_req), flags);
  332. if (!req)
  333. return NULL;
  334. INIT_LIST_HEAD(&req->queue);
  335. req->req.dma = DMA_ADDR_INVALID;
  336. return &req->req;
  337. }
  338. /**
  339. * is_ep_periodic - return true if the endpoint is in periodic mode.
  340. * @hs_ep: The endpoint to query.
  341. *
  342. * Returns true if the endpoint is in periodic mode, meaning it is being
  343. * used for an Interrupt or ISO transfer.
  344. */
  345. static inline int is_ep_periodic(struct s3c_hsotg_ep *hs_ep)
  346. {
  347. return hs_ep->periodic;
  348. }
  349. /**
  350. * s3c_hsotg_unmap_dma - unmap the DMA memory being used for the request
  351. * @hsotg: The device state.
  352. * @hs_ep: The endpoint for the request
  353. * @hs_req: The request being processed.
  354. *
  355. * This is the reverse of s3c_hsotg_map_dma(), called for the completion
  356. * of a request to ensure the buffer is ready for access by the caller.
  357. */
  358. static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg,
  359. struct s3c_hsotg_ep *hs_ep,
  360. struct s3c_hsotg_req *hs_req)
  361. {
  362. struct usb_request *req = &hs_req->req;
  363. enum dma_data_direction dir;
  364. dir = hs_ep->dir_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
  365. /* ignore this if we're not moving any data */
  366. if (hs_req->req.length == 0)
  367. return;
  368. if (hs_req->mapped) {
  369. /* we mapped this, so unmap and remove the dma */
  370. dma_unmap_single(hsotg->dev, req->dma, req->length, dir);
  371. req->dma = DMA_ADDR_INVALID;
  372. hs_req->mapped = 0;
  373. } else {
  374. dma_sync_single_for_cpu(hsotg->dev, req->dma, req->length, dir);
  375. }
  376. }
  377. /**
  378. * s3c_hsotg_write_fifo - write packet Data to the TxFIFO
  379. * @hsotg: The controller state.
  380. * @hs_ep: The endpoint we're going to write for.
  381. * @hs_req: The request to write data for.
  382. *
  383. * This is called when the TxFIFO has some space in it to hold a new
  384. * transmission and we have something to give it. The actual setup of
  385. * the data size is done elsewhere, so all we have to do is to actually
  386. * write the data.
  387. *
  388. * The return value is zero if there is more space (or nothing was done)
  389. * otherwise -ENOSPC is returned if the FIFO space was used up.
  390. *
  391. * This routine is only needed for PIO
  392. */
  393. static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
  394. struct s3c_hsotg_ep *hs_ep,
  395. struct s3c_hsotg_req *hs_req)
  396. {
  397. bool periodic = is_ep_periodic(hs_ep);
  398. u32 gnptxsts = readl(hsotg->regs + S3C_GNPTXSTS);
  399. int buf_pos = hs_req->req.actual;
  400. int to_write = hs_ep->size_loaded;
  401. void *data;
  402. int can_write;
  403. int pkt_round;
  404. to_write -= (buf_pos - hs_ep->last_load);
  405. /* if there's nothing to write, get out early */
  406. if (to_write == 0)
  407. return 0;
  408. if (periodic && !hsotg->dedicated_fifos) {
  409. u32 epsize = readl(hsotg->regs + S3C_DIEPTSIZ(hs_ep->index));
  410. int size_left;
  411. int size_done;
  412. /* work out how much data was loaded so we can calculate
  413. * how much data is left in the fifo. */
  414. size_left = S3C_DxEPTSIZ_XferSize_GET(epsize);
  415. /* if shared fifo, we cannot write anything until the
  416. * previous data has been completely sent.
  417. */
  418. if (hs_ep->fifo_load != 0) {
  419. s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp);
  420. return -ENOSPC;
  421. }
  422. dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n",
  423. __func__, size_left,
  424. hs_ep->size_loaded, hs_ep->fifo_load, hs_ep->fifo_size);
  425. /* how much of the data has moved */
  426. size_done = hs_ep->size_loaded - size_left;
  427. /* how much data is left in the fifo */
  428. can_write = hs_ep->fifo_load - size_done;
  429. dev_dbg(hsotg->dev, "%s: => can_write1=%d\n",
  430. __func__, can_write);
  431. can_write = hs_ep->fifo_size - can_write;
  432. dev_dbg(hsotg->dev, "%s: => can_write2=%d\n",
  433. __func__, can_write);
  434. if (can_write <= 0) {
  435. s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp);
  436. return -ENOSPC;
  437. }
  438. } else if (hsotg->dedicated_fifos && hs_ep->index != 0) {
  439. can_write = readl(hsotg->regs + S3C_DTXFSTS(hs_ep->index));
  440. can_write &= 0xffff;
  441. can_write *= 4;
  442. } else {
  443. if (S3C_GNPTXSTS_NPTxQSpcAvail_GET(gnptxsts) == 0) {
  444. dev_dbg(hsotg->dev,
  445. "%s: no queue slots available (0x%08x)\n",
  446. __func__, gnptxsts);
  447. s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_NPTxFEmp);
  448. return -ENOSPC;
  449. }
  450. can_write = S3C_GNPTXSTS_NPTxFSpcAvail_GET(gnptxsts);
  451. can_write *= 4; /* fifo size is in 32bit quantities. */
  452. }
  453. dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n",
  454. __func__, gnptxsts, can_write, to_write, hs_ep->ep.maxpacket);
  455. /* limit to 512 bytes of data, it seems at least on the non-periodic
  456. * FIFO, requests of >512 cause the endpoint to get stuck with a
  457. * fragment of the end of the transfer in it.
  458. */
  459. if (can_write > 512)
  460. can_write = 512;
  461. /* limit the write to one max-packet size worth of data, but allow
  462. * the transfer to return that it did not run out of fifo space
  463. * doing it. */
  464. if (to_write > hs_ep->ep.maxpacket) {
  465. to_write = hs_ep->ep.maxpacket;
  466. s3c_hsotg_en_gsint(hsotg,
  467. periodic ? S3C_GINTSTS_PTxFEmp :
  468. S3C_GINTSTS_NPTxFEmp);
  469. }
  470. /* see if we can write data */
  471. if (to_write > can_write) {
  472. to_write = can_write;
  473. pkt_round = to_write % hs_ep->ep.maxpacket;
  474. /* Not sure, but we probably shouldn't be writing partial
  475. * packets into the FIFO, so round the write down to an
  476. * exact number of packets.
  477. *
  478. * Note, we do not currently check to see if we can ever
  479. * write a full packet or not to the FIFO.
  480. */
  481. if (pkt_round)
  482. to_write -= pkt_round;
  483. /* enable correct FIFO interrupt to alert us when there
  484. * is more room left. */
  485. s3c_hsotg_en_gsint(hsotg,
  486. periodic ? S3C_GINTSTS_PTxFEmp :
  487. S3C_GINTSTS_NPTxFEmp);
  488. }
  489. dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n",
  490. to_write, hs_req->req.length, can_write, buf_pos);
  491. if (to_write <= 0)
  492. return -ENOSPC;
  493. hs_req->req.actual = buf_pos + to_write;
  494. hs_ep->total_data += to_write;
  495. if (periodic)
  496. hs_ep->fifo_load += to_write;
  497. to_write = DIV_ROUND_UP(to_write, 4);
  498. data = hs_req->req.buf + buf_pos;
  499. writesl(hsotg->regs + S3C_EPFIFO(hs_ep->index), data, to_write);
  500. return (to_write >= can_write) ? -ENOSPC : 0;
  501. }
  502. /**
  503. * get_ep_limit - get the maximum data legnth for this endpoint
  504. * @hs_ep: The endpoint
  505. *
  506. * Return the maximum data that can be queued in one go on a given endpoint
  507. * so that transfers that are too long can be split.
  508. */
  509. static unsigned get_ep_limit(struct s3c_hsotg_ep *hs_ep)
  510. {
  511. int index = hs_ep->index;
  512. unsigned maxsize;
  513. unsigned maxpkt;
  514. if (index != 0) {
  515. maxsize = S3C_DxEPTSIZ_XferSize_LIMIT + 1;
  516. maxpkt = S3C_DxEPTSIZ_PktCnt_LIMIT + 1;
  517. } else {
  518. maxsize = 64+64;
  519. if (hs_ep->dir_in) {
  520. maxpkt = S3C_DIEPTSIZ0_PktCnt_LIMIT + 1;
  521. } else {
  522. maxpkt = 2;
  523. }
  524. }
  525. /* we made the constant loading easier above by using +1 */
  526. maxpkt--;
  527. maxsize--;
  528. /* constrain by packet count if maxpkts*pktsize is greater
  529. * than the length register size. */
  530. if ((maxpkt * hs_ep->ep.maxpacket) < maxsize)
  531. maxsize = maxpkt * hs_ep->ep.maxpacket;
  532. return maxsize;
  533. }
  534. /**
  535. * s3c_hsotg_start_req - start a USB request from an endpoint's queue
  536. * @hsotg: The controller state.
  537. * @hs_ep: The endpoint to process a request for
  538. * @hs_req: The request to start.
  539. * @continuing: True if we are doing more for the current request.
  540. *
  541. * Start the given request running by setting the endpoint registers
  542. * appropriately, and writing any data to the FIFOs.
  543. */
  544. static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg,
  545. struct s3c_hsotg_ep *hs_ep,
  546. struct s3c_hsotg_req *hs_req,
  547. bool continuing)
  548. {
  549. struct usb_request *ureq = &hs_req->req;
  550. int index = hs_ep->index;
  551. int dir_in = hs_ep->dir_in;
  552. u32 epctrl_reg;
  553. u32 epsize_reg;
  554. u32 epsize;
  555. u32 ctrl;
  556. unsigned length;
  557. unsigned packets;
  558. unsigned maxreq;
  559. if (index != 0) {
  560. if (hs_ep->req && !continuing) {
  561. dev_err(hsotg->dev, "%s: active request\n", __func__);
  562. WARN_ON(1);
  563. return;
  564. } else if (hs_ep->req != hs_req && continuing) {
  565. dev_err(hsotg->dev,
  566. "%s: continue different req\n", __func__);
  567. WARN_ON(1);
  568. return;
  569. }
  570. }
  571. epctrl_reg = dir_in ? S3C_DIEPCTL(index) : S3C_DOEPCTL(index);
  572. epsize_reg = dir_in ? S3C_DIEPTSIZ(index) : S3C_DOEPTSIZ(index);
  573. dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x, ep %d, dir %s\n",
  574. __func__, readl(hsotg->regs + epctrl_reg), index,
  575. hs_ep->dir_in ? "in" : "out");
  576. length = ureq->length - ureq->actual;
  577. if (0)
  578. dev_dbg(hsotg->dev,
  579. "REQ buf %p len %d dma 0x%08x noi=%d zp=%d snok=%d\n",
  580. ureq->buf, length, ureq->dma,
  581. ureq->no_interrupt, ureq->zero, ureq->short_not_ok);
  582. maxreq = get_ep_limit(hs_ep);
  583. if (length > maxreq) {
  584. int round = maxreq % hs_ep->ep.maxpacket;
  585. dev_dbg(hsotg->dev, "%s: length %d, max-req %d, r %d\n",
  586. __func__, length, maxreq, round);
  587. /* round down to multiple of packets */
  588. if (round)
  589. maxreq -= round;
  590. length = maxreq;
  591. }
  592. if (length)
  593. packets = DIV_ROUND_UP(length, hs_ep->ep.maxpacket);
  594. else
  595. packets = 1; /* send one packet if length is zero. */
  596. if (dir_in && index != 0)
  597. epsize = S3C_DxEPTSIZ_MC(1);
  598. else
  599. epsize = 0;
  600. if (index != 0 && ureq->zero) {
  601. /* test for the packets being exactly right for the
  602. * transfer */
  603. if (length == (packets * hs_ep->ep.maxpacket))
  604. packets++;
  605. }
  606. epsize |= S3C_DxEPTSIZ_PktCnt(packets);
  607. epsize |= S3C_DxEPTSIZ_XferSize(length);
  608. dev_dbg(hsotg->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n",
  609. __func__, packets, length, ureq->length, epsize, epsize_reg);
  610. /* store the request as the current one we're doing */
  611. hs_ep->req = hs_req;
  612. /* write size / packets */
  613. writel(epsize, hsotg->regs + epsize_reg);
  614. ctrl = readl(hsotg->regs + epctrl_reg);
  615. if (ctrl & S3C_DxEPCTL_Stall) {
  616. dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index);
  617. /* not sure what we can do here, if it is EP0 then we should
  618. * get this cleared once the endpoint has transmitted the
  619. * STALL packet, otherwise it needs to be cleared by the
  620. * host.
  621. */
  622. }
  623. if (using_dma(hsotg)) {
  624. unsigned int dma_reg;
  625. /* write DMA address to control register, buffer already
  626. * synced by s3c_hsotg_ep_queue(). */
  627. dma_reg = dir_in ? S3C_DIEPDMA(index) : S3C_DOEPDMA(index);
  628. writel(ureq->dma, hsotg->regs + dma_reg);
  629. dev_dbg(hsotg->dev, "%s: 0x%08x => 0x%08x\n",
  630. __func__, ureq->dma, dma_reg);
  631. }
  632. ctrl |= S3C_DxEPCTL_EPEna; /* ensure ep enabled */
  633. ctrl |= S3C_DxEPCTL_USBActEp;
  634. ctrl |= S3C_DxEPCTL_CNAK; /* clear NAK set by core */
  635. dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl);
  636. writel(ctrl, hsotg->regs + epctrl_reg);
  637. /* set these, it seems that DMA support increments past the end
  638. * of the packet buffer so we need to calculate the length from
  639. * this information. */
  640. hs_ep->size_loaded = length;
  641. hs_ep->last_load = ureq->actual;
  642. if (dir_in && !using_dma(hsotg)) {
  643. /* set these anyway, we may need them for non-periodic in */
  644. hs_ep->fifo_load = 0;
  645. s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req);
  646. }
  647. /* clear the INTknTXFEmpMsk when we start request, more as a aide
  648. * to debugging to see what is going on. */
  649. if (dir_in)
  650. writel(S3C_DIEPMSK_INTknTXFEmpMsk,
  651. hsotg->regs + S3C_DIEPINT(index));
  652. /* Note, trying to clear the NAK here causes problems with transmit
  653. * on the S3C6400 ending up with the TXFIFO becomming full. */
  654. /* check ep is enabled */
  655. if (!(readl(hsotg->regs + epctrl_reg) & S3C_DxEPCTL_EPEna))
  656. dev_warn(hsotg->dev,
  657. "ep%d: failed to become enabled (DxEPCTL=0x%08x)?\n",
  658. index, readl(hsotg->regs + epctrl_reg));
  659. dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n",
  660. __func__, readl(hsotg->regs + epctrl_reg));
  661. }
  662. /**
  663. * s3c_hsotg_map_dma - map the DMA memory being used for the request
  664. * @hsotg: The device state.
  665. * @hs_ep: The endpoint the request is on.
  666. * @req: The request being processed.
  667. *
  668. * We've been asked to queue a request, so ensure that the memory buffer
  669. * is correctly setup for DMA. If we've been passed an extant DMA address
  670. * then ensure the buffer has been synced to memory. If our buffer has no
  671. * DMA memory, then we map the memory and mark our request to allow us to
  672. * cleanup on completion.
  673. */
  674. static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg,
  675. struct s3c_hsotg_ep *hs_ep,
  676. struct usb_request *req)
  677. {
  678. enum dma_data_direction dir;
  679. struct s3c_hsotg_req *hs_req = our_req(req);
  680. dir = hs_ep->dir_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
  681. /* if the length is zero, ignore the DMA data */
  682. if (hs_req->req.length == 0)
  683. return 0;
  684. if (req->dma == DMA_ADDR_INVALID) {
  685. dma_addr_t dma;
  686. dma = dma_map_single(hsotg->dev, req->buf, req->length, dir);
  687. if (unlikely(dma_mapping_error(hsotg->dev, dma)))
  688. goto dma_error;
  689. if (dma & 3) {
  690. dev_err(hsotg->dev, "%s: unaligned dma buffer\n",
  691. __func__);
  692. dma_unmap_single(hsotg->dev, dma, req->length, dir);
  693. return -EINVAL;
  694. }
  695. hs_req->mapped = 1;
  696. req->dma = dma;
  697. } else {
  698. dma_sync_single_for_cpu(hsotg->dev, req->dma, req->length, dir);
  699. hs_req->mapped = 0;
  700. }
  701. return 0;
  702. dma_error:
  703. dev_err(hsotg->dev, "%s: failed to map buffer %p, %d bytes\n",
  704. __func__, req->buf, req->length);
  705. return -EIO;
  706. }
  707. static int s3c_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req,
  708. gfp_t gfp_flags)
  709. {
  710. struct s3c_hsotg_req *hs_req = our_req(req);
  711. struct s3c_hsotg_ep *hs_ep = our_ep(ep);
  712. struct s3c_hsotg *hs = hs_ep->parent;
  713. unsigned long irqflags;
  714. bool first;
  715. dev_dbg(hs->dev, "%s: req %p: %d@%p, noi=%d, zero=%d, snok=%d\n",
  716. ep->name, req, req->length, req->buf, req->no_interrupt,
  717. req->zero, req->short_not_ok);
  718. /* initialise status of the request */
  719. INIT_LIST_HEAD(&hs_req->queue);
  720. req->actual = 0;
  721. req->status = -EINPROGRESS;
  722. /* if we're using DMA, sync the buffers as necessary */
  723. if (using_dma(hs)) {
  724. int ret = s3c_hsotg_map_dma(hs, hs_ep, req);
  725. if (ret)
  726. return ret;
  727. }
  728. spin_lock_irqsave(&hs_ep->lock, irqflags);
  729. first = list_empty(&hs_ep->queue);
  730. list_add_tail(&hs_req->queue, &hs_ep->queue);
  731. if (first)
  732. s3c_hsotg_start_req(hs, hs_ep, hs_req, false);
  733. spin_unlock_irqrestore(&hs_ep->lock, irqflags);
  734. return 0;
  735. }
  736. static void s3c_hsotg_ep_free_request(struct usb_ep *ep,
  737. struct usb_request *req)
  738. {
  739. struct s3c_hsotg_req *hs_req = our_req(req);
  740. kfree(hs_req);
  741. }
  742. /**
  743. * s3c_hsotg_complete_oursetup - setup completion callback
  744. * @ep: The endpoint the request was on.
  745. * @req: The request completed.
  746. *
  747. * Called on completion of any requests the driver itself
  748. * submitted that need cleaning up.
  749. */
  750. static void s3c_hsotg_complete_oursetup(struct usb_ep *ep,
  751. struct usb_request *req)
  752. {
  753. struct s3c_hsotg_ep *hs_ep = our_ep(ep);
  754. struct s3c_hsotg *hsotg = hs_ep->parent;
  755. dev_dbg(hsotg->dev, "%s: ep %p, req %p\n", __func__, ep, req);
  756. s3c_hsotg_ep_free_request(ep, req);
  757. }
  758. /**
  759. * ep_from_windex - convert control wIndex value to endpoint
  760. * @hsotg: The driver state.
  761. * @windex: The control request wIndex field (in host order).
  762. *
  763. * Convert the given wIndex into a pointer to an driver endpoint
  764. * structure, or return NULL if it is not a valid endpoint.
  765. */
  766. static struct s3c_hsotg_ep *ep_from_windex(struct s3c_hsotg *hsotg,
  767. u32 windex)
  768. {
  769. struct s3c_hsotg_ep *ep = &hsotg->eps[windex & 0x7F];
  770. int dir = (windex & USB_DIR_IN) ? 1 : 0;
  771. int idx = windex & 0x7F;
  772. if (windex >= 0x100)
  773. return NULL;
  774. if (idx > S3C_HSOTG_EPS)
  775. return NULL;
  776. if (idx && ep->dir_in != dir)
  777. return NULL;
  778. return ep;
  779. }
  780. /**
  781. * s3c_hsotg_send_reply - send reply to control request
  782. * @hsotg: The device state
  783. * @ep: Endpoint 0
  784. * @buff: Buffer for request
  785. * @length: Length of reply.
  786. *
  787. * Create a request and queue it on the given endpoint. This is useful as
  788. * an internal method of sending replies to certain control requests, etc.
  789. */
  790. static int s3c_hsotg_send_reply(struct s3c_hsotg *hsotg,
  791. struct s3c_hsotg_ep *ep,
  792. void *buff,
  793. int length)
  794. {
  795. struct usb_request *req;
  796. int ret;
  797. dev_dbg(hsotg->dev, "%s: buff %p, len %d\n", __func__, buff, length);
  798. req = s3c_hsotg_ep_alloc_request(&ep->ep, GFP_ATOMIC);
  799. hsotg->ep0_reply = req;
  800. if (!req) {
  801. dev_warn(hsotg->dev, "%s: cannot alloc req\n", __func__);
  802. return -ENOMEM;
  803. }
  804. req->buf = hsotg->ep0_buff;
  805. req->length = length;
  806. req->zero = 1; /* always do zero-length final transfer */
  807. req->complete = s3c_hsotg_complete_oursetup;
  808. if (length)
  809. memcpy(req->buf, buff, length);
  810. else
  811. ep->sent_zlp = 1;
  812. ret = s3c_hsotg_ep_queue(&ep->ep, req, GFP_ATOMIC);
  813. if (ret) {
  814. dev_warn(hsotg->dev, "%s: cannot queue req\n", __func__);
  815. return ret;
  816. }
  817. return 0;
  818. }
  819. /**
  820. * s3c_hsotg_process_req_status - process request GET_STATUS
  821. * @hsotg: The device state
  822. * @ctrl: USB control request
  823. */
  824. static int s3c_hsotg_process_req_status(struct s3c_hsotg *hsotg,
  825. struct usb_ctrlrequest *ctrl)
  826. {
  827. struct s3c_hsotg_ep *ep0 = &hsotg->eps[0];
  828. struct s3c_hsotg_ep *ep;
  829. __le16 reply;
  830. int ret;
  831. dev_dbg(hsotg->dev, "%s: USB_REQ_GET_STATUS\n", __func__);
  832. if (!ep0->dir_in) {
  833. dev_warn(hsotg->dev, "%s: direction out?\n", __func__);
  834. return -EINVAL;
  835. }
  836. switch (ctrl->bRequestType & USB_RECIP_MASK) {
  837. case USB_RECIP_DEVICE:
  838. reply = cpu_to_le16(0); /* bit 0 => self powered,
  839. * bit 1 => remote wakeup */
  840. break;
  841. case USB_RECIP_INTERFACE:
  842. /* currently, the data result should be zero */
  843. reply = cpu_to_le16(0);
  844. break;
  845. case USB_RECIP_ENDPOINT:
  846. ep = ep_from_windex(hsotg, le16_to_cpu(ctrl->wIndex));
  847. if (!ep)
  848. return -ENOENT;
  849. reply = cpu_to_le16(ep->halted ? 1 : 0);
  850. break;
  851. default:
  852. return 0;
  853. }
  854. if (le16_to_cpu(ctrl->wLength) != 2)
  855. return -EINVAL;
  856. ret = s3c_hsotg_send_reply(hsotg, ep0, &reply, 2);
  857. if (ret) {
  858. dev_err(hsotg->dev, "%s: failed to send reply\n", __func__);
  859. return ret;
  860. }
  861. return 1;
  862. }
  863. static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value);
  864. /**
  865. * s3c_hsotg_process_req_featire - process request {SET,CLEAR}_FEATURE
  866. * @hsotg: The device state
  867. * @ctrl: USB control request
  868. */
  869. static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg,
  870. struct usb_ctrlrequest *ctrl)
  871. {
  872. bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE);
  873. struct s3c_hsotg_ep *ep;
  874. dev_dbg(hsotg->dev, "%s: %s_FEATURE\n",
  875. __func__, set ? "SET" : "CLEAR");
  876. if (ctrl->bRequestType == USB_RECIP_ENDPOINT) {
  877. ep = ep_from_windex(hsotg, le16_to_cpu(ctrl->wIndex));
  878. if (!ep) {
  879. dev_dbg(hsotg->dev, "%s: no endpoint for 0x%04x\n",
  880. __func__, le16_to_cpu(ctrl->wIndex));
  881. return -ENOENT;
  882. }
  883. switch (le16_to_cpu(ctrl->wValue)) {
  884. case USB_ENDPOINT_HALT:
  885. s3c_hsotg_ep_sethalt(&ep->ep, set);
  886. break;
  887. default:
  888. return -ENOENT;
  889. }
  890. } else
  891. return -ENOENT; /* currently only deal with endpoint */
  892. return 1;
  893. }
  894. /**
  895. * s3c_hsotg_process_control - process a control request
  896. * @hsotg: The device state
  897. * @ctrl: The control request received
  898. *
  899. * The controller has received the SETUP phase of a control request, and
  900. * needs to work out what to do next (and whether to pass it on to the
  901. * gadget driver).
  902. */
  903. static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,
  904. struct usb_ctrlrequest *ctrl)
  905. {
  906. struct s3c_hsotg_ep *ep0 = &hsotg->eps[0];
  907. int ret = 0;
  908. u32 dcfg;
  909. ep0->sent_zlp = 0;
  910. dev_dbg(hsotg->dev, "ctrl Req=%02x, Type=%02x, V=%04x, L=%04x\n",
  911. ctrl->bRequest, ctrl->bRequestType,
  912. ctrl->wValue, ctrl->wLength);
  913. /* record the direction of the request, for later use when enquing
  914. * packets onto EP0. */
  915. ep0->dir_in = (ctrl->bRequestType & USB_DIR_IN) ? 1 : 0;
  916. dev_dbg(hsotg->dev, "ctrl: dir_in=%d\n", ep0->dir_in);
  917. /* if we've no data with this request, then the last part of the
  918. * transaction is going to implicitly be IN. */
  919. if (ctrl->wLength == 0)
  920. ep0->dir_in = 1;
  921. if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
  922. switch (ctrl->bRequest) {
  923. case USB_REQ_SET_ADDRESS:
  924. dcfg = readl(hsotg->regs + S3C_DCFG);
  925. dcfg &= ~S3C_DCFG_DevAddr_MASK;
  926. dcfg |= ctrl->wValue << S3C_DCFG_DevAddr_SHIFT;
  927. writel(dcfg, hsotg->regs + S3C_DCFG);
  928. dev_info(hsotg->dev, "new address %d\n", ctrl->wValue);
  929. ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0);
  930. return;
  931. case USB_REQ_GET_STATUS:
  932. ret = s3c_hsotg_process_req_status(hsotg, ctrl);
  933. break;
  934. case USB_REQ_CLEAR_FEATURE:
  935. case USB_REQ_SET_FEATURE:
  936. ret = s3c_hsotg_process_req_feature(hsotg, ctrl);
  937. break;
  938. }
  939. }
  940. /* as a fallback, try delivering it to the driver to deal with */
  941. if (ret == 0 && hsotg->driver) {
  942. ret = hsotg->driver->setup(&hsotg->gadget, ctrl);
  943. if (ret < 0)
  944. dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret);
  945. }
  946. if (ret > 0) {
  947. if (!ep0->dir_in) {
  948. /* need to generate zlp in reply or take data */
  949. /* todo - deal with any data we might be sent? */
  950. ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0);
  951. }
  952. }
  953. /* the request is either unhandlable, or is not formatted correctly
  954. * so respond with a STALL for the status stage to indicate failure.
  955. */
  956. if (ret < 0) {
  957. u32 reg;
  958. u32 ctrl;
  959. dev_dbg(hsotg->dev, "ep0 stall (dir=%d)\n", ep0->dir_in);
  960. reg = (ep0->dir_in) ? S3C_DIEPCTL0 : S3C_DOEPCTL0;
  961. /* S3C_DxEPCTL_Stall will be cleared by EP once it has
  962. * taken effect, so no need to clear later. */
  963. ctrl = readl(hsotg->regs + reg);
  964. ctrl |= S3C_DxEPCTL_Stall;
  965. ctrl |= S3C_DxEPCTL_CNAK;
  966. writel(ctrl, hsotg->regs + reg);
  967. dev_dbg(hsotg->dev,
  968. "writen DxEPCTL=0x%08x to %08x (DxEPCTL=0x%08x)\n",
  969. ctrl, reg, readl(hsotg->regs + reg));
  970. /* don't belive we need to anything more to get the EP
  971. * to reply with a STALL packet */
  972. }
  973. }
  974. static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg);
  975. /**
  976. * s3c_hsotg_complete_setup - completion of a setup transfer
  977. * @ep: The endpoint the request was on.
  978. * @req: The request completed.
  979. *
  980. * Called on completion of any requests the driver itself submitted for
  981. * EP0 setup packets
  982. */
  983. static void s3c_hsotg_complete_setup(struct usb_ep *ep,
  984. struct usb_request *req)
  985. {
  986. struct s3c_hsotg_ep *hs_ep = our_ep(ep);
  987. struct s3c_hsotg *hsotg = hs_ep->parent;
  988. if (req->status < 0) {
  989. dev_dbg(hsotg->dev, "%s: failed %d\n", __func__, req->status);
  990. return;
  991. }
  992. if (req->actual == 0)
  993. s3c_hsotg_enqueue_setup(hsotg);
  994. else
  995. s3c_hsotg_process_control(hsotg, req->buf);
  996. }
  997. /**
  998. * s3c_hsotg_enqueue_setup - start a request for EP0 packets
  999. * @hsotg: The device state.
  1000. *
  1001. * Enqueue a request on EP0 if necessary to received any SETUP packets
  1002. * received from the host.
  1003. */
  1004. static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg)
  1005. {
  1006. struct usb_request *req = hsotg->ctrl_req;
  1007. struct s3c_hsotg_req *hs_req = our_req(req);
  1008. int ret;
  1009. dev_dbg(hsotg->dev, "%s: queueing setup request\n", __func__);
  1010. req->zero = 0;
  1011. req->length = 8;
  1012. req->buf = hsotg->ctrl_buff;
  1013. req->complete = s3c_hsotg_complete_setup;
  1014. if (!list_empty(&hs_req->queue)) {
  1015. dev_dbg(hsotg->dev, "%s already queued???\n", __func__);
  1016. return;
  1017. }
  1018. hsotg->eps[0].dir_in = 0;
  1019. ret = s3c_hsotg_ep_queue(&hsotg->eps[0].ep, req, GFP_ATOMIC);
  1020. if (ret < 0) {
  1021. dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret);
  1022. /* Don't think there's much we can do other than watch the
  1023. * driver fail. */
  1024. }
  1025. }
  1026. /**
  1027. * get_ep_head - return the first request on the endpoint
  1028. * @hs_ep: The controller endpoint to get
  1029. *
  1030. * Get the first request on the endpoint.
  1031. */
  1032. static struct s3c_hsotg_req *get_ep_head(struct s3c_hsotg_ep *hs_ep)
  1033. {
  1034. if (list_empty(&hs_ep->queue))
  1035. return NULL;
  1036. return list_first_entry(&hs_ep->queue, struct s3c_hsotg_req, queue);
  1037. }
  1038. /**
  1039. * s3c_hsotg_complete_request - complete a request given to us
  1040. * @hsotg: The device state.
  1041. * @hs_ep: The endpoint the request was on.
  1042. * @hs_req: The request to complete.
  1043. * @result: The result code (0 => Ok, otherwise errno)
  1044. *
  1045. * The given request has finished, so call the necessary completion
  1046. * if it has one and then look to see if we can start a new request
  1047. * on the endpoint.
  1048. *
  1049. * Note, expects the ep to already be locked as appropriate.
  1050. */
  1051. static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg,
  1052. struct s3c_hsotg_ep *hs_ep,
  1053. struct s3c_hsotg_req *hs_req,
  1054. int result)
  1055. {
  1056. bool restart;
  1057. if (!hs_req) {
  1058. dev_dbg(hsotg->dev, "%s: nothing to complete?\n", __func__);
  1059. return;
  1060. }
  1061. dev_dbg(hsotg->dev, "complete: ep %p %s, req %p, %d => %p\n",
  1062. hs_ep, hs_ep->ep.name, hs_req, result, hs_req->req.complete);
  1063. /* only replace the status if we've not already set an error
  1064. * from a previous transaction */
  1065. if (hs_req->req.status == -EINPROGRESS)
  1066. hs_req->req.status = result;
  1067. hs_ep->req = NULL;
  1068. list_del_init(&hs_req->queue);
  1069. if (using_dma(hsotg))
  1070. s3c_hsotg_unmap_dma(hsotg, hs_ep, hs_req);
  1071. /* call the complete request with the locks off, just in case the
  1072. * request tries to queue more work for this endpoint. */
  1073. if (hs_req->req.complete) {
  1074. spin_unlock(&hs_ep->lock);
  1075. hs_req->req.complete(&hs_ep->ep, &hs_req->req);
  1076. spin_lock(&hs_ep->lock);
  1077. }
  1078. /* Look to see if there is anything else to do. Note, the completion
  1079. * of the previous request may have caused a new request to be started
  1080. * so be careful when doing this. */
  1081. if (!hs_ep->req && result >= 0) {
  1082. restart = !list_empty(&hs_ep->queue);
  1083. if (restart) {
  1084. hs_req = get_ep_head(hs_ep);
  1085. s3c_hsotg_start_req(hsotg, hs_ep, hs_req, false);
  1086. }
  1087. }
  1088. }
  1089. /**
  1090. * s3c_hsotg_complete_request_lock - complete a request given to us (locked)
  1091. * @hsotg: The device state.
  1092. * @hs_ep: The endpoint the request was on.
  1093. * @hs_req: The request to complete.
  1094. * @result: The result code (0 => Ok, otherwise errno)
  1095. *
  1096. * See s3c_hsotg_complete_request(), but called with the endpoint's
  1097. * lock held.
  1098. */
  1099. static void s3c_hsotg_complete_request_lock(struct s3c_hsotg *hsotg,
  1100. struct s3c_hsotg_ep *hs_ep,
  1101. struct s3c_hsotg_req *hs_req,
  1102. int result)
  1103. {
  1104. unsigned long flags;
  1105. spin_lock_irqsave(&hs_ep->lock, flags);
  1106. s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, result);
  1107. spin_unlock_irqrestore(&hs_ep->lock, flags);
  1108. }
  1109. /**
  1110. * s3c_hsotg_rx_data - receive data from the FIFO for an endpoint
  1111. * @hsotg: The device state.
  1112. * @ep_idx: The endpoint index for the data
  1113. * @size: The size of data in the fifo, in bytes
  1114. *
  1115. * The FIFO status shows there is data to read from the FIFO for a given
  1116. * endpoint, so sort out whether we need to read the data into a request
  1117. * that has been made for that endpoint.
  1118. */
  1119. static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size)
  1120. {
  1121. struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep_idx];
  1122. struct s3c_hsotg_req *hs_req = hs_ep->req;
  1123. void __iomem *fifo = hsotg->regs + S3C_EPFIFO(ep_idx);
  1124. int to_read;
  1125. int max_req;
  1126. int read_ptr;
  1127. if (!hs_req) {
  1128. u32 epctl = readl(hsotg->regs + S3C_DOEPCTL(ep_idx));
  1129. int ptr;
  1130. dev_warn(hsotg->dev,
  1131. "%s: FIFO %d bytes on ep%d but no req (DxEPCTl=0x%08x)\n",
  1132. __func__, size, ep_idx, epctl);
  1133. /* dump the data from the FIFO, we've nothing we can do */
  1134. for (ptr = 0; ptr < size; ptr += 4)
  1135. (void)readl(fifo);
  1136. return;
  1137. }
  1138. spin_lock(&hs_ep->lock);
  1139. to_read = size;
  1140. read_ptr = hs_req->req.actual;
  1141. max_req = hs_req->req.length - read_ptr;
  1142. dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n",
  1143. __func__, to_read, max_req, read_ptr, hs_req->req.length);
  1144. if (to_read > max_req) {
  1145. /* more data appeared than we where willing
  1146. * to deal with in this request.
  1147. */
  1148. /* currently we don't deal this */
  1149. WARN_ON_ONCE(1);
  1150. }
  1151. hs_ep->total_data += to_read;
  1152. hs_req->req.actual += to_read;
  1153. to_read = DIV_ROUND_UP(to_read, 4);
  1154. /* note, we might over-write the buffer end by 3 bytes depending on
  1155. * alignment of the data. */
  1156. readsl(fifo, hs_req->req.buf + read_ptr, to_read);
  1157. spin_unlock(&hs_ep->lock);
  1158. }
  1159. /**
  1160. * s3c_hsotg_send_zlp - send zero-length packet on control endpoint
  1161. * @hsotg: The device instance
  1162. * @req: The request currently on this endpoint
  1163. *
  1164. * Generate a zero-length IN packet request for terminating a SETUP
  1165. * transaction.
  1166. *
  1167. * Note, since we don't write any data to the TxFIFO, then it is
  1168. * currently belived that we do not need to wait for any space in
  1169. * the TxFIFO.
  1170. */
  1171. static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg,
  1172. struct s3c_hsotg_req *req)
  1173. {
  1174. u32 ctrl;
  1175. if (!req) {
  1176. dev_warn(hsotg->dev, "%s: no request?\n", __func__);
  1177. return;
  1178. }
  1179. if (req->req.length == 0) {
  1180. hsotg->eps[0].sent_zlp = 1;
  1181. s3c_hsotg_enqueue_setup(hsotg);
  1182. return;
  1183. }
  1184. hsotg->eps[0].dir_in = 1;
  1185. hsotg->eps[0].sent_zlp = 1;
  1186. dev_dbg(hsotg->dev, "sending zero-length packet\n");
  1187. /* issue a zero-sized packet to terminate this */
  1188. writel(S3C_DxEPTSIZ_MC(1) | S3C_DxEPTSIZ_PktCnt(1) |
  1189. S3C_DxEPTSIZ_XferSize(0), hsotg->regs + S3C_DIEPTSIZ(0));
  1190. ctrl = readl(hsotg->regs + S3C_DIEPCTL0);
  1191. ctrl |= S3C_DxEPCTL_CNAK; /* clear NAK set by core */
  1192. ctrl |= S3C_DxEPCTL_EPEna; /* ensure ep enabled */
  1193. ctrl |= S3C_DxEPCTL_USBActEp;
  1194. writel(ctrl, hsotg->regs + S3C_DIEPCTL0);
  1195. }
  1196. /**
  1197. * s3c_hsotg_handle_outdone - handle receiving OutDone/SetupDone from RXFIFO
  1198. * @hsotg: The device instance
  1199. * @epnum: The endpoint received from
  1200. * @was_setup: Set if processing a SetupDone event.
  1201. *
  1202. * The RXFIFO has delivered an OutDone event, which means that the data
  1203. * transfer for an OUT endpoint has been completed, either by a short
  1204. * packet or by the finish of a transfer.
  1205. */
  1206. static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg,
  1207. int epnum, bool was_setup)
  1208. {
  1209. u32 epsize = readl(hsotg->regs + S3C_DOEPTSIZ(epnum));
  1210. struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum];
  1211. struct s3c_hsotg_req *hs_req = hs_ep->req;
  1212. struct usb_request *req = &hs_req->req;
  1213. unsigned size_left = S3C_DxEPTSIZ_XferSize_GET(epsize);
  1214. int result = 0;
  1215. if (!hs_req) {
  1216. dev_dbg(hsotg->dev, "%s: no request active\n", __func__);
  1217. return;
  1218. }
  1219. if (using_dma(hsotg)) {
  1220. unsigned size_done;
  1221. /* Calculate the size of the transfer by checking how much
  1222. * is left in the endpoint size register and then working it
  1223. * out from the amount we loaded for the transfer.
  1224. *
  1225. * We need to do this as DMA pointers are always 32bit aligned
  1226. * so may overshoot/undershoot the transfer.
  1227. */
  1228. size_done = hs_ep->size_loaded - size_left;
  1229. size_done += hs_ep->last_load;
  1230. req->actual = size_done;
  1231. }
  1232. /* if there is more request to do, schedule new transfer */
  1233. if (req->actual < req->length && size_left == 0) {
  1234. s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true);
  1235. return;
  1236. }
  1237. if (req->actual < req->length && req->short_not_ok) {
  1238. dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n",
  1239. __func__, req->actual, req->length);
  1240. /* todo - what should we return here? there's no one else
  1241. * even bothering to check the status. */
  1242. }
  1243. if (epnum == 0) {
  1244. if (!was_setup && req->complete != s3c_hsotg_complete_setup)
  1245. s3c_hsotg_send_zlp(hsotg, hs_req);
  1246. }
  1247. s3c_hsotg_complete_request_lock(hsotg, hs_ep, hs_req, result);
  1248. }
  1249. /**
  1250. * s3c_hsotg_read_frameno - read current frame number
  1251. * @hsotg: The device instance
  1252. *
  1253. * Return the current frame number
  1254. */
  1255. static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg)
  1256. {
  1257. u32 dsts;
  1258. dsts = readl(hsotg->regs + S3C_DSTS);
  1259. dsts &= S3C_DSTS_SOFFN_MASK;
  1260. dsts >>= S3C_DSTS_SOFFN_SHIFT;
  1261. return dsts;
  1262. }
  1263. /**
  1264. * s3c_hsotg_handle_rx - RX FIFO has data
  1265. * @hsotg: The device instance
  1266. *
  1267. * The IRQ handler has detected that the RX FIFO has some data in it
  1268. * that requires processing, so find out what is in there and do the
  1269. * appropriate read.
  1270. *
  1271. * The RXFIFO is a true FIFO, the packets comming out are still in packet
  1272. * chunks, so if you have x packets received on an endpoint you'll get x
  1273. * FIFO events delivered, each with a packet's worth of data in it.
  1274. *
  1275. * When using DMA, we should not be processing events from the RXFIFO
  1276. * as the actual data should be sent to the memory directly and we turn
  1277. * on the completion interrupts to get notifications of transfer completion.
  1278. */
  1279. static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg)
  1280. {
  1281. u32 grxstsr = readl(hsotg->regs + S3C_GRXSTSP);
  1282. u32 epnum, status, size;
  1283. WARN_ON(using_dma(hsotg));
  1284. epnum = grxstsr & S3C_GRXSTS_EPNum_MASK;
  1285. status = grxstsr & S3C_GRXSTS_PktSts_MASK;
  1286. size = grxstsr & S3C_GRXSTS_ByteCnt_MASK;
  1287. size >>= S3C_GRXSTS_ByteCnt_SHIFT;
  1288. if (1)
  1289. dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n",
  1290. __func__, grxstsr, size, epnum);
  1291. #define __status(x) ((x) >> S3C_GRXSTS_PktSts_SHIFT)
  1292. switch (status >> S3C_GRXSTS_PktSts_SHIFT) {
  1293. case __status(S3C_GRXSTS_PktSts_GlobalOutNAK):
  1294. dev_dbg(hsotg->dev, "GlobalOutNAK\n");
  1295. break;
  1296. case __status(S3C_GRXSTS_PktSts_OutDone):
  1297. dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n",
  1298. s3c_hsotg_read_frameno(hsotg));
  1299. if (!using_dma(hsotg))
  1300. s3c_hsotg_handle_outdone(hsotg, epnum, false);
  1301. break;
  1302. case __status(S3C_GRXSTS_PktSts_SetupDone):
  1303. dev_dbg(hsotg->dev,
  1304. "SetupDone (Frame=0x%08x, DOPEPCTL=0x%08x)\n",
  1305. s3c_hsotg_read_frameno(hsotg),
  1306. readl(hsotg->regs + S3C_DOEPCTL(0)));
  1307. s3c_hsotg_handle_outdone(hsotg, epnum, true);
  1308. break;
  1309. case __status(S3C_GRXSTS_PktSts_OutRX):
  1310. s3c_hsotg_rx_data(hsotg, epnum, size);
  1311. break;
  1312. case __status(S3C_GRXSTS_PktSts_SetupRX):
  1313. dev_dbg(hsotg->dev,
  1314. "SetupRX (Frame=0x%08x, DOPEPCTL=0x%08x)\n",
  1315. s3c_hsotg_read_frameno(hsotg),
  1316. readl(hsotg->regs + S3C_DOEPCTL(0)));
  1317. s3c_hsotg_rx_data(hsotg, epnum, size);
  1318. break;
  1319. default:
  1320. dev_warn(hsotg->dev, "%s: unknown status %08x\n",
  1321. __func__, grxstsr);
  1322. s3c_hsotg_dump(hsotg);
  1323. break;
  1324. }
  1325. }
  1326. /**
  1327. * s3c_hsotg_ep0_mps - turn max packet size into register setting
  1328. * @mps: The maximum packet size in bytes.
  1329. */
  1330. static u32 s3c_hsotg_ep0_mps(unsigned int mps)
  1331. {
  1332. switch (mps) {
  1333. case 64:
  1334. return S3C_D0EPCTL_MPS_64;
  1335. case 32:
  1336. return S3C_D0EPCTL_MPS_32;
  1337. case 16:
  1338. return S3C_D0EPCTL_MPS_16;
  1339. case 8:
  1340. return S3C_D0EPCTL_MPS_8;
  1341. }
  1342. /* bad max packet size, warn and return invalid result */
  1343. WARN_ON(1);
  1344. return (u32)-1;
  1345. }
  1346. /**
  1347. * s3c_hsotg_set_ep_maxpacket - set endpoint's max-packet field
  1348. * @hsotg: The driver state.
  1349. * @ep: The index number of the endpoint
  1350. * @mps: The maximum packet size in bytes
  1351. *
  1352. * Configure the maximum packet size for the given endpoint, updating
  1353. * the hardware control registers to reflect this.
  1354. */
  1355. static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg,
  1356. unsigned int ep, unsigned int mps)
  1357. {
  1358. struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep];
  1359. void __iomem *regs = hsotg->regs;
  1360. u32 mpsval;
  1361. u32 reg;
  1362. if (ep == 0) {
  1363. /* EP0 is a special case */
  1364. mpsval = s3c_hsotg_ep0_mps(mps);
  1365. if (mpsval > 3)
  1366. goto bad_mps;
  1367. } else {
  1368. if (mps >= S3C_DxEPCTL_MPS_LIMIT+1)
  1369. goto bad_mps;
  1370. mpsval = mps;
  1371. }
  1372. hs_ep->ep.maxpacket = mps;
  1373. /* update both the in and out endpoint controldir_ registers, even
  1374. * if one of the directions may not be in use. */
  1375. reg = readl(regs + S3C_DIEPCTL(ep));
  1376. reg &= ~S3C_DxEPCTL_MPS_MASK;
  1377. reg |= mpsval;
  1378. writel(reg, regs + S3C_DIEPCTL(ep));
  1379. reg = readl(regs + S3C_DOEPCTL(ep));
  1380. reg &= ~S3C_DxEPCTL_MPS_MASK;
  1381. reg |= mpsval;
  1382. writel(reg, regs + S3C_DOEPCTL(ep));
  1383. return;
  1384. bad_mps:
  1385. dev_err(hsotg->dev, "ep%d: bad mps of %d\n", ep, mps);
  1386. }
  1387. /**
  1388. * s3c_hsotg_trytx - check to see if anything needs transmitting
  1389. * @hsotg: The driver state
  1390. * @hs_ep: The driver endpoint to check.
  1391. *
  1392. * Check to see if there is a request that has data to send, and if so
  1393. * make an attempt to write data into the FIFO.
  1394. */
  1395. static int s3c_hsotg_trytx(struct s3c_hsotg *hsotg,
  1396. struct s3c_hsotg_ep *hs_ep)
  1397. {
  1398. struct s3c_hsotg_req *hs_req = hs_ep->req;
  1399. if (!hs_ep->dir_in || !hs_req)
  1400. return 0;
  1401. if (hs_req->req.actual < hs_req->req.length) {
  1402. dev_dbg(hsotg->dev, "trying to write more for ep%d\n",
  1403. hs_ep->index);
  1404. return s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req);
  1405. }
  1406. return 0;
  1407. }
  1408. /**
  1409. * s3c_hsotg_complete_in - complete IN transfer
  1410. * @hsotg: The device state.
  1411. * @hs_ep: The endpoint that has just completed.
  1412. *
  1413. * An IN transfer has been completed, update the transfer's state and then
  1414. * call the relevant completion routines.
  1415. */
  1416. static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg,
  1417. struct s3c_hsotg_ep *hs_ep)
  1418. {
  1419. struct s3c_hsotg_req *hs_req = hs_ep->req;
  1420. u32 epsize = readl(hsotg->regs + S3C_DIEPTSIZ(hs_ep->index));
  1421. int size_left, size_done;
  1422. if (!hs_req) {
  1423. dev_dbg(hsotg->dev, "XferCompl but no req\n");
  1424. return;
  1425. }
  1426. /* Calculate the size of the transfer by checking how much is left
  1427. * in the endpoint size register and then working it out from
  1428. * the amount we loaded for the transfer.
  1429. *
  1430. * We do this even for DMA, as the transfer may have incremented
  1431. * past the end of the buffer (DMA transfers are always 32bit
  1432. * aligned).
  1433. */
  1434. size_left = S3C_DxEPTSIZ_XferSize_GET(epsize);
  1435. size_done = hs_ep->size_loaded - size_left;
  1436. size_done += hs_ep->last_load;
  1437. if (hs_req->req.actual != size_done)
  1438. dev_dbg(hsotg->dev, "%s: adjusting size done %d => %d\n",
  1439. __func__, hs_req->req.actual, size_done);
  1440. hs_req->req.actual = size_done;
  1441. /* if we did all of the transfer, and there is more data left
  1442. * around, then try restarting the rest of the request */
  1443. if (!size_left && hs_req->req.actual < hs_req->req.length) {
  1444. dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__);
  1445. s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true);
  1446. } else
  1447. s3c_hsotg_complete_request_lock(hsotg, hs_ep, hs_req, 0);
  1448. }
  1449. /**
  1450. * s3c_hsotg_epint - handle an in/out endpoint interrupt
  1451. * @hsotg: The driver state
  1452. * @idx: The index for the endpoint (0..15)
  1453. * @dir_in: Set if this is an IN endpoint
  1454. *
  1455. * Process and clear any interrupt pending for an individual endpoint
  1456. */
  1457. static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
  1458. int dir_in)
  1459. {
  1460. struct s3c_hsotg_ep *hs_ep = &hsotg->eps[idx];
  1461. u32 epint_reg = dir_in ? S3C_DIEPINT(idx) : S3C_DOEPINT(idx);
  1462. u32 epctl_reg = dir_in ? S3C_DIEPCTL(idx) : S3C_DOEPCTL(idx);
  1463. u32 epsiz_reg = dir_in ? S3C_DIEPTSIZ(idx) : S3C_DOEPTSIZ(idx);
  1464. u32 ints;
  1465. u32 clear = 0;
  1466. ints = readl(hsotg->regs + epint_reg);
  1467. dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n",
  1468. __func__, idx, dir_in ? "in" : "out", ints);
  1469. if (ints & S3C_DxEPINT_XferCompl) {
  1470. dev_dbg(hsotg->dev,
  1471. "%s: XferCompl: DxEPCTL=0x%08x, DxEPTSIZ=%08x\n",
  1472. __func__, readl(hsotg->regs + epctl_reg),
  1473. readl(hsotg->regs + epsiz_reg));
  1474. /* we get OutDone from the FIFO, so we only need to look
  1475. * at completing IN requests here */
  1476. if (dir_in) {
  1477. s3c_hsotg_complete_in(hsotg, hs_ep);
  1478. if (idx == 0 && !hs_ep->req)
  1479. s3c_hsotg_enqueue_setup(hsotg);
  1480. } else if (using_dma(hsotg)) {
  1481. /* We're using DMA, we need to fire an OutDone here
  1482. * as we ignore the RXFIFO. */
  1483. s3c_hsotg_handle_outdone(hsotg, idx, false);
  1484. }
  1485. clear |= S3C_DxEPINT_XferCompl;
  1486. }
  1487. if (ints & S3C_DxEPINT_EPDisbld) {
  1488. dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__);
  1489. clear |= S3C_DxEPINT_EPDisbld;
  1490. }
  1491. if (ints & S3C_DxEPINT_AHBErr) {
  1492. dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__);
  1493. clear |= S3C_DxEPINT_AHBErr;
  1494. }
  1495. if (ints & S3C_DxEPINT_Setup) { /* Setup or Timeout */
  1496. dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__);
  1497. if (using_dma(hsotg) && idx == 0) {
  1498. /* this is the notification we've received a
  1499. * setup packet. In non-DMA mode we'd get this
  1500. * from the RXFIFO, instead we need to process
  1501. * the setup here. */
  1502. if (dir_in)
  1503. WARN_ON_ONCE(1);
  1504. else
  1505. s3c_hsotg_handle_outdone(hsotg, 0, true);
  1506. }
  1507. clear |= S3C_DxEPINT_Setup;
  1508. }
  1509. if (ints & S3C_DxEPINT_Back2BackSetup) {
  1510. dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__);
  1511. clear |= S3C_DxEPINT_Back2BackSetup;
  1512. }
  1513. if (dir_in) {
  1514. /* not sure if this is important, but we'll clear it anyway
  1515. */
  1516. if (ints & S3C_DIEPMSK_INTknTXFEmpMsk) {
  1517. dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n",
  1518. __func__, idx);
  1519. clear |= S3C_DIEPMSK_INTknTXFEmpMsk;
  1520. }
  1521. /* this probably means something bad is happening */
  1522. if (ints & S3C_DIEPMSK_INTknEPMisMsk) {
  1523. dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n",
  1524. __func__, idx);
  1525. clear |= S3C_DIEPMSK_INTknEPMisMsk;
  1526. }
  1527. /* FIFO has space or is empty (see GAHBCFG) */
  1528. if (hsotg->dedicated_fifos &&
  1529. ints & S3C_DIEPMSK_TxFIFOEmpty) {
  1530. dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n",
  1531. __func__, idx);
  1532. s3c_hsotg_trytx(hsotg, hs_ep);
  1533. clear |= S3C_DIEPMSK_TxFIFOEmpty;
  1534. }
  1535. }
  1536. writel(clear, hsotg->regs + epint_reg);
  1537. }
  1538. /**
  1539. * s3c_hsotg_irq_enumdone - Handle EnumDone interrupt (enumeration done)
  1540. * @hsotg: The device state.
  1541. *
  1542. * Handle updating the device settings after the enumeration phase has
  1543. * been completed.
  1544. */
  1545. static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg)
  1546. {
  1547. u32 dsts = readl(hsotg->regs + S3C_DSTS);
  1548. int ep0_mps = 0, ep_mps;
  1549. /* This should signal the finish of the enumeration phase
  1550. * of the USB handshaking, so we should now know what rate
  1551. * we connected at. */
  1552. dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts);
  1553. /* note, since we're limited by the size of transfer on EP0, and
  1554. * it seems IN transfers must be a even number of packets we do
  1555. * not advertise a 64byte MPS on EP0. */
  1556. /* catch both EnumSpd_FS and EnumSpd_FS48 */
  1557. switch (dsts & S3C_DSTS_EnumSpd_MASK) {
  1558. case S3C_DSTS_EnumSpd_FS:
  1559. case S3C_DSTS_EnumSpd_FS48:
  1560. hsotg->gadget.speed = USB_SPEED_FULL;
  1561. dev_info(hsotg->dev, "new device is full-speed\n");
  1562. ep0_mps = EP0_MPS_LIMIT;
  1563. ep_mps = 64;
  1564. break;
  1565. case S3C_DSTS_EnumSpd_HS:
  1566. dev_info(hsotg->dev, "new device is high-speed\n");
  1567. hsotg->gadget.speed = USB_SPEED_HIGH;
  1568. ep0_mps = EP0_MPS_LIMIT;
  1569. ep_mps = 512;
  1570. break;
  1571. case S3C_DSTS_EnumSpd_LS:
  1572. hsotg->gadget.speed = USB_SPEED_LOW;
  1573. dev_info(hsotg->dev, "new device is low-speed\n");
  1574. /* note, we don't actually support LS in this driver at the
  1575. * moment, and the documentation seems to imply that it isn't
  1576. * supported by the PHYs on some of the devices.
  1577. */
  1578. break;
  1579. }
  1580. /* we should now know the maximum packet size for an
  1581. * endpoint, so set the endpoints to a default value. */
  1582. if (ep0_mps) {
  1583. int i;
  1584. s3c_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps);
  1585. for (i = 1; i < S3C_HSOTG_EPS; i++)
  1586. s3c_hsotg_set_ep_maxpacket(hsotg, i, ep_mps);
  1587. }
  1588. /* ensure after enumeration our EP0 is active */
  1589. s3c_hsotg_enqueue_setup(hsotg);
  1590. dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
  1591. readl(hsotg->regs + S3C_DIEPCTL0),
  1592. readl(hsotg->regs + S3C_DOEPCTL0));
  1593. }
  1594. /**
  1595. * kill_all_requests - remove all requests from the endpoint's queue
  1596. * @hsotg: The device state.
  1597. * @ep: The endpoint the requests may be on.
  1598. * @result: The result code to use.
  1599. * @force: Force removal of any current requests
  1600. *
  1601. * Go through the requests on the given endpoint and mark them
  1602. * completed with the given result code.
  1603. */
  1604. static void kill_all_requests(struct s3c_hsotg *hsotg,
  1605. struct s3c_hsotg_ep *ep,
  1606. int result, bool force)
  1607. {
  1608. struct s3c_hsotg_req *req, *treq;
  1609. unsigned long flags;
  1610. spin_lock_irqsave(&ep->lock, flags);
  1611. list_for_each_entry_safe(req, treq, &ep->queue, queue) {
  1612. /* currently, we can't do much about an already
  1613. * running request on an in endpoint */
  1614. if (ep->req == req && ep->dir_in && !force)
  1615. continue;
  1616. s3c_hsotg_complete_request(hsotg, ep, req,
  1617. result);
  1618. }
  1619. spin_unlock_irqrestore(&ep->lock, flags);
  1620. }
  1621. #define call_gadget(_hs, _entry) \
  1622. if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
  1623. (_hs)->driver && (_hs)->driver->_entry) \
  1624. (_hs)->driver->_entry(&(_hs)->gadget);
  1625. /**
  1626. * s3c_hsotg_disconnect_irq - disconnect irq service
  1627. * @hsotg: The device state.
  1628. *
  1629. * A disconnect IRQ has been received, meaning that the host has
  1630. * lost contact with the bus. Remove all current transactions
  1631. * and signal the gadget driver that this has happened.
  1632. */
  1633. static void s3c_hsotg_disconnect_irq(struct s3c_hsotg *hsotg)
  1634. {
  1635. unsigned ep;
  1636. for (ep = 0; ep < S3C_HSOTG_EPS; ep++)
  1637. kill_all_requests(hsotg, &hsotg->eps[ep], -ESHUTDOWN, true);
  1638. call_gadget(hsotg, disconnect);
  1639. }
  1640. /**
  1641. * s3c_hsotg_irq_fifoempty - TX FIFO empty interrupt handler
  1642. * @hsotg: The device state:
  1643. * @periodic: True if this is a periodic FIFO interrupt
  1644. */
  1645. static void s3c_hsotg_irq_fifoempty(struct s3c_hsotg *hsotg, bool periodic)
  1646. {
  1647. struct s3c_hsotg_ep *ep;
  1648. int epno, ret;
  1649. /* look through for any more data to transmit */
  1650. for (epno = 0; epno < S3C_HSOTG_EPS; epno++) {
  1651. ep = &hsotg->eps[epno];
  1652. if (!ep->dir_in)
  1653. continue;
  1654. if ((periodic && !ep->periodic) ||
  1655. (!periodic && ep->periodic))
  1656. continue;
  1657. ret = s3c_hsotg_trytx(hsotg, ep);
  1658. if (ret < 0)
  1659. break;
  1660. }
  1661. }
  1662. static struct s3c_hsotg *our_hsotg;
  1663. /* IRQ flags which will trigger a retry around the IRQ loop */
  1664. #define IRQ_RETRY_MASK (S3C_GINTSTS_NPTxFEmp | \
  1665. S3C_GINTSTS_PTxFEmp | \
  1666. S3C_GINTSTS_RxFLvl)
  1667. /**
  1668. * s3c_hsotg_irq - handle device interrupt
  1669. * @irq: The IRQ number triggered
  1670. * @pw: The pw value when registered the handler.
  1671. */
  1672. static irqreturn_t s3c_hsotg_irq(int irq, void *pw)
  1673. {
  1674. struct s3c_hsotg *hsotg = pw;
  1675. int retry_count = 8;
  1676. u32 gintsts;
  1677. u32 gintmsk;
  1678. irq_retry:
  1679. gintsts = readl(hsotg->regs + S3C_GINTSTS);
  1680. gintmsk = readl(hsotg->regs + S3C_GINTMSK);
  1681. dev_dbg(hsotg->dev, "%s: %08x %08x (%08x) retry %d\n",
  1682. __func__, gintsts, gintsts & gintmsk, gintmsk, retry_count);
  1683. gintsts &= gintmsk;
  1684. if (gintsts & S3C_GINTSTS_OTGInt) {
  1685. u32 otgint = readl(hsotg->regs + S3C_GOTGINT);
  1686. dev_info(hsotg->dev, "OTGInt: %08x\n", otgint);
  1687. writel(otgint, hsotg->regs + S3C_GOTGINT);
  1688. writel(S3C_GINTSTS_OTGInt, hsotg->regs + S3C_GINTSTS);
  1689. }
  1690. if (gintsts & S3C_GINTSTS_DisconnInt) {
  1691. dev_dbg(hsotg->dev, "%s: DisconnInt\n", __func__);
  1692. writel(S3C_GINTSTS_DisconnInt, hsotg->regs + S3C_GINTSTS);
  1693. s3c_hsotg_disconnect_irq(hsotg);
  1694. }
  1695. if (gintsts & S3C_GINTSTS_SessReqInt) {
  1696. dev_dbg(hsotg->dev, "%s: SessReqInt\n", __func__);
  1697. writel(S3C_GINTSTS_SessReqInt, hsotg->regs + S3C_GINTSTS);
  1698. }
  1699. if (gintsts & S3C_GINTSTS_EnumDone) {
  1700. s3c_hsotg_irq_enumdone(hsotg);
  1701. writel(S3C_GINTSTS_EnumDone, hsotg->regs + S3C_GINTSTS);
  1702. }
  1703. if (gintsts & S3C_GINTSTS_ConIDStsChng) {
  1704. dev_dbg(hsotg->dev, "ConIDStsChg (DSTS=0x%08x, GOTCTL=%08x)\n",
  1705. readl(hsotg->regs + S3C_DSTS),
  1706. readl(hsotg->regs + S3C_GOTGCTL));
  1707. writel(S3C_GINTSTS_ConIDStsChng, hsotg->regs + S3C_GINTSTS);
  1708. }
  1709. if (gintsts & (S3C_GINTSTS_OEPInt | S3C_GINTSTS_IEPInt)) {
  1710. u32 daint = readl(hsotg->regs + S3C_DAINT);
  1711. u32 daint_out = daint >> S3C_DAINT_OutEP_SHIFT;
  1712. u32 daint_in = daint & ~(daint_out << S3C_DAINT_OutEP_SHIFT);
  1713. int ep;
  1714. dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint);
  1715. for (ep = 0; ep < 15 && daint_out; ep++, daint_out >>= 1) {
  1716. if (daint_out & 1)
  1717. s3c_hsotg_epint(hsotg, ep, 0);
  1718. }
  1719. for (ep = 0; ep < 15 && daint_in; ep++, daint_in >>= 1) {
  1720. if (daint_in & 1)
  1721. s3c_hsotg_epint(hsotg, ep, 1);
  1722. }
  1723. writel(daint, hsotg->regs + S3C_DAINT);
  1724. writel(gintsts & (S3C_GINTSTS_OEPInt | S3C_GINTSTS_IEPInt),
  1725. hsotg->regs + S3C_GINTSTS);
  1726. }
  1727. if (gintsts & S3C_GINTSTS_USBRst) {
  1728. dev_info(hsotg->dev, "%s: USBRst\n", __func__);
  1729. dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n",
  1730. readl(hsotg->regs + S3C_GNPTXSTS));
  1731. kill_all_requests(hsotg, &hsotg->eps[0], -ECONNRESET, true);
  1732. /* it seems after a reset we can end up with a situation
  1733. * where the TXFIFO still has data in it... the docs
  1734. * suggest resetting all the fifos, so use the init_fifo
  1735. * code to relayout and flush the fifos.
  1736. */
  1737. s3c_hsotg_init_fifo(hsotg);
  1738. s3c_hsotg_enqueue_setup(hsotg);
  1739. writel(S3C_GINTSTS_USBRst, hsotg->regs + S3C_GINTSTS);
  1740. }
  1741. /* check both FIFOs */
  1742. if (gintsts & S3C_GINTSTS_NPTxFEmp) {
  1743. dev_dbg(hsotg->dev, "NPTxFEmp\n");
  1744. /* Disable the interrupt to stop it happening again
  1745. * unless one of these endpoint routines decides that
  1746. * it needs re-enabling */
  1747. s3c_hsotg_disable_gsint(hsotg, S3C_GINTSTS_NPTxFEmp);
  1748. s3c_hsotg_irq_fifoempty(hsotg, false);
  1749. writel(S3C_GINTSTS_NPTxFEmp, hsotg->regs + S3C_GINTSTS);
  1750. }
  1751. if (gintsts & S3C_GINTSTS_PTxFEmp) {
  1752. dev_dbg(hsotg->dev, "PTxFEmp\n");
  1753. /* See note in S3C_GINTSTS_NPTxFEmp */
  1754. s3c_hsotg_disable_gsint(hsotg, S3C_GINTSTS_PTxFEmp);
  1755. s3c_hsotg_irq_fifoempty(hsotg, true);
  1756. writel(S3C_GINTSTS_PTxFEmp, hsotg->regs + S3C_GINTSTS);
  1757. }
  1758. if (gintsts & S3C_GINTSTS_RxFLvl) {
  1759. /* note, since GINTSTS_RxFLvl doubles as FIFO-not-empty,
  1760. * we need to retry s3c_hsotg_handle_rx if this is still
  1761. * set. */
  1762. s3c_hsotg_handle_rx(hsotg);
  1763. writel(S3C_GINTSTS_RxFLvl, hsotg->regs + S3C_GINTSTS);
  1764. }
  1765. if (gintsts & S3C_GINTSTS_ModeMis) {
  1766. dev_warn(hsotg->dev, "warning, mode mismatch triggered\n");
  1767. writel(S3C_GINTSTS_ModeMis, hsotg->regs + S3C_GINTSTS);
  1768. }
  1769. if (gintsts & S3C_GINTSTS_USBSusp) {
  1770. dev_info(hsotg->dev, "S3C_GINTSTS_USBSusp\n");
  1771. writel(S3C_GINTSTS_USBSusp, hsotg->regs + S3C_GINTSTS);
  1772. call_gadget(hsotg, suspend);
  1773. }
  1774. if (gintsts & S3C_GINTSTS_WkUpInt) {
  1775. dev_info(hsotg->dev, "S3C_GINTSTS_WkUpIn\n");
  1776. writel(S3C_GINTSTS_WkUpInt, hsotg->regs + S3C_GINTSTS);
  1777. call_gadget(hsotg, resume);
  1778. }
  1779. if (gintsts & S3C_GINTSTS_ErlySusp) {
  1780. dev_dbg(hsotg->dev, "S3C_GINTSTS_ErlySusp\n");
  1781. writel(S3C_GINTSTS_ErlySusp, hsotg->regs + S3C_GINTSTS);
  1782. }
  1783. /* these next two seem to crop-up occasionally causing the core
  1784. * to shutdown the USB transfer, so try clearing them and logging
  1785. * the occurence. */
  1786. if (gintsts & S3C_GINTSTS_GOUTNakEff) {
  1787. dev_info(hsotg->dev, "GOUTNakEff triggered\n");
  1788. s3c_hsotg_dump(hsotg);
  1789. writel(S3C_DCTL_CGOUTNak, hsotg->regs + S3C_DCTL);
  1790. writel(S3C_GINTSTS_GOUTNakEff, hsotg->regs + S3C_GINTSTS);
  1791. }
  1792. if (gintsts & S3C_GINTSTS_GINNakEff) {
  1793. dev_info(hsotg->dev, "GINNakEff triggered\n");
  1794. s3c_hsotg_dump(hsotg);
  1795. writel(S3C_DCTL_CGNPInNAK, hsotg->regs + S3C_DCTL);
  1796. writel(S3C_GINTSTS_GINNakEff, hsotg->regs + S3C_GINTSTS);
  1797. }
  1798. /* if we've had fifo events, we should try and go around the
  1799. * loop again to see if there's any point in returning yet. */
  1800. if (gintsts & IRQ_RETRY_MASK && --retry_count > 0)
  1801. goto irq_retry;
  1802. return IRQ_HANDLED;
  1803. }
  1804. /**
  1805. * s3c_hsotg_ep_enable - enable the given endpoint
  1806. * @ep: The USB endpint to configure
  1807. * @desc: The USB endpoint descriptor to configure with.
  1808. *
  1809. * This is called from the USB gadget code's usb_ep_enable().
  1810. */
  1811. static int s3c_hsotg_ep_enable(struct usb_ep *ep,
  1812. const struct usb_endpoint_descriptor *desc)
  1813. {
  1814. struct s3c_hsotg_ep *hs_ep = our_ep(ep);
  1815. struct s3c_hsotg *hsotg = hs_ep->parent;
  1816. unsigned long flags;
  1817. int index = hs_ep->index;
  1818. u32 epctrl_reg;
  1819. u32 epctrl;
  1820. u32 mps;
  1821. int dir_in;
  1822. int ret = 0;
  1823. dev_dbg(hsotg->dev,
  1824. "%s: ep %s: a 0x%02x, attr 0x%02x, mps 0x%04x, intr %d\n",
  1825. __func__, ep->name, desc->bEndpointAddress, desc->bmAttributes,
  1826. desc->wMaxPacketSize, desc->bInterval);
  1827. /* not to be called for EP0 */
  1828. WARN_ON(index == 0);
  1829. dir_in = (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? 1 : 0;
  1830. if (dir_in != hs_ep->dir_in) {
  1831. dev_err(hsotg->dev, "%s: direction mismatch!\n", __func__);
  1832. return -EINVAL;
  1833. }
  1834. mps = le16_to_cpu(desc->wMaxPacketSize);
  1835. /* note, we handle this here instead of s3c_hsotg_set_ep_maxpacket */
  1836. epctrl_reg = dir_in ? S3C_DIEPCTL(index) : S3C_DOEPCTL(index);
  1837. epctrl = readl(hsotg->regs + epctrl_reg);
  1838. dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n",
  1839. __func__, epctrl, epctrl_reg);
  1840. spin_lock_irqsave(&hs_ep->lock, flags);
  1841. epctrl &= ~(S3C_DxEPCTL_EPType_MASK | S3C_DxEPCTL_MPS_MASK);
  1842. epctrl |= S3C_DxEPCTL_MPS(mps);
  1843. /* mark the endpoint as active, otherwise the core may ignore
  1844. * transactions entirely for this endpoint */
  1845. epctrl |= S3C_DxEPCTL_USBActEp;
  1846. /* set the NAK status on the endpoint, otherwise we might try and
  1847. * do something with data that we've yet got a request to process
  1848. * since the RXFIFO will take data for an endpoint even if the
  1849. * size register hasn't been set.
  1850. */
  1851. epctrl |= S3C_DxEPCTL_SNAK;
  1852. /* update the endpoint state */
  1853. hs_ep->ep.maxpacket = mps;
  1854. /* default, set to non-periodic */
  1855. hs_ep->periodic = 0;
  1856. switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
  1857. case USB_ENDPOINT_XFER_ISOC:
  1858. dev_err(hsotg->dev, "no current ISOC support\n");
  1859. ret = -EINVAL;
  1860. goto out;
  1861. case USB_ENDPOINT_XFER_BULK:
  1862. epctrl |= S3C_DxEPCTL_EPType_Bulk;
  1863. break;
  1864. case USB_ENDPOINT_XFER_INT:
  1865. if (dir_in) {
  1866. /* Allocate our TxFNum by simply using the index
  1867. * of the endpoint for the moment. We could do
  1868. * something better if the host indicates how
  1869. * many FIFOs we are expecting to use. */
  1870. hs_ep->periodic = 1;
  1871. epctrl |= S3C_DxEPCTL_TxFNum(index);
  1872. }
  1873. epctrl |= S3C_DxEPCTL_EPType_Intterupt;
  1874. break;
  1875. case USB_ENDPOINT_XFER_CONTROL:
  1876. epctrl |= S3C_DxEPCTL_EPType_Control;
  1877. break;
  1878. }
  1879. /* if the hardware has dedicated fifos, we must give each IN EP
  1880. * a unique tx-fifo even if it is non-periodic.
  1881. */
  1882. if (dir_in && hsotg->dedicated_fifos)
  1883. epctrl |= S3C_DxEPCTL_TxFNum(index);
  1884. /* for non control endpoints, set PID to D0 */
  1885. if (index)
  1886. epctrl |= S3C_DxEPCTL_SetD0PID;
  1887. dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n",
  1888. __func__, epctrl);
  1889. writel(epctrl, hsotg->regs + epctrl_reg);
  1890. dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x\n",
  1891. __func__, readl(hsotg->regs + epctrl_reg));
  1892. /* enable the endpoint interrupt */
  1893. s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1);
  1894. out:
  1895. spin_unlock_irqrestore(&hs_ep->lock, flags);
  1896. return ret;
  1897. }
  1898. static int s3c_hsotg_ep_disable(struct usb_ep *ep)
  1899. {
  1900. struct s3c_hsotg_ep *hs_ep = our_ep(ep);
  1901. struct s3c_hsotg *hsotg = hs_ep->parent;
  1902. int dir_in = hs_ep->dir_in;
  1903. int index = hs_ep->index;
  1904. unsigned long flags;
  1905. u32 epctrl_reg;
  1906. u32 ctrl;
  1907. dev_info(hsotg->dev, "%s(ep %p)\n", __func__, ep);
  1908. if (ep == &hsotg->eps[0].ep) {
  1909. dev_err(hsotg->dev, "%s: called for ep0\n", __func__);
  1910. return -EINVAL;
  1911. }
  1912. epctrl_reg = dir_in ? S3C_DIEPCTL(index) : S3C_DOEPCTL(index);
  1913. /* terminate all requests with shutdown */
  1914. kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false);
  1915. spin_lock_irqsave(&hs_ep->lock, flags);
  1916. ctrl = readl(hsotg->regs + epctrl_reg);
  1917. ctrl &= ~S3C_DxEPCTL_EPEna;
  1918. ctrl &= ~S3C_DxEPCTL_USBActEp;
  1919. ctrl |= S3C_DxEPCTL_SNAK;
  1920. dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl);
  1921. writel(ctrl, hsotg->regs + epctrl_reg);
  1922. /* disable endpoint interrupts */
  1923. s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 0);
  1924. spin_unlock_irqrestore(&hs_ep->lock, flags);
  1925. return 0;
  1926. }
  1927. /**
  1928. * on_list - check request is on the given endpoint
  1929. * @ep: The endpoint to check.
  1930. * @test: The request to test if it is on the endpoint.
  1931. */
  1932. static bool on_list(struct s3c_hsotg_ep *ep, struct s3c_hsotg_req *test)
  1933. {
  1934. struct s3c_hsotg_req *req, *treq;
  1935. list_for_each_entry_safe(req, treq, &ep->queue, queue) {
  1936. if (req == test)
  1937. return true;
  1938. }
  1939. return false;
  1940. }
  1941. static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req)
  1942. {
  1943. struct s3c_hsotg_req *hs_req = our_req(req);
  1944. struct s3c_hsotg_ep *hs_ep = our_ep(ep);
  1945. struct s3c_hsotg *hs = hs_ep->parent;
  1946. unsigned long flags;
  1947. dev_info(hs->dev, "ep_dequeue(%p,%p)\n", ep, req);
  1948. if (hs_req == hs_ep->req) {
  1949. dev_dbg(hs->dev, "%s: already in progress\n", __func__);
  1950. return -EINPROGRESS;
  1951. }
  1952. spin_lock_irqsave(&hs_ep->lock, flags);
  1953. if (!on_list(hs_ep, hs_req)) {
  1954. spin_unlock_irqrestore(&hs_ep->lock, flags);
  1955. return -EINVAL;
  1956. }
  1957. s3c_hsotg_complete_request(hs, hs_ep, hs_req, -ECONNRESET);
  1958. spin_unlock_irqrestore(&hs_ep->lock, flags);
  1959. return 0;
  1960. }
  1961. static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value)
  1962. {
  1963. struct s3c_hsotg_ep *hs_ep = our_ep(ep);
  1964. struct s3c_hsotg *hs = hs_ep->parent;
  1965. int index = hs_ep->index;
  1966. unsigned long irqflags;
  1967. u32 epreg;
  1968. u32 epctl;
  1969. dev_info(hs->dev, "%s(ep %p %s, %d)\n", __func__, ep, ep->name, value);
  1970. spin_lock_irqsave(&hs_ep->lock, irqflags);
  1971. /* write both IN and OUT control registers */
  1972. epreg = S3C_DIEPCTL(index);
  1973. epctl = readl(hs->regs + epreg);
  1974. if (value)
  1975. epctl |= S3C_DxEPCTL_Stall;
  1976. else
  1977. epctl &= ~S3C_DxEPCTL_Stall;
  1978. writel(epctl, hs->regs + epreg);
  1979. epreg = S3C_DOEPCTL(index);
  1980. epctl = readl(hs->regs + epreg);
  1981. if (value)
  1982. epctl |= S3C_DxEPCTL_Stall;
  1983. else
  1984. epctl &= ~S3C_DxEPCTL_Stall;
  1985. writel(epctl, hs->regs + epreg);
  1986. spin_unlock_irqrestore(&hs_ep->lock, irqflags);
  1987. return 0;
  1988. }
  1989. static struct usb_ep_ops s3c_hsotg_ep_ops = {
  1990. .enable = s3c_hsotg_ep_enable,
  1991. .disable = s3c_hsotg_ep_disable,
  1992. .alloc_request = s3c_hsotg_ep_alloc_request,
  1993. .free_request = s3c_hsotg_ep_free_request,
  1994. .queue = s3c_hsotg_ep_queue,
  1995. .dequeue = s3c_hsotg_ep_dequeue,
  1996. .set_halt = s3c_hsotg_ep_sethalt,
  1997. /* note, don't belive we have any call for the fifo routines */
  1998. };
  1999. /**
  2000. * s3c_hsotg_corereset - issue softreset to the core
  2001. * @hsotg: The device state
  2002. *
  2003. * Issue a soft reset to the core, and await the core finishing it.
  2004. */
  2005. static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
  2006. {
  2007. int timeout;
  2008. u32 grstctl;
  2009. dev_dbg(hsotg->dev, "resetting core\n");
  2010. /* issue soft reset */
  2011. writel(S3C_GRSTCTL_CSftRst, hsotg->regs + S3C_GRSTCTL);
  2012. timeout = 1000;
  2013. do {
  2014. grstctl = readl(hsotg->regs + S3C_GRSTCTL);
  2015. } while (!(grstctl & S3C_GRSTCTL_CSftRst) && timeout-- > 0);
  2016. if (!(grstctl & S3C_GRSTCTL_CSftRst)) {
  2017. dev_err(hsotg->dev, "Failed to get CSftRst asserted\n");
  2018. return -EINVAL;
  2019. }
  2020. timeout = 1000;
  2021. while (1) {
  2022. u32 grstctl = readl(hsotg->regs + S3C_GRSTCTL);
  2023. if (timeout-- < 0) {
  2024. dev_info(hsotg->dev,
  2025. "%s: reset failed, GRSTCTL=%08x\n",
  2026. __func__, grstctl);
  2027. return -ETIMEDOUT;
  2028. }
  2029. if (grstctl & S3C_GRSTCTL_CSftRst)
  2030. continue;
  2031. if (!(grstctl & S3C_GRSTCTL_AHBIdle))
  2032. continue;
  2033. break; /* reset done */
  2034. }
  2035. dev_dbg(hsotg->dev, "reset successful\n");
  2036. return 0;
  2037. }
  2038. int usb_gadget_register_driver(struct usb_gadget_driver *driver)
  2039. {
  2040. struct s3c_hsotg *hsotg = our_hsotg;
  2041. int ret;
  2042. if (!hsotg) {
  2043. printk(KERN_ERR "%s: called with no device\n", __func__);
  2044. return -ENODEV;
  2045. }
  2046. if (!driver) {
  2047. dev_err(hsotg->dev, "%s: no driver\n", __func__);
  2048. return -EINVAL;
  2049. }
  2050. if (driver->speed != USB_SPEED_HIGH &&
  2051. driver->speed != USB_SPEED_FULL) {
  2052. dev_err(hsotg->dev, "%s: bad speed\n", __func__);
  2053. }
  2054. if (!driver->bind || !driver->setup) {
  2055. dev_err(hsotg->dev, "%s: missing entry points\n", __func__);
  2056. return -EINVAL;
  2057. }
  2058. WARN_ON(hsotg->driver);
  2059. driver->driver.bus = NULL;
  2060. hsotg->driver = driver;
  2061. hsotg->gadget.dev.driver = &driver->driver;
  2062. hsotg->gadget.dev.dma_mask = hsotg->dev->dma_mask;
  2063. hsotg->gadget.speed = USB_SPEED_UNKNOWN;
  2064. ret = device_add(&hsotg->gadget.dev);
  2065. if (ret) {
  2066. dev_err(hsotg->dev, "failed to register gadget device\n");
  2067. goto err;
  2068. }
  2069. ret = driver->bind(&hsotg->gadget);
  2070. if (ret) {
  2071. dev_err(hsotg->dev, "failed bind %s\n", driver->driver.name);
  2072. hsotg->gadget.dev.driver = NULL;
  2073. hsotg->driver = NULL;
  2074. goto err;
  2075. }
  2076. /* we must now enable ep0 ready for host detection and then
  2077. * set configuration. */
  2078. s3c_hsotg_corereset(hsotg);
  2079. /* set the PLL on, remove the HNP/SRP and set the PHY */
  2080. writel(S3C_GUSBCFG_PHYIf16 | S3C_GUSBCFG_TOutCal(7) |
  2081. (0x5 << 10), hsotg->regs + S3C_GUSBCFG);
  2082. /* looks like soft-reset changes state of FIFOs */
  2083. s3c_hsotg_init_fifo(hsotg);
  2084. __orr32(hsotg->regs + S3C_DCTL, S3C_DCTL_SftDiscon);
  2085. writel(1 << 18 | S3C_DCFG_DevSpd_HS, hsotg->regs + S3C_DCFG);
  2086. writel(S3C_GINTSTS_DisconnInt | S3C_GINTSTS_SessReqInt |
  2087. S3C_GINTSTS_ConIDStsChng | S3C_GINTSTS_USBRst |
  2088. S3C_GINTSTS_EnumDone | S3C_GINTSTS_OTGInt |
  2089. S3C_GINTSTS_USBSusp | S3C_GINTSTS_WkUpInt |
  2090. S3C_GINTSTS_GOUTNakEff | S3C_GINTSTS_GINNakEff |
  2091. S3C_GINTSTS_ErlySusp,
  2092. hsotg->regs + S3C_GINTMSK);
  2093. if (using_dma(hsotg))
  2094. writel(S3C_GAHBCFG_GlblIntrEn | S3C_GAHBCFG_DMAEn |
  2095. S3C_GAHBCFG_HBstLen_Incr4,
  2096. hsotg->regs + S3C_GAHBCFG);
  2097. else
  2098. writel(S3C_GAHBCFG_GlblIntrEn, hsotg->regs + S3C_GAHBCFG);
  2099. /* Enabling INTknTXFEmpMsk here seems to be a big mistake, we end
  2100. * up being flooded with interrupts if the host is polling the
  2101. * endpoint to try and read data. */
  2102. writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk |
  2103. S3C_DIEPMSK_INTknEPMisMsk |
  2104. S3C_DIEPMSK_EPDisbldMsk | S3C_DIEPMSK_XferComplMsk |
  2105. ((hsotg->dedicated_fifos) ? S3C_DIEPMSK_TxFIFOEmpty : 0),
  2106. hsotg->regs + S3C_DIEPMSK);
  2107. /* don't need XferCompl, we get that from RXFIFO in slave mode. In
  2108. * DMA mode we may need this. */
  2109. writel(S3C_DOEPMSK_SetupMsk | S3C_DOEPMSK_AHBErrMsk |
  2110. S3C_DOEPMSK_EPDisbldMsk |
  2111. (using_dma(hsotg) ? (S3C_DIEPMSK_XferComplMsk |
  2112. S3C_DIEPMSK_TimeOUTMsk) : 0),
  2113. hsotg->regs + S3C_DOEPMSK);
  2114. writel(0, hsotg->regs + S3C_DAINTMSK);
  2115. dev_info(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
  2116. readl(hsotg->regs + S3C_DIEPCTL0),
  2117. readl(hsotg->regs + S3C_DOEPCTL0));
  2118. /* enable in and out endpoint interrupts */
  2119. s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_OEPInt | S3C_GINTSTS_IEPInt);
  2120. /* Enable the RXFIFO when in slave mode, as this is how we collect
  2121. * the data. In DMA mode, we get events from the FIFO but also
  2122. * things we cannot process, so do not use it. */
  2123. if (!using_dma(hsotg))
  2124. s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_RxFLvl);
  2125. /* Enable interrupts for EP0 in and out */
  2126. s3c_hsotg_ctrl_epint(hsotg, 0, 0, 1);
  2127. s3c_hsotg_ctrl_epint(hsotg, 0, 1, 1);
  2128. __orr32(hsotg->regs + S3C_DCTL, S3C_DCTL_PWROnPrgDone);
  2129. udelay(10); /* see openiboot */
  2130. __bic32(hsotg->regs + S3C_DCTL, S3C_DCTL_PWROnPrgDone);
  2131. dev_info(hsotg->dev, "DCTL=0x%08x\n", readl(hsotg->regs + S3C_DCTL));
  2132. /* S3C_DxEPCTL_USBActEp says RO in manual, but seems to be set by
  2133. writing to the EPCTL register.. */
  2134. /* set to read 1 8byte packet */
  2135. writel(S3C_DxEPTSIZ_MC(1) | S3C_DxEPTSIZ_PktCnt(1) |
  2136. S3C_DxEPTSIZ_XferSize(8), hsotg->regs + DOEPTSIZ0);
  2137. writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) |
  2138. S3C_DxEPCTL_CNAK | S3C_DxEPCTL_EPEna |
  2139. S3C_DxEPCTL_USBActEp,
  2140. hsotg->regs + S3C_DOEPCTL0);
  2141. /* enable, but don't activate EP0in */
  2142. writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) |
  2143. S3C_DxEPCTL_USBActEp, hsotg->regs + S3C_DIEPCTL0);
  2144. s3c_hsotg_enqueue_setup(hsotg);
  2145. dev_info(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
  2146. readl(hsotg->regs + S3C_DIEPCTL0),
  2147. readl(hsotg->regs + S3C_DOEPCTL0));
  2148. /* clear global NAKs */
  2149. writel(S3C_DCTL_CGOUTNak | S3C_DCTL_CGNPInNAK,
  2150. hsotg->regs + S3C_DCTL);
  2151. /* must be at-least 3ms to allow bus to see disconnect */
  2152. msleep(3);
  2153. /* remove the soft-disconnect and let's go */
  2154. __bic32(hsotg->regs + S3C_DCTL, S3C_DCTL_SftDiscon);
  2155. /* report to the user, and return */
  2156. dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name);
  2157. return 0;
  2158. err:
  2159. hsotg->driver = NULL;
  2160. hsotg->gadget.dev.driver = NULL;
  2161. return ret;
  2162. }
  2163. EXPORT_SYMBOL(usb_gadget_register_driver);
  2164. int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  2165. {
  2166. struct s3c_hsotg *hsotg = our_hsotg;
  2167. int ep;
  2168. if (!hsotg)
  2169. return -ENODEV;
  2170. if (!driver || driver != hsotg->driver || !driver->unbind)
  2171. return -EINVAL;
  2172. /* all endpoints should be shutdown */
  2173. for (ep = 0; ep < S3C_HSOTG_EPS; ep++)
  2174. s3c_hsotg_ep_disable(&hsotg->eps[ep].ep);
  2175. call_gadget(hsotg, disconnect);
  2176. driver->unbind(&hsotg->gadget);
  2177. hsotg->driver = NULL;
  2178. hsotg->gadget.speed = USB_SPEED_UNKNOWN;
  2179. device_del(&hsotg->gadget.dev);
  2180. dev_info(hsotg->dev, "unregistered gadget driver '%s'\n",
  2181. driver->driver.name);
  2182. return 0;
  2183. }
  2184. EXPORT_SYMBOL(usb_gadget_unregister_driver);
  2185. static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget)
  2186. {
  2187. return s3c_hsotg_read_frameno(to_hsotg(gadget));
  2188. }
  2189. static struct usb_gadget_ops s3c_hsotg_gadget_ops = {
  2190. .get_frame = s3c_hsotg_gadget_getframe,
  2191. };
  2192. /**
  2193. * s3c_hsotg_initep - initialise a single endpoint
  2194. * @hsotg: The device state.
  2195. * @hs_ep: The endpoint to be initialised.
  2196. * @epnum: The endpoint number
  2197. *
  2198. * Initialise the given endpoint (as part of the probe and device state
  2199. * creation) to give to the gadget driver. Setup the endpoint name, any
  2200. * direction information and other state that may be required.
  2201. */
  2202. static void __devinit s3c_hsotg_initep(struct s3c_hsotg *hsotg,
  2203. struct s3c_hsotg_ep *hs_ep,
  2204. int epnum)
  2205. {
  2206. u32 ptxfifo;
  2207. char *dir;
  2208. if (epnum == 0)
  2209. dir = "";
  2210. else if ((epnum % 2) == 0) {
  2211. dir = "out";
  2212. } else {
  2213. dir = "in";
  2214. hs_ep->dir_in = 1;
  2215. }
  2216. hs_ep->index = epnum;
  2217. snprintf(hs_ep->name, sizeof(hs_ep->name), "ep%d%s", epnum, dir);
  2218. INIT_LIST_HEAD(&hs_ep->queue);
  2219. INIT_LIST_HEAD(&hs_ep->ep.ep_list);
  2220. spin_lock_init(&hs_ep->lock);
  2221. /* add to the list of endpoints known by the gadget driver */
  2222. if (epnum)
  2223. list_add_tail(&hs_ep->ep.ep_list, &hsotg->gadget.ep_list);
  2224. hs_ep->parent = hsotg;
  2225. hs_ep->ep.name = hs_ep->name;
  2226. hs_ep->ep.maxpacket = epnum ? 512 : EP0_MPS_LIMIT;
  2227. hs_ep->ep.ops = &s3c_hsotg_ep_ops;
  2228. /* Read the FIFO size for the Periodic TX FIFO, even if we're
  2229. * an OUT endpoint, we may as well do this if in future the
  2230. * code is changed to make each endpoint's direction changeable.
  2231. */
  2232. ptxfifo = readl(hsotg->regs + S3C_DPTXFSIZn(epnum));
  2233. hs_ep->fifo_size = S3C_DPTXFSIZn_DPTxFSize_GET(ptxfifo) * 4;
  2234. /* if we're using dma, we need to set the next-endpoint pointer
  2235. * to be something valid.
  2236. */
  2237. if (using_dma(hsotg)) {
  2238. u32 next = S3C_DxEPCTL_NextEp((epnum + 1) % 15);
  2239. writel(next, hsotg->regs + S3C_DIEPCTL(epnum));
  2240. writel(next, hsotg->regs + S3C_DOEPCTL(epnum));
  2241. }
  2242. }
  2243. /**
  2244. * s3c_hsotg_otgreset - reset the OtG phy block
  2245. * @hsotg: The host state.
  2246. *
  2247. * Power up the phy, set the basic configuration and start the PHY.
  2248. */
  2249. static void s3c_hsotg_otgreset(struct s3c_hsotg *hsotg)
  2250. {
  2251. struct clk *xusbxti;
  2252. u32 pwr, osc;
  2253. pwr = readl(S3C_PHYPWR);
  2254. pwr &= ~0x19;
  2255. writel(pwr, S3C_PHYPWR);
  2256. mdelay(1);
  2257. osc = hsotg->plat->is_osc ? S3C_PHYCLK_EXT_OSC : 0;
  2258. xusbxti = clk_get(hsotg->dev, "xusbxti");
  2259. if (xusbxti && !IS_ERR(xusbxti)) {
  2260. switch (clk_get_rate(xusbxti)) {
  2261. case 12*MHZ:
  2262. osc |= S3C_PHYCLK_CLKSEL_12M;
  2263. break;
  2264. case 24*MHZ:
  2265. osc |= S3C_PHYCLK_CLKSEL_24M;
  2266. break;
  2267. default:
  2268. case 48*MHZ:
  2269. /* default reference clock */
  2270. break;
  2271. }
  2272. clk_put(xusbxti);
  2273. }
  2274. writel(osc | 0x10, S3C_PHYCLK);
  2275. /* issue a full set of resets to the otg and core */
  2276. writel(S3C_RSTCON_PHY, S3C_RSTCON);
  2277. udelay(20); /* at-least 10uS */
  2278. writel(0, S3C_RSTCON);
  2279. }
  2280. static void s3c_hsotg_init(struct s3c_hsotg *hsotg)
  2281. {
  2282. u32 cfg4;
  2283. /* unmask subset of endpoint interrupts */
  2284. writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk |
  2285. S3C_DIEPMSK_EPDisbldMsk | S3C_DIEPMSK_XferComplMsk,
  2286. hsotg->regs + S3C_DIEPMSK);
  2287. writel(S3C_DOEPMSK_SetupMsk | S3C_DOEPMSK_AHBErrMsk |
  2288. S3C_DOEPMSK_EPDisbldMsk | S3C_DOEPMSK_XferComplMsk,
  2289. hsotg->regs + S3C_DOEPMSK);
  2290. writel(0, hsotg->regs + S3C_DAINTMSK);
  2291. /* Be in disconnected state until gadget is registered */
  2292. __orr32(hsotg->regs + S3C_DCTL, S3C_DCTL_SftDiscon);
  2293. if (0) {
  2294. /* post global nak until we're ready */
  2295. writel(S3C_DCTL_SGNPInNAK | S3C_DCTL_SGOUTNak,
  2296. hsotg->regs + S3C_DCTL);
  2297. }
  2298. /* setup fifos */
  2299. dev_info(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n",
  2300. readl(hsotg->regs + S3C_GRXFSIZ),
  2301. readl(hsotg->regs + S3C_GNPTXFSIZ));
  2302. s3c_hsotg_init_fifo(hsotg);
  2303. /* set the PLL on, remove the HNP/SRP and set the PHY */
  2304. writel(S3C_GUSBCFG_PHYIf16 | S3C_GUSBCFG_TOutCal(7) | (0x5 << 10),
  2305. hsotg->regs + S3C_GUSBCFG);
  2306. writel(using_dma(hsotg) ? S3C_GAHBCFG_DMAEn : 0x0,
  2307. hsotg->regs + S3C_GAHBCFG);
  2308. /* check hardware configuration */
  2309. cfg4 = readl(hsotg->regs + 0x50);
  2310. hsotg->dedicated_fifos = (cfg4 >> 25) & 1;
  2311. dev_info(hsotg->dev, "%s fifos\n",
  2312. hsotg->dedicated_fifos ? "dedicated" : "shared");
  2313. }
  2314. static void s3c_hsotg_dump(struct s3c_hsotg *hsotg)
  2315. {
  2316. struct device *dev = hsotg->dev;
  2317. void __iomem *regs = hsotg->regs;
  2318. u32 val;
  2319. int idx;
  2320. dev_info(dev, "DCFG=0x%08x, DCTL=0x%08x, DIEPMSK=%08x\n",
  2321. readl(regs + S3C_DCFG), readl(regs + S3C_DCTL),
  2322. readl(regs + S3C_DIEPMSK));
  2323. dev_info(dev, "GAHBCFG=0x%08x, 0x44=0x%08x\n",
  2324. readl(regs + S3C_GAHBCFG), readl(regs + 0x44));
  2325. dev_info(dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n",
  2326. readl(regs + S3C_GRXFSIZ), readl(regs + S3C_GNPTXFSIZ));
  2327. /* show periodic fifo settings */
  2328. for (idx = 1; idx <= 15; idx++) {
  2329. val = readl(regs + S3C_DPTXFSIZn(idx));
  2330. dev_info(dev, "DPTx[%d] FSize=%d, StAddr=0x%08x\n", idx,
  2331. val >> S3C_DPTXFSIZn_DPTxFSize_SHIFT,
  2332. val & S3C_DPTXFSIZn_DPTxFStAddr_MASK);
  2333. }
  2334. for (idx = 0; idx < 15; idx++) {
  2335. dev_info(dev,
  2336. "ep%d-in: EPCTL=0x%08x, SIZ=0x%08x, DMA=0x%08x\n", idx,
  2337. readl(regs + S3C_DIEPCTL(idx)),
  2338. readl(regs + S3C_DIEPTSIZ(idx)),
  2339. readl(regs + S3C_DIEPDMA(idx)));
  2340. val = readl(regs + S3C_DOEPCTL(idx));
  2341. dev_info(dev,
  2342. "ep%d-out: EPCTL=0x%08x, SIZ=0x%08x, DMA=0x%08x\n",
  2343. idx, readl(regs + S3C_DOEPCTL(idx)),
  2344. readl(regs + S3C_DOEPTSIZ(idx)),
  2345. readl(regs + S3C_DOEPDMA(idx)));
  2346. }
  2347. dev_info(dev, "DVBUSDIS=0x%08x, DVBUSPULSE=%08x\n",
  2348. readl(regs + S3C_DVBUSDIS), readl(regs + S3C_DVBUSPULSE));
  2349. }
  2350. /**
  2351. * state_show - debugfs: show overall driver and device state.
  2352. * @seq: The seq file to write to.
  2353. * @v: Unused parameter.
  2354. *
  2355. * This debugfs entry shows the overall state of the hardware and
  2356. * some general information about each of the endpoints available
  2357. * to the system.
  2358. */
  2359. static int state_show(struct seq_file *seq, void *v)
  2360. {
  2361. struct s3c_hsotg *hsotg = seq->private;
  2362. void __iomem *regs = hsotg->regs;
  2363. int idx;
  2364. seq_printf(seq, "DCFG=0x%08x, DCTL=0x%08x, DSTS=0x%08x\n",
  2365. readl(regs + S3C_DCFG),
  2366. readl(regs + S3C_DCTL),
  2367. readl(regs + S3C_DSTS));
  2368. seq_printf(seq, "DIEPMSK=0x%08x, DOEPMASK=0x%08x\n",
  2369. readl(regs + S3C_DIEPMSK), readl(regs + S3C_DOEPMSK));
  2370. seq_printf(seq, "GINTMSK=0x%08x, GINTSTS=0x%08x\n",
  2371. readl(regs + S3C_GINTMSK),
  2372. readl(regs + S3C_GINTSTS));
  2373. seq_printf(seq, "DAINTMSK=0x%08x, DAINT=0x%08x\n",
  2374. readl(regs + S3C_DAINTMSK),
  2375. readl(regs + S3C_DAINT));
  2376. seq_printf(seq, "GNPTXSTS=0x%08x, GRXSTSR=%08x\n",
  2377. readl(regs + S3C_GNPTXSTS),
  2378. readl(regs + S3C_GRXSTSR));
  2379. seq_printf(seq, "\nEndpoint status:\n");
  2380. for (idx = 0; idx < 15; idx++) {
  2381. u32 in, out;
  2382. in = readl(regs + S3C_DIEPCTL(idx));
  2383. out = readl(regs + S3C_DOEPCTL(idx));
  2384. seq_printf(seq, "ep%d: DIEPCTL=0x%08x, DOEPCTL=0x%08x",
  2385. idx, in, out);
  2386. in = readl(regs + S3C_DIEPTSIZ(idx));
  2387. out = readl(regs + S3C_DOEPTSIZ(idx));
  2388. seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x",
  2389. in, out);
  2390. seq_printf(seq, "\n");
  2391. }
  2392. return 0;
  2393. }
  2394. static int state_open(struct inode *inode, struct file *file)
  2395. {
  2396. return single_open(file, state_show, inode->i_private);
  2397. }
  2398. static const struct file_operations state_fops = {
  2399. .owner = THIS_MODULE,
  2400. .open = state_open,
  2401. .read = seq_read,
  2402. .llseek = seq_lseek,
  2403. .release = single_release,
  2404. };
  2405. /**
  2406. * fifo_show - debugfs: show the fifo information
  2407. * @seq: The seq_file to write data to.
  2408. * @v: Unused parameter.
  2409. *
  2410. * Show the FIFO information for the overall fifo and all the
  2411. * periodic transmission FIFOs.
  2412. */
  2413. static int fifo_show(struct seq_file *seq, void *v)
  2414. {
  2415. struct s3c_hsotg *hsotg = seq->private;
  2416. void __iomem *regs = hsotg->regs;
  2417. u32 val;
  2418. int idx;
  2419. seq_printf(seq, "Non-periodic FIFOs:\n");
  2420. seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + S3C_GRXFSIZ));
  2421. val = readl(regs + S3C_GNPTXFSIZ);
  2422. seq_printf(seq, "NPTXFIFO: Size %d, Start 0x%08x\n",
  2423. val >> S3C_GNPTXFSIZ_NPTxFDep_SHIFT,
  2424. val & S3C_GNPTXFSIZ_NPTxFStAddr_MASK);
  2425. seq_printf(seq, "\nPeriodic TXFIFOs:\n");
  2426. for (idx = 1; idx <= 15; idx++) {
  2427. val = readl(regs + S3C_DPTXFSIZn(idx));
  2428. seq_printf(seq, "\tDPTXFIFO%2d: Size %d, Start 0x%08x\n", idx,
  2429. val >> S3C_DPTXFSIZn_DPTxFSize_SHIFT,
  2430. val & S3C_DPTXFSIZn_DPTxFStAddr_MASK);
  2431. }
  2432. return 0;
  2433. }
  2434. static int fifo_open(struct inode *inode, struct file *file)
  2435. {
  2436. return single_open(file, fifo_show, inode->i_private);
  2437. }
  2438. static const struct file_operations fifo_fops = {
  2439. .owner = THIS_MODULE,
  2440. .open = fifo_open,
  2441. .read = seq_read,
  2442. .llseek = seq_lseek,
  2443. .release = single_release,
  2444. };
  2445. static const char *decode_direction(int is_in)
  2446. {
  2447. return is_in ? "in" : "out";
  2448. }
  2449. /**
  2450. * ep_show - debugfs: show the state of an endpoint.
  2451. * @seq: The seq_file to write data to.
  2452. * @v: Unused parameter.
  2453. *
  2454. * This debugfs entry shows the state of the given endpoint (one is
  2455. * registered for each available).
  2456. */
  2457. static int ep_show(struct seq_file *seq, void *v)
  2458. {
  2459. struct s3c_hsotg_ep *ep = seq->private;
  2460. struct s3c_hsotg *hsotg = ep->parent;
  2461. struct s3c_hsotg_req *req;
  2462. void __iomem *regs = hsotg->regs;
  2463. int index = ep->index;
  2464. int show_limit = 15;
  2465. unsigned long flags;
  2466. seq_printf(seq, "Endpoint index %d, named %s, dir %s:\n",
  2467. ep->index, ep->ep.name, decode_direction(ep->dir_in));
  2468. /* first show the register state */
  2469. seq_printf(seq, "\tDIEPCTL=0x%08x, DOEPCTL=0x%08x\n",
  2470. readl(regs + S3C_DIEPCTL(index)),
  2471. readl(regs + S3C_DOEPCTL(index)));
  2472. seq_printf(seq, "\tDIEPDMA=0x%08x, DOEPDMA=0x%08x\n",
  2473. readl(regs + S3C_DIEPDMA(index)),
  2474. readl(regs + S3C_DOEPDMA(index)));
  2475. seq_printf(seq, "\tDIEPINT=0x%08x, DOEPINT=0x%08x\n",
  2476. readl(regs + S3C_DIEPINT(index)),
  2477. readl(regs + S3C_DOEPINT(index)));
  2478. seq_printf(seq, "\tDIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x\n",
  2479. readl(regs + S3C_DIEPTSIZ(index)),
  2480. readl(regs + S3C_DOEPTSIZ(index)));
  2481. seq_printf(seq, "\n");
  2482. seq_printf(seq, "mps %d\n", ep->ep.maxpacket);
  2483. seq_printf(seq, "total_data=%ld\n", ep->total_data);
  2484. seq_printf(seq, "request list (%p,%p):\n",
  2485. ep->queue.next, ep->queue.prev);
  2486. spin_lock_irqsave(&ep->lock, flags);
  2487. list_for_each_entry(req, &ep->queue, queue) {
  2488. if (--show_limit < 0) {
  2489. seq_printf(seq, "not showing more requests...\n");
  2490. break;
  2491. }
  2492. seq_printf(seq, "%c req %p: %d bytes @%p, ",
  2493. req == ep->req ? '*' : ' ',
  2494. req, req->req.length, req->req.buf);
  2495. seq_printf(seq, "%d done, res %d\n",
  2496. req->req.actual, req->req.status);
  2497. }
  2498. spin_unlock_irqrestore(&ep->lock, flags);
  2499. return 0;
  2500. }
  2501. static int ep_open(struct inode *inode, struct file *file)
  2502. {
  2503. return single_open(file, ep_show, inode->i_private);
  2504. }
  2505. static const struct file_operations ep_fops = {
  2506. .owner = THIS_MODULE,
  2507. .open = ep_open,
  2508. .read = seq_read,
  2509. .llseek = seq_lseek,
  2510. .release = single_release,
  2511. };
  2512. /**
  2513. * s3c_hsotg_create_debug - create debugfs directory and files
  2514. * @hsotg: The driver state
  2515. *
  2516. * Create the debugfs files to allow the user to get information
  2517. * about the state of the system. The directory name is created
  2518. * with the same name as the device itself, in case we end up
  2519. * with multiple blocks in future systems.
  2520. */
  2521. static void __devinit s3c_hsotg_create_debug(struct s3c_hsotg *hsotg)
  2522. {
  2523. struct dentry *root;
  2524. unsigned epidx;
  2525. root = debugfs_create_dir(dev_name(hsotg->dev), NULL);
  2526. hsotg->debug_root = root;
  2527. if (IS_ERR(root)) {
  2528. dev_err(hsotg->dev, "cannot create debug root\n");
  2529. return;
  2530. }
  2531. /* create general state file */
  2532. hsotg->debug_file = debugfs_create_file("state", 0444, root,
  2533. hsotg, &state_fops);
  2534. if (IS_ERR(hsotg->debug_file))
  2535. dev_err(hsotg->dev, "%s: failed to create state\n", __func__);
  2536. hsotg->debug_fifo = debugfs_create_file("fifo", 0444, root,
  2537. hsotg, &fifo_fops);
  2538. if (IS_ERR(hsotg->debug_fifo))
  2539. dev_err(hsotg->dev, "%s: failed to create fifo\n", __func__);
  2540. /* create one file for each endpoint */
  2541. for (epidx = 0; epidx < S3C_HSOTG_EPS; epidx++) {
  2542. struct s3c_hsotg_ep *ep = &hsotg->eps[epidx];
  2543. ep->debugfs = debugfs_create_file(ep->name, 0444,
  2544. root, ep, &ep_fops);
  2545. if (IS_ERR(ep->debugfs))
  2546. dev_err(hsotg->dev, "failed to create %s debug file\n",
  2547. ep->name);
  2548. }
  2549. }
  2550. /**
  2551. * s3c_hsotg_delete_debug - cleanup debugfs entries
  2552. * @hsotg: The driver state
  2553. *
  2554. * Cleanup (remove) the debugfs files for use on module exit.
  2555. */
  2556. static void __devexit s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg)
  2557. {
  2558. unsigned epidx;
  2559. for (epidx = 0; epidx < S3C_HSOTG_EPS; epidx++) {
  2560. struct s3c_hsotg_ep *ep = &hsotg->eps[epidx];
  2561. debugfs_remove(ep->debugfs);
  2562. }
  2563. debugfs_remove(hsotg->debug_file);
  2564. debugfs_remove(hsotg->debug_fifo);
  2565. debugfs_remove(hsotg->debug_root);
  2566. }
  2567. /**
  2568. * s3c_hsotg_gate - set the hardware gate for the block
  2569. * @pdev: The device we bound to
  2570. * @on: On or off.
  2571. *
  2572. * Set the hardware gate setting into the block. If we end up on
  2573. * something other than an S3C64XX, then we might need to change this
  2574. * to using a platform data callback, or some other mechanism.
  2575. */
  2576. static void s3c_hsotg_gate(struct platform_device *pdev, bool on)
  2577. {
  2578. unsigned long flags;
  2579. u32 others;
  2580. local_irq_save(flags);
  2581. others = __raw_readl(S3C64XX_OTHERS);
  2582. if (on)
  2583. others |= S3C64XX_OTHERS_USBMASK;
  2584. else
  2585. others &= ~S3C64XX_OTHERS_USBMASK;
  2586. __raw_writel(others, S3C64XX_OTHERS);
  2587. local_irq_restore(flags);
  2588. }
  2589. static struct s3c_hsotg_plat s3c_hsotg_default_pdata;
  2590. static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
  2591. {
  2592. struct s3c_hsotg_plat *plat = pdev->dev.platform_data;
  2593. struct device *dev = &pdev->dev;
  2594. struct s3c_hsotg *hsotg;
  2595. struct resource *res;
  2596. int epnum;
  2597. int ret;
  2598. if (!plat)
  2599. plat = &s3c_hsotg_default_pdata;
  2600. hsotg = kzalloc(sizeof(struct s3c_hsotg) +
  2601. sizeof(struct s3c_hsotg_ep) * S3C_HSOTG_EPS,
  2602. GFP_KERNEL);
  2603. if (!hsotg) {
  2604. dev_err(dev, "cannot get memory\n");
  2605. return -ENOMEM;
  2606. }
  2607. hsotg->dev = dev;
  2608. hsotg->plat = plat;
  2609. hsotg->clk = clk_get(&pdev->dev, "otg");
  2610. if (IS_ERR(hsotg->clk)) {
  2611. dev_err(dev, "cannot get otg clock\n");
  2612. ret = -EINVAL;
  2613. goto err_mem;
  2614. }
  2615. platform_set_drvdata(pdev, hsotg);
  2616. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2617. if (!res) {
  2618. dev_err(dev, "cannot find register resource 0\n");
  2619. ret = -EINVAL;
  2620. goto err_clk;
  2621. }
  2622. hsotg->regs_res = request_mem_region(res->start, resource_size(res),
  2623. dev_name(dev));
  2624. if (!hsotg->regs_res) {
  2625. dev_err(dev, "cannot reserve registers\n");
  2626. ret = -ENOENT;
  2627. goto err_clk;
  2628. }
  2629. hsotg->regs = ioremap(res->start, resource_size(res));
  2630. if (!hsotg->regs) {
  2631. dev_err(dev, "cannot map registers\n");
  2632. ret = -ENXIO;
  2633. goto err_regs_res;
  2634. }
  2635. ret = platform_get_irq(pdev, 0);
  2636. if (ret < 0) {
  2637. dev_err(dev, "cannot find IRQ\n");
  2638. goto err_regs;
  2639. }
  2640. hsotg->irq = ret;
  2641. ret = request_irq(ret, s3c_hsotg_irq, 0, dev_name(dev), hsotg);
  2642. if (ret < 0) {
  2643. dev_err(dev, "cannot claim IRQ\n");
  2644. goto err_regs;
  2645. }
  2646. dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq);
  2647. device_initialize(&hsotg->gadget.dev);
  2648. dev_set_name(&hsotg->gadget.dev, "gadget");
  2649. hsotg->gadget.is_dualspeed = 1;
  2650. hsotg->gadget.ops = &s3c_hsotg_gadget_ops;
  2651. hsotg->gadget.name = dev_name(dev);
  2652. hsotg->gadget.dev.parent = dev;
  2653. hsotg->gadget.dev.dma_mask = dev->dma_mask;
  2654. /* setup endpoint information */
  2655. INIT_LIST_HEAD(&hsotg->gadget.ep_list);
  2656. hsotg->gadget.ep0 = &hsotg->eps[0].ep;
  2657. /* allocate EP0 request */
  2658. hsotg->ctrl_req = s3c_hsotg_ep_alloc_request(&hsotg->eps[0].ep,
  2659. GFP_KERNEL);
  2660. if (!hsotg->ctrl_req) {
  2661. dev_err(dev, "failed to allocate ctrl req\n");
  2662. goto err_regs;
  2663. }
  2664. /* reset the system */
  2665. clk_enable(hsotg->clk);
  2666. s3c_hsotg_gate(pdev, true);
  2667. s3c_hsotg_otgreset(hsotg);
  2668. s3c_hsotg_corereset(hsotg);
  2669. s3c_hsotg_init(hsotg);
  2670. /* initialise the endpoints now the core has been initialised */
  2671. for (epnum = 0; epnum < S3C_HSOTG_EPS; epnum++)
  2672. s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum);
  2673. s3c_hsotg_create_debug(hsotg);
  2674. s3c_hsotg_dump(hsotg);
  2675. our_hsotg = hsotg;
  2676. return 0;
  2677. err_regs:
  2678. iounmap(hsotg->regs);
  2679. err_regs_res:
  2680. release_resource(hsotg->regs_res);
  2681. kfree(hsotg->regs_res);
  2682. err_clk:
  2683. clk_put(hsotg->clk);
  2684. err_mem:
  2685. kfree(hsotg);
  2686. return ret;
  2687. }
  2688. static int __devexit s3c_hsotg_remove(struct platform_device *pdev)
  2689. {
  2690. struct s3c_hsotg *hsotg = platform_get_drvdata(pdev);
  2691. s3c_hsotg_delete_debug(hsotg);
  2692. usb_gadget_unregister_driver(hsotg->driver);
  2693. free_irq(hsotg->irq, hsotg);
  2694. iounmap(hsotg->regs);
  2695. release_resource(hsotg->regs_res);
  2696. kfree(hsotg->regs_res);
  2697. s3c_hsotg_gate(pdev, false);
  2698. clk_disable(hsotg->clk);
  2699. clk_put(hsotg->clk);
  2700. kfree(hsotg);
  2701. return 0;
  2702. }
  2703. #if 1
  2704. #define s3c_hsotg_suspend NULL
  2705. #define s3c_hsotg_resume NULL
  2706. #endif
  2707. static struct platform_driver s3c_hsotg_driver = {
  2708. .driver = {
  2709. .name = "s3c-hsotg",
  2710. .owner = THIS_MODULE,
  2711. },
  2712. .probe = s3c_hsotg_probe,
  2713. .remove = __devexit_p(s3c_hsotg_remove),
  2714. .suspend = s3c_hsotg_suspend,
  2715. .resume = s3c_hsotg_resume,
  2716. };
  2717. static int __init s3c_hsotg_modinit(void)
  2718. {
  2719. return platform_driver_register(&s3c_hsotg_driver);
  2720. }
  2721. static void __exit s3c_hsotg_modexit(void)
  2722. {
  2723. platform_driver_unregister(&s3c_hsotg_driver);
  2724. }
  2725. module_init(s3c_hsotg_modinit);
  2726. module_exit(s3c_hsotg_modexit);
  2727. MODULE_DESCRIPTION("Samsung S3C USB High-speed/OtG device");
  2728. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  2729. MODULE_LICENSE("GPL");
  2730. MODULE_ALIAS("platform:s3c-hsotg");