fusb300_udc.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746
  1. /*
  2. * Fusb300 UDC (USB gadget)
  3. *
  4. * Copyright (C) 2010 Faraday Technology Corp.
  5. *
  6. * Author : Yuan-hsin Chen <yhchen@faraday-tech.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; version 2 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. */
  22. #include <linux/dma-mapping.h>
  23. #include <linux/err.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/io.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/usb/ch9.h>
  28. #include <linux/usb/gadget.h>
  29. #include "fusb300_udc.h"
  30. MODULE_DESCRIPTION("FUSB300 USB gadget driver");
  31. MODULE_LICENSE("GPL");
  32. MODULE_AUTHOR("Yuan Hsin Chen <yhchen@faraday-tech.com>");
  33. MODULE_ALIAS("platform:fusb300_udc");
  34. #define DRIVER_VERSION "20 October 2010"
  35. static const char udc_name[] = "fusb300_udc";
  36. static const char * const fusb300_ep_name[] = {
  37. "ep0", "ep1", "ep2", "ep3", "ep4", "ep5", "ep6", "ep7", "ep8", "ep9",
  38. "ep10", "ep11", "ep12", "ep13", "ep14", "ep15"
  39. };
  40. static void done(struct fusb300_ep *ep, struct fusb300_request *req,
  41. int status);
  42. static void fusb300_enable_bit(struct fusb300 *fusb300, u32 offset,
  43. u32 value)
  44. {
  45. u32 reg = ioread32(fusb300->reg + offset);
  46. reg |= value;
  47. iowrite32(reg, fusb300->reg + offset);
  48. }
  49. static void fusb300_disable_bit(struct fusb300 *fusb300, u32 offset,
  50. u32 value)
  51. {
  52. u32 reg = ioread32(fusb300->reg + offset);
  53. reg &= ~value;
  54. iowrite32(reg, fusb300->reg + offset);
  55. }
  56. static void fusb300_ep_setting(struct fusb300_ep *ep,
  57. struct fusb300_ep_info info)
  58. {
  59. ep->epnum = info.epnum;
  60. ep->type = info.type;
  61. }
  62. static int fusb300_ep_release(struct fusb300_ep *ep)
  63. {
  64. if (!ep->epnum)
  65. return 0;
  66. ep->epnum = 0;
  67. ep->stall = 0;
  68. ep->wedged = 0;
  69. return 0;
  70. }
  71. static void fusb300_set_fifo_entry(struct fusb300 *fusb300,
  72. u32 ep)
  73. {
  74. u32 val = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
  75. val &= ~FUSB300_EPSET1_FIFOENTRY_MSK;
  76. val |= FUSB300_EPSET1_FIFOENTRY(FUSB300_FIFO_ENTRY_NUM);
  77. iowrite32(val, fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
  78. }
  79. static void fusb300_set_start_entry(struct fusb300 *fusb300,
  80. u8 ep)
  81. {
  82. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
  83. u32 start_entry = fusb300->fifo_entry_num * FUSB300_FIFO_ENTRY_NUM;
  84. reg &= ~FUSB300_EPSET1_START_ENTRY_MSK ;
  85. reg |= FUSB300_EPSET1_START_ENTRY(start_entry);
  86. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
  87. if (fusb300->fifo_entry_num == FUSB300_MAX_FIFO_ENTRY) {
  88. fusb300->fifo_entry_num = 0;
  89. fusb300->addrofs = 0;
  90. pr_err("fifo entry is over the maximum number!\n");
  91. } else
  92. fusb300->fifo_entry_num++;
  93. }
  94. /* set fusb300_set_start_entry first before fusb300_set_epaddrofs */
  95. static void fusb300_set_epaddrofs(struct fusb300 *fusb300,
  96. struct fusb300_ep_info info)
  97. {
  98. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum));
  99. reg &= ~FUSB300_EPSET2_ADDROFS_MSK;
  100. reg |= FUSB300_EPSET2_ADDROFS(fusb300->addrofs);
  101. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum));
  102. fusb300->addrofs += (info.maxpacket + 7) / 8 * FUSB300_FIFO_ENTRY_NUM;
  103. }
  104. static void ep_fifo_setting(struct fusb300 *fusb300,
  105. struct fusb300_ep_info info)
  106. {
  107. fusb300_set_fifo_entry(fusb300, info.epnum);
  108. fusb300_set_start_entry(fusb300, info.epnum);
  109. fusb300_set_epaddrofs(fusb300, info);
  110. }
  111. static void fusb300_set_eptype(struct fusb300 *fusb300,
  112. struct fusb300_ep_info info)
  113. {
  114. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
  115. reg &= ~FUSB300_EPSET1_TYPE_MSK;
  116. reg |= FUSB300_EPSET1_TYPE(info.type);
  117. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
  118. }
  119. static void fusb300_set_epdir(struct fusb300 *fusb300,
  120. struct fusb300_ep_info info)
  121. {
  122. u32 reg;
  123. if (!info.dir_in)
  124. return;
  125. reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
  126. reg &= ~FUSB300_EPSET1_DIR_MSK;
  127. reg |= FUSB300_EPSET1_DIRIN;
  128. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
  129. }
  130. static void fusb300_set_ep_active(struct fusb300 *fusb300,
  131. u8 ep)
  132. {
  133. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
  134. reg |= FUSB300_EPSET1_ACTEN;
  135. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
  136. }
  137. static void fusb300_set_epmps(struct fusb300 *fusb300,
  138. struct fusb300_ep_info info)
  139. {
  140. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum));
  141. reg &= ~FUSB300_EPSET2_MPS_MSK;
  142. reg |= FUSB300_EPSET2_MPS(info.maxpacket);
  143. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum));
  144. }
  145. static void fusb300_set_interval(struct fusb300 *fusb300,
  146. struct fusb300_ep_info info)
  147. {
  148. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
  149. reg &= ~FUSB300_EPSET1_INTERVAL(0x7);
  150. reg |= FUSB300_EPSET1_INTERVAL(info.interval);
  151. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
  152. }
  153. static void fusb300_set_bwnum(struct fusb300 *fusb300,
  154. struct fusb300_ep_info info)
  155. {
  156. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
  157. reg &= ~FUSB300_EPSET1_BWNUM(0x3);
  158. reg |= FUSB300_EPSET1_BWNUM(info.bw_num);
  159. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
  160. }
  161. static void set_ep_reg(struct fusb300 *fusb300,
  162. struct fusb300_ep_info info)
  163. {
  164. fusb300_set_eptype(fusb300, info);
  165. fusb300_set_epdir(fusb300, info);
  166. fusb300_set_epmps(fusb300, info);
  167. if (info.interval)
  168. fusb300_set_interval(fusb300, info);
  169. if (info.bw_num)
  170. fusb300_set_bwnum(fusb300, info);
  171. fusb300_set_ep_active(fusb300, info.epnum);
  172. }
  173. static int config_ep(struct fusb300_ep *ep,
  174. const struct usb_endpoint_descriptor *desc)
  175. {
  176. struct fusb300 *fusb300 = ep->fusb300;
  177. struct fusb300_ep_info info;
  178. ep->desc = desc;
  179. info.interval = 0;
  180. info.addrofs = 0;
  181. info.bw_num = 0;
  182. info.type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
  183. info.dir_in = (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? 1 : 0;
  184. info.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
  185. info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  186. if ((info.type == USB_ENDPOINT_XFER_INT) ||
  187. (info.type == USB_ENDPOINT_XFER_ISOC)) {
  188. info.interval = desc->bInterval;
  189. if (info.type == USB_ENDPOINT_XFER_ISOC)
  190. info.bw_num = ((desc->wMaxPacketSize & 0x1800) >> 11);
  191. }
  192. ep_fifo_setting(fusb300, info);
  193. set_ep_reg(fusb300, info);
  194. fusb300_ep_setting(ep, info);
  195. fusb300->ep[info.epnum] = ep;
  196. return 0;
  197. }
  198. static int fusb300_enable(struct usb_ep *_ep,
  199. const struct usb_endpoint_descriptor *desc)
  200. {
  201. struct fusb300_ep *ep;
  202. ep = container_of(_ep, struct fusb300_ep, ep);
  203. if (ep->fusb300->reenum) {
  204. ep->fusb300->fifo_entry_num = 0;
  205. ep->fusb300->addrofs = 0;
  206. ep->fusb300->reenum = 0;
  207. }
  208. return config_ep(ep, desc);
  209. }
  210. static int fusb300_disable(struct usb_ep *_ep)
  211. {
  212. struct fusb300_ep *ep;
  213. struct fusb300_request *req;
  214. unsigned long flags;
  215. ep = container_of(_ep, struct fusb300_ep, ep);
  216. BUG_ON(!ep);
  217. while (!list_empty(&ep->queue)) {
  218. req = list_entry(ep->queue.next, struct fusb300_request, queue);
  219. spin_lock_irqsave(&ep->fusb300->lock, flags);
  220. done(ep, req, -ECONNRESET);
  221. spin_unlock_irqrestore(&ep->fusb300->lock, flags);
  222. }
  223. return fusb300_ep_release(ep);
  224. }
  225. static struct usb_request *fusb300_alloc_request(struct usb_ep *_ep,
  226. gfp_t gfp_flags)
  227. {
  228. struct fusb300_request *req;
  229. req = kzalloc(sizeof(struct fusb300_request), gfp_flags);
  230. if (!req)
  231. return NULL;
  232. INIT_LIST_HEAD(&req->queue);
  233. return &req->req;
  234. }
  235. static void fusb300_free_request(struct usb_ep *_ep, struct usb_request *_req)
  236. {
  237. struct fusb300_request *req;
  238. req = container_of(_req, struct fusb300_request, req);
  239. kfree(req);
  240. }
  241. static int enable_fifo_int(struct fusb300_ep *ep)
  242. {
  243. struct fusb300 *fusb300 = ep->fusb300;
  244. if (ep->epnum) {
  245. fusb300_enable_bit(fusb300, FUSB300_OFFSET_IGER0,
  246. FUSB300_IGER0_EEPn_FIFO_INT(ep->epnum));
  247. } else {
  248. pr_err("can't enable_fifo_int ep0\n");
  249. return -EINVAL;
  250. }
  251. return 0;
  252. }
  253. static int disable_fifo_int(struct fusb300_ep *ep)
  254. {
  255. struct fusb300 *fusb300 = ep->fusb300;
  256. if (ep->epnum) {
  257. fusb300_disable_bit(fusb300, FUSB300_OFFSET_IGER0,
  258. FUSB300_IGER0_EEPn_FIFO_INT(ep->epnum));
  259. } else {
  260. pr_err("can't disable_fifo_int ep0\n");
  261. return -EINVAL;
  262. }
  263. return 0;
  264. }
  265. static void fusb300_set_cxlen(struct fusb300 *fusb300, u32 length)
  266. {
  267. u32 reg;
  268. reg = ioread32(fusb300->reg + FUSB300_OFFSET_CSR);
  269. reg &= ~FUSB300_CSR_LEN_MSK;
  270. reg |= FUSB300_CSR_LEN(length);
  271. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_CSR);
  272. }
  273. /* write data to cx fifo */
  274. static void fusb300_wrcxf(struct fusb300_ep *ep,
  275. struct fusb300_request *req)
  276. {
  277. int i = 0;
  278. u8 *tmp;
  279. u32 data;
  280. struct fusb300 *fusb300 = ep->fusb300;
  281. u32 length = req->req.length - req->req.actual;
  282. tmp = req->req.buf + req->req.actual;
  283. if (length > SS_CTL_MAX_PACKET_SIZE) {
  284. fusb300_set_cxlen(fusb300, SS_CTL_MAX_PACKET_SIZE);
  285. for (i = (SS_CTL_MAX_PACKET_SIZE >> 2); i > 0; i--) {
  286. data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16 |
  287. *(tmp + 3) << 24;
  288. iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
  289. tmp += 4;
  290. }
  291. req->req.actual += SS_CTL_MAX_PACKET_SIZE;
  292. } else { /* length is less than max packet size */
  293. fusb300_set_cxlen(fusb300, length);
  294. for (i = length >> 2; i > 0; i--) {
  295. data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16 |
  296. *(tmp + 3) << 24;
  297. printk(KERN_DEBUG " 0x%x\n", data);
  298. iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
  299. tmp = tmp + 4;
  300. }
  301. switch (length % 4) {
  302. case 1:
  303. data = *tmp;
  304. printk(KERN_DEBUG " 0x%x\n", data);
  305. iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
  306. break;
  307. case 2:
  308. data = *tmp | *(tmp + 1) << 8;
  309. printk(KERN_DEBUG " 0x%x\n", data);
  310. iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
  311. break;
  312. case 3:
  313. data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16;
  314. printk(KERN_DEBUG " 0x%x\n", data);
  315. iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
  316. break;
  317. default:
  318. break;
  319. }
  320. req->req.actual += length;
  321. }
  322. }
  323. static void fusb300_set_epnstall(struct fusb300 *fusb300, u8 ep)
  324. {
  325. fusb300_enable_bit(fusb300, FUSB300_OFFSET_EPSET0(ep),
  326. FUSB300_EPSET0_STL);
  327. }
  328. static void fusb300_clear_epnstall(struct fusb300 *fusb300, u8 ep)
  329. {
  330. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET0(ep));
  331. if (reg & FUSB300_EPSET0_STL) {
  332. printk(KERN_DEBUG "EP%d stall... Clear!!\n", ep);
  333. reg &= ~FUSB300_EPSET0_STL;
  334. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET0(ep));
  335. }
  336. }
  337. static void ep0_queue(struct fusb300_ep *ep, struct fusb300_request *req)
  338. {
  339. if (ep->fusb300->ep0_dir) { /* if IN */
  340. if (req->req.length) {
  341. fusb300_wrcxf(ep, req);
  342. } else
  343. printk(KERN_DEBUG "%s : req->req.length = 0x%x\n",
  344. __func__, req->req.length);
  345. if ((req->req.length == req->req.actual) ||
  346. (req->req.actual < ep->ep.maxpacket))
  347. done(ep, req, 0);
  348. } else { /* OUT */
  349. if (!req->req.length)
  350. done(ep, req, 0);
  351. else
  352. fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER1,
  353. FUSB300_IGER1_CX_OUT_INT);
  354. }
  355. }
  356. static int fusb300_queue(struct usb_ep *_ep, struct usb_request *_req,
  357. gfp_t gfp_flags)
  358. {
  359. struct fusb300_ep *ep;
  360. struct fusb300_request *req;
  361. unsigned long flags;
  362. int request = 0;
  363. ep = container_of(_ep, struct fusb300_ep, ep);
  364. req = container_of(_req, struct fusb300_request, req);
  365. if (ep->fusb300->gadget.speed == USB_SPEED_UNKNOWN)
  366. return -ESHUTDOWN;
  367. spin_lock_irqsave(&ep->fusb300->lock, flags);
  368. if (list_empty(&ep->queue))
  369. request = 1;
  370. list_add_tail(&req->queue, &ep->queue);
  371. req->req.actual = 0;
  372. req->req.status = -EINPROGRESS;
  373. if (ep->desc == NULL) /* ep0 */
  374. ep0_queue(ep, req);
  375. else if (request && !ep->stall)
  376. enable_fifo_int(ep);
  377. spin_unlock_irqrestore(&ep->fusb300->lock, flags);
  378. return 0;
  379. }
  380. static int fusb300_dequeue(struct usb_ep *_ep, struct usb_request *_req)
  381. {
  382. struct fusb300_ep *ep;
  383. struct fusb300_request *req;
  384. unsigned long flags;
  385. ep = container_of(_ep, struct fusb300_ep, ep);
  386. req = container_of(_req, struct fusb300_request, req);
  387. spin_lock_irqsave(&ep->fusb300->lock, flags);
  388. if (!list_empty(&ep->queue))
  389. done(ep, req, -ECONNRESET);
  390. spin_unlock_irqrestore(&ep->fusb300->lock, flags);
  391. return 0;
  392. }
  393. static int fusb300_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedge)
  394. {
  395. struct fusb300_ep *ep;
  396. struct fusb300 *fusb300;
  397. unsigned long flags;
  398. int ret = 0;
  399. ep = container_of(_ep, struct fusb300_ep, ep);
  400. fusb300 = ep->fusb300;
  401. spin_lock_irqsave(&ep->fusb300->lock, flags);
  402. if (!list_empty(&ep->queue)) {
  403. ret = -EAGAIN;
  404. goto out;
  405. }
  406. if (value) {
  407. fusb300_set_epnstall(fusb300, ep->epnum);
  408. ep->stall = 1;
  409. if (wedge)
  410. ep->wedged = 1;
  411. } else {
  412. fusb300_clear_epnstall(fusb300, ep->epnum);
  413. ep->stall = 0;
  414. ep->wedged = 0;
  415. }
  416. out:
  417. spin_unlock_irqrestore(&ep->fusb300->lock, flags);
  418. return ret;
  419. }
  420. static int fusb300_set_halt(struct usb_ep *_ep, int value)
  421. {
  422. return fusb300_set_halt_and_wedge(_ep, value, 0);
  423. }
  424. static int fusb300_set_wedge(struct usb_ep *_ep)
  425. {
  426. return fusb300_set_halt_and_wedge(_ep, 1, 1);
  427. }
  428. static void fusb300_fifo_flush(struct usb_ep *_ep)
  429. {
  430. }
  431. static struct usb_ep_ops fusb300_ep_ops = {
  432. .enable = fusb300_enable,
  433. .disable = fusb300_disable,
  434. .alloc_request = fusb300_alloc_request,
  435. .free_request = fusb300_free_request,
  436. .queue = fusb300_queue,
  437. .dequeue = fusb300_dequeue,
  438. .set_halt = fusb300_set_halt,
  439. .fifo_flush = fusb300_fifo_flush,
  440. .set_wedge = fusb300_set_wedge,
  441. };
  442. /*****************************************************************************/
  443. static void fusb300_clear_int(struct fusb300 *fusb300, u32 offset,
  444. u32 value)
  445. {
  446. iowrite32(value, fusb300->reg + offset);
  447. }
  448. static void fusb300_reset(void)
  449. {
  450. }
  451. static void fusb300_set_cxstall(struct fusb300 *fusb300)
  452. {
  453. fusb300_enable_bit(fusb300, FUSB300_OFFSET_CSR,
  454. FUSB300_CSR_STL);
  455. }
  456. static void fusb300_set_cxdone(struct fusb300 *fusb300)
  457. {
  458. fusb300_enable_bit(fusb300, FUSB300_OFFSET_CSR,
  459. FUSB300_CSR_DONE);
  460. }
  461. /* read data from cx fifo */
  462. void fusb300_rdcxf(struct fusb300 *fusb300,
  463. u8 *buffer, u32 length)
  464. {
  465. int i = 0;
  466. u8 *tmp;
  467. u32 data;
  468. tmp = buffer;
  469. for (i = (length >> 2); i > 0; i--) {
  470. data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT);
  471. printk(KERN_DEBUG " 0x%x\n", data);
  472. *tmp = data & 0xFF;
  473. *(tmp + 1) = (data >> 8) & 0xFF;
  474. *(tmp + 2) = (data >> 16) & 0xFF;
  475. *(tmp + 3) = (data >> 24) & 0xFF;
  476. tmp = tmp + 4;
  477. }
  478. switch (length % 4) {
  479. case 1:
  480. data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT);
  481. printk(KERN_DEBUG " 0x%x\n", data);
  482. *tmp = data & 0xFF;
  483. break;
  484. case 2:
  485. data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT);
  486. printk(KERN_DEBUG " 0x%x\n", data);
  487. *tmp = data & 0xFF;
  488. *(tmp + 1) = (data >> 8) & 0xFF;
  489. break;
  490. case 3:
  491. data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT);
  492. printk(KERN_DEBUG " 0x%x\n", data);
  493. *tmp = data & 0xFF;
  494. *(tmp + 1) = (data >> 8) & 0xFF;
  495. *(tmp + 2) = (data >> 16) & 0xFF;
  496. break;
  497. default:
  498. break;
  499. }
  500. }
  501. #if 0
  502. static void fusb300_dbg_fifo(struct fusb300_ep *ep,
  503. u8 entry, u16 length)
  504. {
  505. u32 reg;
  506. u32 i = 0;
  507. u32 j = 0;
  508. reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_GTM);
  509. reg &= ~(FUSB300_GTM_TST_EP_ENTRY(0xF) |
  510. FUSB300_GTM_TST_EP_NUM(0xF) | FUSB300_GTM_TST_FIFO_DEG);
  511. reg |= (FUSB300_GTM_TST_EP_ENTRY(entry) |
  512. FUSB300_GTM_TST_EP_NUM(ep->epnum) | FUSB300_GTM_TST_FIFO_DEG);
  513. iowrite32(reg, ep->fusb300->reg + FUSB300_OFFSET_GTM);
  514. for (i = 0; i < (length >> 2); i++) {
  515. if (i * 4 == 1024)
  516. break;
  517. reg = ioread32(ep->fusb300->reg +
  518. FUSB300_OFFSET_BUFDBG_START + i * 4);
  519. printk(KERN_DEBUG" 0x%-8x", reg);
  520. j++;
  521. if ((j % 4) == 0)
  522. printk(KERN_DEBUG "\n");
  523. }
  524. if (length % 4) {
  525. reg = ioread32(ep->fusb300->reg +
  526. FUSB300_OFFSET_BUFDBG_START + i * 4);
  527. printk(KERN_DEBUG " 0x%x\n", reg);
  528. }
  529. if ((j % 4) != 0)
  530. printk(KERN_DEBUG "\n");
  531. fusb300_disable_bit(ep->fusb300, FUSB300_OFFSET_GTM,
  532. FUSB300_GTM_TST_FIFO_DEG);
  533. }
  534. static void fusb300_cmp_dbg_fifo(struct fusb300_ep *ep,
  535. u8 entry, u16 length, u8 *golden)
  536. {
  537. u32 reg;
  538. u32 i = 0;
  539. u32 golden_value;
  540. u8 *tmp;
  541. tmp = golden;
  542. printk(KERN_DEBUG "fusb300_cmp_dbg_fifo (entry %d) : start\n", entry);
  543. reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_GTM);
  544. reg &= ~(FUSB300_GTM_TST_EP_ENTRY(0xF) |
  545. FUSB300_GTM_TST_EP_NUM(0xF) | FUSB300_GTM_TST_FIFO_DEG);
  546. reg |= (FUSB300_GTM_TST_EP_ENTRY(entry) |
  547. FUSB300_GTM_TST_EP_NUM(ep->epnum) | FUSB300_GTM_TST_FIFO_DEG);
  548. iowrite32(reg, ep->fusb300->reg + FUSB300_OFFSET_GTM);
  549. for (i = 0; i < (length >> 2); i++) {
  550. if (i * 4 == 1024)
  551. break;
  552. golden_value = *tmp | *(tmp + 1) << 8 |
  553. *(tmp + 2) << 16 | *(tmp + 3) << 24;
  554. reg = ioread32(ep->fusb300->reg +
  555. FUSB300_OFFSET_BUFDBG_START + i*4);
  556. if (reg != golden_value) {
  557. printk(KERN_DEBUG "0x%x : ", (u32)(ep->fusb300->reg +
  558. FUSB300_OFFSET_BUFDBG_START + i*4));
  559. printk(KERN_DEBUG " golden = 0x%x, reg = 0x%x\n",
  560. golden_value, reg);
  561. }
  562. tmp += 4;
  563. }
  564. switch (length % 4) {
  565. case 1:
  566. golden_value = *tmp;
  567. case 2:
  568. golden_value = *tmp | *(tmp + 1) << 8;
  569. case 3:
  570. golden_value = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16;
  571. default:
  572. break;
  573. reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_BUFDBG_START + i*4);
  574. if (reg != golden_value) {
  575. printk(KERN_DEBUG "0x%x:", (u32)(ep->fusb300->reg +
  576. FUSB300_OFFSET_BUFDBG_START + i*4));
  577. printk(KERN_DEBUG " golden = 0x%x, reg = 0x%x\n",
  578. golden_value, reg);
  579. }
  580. }
  581. printk(KERN_DEBUG "fusb300_cmp_dbg_fifo : end\n");
  582. fusb300_disable_bit(ep->fusb300, FUSB300_OFFSET_GTM,
  583. FUSB300_GTM_TST_FIFO_DEG);
  584. }
  585. #endif
  586. static void fusb300_rdfifo(struct fusb300_ep *ep,
  587. struct fusb300_request *req,
  588. u32 length)
  589. {
  590. int i = 0;
  591. u8 *tmp;
  592. u32 data, reg;
  593. struct fusb300 *fusb300 = ep->fusb300;
  594. tmp = req->req.buf + req->req.actual;
  595. req->req.actual += length;
  596. if (req->req.actual > req->req.length)
  597. printk(KERN_DEBUG "req->req.actual > req->req.length\n");
  598. for (i = (length >> 2); i > 0; i--) {
  599. data = ioread32(fusb300->reg +
  600. FUSB300_OFFSET_EPPORT(ep->epnum));
  601. *tmp = data & 0xFF;
  602. *(tmp + 1) = (data >> 8) & 0xFF;
  603. *(tmp + 2) = (data >> 16) & 0xFF;
  604. *(tmp + 3) = (data >> 24) & 0xFF;
  605. tmp = tmp + 4;
  606. }
  607. switch (length % 4) {
  608. case 1:
  609. data = ioread32(fusb300->reg +
  610. FUSB300_OFFSET_EPPORT(ep->epnum));
  611. *tmp = data & 0xFF;
  612. break;
  613. case 2:
  614. data = ioread32(fusb300->reg +
  615. FUSB300_OFFSET_EPPORT(ep->epnum));
  616. *tmp = data & 0xFF;
  617. *(tmp + 1) = (data >> 8) & 0xFF;
  618. break;
  619. case 3:
  620. data = ioread32(fusb300->reg +
  621. FUSB300_OFFSET_EPPORT(ep->epnum));
  622. *tmp = data & 0xFF;
  623. *(tmp + 1) = (data >> 8) & 0xFF;
  624. *(tmp + 2) = (data >> 16) & 0xFF;
  625. break;
  626. default:
  627. break;
  628. }
  629. do {
  630. reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1);
  631. reg &= FUSB300_IGR1_SYNF0_EMPTY_INT;
  632. if (i)
  633. printk(KERN_INFO "sync fifo is not empty!\n");
  634. i++;
  635. } while (!reg);
  636. }
  637. /* write data to fifo */
  638. static void fusb300_wrfifo(struct fusb300_ep *ep,
  639. struct fusb300_request *req)
  640. {
  641. int i = 0;
  642. u8 *tmp;
  643. u32 data, reg;
  644. struct fusb300 *fusb300 = ep->fusb300;
  645. tmp = req->req.buf;
  646. req->req.actual = req->req.length;
  647. for (i = (req->req.length >> 2); i > 0; i--) {
  648. data = *tmp | *(tmp + 1) << 8 |
  649. *(tmp + 2) << 16 | *(tmp + 3) << 24;
  650. iowrite32(data, fusb300->reg +
  651. FUSB300_OFFSET_EPPORT(ep->epnum));
  652. tmp += 4;
  653. }
  654. switch (req->req.length % 4) {
  655. case 1:
  656. data = *tmp;
  657. iowrite32(data, fusb300->reg +
  658. FUSB300_OFFSET_EPPORT(ep->epnum));
  659. break;
  660. case 2:
  661. data = *tmp | *(tmp + 1) << 8;
  662. iowrite32(data, fusb300->reg +
  663. FUSB300_OFFSET_EPPORT(ep->epnum));
  664. break;
  665. case 3:
  666. data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16;
  667. iowrite32(data, fusb300->reg +
  668. FUSB300_OFFSET_EPPORT(ep->epnum));
  669. break;
  670. default:
  671. break;
  672. }
  673. do {
  674. reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1);
  675. reg &= FUSB300_IGR1_SYNF0_EMPTY_INT;
  676. if (i)
  677. printk(KERN_INFO"sync fifo is not empty!\n");
  678. i++;
  679. } while (!reg);
  680. }
  681. static u8 fusb300_get_epnstall(struct fusb300 *fusb300, u8 ep)
  682. {
  683. u8 value;
  684. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET0(ep));
  685. value = reg & FUSB300_EPSET0_STL;
  686. return value;
  687. }
  688. static u8 fusb300_get_cxstall(struct fusb300 *fusb300)
  689. {
  690. u8 value;
  691. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_CSR);
  692. value = (reg & FUSB300_CSR_STL) >> 1;
  693. return value;
  694. }
  695. static void request_error(struct fusb300 *fusb300)
  696. {
  697. fusb300_set_cxstall(fusb300);
  698. printk(KERN_DEBUG "request error!!\n");
  699. }
  700. static void get_status(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
  701. __releases(fusb300->lock)
  702. __acquires(fusb300->lock)
  703. {
  704. u8 ep;
  705. u16 status = 0;
  706. u16 w_index = ctrl->wIndex;
  707. switch (ctrl->bRequestType & USB_RECIP_MASK) {
  708. case USB_RECIP_DEVICE:
  709. status = 1 << USB_DEVICE_SELF_POWERED;
  710. break;
  711. case USB_RECIP_INTERFACE:
  712. status = 0;
  713. break;
  714. case USB_RECIP_ENDPOINT:
  715. ep = w_index & USB_ENDPOINT_NUMBER_MASK;
  716. if (ep) {
  717. if (fusb300_get_epnstall(fusb300, ep))
  718. status = 1 << USB_ENDPOINT_HALT;
  719. } else {
  720. if (fusb300_get_cxstall(fusb300))
  721. status = 0;
  722. }
  723. break;
  724. default:
  725. request_error(fusb300);
  726. return; /* exit */
  727. }
  728. fusb300->ep0_data = cpu_to_le16(status);
  729. fusb300->ep0_req->buf = &fusb300->ep0_data;
  730. fusb300->ep0_req->length = 2;
  731. spin_unlock(&fusb300->lock);
  732. fusb300_queue(fusb300->gadget.ep0, fusb300->ep0_req, GFP_KERNEL);
  733. spin_lock(&fusb300->lock);
  734. }
  735. static void set_feature(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
  736. {
  737. u8 ep;
  738. switch (ctrl->bRequestType & USB_RECIP_MASK) {
  739. case USB_RECIP_DEVICE:
  740. fusb300_set_cxdone(fusb300);
  741. break;
  742. case USB_RECIP_INTERFACE:
  743. fusb300_set_cxdone(fusb300);
  744. break;
  745. case USB_RECIP_ENDPOINT: {
  746. u16 w_index = le16_to_cpu(ctrl->wIndex);
  747. ep = w_index & USB_ENDPOINT_NUMBER_MASK;
  748. if (ep)
  749. fusb300_set_epnstall(fusb300, ep);
  750. else
  751. fusb300_set_cxstall(fusb300);
  752. fusb300_set_cxdone(fusb300);
  753. }
  754. break;
  755. default:
  756. request_error(fusb300);
  757. break;
  758. }
  759. }
  760. static void fusb300_clear_seqnum(struct fusb300 *fusb300, u8 ep)
  761. {
  762. fusb300_enable_bit(fusb300, FUSB300_OFFSET_EPSET0(ep),
  763. FUSB300_EPSET0_CLRSEQNUM);
  764. }
  765. static void clear_feature(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
  766. {
  767. struct fusb300_ep *ep =
  768. fusb300->ep[ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK];
  769. switch (ctrl->bRequestType & USB_RECIP_MASK) {
  770. case USB_RECIP_DEVICE:
  771. fusb300_set_cxdone(fusb300);
  772. break;
  773. case USB_RECIP_INTERFACE:
  774. fusb300_set_cxdone(fusb300);
  775. break;
  776. case USB_RECIP_ENDPOINT:
  777. if (ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK) {
  778. if (ep->wedged) {
  779. fusb300_set_cxdone(fusb300);
  780. break;
  781. }
  782. if (ep->stall) {
  783. ep->stall = 0;
  784. fusb300_clear_seqnum(fusb300, ep->epnum);
  785. fusb300_clear_epnstall(fusb300, ep->epnum);
  786. if (!list_empty(&ep->queue))
  787. enable_fifo_int(ep);
  788. }
  789. }
  790. fusb300_set_cxdone(fusb300);
  791. break;
  792. default:
  793. request_error(fusb300);
  794. break;
  795. }
  796. }
  797. static void fusb300_set_dev_addr(struct fusb300 *fusb300, u16 addr)
  798. {
  799. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_DAR);
  800. reg &= ~FUSB300_DAR_DRVADDR_MSK;
  801. reg |= FUSB300_DAR_DRVADDR(addr);
  802. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_DAR);
  803. }
  804. static void set_address(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
  805. {
  806. if (ctrl->wValue >= 0x0100)
  807. request_error(fusb300);
  808. else {
  809. fusb300_set_dev_addr(fusb300, ctrl->wValue);
  810. fusb300_set_cxdone(fusb300);
  811. }
  812. }
  813. #define UVC_COPY_DESCRIPTORS(mem, src) \
  814. do { \
  815. const struct usb_descriptor_header * const *__src; \
  816. for (__src = src; *__src; ++__src) { \
  817. memcpy(mem, *__src, (*__src)->bLength); \
  818. mem += (*__src)->bLength; \
  819. } \
  820. } while (0)
  821. static int setup_packet(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
  822. {
  823. u8 *p = (u8 *)ctrl;
  824. u8 ret = 0;
  825. u8 i = 0;
  826. fusb300_rdcxf(fusb300, p, 8);
  827. fusb300->ep0_dir = ctrl->bRequestType & USB_DIR_IN;
  828. fusb300->ep0_length = ctrl->wLength;
  829. /* check request */
  830. if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
  831. switch (ctrl->bRequest) {
  832. case USB_REQ_GET_STATUS:
  833. get_status(fusb300, ctrl);
  834. break;
  835. case USB_REQ_CLEAR_FEATURE:
  836. clear_feature(fusb300, ctrl);
  837. break;
  838. case USB_REQ_SET_FEATURE:
  839. set_feature(fusb300, ctrl);
  840. break;
  841. case USB_REQ_SET_ADDRESS:
  842. set_address(fusb300, ctrl);
  843. break;
  844. case USB_REQ_SET_CONFIGURATION:
  845. fusb300_enable_bit(fusb300, FUSB300_OFFSET_DAR,
  846. FUSB300_DAR_SETCONFG);
  847. /* clear sequence number */
  848. for (i = 1; i <= FUSB300_MAX_NUM_EP; i++)
  849. fusb300_clear_seqnum(fusb300, i);
  850. fusb300->reenum = 1;
  851. ret = 1;
  852. break;
  853. default:
  854. ret = 1;
  855. break;
  856. }
  857. } else
  858. ret = 1;
  859. return ret;
  860. }
  861. static void fusb300_set_ep_bycnt(struct fusb300_ep *ep, u32 bycnt)
  862. {
  863. struct fusb300 *fusb300 = ep->fusb300;
  864. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
  865. reg &= ~FUSB300_FFR_BYCNT;
  866. reg |= bycnt & FUSB300_FFR_BYCNT;
  867. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
  868. }
  869. static void done(struct fusb300_ep *ep, struct fusb300_request *req,
  870. int status)
  871. {
  872. list_del_init(&req->queue);
  873. /* don't modify queue heads during completion callback */
  874. if (ep->fusb300->gadget.speed == USB_SPEED_UNKNOWN)
  875. req->req.status = -ESHUTDOWN;
  876. else
  877. req->req.status = status;
  878. spin_unlock(&ep->fusb300->lock);
  879. req->req.complete(&ep->ep, &req->req);
  880. spin_lock(&ep->fusb300->lock);
  881. if (ep->epnum) {
  882. disable_fifo_int(ep);
  883. if (!list_empty(&ep->queue))
  884. enable_fifo_int(ep);
  885. } else
  886. fusb300_set_cxdone(ep->fusb300);
  887. }
  888. void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep,
  889. struct fusb300_request *req)
  890. {
  891. u32 value;
  892. u32 reg;
  893. /* wait SW owner */
  894. do {
  895. reg = ioread32(ep->fusb300->reg +
  896. FUSB300_OFFSET_EPPRD_W0(ep->epnum));
  897. reg &= FUSB300_EPPRD0_H;
  898. } while (reg);
  899. iowrite32((u32) req->req.buf, ep->fusb300->reg +
  900. FUSB300_OFFSET_EPPRD_W1(ep->epnum));
  901. value = FUSB300_EPPRD0_BTC(req->req.length) | FUSB300_EPPRD0_H |
  902. FUSB300_EPPRD0_F | FUSB300_EPPRD0_L | FUSB300_EPPRD0_I;
  903. iowrite32(value, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W0(ep->epnum));
  904. iowrite32(0x0, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W2(ep->epnum));
  905. fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_EPPRDRDY,
  906. FUSB300_EPPRDR_EP_PRD_RDY(ep->epnum));
  907. }
  908. static void fusb300_wait_idma_finished(struct fusb300_ep *ep)
  909. {
  910. u32 reg;
  911. do {
  912. reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGR1);
  913. if ((reg & FUSB300_IGR1_VBUS_CHG_INT) ||
  914. (reg & FUSB300_IGR1_WARM_RST_INT) ||
  915. (reg & FUSB300_IGR1_HOT_RST_INT) ||
  916. (reg & FUSB300_IGR1_USBRST_INT)
  917. )
  918. goto IDMA_RESET;
  919. reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGR0);
  920. reg &= FUSB300_IGR0_EPn_PRD_INT(ep->epnum);
  921. } while (!reg);
  922. fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGR0,
  923. FUSB300_IGR0_EPn_PRD_INT(ep->epnum));
  924. IDMA_RESET:
  925. fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGER0,
  926. FUSB300_IGER0_EEPn_PRD_INT(ep->epnum));
  927. }
  928. static void fusb300_set_idma(struct fusb300_ep *ep,
  929. struct fusb300_request *req)
  930. {
  931. dma_addr_t d;
  932. u8 *tmp = NULL;
  933. d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE);
  934. if (dma_mapping_error(NULL, d)) {
  935. kfree(req->req.buf);
  936. printk(KERN_DEBUG "dma_mapping_error\n");
  937. }
  938. dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE);
  939. fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0,
  940. FUSB300_IGER0_EEPn_PRD_INT(ep->epnum));
  941. tmp = req->req.buf;
  942. req->req.buf = (u8 *)d;
  943. fusb300_fill_idma_prdtbl(ep, req);
  944. /* check idma is done */
  945. fusb300_wait_idma_finished(ep);
  946. req->req.buf = tmp;
  947. if (d)
  948. dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE);
  949. }
  950. static void in_ep_fifo_handler(struct fusb300_ep *ep)
  951. {
  952. struct fusb300_request *req = list_entry(ep->queue.next,
  953. struct fusb300_request, queue);
  954. if (req->req.length) {
  955. #if 0
  956. fusb300_set_ep_bycnt(ep, req->req.length);
  957. fusb300_wrfifo(ep, req);
  958. #else
  959. fusb300_set_idma(ep, req);
  960. #endif
  961. }
  962. done(ep, req, 0);
  963. }
  964. static void out_ep_fifo_handler(struct fusb300_ep *ep)
  965. {
  966. struct fusb300 *fusb300 = ep->fusb300;
  967. struct fusb300_request *req = list_entry(ep->queue.next,
  968. struct fusb300_request, queue);
  969. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
  970. u32 length = reg & FUSB300_FFR_BYCNT;
  971. fusb300_rdfifo(ep, req, length);
  972. /* finish out transfer */
  973. if ((req->req.length == req->req.actual) || (length < ep->ep.maxpacket))
  974. done(ep, req, 0);
  975. }
  976. static void check_device_mode(struct fusb300 *fusb300)
  977. {
  978. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_GCR);
  979. switch (reg & FUSB300_GCR_DEVEN_MSK) {
  980. case FUSB300_GCR_DEVEN_SS:
  981. fusb300->gadget.speed = USB_SPEED_SUPER;
  982. break;
  983. case FUSB300_GCR_DEVEN_HS:
  984. fusb300->gadget.speed = USB_SPEED_HIGH;
  985. break;
  986. case FUSB300_GCR_DEVEN_FS:
  987. fusb300->gadget.speed = USB_SPEED_FULL;
  988. break;
  989. default:
  990. fusb300->gadget.speed = USB_SPEED_UNKNOWN;
  991. break;
  992. }
  993. printk(KERN_INFO "dev_mode = %d\n", (reg & FUSB300_GCR_DEVEN_MSK));
  994. }
  995. static void fusb300_ep0out(struct fusb300 *fusb300)
  996. {
  997. struct fusb300_ep *ep = fusb300->ep[0];
  998. u32 reg;
  999. if (!list_empty(&ep->queue)) {
  1000. struct fusb300_request *req;
  1001. req = list_first_entry(&ep->queue,
  1002. struct fusb300_request, queue);
  1003. if (req->req.length)
  1004. fusb300_rdcxf(ep->fusb300, req->req.buf,
  1005. req->req.length);
  1006. done(ep, req, 0);
  1007. reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGER1);
  1008. reg &= ~FUSB300_IGER1_CX_OUT_INT;
  1009. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_IGER1);
  1010. } else
  1011. pr_err("%s : empty queue\n", __func__);
  1012. }
  1013. static void fusb300_ep0in(struct fusb300 *fusb300)
  1014. {
  1015. struct fusb300_request *req;
  1016. struct fusb300_ep *ep = fusb300->ep[0];
  1017. if ((!list_empty(&ep->queue)) && (fusb300->ep0_dir)) {
  1018. req = list_entry(ep->queue.next,
  1019. struct fusb300_request, queue);
  1020. if (req->req.length)
  1021. fusb300_wrcxf(ep, req);
  1022. if ((req->req.length - req->req.actual) < ep->ep.maxpacket)
  1023. done(ep, req, 0);
  1024. } else
  1025. fusb300_set_cxdone(fusb300);
  1026. }
  1027. static void fusb300_grp2_handler(void)
  1028. {
  1029. }
  1030. static void fusb300_grp3_handler(void)
  1031. {
  1032. }
  1033. static void fusb300_grp4_handler(void)
  1034. {
  1035. }
  1036. static void fusb300_grp5_handler(void)
  1037. {
  1038. }
  1039. static irqreturn_t fusb300_irq(int irq, void *_fusb300)
  1040. {
  1041. struct fusb300 *fusb300 = _fusb300;
  1042. u32 int_grp1 = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1);
  1043. u32 int_grp1_en = ioread32(fusb300->reg + FUSB300_OFFSET_IGER1);
  1044. u32 int_grp0 = ioread32(fusb300->reg + FUSB300_OFFSET_IGR0);
  1045. u32 int_grp0_en = ioread32(fusb300->reg + FUSB300_OFFSET_IGER0);
  1046. struct usb_ctrlrequest ctrl;
  1047. u8 in;
  1048. u32 reg;
  1049. int i;
  1050. spin_lock(&fusb300->lock);
  1051. int_grp1 &= int_grp1_en;
  1052. int_grp0 &= int_grp0_en;
  1053. if (int_grp1 & FUSB300_IGR1_WARM_RST_INT) {
  1054. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1055. FUSB300_IGR1_WARM_RST_INT);
  1056. printk(KERN_INFO"fusb300_warmreset\n");
  1057. fusb300_reset();
  1058. }
  1059. if (int_grp1 & FUSB300_IGR1_HOT_RST_INT) {
  1060. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1061. FUSB300_IGR1_HOT_RST_INT);
  1062. printk(KERN_INFO"fusb300_hotreset\n");
  1063. fusb300_reset();
  1064. }
  1065. if (int_grp1 & FUSB300_IGR1_USBRST_INT) {
  1066. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1067. FUSB300_IGR1_USBRST_INT);
  1068. fusb300_reset();
  1069. }
  1070. /* COMABT_INT has a highest priority */
  1071. if (int_grp1 & FUSB300_IGR1_CX_COMABT_INT) {
  1072. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1073. FUSB300_IGR1_CX_COMABT_INT);
  1074. printk(KERN_INFO"fusb300_ep0abt\n");
  1075. }
  1076. if (int_grp1 & FUSB300_IGR1_VBUS_CHG_INT) {
  1077. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1078. FUSB300_IGR1_VBUS_CHG_INT);
  1079. printk(KERN_INFO"fusb300_vbus_change\n");
  1080. }
  1081. if (int_grp1 & FUSB300_IGR1_U3_EXIT_FAIL_INT) {
  1082. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1083. FUSB300_IGR1_U3_EXIT_FAIL_INT);
  1084. }
  1085. if (int_grp1 & FUSB300_IGR1_U2_EXIT_FAIL_INT) {
  1086. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1087. FUSB300_IGR1_U2_EXIT_FAIL_INT);
  1088. }
  1089. if (int_grp1 & FUSB300_IGR1_U1_EXIT_FAIL_INT) {
  1090. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1091. FUSB300_IGR1_U1_EXIT_FAIL_INT);
  1092. }
  1093. if (int_grp1 & FUSB300_IGR1_U2_ENTRY_FAIL_INT) {
  1094. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1095. FUSB300_IGR1_U2_ENTRY_FAIL_INT);
  1096. }
  1097. if (int_grp1 & FUSB300_IGR1_U1_ENTRY_FAIL_INT) {
  1098. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1099. FUSB300_IGR1_U1_ENTRY_FAIL_INT);
  1100. }
  1101. if (int_grp1 & FUSB300_IGR1_U3_EXIT_INT) {
  1102. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1103. FUSB300_IGR1_U3_EXIT_INT);
  1104. printk(KERN_INFO "FUSB300_IGR1_U3_EXIT_INT\n");
  1105. }
  1106. if (int_grp1 & FUSB300_IGR1_U2_EXIT_INT) {
  1107. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1108. FUSB300_IGR1_U2_EXIT_INT);
  1109. printk(KERN_INFO "FUSB300_IGR1_U2_EXIT_INT\n");
  1110. }
  1111. if (int_grp1 & FUSB300_IGR1_U1_EXIT_INT) {
  1112. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1113. FUSB300_IGR1_U1_EXIT_INT);
  1114. printk(KERN_INFO "FUSB300_IGR1_U1_EXIT_INT\n");
  1115. }
  1116. if (int_grp1 & FUSB300_IGR1_U3_ENTRY_INT) {
  1117. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1118. FUSB300_IGR1_U3_ENTRY_INT);
  1119. printk(KERN_INFO "FUSB300_IGR1_U3_ENTRY_INT\n");
  1120. fusb300_enable_bit(fusb300, FUSB300_OFFSET_SSCR1,
  1121. FUSB300_SSCR1_GO_U3_DONE);
  1122. }
  1123. if (int_grp1 & FUSB300_IGR1_U2_ENTRY_INT) {
  1124. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1125. FUSB300_IGR1_U2_ENTRY_INT);
  1126. printk(KERN_INFO "FUSB300_IGR1_U2_ENTRY_INT\n");
  1127. }
  1128. if (int_grp1 & FUSB300_IGR1_U1_ENTRY_INT) {
  1129. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1130. FUSB300_IGR1_U1_ENTRY_INT);
  1131. printk(KERN_INFO "FUSB300_IGR1_U1_ENTRY_INT\n");
  1132. }
  1133. if (int_grp1 & FUSB300_IGR1_RESM_INT) {
  1134. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1135. FUSB300_IGR1_RESM_INT);
  1136. printk(KERN_INFO "fusb300_resume\n");
  1137. }
  1138. if (int_grp1 & FUSB300_IGR1_SUSP_INT) {
  1139. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1140. FUSB300_IGR1_SUSP_INT);
  1141. printk(KERN_INFO "fusb300_suspend\n");
  1142. }
  1143. if (int_grp1 & FUSB300_IGR1_HS_LPM_INT) {
  1144. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1145. FUSB300_IGR1_HS_LPM_INT);
  1146. printk(KERN_INFO "fusb300_HS_LPM_INT\n");
  1147. }
  1148. if (int_grp1 & FUSB300_IGR1_DEV_MODE_CHG_INT) {
  1149. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1150. FUSB300_IGR1_DEV_MODE_CHG_INT);
  1151. check_device_mode(fusb300);
  1152. }
  1153. if (int_grp1 & FUSB300_IGR1_CX_COMFAIL_INT) {
  1154. fusb300_set_cxstall(fusb300);
  1155. printk(KERN_INFO "fusb300_ep0fail\n");
  1156. }
  1157. if (int_grp1 & FUSB300_IGR1_CX_SETUP_INT) {
  1158. printk(KERN_INFO "fusb300_ep0setup\n");
  1159. if (setup_packet(fusb300, &ctrl)) {
  1160. spin_unlock(&fusb300->lock);
  1161. if (fusb300->driver->setup(&fusb300->gadget, &ctrl) < 0)
  1162. fusb300_set_cxstall(fusb300);
  1163. spin_lock(&fusb300->lock);
  1164. }
  1165. }
  1166. if (int_grp1 & FUSB300_IGR1_CX_CMDEND_INT)
  1167. printk(KERN_INFO "fusb300_cmdend\n");
  1168. if (int_grp1 & FUSB300_IGR1_CX_OUT_INT) {
  1169. printk(KERN_INFO "fusb300_cxout\n");
  1170. fusb300_ep0out(fusb300);
  1171. }
  1172. if (int_grp1 & FUSB300_IGR1_CX_IN_INT) {
  1173. printk(KERN_INFO "fusb300_cxin\n");
  1174. fusb300_ep0in(fusb300);
  1175. }
  1176. if (int_grp1 & FUSB300_IGR1_INTGRP5)
  1177. fusb300_grp5_handler();
  1178. if (int_grp1 & FUSB300_IGR1_INTGRP4)
  1179. fusb300_grp4_handler();
  1180. if (int_grp1 & FUSB300_IGR1_INTGRP3)
  1181. fusb300_grp3_handler();
  1182. if (int_grp1 & FUSB300_IGR1_INTGRP2)
  1183. fusb300_grp2_handler();
  1184. if (int_grp0) {
  1185. for (i = 1; i < FUSB300_MAX_NUM_EP; i++) {
  1186. if (int_grp0 & FUSB300_IGR0_EPn_FIFO_INT(i)) {
  1187. reg = ioread32(fusb300->reg +
  1188. FUSB300_OFFSET_EPSET1(i));
  1189. in = (reg & FUSB300_EPSET1_DIRIN) ? 1 : 0;
  1190. if (in)
  1191. in_ep_fifo_handler(fusb300->ep[i]);
  1192. else
  1193. out_ep_fifo_handler(fusb300->ep[i]);
  1194. }
  1195. }
  1196. }
  1197. spin_unlock(&fusb300->lock);
  1198. return IRQ_HANDLED;
  1199. }
  1200. static void fusb300_set_u2_timeout(struct fusb300 *fusb300,
  1201. u32 time)
  1202. {
  1203. u32 reg;
  1204. reg = ioread32(fusb300->reg + FUSB300_OFFSET_TT);
  1205. reg &= ~0xff;
  1206. reg |= FUSB300_SSCR2_U2TIMEOUT(time);
  1207. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_TT);
  1208. }
  1209. static void fusb300_set_u1_timeout(struct fusb300 *fusb300,
  1210. u32 time)
  1211. {
  1212. u32 reg;
  1213. reg = ioread32(fusb300->reg + FUSB300_OFFSET_TT);
  1214. reg &= ~(0xff << 8);
  1215. reg |= FUSB300_SSCR2_U1TIMEOUT(time);
  1216. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_TT);
  1217. }
  1218. static void init_controller(struct fusb300 *fusb300)
  1219. {
  1220. u32 reg;
  1221. u32 mask = 0;
  1222. u32 val = 0;
  1223. /* split on */
  1224. mask = val = FUSB300_AHBBCR_S0_SPLIT_ON | FUSB300_AHBBCR_S1_SPLIT_ON;
  1225. reg = ioread32(fusb300->reg + FUSB300_OFFSET_AHBCR);
  1226. reg &= ~mask;
  1227. reg |= val;
  1228. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_AHBCR);
  1229. /* enable high-speed LPM */
  1230. mask = val = FUSB300_HSCR_HS_LPM_PERMIT;
  1231. reg = ioread32(fusb300->reg + FUSB300_OFFSET_HSCR);
  1232. reg &= ~mask;
  1233. reg |= val;
  1234. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_HSCR);
  1235. /*set u1 u2 timmer*/
  1236. fusb300_set_u2_timeout(fusb300, 0xff);
  1237. fusb300_set_u1_timeout(fusb300, 0xff);
  1238. /* enable all grp1 interrupt */
  1239. iowrite32(0xcfffff9f, fusb300->reg + FUSB300_OFFSET_IGER1);
  1240. }
  1241. /*------------------------------------------------------------------------*/
  1242. static struct fusb300 *the_controller;
  1243. static int fusb300_udc_start(struct usb_gadget_driver *driver,
  1244. int (*bind)(struct usb_gadget *))
  1245. {
  1246. struct fusb300 *fusb300 = the_controller;
  1247. int retval;
  1248. if (!driver
  1249. || driver->speed < USB_SPEED_FULL
  1250. || !bind
  1251. || !driver->setup)
  1252. return -EINVAL;
  1253. if (!fusb300)
  1254. return -ENODEV;
  1255. if (fusb300->driver)
  1256. return -EBUSY;
  1257. /* hook up the driver */
  1258. driver->driver.bus = NULL;
  1259. fusb300->driver = driver;
  1260. fusb300->gadget.dev.driver = &driver->driver;
  1261. retval = device_add(&fusb300->gadget.dev);
  1262. if (retval) {
  1263. pr_err("device_add error (%d)\n", retval);
  1264. goto error;
  1265. }
  1266. retval = bind(&fusb300->gadget);
  1267. if (retval) {
  1268. pr_err("bind to driver error (%d)\n", retval);
  1269. device_del(&fusb300->gadget.dev);
  1270. goto error;
  1271. }
  1272. return 0;
  1273. error:
  1274. fusb300->driver = NULL;
  1275. fusb300->gadget.dev.driver = NULL;
  1276. return retval;
  1277. }
  1278. static int fusb300_udc_stop(struct usb_gadget_driver *driver)
  1279. {
  1280. struct fusb300 *fusb300 = the_controller;
  1281. if (driver != fusb300->driver || !driver->unbind)
  1282. return -EINVAL;
  1283. driver->unbind(&fusb300->gadget);
  1284. fusb300->gadget.dev.driver = NULL;
  1285. init_controller(fusb300);
  1286. device_del(&fusb300->gadget.dev);
  1287. fusb300->driver = NULL;
  1288. return 0;
  1289. }
  1290. /*--------------------------------------------------------------------------*/
  1291. static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active)
  1292. {
  1293. return 0;
  1294. }
  1295. static struct usb_gadget_ops fusb300_gadget_ops = {
  1296. .pullup = fusb300_udc_pullup,
  1297. .start = fusb300_udc_start,
  1298. .stop = fusb300_udc_stop,
  1299. };
  1300. static int __exit fusb300_remove(struct platform_device *pdev)
  1301. {
  1302. struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev);
  1303. usb_del_gadget_udc(&fusb300->gadget);
  1304. iounmap(fusb300->reg);
  1305. free_irq(platform_get_irq(pdev, 0), fusb300);
  1306. fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req);
  1307. kfree(fusb300);
  1308. return 0;
  1309. }
  1310. static int __init fusb300_probe(struct platform_device *pdev)
  1311. {
  1312. struct resource *res, *ires, *ires1;
  1313. void __iomem *reg = NULL;
  1314. struct fusb300 *fusb300 = NULL;
  1315. struct fusb300_ep *_ep[FUSB300_MAX_NUM_EP];
  1316. int ret = 0;
  1317. int i;
  1318. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1319. if (!res) {
  1320. ret = -ENODEV;
  1321. pr_err("platform_get_resource error.\n");
  1322. goto clean_up;
  1323. }
  1324. ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1325. if (!ires) {
  1326. ret = -ENODEV;
  1327. dev_err(&pdev->dev,
  1328. "platform_get_resource IORESOURCE_IRQ error.\n");
  1329. goto clean_up;
  1330. }
  1331. ires1 = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
  1332. if (!ires1) {
  1333. ret = -ENODEV;
  1334. dev_err(&pdev->dev,
  1335. "platform_get_resource IORESOURCE_IRQ 1 error.\n");
  1336. goto clean_up;
  1337. }
  1338. reg = ioremap(res->start, resource_size(res));
  1339. if (reg == NULL) {
  1340. ret = -ENOMEM;
  1341. pr_err("ioremap error.\n");
  1342. goto clean_up;
  1343. }
  1344. /* initialize udc */
  1345. fusb300 = kzalloc(sizeof(struct fusb300), GFP_KERNEL);
  1346. if (fusb300 == NULL) {
  1347. pr_err("kzalloc error\n");
  1348. goto clean_up;
  1349. }
  1350. for (i = 0; i < FUSB300_MAX_NUM_EP; i++) {
  1351. _ep[i] = kzalloc(sizeof(struct fusb300_ep), GFP_KERNEL);
  1352. if (_ep[i] == NULL) {
  1353. pr_err("_ep kzalloc error\n");
  1354. goto clean_up;
  1355. }
  1356. fusb300->ep[i] = _ep[i];
  1357. }
  1358. spin_lock_init(&fusb300->lock);
  1359. dev_set_drvdata(&pdev->dev, fusb300);
  1360. fusb300->gadget.ops = &fusb300_gadget_ops;
  1361. device_initialize(&fusb300->gadget.dev);
  1362. dev_set_name(&fusb300->gadget.dev, "gadget");
  1363. fusb300->gadget.is_dualspeed = 1;
  1364. fusb300->gadget.dev.parent = &pdev->dev;
  1365. fusb300->gadget.dev.dma_mask = pdev->dev.dma_mask;
  1366. fusb300->gadget.dev.release = pdev->dev.release;
  1367. fusb300->gadget.name = udc_name;
  1368. fusb300->reg = reg;
  1369. ret = request_irq(ires->start, fusb300_irq, IRQF_DISABLED | IRQF_SHARED,
  1370. udc_name, fusb300);
  1371. if (ret < 0) {
  1372. pr_err("request_irq error (%d)\n", ret);
  1373. goto clean_up;
  1374. }
  1375. ret = request_irq(ires1->start, fusb300_irq,
  1376. IRQF_DISABLED | IRQF_SHARED, udc_name, fusb300);
  1377. if (ret < 0) {
  1378. pr_err("request_irq1 error (%d)\n", ret);
  1379. goto clean_up;
  1380. }
  1381. INIT_LIST_HEAD(&fusb300->gadget.ep_list);
  1382. for (i = 0; i < FUSB300_MAX_NUM_EP ; i++) {
  1383. struct fusb300_ep *ep = fusb300->ep[i];
  1384. if (i != 0) {
  1385. INIT_LIST_HEAD(&fusb300->ep[i]->ep.ep_list);
  1386. list_add_tail(&fusb300->ep[i]->ep.ep_list,
  1387. &fusb300->gadget.ep_list);
  1388. }
  1389. ep->fusb300 = fusb300;
  1390. INIT_LIST_HEAD(&ep->queue);
  1391. ep->ep.name = fusb300_ep_name[i];
  1392. ep->ep.ops = &fusb300_ep_ops;
  1393. ep->ep.maxpacket = HS_BULK_MAX_PACKET_SIZE;
  1394. }
  1395. fusb300->ep[0]->ep.maxpacket = HS_CTL_MAX_PACKET_SIZE;
  1396. fusb300->ep[0]->epnum = 0;
  1397. fusb300->gadget.ep0 = &fusb300->ep[0]->ep;
  1398. INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list);
  1399. the_controller = fusb300;
  1400. fusb300->ep0_req = fusb300_alloc_request(&fusb300->ep[0]->ep,
  1401. GFP_KERNEL);
  1402. if (fusb300->ep0_req == NULL)
  1403. goto clean_up3;
  1404. init_controller(fusb300);
  1405. ret = usb_add_gadget_udc(&pdev->dev, &fusb300->gadget);
  1406. if (ret)
  1407. goto err_add_udc;
  1408. dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
  1409. return 0;
  1410. err_add_udc:
  1411. fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req);
  1412. clean_up3:
  1413. free_irq(ires->start, fusb300);
  1414. clean_up:
  1415. if (fusb300) {
  1416. if (fusb300->ep0_req)
  1417. fusb300_free_request(&fusb300->ep[0]->ep,
  1418. fusb300->ep0_req);
  1419. kfree(fusb300);
  1420. }
  1421. if (reg)
  1422. iounmap(reg);
  1423. return ret;
  1424. }
  1425. static struct platform_driver fusb300_driver = {
  1426. .remove = __exit_p(fusb300_remove),
  1427. .driver = {
  1428. .name = (char *) udc_name,
  1429. .owner = THIS_MODULE,
  1430. },
  1431. };
  1432. static int __init fusb300_udc_init(void)
  1433. {
  1434. return platform_driver_probe(&fusb300_driver, fusb300_probe);
  1435. }
  1436. module_init(fusb300_udc_init);
  1437. static void __exit fusb300_udc_cleanup(void)
  1438. {
  1439. platform_driver_unregister(&fusb300_driver);
  1440. }
  1441. module_exit(fusb300_udc_cleanup);