fusb300_udc.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  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. int usb_gadget_probe_driver(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. EXPORT_SYMBOL(usb_gadget_probe_driver);
  1279. int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  1280. {
  1281. struct fusb300 *fusb300 = the_controller;
  1282. if (driver != fusb300->driver || !driver->unbind)
  1283. return -EINVAL;
  1284. driver->unbind(&fusb300->gadget);
  1285. fusb300->gadget.dev.driver = NULL;
  1286. init_controller(fusb300);
  1287. device_del(&fusb300->gadget.dev);
  1288. fusb300->driver = NULL;
  1289. return 0;
  1290. }
  1291. EXPORT_SYMBOL(usb_gadget_unregister_driver);
  1292. /*--------------------------------------------------------------------------*/
  1293. static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active)
  1294. {
  1295. return 0;
  1296. }
  1297. static struct usb_gadget_ops fusb300_gadget_ops = {
  1298. .pullup = fusb300_udc_pullup,
  1299. };
  1300. static int __exit fusb300_remove(struct platform_device *pdev)
  1301. {
  1302. struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev);
  1303. iounmap(fusb300->reg);
  1304. free_irq(platform_get_irq(pdev, 0), fusb300);
  1305. fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req);
  1306. kfree(fusb300);
  1307. return 0;
  1308. }
  1309. static int __init fusb300_probe(struct platform_device *pdev)
  1310. {
  1311. struct resource *res, *ires, *ires1;
  1312. void __iomem *reg = NULL;
  1313. struct fusb300 *fusb300 = NULL;
  1314. struct fusb300_ep *_ep[FUSB300_MAX_NUM_EP];
  1315. int ret = 0;
  1316. int i;
  1317. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1318. if (!res) {
  1319. ret = -ENODEV;
  1320. pr_err("platform_get_resource error.\n");
  1321. goto clean_up;
  1322. }
  1323. ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1324. if (!ires) {
  1325. ret = -ENODEV;
  1326. dev_err(&pdev->dev,
  1327. "platform_get_resource IORESOURCE_IRQ error.\n");
  1328. goto clean_up;
  1329. }
  1330. ires1 = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
  1331. if (!ires1) {
  1332. ret = -ENODEV;
  1333. dev_err(&pdev->dev,
  1334. "platform_get_resource IORESOURCE_IRQ 1 error.\n");
  1335. goto clean_up;
  1336. }
  1337. reg = ioremap(res->start, resource_size(res));
  1338. if (reg == NULL) {
  1339. ret = -ENOMEM;
  1340. pr_err("ioremap error.\n");
  1341. goto clean_up;
  1342. }
  1343. /* initialize udc */
  1344. fusb300 = kzalloc(sizeof(struct fusb300), GFP_KERNEL);
  1345. if (fusb300 == NULL) {
  1346. pr_err("kzalloc error\n");
  1347. goto clean_up;
  1348. }
  1349. for (i = 0; i < FUSB300_MAX_NUM_EP; i++) {
  1350. _ep[i] = kzalloc(sizeof(struct fusb300_ep), GFP_KERNEL);
  1351. if (_ep[i] == NULL) {
  1352. pr_err("_ep kzalloc error\n");
  1353. goto clean_up;
  1354. }
  1355. fusb300->ep[i] = _ep[i];
  1356. }
  1357. spin_lock_init(&fusb300->lock);
  1358. dev_set_drvdata(&pdev->dev, fusb300);
  1359. fusb300->gadget.ops = &fusb300_gadget_ops;
  1360. device_initialize(&fusb300->gadget.dev);
  1361. dev_set_name(&fusb300->gadget.dev, "gadget");
  1362. fusb300->gadget.is_dualspeed = 1;
  1363. fusb300->gadget.dev.parent = &pdev->dev;
  1364. fusb300->gadget.dev.dma_mask = pdev->dev.dma_mask;
  1365. fusb300->gadget.dev.release = pdev->dev.release;
  1366. fusb300->gadget.name = udc_name;
  1367. fusb300->reg = reg;
  1368. ret = request_irq(ires->start, fusb300_irq, IRQF_DISABLED | IRQF_SHARED,
  1369. udc_name, fusb300);
  1370. if (ret < 0) {
  1371. pr_err("request_irq error (%d)\n", ret);
  1372. goto clean_up;
  1373. }
  1374. ret = request_irq(ires1->start, fusb300_irq,
  1375. IRQF_DISABLED | IRQF_SHARED, udc_name, fusb300);
  1376. if (ret < 0) {
  1377. pr_err("request_irq1 error (%d)\n", ret);
  1378. goto clean_up;
  1379. }
  1380. INIT_LIST_HEAD(&fusb300->gadget.ep_list);
  1381. for (i = 0; i < FUSB300_MAX_NUM_EP ; i++) {
  1382. struct fusb300_ep *ep = fusb300->ep[i];
  1383. if (i != 0) {
  1384. INIT_LIST_HEAD(&fusb300->ep[i]->ep.ep_list);
  1385. list_add_tail(&fusb300->ep[i]->ep.ep_list,
  1386. &fusb300->gadget.ep_list);
  1387. }
  1388. ep->fusb300 = fusb300;
  1389. INIT_LIST_HEAD(&ep->queue);
  1390. ep->ep.name = fusb300_ep_name[i];
  1391. ep->ep.ops = &fusb300_ep_ops;
  1392. ep->ep.maxpacket = HS_BULK_MAX_PACKET_SIZE;
  1393. }
  1394. fusb300->ep[0]->ep.maxpacket = HS_CTL_MAX_PACKET_SIZE;
  1395. fusb300->ep[0]->epnum = 0;
  1396. fusb300->gadget.ep0 = &fusb300->ep[0]->ep;
  1397. INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list);
  1398. the_controller = fusb300;
  1399. fusb300->ep0_req = fusb300_alloc_request(&fusb300->ep[0]->ep,
  1400. GFP_KERNEL);
  1401. if (fusb300->ep0_req == NULL)
  1402. goto clean_up3;
  1403. init_controller(fusb300);
  1404. dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
  1405. return 0;
  1406. clean_up3:
  1407. free_irq(ires->start, fusb300);
  1408. clean_up:
  1409. if (fusb300) {
  1410. if (fusb300->ep0_req)
  1411. fusb300_free_request(&fusb300->ep[0]->ep,
  1412. fusb300->ep0_req);
  1413. kfree(fusb300);
  1414. }
  1415. if (reg)
  1416. iounmap(reg);
  1417. return ret;
  1418. }
  1419. static struct platform_driver fusb300_driver = {
  1420. .remove = __exit_p(fusb300_remove),
  1421. .driver = {
  1422. .name = (char *) udc_name,
  1423. .owner = THIS_MODULE,
  1424. },
  1425. };
  1426. static int __init fusb300_udc_init(void)
  1427. {
  1428. return platform_driver_probe(&fusb300_driver, fusb300_probe);
  1429. }
  1430. module_init(fusb300_udc_init);
  1431. static void __exit fusb300_udc_cleanup(void)
  1432. {
  1433. platform_driver_unregister(&fusb300_driver);
  1434. }
  1435. module_exit(fusb300_udc_cleanup);