s3c-hsotg.c 89 KB

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