fusb300_udc.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745
  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 void fusb300_ep0_complete(struct usb_ep *ep,
  822. struct usb_request *req)
  823. {
  824. }
  825. static int setup_packet(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
  826. {
  827. u8 *p = (u8 *)ctrl;
  828. u8 ret = 0;
  829. u8 i = 0;
  830. fusb300_rdcxf(fusb300, p, 8);
  831. fusb300->ep0_dir = ctrl->bRequestType & USB_DIR_IN;
  832. fusb300->ep0_length = ctrl->wLength;
  833. /* check request */
  834. if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
  835. switch (ctrl->bRequest) {
  836. case USB_REQ_GET_STATUS:
  837. get_status(fusb300, ctrl);
  838. break;
  839. case USB_REQ_CLEAR_FEATURE:
  840. clear_feature(fusb300, ctrl);
  841. break;
  842. case USB_REQ_SET_FEATURE:
  843. set_feature(fusb300, ctrl);
  844. break;
  845. case USB_REQ_SET_ADDRESS:
  846. set_address(fusb300, ctrl);
  847. break;
  848. case USB_REQ_SET_CONFIGURATION:
  849. fusb300_enable_bit(fusb300, FUSB300_OFFSET_DAR,
  850. FUSB300_DAR_SETCONFG);
  851. /* clear sequence number */
  852. for (i = 1; i <= FUSB300_MAX_NUM_EP; i++)
  853. fusb300_clear_seqnum(fusb300, i);
  854. fusb300->reenum = 1;
  855. ret = 1;
  856. break;
  857. default:
  858. ret = 1;
  859. break;
  860. }
  861. } else
  862. ret = 1;
  863. return ret;
  864. }
  865. static void fusb300_set_ep_bycnt(struct fusb300_ep *ep, u32 bycnt)
  866. {
  867. struct fusb300 *fusb300 = ep->fusb300;
  868. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
  869. reg &= ~FUSB300_FFR_BYCNT;
  870. reg |= bycnt & FUSB300_FFR_BYCNT;
  871. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
  872. }
  873. static void done(struct fusb300_ep *ep, struct fusb300_request *req,
  874. int status)
  875. {
  876. list_del_init(&req->queue);
  877. /* don't modify queue heads during completion callback */
  878. if (ep->fusb300->gadget.speed == USB_SPEED_UNKNOWN)
  879. req->req.status = -ESHUTDOWN;
  880. else
  881. req->req.status = status;
  882. spin_unlock(&ep->fusb300->lock);
  883. req->req.complete(&ep->ep, &req->req);
  884. spin_lock(&ep->fusb300->lock);
  885. if (ep->epnum) {
  886. disable_fifo_int(ep);
  887. if (!list_empty(&ep->queue))
  888. enable_fifo_int(ep);
  889. } else
  890. fusb300_set_cxdone(ep->fusb300);
  891. }
  892. void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep,
  893. struct fusb300_request *req)
  894. {
  895. u32 value;
  896. u32 reg;
  897. /* wait SW owner */
  898. do {
  899. reg = ioread32(ep->fusb300->reg +
  900. FUSB300_OFFSET_EPPRD_W0(ep->epnum));
  901. reg &= FUSB300_EPPRD0_H;
  902. } while (reg);
  903. iowrite32((u32) req->req.buf, ep->fusb300->reg +
  904. FUSB300_OFFSET_EPPRD_W1(ep->epnum));
  905. value = FUSB300_EPPRD0_BTC(req->req.length) | FUSB300_EPPRD0_H |
  906. FUSB300_EPPRD0_F | FUSB300_EPPRD0_L | FUSB300_EPPRD0_I;
  907. iowrite32(value, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W0(ep->epnum));
  908. iowrite32(0x0, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W2(ep->epnum));
  909. fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_EPPRDRDY,
  910. FUSB300_EPPRDR_EP_PRD_RDY(ep->epnum));
  911. }
  912. static void fusb300_wait_idma_finished(struct fusb300_ep *ep)
  913. {
  914. u32 reg;
  915. do {
  916. reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGR1);
  917. if ((reg & FUSB300_IGR1_VBUS_CHG_INT) ||
  918. (reg & FUSB300_IGR1_WARM_RST_INT) ||
  919. (reg & FUSB300_IGR1_HOT_RST_INT) ||
  920. (reg & FUSB300_IGR1_USBRST_INT)
  921. )
  922. goto IDMA_RESET;
  923. reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGR0);
  924. reg &= FUSB300_IGR0_EPn_PRD_INT(ep->epnum);
  925. } while (!reg);
  926. fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGR0,
  927. FUSB300_IGR0_EPn_PRD_INT(ep->epnum));
  928. IDMA_RESET:
  929. fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGER0,
  930. FUSB300_IGER0_EEPn_PRD_INT(ep->epnum));
  931. }
  932. static void fusb300_set_idma(struct fusb300_ep *ep,
  933. struct fusb300_request *req)
  934. {
  935. dma_addr_t d;
  936. u8 *tmp = NULL;
  937. d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE);
  938. if (dma_mapping_error(NULL, d)) {
  939. kfree(req->req.buf);
  940. printk(KERN_DEBUG "dma_mapping_error\n");
  941. }
  942. dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE);
  943. fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0,
  944. FUSB300_IGER0_EEPn_PRD_INT(ep->epnum));
  945. tmp = req->req.buf;
  946. req->req.buf = (u8 *)d;
  947. fusb300_fill_idma_prdtbl(ep, req);
  948. /* check idma is done */
  949. fusb300_wait_idma_finished(ep);
  950. req->req.buf = tmp;
  951. if (d)
  952. dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE);
  953. }
  954. static void in_ep_fifo_handler(struct fusb300_ep *ep)
  955. {
  956. struct fusb300_request *req = list_entry(ep->queue.next,
  957. struct fusb300_request, queue);
  958. if (req->req.length) {
  959. #if 0
  960. fusb300_set_ep_bycnt(ep, req->req.length);
  961. fusb300_wrfifo(ep, req);
  962. #else
  963. fusb300_set_idma(ep, req);
  964. #endif
  965. }
  966. done(ep, req, 0);
  967. }
  968. static void out_ep_fifo_handler(struct fusb300_ep *ep)
  969. {
  970. struct fusb300 *fusb300 = ep->fusb300;
  971. struct fusb300_request *req = list_entry(ep->queue.next,
  972. struct fusb300_request, queue);
  973. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
  974. u32 length = reg & FUSB300_FFR_BYCNT;
  975. fusb300_rdfifo(ep, req, length);
  976. /* finish out transfer */
  977. if ((req->req.length == req->req.actual) || (length < ep->ep.maxpacket))
  978. done(ep, req, 0);
  979. }
  980. static void check_device_mode(struct fusb300 *fusb300)
  981. {
  982. u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_GCR);
  983. switch (reg & FUSB300_GCR_DEVEN_MSK) {
  984. case FUSB300_GCR_DEVEN_SS:
  985. fusb300->gadget.speed = USB_SPEED_SUPER;
  986. break;
  987. case FUSB300_GCR_DEVEN_HS:
  988. fusb300->gadget.speed = USB_SPEED_HIGH;
  989. break;
  990. case FUSB300_GCR_DEVEN_FS:
  991. fusb300->gadget.speed = USB_SPEED_FULL;
  992. break;
  993. default:
  994. fusb300->gadget.speed = USB_SPEED_UNKNOWN;
  995. break;
  996. }
  997. printk(KERN_INFO "dev_mode = %d\n", (reg & FUSB300_GCR_DEVEN_MSK));
  998. }
  999. static void fusb300_ep0out(struct fusb300 *fusb300)
  1000. {
  1001. struct fusb300_ep *ep = fusb300->ep[0];
  1002. u32 reg;
  1003. if (!list_empty(&ep->queue)) {
  1004. struct fusb300_request *req;
  1005. req = list_first_entry(&ep->queue,
  1006. struct fusb300_request, queue);
  1007. if (req->req.length)
  1008. fusb300_rdcxf(ep->fusb300, req->req.buf,
  1009. req->req.length);
  1010. done(ep, req, 0);
  1011. reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGER1);
  1012. reg &= ~FUSB300_IGER1_CX_OUT_INT;
  1013. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_IGER1);
  1014. } else
  1015. pr_err("%s : empty queue\n", __func__);
  1016. }
  1017. static void fusb300_ep0in(struct fusb300 *fusb300)
  1018. {
  1019. struct fusb300_request *req;
  1020. struct fusb300_ep *ep = fusb300->ep[0];
  1021. if ((!list_empty(&ep->queue)) && (fusb300->ep0_dir)) {
  1022. req = list_entry(ep->queue.next,
  1023. struct fusb300_request, queue);
  1024. if (req->req.length)
  1025. fusb300_wrcxf(ep, req);
  1026. if ((req->req.length - req->req.actual) < ep->ep.maxpacket)
  1027. done(ep, req, 0);
  1028. } else
  1029. fusb300_set_cxdone(fusb300);
  1030. }
  1031. static void fusb300_grp2_handler(void)
  1032. {
  1033. }
  1034. static void fusb300_grp3_handler(void)
  1035. {
  1036. }
  1037. static void fusb300_grp4_handler(void)
  1038. {
  1039. }
  1040. static void fusb300_grp5_handler(void)
  1041. {
  1042. }
  1043. static irqreturn_t fusb300_irq(int irq, void *_fusb300)
  1044. {
  1045. struct fusb300 *fusb300 = _fusb300;
  1046. u32 int_grp1 = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1);
  1047. u32 int_grp1_en = ioread32(fusb300->reg + FUSB300_OFFSET_IGER1);
  1048. u32 int_grp0 = ioread32(fusb300->reg + FUSB300_OFFSET_IGR0);
  1049. u32 int_grp0_en = ioread32(fusb300->reg + FUSB300_OFFSET_IGER0);
  1050. struct usb_ctrlrequest ctrl;
  1051. u8 in;
  1052. u32 reg;
  1053. int i;
  1054. spin_lock(&fusb300->lock);
  1055. int_grp1 &= int_grp1_en;
  1056. int_grp0 &= int_grp0_en;
  1057. if (int_grp1 & FUSB300_IGR1_WARM_RST_INT) {
  1058. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1059. FUSB300_IGR1_WARM_RST_INT);
  1060. printk(KERN_INFO"fusb300_warmreset\n");
  1061. fusb300_reset();
  1062. }
  1063. if (int_grp1 & FUSB300_IGR1_HOT_RST_INT) {
  1064. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1065. FUSB300_IGR1_HOT_RST_INT);
  1066. printk(KERN_INFO"fusb300_hotreset\n");
  1067. fusb300_reset();
  1068. }
  1069. if (int_grp1 & FUSB300_IGR1_USBRST_INT) {
  1070. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1071. FUSB300_IGR1_USBRST_INT);
  1072. fusb300_reset();
  1073. }
  1074. /* COMABT_INT has a highest priority */
  1075. if (int_grp1 & FUSB300_IGR1_CX_COMABT_INT) {
  1076. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1077. FUSB300_IGR1_CX_COMABT_INT);
  1078. printk(KERN_INFO"fusb300_ep0abt\n");
  1079. }
  1080. if (int_grp1 & FUSB300_IGR1_VBUS_CHG_INT) {
  1081. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1082. FUSB300_IGR1_VBUS_CHG_INT);
  1083. printk(KERN_INFO"fusb300_vbus_change\n");
  1084. }
  1085. if (int_grp1 & FUSB300_IGR1_U3_EXIT_FAIL_INT) {
  1086. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1087. FUSB300_IGR1_U3_EXIT_FAIL_INT);
  1088. }
  1089. if (int_grp1 & FUSB300_IGR1_U2_EXIT_FAIL_INT) {
  1090. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1091. FUSB300_IGR1_U2_EXIT_FAIL_INT);
  1092. }
  1093. if (int_grp1 & FUSB300_IGR1_U1_EXIT_FAIL_INT) {
  1094. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1095. FUSB300_IGR1_U1_EXIT_FAIL_INT);
  1096. }
  1097. if (int_grp1 & FUSB300_IGR1_U2_ENTRY_FAIL_INT) {
  1098. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1099. FUSB300_IGR1_U2_ENTRY_FAIL_INT);
  1100. }
  1101. if (int_grp1 & FUSB300_IGR1_U1_ENTRY_FAIL_INT) {
  1102. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1103. FUSB300_IGR1_U1_ENTRY_FAIL_INT);
  1104. }
  1105. if (int_grp1 & FUSB300_IGR1_U3_EXIT_INT) {
  1106. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1107. FUSB300_IGR1_U3_EXIT_INT);
  1108. printk(KERN_INFO "FUSB300_IGR1_U3_EXIT_INT\n");
  1109. }
  1110. if (int_grp1 & FUSB300_IGR1_U2_EXIT_INT) {
  1111. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1112. FUSB300_IGR1_U2_EXIT_INT);
  1113. printk(KERN_INFO "FUSB300_IGR1_U2_EXIT_INT\n");
  1114. }
  1115. if (int_grp1 & FUSB300_IGR1_U1_EXIT_INT) {
  1116. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1117. FUSB300_IGR1_U1_EXIT_INT);
  1118. printk(KERN_INFO "FUSB300_IGR1_U1_EXIT_INT\n");
  1119. }
  1120. if (int_grp1 & FUSB300_IGR1_U3_ENTRY_INT) {
  1121. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1122. FUSB300_IGR1_U3_ENTRY_INT);
  1123. printk(KERN_INFO "FUSB300_IGR1_U3_ENTRY_INT\n");
  1124. fusb300_enable_bit(fusb300, FUSB300_OFFSET_SSCR1,
  1125. FUSB300_SSCR1_GO_U3_DONE);
  1126. }
  1127. if (int_grp1 & FUSB300_IGR1_U2_ENTRY_INT) {
  1128. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1129. FUSB300_IGR1_U2_ENTRY_INT);
  1130. printk(KERN_INFO "FUSB300_IGR1_U2_ENTRY_INT\n");
  1131. }
  1132. if (int_grp1 & FUSB300_IGR1_U1_ENTRY_INT) {
  1133. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1134. FUSB300_IGR1_U1_ENTRY_INT);
  1135. printk(KERN_INFO "FUSB300_IGR1_U1_ENTRY_INT\n");
  1136. }
  1137. if (int_grp1 & FUSB300_IGR1_RESM_INT) {
  1138. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1139. FUSB300_IGR1_RESM_INT);
  1140. printk(KERN_INFO "fusb300_resume\n");
  1141. }
  1142. if (int_grp1 & FUSB300_IGR1_SUSP_INT) {
  1143. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1144. FUSB300_IGR1_SUSP_INT);
  1145. printk(KERN_INFO "fusb300_suspend\n");
  1146. }
  1147. if (int_grp1 & FUSB300_IGR1_HS_LPM_INT) {
  1148. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1149. FUSB300_IGR1_HS_LPM_INT);
  1150. printk(KERN_INFO "fusb300_HS_LPM_INT\n");
  1151. }
  1152. if (int_grp1 & FUSB300_IGR1_DEV_MODE_CHG_INT) {
  1153. fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
  1154. FUSB300_IGR1_DEV_MODE_CHG_INT);
  1155. check_device_mode(fusb300);
  1156. }
  1157. if (int_grp1 & FUSB300_IGR1_CX_COMFAIL_INT) {
  1158. fusb300_set_cxstall(fusb300);
  1159. printk(KERN_INFO "fusb300_ep0fail\n");
  1160. }
  1161. if (int_grp1 & FUSB300_IGR1_CX_SETUP_INT) {
  1162. printk(KERN_INFO "fusb300_ep0setup\n");
  1163. if (setup_packet(fusb300, &ctrl)) {
  1164. spin_unlock(&fusb300->lock);
  1165. if (fusb300->driver->setup(&fusb300->gadget, &ctrl) < 0)
  1166. fusb300_set_cxstall(fusb300);
  1167. spin_lock(&fusb300->lock);
  1168. }
  1169. }
  1170. if (int_grp1 & FUSB300_IGR1_CX_CMDEND_INT)
  1171. printk(KERN_INFO "fusb300_cmdend\n");
  1172. if (int_grp1 & FUSB300_IGR1_CX_OUT_INT) {
  1173. printk(KERN_INFO "fusb300_cxout\n");
  1174. fusb300_ep0out(fusb300);
  1175. }
  1176. if (int_grp1 & FUSB300_IGR1_CX_IN_INT) {
  1177. printk(KERN_INFO "fusb300_cxin\n");
  1178. fusb300_ep0in(fusb300);
  1179. }
  1180. if (int_grp1 & FUSB300_IGR1_INTGRP5)
  1181. fusb300_grp5_handler();
  1182. if (int_grp1 & FUSB300_IGR1_INTGRP4)
  1183. fusb300_grp4_handler();
  1184. if (int_grp1 & FUSB300_IGR1_INTGRP3)
  1185. fusb300_grp3_handler();
  1186. if (int_grp1 & FUSB300_IGR1_INTGRP2)
  1187. fusb300_grp2_handler();
  1188. if (int_grp0) {
  1189. for (i = 1; i < FUSB300_MAX_NUM_EP; i++) {
  1190. if (int_grp0 & FUSB300_IGR0_EPn_FIFO_INT(i)) {
  1191. reg = ioread32(fusb300->reg +
  1192. FUSB300_OFFSET_EPSET1(i));
  1193. in = (reg & FUSB300_EPSET1_DIRIN) ? 1 : 0;
  1194. if (in)
  1195. in_ep_fifo_handler(fusb300->ep[i]);
  1196. else
  1197. out_ep_fifo_handler(fusb300->ep[i]);
  1198. }
  1199. }
  1200. }
  1201. spin_unlock(&fusb300->lock);
  1202. return IRQ_HANDLED;
  1203. }
  1204. static void fusb300_set_u2_timeout(struct fusb300 *fusb300,
  1205. u32 time)
  1206. {
  1207. u32 reg;
  1208. reg = ioread32(fusb300->reg + FUSB300_OFFSET_TT);
  1209. reg &= ~0xff;
  1210. reg |= FUSB300_SSCR2_U2TIMEOUT(time);
  1211. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_TT);
  1212. }
  1213. static void fusb300_set_u1_timeout(struct fusb300 *fusb300,
  1214. u32 time)
  1215. {
  1216. u32 reg;
  1217. reg = ioread32(fusb300->reg + FUSB300_OFFSET_TT);
  1218. reg &= ~(0xff << 8);
  1219. reg |= FUSB300_SSCR2_U1TIMEOUT(time);
  1220. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_TT);
  1221. }
  1222. static void init_controller(struct fusb300 *fusb300)
  1223. {
  1224. u32 reg;
  1225. u32 mask = 0;
  1226. u32 val = 0;
  1227. /* split on */
  1228. mask = val = FUSB300_AHBBCR_S0_SPLIT_ON | FUSB300_AHBBCR_S1_SPLIT_ON;
  1229. reg = ioread32(fusb300->reg + FUSB300_OFFSET_AHBCR);
  1230. reg &= ~mask;
  1231. reg |= val;
  1232. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_AHBCR);
  1233. /* enable high-speed LPM */
  1234. mask = val = FUSB300_HSCR_HS_LPM_PERMIT;
  1235. reg = ioread32(fusb300->reg + FUSB300_OFFSET_HSCR);
  1236. reg &= ~mask;
  1237. reg |= val;
  1238. iowrite32(reg, fusb300->reg + FUSB300_OFFSET_HSCR);
  1239. /*set u1 u2 timmer*/
  1240. fusb300_set_u2_timeout(fusb300, 0xff);
  1241. fusb300_set_u1_timeout(fusb300, 0xff);
  1242. /* enable all grp1 interrupt */
  1243. iowrite32(0xcfffff9f, fusb300->reg + FUSB300_OFFSET_IGER1);
  1244. }
  1245. /*------------------------------------------------------------------------*/
  1246. static struct fusb300 *the_controller;
  1247. int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
  1248. int (*bind)(struct usb_gadget *))
  1249. {
  1250. struct fusb300 *fusb300 = the_controller;
  1251. int retval;
  1252. if (!driver
  1253. || driver->speed < USB_SPEED_FULL
  1254. || !bind
  1255. || !driver->setup)
  1256. return -EINVAL;
  1257. if (!fusb300)
  1258. return -ENODEV;
  1259. if (fusb300->driver)
  1260. return -EBUSY;
  1261. /* hook up the driver */
  1262. driver->driver.bus = NULL;
  1263. fusb300->driver = driver;
  1264. fusb300->gadget.dev.driver = &driver->driver;
  1265. retval = device_add(&fusb300->gadget.dev);
  1266. if (retval) {
  1267. pr_err("device_add error (%d)\n", retval);
  1268. goto error;
  1269. }
  1270. retval = bind(&fusb300->gadget);
  1271. if (retval) {
  1272. pr_err("bind to driver error (%d)\n", retval);
  1273. device_del(&fusb300->gadget.dev);
  1274. goto error;
  1275. }
  1276. return 0;
  1277. error:
  1278. fusb300->driver = NULL;
  1279. fusb300->gadget.dev.driver = NULL;
  1280. return retval;
  1281. }
  1282. EXPORT_SYMBOL(usb_gadget_probe_driver);
  1283. int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  1284. {
  1285. struct fusb300 *fusb300 = the_controller;
  1286. if (driver != fusb300->driver || !driver->unbind)
  1287. return -EINVAL;
  1288. driver->unbind(&fusb300->gadget);
  1289. fusb300->gadget.dev.driver = NULL;
  1290. init_controller(fusb300);
  1291. device_del(&fusb300->gadget.dev);
  1292. fusb300->driver = NULL;
  1293. return 0;
  1294. }
  1295. EXPORT_SYMBOL(usb_gadget_unregister_driver);
  1296. /*--------------------------------------------------------------------------*/
  1297. static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active)
  1298. {
  1299. return 0;
  1300. }
  1301. static struct usb_gadget_ops fusb300_gadget_ops = {
  1302. .pullup = fusb300_udc_pullup,
  1303. };
  1304. static int __exit fusb300_remove(struct platform_device *pdev)
  1305. {
  1306. struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev);
  1307. iounmap(fusb300->reg);
  1308. free_irq(platform_get_irq(pdev, 0), fusb300);
  1309. fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req);
  1310. kfree(fusb300);
  1311. return 0;
  1312. }
  1313. static int __init fusb300_probe(struct platform_device *pdev)
  1314. {
  1315. struct resource *res, *ires, *ires1;
  1316. void __iomem *reg = NULL;
  1317. struct fusb300 *fusb300 = NULL;
  1318. struct fusb300_ep *_ep[FUSB300_MAX_NUM_EP];
  1319. int ret = 0;
  1320. int i;
  1321. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1322. if (!res) {
  1323. ret = -ENODEV;
  1324. pr_err("platform_get_resource error.\n");
  1325. goto clean_up;
  1326. }
  1327. ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1328. if (!ires) {
  1329. ret = -ENODEV;
  1330. dev_err(&pdev->dev,
  1331. "platform_get_resource IORESOURCE_IRQ error.\n");
  1332. goto clean_up;
  1333. }
  1334. ires1 = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
  1335. if (!ires1) {
  1336. ret = -ENODEV;
  1337. dev_err(&pdev->dev,
  1338. "platform_get_resource IORESOURCE_IRQ 1 error.\n");
  1339. goto clean_up;
  1340. }
  1341. reg = ioremap(res->start, resource_size(res));
  1342. if (reg == NULL) {
  1343. ret = -ENOMEM;
  1344. pr_err("ioremap error.\n");
  1345. goto clean_up;
  1346. }
  1347. /* initialize udc */
  1348. fusb300 = kzalloc(sizeof(struct fusb300), GFP_KERNEL);
  1349. if (fusb300 == NULL) {
  1350. pr_err("kzalloc error\n");
  1351. goto clean_up;
  1352. }
  1353. for (i = 0; i < FUSB300_MAX_NUM_EP; i++) {
  1354. _ep[i] = kzalloc(sizeof(struct fusb300_ep), GFP_KERNEL);
  1355. if (_ep[i] == NULL) {
  1356. pr_err("_ep kzalloc error\n");
  1357. goto clean_up;
  1358. }
  1359. fusb300->ep[i] = _ep[i];
  1360. }
  1361. spin_lock_init(&fusb300->lock);
  1362. dev_set_drvdata(&pdev->dev, fusb300);
  1363. fusb300->gadget.ops = &fusb300_gadget_ops;
  1364. device_initialize(&fusb300->gadget.dev);
  1365. dev_set_name(&fusb300->gadget.dev, "gadget");
  1366. fusb300->gadget.is_dualspeed = 1;
  1367. fusb300->gadget.dev.parent = &pdev->dev;
  1368. fusb300->gadget.dev.dma_mask = pdev->dev.dma_mask;
  1369. fusb300->gadget.dev.release = pdev->dev.release;
  1370. fusb300->gadget.name = udc_name;
  1371. fusb300->reg = reg;
  1372. ret = request_irq(ires->start, fusb300_irq, IRQF_DISABLED | IRQF_SHARED,
  1373. udc_name, fusb300);
  1374. if (ret < 0) {
  1375. pr_err("request_irq error (%d)\n", ret);
  1376. goto clean_up;
  1377. }
  1378. ret = request_irq(ires1->start, fusb300_irq,
  1379. IRQF_DISABLED | IRQF_SHARED, udc_name, fusb300);
  1380. if (ret < 0) {
  1381. pr_err("request_irq1 error (%d)\n", ret);
  1382. goto clean_up;
  1383. }
  1384. INIT_LIST_HEAD(&fusb300->gadget.ep_list);
  1385. for (i = 0; i < FUSB300_MAX_NUM_EP ; i++) {
  1386. struct fusb300_ep *ep = fusb300->ep[i];
  1387. if (i != 0) {
  1388. INIT_LIST_HEAD(&fusb300->ep[i]->ep.ep_list);
  1389. list_add_tail(&fusb300->ep[i]->ep.ep_list,
  1390. &fusb300->gadget.ep_list);
  1391. }
  1392. ep->fusb300 = fusb300;
  1393. INIT_LIST_HEAD(&ep->queue);
  1394. ep->ep.name = fusb300_ep_name[i];
  1395. ep->ep.ops = &fusb300_ep_ops;
  1396. ep->ep.maxpacket = HS_BULK_MAX_PACKET_SIZE;
  1397. }
  1398. fusb300->ep[0]->ep.maxpacket = HS_CTL_MAX_PACKET_SIZE;
  1399. fusb300->ep[0]->epnum = 0;
  1400. fusb300->gadget.ep0 = &fusb300->ep[0]->ep;
  1401. INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list);
  1402. the_controller = fusb300;
  1403. fusb300->ep0_req = fusb300_alloc_request(&fusb300->ep[0]->ep,
  1404. GFP_KERNEL);
  1405. if (fusb300->ep0_req == NULL)
  1406. goto clean_up3;
  1407. init_controller(fusb300);
  1408. dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
  1409. return 0;
  1410. clean_up3:
  1411. free_irq(ires->start, fusb300);
  1412. clean_up:
  1413. if (fusb300) {
  1414. if (fusb300->ep0_req)
  1415. fusb300_free_request(&fusb300->ep[0]->ep,
  1416. fusb300->ep0_req);
  1417. kfree(fusb300);
  1418. }
  1419. if (reg)
  1420. iounmap(reg);
  1421. return ret;
  1422. }
  1423. static struct platform_driver fusb300_driver = {
  1424. .remove = __exit_p(fusb300_remove),
  1425. .driver = {
  1426. .name = (char *) udc_name,
  1427. .owner = THIS_MODULE,
  1428. },
  1429. };
  1430. static int __init fusb300_udc_init(void)
  1431. {
  1432. return platform_driver_probe(&fusb300_driver, fusb300_probe);
  1433. }
  1434. module_init(fusb300_udc_init);
  1435. static void __exit fusb300_udc_cleanup(void)
  1436. {
  1437. platform_driver_unregister(&fusb300_driver);
  1438. }
  1439. module_exit(fusb300_udc_cleanup);