r8a66597-hcd.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346
  1. /*
  2. * R8A66597 HCD (Host Controller Driver)
  3. *
  4. * Copyright (C) 2006-2007 Renesas Solutions Corp.
  5. * Portions Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
  6. * Portions Copyright (C) 2004-2005 David Brownell
  7. * Portions Copyright (C) 1999 Roman Weissgaerber
  8. *
  9. * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; version 2 of the License.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/kernel.h>
  27. #include <linux/sched.h>
  28. #include <linux/smp_lock.h>
  29. #include <linux/errno.h>
  30. #include <linux/init.h>
  31. #include <linux/timer.h>
  32. #include <linux/delay.h>
  33. #include <linux/list.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/usb.h>
  36. #include <linux/platform_device.h>
  37. #include <linux/io.h>
  38. #include <linux/irq.h>
  39. #include "../core/hcd.h"
  40. #include "r8a66597.h"
  41. MODULE_DESCRIPTION("R8A66597 USB Host Controller Driver");
  42. MODULE_LICENSE("GPL");
  43. MODULE_AUTHOR("Yoshihiro Shimoda");
  44. MODULE_ALIAS("platform:r8a66597_hcd");
  45. #define DRIVER_VERSION "10 Apr 2008"
  46. static const char hcd_name[] = "r8a66597_hcd";
  47. /* module parameters */
  48. #if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
  49. static unsigned short clock = XTAL12;
  50. module_param(clock, ushort, 0644);
  51. MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 "
  52. "(default=0)");
  53. #endif
  54. static unsigned short vif = LDRV;
  55. module_param(vif, ushort, 0644);
  56. MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0(default=32768)");
  57. static unsigned short endian;
  58. module_param(endian, ushort, 0644);
  59. MODULE_PARM_DESC(endian, "data endian: big=256, little=0 (default=0)");
  60. static unsigned short irq_sense = INTL;
  61. module_param(irq_sense, ushort, 0644);
  62. MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=32, falling edge=0 "
  63. "(default=32)");
  64. static void packet_write(struct r8a66597 *r8a66597, u16 pipenum);
  65. static int r8a66597_get_frame(struct usb_hcd *hcd);
  66. /* this function must be called with interrupt disabled */
  67. static void enable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum,
  68. unsigned long reg)
  69. {
  70. u16 tmp;
  71. tmp = r8a66597_read(r8a66597, INTENB0);
  72. r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0);
  73. r8a66597_bset(r8a66597, 1 << pipenum, reg);
  74. r8a66597_write(r8a66597, tmp, INTENB0);
  75. }
  76. /* this function must be called with interrupt disabled */
  77. static void disable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum,
  78. unsigned long reg)
  79. {
  80. u16 tmp;
  81. tmp = r8a66597_read(r8a66597, INTENB0);
  82. r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0);
  83. r8a66597_bclr(r8a66597, 1 << pipenum, reg);
  84. r8a66597_write(r8a66597, tmp, INTENB0);
  85. }
  86. static void set_devadd_reg(struct r8a66597 *r8a66597, u8 r8a66597_address,
  87. u16 usbspd, u8 upphub, u8 hubport, int port)
  88. {
  89. u16 val;
  90. unsigned long devadd_reg = get_devadd_addr(r8a66597_address);
  91. val = (upphub << 11) | (hubport << 8) | (usbspd << 6) | (port & 0x0001);
  92. r8a66597_write(r8a66597, val, devadd_reg);
  93. }
  94. static int r8a66597_clock_enable(struct r8a66597 *r8a66597)
  95. {
  96. u16 tmp;
  97. int i = 0;
  98. #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
  99. do {
  100. r8a66597_write(r8a66597, SCKE, SYSCFG0);
  101. tmp = r8a66597_read(r8a66597, SYSCFG0);
  102. if (i++ > 1000) {
  103. err("register access fail.");
  104. return -ENXIO;
  105. }
  106. } while ((tmp & SCKE) != SCKE);
  107. r8a66597_write(r8a66597, 0x04, 0x02);
  108. #else
  109. do {
  110. r8a66597_write(r8a66597, USBE, SYSCFG0);
  111. tmp = r8a66597_read(r8a66597, SYSCFG0);
  112. if (i++ > 1000) {
  113. err("register access fail.");
  114. return -ENXIO;
  115. }
  116. } while ((tmp & USBE) != USBE);
  117. r8a66597_bclr(r8a66597, USBE, SYSCFG0);
  118. r8a66597_mdfy(r8a66597, clock, XTAL, SYSCFG0);
  119. i = 0;
  120. r8a66597_bset(r8a66597, XCKE, SYSCFG0);
  121. do {
  122. msleep(1);
  123. tmp = r8a66597_read(r8a66597, SYSCFG0);
  124. if (i++ > 500) {
  125. err("register access fail.");
  126. return -ENXIO;
  127. }
  128. } while ((tmp & SCKE) != SCKE);
  129. #endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */
  130. return 0;
  131. }
  132. static void r8a66597_clock_disable(struct r8a66597 *r8a66597)
  133. {
  134. r8a66597_bclr(r8a66597, SCKE, SYSCFG0);
  135. udelay(1);
  136. #if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
  137. r8a66597_bclr(r8a66597, PLLC, SYSCFG0);
  138. r8a66597_bclr(r8a66597, XCKE, SYSCFG0);
  139. r8a66597_bclr(r8a66597, USBE, SYSCFG0);
  140. #endif
  141. }
  142. static void r8a66597_enable_port(struct r8a66597 *r8a66597, int port)
  143. {
  144. u16 val;
  145. val = port ? DRPD : DCFM | DRPD;
  146. r8a66597_bset(r8a66597, val, get_syscfg_reg(port));
  147. r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port));
  148. r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, get_dmacfg_reg(port));
  149. r8a66597_bclr(r8a66597, DTCHE, get_intenb_reg(port));
  150. r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
  151. }
  152. static void r8a66597_disable_port(struct r8a66597 *r8a66597, int port)
  153. {
  154. u16 val, tmp;
  155. r8a66597_write(r8a66597, 0, get_intenb_reg(port));
  156. r8a66597_write(r8a66597, 0, get_intsts_reg(port));
  157. r8a66597_port_power(r8a66597, port, 0);
  158. do {
  159. tmp = r8a66597_read(r8a66597, SOFCFG) & EDGESTS;
  160. udelay(640);
  161. } while (tmp == EDGESTS);
  162. val = port ? DRPD : DCFM | DRPD;
  163. r8a66597_bclr(r8a66597, val, get_syscfg_reg(port));
  164. r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port));
  165. }
  166. static int enable_controller(struct r8a66597 *r8a66597)
  167. {
  168. int ret, port;
  169. ret = r8a66597_clock_enable(r8a66597);
  170. if (ret < 0)
  171. return ret;
  172. r8a66597_bset(r8a66597, vif & LDRV, PINCFG);
  173. r8a66597_bset(r8a66597, USBE, SYSCFG0);
  174. r8a66597_bset(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0);
  175. r8a66597_bset(r8a66597, irq_sense & INTL, SOFCFG);
  176. r8a66597_bset(r8a66597, BRDY0, BRDYENB);
  177. r8a66597_bset(r8a66597, BEMP0, BEMPENB);
  178. r8a66597_bset(r8a66597, endian & BIGEND, CFIFOSEL);
  179. r8a66597_bset(r8a66597, endian & BIGEND, D0FIFOSEL);
  180. r8a66597_bset(r8a66597, endian & BIGEND, D1FIFOSEL);
  181. r8a66597_bset(r8a66597, TRNENSEL, SOFCFG);
  182. r8a66597_bset(r8a66597, SIGNE | SACKE, INTENB1);
  183. for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
  184. r8a66597_enable_port(r8a66597, port);
  185. return 0;
  186. }
  187. static void disable_controller(struct r8a66597 *r8a66597)
  188. {
  189. int port;
  190. r8a66597_write(r8a66597, 0, INTENB0);
  191. r8a66597_write(r8a66597, 0, INTSTS0);
  192. for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
  193. r8a66597_disable_port(r8a66597, port);
  194. r8a66597_clock_disable(r8a66597);
  195. }
  196. static int get_parent_r8a66597_address(struct r8a66597 *r8a66597,
  197. struct usb_device *udev)
  198. {
  199. struct r8a66597_device *dev;
  200. if (udev->parent && udev->parent->devnum != 1)
  201. udev = udev->parent;
  202. dev = dev_get_drvdata(&udev->dev);
  203. if (dev)
  204. return dev->address;
  205. else
  206. return 0;
  207. }
  208. static int is_child_device(char *devpath)
  209. {
  210. return (devpath[2] ? 1 : 0);
  211. }
  212. static int is_hub_limit(char *devpath)
  213. {
  214. return ((strlen(devpath) >= 4) ? 1 : 0);
  215. }
  216. static void get_port_number(char *devpath, u16 *root_port, u16 *hub_port)
  217. {
  218. if (root_port) {
  219. *root_port = (devpath[0] & 0x0F) - 1;
  220. if (*root_port >= R8A66597_MAX_ROOT_HUB)
  221. err("illegal root port number");
  222. }
  223. if (hub_port)
  224. *hub_port = devpath[2] & 0x0F;
  225. }
  226. static u16 get_r8a66597_usb_speed(enum usb_device_speed speed)
  227. {
  228. u16 usbspd = 0;
  229. switch (speed) {
  230. case USB_SPEED_LOW:
  231. usbspd = LSMODE;
  232. break;
  233. case USB_SPEED_FULL:
  234. usbspd = FSMODE;
  235. break;
  236. case USB_SPEED_HIGH:
  237. usbspd = HSMODE;
  238. break;
  239. default:
  240. err("unknown speed");
  241. break;
  242. }
  243. return usbspd;
  244. }
  245. static void set_child_connect_map(struct r8a66597 *r8a66597, int address)
  246. {
  247. int idx;
  248. idx = address / 32;
  249. r8a66597->child_connect_map[idx] |= 1 << (address % 32);
  250. }
  251. static void put_child_connect_map(struct r8a66597 *r8a66597, int address)
  252. {
  253. int idx;
  254. idx = address / 32;
  255. r8a66597->child_connect_map[idx] &= ~(1 << (address % 32));
  256. }
  257. static void set_pipe_reg_addr(struct r8a66597_pipe *pipe, u8 dma_ch)
  258. {
  259. u16 pipenum = pipe->info.pipenum;
  260. unsigned long fifoaddr[] = {D0FIFO, D1FIFO, CFIFO};
  261. unsigned long fifosel[] = {D0FIFOSEL, D1FIFOSEL, CFIFOSEL};
  262. unsigned long fifoctr[] = {D0FIFOCTR, D1FIFOCTR, CFIFOCTR};
  263. if (dma_ch > R8A66597_PIPE_NO_DMA) /* dma fifo not use? */
  264. dma_ch = R8A66597_PIPE_NO_DMA;
  265. pipe->fifoaddr = fifoaddr[dma_ch];
  266. pipe->fifosel = fifosel[dma_ch];
  267. pipe->fifoctr = fifoctr[dma_ch];
  268. if (pipenum == 0)
  269. pipe->pipectr = DCPCTR;
  270. else
  271. pipe->pipectr = get_pipectr_addr(pipenum);
  272. if (check_bulk_or_isoc(pipenum)) {
  273. pipe->pipetre = get_pipetre_addr(pipenum);
  274. pipe->pipetrn = get_pipetrn_addr(pipenum);
  275. } else {
  276. pipe->pipetre = 0;
  277. pipe->pipetrn = 0;
  278. }
  279. }
  280. static struct r8a66597_device *
  281. get_urb_to_r8a66597_dev(struct r8a66597 *r8a66597, struct urb *urb)
  282. {
  283. if (usb_pipedevice(urb->pipe) == 0)
  284. return &r8a66597->device0;
  285. return dev_get_drvdata(&urb->dev->dev);
  286. }
  287. static int make_r8a66597_device(struct r8a66597 *r8a66597,
  288. struct urb *urb, u8 addr)
  289. {
  290. struct r8a66597_device *dev;
  291. int usb_address = urb->setup_packet[2]; /* urb->pipe is address 0 */
  292. dev = kzalloc(sizeof(struct r8a66597_device), GFP_ATOMIC);
  293. if (dev == NULL)
  294. return -ENOMEM;
  295. dev_set_drvdata(&urb->dev->dev, dev);
  296. dev->udev = urb->dev;
  297. dev->address = addr;
  298. dev->usb_address = usb_address;
  299. dev->state = USB_STATE_ADDRESS;
  300. dev->ep_in_toggle = 0;
  301. dev->ep_out_toggle = 0;
  302. INIT_LIST_HEAD(&dev->device_list);
  303. list_add_tail(&dev->device_list, &r8a66597->child_device);
  304. get_port_number(urb->dev->devpath, &dev->root_port, &dev->hub_port);
  305. if (!is_child_device(urb->dev->devpath))
  306. r8a66597->root_hub[dev->root_port].dev = dev;
  307. set_devadd_reg(r8a66597, dev->address,
  308. get_r8a66597_usb_speed(urb->dev->speed),
  309. get_parent_r8a66597_address(r8a66597, urb->dev),
  310. dev->hub_port, dev->root_port);
  311. return 0;
  312. }
  313. /* this function must be called with interrupt disabled */
  314. static u8 alloc_usb_address(struct r8a66597 *r8a66597, struct urb *urb)
  315. {
  316. u8 addr; /* R8A66597's address */
  317. struct r8a66597_device *dev;
  318. if (is_hub_limit(urb->dev->devpath)) {
  319. err("Externel hub limit reached.");
  320. return 0;
  321. }
  322. dev = get_urb_to_r8a66597_dev(r8a66597, urb);
  323. if (dev && dev->state >= USB_STATE_ADDRESS)
  324. return dev->address;
  325. for (addr = 1; addr <= R8A66597_MAX_DEVICE; addr++) {
  326. if (r8a66597->address_map & (1 << addr))
  327. continue;
  328. dbg("alloc_address: r8a66597_addr=%d", addr);
  329. r8a66597->address_map |= 1 << addr;
  330. if (make_r8a66597_device(r8a66597, urb, addr) < 0)
  331. return 0;
  332. return addr;
  333. }
  334. err("cannot communicate with a USB device more than 10.(%x)",
  335. r8a66597->address_map);
  336. return 0;
  337. }
  338. /* this function must be called with interrupt disabled */
  339. static void free_usb_address(struct r8a66597 *r8a66597,
  340. struct r8a66597_device *dev)
  341. {
  342. int port;
  343. if (!dev)
  344. return;
  345. dbg("free_addr: addr=%d", dev->address);
  346. dev->state = USB_STATE_DEFAULT;
  347. r8a66597->address_map &= ~(1 << dev->address);
  348. dev->address = 0;
  349. dev_set_drvdata(&dev->udev->dev, NULL);
  350. list_del(&dev->device_list);
  351. kfree(dev);
  352. for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) {
  353. if (r8a66597->root_hub[port].dev == dev) {
  354. r8a66597->root_hub[port].dev = NULL;
  355. break;
  356. }
  357. }
  358. }
  359. static void r8a66597_reg_wait(struct r8a66597 *r8a66597, unsigned long reg,
  360. u16 mask, u16 loop)
  361. {
  362. u16 tmp;
  363. int i = 0;
  364. do {
  365. tmp = r8a66597_read(r8a66597, reg);
  366. if (i++ > 1000000) {
  367. err("register%lx, loop %x is timeout", reg, loop);
  368. break;
  369. }
  370. ndelay(1);
  371. } while ((tmp & mask) != loop);
  372. }
  373. /* this function must be called with interrupt disabled */
  374. static void pipe_start(struct r8a66597 *r8a66597, struct r8a66597_pipe *pipe)
  375. {
  376. u16 tmp;
  377. tmp = r8a66597_read(r8a66597, pipe->pipectr) & PID;
  378. if ((pipe->info.pipenum != 0) & ((tmp & PID_STALL) != 0)) /* stall? */
  379. r8a66597_mdfy(r8a66597, PID_NAK, PID, pipe->pipectr);
  380. r8a66597_mdfy(r8a66597, PID_BUF, PID, pipe->pipectr);
  381. }
  382. /* this function must be called with interrupt disabled */
  383. static void pipe_stop(struct r8a66597 *r8a66597, struct r8a66597_pipe *pipe)
  384. {
  385. u16 tmp;
  386. tmp = r8a66597_read(r8a66597, pipe->pipectr) & PID;
  387. if ((tmp & PID_STALL11) != PID_STALL11) /* force stall? */
  388. r8a66597_mdfy(r8a66597, PID_STALL, PID, pipe->pipectr);
  389. r8a66597_mdfy(r8a66597, PID_NAK, PID, pipe->pipectr);
  390. r8a66597_reg_wait(r8a66597, pipe->pipectr, PBUSY, 0);
  391. }
  392. /* this function must be called with interrupt disabled */
  393. static void clear_all_buffer(struct r8a66597 *r8a66597,
  394. struct r8a66597_pipe *pipe)
  395. {
  396. u16 tmp;
  397. if (!pipe || pipe->info.pipenum == 0)
  398. return;
  399. pipe_stop(r8a66597, pipe);
  400. r8a66597_bset(r8a66597, ACLRM, pipe->pipectr);
  401. tmp = r8a66597_read(r8a66597, pipe->pipectr);
  402. tmp = r8a66597_read(r8a66597, pipe->pipectr);
  403. tmp = r8a66597_read(r8a66597, pipe->pipectr);
  404. r8a66597_bclr(r8a66597, ACLRM, pipe->pipectr);
  405. }
  406. /* this function must be called with interrupt disabled */
  407. static void r8a66597_pipe_toggle(struct r8a66597 *r8a66597,
  408. struct r8a66597_pipe *pipe, int toggle)
  409. {
  410. if (toggle)
  411. r8a66597_bset(r8a66597, SQSET, pipe->pipectr);
  412. else
  413. r8a66597_bset(r8a66597, SQCLR, pipe->pipectr);
  414. }
  415. /* this function must be called with interrupt disabled */
  416. static inline void cfifo_change(struct r8a66597 *r8a66597, u16 pipenum)
  417. {
  418. r8a66597_mdfy(r8a66597, MBW | pipenum, MBW | CURPIPE, CFIFOSEL);
  419. r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, pipenum);
  420. }
  421. /* this function must be called with interrupt disabled */
  422. static inline void fifo_change_from_pipe(struct r8a66597 *r8a66597,
  423. struct r8a66597_pipe *pipe)
  424. {
  425. cfifo_change(r8a66597, 0);
  426. r8a66597_mdfy(r8a66597, MBW | 0, MBW | CURPIPE, D0FIFOSEL);
  427. r8a66597_mdfy(r8a66597, MBW | 0, MBW | CURPIPE, D1FIFOSEL);
  428. r8a66597_mdfy(r8a66597, MBW | pipe->info.pipenum, MBW | CURPIPE,
  429. pipe->fifosel);
  430. r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE, pipe->info.pipenum);
  431. }
  432. static u16 r8a66597_get_pipenum(struct urb *urb, struct usb_host_endpoint *hep)
  433. {
  434. struct r8a66597_pipe *pipe = hep->hcpriv;
  435. if (usb_pipeendpoint(urb->pipe) == 0)
  436. return 0;
  437. else
  438. return pipe->info.pipenum;
  439. }
  440. static u16 get_urb_to_r8a66597_addr(struct r8a66597 *r8a66597, struct urb *urb)
  441. {
  442. struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
  443. return (usb_pipedevice(urb->pipe) == 0) ? 0 : dev->address;
  444. }
  445. static unsigned short *get_toggle_pointer(struct r8a66597_device *dev,
  446. int urb_pipe)
  447. {
  448. if (!dev)
  449. return NULL;
  450. return usb_pipein(urb_pipe) ? &dev->ep_in_toggle : &dev->ep_out_toggle;
  451. }
  452. /* this function must be called with interrupt disabled */
  453. static void pipe_toggle_set(struct r8a66597 *r8a66597,
  454. struct r8a66597_pipe *pipe,
  455. struct urb *urb, int set)
  456. {
  457. struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
  458. unsigned char endpoint = usb_pipeendpoint(urb->pipe);
  459. unsigned short *toggle = get_toggle_pointer(dev, urb->pipe);
  460. if (!toggle)
  461. return;
  462. if (set)
  463. *toggle |= 1 << endpoint;
  464. else
  465. *toggle &= ~(1 << endpoint);
  466. }
  467. /* this function must be called with interrupt disabled */
  468. static void pipe_toggle_save(struct r8a66597 *r8a66597,
  469. struct r8a66597_pipe *pipe,
  470. struct urb *urb)
  471. {
  472. if (r8a66597_read(r8a66597, pipe->pipectr) & SQMON)
  473. pipe_toggle_set(r8a66597, pipe, urb, 1);
  474. else
  475. pipe_toggle_set(r8a66597, pipe, urb, 0);
  476. }
  477. /* this function must be called with interrupt disabled */
  478. static void pipe_toggle_restore(struct r8a66597 *r8a66597,
  479. struct r8a66597_pipe *pipe,
  480. struct urb *urb)
  481. {
  482. struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
  483. unsigned char endpoint = usb_pipeendpoint(urb->pipe);
  484. unsigned short *toggle = get_toggle_pointer(dev, urb->pipe);
  485. if (!toggle)
  486. return;
  487. r8a66597_pipe_toggle(r8a66597, pipe, *toggle & (1 << endpoint));
  488. }
  489. /* this function must be called with interrupt disabled */
  490. static void pipe_buffer_setting(struct r8a66597 *r8a66597,
  491. struct r8a66597_pipe_info *info)
  492. {
  493. u16 val = 0;
  494. if (info->pipenum == 0)
  495. return;
  496. r8a66597_bset(r8a66597, ACLRM, get_pipectr_addr(info->pipenum));
  497. r8a66597_bclr(r8a66597, ACLRM, get_pipectr_addr(info->pipenum));
  498. r8a66597_write(r8a66597, info->pipenum, PIPESEL);
  499. if (!info->dir_in)
  500. val |= R8A66597_DIR;
  501. if (info->type == R8A66597_BULK && info->dir_in)
  502. val |= R8A66597_DBLB | R8A66597_SHTNAK;
  503. val |= info->type | info->epnum;
  504. r8a66597_write(r8a66597, val, PIPECFG);
  505. r8a66597_write(r8a66597, (info->buf_bsize << 10) | (info->bufnum),
  506. PIPEBUF);
  507. r8a66597_write(r8a66597, make_devsel(info->address) | info->maxpacket,
  508. PIPEMAXP);
  509. r8a66597_write(r8a66597, info->interval, PIPEPERI);
  510. }
  511. /* this function must be called with interrupt disabled */
  512. static void pipe_setting(struct r8a66597 *r8a66597, struct r8a66597_td *td)
  513. {
  514. struct r8a66597_pipe_info *info;
  515. struct urb *urb = td->urb;
  516. if (td->pipenum > 0) {
  517. info = &td->pipe->info;
  518. cfifo_change(r8a66597, 0);
  519. pipe_buffer_setting(r8a66597, info);
  520. if (!usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe),
  521. usb_pipeout(urb->pipe)) &&
  522. !usb_pipecontrol(urb->pipe)) {
  523. r8a66597_pipe_toggle(r8a66597, td->pipe, 0);
  524. pipe_toggle_set(r8a66597, td->pipe, urb, 0);
  525. clear_all_buffer(r8a66597, td->pipe);
  526. usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
  527. usb_pipeout(urb->pipe), 1);
  528. }
  529. pipe_toggle_restore(r8a66597, td->pipe, urb);
  530. }
  531. }
  532. /* this function must be called with interrupt disabled */
  533. static u16 get_empty_pipenum(struct r8a66597 *r8a66597,
  534. struct usb_endpoint_descriptor *ep)
  535. {
  536. u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min;
  537. memset(array, 0, sizeof(array));
  538. switch (ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
  539. case USB_ENDPOINT_XFER_BULK:
  540. if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
  541. array[i++] = 4;
  542. else {
  543. array[i++] = 3;
  544. array[i++] = 5;
  545. }
  546. break;
  547. case USB_ENDPOINT_XFER_INT:
  548. if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) {
  549. array[i++] = 6;
  550. array[i++] = 7;
  551. array[i++] = 8;
  552. } else
  553. array[i++] = 9;
  554. break;
  555. case USB_ENDPOINT_XFER_ISOC:
  556. if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
  557. array[i++] = 2;
  558. else
  559. array[i++] = 1;
  560. break;
  561. default:
  562. err("Illegal type");
  563. return 0;
  564. }
  565. i = 1;
  566. min = array[0];
  567. while (array[i] != 0) {
  568. if (r8a66597->pipe_cnt[min] > r8a66597->pipe_cnt[array[i]])
  569. min = array[i];
  570. i++;
  571. }
  572. return min;
  573. }
  574. static u16 get_r8a66597_type(__u8 type)
  575. {
  576. u16 r8a66597_type;
  577. switch (type) {
  578. case USB_ENDPOINT_XFER_BULK:
  579. r8a66597_type = R8A66597_BULK;
  580. break;
  581. case USB_ENDPOINT_XFER_INT:
  582. r8a66597_type = R8A66597_INT;
  583. break;
  584. case USB_ENDPOINT_XFER_ISOC:
  585. r8a66597_type = R8A66597_ISO;
  586. break;
  587. default:
  588. err("Illegal type");
  589. r8a66597_type = 0x0000;
  590. break;
  591. }
  592. return r8a66597_type;
  593. }
  594. static u16 get_bufnum(u16 pipenum)
  595. {
  596. u16 bufnum = 0;
  597. if (pipenum == 0)
  598. bufnum = 0;
  599. else if (check_bulk_or_isoc(pipenum))
  600. bufnum = 8 + (pipenum - 1) * R8A66597_BUF_BSIZE*2;
  601. else if (check_interrupt(pipenum))
  602. bufnum = 4 + (pipenum - 6);
  603. else
  604. err("Illegal pipenum (%d)", pipenum);
  605. return bufnum;
  606. }
  607. static u16 get_buf_bsize(u16 pipenum)
  608. {
  609. u16 buf_bsize = 0;
  610. if (pipenum == 0)
  611. buf_bsize = 3;
  612. else if (check_bulk_or_isoc(pipenum))
  613. buf_bsize = R8A66597_BUF_BSIZE - 1;
  614. else if (check_interrupt(pipenum))
  615. buf_bsize = 0;
  616. else
  617. err("Illegal pipenum (%d)", pipenum);
  618. return buf_bsize;
  619. }
  620. /* this function must be called with interrupt disabled */
  621. static void enable_r8a66597_pipe_dma(struct r8a66597 *r8a66597,
  622. struct r8a66597_device *dev,
  623. struct r8a66597_pipe *pipe,
  624. struct urb *urb)
  625. {
  626. #if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
  627. int i;
  628. struct r8a66597_pipe_info *info = &pipe->info;
  629. if ((pipe->info.pipenum != 0) && (info->type != R8A66597_INT)) {
  630. for (i = 0; i < R8A66597_MAX_DMA_CHANNEL; i++) {
  631. if ((r8a66597->dma_map & (1 << i)) != 0)
  632. continue;
  633. info("address %d, EndpointAddress 0x%02x use DMA FIFO",
  634. usb_pipedevice(urb->pipe),
  635. info->dir_in ? USB_ENDPOINT_DIR_MASK + info->epnum
  636. : info->epnum);
  637. r8a66597->dma_map |= 1 << i;
  638. dev->dma_map |= 1 << i;
  639. set_pipe_reg_addr(pipe, i);
  640. cfifo_change(r8a66597, 0);
  641. r8a66597_mdfy(r8a66597, MBW | pipe->info.pipenum,
  642. MBW | CURPIPE, pipe->fifosel);
  643. r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE,
  644. pipe->info.pipenum);
  645. r8a66597_bset(r8a66597, BCLR, pipe->fifoctr);
  646. break;
  647. }
  648. }
  649. #endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */
  650. }
  651. /* this function must be called with interrupt disabled */
  652. static void enable_r8a66597_pipe(struct r8a66597 *r8a66597, struct urb *urb,
  653. struct usb_host_endpoint *hep,
  654. struct r8a66597_pipe_info *info)
  655. {
  656. struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
  657. struct r8a66597_pipe *pipe = hep->hcpriv;
  658. dbg("enable_pipe:");
  659. pipe->info = *info;
  660. set_pipe_reg_addr(pipe, R8A66597_PIPE_NO_DMA);
  661. r8a66597->pipe_cnt[pipe->info.pipenum]++;
  662. dev->pipe_cnt[pipe->info.pipenum]++;
  663. enable_r8a66597_pipe_dma(r8a66597, dev, pipe, urb);
  664. }
  665. /* this function must be called with interrupt disabled */
  666. static void force_dequeue(struct r8a66597 *r8a66597, u16 pipenum, u16 address)
  667. {
  668. struct r8a66597_td *td, *next;
  669. struct urb *urb;
  670. struct list_head *list = &r8a66597->pipe_queue[pipenum];
  671. if (list_empty(list))
  672. return;
  673. list_for_each_entry_safe(td, next, list, queue) {
  674. if (!td)
  675. continue;
  676. if (td->address != address)
  677. continue;
  678. urb = td->urb;
  679. list_del(&td->queue);
  680. kfree(td);
  681. if (urb) {
  682. usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597),
  683. urb);
  684. spin_unlock(&r8a66597->lock);
  685. usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597), urb,
  686. -ENODEV);
  687. spin_lock(&r8a66597->lock);
  688. }
  689. break;
  690. }
  691. }
  692. /* this function must be called with interrupt disabled */
  693. static void disable_r8a66597_pipe_all(struct r8a66597 *r8a66597,
  694. struct r8a66597_device *dev)
  695. {
  696. int check_ep0 = 0;
  697. u16 pipenum;
  698. if (!dev)
  699. return;
  700. for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
  701. if (!dev->pipe_cnt[pipenum])
  702. continue;
  703. if (!check_ep0) {
  704. check_ep0 = 1;
  705. force_dequeue(r8a66597, 0, dev->address);
  706. }
  707. r8a66597->pipe_cnt[pipenum] -= dev->pipe_cnt[pipenum];
  708. dev->pipe_cnt[pipenum] = 0;
  709. force_dequeue(r8a66597, pipenum, dev->address);
  710. }
  711. dbg("disable_pipe");
  712. r8a66597->dma_map &= ~(dev->dma_map);
  713. dev->dma_map = 0;
  714. }
  715. static unsigned long get_timer_interval(struct urb *urb, __u8 interval)
  716. {
  717. __u8 i;
  718. unsigned long time = 1;
  719. if (usb_pipeisoc(urb->pipe))
  720. return 0;
  721. if (get_r8a66597_usb_speed(urb->dev->speed) == HSMODE) {
  722. for (i = 0; i < (interval - 1); i++)
  723. time *= 2;
  724. time = time * 125 / 1000; /* uSOF -> msec */
  725. } else {
  726. time = interval;
  727. }
  728. return time;
  729. }
  730. /* this function must be called with interrupt disabled */
  731. static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb,
  732. struct usb_host_endpoint *hep,
  733. struct usb_endpoint_descriptor *ep)
  734. {
  735. struct r8a66597_pipe_info info;
  736. info.pipenum = get_empty_pipenum(r8a66597, ep);
  737. info.address = get_urb_to_r8a66597_addr(r8a66597, urb);
  738. info.epnum = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  739. info.maxpacket = le16_to_cpu(ep->wMaxPacketSize);
  740. info.type = get_r8a66597_type(ep->bmAttributes
  741. & USB_ENDPOINT_XFERTYPE_MASK);
  742. info.bufnum = get_bufnum(info.pipenum);
  743. info.buf_bsize = get_buf_bsize(info.pipenum);
  744. if (info.type == R8A66597_BULK) {
  745. info.interval = 0;
  746. info.timer_interval = 0;
  747. } else {
  748. if (ep->bInterval > IITV)
  749. info.interval = IITV;
  750. else
  751. info.interval = ep->bInterval ? ep->bInterval - 1 : 0;
  752. info.timer_interval = get_timer_interval(urb, ep->bInterval);
  753. }
  754. if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
  755. info.dir_in = 1;
  756. else
  757. info.dir_in = 0;
  758. enable_r8a66597_pipe(r8a66597, urb, hep, &info);
  759. }
  760. static void init_pipe_config(struct r8a66597 *r8a66597, struct urb *urb)
  761. {
  762. struct r8a66597_device *dev;
  763. dev = get_urb_to_r8a66597_dev(r8a66597, urb);
  764. dev->state = USB_STATE_CONFIGURED;
  765. }
  766. static void pipe_irq_enable(struct r8a66597 *r8a66597, struct urb *urb,
  767. u16 pipenum)
  768. {
  769. if (pipenum == 0 && usb_pipeout(urb->pipe))
  770. enable_irq_empty(r8a66597, pipenum);
  771. else
  772. enable_irq_ready(r8a66597, pipenum);
  773. if (!usb_pipeisoc(urb->pipe))
  774. enable_irq_nrdy(r8a66597, pipenum);
  775. }
  776. static void pipe_irq_disable(struct r8a66597 *r8a66597, u16 pipenum)
  777. {
  778. disable_irq_ready(r8a66597, pipenum);
  779. disable_irq_nrdy(r8a66597, pipenum);
  780. }
  781. /* this function must be called with interrupt disabled */
  782. static void r8a66597_check_syssts(struct r8a66597 *r8a66597, int port,
  783. u16 syssts)
  784. {
  785. if (syssts == SE0) {
  786. r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
  787. return;
  788. }
  789. if (syssts == FS_JSTS)
  790. r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port));
  791. else if (syssts == LS_JSTS)
  792. r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port));
  793. r8a66597_write(r8a66597, ~DTCH, get_intsts_reg(port));
  794. r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port));
  795. }
  796. /* this function must be called with interrupt disabled */
  797. static void r8a66597_usb_connect(struct r8a66597 *r8a66597, int port)
  798. {
  799. u16 speed = get_rh_usb_speed(r8a66597, port);
  800. struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
  801. if (speed == HSMODE)
  802. rh->port |= (1 << USB_PORT_FEAT_HIGHSPEED);
  803. else if (speed == LSMODE)
  804. rh->port |= (1 << USB_PORT_FEAT_LOWSPEED);
  805. rh->port &= ~(1 << USB_PORT_FEAT_RESET);
  806. rh->port |= 1 << USB_PORT_FEAT_ENABLE;
  807. }
  808. /* this function must be called with interrupt disabled */
  809. static void r8a66597_usb_disconnect(struct r8a66597 *r8a66597, int port)
  810. {
  811. struct r8a66597_device *dev = r8a66597->root_hub[port].dev;
  812. r8a66597->root_hub[port].port &= ~(1 << USB_PORT_FEAT_CONNECTION);
  813. r8a66597->root_hub[port].port |= (1 << USB_PORT_FEAT_C_CONNECTION);
  814. disable_r8a66597_pipe_all(r8a66597, dev);
  815. free_usb_address(r8a66597, dev);
  816. r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
  817. }
  818. /* this function must be called with interrupt disabled */
  819. static void prepare_setup_packet(struct r8a66597 *r8a66597,
  820. struct r8a66597_td *td)
  821. {
  822. int i;
  823. u16 *p = (u16 *)td->urb->setup_packet;
  824. unsigned long setup_addr = USBREQ;
  825. r8a66597_write(r8a66597, make_devsel(td->address) | td->maxpacket,
  826. DCPMAXP);
  827. r8a66597_write(r8a66597, ~(SIGN | SACK), INTSTS1);
  828. for (i = 0; i < 4; i++) {
  829. r8a66597_write(r8a66597, cpu_to_le16(p[i]), setup_addr);
  830. setup_addr += 2;
  831. }
  832. r8a66597_write(r8a66597, SUREQ, DCPCTR);
  833. }
  834. /* this function must be called with interrupt disabled */
  835. static void prepare_packet_read(struct r8a66597 *r8a66597,
  836. struct r8a66597_td *td)
  837. {
  838. struct urb *urb = td->urb;
  839. if (usb_pipecontrol(urb->pipe)) {
  840. r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
  841. r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
  842. r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
  843. if (urb->actual_length == 0) {
  844. r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
  845. r8a66597_write(r8a66597, BCLR, CFIFOCTR);
  846. }
  847. pipe_irq_disable(r8a66597, td->pipenum);
  848. pipe_start(r8a66597, td->pipe);
  849. pipe_irq_enable(r8a66597, urb, td->pipenum);
  850. } else {
  851. if (urb->actual_length == 0) {
  852. pipe_irq_disable(r8a66597, td->pipenum);
  853. pipe_setting(r8a66597, td);
  854. pipe_stop(r8a66597, td->pipe);
  855. r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS);
  856. if (td->pipe->pipetre) {
  857. r8a66597_write(r8a66597, TRCLR,
  858. td->pipe->pipetre);
  859. r8a66597_write(r8a66597,
  860. DIV_ROUND_UP
  861. (urb->transfer_buffer_length,
  862. td->maxpacket),
  863. td->pipe->pipetrn);
  864. r8a66597_bset(r8a66597, TRENB,
  865. td->pipe->pipetre);
  866. }
  867. pipe_start(r8a66597, td->pipe);
  868. pipe_irq_enable(r8a66597, urb, td->pipenum);
  869. }
  870. }
  871. }
  872. /* this function must be called with interrupt disabled */
  873. static void prepare_packet_write(struct r8a66597 *r8a66597,
  874. struct r8a66597_td *td)
  875. {
  876. u16 tmp;
  877. struct urb *urb = td->urb;
  878. if (usb_pipecontrol(urb->pipe)) {
  879. pipe_stop(r8a66597, td->pipe);
  880. r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG);
  881. r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
  882. r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
  883. if (urb->actual_length == 0) {
  884. r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
  885. r8a66597_write(r8a66597, BCLR, CFIFOCTR);
  886. }
  887. } else {
  888. if (urb->actual_length == 0)
  889. pipe_setting(r8a66597, td);
  890. if (td->pipe->pipetre)
  891. r8a66597_bclr(r8a66597, TRENB, td->pipe->pipetre);
  892. }
  893. r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS);
  894. fifo_change_from_pipe(r8a66597, td->pipe);
  895. tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
  896. if (unlikely((tmp & FRDY) == 0))
  897. pipe_irq_enable(r8a66597, urb, td->pipenum);
  898. else
  899. packet_write(r8a66597, td->pipenum);
  900. pipe_start(r8a66597, td->pipe);
  901. }
  902. /* this function must be called with interrupt disabled */
  903. static void prepare_status_packet(struct r8a66597 *r8a66597,
  904. struct r8a66597_td *td)
  905. {
  906. struct urb *urb = td->urb;
  907. r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
  908. pipe_stop(r8a66597, td->pipe);
  909. if (urb->setup_packet[0] & USB_ENDPOINT_DIR_MASK) {
  910. r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG);
  911. r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
  912. r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
  913. r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
  914. r8a66597_write(r8a66597, BCLR | BVAL, CFIFOCTR);
  915. enable_irq_empty(r8a66597, 0);
  916. } else {
  917. r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
  918. r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
  919. r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
  920. r8a66597_write(r8a66597, BCLR, CFIFOCTR);
  921. enable_irq_ready(r8a66597, 0);
  922. }
  923. enable_irq_nrdy(r8a66597, 0);
  924. pipe_start(r8a66597, td->pipe);
  925. }
  926. static int is_set_address(unsigned char *setup_packet)
  927. {
  928. if (((setup_packet[0] & USB_TYPE_MASK) == USB_TYPE_STANDARD) &&
  929. setup_packet[1] == USB_REQ_SET_ADDRESS)
  930. return 1;
  931. else
  932. return 0;
  933. }
  934. /* this function must be called with interrupt disabled */
  935. static int start_transfer(struct r8a66597 *r8a66597, struct r8a66597_td *td)
  936. {
  937. BUG_ON(!td);
  938. switch (td->type) {
  939. case USB_PID_SETUP:
  940. if (is_set_address(td->urb->setup_packet)) {
  941. td->set_address = 1;
  942. td->urb->setup_packet[2] = alloc_usb_address(r8a66597,
  943. td->urb);
  944. if (td->urb->setup_packet[2] == 0)
  945. return -EPIPE;
  946. }
  947. prepare_setup_packet(r8a66597, td);
  948. break;
  949. case USB_PID_IN:
  950. prepare_packet_read(r8a66597, td);
  951. break;
  952. case USB_PID_OUT:
  953. prepare_packet_write(r8a66597, td);
  954. break;
  955. case USB_PID_ACK:
  956. prepare_status_packet(r8a66597, td);
  957. break;
  958. default:
  959. err("invalid type.");
  960. break;
  961. }
  962. return 0;
  963. }
  964. static int check_transfer_finish(struct r8a66597_td *td, struct urb *urb)
  965. {
  966. if (usb_pipeisoc(urb->pipe)) {
  967. if (urb->number_of_packets == td->iso_cnt)
  968. return 1;
  969. }
  970. /* control or bulk or interrupt */
  971. if ((urb->transfer_buffer_length <= urb->actual_length) ||
  972. (td->short_packet) || (td->zero_packet))
  973. return 1;
  974. return 0;
  975. }
  976. /* this function must be called with interrupt disabled */
  977. static void set_td_timer(struct r8a66597 *r8a66597, struct r8a66597_td *td)
  978. {
  979. unsigned long time;
  980. BUG_ON(!td);
  981. if (!list_empty(&r8a66597->pipe_queue[td->pipenum]) &&
  982. !usb_pipecontrol(td->urb->pipe) && usb_pipein(td->urb->pipe)) {
  983. r8a66597->timeout_map |= 1 << td->pipenum;
  984. switch (usb_pipetype(td->urb->pipe)) {
  985. case PIPE_INTERRUPT:
  986. case PIPE_ISOCHRONOUS:
  987. time = 30;
  988. break;
  989. default:
  990. time = 300;
  991. break;
  992. }
  993. mod_timer(&r8a66597->td_timer[td->pipenum],
  994. jiffies + msecs_to_jiffies(time));
  995. }
  996. }
  997. /* this function must be called with interrupt disabled */
  998. static void finish_request(struct r8a66597 *r8a66597, struct r8a66597_td *td,
  999. u16 pipenum, struct urb *urb, int status)
  1000. __releases(r8a66597->lock) __acquires(r8a66597->lock)
  1001. {
  1002. int restart = 0;
  1003. struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
  1004. r8a66597->timeout_map &= ~(1 << pipenum);
  1005. if (likely(td)) {
  1006. if (td->set_address && (status != 0 || urb->unlinked))
  1007. r8a66597->address_map &= ~(1 << urb->setup_packet[2]);
  1008. pipe_toggle_save(r8a66597, td->pipe, urb);
  1009. list_del(&td->queue);
  1010. kfree(td);
  1011. }
  1012. if (!list_empty(&r8a66597->pipe_queue[pipenum]))
  1013. restart = 1;
  1014. if (likely(urb)) {
  1015. if (usb_pipeisoc(urb->pipe))
  1016. urb->start_frame = r8a66597_get_frame(hcd);
  1017. usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597), urb);
  1018. spin_unlock(&r8a66597->lock);
  1019. usb_hcd_giveback_urb(hcd, urb, status);
  1020. spin_lock(&r8a66597->lock);
  1021. }
  1022. if (restart) {
  1023. td = r8a66597_get_td(r8a66597, pipenum);
  1024. if (unlikely(!td))
  1025. return;
  1026. start_transfer(r8a66597, td);
  1027. set_td_timer(r8a66597, td);
  1028. }
  1029. }
  1030. static void packet_read(struct r8a66597 *r8a66597, u16 pipenum)
  1031. {
  1032. u16 tmp;
  1033. int rcv_len, bufsize, urb_len, size;
  1034. u16 *buf;
  1035. struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
  1036. struct urb *urb;
  1037. int finish = 0;
  1038. int status = 0;
  1039. if (unlikely(!td))
  1040. return;
  1041. urb = td->urb;
  1042. fifo_change_from_pipe(r8a66597, td->pipe);
  1043. tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
  1044. if (unlikely((tmp & FRDY) == 0)) {
  1045. pipe_stop(r8a66597, td->pipe);
  1046. pipe_irq_disable(r8a66597, pipenum);
  1047. err("in fifo not ready (%d)", pipenum);
  1048. finish_request(r8a66597, td, pipenum, td->urb, -EPIPE);
  1049. return;
  1050. }
  1051. /* prepare parameters */
  1052. rcv_len = tmp & DTLN;
  1053. if (usb_pipeisoc(urb->pipe)) {
  1054. buf = (u16 *)(urb->transfer_buffer +
  1055. urb->iso_frame_desc[td->iso_cnt].offset);
  1056. urb_len = urb->iso_frame_desc[td->iso_cnt].length;
  1057. } else {
  1058. buf = (void *)urb->transfer_buffer + urb->actual_length;
  1059. urb_len = urb->transfer_buffer_length - urb->actual_length;
  1060. }
  1061. bufsize = min(urb_len, (int) td->maxpacket);
  1062. if (rcv_len <= bufsize) {
  1063. size = rcv_len;
  1064. } else {
  1065. size = bufsize;
  1066. status = -EOVERFLOW;
  1067. finish = 1;
  1068. }
  1069. /* update parameters */
  1070. urb->actual_length += size;
  1071. if (rcv_len == 0)
  1072. td->zero_packet = 1;
  1073. if (rcv_len < bufsize) {
  1074. td->short_packet = 1;
  1075. }
  1076. if (usb_pipeisoc(urb->pipe)) {
  1077. urb->iso_frame_desc[td->iso_cnt].actual_length = size;
  1078. urb->iso_frame_desc[td->iso_cnt].status = status;
  1079. td->iso_cnt++;
  1080. finish = 0;
  1081. }
  1082. /* check transfer finish */
  1083. if (finish || check_transfer_finish(td, urb)) {
  1084. pipe_stop(r8a66597, td->pipe);
  1085. pipe_irq_disable(r8a66597, pipenum);
  1086. finish = 1;
  1087. }
  1088. /* read fifo */
  1089. if (urb->transfer_buffer) {
  1090. if (size == 0)
  1091. r8a66597_write(r8a66597, BCLR, td->pipe->fifoctr);
  1092. else
  1093. r8a66597_read_fifo(r8a66597, td->pipe->fifoaddr,
  1094. buf, size);
  1095. }
  1096. if (finish && pipenum != 0)
  1097. finish_request(r8a66597, td, pipenum, urb, status);
  1098. }
  1099. static void packet_write(struct r8a66597 *r8a66597, u16 pipenum)
  1100. {
  1101. u16 tmp;
  1102. int bufsize, size;
  1103. u16 *buf;
  1104. struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
  1105. struct urb *urb;
  1106. if (unlikely(!td))
  1107. return;
  1108. urb = td->urb;
  1109. fifo_change_from_pipe(r8a66597, td->pipe);
  1110. tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
  1111. if (unlikely((tmp & FRDY) == 0)) {
  1112. pipe_stop(r8a66597, td->pipe);
  1113. pipe_irq_disable(r8a66597, pipenum);
  1114. err("out write fifo not ready. (%d)", pipenum);
  1115. finish_request(r8a66597, td, pipenum, urb, -EPIPE);
  1116. return;
  1117. }
  1118. /* prepare parameters */
  1119. bufsize = td->maxpacket;
  1120. if (usb_pipeisoc(urb->pipe)) {
  1121. buf = (u16 *)(urb->transfer_buffer +
  1122. urb->iso_frame_desc[td->iso_cnt].offset);
  1123. size = min(bufsize,
  1124. (int)urb->iso_frame_desc[td->iso_cnt].length);
  1125. } else {
  1126. buf = (u16 *)(urb->transfer_buffer + urb->actual_length);
  1127. size = min((int)bufsize,
  1128. urb->transfer_buffer_length - urb->actual_length);
  1129. }
  1130. /* write fifo */
  1131. if (pipenum > 0)
  1132. r8a66597_write(r8a66597, ~(1 << pipenum), BEMPSTS);
  1133. if (urb->transfer_buffer) {
  1134. r8a66597_write_fifo(r8a66597, td->pipe->fifoaddr, buf, size);
  1135. if (!usb_pipebulk(urb->pipe) || td->maxpacket != size)
  1136. r8a66597_write(r8a66597, BVAL, td->pipe->fifoctr);
  1137. }
  1138. /* update parameters */
  1139. urb->actual_length += size;
  1140. if (usb_pipeisoc(urb->pipe)) {
  1141. urb->iso_frame_desc[td->iso_cnt].actual_length = size;
  1142. urb->iso_frame_desc[td->iso_cnt].status = 0;
  1143. td->iso_cnt++;
  1144. }
  1145. /* check transfer finish */
  1146. if (check_transfer_finish(td, urb)) {
  1147. disable_irq_ready(r8a66597, pipenum);
  1148. enable_irq_empty(r8a66597, pipenum);
  1149. if (!usb_pipeisoc(urb->pipe))
  1150. enable_irq_nrdy(r8a66597, pipenum);
  1151. } else
  1152. pipe_irq_enable(r8a66597, urb, pipenum);
  1153. }
  1154. static void check_next_phase(struct r8a66597 *r8a66597, int status)
  1155. {
  1156. struct r8a66597_td *td = r8a66597_get_td(r8a66597, 0);
  1157. struct urb *urb;
  1158. u8 finish = 0;
  1159. if (unlikely(!td))
  1160. return;
  1161. urb = td->urb;
  1162. switch (td->type) {
  1163. case USB_PID_IN:
  1164. case USB_PID_OUT:
  1165. if (check_transfer_finish(td, urb))
  1166. td->type = USB_PID_ACK;
  1167. break;
  1168. case USB_PID_SETUP:
  1169. if (urb->transfer_buffer_length == urb->actual_length)
  1170. td->type = USB_PID_ACK;
  1171. else if (usb_pipeout(urb->pipe))
  1172. td->type = USB_PID_OUT;
  1173. else
  1174. td->type = USB_PID_IN;
  1175. break;
  1176. case USB_PID_ACK:
  1177. finish = 1;
  1178. break;
  1179. }
  1180. if (finish || status != 0 || urb->unlinked)
  1181. finish_request(r8a66597, td, 0, urb, status);
  1182. else
  1183. start_transfer(r8a66597, td);
  1184. }
  1185. static int get_urb_error(struct r8a66597 *r8a66597, u16 pipenum)
  1186. {
  1187. struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
  1188. if (td) {
  1189. u16 pid = r8a66597_read(r8a66597, td->pipe->pipectr) & PID;
  1190. if (pid == PID_NAK)
  1191. return -ECONNRESET;
  1192. else
  1193. return -EPIPE;
  1194. }
  1195. return 0;
  1196. }
  1197. static void irq_pipe_ready(struct r8a66597 *r8a66597)
  1198. {
  1199. u16 check;
  1200. u16 pipenum;
  1201. u16 mask;
  1202. struct r8a66597_td *td;
  1203. mask = r8a66597_read(r8a66597, BRDYSTS)
  1204. & r8a66597_read(r8a66597, BRDYENB);
  1205. r8a66597_write(r8a66597, ~mask, BRDYSTS);
  1206. if (mask & BRDY0) {
  1207. td = r8a66597_get_td(r8a66597, 0);
  1208. if (td && td->type == USB_PID_IN)
  1209. packet_read(r8a66597, 0);
  1210. else
  1211. pipe_irq_disable(r8a66597, 0);
  1212. check_next_phase(r8a66597, 0);
  1213. }
  1214. for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
  1215. check = 1 << pipenum;
  1216. if (mask & check) {
  1217. td = r8a66597_get_td(r8a66597, pipenum);
  1218. if (unlikely(!td))
  1219. continue;
  1220. if (td->type == USB_PID_IN)
  1221. packet_read(r8a66597, pipenum);
  1222. else if (td->type == USB_PID_OUT)
  1223. packet_write(r8a66597, pipenum);
  1224. }
  1225. }
  1226. }
  1227. static void irq_pipe_empty(struct r8a66597 *r8a66597)
  1228. {
  1229. u16 tmp;
  1230. u16 check;
  1231. u16 pipenum;
  1232. u16 mask;
  1233. struct r8a66597_td *td;
  1234. mask = r8a66597_read(r8a66597, BEMPSTS)
  1235. & r8a66597_read(r8a66597, BEMPENB);
  1236. r8a66597_write(r8a66597, ~mask, BEMPSTS);
  1237. if (mask & BEMP0) {
  1238. cfifo_change(r8a66597, 0);
  1239. td = r8a66597_get_td(r8a66597, 0);
  1240. if (td && td->type != USB_PID_OUT)
  1241. disable_irq_empty(r8a66597, 0);
  1242. check_next_phase(r8a66597, 0);
  1243. }
  1244. for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
  1245. check = 1 << pipenum;
  1246. if (mask & check) {
  1247. struct r8a66597_td *td;
  1248. td = r8a66597_get_td(r8a66597, pipenum);
  1249. if (unlikely(!td))
  1250. continue;
  1251. tmp = r8a66597_read(r8a66597, td->pipe->pipectr);
  1252. if ((tmp & INBUFM) == 0) {
  1253. disable_irq_empty(r8a66597, pipenum);
  1254. pipe_irq_disable(r8a66597, pipenum);
  1255. finish_request(r8a66597, td, pipenum, td->urb,
  1256. 0);
  1257. }
  1258. }
  1259. }
  1260. }
  1261. static void irq_pipe_nrdy(struct r8a66597 *r8a66597)
  1262. {
  1263. u16 check;
  1264. u16 pipenum;
  1265. u16 mask;
  1266. int status;
  1267. mask = r8a66597_read(r8a66597, NRDYSTS)
  1268. & r8a66597_read(r8a66597, NRDYENB);
  1269. r8a66597_write(r8a66597, ~mask, NRDYSTS);
  1270. if (mask & NRDY0) {
  1271. cfifo_change(r8a66597, 0);
  1272. status = get_urb_error(r8a66597, 0);
  1273. pipe_irq_disable(r8a66597, 0);
  1274. check_next_phase(r8a66597, status);
  1275. }
  1276. for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
  1277. check = 1 << pipenum;
  1278. if (mask & check) {
  1279. struct r8a66597_td *td;
  1280. td = r8a66597_get_td(r8a66597, pipenum);
  1281. if (unlikely(!td))
  1282. continue;
  1283. status = get_urb_error(r8a66597, pipenum);
  1284. pipe_irq_disable(r8a66597, pipenum);
  1285. pipe_stop(r8a66597, td->pipe);
  1286. finish_request(r8a66597, td, pipenum, td->urb, status);
  1287. }
  1288. }
  1289. }
  1290. static void r8a66597_root_hub_start_polling(struct r8a66597 *r8a66597)
  1291. {
  1292. mod_timer(&r8a66597->rh_timer,
  1293. jiffies + msecs_to_jiffies(R8A66597_RH_POLL_TIME));
  1294. }
  1295. static void start_root_hub_sampling(struct r8a66597 *r8a66597, int port)
  1296. {
  1297. struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
  1298. rh->old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST;
  1299. rh->scount = R8A66597_MAX_SAMPLING;
  1300. r8a66597->root_hub[port].port |= (1 << USB_PORT_FEAT_CONNECTION)
  1301. | (1 << USB_PORT_FEAT_C_CONNECTION);
  1302. r8a66597_root_hub_start_polling(r8a66597);
  1303. }
  1304. static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
  1305. {
  1306. struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
  1307. u16 intsts0, intsts1, intsts2;
  1308. u16 intenb0, intenb1, intenb2;
  1309. u16 mask0, mask1, mask2;
  1310. int status;
  1311. spin_lock(&r8a66597->lock);
  1312. intsts0 = r8a66597_read(r8a66597, INTSTS0);
  1313. intsts1 = r8a66597_read(r8a66597, INTSTS1);
  1314. intsts2 = r8a66597_read(r8a66597, INTSTS2);
  1315. intenb0 = r8a66597_read(r8a66597, INTENB0);
  1316. intenb1 = r8a66597_read(r8a66597, INTENB1);
  1317. intenb2 = r8a66597_read(r8a66597, INTENB2);
  1318. mask2 = intsts2 & intenb2;
  1319. mask1 = intsts1 & intenb1;
  1320. mask0 = intsts0 & intenb0 & (BEMP | NRDY | BRDY);
  1321. if (mask2) {
  1322. if (mask2 & ATTCH) {
  1323. r8a66597_write(r8a66597, ~ATTCH, INTSTS2);
  1324. r8a66597_bclr(r8a66597, ATTCHE, INTENB2);
  1325. /* start usb bus sampling */
  1326. start_root_hub_sampling(r8a66597, 1);
  1327. }
  1328. if (mask2 & DTCH) {
  1329. r8a66597_write(r8a66597, ~DTCH, INTSTS2);
  1330. r8a66597_bclr(r8a66597, DTCHE, INTENB2);
  1331. r8a66597_usb_disconnect(r8a66597, 1);
  1332. }
  1333. }
  1334. if (mask1) {
  1335. if (mask1 & ATTCH) {
  1336. r8a66597_write(r8a66597, ~ATTCH, INTSTS1);
  1337. r8a66597_bclr(r8a66597, ATTCHE, INTENB1);
  1338. /* start usb bus sampling */
  1339. start_root_hub_sampling(r8a66597, 0);
  1340. }
  1341. if (mask1 & DTCH) {
  1342. r8a66597_write(r8a66597, ~DTCH, INTSTS1);
  1343. r8a66597_bclr(r8a66597, DTCHE, INTENB1);
  1344. r8a66597_usb_disconnect(r8a66597, 0);
  1345. }
  1346. if (mask1 & SIGN) {
  1347. r8a66597_write(r8a66597, ~SIGN, INTSTS1);
  1348. status = get_urb_error(r8a66597, 0);
  1349. check_next_phase(r8a66597, status);
  1350. }
  1351. if (mask1 & SACK) {
  1352. r8a66597_write(r8a66597, ~SACK, INTSTS1);
  1353. check_next_phase(r8a66597, 0);
  1354. }
  1355. }
  1356. if (mask0) {
  1357. if (mask0 & BRDY)
  1358. irq_pipe_ready(r8a66597);
  1359. if (mask0 & BEMP)
  1360. irq_pipe_empty(r8a66597);
  1361. if (mask0 & NRDY)
  1362. irq_pipe_nrdy(r8a66597);
  1363. }
  1364. spin_unlock(&r8a66597->lock);
  1365. return IRQ_HANDLED;
  1366. }
  1367. /* this function must be called with interrupt disabled */
  1368. static void r8a66597_root_hub_control(struct r8a66597 *r8a66597, int port)
  1369. {
  1370. u16 tmp;
  1371. struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
  1372. if (rh->port & (1 << USB_PORT_FEAT_RESET)) {
  1373. unsigned long dvstctr_reg = get_dvstctr_reg(port);
  1374. tmp = r8a66597_read(r8a66597, dvstctr_reg);
  1375. if ((tmp & USBRST) == USBRST) {
  1376. r8a66597_mdfy(r8a66597, UACT, USBRST | UACT,
  1377. dvstctr_reg);
  1378. r8a66597_root_hub_start_polling(r8a66597);
  1379. } else
  1380. r8a66597_usb_connect(r8a66597, port);
  1381. }
  1382. if (!(rh->port & (1 << USB_PORT_FEAT_CONNECTION))) {
  1383. r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port));
  1384. r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
  1385. }
  1386. if (rh->scount > 0) {
  1387. tmp = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST;
  1388. if (tmp == rh->old_syssts) {
  1389. rh->scount--;
  1390. if (rh->scount == 0)
  1391. r8a66597_check_syssts(r8a66597, port, tmp);
  1392. else
  1393. r8a66597_root_hub_start_polling(r8a66597);
  1394. } else {
  1395. rh->scount = R8A66597_MAX_SAMPLING;
  1396. rh->old_syssts = tmp;
  1397. r8a66597_root_hub_start_polling(r8a66597);
  1398. }
  1399. }
  1400. }
  1401. static void r8a66597_interval_timer(unsigned long _r8a66597)
  1402. {
  1403. struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
  1404. unsigned long flags;
  1405. u16 pipenum;
  1406. struct r8a66597_td *td;
  1407. spin_lock_irqsave(&r8a66597->lock, flags);
  1408. for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
  1409. if (!(r8a66597->interval_map & (1 << pipenum)))
  1410. continue;
  1411. if (timer_pending(&r8a66597->interval_timer[pipenum]))
  1412. continue;
  1413. td = r8a66597_get_td(r8a66597, pipenum);
  1414. if (td)
  1415. start_transfer(r8a66597, td);
  1416. }
  1417. spin_unlock_irqrestore(&r8a66597->lock, flags);
  1418. }
  1419. static void r8a66597_td_timer(unsigned long _r8a66597)
  1420. {
  1421. struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
  1422. unsigned long flags;
  1423. u16 pipenum;
  1424. struct r8a66597_td *td, *new_td = NULL;
  1425. struct r8a66597_pipe *pipe;
  1426. spin_lock_irqsave(&r8a66597->lock, flags);
  1427. for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
  1428. if (!(r8a66597->timeout_map & (1 << pipenum)))
  1429. continue;
  1430. if (timer_pending(&r8a66597->td_timer[pipenum]))
  1431. continue;
  1432. td = r8a66597_get_td(r8a66597, pipenum);
  1433. if (!td) {
  1434. r8a66597->timeout_map &= ~(1 << pipenum);
  1435. continue;
  1436. }
  1437. if (td->urb->actual_length) {
  1438. set_td_timer(r8a66597, td);
  1439. break;
  1440. }
  1441. pipe = td->pipe;
  1442. pipe_stop(r8a66597, pipe);
  1443. new_td = td;
  1444. do {
  1445. list_move_tail(&new_td->queue,
  1446. &r8a66597->pipe_queue[pipenum]);
  1447. new_td = r8a66597_get_td(r8a66597, pipenum);
  1448. if (!new_td) {
  1449. new_td = td;
  1450. break;
  1451. }
  1452. } while (td != new_td && td->address == new_td->address);
  1453. start_transfer(r8a66597, new_td);
  1454. if (td == new_td)
  1455. r8a66597->timeout_map &= ~(1 << pipenum);
  1456. else
  1457. set_td_timer(r8a66597, new_td);
  1458. break;
  1459. }
  1460. spin_unlock_irqrestore(&r8a66597->lock, flags);
  1461. }
  1462. static void r8a66597_timer(unsigned long _r8a66597)
  1463. {
  1464. struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
  1465. unsigned long flags;
  1466. spin_lock_irqsave(&r8a66597->lock, flags);
  1467. r8a66597_root_hub_control(r8a66597, 0);
  1468. r8a66597_root_hub_control(r8a66597, 1);
  1469. spin_unlock_irqrestore(&r8a66597->lock, flags);
  1470. }
  1471. static int check_pipe_config(struct r8a66597 *r8a66597, struct urb *urb)
  1472. {
  1473. struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
  1474. if (dev && dev->address && dev->state != USB_STATE_CONFIGURED &&
  1475. (urb->dev->state == USB_STATE_CONFIGURED))
  1476. return 1;
  1477. else
  1478. return 0;
  1479. }
  1480. static int r8a66597_start(struct usb_hcd *hcd)
  1481. {
  1482. struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
  1483. hcd->state = HC_STATE_RUNNING;
  1484. return enable_controller(r8a66597);
  1485. }
  1486. static void r8a66597_stop(struct usb_hcd *hcd)
  1487. {
  1488. struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
  1489. disable_controller(r8a66597);
  1490. }
  1491. static void set_address_zero(struct r8a66597 *r8a66597, struct urb *urb)
  1492. {
  1493. unsigned int usb_address = usb_pipedevice(urb->pipe);
  1494. u16 root_port, hub_port;
  1495. if (usb_address == 0) {
  1496. get_port_number(urb->dev->devpath,
  1497. &root_port, &hub_port);
  1498. set_devadd_reg(r8a66597, 0,
  1499. get_r8a66597_usb_speed(urb->dev->speed),
  1500. get_parent_r8a66597_address(r8a66597, urb->dev),
  1501. hub_port, root_port);
  1502. }
  1503. }
  1504. static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597,
  1505. struct urb *urb,
  1506. struct usb_host_endpoint *hep)
  1507. {
  1508. struct r8a66597_td *td;
  1509. u16 pipenum;
  1510. td = kzalloc(sizeof(struct r8a66597_td), GFP_ATOMIC);
  1511. if (td == NULL)
  1512. return NULL;
  1513. pipenum = r8a66597_get_pipenum(urb, hep);
  1514. td->pipenum = pipenum;
  1515. td->pipe = hep->hcpriv;
  1516. td->urb = urb;
  1517. td->address = get_urb_to_r8a66597_addr(r8a66597, urb);
  1518. td->maxpacket = usb_maxpacket(urb->dev, urb->pipe,
  1519. !usb_pipein(urb->pipe));
  1520. if (usb_pipecontrol(urb->pipe))
  1521. td->type = USB_PID_SETUP;
  1522. else if (usb_pipein(urb->pipe))
  1523. td->type = USB_PID_IN;
  1524. else
  1525. td->type = USB_PID_OUT;
  1526. INIT_LIST_HEAD(&td->queue);
  1527. return td;
  1528. }
  1529. static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
  1530. struct urb *urb,
  1531. gfp_t mem_flags)
  1532. {
  1533. struct usb_host_endpoint *hep = urb->ep;
  1534. struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
  1535. struct r8a66597_td *td = NULL;
  1536. int ret, request = 0;
  1537. unsigned long flags;
  1538. spin_lock_irqsave(&r8a66597->lock, flags);
  1539. if (!get_urb_to_r8a66597_dev(r8a66597, urb)) {
  1540. ret = -ENODEV;
  1541. goto error_not_linked;
  1542. }
  1543. ret = usb_hcd_link_urb_to_ep(hcd, urb);
  1544. if (ret)
  1545. goto error_not_linked;
  1546. if (!hep->hcpriv) {
  1547. hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe),
  1548. GFP_ATOMIC);
  1549. if (!hep->hcpriv) {
  1550. ret = -ENOMEM;
  1551. goto error;
  1552. }
  1553. set_pipe_reg_addr(hep->hcpriv, R8A66597_PIPE_NO_DMA);
  1554. if (usb_pipeendpoint(urb->pipe))
  1555. init_pipe_info(r8a66597, urb, hep, &hep->desc);
  1556. }
  1557. if (unlikely(check_pipe_config(r8a66597, urb)))
  1558. init_pipe_config(r8a66597, urb);
  1559. set_address_zero(r8a66597, urb);
  1560. td = r8a66597_make_td(r8a66597, urb, hep);
  1561. if (td == NULL) {
  1562. ret = -ENOMEM;
  1563. goto error;
  1564. }
  1565. if (list_empty(&r8a66597->pipe_queue[td->pipenum]))
  1566. request = 1;
  1567. list_add_tail(&td->queue, &r8a66597->pipe_queue[td->pipenum]);
  1568. urb->hcpriv = td;
  1569. if (request) {
  1570. if (td->pipe->info.timer_interval) {
  1571. r8a66597->interval_map |= 1 << td->pipenum;
  1572. mod_timer(&r8a66597->interval_timer[td->pipenum],
  1573. jiffies + msecs_to_jiffies(
  1574. td->pipe->info.timer_interval));
  1575. } else {
  1576. ret = start_transfer(r8a66597, td);
  1577. if (ret < 0) {
  1578. list_del(&td->queue);
  1579. kfree(td);
  1580. }
  1581. }
  1582. } else
  1583. set_td_timer(r8a66597, td);
  1584. error:
  1585. if (ret)
  1586. usb_hcd_unlink_urb_from_ep(hcd, urb);
  1587. error_not_linked:
  1588. spin_unlock_irqrestore(&r8a66597->lock, flags);
  1589. return ret;
  1590. }
  1591. static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
  1592. int status)
  1593. {
  1594. struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
  1595. struct r8a66597_td *td;
  1596. unsigned long flags;
  1597. int rc;
  1598. spin_lock_irqsave(&r8a66597->lock, flags);
  1599. rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  1600. if (rc)
  1601. goto done;
  1602. if (urb->hcpriv) {
  1603. td = urb->hcpriv;
  1604. pipe_stop(r8a66597, td->pipe);
  1605. pipe_irq_disable(r8a66597, td->pipenum);
  1606. disable_irq_empty(r8a66597, td->pipenum);
  1607. finish_request(r8a66597, td, td->pipenum, urb, status);
  1608. }
  1609. done:
  1610. spin_unlock_irqrestore(&r8a66597->lock, flags);
  1611. return rc;
  1612. }
  1613. static void r8a66597_endpoint_disable(struct usb_hcd *hcd,
  1614. struct usb_host_endpoint *hep)
  1615. {
  1616. struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
  1617. struct r8a66597_pipe *pipe = (struct r8a66597_pipe *)hep->hcpriv;
  1618. struct r8a66597_td *td;
  1619. struct urb *urb = NULL;
  1620. u16 pipenum;
  1621. unsigned long flags;
  1622. if (pipe == NULL)
  1623. return;
  1624. pipenum = pipe->info.pipenum;
  1625. if (pipenum == 0) {
  1626. kfree(hep->hcpriv);
  1627. hep->hcpriv = NULL;
  1628. return;
  1629. }
  1630. spin_lock_irqsave(&r8a66597->lock, flags);
  1631. pipe_stop(r8a66597, pipe);
  1632. pipe_irq_disable(r8a66597, pipenum);
  1633. disable_irq_empty(r8a66597, pipenum);
  1634. td = r8a66597_get_td(r8a66597, pipenum);
  1635. if (td)
  1636. urb = td->urb;
  1637. finish_request(r8a66597, td, pipenum, urb, -ESHUTDOWN);
  1638. kfree(hep->hcpriv);
  1639. hep->hcpriv = NULL;
  1640. spin_unlock_irqrestore(&r8a66597->lock, flags);
  1641. }
  1642. static int r8a66597_get_frame(struct usb_hcd *hcd)
  1643. {
  1644. struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
  1645. return r8a66597_read(r8a66597, FRMNUM) & 0x03FF;
  1646. }
  1647. static void collect_usb_address_map(struct usb_device *udev, unsigned long *map)
  1648. {
  1649. int chix;
  1650. if (udev->state == USB_STATE_CONFIGURED &&
  1651. udev->parent && udev->parent->devnum > 1 &&
  1652. udev->parent->descriptor.bDeviceClass == USB_CLASS_HUB)
  1653. map[udev->devnum/32] |= (1 << (udev->devnum % 32));
  1654. for (chix = 0; chix < udev->maxchild; chix++) {
  1655. struct usb_device *childdev = udev->children[chix];
  1656. if (childdev)
  1657. collect_usb_address_map(childdev, map);
  1658. }
  1659. }
  1660. /* this function must be called with interrupt disabled */
  1661. static struct r8a66597_device *get_r8a66597_device(struct r8a66597 *r8a66597,
  1662. int addr)
  1663. {
  1664. struct r8a66597_device *dev;
  1665. struct list_head *list = &r8a66597->child_device;
  1666. list_for_each_entry(dev, list, device_list) {
  1667. if (!dev)
  1668. continue;
  1669. if (dev->usb_address != addr)
  1670. continue;
  1671. return dev;
  1672. }
  1673. err("get_r8a66597_device fail.(%d)\n", addr);
  1674. return NULL;
  1675. }
  1676. static void update_usb_address_map(struct r8a66597 *r8a66597,
  1677. struct usb_device *root_hub,
  1678. unsigned long *map)
  1679. {
  1680. int i, j, addr;
  1681. unsigned long diff;
  1682. unsigned long flags;
  1683. for (i = 0; i < 4; i++) {
  1684. diff = r8a66597->child_connect_map[i] ^ map[i];
  1685. if (!diff)
  1686. continue;
  1687. for (j = 0; j < 32; j++) {
  1688. if (!(diff & (1 << j)))
  1689. continue;
  1690. addr = i * 32 + j;
  1691. if (map[i] & (1 << j))
  1692. set_child_connect_map(r8a66597, addr);
  1693. else {
  1694. struct r8a66597_device *dev;
  1695. spin_lock_irqsave(&r8a66597->lock, flags);
  1696. dev = get_r8a66597_device(r8a66597, addr);
  1697. disable_r8a66597_pipe_all(r8a66597, dev);
  1698. free_usb_address(r8a66597, dev);
  1699. put_child_connect_map(r8a66597, addr);
  1700. spin_unlock_irqrestore(&r8a66597->lock, flags);
  1701. }
  1702. }
  1703. }
  1704. }
  1705. static void r8a66597_check_detect_child(struct r8a66597 *r8a66597,
  1706. struct usb_hcd *hcd)
  1707. {
  1708. struct usb_bus *bus;
  1709. unsigned long now_map[4];
  1710. memset(now_map, 0, sizeof(now_map));
  1711. list_for_each_entry(bus, &usb_bus_list, bus_list) {
  1712. if (!bus->root_hub)
  1713. continue;
  1714. if (bus->busnum != hcd->self.busnum)
  1715. continue;
  1716. collect_usb_address_map(bus->root_hub, now_map);
  1717. update_usb_address_map(r8a66597, bus->root_hub, now_map);
  1718. }
  1719. }
  1720. static int r8a66597_hub_status_data(struct usb_hcd *hcd, char *buf)
  1721. {
  1722. struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
  1723. unsigned long flags;
  1724. int i;
  1725. r8a66597_check_detect_child(r8a66597, hcd);
  1726. spin_lock_irqsave(&r8a66597->lock, flags);
  1727. *buf = 0; /* initialize (no change) */
  1728. for (i = 0; i < R8A66597_MAX_ROOT_HUB; i++) {
  1729. if (r8a66597->root_hub[i].port & 0xffff0000)
  1730. *buf |= 1 << (i + 1);
  1731. }
  1732. spin_unlock_irqrestore(&r8a66597->lock, flags);
  1733. return (*buf != 0);
  1734. }
  1735. static void r8a66597_hub_descriptor(struct r8a66597 *r8a66597,
  1736. struct usb_hub_descriptor *desc)
  1737. {
  1738. desc->bDescriptorType = 0x29;
  1739. desc->bHubContrCurrent = 0;
  1740. desc->bNbrPorts = R8A66597_MAX_ROOT_HUB;
  1741. desc->bDescLength = 9;
  1742. desc->bPwrOn2PwrGood = 0;
  1743. desc->wHubCharacteristics = cpu_to_le16(0x0011);
  1744. desc->bitmap[0] = ((1 << R8A66597_MAX_ROOT_HUB) - 1) << 1;
  1745. desc->bitmap[1] = ~0;
  1746. }
  1747. static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  1748. u16 wIndex, char *buf, u16 wLength)
  1749. {
  1750. struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
  1751. int ret;
  1752. int port = (wIndex & 0x00FF) - 1;
  1753. struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
  1754. unsigned long flags;
  1755. ret = 0;
  1756. spin_lock_irqsave(&r8a66597->lock, flags);
  1757. switch (typeReq) {
  1758. case ClearHubFeature:
  1759. case SetHubFeature:
  1760. switch (wValue) {
  1761. case C_HUB_OVER_CURRENT:
  1762. case C_HUB_LOCAL_POWER:
  1763. break;
  1764. default:
  1765. goto error;
  1766. }
  1767. break;
  1768. case ClearPortFeature:
  1769. if (wIndex > R8A66597_MAX_ROOT_HUB)
  1770. goto error;
  1771. if (wLength != 0)
  1772. goto error;
  1773. switch (wValue) {
  1774. case USB_PORT_FEAT_ENABLE:
  1775. rh->port &= (1 << USB_PORT_FEAT_POWER);
  1776. break;
  1777. case USB_PORT_FEAT_SUSPEND:
  1778. break;
  1779. case USB_PORT_FEAT_POWER:
  1780. r8a66597_port_power(r8a66597, port, 0);
  1781. break;
  1782. case USB_PORT_FEAT_C_ENABLE:
  1783. case USB_PORT_FEAT_C_SUSPEND:
  1784. case USB_PORT_FEAT_C_CONNECTION:
  1785. case USB_PORT_FEAT_C_OVER_CURRENT:
  1786. case USB_PORT_FEAT_C_RESET:
  1787. break;
  1788. default:
  1789. goto error;
  1790. }
  1791. rh->port &= ~(1 << wValue);
  1792. break;
  1793. case GetHubDescriptor:
  1794. r8a66597_hub_descriptor(r8a66597,
  1795. (struct usb_hub_descriptor *)buf);
  1796. break;
  1797. case GetHubStatus:
  1798. *buf = 0x00;
  1799. break;
  1800. case GetPortStatus:
  1801. if (wIndex > R8A66597_MAX_ROOT_HUB)
  1802. goto error;
  1803. *(u32 *)buf = cpu_to_le32(rh->port);
  1804. break;
  1805. case SetPortFeature:
  1806. if (wIndex > R8A66597_MAX_ROOT_HUB)
  1807. goto error;
  1808. if (wLength != 0)
  1809. goto error;
  1810. switch (wValue) {
  1811. case USB_PORT_FEAT_SUSPEND:
  1812. break;
  1813. case USB_PORT_FEAT_POWER:
  1814. r8a66597_port_power(r8a66597, port, 1);
  1815. rh->port |= (1 << USB_PORT_FEAT_POWER);
  1816. break;
  1817. case USB_PORT_FEAT_RESET: {
  1818. struct r8a66597_device *dev = rh->dev;
  1819. rh->port |= (1 << USB_PORT_FEAT_RESET);
  1820. disable_r8a66597_pipe_all(r8a66597, dev);
  1821. free_usb_address(r8a66597, dev);
  1822. r8a66597_mdfy(r8a66597, USBRST, USBRST | UACT,
  1823. get_dvstctr_reg(port));
  1824. mod_timer(&r8a66597->rh_timer,
  1825. jiffies + msecs_to_jiffies(50));
  1826. }
  1827. break;
  1828. default:
  1829. goto error;
  1830. }
  1831. rh->port |= 1 << wValue;
  1832. break;
  1833. default:
  1834. error:
  1835. ret = -EPIPE;
  1836. break;
  1837. }
  1838. spin_unlock_irqrestore(&r8a66597->lock, flags);
  1839. return ret;
  1840. }
  1841. static struct hc_driver r8a66597_hc_driver = {
  1842. .description = hcd_name,
  1843. .hcd_priv_size = sizeof(struct r8a66597),
  1844. .irq = r8a66597_irq,
  1845. /*
  1846. * generic hardware linkage
  1847. */
  1848. .flags = HCD_USB2,
  1849. .start = r8a66597_start,
  1850. .stop = r8a66597_stop,
  1851. /*
  1852. * managing i/o requests and associated device resources
  1853. */
  1854. .urb_enqueue = r8a66597_urb_enqueue,
  1855. .urb_dequeue = r8a66597_urb_dequeue,
  1856. .endpoint_disable = r8a66597_endpoint_disable,
  1857. /*
  1858. * periodic schedule support
  1859. */
  1860. .get_frame_number = r8a66597_get_frame,
  1861. /*
  1862. * root hub support
  1863. */
  1864. .hub_status_data = r8a66597_hub_status_data,
  1865. .hub_control = r8a66597_hub_control,
  1866. };
  1867. #if defined(CONFIG_PM)
  1868. static int r8a66597_suspend(struct platform_device *pdev, pm_message_t state)
  1869. {
  1870. return 0;
  1871. }
  1872. static int r8a66597_resume(struct platform_device *pdev)
  1873. {
  1874. return 0;
  1875. }
  1876. #else /* if defined(CONFIG_PM) */
  1877. #define r8a66597_suspend NULL
  1878. #define r8a66597_resume NULL
  1879. #endif
  1880. static int __init_or_module r8a66597_remove(struct platform_device *pdev)
  1881. {
  1882. struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev);
  1883. struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
  1884. del_timer_sync(&r8a66597->rh_timer);
  1885. usb_remove_hcd(hcd);
  1886. iounmap((void *)r8a66597->reg);
  1887. usb_put_hcd(hcd);
  1888. return 0;
  1889. }
  1890. #define resource_len(r) (((r)->end - (r)->start) + 1)
  1891. static int __init r8a66597_probe(struct platform_device *pdev)
  1892. {
  1893. struct resource *res = NULL;
  1894. int irq = -1;
  1895. void __iomem *reg = NULL;
  1896. struct usb_hcd *hcd = NULL;
  1897. struct r8a66597 *r8a66597;
  1898. int ret = 0;
  1899. int i;
  1900. if (pdev->dev.dma_mask) {
  1901. ret = -EINVAL;
  1902. err("dma not support");
  1903. goto clean_up;
  1904. }
  1905. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  1906. (char *)hcd_name);
  1907. if (!res) {
  1908. ret = -ENODEV;
  1909. err("platform_get_resource_byname error.");
  1910. goto clean_up;
  1911. }
  1912. irq = platform_get_irq(pdev, 0);
  1913. if (irq < 0) {
  1914. ret = -ENODEV;
  1915. err("platform_get_irq error.");
  1916. goto clean_up;
  1917. }
  1918. reg = ioremap(res->start, resource_len(res));
  1919. if (reg == NULL) {
  1920. ret = -ENOMEM;
  1921. err("ioremap error.");
  1922. goto clean_up;
  1923. }
  1924. /* initialize hcd */
  1925. hcd = usb_create_hcd(&r8a66597_hc_driver, &pdev->dev, (char *)hcd_name);
  1926. if (!hcd) {
  1927. ret = -ENOMEM;
  1928. err("Failed to create hcd");
  1929. goto clean_up;
  1930. }
  1931. r8a66597 = hcd_to_r8a66597(hcd);
  1932. memset(r8a66597, 0, sizeof(struct r8a66597));
  1933. dev_set_drvdata(&pdev->dev, r8a66597);
  1934. spin_lock_init(&r8a66597->lock);
  1935. init_timer(&r8a66597->rh_timer);
  1936. r8a66597->rh_timer.function = r8a66597_timer;
  1937. r8a66597->rh_timer.data = (unsigned long)r8a66597;
  1938. r8a66597->reg = (unsigned long)reg;
  1939. for (i = 0; i < R8A66597_MAX_NUM_PIPE; i++) {
  1940. INIT_LIST_HEAD(&r8a66597->pipe_queue[i]);
  1941. init_timer(&r8a66597->td_timer[i]);
  1942. r8a66597->td_timer[i].function = r8a66597_td_timer;
  1943. r8a66597->td_timer[i].data = (unsigned long)r8a66597;
  1944. setup_timer(&r8a66597->interval_timer[i],
  1945. r8a66597_interval_timer,
  1946. (unsigned long)r8a66597);
  1947. }
  1948. INIT_LIST_HEAD(&r8a66597->child_device);
  1949. hcd->rsrc_start = res->start;
  1950. ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
  1951. if (ret != 0) {
  1952. err("Failed to add hcd");
  1953. goto clean_up;
  1954. }
  1955. return 0;
  1956. clean_up:
  1957. if (reg)
  1958. iounmap(reg);
  1959. return ret;
  1960. }
  1961. static struct platform_driver r8a66597_driver = {
  1962. .probe = r8a66597_probe,
  1963. .remove = r8a66597_remove,
  1964. .suspend = r8a66597_suspend,
  1965. .resume = r8a66597_resume,
  1966. .driver = {
  1967. .name = (char *) hcd_name,
  1968. .owner = THIS_MODULE,
  1969. },
  1970. };
  1971. static int __init r8a66597_init(void)
  1972. {
  1973. if (usb_disabled())
  1974. return -ENODEV;
  1975. info("driver %s, %s", hcd_name, DRIVER_VERSION);
  1976. return platform_driver_register(&r8a66597_driver);
  1977. }
  1978. module_init(r8a66597_init);
  1979. static void __exit r8a66597_cleanup(void)
  1980. {
  1981. platform_driver_unregister(&r8a66597_driver);
  1982. }
  1983. module_exit(r8a66597_cleanup);