io_ti.c 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009
  1. /*
  2. * Edgeport USB Serial Converter driver
  3. *
  4. * Copyright (C) 2000-2002 Inside Out Networks, All rights reserved.
  5. * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Supports the following devices:
  13. * EP/1 EP/2 EP/4 EP/21 EP/22 EP/221 EP/42 EP/421 WATCHPORT
  14. *
  15. * For questions or problems with this driver, contact Inside Out
  16. * Networks technical support, or Peter Berger <pberger@brimson.com>,
  17. * or Al Borchers <alborchers@steinerpoint.com>.
  18. *
  19. * Version history:
  20. *
  21. * July 11, 2002 Removed 4 port device structure since all TI UMP
  22. * chips have only 2 ports
  23. * David Iacovelli (davidi@ionetworks.com)
  24. *
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/jiffies.h>
  28. #include <linux/errno.h>
  29. #include <linux/init.h>
  30. #include <linux/slab.h>
  31. #include <linux/tty.h>
  32. #include <linux/tty_driver.h>
  33. #include <linux/tty_flip.h>
  34. #include <linux/module.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/mutex.h>
  37. #include <linux/serial.h>
  38. #include <linux/ioctl.h>
  39. #include <linux/firmware.h>
  40. #include <linux/uaccess.h>
  41. #include <linux/usb.h>
  42. #include <linux/usb/serial.h>
  43. #include "io_16654.h"
  44. #include "io_usbvend.h"
  45. #include "io_ti.h"
  46. /*
  47. * Version Information
  48. */
  49. #define DRIVER_VERSION "v0.7mode043006"
  50. #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
  51. #define DRIVER_DESC "Edgeport USB Serial Driver"
  52. #define EPROM_PAGE_SIZE 64
  53. struct edgeport_uart_buf_desc {
  54. __u32 count; /* Number of bytes currently in buffer */
  55. };
  56. /* different hardware types */
  57. #define HARDWARE_TYPE_930 0
  58. #define HARDWARE_TYPE_TIUMP 1
  59. /* IOCTL_PRIVATE_TI_GET_MODE Definitions */
  60. #define TI_MODE_CONFIGURING 0 /* Device has not entered start device */
  61. #define TI_MODE_BOOT 1 /* Staying in boot mode */
  62. #define TI_MODE_DOWNLOAD 2 /* Made it to download mode */
  63. #define TI_MODE_TRANSITIONING 3 /* Currently in boot mode but
  64. transitioning to download mode */
  65. /* read urb state */
  66. #define EDGE_READ_URB_RUNNING 0
  67. #define EDGE_READ_URB_STOPPING 1
  68. #define EDGE_READ_URB_STOPPED 2
  69. #define EDGE_LOW_LATENCY 1
  70. #define EDGE_CLOSING_WAIT 4000 /* in .01 sec */
  71. #define EDGE_OUT_BUF_SIZE 1024
  72. /* Product information read from the Edgeport */
  73. struct product_info {
  74. int TiMode; /* Current TI Mode */
  75. __u8 hardware_type; /* Type of hardware */
  76. } __attribute__((packed));
  77. /* circular buffer */
  78. struct edge_buf {
  79. unsigned int buf_size;
  80. char *buf_buf;
  81. char *buf_get;
  82. char *buf_put;
  83. };
  84. struct edgeport_port {
  85. __u16 uart_base;
  86. __u16 dma_address;
  87. __u8 shadow_msr;
  88. __u8 shadow_mcr;
  89. __u8 shadow_lsr;
  90. __u8 lsr_mask;
  91. __u32 ump_read_timeout; /* Number of miliseconds the UMP will
  92. wait without data before completing
  93. a read short */
  94. int baud_rate;
  95. int close_pending;
  96. int lsr_event;
  97. struct edgeport_uart_buf_desc tx;
  98. struct async_icount icount;
  99. wait_queue_head_t delta_msr_wait; /* for handling sleeping while
  100. waiting for msr change to
  101. happen */
  102. struct edgeport_serial *edge_serial;
  103. struct usb_serial_port *port;
  104. __u8 bUartMode; /* Port type, 0: RS232, etc. */
  105. spinlock_t ep_lock;
  106. int ep_read_urb_state;
  107. int ep_write_urb_in_use;
  108. struct edge_buf *ep_out_buf;
  109. };
  110. struct edgeport_serial {
  111. struct product_info product_info;
  112. u8 TI_I2C_Type; /* Type of I2C in UMP */
  113. u8 TiReadI2C; /* Set to TRUE if we have read the
  114. I2c in Boot Mode */
  115. struct mutex es_lock;
  116. int num_ports_open;
  117. struct usb_serial *serial;
  118. };
  119. /* Devices that this driver supports */
  120. static struct usb_device_id edgeport_1port_id_table [] = {
  121. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
  122. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
  123. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
  124. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) },
  125. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) },
  126. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) },
  127. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) },
  128. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) },
  129. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) },
  130. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) },
  131. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) },
  132. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) },
  133. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) },
  134. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) },
  135. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) },
  136. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) },
  137. { }
  138. };
  139. static struct usb_device_id edgeport_2port_id_table [] = {
  140. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
  141. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
  142. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
  143. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
  144. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
  145. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
  146. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
  147. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
  148. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) },
  149. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) },
  150. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) },
  151. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) },
  152. /* The 4, 8 and 16 port devices show up as multiple 2 port devices */
  153. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) },
  154. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8) },
  155. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) },
  156. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) },
  157. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) },
  158. { }
  159. };
  160. /* Devices that this driver supports */
  161. static struct usb_device_id id_table_combined [] = {
  162. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
  163. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
  164. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
  165. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) },
  166. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) },
  167. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) },
  168. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) },
  169. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) },
  170. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) },
  171. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) },
  172. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) },
  173. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) },
  174. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) },
  175. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) },
  176. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) },
  177. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) },
  178. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
  179. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
  180. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
  181. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
  182. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
  183. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
  184. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
  185. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
  186. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) },
  187. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) },
  188. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) },
  189. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) },
  190. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) },
  191. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8) },
  192. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) },
  193. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) },
  194. { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) },
  195. { }
  196. };
  197. MODULE_DEVICE_TABLE(usb, id_table_combined);
  198. static struct usb_driver io_driver = {
  199. .name = "io_ti",
  200. .probe = usb_serial_probe,
  201. .disconnect = usb_serial_disconnect,
  202. .id_table = id_table_combined,
  203. .no_dynamic_id = 1,
  204. };
  205. static unsigned char OperationalMajorVersion;
  206. static unsigned char OperationalMinorVersion;
  207. static unsigned short OperationalBuildNumber;
  208. static int debug;
  209. static int low_latency = EDGE_LOW_LATENCY;
  210. static int closing_wait = EDGE_CLOSING_WAIT;
  211. static int ignore_cpu_rev;
  212. static int default_uart_mode; /* RS232 */
  213. static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
  214. unsigned char *data, int length);
  215. static void stop_read(struct edgeport_port *edge_port);
  216. static int restart_read(struct edgeport_port *edge_port);
  217. static void edge_set_termios(struct tty_struct *tty,
  218. struct usb_serial_port *port, struct ktermios *old_termios);
  219. static void edge_send(struct tty_struct *tty);
  220. /* sysfs attributes */
  221. static int edge_create_sysfs_attrs(struct usb_serial_port *port);
  222. static int edge_remove_sysfs_attrs(struct usb_serial_port *port);
  223. /* circular buffer */
  224. static struct edge_buf *edge_buf_alloc(unsigned int size);
  225. static void edge_buf_free(struct edge_buf *eb);
  226. static void edge_buf_clear(struct edge_buf *eb);
  227. static unsigned int edge_buf_data_avail(struct edge_buf *eb);
  228. static unsigned int edge_buf_space_avail(struct edge_buf *eb);
  229. static unsigned int edge_buf_put(struct edge_buf *eb, const char *buf,
  230. unsigned int count);
  231. static unsigned int edge_buf_get(struct edge_buf *eb, char *buf,
  232. unsigned int count);
  233. static int ti_vread_sync(struct usb_device *dev, __u8 request,
  234. __u16 value, __u16 index, u8 *data, int size)
  235. {
  236. int status;
  237. status = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request,
  238. (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN),
  239. value, index, data, size, 1000);
  240. if (status < 0)
  241. return status;
  242. if (status != size) {
  243. dbg("%s - wanted to write %d, but only wrote %d",
  244. __func__, size, status);
  245. return -ECOMM;
  246. }
  247. return 0;
  248. }
  249. static int ti_vsend_sync(struct usb_device *dev, __u8 request,
  250. __u16 value, __u16 index, u8 *data, int size)
  251. {
  252. int status;
  253. status = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
  254. (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT),
  255. value, index, data, size, 1000);
  256. if (status < 0)
  257. return status;
  258. if (status != size) {
  259. dbg("%s - wanted to write %d, but only wrote %d",
  260. __func__, size, status);
  261. return -ECOMM;
  262. }
  263. return 0;
  264. }
  265. static int send_cmd(struct usb_device *dev, __u8 command,
  266. __u8 moduleid, __u16 value, u8 *data,
  267. int size)
  268. {
  269. return ti_vsend_sync(dev, command, value, moduleid, data, size);
  270. }
  271. /* clear tx/rx buffers and fifo in TI UMP */
  272. static int purge_port(struct usb_serial_port *port, __u16 mask)
  273. {
  274. int port_number = port->number - port->serial->minor;
  275. dbg("%s - port %d, mask %x", __func__, port_number, mask);
  276. return send_cmd(port->serial->dev,
  277. UMPC_PURGE_PORT,
  278. (__u8)(UMPM_UART1_PORT + port_number),
  279. mask,
  280. NULL,
  281. 0);
  282. }
  283. /**
  284. * read_download_mem - Read edgeport memory from TI chip
  285. * @dev: usb device pointer
  286. * @start_address: Device CPU address at which to read
  287. * @length: Length of above data
  288. * @address_type: Can read both XDATA and I2C
  289. * @buffer: pointer to input data buffer
  290. */
  291. static int read_download_mem(struct usb_device *dev, int start_address,
  292. int length, __u8 address_type, __u8 *buffer)
  293. {
  294. int status = 0;
  295. __u8 read_length;
  296. __be16 be_start_address;
  297. dbg("%s - @ %x for %d", __func__, start_address, length);
  298. /* Read in blocks of 64 bytes
  299. * (TI firmware can't handle more than 64 byte reads)
  300. */
  301. while (length) {
  302. if (length > 64)
  303. read_length = 64;
  304. else
  305. read_length = (__u8)length;
  306. if (read_length > 1) {
  307. dbg("%s - @ %x for %d", __func__,
  308. start_address, read_length);
  309. }
  310. be_start_address = cpu_to_be16(start_address);
  311. status = ti_vread_sync(dev, UMPC_MEMORY_READ,
  312. (__u16)address_type,
  313. (__force __u16)be_start_address,
  314. buffer, read_length);
  315. if (status) {
  316. dbg("%s - ERROR %x", __func__, status);
  317. return status;
  318. }
  319. if (read_length > 1)
  320. usb_serial_debug_data(debug, &dev->dev, __func__,
  321. read_length, buffer);
  322. /* Update pointers/length */
  323. start_address += read_length;
  324. buffer += read_length;
  325. length -= read_length;
  326. }
  327. return status;
  328. }
  329. static int read_ram(struct usb_device *dev, int start_address,
  330. int length, __u8 *buffer)
  331. {
  332. return read_download_mem(dev, start_address, length,
  333. DTK_ADDR_SPACE_XDATA, buffer);
  334. }
  335. /* Read edgeport memory to a given block */
  336. static int read_boot_mem(struct edgeport_serial *serial,
  337. int start_address, int length, __u8 *buffer)
  338. {
  339. int status = 0;
  340. int i;
  341. for (i = 0; i < length; i++) {
  342. status = ti_vread_sync(serial->serial->dev,
  343. UMPC_MEMORY_READ, serial->TI_I2C_Type,
  344. (__u16)(start_address+i), &buffer[i], 0x01);
  345. if (status) {
  346. dbg("%s - ERROR %x", __func__, status);
  347. return status;
  348. }
  349. }
  350. dbg("%s - start_address = %x, length = %d",
  351. __func__, start_address, length);
  352. usb_serial_debug_data(debug, &serial->serial->dev->dev,
  353. __func__, length, buffer);
  354. serial->TiReadI2C = 1;
  355. return status;
  356. }
  357. /* Write given block to TI EPROM memory */
  358. static int write_boot_mem(struct edgeport_serial *serial,
  359. int start_address, int length, __u8 *buffer)
  360. {
  361. int status = 0;
  362. int i;
  363. __u8 temp;
  364. /* Must do a read before write */
  365. if (!serial->TiReadI2C) {
  366. status = read_boot_mem(serial, 0, 1, &temp);
  367. if (status)
  368. return status;
  369. }
  370. for (i = 0; i < length; ++i) {
  371. status = ti_vsend_sync(serial->serial->dev,
  372. UMPC_MEMORY_WRITE, buffer[i],
  373. (__u16)(i + start_address), NULL, 0);
  374. if (status)
  375. return status;
  376. }
  377. dbg("%s - start_sddr = %x, length = %d",
  378. __func__, start_address, length);
  379. usb_serial_debug_data(debug, &serial->serial->dev->dev,
  380. __func__, length, buffer);
  381. return status;
  382. }
  383. /* Write edgeport I2C memory to TI chip */
  384. static int write_i2c_mem(struct edgeport_serial *serial,
  385. int start_address, int length, __u8 address_type, __u8 *buffer)
  386. {
  387. int status = 0;
  388. int write_length;
  389. __be16 be_start_address;
  390. /* We can only send a maximum of 1 aligned byte page at a time */
  391. /* calulate the number of bytes left in the first page */
  392. write_length = EPROM_PAGE_SIZE -
  393. (start_address & (EPROM_PAGE_SIZE - 1));
  394. if (write_length > length)
  395. write_length = length;
  396. dbg("%s - BytesInFirstPage Addr = %x, length = %d",
  397. __func__, start_address, write_length);
  398. usb_serial_debug_data(debug, &serial->serial->dev->dev,
  399. __func__, write_length, buffer);
  400. /* Write first page */
  401. be_start_address = cpu_to_be16(start_address);
  402. status = ti_vsend_sync(serial->serial->dev,
  403. UMPC_MEMORY_WRITE, (__u16)address_type,
  404. (__force __u16)be_start_address,
  405. buffer, write_length);
  406. if (status) {
  407. dbg("%s - ERROR %d", __func__, status);
  408. return status;
  409. }
  410. length -= write_length;
  411. start_address += write_length;
  412. buffer += write_length;
  413. /* We should be aligned now -- can write
  414. max page size bytes at a time */
  415. while (length) {
  416. if (length > EPROM_PAGE_SIZE)
  417. write_length = EPROM_PAGE_SIZE;
  418. else
  419. write_length = length;
  420. dbg("%s - Page Write Addr = %x, length = %d",
  421. __func__, start_address, write_length);
  422. usb_serial_debug_data(debug, &serial->serial->dev->dev,
  423. __func__, write_length, buffer);
  424. /* Write next page */
  425. be_start_address = cpu_to_be16(start_address);
  426. status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE,
  427. (__u16)address_type,
  428. (__force __u16)be_start_address,
  429. buffer, write_length);
  430. if (status) {
  431. dev_err(&serial->serial->dev->dev, "%s - ERROR %d\n",
  432. __func__, status);
  433. return status;
  434. }
  435. length -= write_length;
  436. start_address += write_length;
  437. buffer += write_length;
  438. }
  439. return status;
  440. }
  441. /* Examine the UMP DMA registers and LSR
  442. *
  443. * Check the MSBit of the X and Y DMA byte count registers.
  444. * A zero in this bit indicates that the TX DMA buffers are empty
  445. * then check the TX Empty bit in the UART.
  446. */
  447. static int tx_active(struct edgeport_port *port)
  448. {
  449. int status;
  450. struct out_endpoint_desc_block *oedb;
  451. __u8 *lsr;
  452. int bytes_left = 0;
  453. oedb = kmalloc(sizeof(*oedb), GFP_KERNEL);
  454. if (!oedb) {
  455. dev_err(&port->port->dev, "%s - out of memory\n", __func__);
  456. return -ENOMEM;
  457. }
  458. lsr = kmalloc(1, GFP_KERNEL); /* Sigh, that's right, just one byte,
  459. as not all platforms can do DMA
  460. from stack */
  461. if (!lsr) {
  462. kfree(oedb);
  463. return -ENOMEM;
  464. }
  465. /* Read the DMA Count Registers */
  466. status = read_ram(port->port->serial->dev, port->dma_address,
  467. sizeof(*oedb), (void *)oedb);
  468. if (status)
  469. goto exit_is_tx_active;
  470. dbg("%s - XByteCount 0x%X", __func__, oedb->XByteCount);
  471. /* and the LSR */
  472. status = read_ram(port->port->serial->dev,
  473. port->uart_base + UMPMEM_OFFS_UART_LSR, 1, lsr);
  474. if (status)
  475. goto exit_is_tx_active;
  476. dbg("%s - LSR = 0x%X", __func__, *lsr);
  477. /* If either buffer has data or we are transmitting then return TRUE */
  478. if ((oedb->XByteCount & 0x80) != 0)
  479. bytes_left += 64;
  480. if ((*lsr & UMP_UART_LSR_TX_MASK) == 0)
  481. bytes_left += 1;
  482. /* We return Not Active if we get any kind of error */
  483. exit_is_tx_active:
  484. dbg("%s - return %d", __func__, bytes_left);
  485. kfree(lsr);
  486. kfree(oedb);
  487. return bytes_left;
  488. }
  489. static void chase_port(struct edgeport_port *port, unsigned long timeout,
  490. int flush)
  491. {
  492. int baud_rate;
  493. struct tty_struct *tty = port->port->port.tty;
  494. wait_queue_t wait;
  495. unsigned long flags;
  496. if (!timeout)
  497. timeout = (HZ * EDGE_CLOSING_WAIT)/100;
  498. /* wait for data to drain from the buffer */
  499. spin_lock_irqsave(&port->ep_lock, flags);
  500. init_waitqueue_entry(&wait, current);
  501. add_wait_queue(&tty->write_wait, &wait);
  502. for (;;) {
  503. set_current_state(TASK_INTERRUPTIBLE);
  504. if (edge_buf_data_avail(port->ep_out_buf) == 0
  505. || timeout == 0 || signal_pending(current)
  506. || !usb_get_intfdata(port->port->serial->interface))
  507. /* disconnect */
  508. break;
  509. spin_unlock_irqrestore(&port->ep_lock, flags);
  510. timeout = schedule_timeout(timeout);
  511. spin_lock_irqsave(&port->ep_lock, flags);
  512. }
  513. set_current_state(TASK_RUNNING);
  514. remove_wait_queue(&tty->write_wait, &wait);
  515. if (flush)
  516. edge_buf_clear(port->ep_out_buf);
  517. spin_unlock_irqrestore(&port->ep_lock, flags);
  518. /* wait for data to drain from the device */
  519. timeout += jiffies;
  520. while ((long)(jiffies - timeout) < 0 && !signal_pending(current)
  521. && usb_get_intfdata(port->port->serial->interface)) {
  522. /* not disconnected */
  523. if (!tx_active(port))
  524. break;
  525. msleep(10);
  526. }
  527. /* disconnected */
  528. if (!usb_get_intfdata(port->port->serial->interface))
  529. return;
  530. /* wait one more character time, based on baud rate */
  531. /* (tx_active doesn't seem to wait for the last byte) */
  532. baud_rate = port->baud_rate;
  533. if (baud_rate == 0)
  534. baud_rate = 50;
  535. msleep(max(1, DIV_ROUND_UP(10000, baud_rate)));
  536. }
  537. static int choose_config(struct usb_device *dev)
  538. {
  539. /*
  540. * There may be multiple configurations on this device, in which case
  541. * we would need to read and parse all of them to find out which one
  542. * we want. However, we just support one config at this point,
  543. * configuration # 1, which is Config Descriptor 0.
  544. */
  545. dbg("%s - Number of Interfaces = %d",
  546. __func__, dev->config->desc.bNumInterfaces);
  547. dbg("%s - MAX Power = %d",
  548. __func__, dev->config->desc.bMaxPower * 2);
  549. if (dev->config->desc.bNumInterfaces != 1) {
  550. dev_err(&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n",
  551. __func__);
  552. return -ENODEV;
  553. }
  554. return 0;
  555. }
  556. static int read_rom(struct edgeport_serial *serial,
  557. int start_address, int length, __u8 *buffer)
  558. {
  559. int status;
  560. if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
  561. status = read_download_mem(serial->serial->dev,
  562. start_address,
  563. length,
  564. serial->TI_I2C_Type,
  565. buffer);
  566. } else {
  567. status = read_boot_mem(serial, start_address, length,
  568. buffer);
  569. }
  570. return status;
  571. }
  572. static int write_rom(struct edgeport_serial *serial, int start_address,
  573. int length, __u8 *buffer)
  574. {
  575. if (serial->product_info.TiMode == TI_MODE_BOOT)
  576. return write_boot_mem(serial, start_address, length,
  577. buffer);
  578. if (serial->product_info.TiMode == TI_MODE_DOWNLOAD)
  579. return write_i2c_mem(serial, start_address, length,
  580. serial->TI_I2C_Type, buffer);
  581. return -EINVAL;
  582. }
  583. /* Read a descriptor header from I2C based on type */
  584. static int get_descriptor_addr(struct edgeport_serial *serial,
  585. int desc_type, struct ti_i2c_desc *rom_desc)
  586. {
  587. int start_address;
  588. int status;
  589. /* Search for requested descriptor in I2C */
  590. start_address = 2;
  591. do {
  592. status = read_rom(serial,
  593. start_address,
  594. sizeof(struct ti_i2c_desc),
  595. (__u8 *)rom_desc);
  596. if (status)
  597. return 0;
  598. if (rom_desc->Type == desc_type)
  599. return start_address;
  600. start_address = start_address + sizeof(struct ti_i2c_desc)
  601. + rom_desc->Size;
  602. } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type);
  603. return 0;
  604. }
  605. /* Validate descriptor checksum */
  606. static int valid_csum(struct ti_i2c_desc *rom_desc, __u8 *buffer)
  607. {
  608. __u16 i;
  609. __u8 cs = 0;
  610. for (i = 0; i < rom_desc->Size; i++)
  611. cs = (__u8)(cs + buffer[i]);
  612. if (cs != rom_desc->CheckSum) {
  613. dbg("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs);
  614. return -EINVAL;
  615. }
  616. return 0;
  617. }
  618. /* Make sure that the I2C image is good */
  619. static int check_i2c_image(struct edgeport_serial *serial)
  620. {
  621. struct device *dev = &serial->serial->dev->dev;
  622. int status = 0;
  623. struct ti_i2c_desc *rom_desc;
  624. int start_address = 2;
  625. __u8 *buffer;
  626. __u16 ttype;
  627. rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
  628. if (!rom_desc) {
  629. dev_err(dev, "%s - out of memory\n", __func__);
  630. return -ENOMEM;
  631. }
  632. buffer = kmalloc(TI_MAX_I2C_SIZE, GFP_KERNEL);
  633. if (!buffer) {
  634. dev_err(dev, "%s - out of memory when allocating buffer\n",
  635. __func__);
  636. kfree(rom_desc);
  637. return -ENOMEM;
  638. }
  639. /* Read the first byte (Signature0) must be 0x52 or 0x10 */
  640. status = read_rom(serial, 0, 1, buffer);
  641. if (status)
  642. goto out;
  643. if (*buffer != UMP5152 && *buffer != UMP3410) {
  644. dev_err(dev, "%s - invalid buffer signature\n", __func__);
  645. status = -ENODEV;
  646. goto out;
  647. }
  648. do {
  649. /* Validate the I2C */
  650. status = read_rom(serial,
  651. start_address,
  652. sizeof(struct ti_i2c_desc),
  653. (__u8 *)rom_desc);
  654. if (status)
  655. break;
  656. if ((start_address + sizeof(struct ti_i2c_desc) +
  657. rom_desc->Size) > TI_MAX_I2C_SIZE) {
  658. status = -ENODEV;
  659. dbg("%s - structure too big, erroring out.", __func__);
  660. break;
  661. }
  662. dbg("%s Type = 0x%x", __func__, rom_desc->Type);
  663. /* Skip type 2 record */
  664. ttype = rom_desc->Type & 0x0f;
  665. if (ttype != I2C_DESC_TYPE_FIRMWARE_BASIC
  666. && ttype != I2C_DESC_TYPE_FIRMWARE_AUTO) {
  667. /* Read the descriptor data */
  668. status = read_rom(serial, start_address +
  669. sizeof(struct ti_i2c_desc),
  670. rom_desc->Size, buffer);
  671. if (status)
  672. break;
  673. status = valid_csum(rom_desc, buffer);
  674. if (status)
  675. break;
  676. }
  677. start_address = start_address + sizeof(struct ti_i2c_desc) +
  678. rom_desc->Size;
  679. } while ((rom_desc->Type != I2C_DESC_TYPE_ION) &&
  680. (start_address < TI_MAX_I2C_SIZE));
  681. if ((rom_desc->Type != I2C_DESC_TYPE_ION) ||
  682. (start_address > TI_MAX_I2C_SIZE))
  683. status = -ENODEV;
  684. out:
  685. kfree(buffer);
  686. kfree(rom_desc);
  687. return status;
  688. }
  689. static int get_manuf_info(struct edgeport_serial *serial, __u8 *buffer)
  690. {
  691. int status;
  692. int start_address;
  693. struct ti_i2c_desc *rom_desc;
  694. struct edge_ti_manuf_descriptor *desc;
  695. rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
  696. if (!rom_desc) {
  697. dev_err(&serial->serial->dev->dev, "%s - out of memory\n",
  698. __func__);
  699. return -ENOMEM;
  700. }
  701. start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_ION,
  702. rom_desc);
  703. if (!start_address) {
  704. dbg("%s - Edge Descriptor not found in I2C", __func__);
  705. status = -ENODEV;
  706. goto exit;
  707. }
  708. /* Read the descriptor data */
  709. status = read_rom(serial, start_address+sizeof(struct ti_i2c_desc),
  710. rom_desc->Size, buffer);
  711. if (status)
  712. goto exit;
  713. status = valid_csum(rom_desc, buffer);
  714. desc = (struct edge_ti_manuf_descriptor *)buffer;
  715. dbg("%s - IonConfig 0x%x", __func__, desc->IonConfig);
  716. dbg("%s - Version %d", __func__, desc->Version);
  717. dbg("%s - Cpu/Board 0x%x", __func__, desc->CpuRev_BoardRev);
  718. dbg("%s - NumPorts %d", __func__, desc->NumPorts);
  719. dbg("%s - NumVirtualPorts %d", __func__, desc->NumVirtualPorts);
  720. dbg("%s - TotalPorts %d", __func__, desc->TotalPorts);
  721. exit:
  722. kfree(rom_desc);
  723. return status;
  724. }
  725. /* Build firmware header used for firmware update */
  726. static int build_i2c_fw_hdr(__u8 *header, struct device *dev)
  727. {
  728. __u8 *buffer;
  729. int buffer_size;
  730. int i;
  731. int err;
  732. __u8 cs = 0;
  733. struct ti_i2c_desc *i2c_header;
  734. struct ti_i2c_image_header *img_header;
  735. struct ti_i2c_firmware_rec *firmware_rec;
  736. const struct firmware *fw;
  737. const char *fw_name = "edgeport/down3.bin";
  738. /* In order to update the I2C firmware we must change the type 2 record
  739. * to type 0xF2. This will force the UMP to come up in Boot Mode.
  740. * Then while in boot mode, the driver will download the latest
  741. * firmware (padded to 15.5k) into the UMP ram. And finally when the
  742. * device comes back up in download mode the driver will cause the new
  743. * firmware to be copied from the UMP Ram to I2C and the firmware will
  744. * update the record type from 0xf2 to 0x02.
  745. */
  746. /* Allocate a 15.5k buffer + 2 bytes for version number
  747. * (Firmware Record) */
  748. buffer_size = (((1024 * 16) - 512 ) +
  749. sizeof(struct ti_i2c_firmware_rec));
  750. buffer = kmalloc(buffer_size, GFP_KERNEL);
  751. if (!buffer) {
  752. dev_err(dev, "%s - out of memory\n", __func__);
  753. return -ENOMEM;
  754. }
  755. // Set entire image of 0xffs
  756. memset(buffer, 0xff, buffer_size);
  757. err = request_firmware(&fw, fw_name, dev);
  758. if (err) {
  759. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  760. fw_name, err);
  761. kfree(buffer);
  762. return err;
  763. }
  764. /* Save Download Version Number */
  765. OperationalMajorVersion = fw->data[0];
  766. OperationalMinorVersion = fw->data[1];
  767. OperationalBuildNumber = fw->data[2] | (fw->data[3] << 8);
  768. /* Copy version number into firmware record */
  769. firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
  770. firmware_rec->Ver_Major = OperationalMajorVersion;
  771. firmware_rec->Ver_Minor = OperationalMinorVersion;
  772. /* Pointer to fw_down memory image */
  773. img_header = (struct ti_i2c_image_header *)&fw->data[4];
  774. memcpy(buffer + sizeof(struct ti_i2c_firmware_rec),
  775. &fw->data[4 + sizeof(struct ti_i2c_image_header)],
  776. le16_to_cpu(img_header->Length));
  777. release_firmware(fw);
  778. for (i=0; i < buffer_size; i++) {
  779. cs = (__u8)(cs + buffer[i]);
  780. }
  781. kfree(buffer);
  782. /* Build new header */
  783. i2c_header = (struct ti_i2c_desc *)header;
  784. firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data;
  785. i2c_header->Type = I2C_DESC_TYPE_FIRMWARE_BLANK;
  786. i2c_header->Size = (__u16)buffer_size;
  787. i2c_header->CheckSum = cs;
  788. firmware_rec->Ver_Major = OperationalMajorVersion;
  789. firmware_rec->Ver_Minor = OperationalMinorVersion;
  790. return 0;
  791. }
  792. /* Try to figure out what type of I2c we have */
  793. static int i2c_type_bootmode(struct edgeport_serial *serial)
  794. {
  795. int status;
  796. __u8 data;
  797. /* Try to read type 2 */
  798. status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
  799. DTK_ADDR_SPACE_I2C_TYPE_II, 0, &data, 0x01);
  800. if (status)
  801. dbg("%s - read 2 status error = %d", __func__, status);
  802. else
  803. dbg("%s - read 2 data = 0x%x", __func__, data);
  804. if ((!status) && (data == UMP5152 || data == UMP3410)) {
  805. dbg("%s - ROM_TYPE_II", __func__);
  806. serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
  807. return 0;
  808. }
  809. /* Try to read type 3 */
  810. status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
  811. DTK_ADDR_SPACE_I2C_TYPE_III, 0, &data, 0x01);
  812. if (status)
  813. dbg("%s - read 3 status error = %d", __func__, status);
  814. else
  815. dbg("%s - read 2 data = 0x%x", __func__, data);
  816. if ((!status) && (data == UMP5152 || data == UMP3410)) {
  817. dbg("%s - ROM_TYPE_III", __func__);
  818. serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
  819. return 0;
  820. }
  821. dbg("%s - Unknown", __func__);
  822. serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
  823. return -ENODEV;
  824. }
  825. static int bulk_xfer(struct usb_serial *serial, void *buffer,
  826. int length, int *num_sent)
  827. {
  828. int status;
  829. status = usb_bulk_msg(serial->dev,
  830. usb_sndbulkpipe(serial->dev,
  831. serial->port[0]->bulk_out_endpointAddress),
  832. buffer, length, num_sent, 1000);
  833. return status;
  834. }
  835. /* Download given firmware image to the device (IN BOOT MODE) */
  836. static int download_code(struct edgeport_serial *serial, __u8 *image,
  837. int image_length)
  838. {
  839. int status = 0;
  840. int pos;
  841. int transfer;
  842. int done;
  843. /* Transfer firmware image */
  844. for (pos = 0; pos < image_length; ) {
  845. /* Read the next buffer from file */
  846. transfer = image_length - pos;
  847. if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE)
  848. transfer = EDGE_FW_BULK_MAX_PACKET_SIZE;
  849. /* Transfer data */
  850. status = bulk_xfer(serial->serial, &image[pos],
  851. transfer, &done);
  852. if (status)
  853. break;
  854. /* Advance buffer pointer */
  855. pos += done;
  856. }
  857. return status;
  858. }
  859. /* FIXME!!! */
  860. static int config_boot_dev(struct usb_device *dev)
  861. {
  862. return 0;
  863. }
  864. static int ti_cpu_rev(struct edge_ti_manuf_descriptor *desc)
  865. {
  866. return TI_GET_CPU_REVISION(desc->CpuRev_BoardRev);
  867. }
  868. /**
  869. * DownloadTIFirmware - Download run-time operating firmware to the TI5052
  870. *
  871. * This routine downloads the main operating code into the TI5052, using the
  872. * boot code already burned into E2PROM or ROM.
  873. */
  874. static int download_fw(struct edgeport_serial *serial)
  875. {
  876. struct device *dev = &serial->serial->dev->dev;
  877. int status = 0;
  878. int start_address;
  879. struct edge_ti_manuf_descriptor *ti_manuf_desc;
  880. struct usb_interface_descriptor *interface;
  881. int download_cur_ver;
  882. int download_new_ver;
  883. /* This routine is entered by both the BOOT mode and the Download mode
  884. * We can determine which code is running by the reading the config
  885. * descriptor and if we have only one bulk pipe it is in boot mode
  886. */
  887. serial->product_info.hardware_type = HARDWARE_TYPE_TIUMP;
  888. /* Default to type 2 i2c */
  889. serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
  890. status = choose_config(serial->serial->dev);
  891. if (status)
  892. return status;
  893. interface = &serial->serial->interface->cur_altsetting->desc;
  894. if (!interface) {
  895. dev_err(dev, "%s - no interface set, error!\n", __func__);
  896. return -ENODEV;
  897. }
  898. /*
  899. * Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
  900. * if we have more than one endpoint we are definitely in download
  901. * mode
  902. */
  903. if (interface->bNumEndpoints > 1)
  904. serial->product_info.TiMode = TI_MODE_DOWNLOAD;
  905. else
  906. /* Otherwise we will remain in configuring mode */
  907. serial->product_info.TiMode = TI_MODE_CONFIGURING;
  908. /********************************************************************/
  909. /* Download Mode */
  910. /********************************************************************/
  911. if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
  912. struct ti_i2c_desc *rom_desc;
  913. dbg("%s - RUNNING IN DOWNLOAD MODE", __func__);
  914. status = check_i2c_image(serial);
  915. if (status) {
  916. dbg("%s - DOWNLOAD MODE -- BAD I2C", __func__);
  917. return status;
  918. }
  919. /* Validate Hardware version number
  920. * Read Manufacturing Descriptor from TI Based Edgeport
  921. */
  922. ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
  923. if (!ti_manuf_desc) {
  924. dev_err(dev, "%s - out of memory.\n", __func__);
  925. return -ENOMEM;
  926. }
  927. status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
  928. if (status) {
  929. kfree(ti_manuf_desc);
  930. return status;
  931. }
  932. /* Check version number of ION descriptor */
  933. if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
  934. dbg("%s - Wrong CPU Rev %d (Must be 2)",
  935. __func__, ti_cpu_rev(ti_manuf_desc));
  936. kfree(ti_manuf_desc);
  937. return -EINVAL;
  938. }
  939. rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
  940. if (!rom_desc) {
  941. dev_err(dev, "%s - out of memory.\n", __func__);
  942. kfree(ti_manuf_desc);
  943. return -ENOMEM;
  944. }
  945. /* Search for type 2 record (firmware record) */
  946. start_address = get_descriptor_addr(serial,
  947. I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc);
  948. if (start_address != 0) {
  949. struct ti_i2c_firmware_rec *firmware_version;
  950. __u8 record;
  951. dbg("%s - Found Type FIRMWARE (Type 2) record",
  952. __func__);
  953. firmware_version = kmalloc(sizeof(*firmware_version),
  954. GFP_KERNEL);
  955. if (!firmware_version) {
  956. dev_err(dev, "%s - out of memory.\n", __func__);
  957. kfree(rom_desc);
  958. kfree(ti_manuf_desc);
  959. return -ENOMEM;
  960. }
  961. /* Validate version number
  962. * Read the descriptor data
  963. */
  964. status = read_rom(serial, start_address +
  965. sizeof(struct ti_i2c_desc),
  966. sizeof(struct ti_i2c_firmware_rec),
  967. (__u8 *)firmware_version);
  968. if (status) {
  969. kfree(firmware_version);
  970. kfree(rom_desc);
  971. kfree(ti_manuf_desc);
  972. return status;
  973. }
  974. /* Check version number of download with current
  975. version in I2c */
  976. download_cur_ver = (firmware_version->Ver_Major << 8) +
  977. (firmware_version->Ver_Minor);
  978. download_new_ver = (OperationalMajorVersion << 8) +
  979. (OperationalMinorVersion);
  980. dbg("%s - >> FW Versions Device %d.%d Driver %d.%d",
  981. __func__,
  982. firmware_version->Ver_Major,
  983. firmware_version->Ver_Minor,
  984. OperationalMajorVersion,
  985. OperationalMinorVersion);
  986. /* Check if we have an old version in the I2C and
  987. update if necessary */
  988. if (download_cur_ver != download_new_ver) {
  989. dbg("%s - Update I2C dld from %d.%d to %d.%d",
  990. __func__,
  991. firmware_version->Ver_Major,
  992. firmware_version->Ver_Minor,
  993. OperationalMajorVersion,
  994. OperationalMinorVersion);
  995. /* In order to update the I2C firmware we must
  996. * change the type 2 record to type 0xF2. This
  997. * will force the UMP to come up in Boot Mode.
  998. * Then while in boot mode, the driver will
  999. * download the latest firmware (padded to
  1000. * 15.5k) into the UMP ram. Finally when the
  1001. * device comes back up in download mode the
  1002. * driver will cause the new firmware to be
  1003. * copied from the UMP Ram to I2C and the
  1004. * firmware will update the record type from
  1005. * 0xf2 to 0x02.
  1006. */
  1007. record = I2C_DESC_TYPE_FIRMWARE_BLANK;
  1008. /* Change the I2C Firmware record type to
  1009. 0xf2 to trigger an update */
  1010. status = write_rom(serial, start_address,
  1011. sizeof(record), &record);
  1012. if (status) {
  1013. kfree(firmware_version);
  1014. kfree(rom_desc);
  1015. kfree(ti_manuf_desc);
  1016. return status;
  1017. }
  1018. /* verify the write -- must do this in order
  1019. * for write to complete before we do the
  1020. * hardware reset
  1021. */
  1022. status = read_rom(serial,
  1023. start_address,
  1024. sizeof(record),
  1025. &record);
  1026. if (status) {
  1027. kfree(firmware_version);
  1028. kfree(rom_desc);
  1029. kfree(ti_manuf_desc);
  1030. return status;
  1031. }
  1032. if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
  1033. dev_err(dev,
  1034. "%s - error resetting device\n",
  1035. __func__);
  1036. kfree(firmware_version);
  1037. kfree(rom_desc);
  1038. kfree(ti_manuf_desc);
  1039. return -ENODEV;
  1040. }
  1041. dbg("%s - HARDWARE RESET", __func__);
  1042. /* Reset UMP -- Back to BOOT MODE */
  1043. status = ti_vsend_sync(serial->serial->dev,
  1044. UMPC_HARDWARE_RESET,
  1045. 0, 0, NULL, 0);
  1046. dbg("%s - HARDWARE RESET return %d",
  1047. __func__, status);
  1048. /* return an error on purpose. */
  1049. kfree(firmware_version);
  1050. kfree(rom_desc);
  1051. kfree(ti_manuf_desc);
  1052. return -ENODEV;
  1053. }
  1054. kfree(firmware_version);
  1055. }
  1056. /* Search for type 0xF2 record (firmware blank record) */
  1057. else if ((start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) {
  1058. #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + \
  1059. sizeof(struct ti_i2c_firmware_rec))
  1060. __u8 *header;
  1061. __u8 *vheader;
  1062. header = kmalloc(HEADER_SIZE, GFP_KERNEL);
  1063. if (!header) {
  1064. dev_err(dev, "%s - out of memory.\n", __func__);
  1065. kfree(rom_desc);
  1066. kfree(ti_manuf_desc);
  1067. return -ENOMEM;
  1068. }
  1069. vheader = kmalloc(HEADER_SIZE, GFP_KERNEL);
  1070. if (!vheader) {
  1071. dev_err(dev, "%s - out of memory.\n", __func__);
  1072. kfree(header);
  1073. kfree(rom_desc);
  1074. kfree(ti_manuf_desc);
  1075. return -ENOMEM;
  1076. }
  1077. dbg("%s - Found Type BLANK FIRMWARE (Type F2) record",
  1078. __func__);
  1079. /*
  1080. * In order to update the I2C firmware we must change
  1081. * the type 2 record to type 0xF2. This will force the
  1082. * UMP to come up in Boot Mode. Then while in boot
  1083. * mode, the driver will download the latest firmware
  1084. * (padded to 15.5k) into the UMP ram. Finally when the
  1085. * device comes back up in download mode the driver
  1086. * will cause the new firmware to be copied from the
  1087. * UMP Ram to I2C and the firmware will update the
  1088. * record type from 0xf2 to 0x02.
  1089. */
  1090. status = build_i2c_fw_hdr(header, dev);
  1091. if (status) {
  1092. kfree(vheader);
  1093. kfree(header);
  1094. kfree(rom_desc);
  1095. kfree(ti_manuf_desc);
  1096. return status;
  1097. }
  1098. /* Update I2C with type 0xf2 record with correct
  1099. size and checksum */
  1100. status = write_rom(serial,
  1101. start_address,
  1102. HEADER_SIZE,
  1103. header);
  1104. if (status) {
  1105. kfree(vheader);
  1106. kfree(header);
  1107. kfree(rom_desc);
  1108. kfree(ti_manuf_desc);
  1109. return status;
  1110. }
  1111. /* verify the write -- must do this in order for
  1112. write to complete before we do the hardware reset */
  1113. status = read_rom(serial, start_address,
  1114. HEADER_SIZE, vheader);
  1115. if (status) {
  1116. dbg("%s - can't read header back", __func__);
  1117. kfree(vheader);
  1118. kfree(header);
  1119. kfree(rom_desc);
  1120. kfree(ti_manuf_desc);
  1121. return status;
  1122. }
  1123. if (memcmp(vheader, header, HEADER_SIZE)) {
  1124. dbg("%s - write download record failed",
  1125. __func__);
  1126. kfree(vheader);
  1127. kfree(header);
  1128. kfree(rom_desc);
  1129. kfree(ti_manuf_desc);
  1130. return status;
  1131. }
  1132. kfree(vheader);
  1133. kfree(header);
  1134. dbg("%s - Start firmware update", __func__);
  1135. /* Tell firmware to copy download image into I2C */
  1136. status = ti_vsend_sync(serial->serial->dev,
  1137. UMPC_COPY_DNLD_TO_I2C, 0, 0, NULL, 0);
  1138. dbg("%s - Update complete 0x%x", __func__, status);
  1139. if (status) {
  1140. dev_err(dev,
  1141. "%s - UMPC_COPY_DNLD_TO_I2C failed\n",
  1142. __func__);
  1143. kfree(rom_desc);
  1144. kfree(ti_manuf_desc);
  1145. return status;
  1146. }
  1147. }
  1148. // The device is running the download code
  1149. kfree(rom_desc);
  1150. kfree(ti_manuf_desc);
  1151. return 0;
  1152. }
  1153. /********************************************************************/
  1154. /* Boot Mode */
  1155. /********************************************************************/
  1156. dbg("%s - RUNNING IN BOOT MODE", __func__);
  1157. /* Configure the TI device so we can use the BULK pipes for download */
  1158. status = config_boot_dev(serial->serial->dev);
  1159. if (status)
  1160. return status;
  1161. if (le16_to_cpu(serial->serial->dev->descriptor.idVendor)
  1162. != USB_VENDOR_ID_ION) {
  1163. dbg("%s - VID = 0x%x", __func__,
  1164. le16_to_cpu(serial->serial->dev->descriptor.idVendor));
  1165. serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
  1166. goto stayinbootmode;
  1167. }
  1168. /* We have an ION device (I2c Must be programmed)
  1169. Determine I2C image type */
  1170. if (i2c_type_bootmode(serial))
  1171. goto stayinbootmode;
  1172. /* Check for ION Vendor ID and that the I2C is valid */
  1173. if (!check_i2c_image(serial)) {
  1174. struct ti_i2c_image_header *header;
  1175. int i;
  1176. __u8 cs = 0;
  1177. __u8 *buffer;
  1178. int buffer_size;
  1179. int err;
  1180. const struct firmware *fw;
  1181. const char *fw_name = "edgeport/down3.bin";
  1182. /* Validate Hardware version number
  1183. * Read Manufacturing Descriptor from TI Based Edgeport
  1184. */
  1185. ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
  1186. if (!ti_manuf_desc) {
  1187. dev_err(dev, "%s - out of memory.\n", __func__);
  1188. return -ENOMEM;
  1189. }
  1190. status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
  1191. if (status) {
  1192. kfree(ti_manuf_desc);
  1193. goto stayinbootmode;
  1194. }
  1195. /* Check for version 2 */
  1196. if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
  1197. dbg("%s - Wrong CPU Rev %d (Must be 2)",
  1198. __func__, ti_cpu_rev(ti_manuf_desc));
  1199. kfree(ti_manuf_desc);
  1200. goto stayinbootmode;
  1201. }
  1202. kfree(ti_manuf_desc);
  1203. /*
  1204. * In order to update the I2C firmware we must change the type
  1205. * 2 record to type 0xF2. This will force the UMP to come up
  1206. * in Boot Mode. Then while in boot mode, the driver will
  1207. * download the latest firmware (padded to 15.5k) into the
  1208. * UMP ram. Finally when the device comes back up in download
  1209. * mode the driver will cause the new firmware to be copied
  1210. * from the UMP Ram to I2C and the firmware will update the
  1211. * record type from 0xf2 to 0x02.
  1212. *
  1213. * Do we really have to copy the whole firmware image,
  1214. * or could we do this in place!
  1215. */
  1216. /* Allocate a 15.5k buffer + 3 byte header */
  1217. buffer_size = (((1024 * 16) - 512) +
  1218. sizeof(struct ti_i2c_image_header));
  1219. buffer = kmalloc(buffer_size, GFP_KERNEL);
  1220. if (!buffer) {
  1221. dev_err(dev, "%s - out of memory\n", __func__);
  1222. return -ENOMEM;
  1223. }
  1224. /* Initialize the buffer to 0xff (pad the buffer) */
  1225. memset(buffer, 0xff, buffer_size);
  1226. err = request_firmware(&fw, fw_name, dev);
  1227. if (err) {
  1228. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  1229. fw_name, err);
  1230. kfree(buffer);
  1231. return err;
  1232. }
  1233. memcpy(buffer, &fw->data[4], fw->size - 4);
  1234. release_firmware(fw);
  1235. for (i = sizeof(struct ti_i2c_image_header);
  1236. i < buffer_size; i++) {
  1237. cs = (__u8)(cs + buffer[i]);
  1238. }
  1239. header = (struct ti_i2c_image_header *)buffer;
  1240. /* update length and checksum after padding */
  1241. header->Length = cpu_to_le16((__u16)(buffer_size -
  1242. sizeof(struct ti_i2c_image_header)));
  1243. header->CheckSum = cs;
  1244. /* Download the operational code */
  1245. dbg("%s - Downloading operational code image (TI UMP)",
  1246. __func__);
  1247. status = download_code(serial, buffer, buffer_size);
  1248. kfree(buffer);
  1249. if (status) {
  1250. dbg("%s - Error downloading operational code image",
  1251. __func__);
  1252. return status;
  1253. }
  1254. /* Device will reboot */
  1255. serial->product_info.TiMode = TI_MODE_TRANSITIONING;
  1256. dbg("%s - Download successful -- Device rebooting...",
  1257. __func__);
  1258. /* return an error on purpose */
  1259. return -ENODEV;
  1260. }
  1261. stayinbootmode:
  1262. /* Eprom is invalid or blank stay in boot mode */
  1263. dbg("%s - STAYING IN BOOT MODE", __func__);
  1264. serial->product_info.TiMode = TI_MODE_BOOT;
  1265. return 0;
  1266. }
  1267. static int ti_do_config(struct edgeport_port *port, int feature, int on)
  1268. {
  1269. int port_number = port->port->number - port->port->serial->minor;
  1270. on = !!on; /* 1 or 0 not bitmask */
  1271. return send_cmd(port->port->serial->dev,
  1272. feature, (__u8)(UMPM_UART1_PORT + port_number),
  1273. on, NULL, 0);
  1274. }
  1275. static int restore_mcr(struct edgeport_port *port, __u8 mcr)
  1276. {
  1277. int status = 0;
  1278. dbg("%s - %x", __func__, mcr);
  1279. status = ti_do_config(port, UMPC_SET_CLR_DTR, mcr & MCR_DTR);
  1280. if (status)
  1281. return status;
  1282. status = ti_do_config(port, UMPC_SET_CLR_RTS, mcr & MCR_RTS);
  1283. if (status)
  1284. return status;
  1285. return ti_do_config(port, UMPC_SET_CLR_LOOPBACK, mcr & MCR_LOOPBACK);
  1286. }
  1287. /* Convert TI LSR to standard UART flags */
  1288. static __u8 map_line_status(__u8 ti_lsr)
  1289. {
  1290. __u8 lsr = 0;
  1291. #define MAP_FLAG(flagUmp, flagUart) \
  1292. if (ti_lsr & flagUmp) \
  1293. lsr |= flagUart;
  1294. MAP_FLAG(UMP_UART_LSR_OV_MASK, LSR_OVER_ERR) /* overrun */
  1295. MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */
  1296. MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */
  1297. MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */
  1298. MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* rx data available */
  1299. MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* tx hold reg empty */
  1300. #undef MAP_FLAG
  1301. return lsr;
  1302. }
  1303. static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
  1304. {
  1305. struct async_icount *icount;
  1306. struct tty_struct *tty;
  1307. dbg("%s - %02x", __func__, msr);
  1308. if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
  1309. EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
  1310. icount = &edge_port->icount;
  1311. /* update input line counters */
  1312. if (msr & EDGEPORT_MSR_DELTA_CTS)
  1313. icount->cts++;
  1314. if (msr & EDGEPORT_MSR_DELTA_DSR)
  1315. icount->dsr++;
  1316. if (msr & EDGEPORT_MSR_DELTA_CD)
  1317. icount->dcd++;
  1318. if (msr & EDGEPORT_MSR_DELTA_RI)
  1319. icount->rng++;
  1320. wake_up_interruptible(&edge_port->delta_msr_wait);
  1321. }
  1322. /* Save the new modem status */
  1323. edge_port->shadow_msr = msr & 0xf0;
  1324. tty = edge_port->port->port.tty;
  1325. /* handle CTS flow control */
  1326. if (tty && C_CRTSCTS(tty)) {
  1327. if (msr & EDGEPORT_MSR_CTS) {
  1328. tty->hw_stopped = 0;
  1329. tty_wakeup(tty);
  1330. } else {
  1331. tty->hw_stopped = 1;
  1332. }
  1333. }
  1334. return;
  1335. }
  1336. static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
  1337. __u8 lsr, __u8 data)
  1338. {
  1339. struct async_icount *icount;
  1340. __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR |
  1341. LSR_FRM_ERR | LSR_BREAK));
  1342. dbg("%s - %02x", __func__, new_lsr);
  1343. edge_port->shadow_lsr = lsr;
  1344. if (new_lsr & LSR_BREAK)
  1345. /*
  1346. * Parity and Framing errors only count if they
  1347. * occur exclusive of a break being received.
  1348. */
  1349. new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
  1350. /* Place LSR data byte into Rx buffer */
  1351. if (lsr_data && edge_port->port->port.tty)
  1352. edge_tty_recv(&edge_port->port->dev, edge_port->port->port.tty, &data, 1);
  1353. /* update input line counters */
  1354. icount = &edge_port->icount;
  1355. if (new_lsr & LSR_BREAK)
  1356. icount->brk++;
  1357. if (new_lsr & LSR_OVER_ERR)
  1358. icount->overrun++;
  1359. if (new_lsr & LSR_PAR_ERR)
  1360. icount->parity++;
  1361. if (new_lsr & LSR_FRM_ERR)
  1362. icount->frame++;
  1363. }
  1364. static void edge_interrupt_callback(struct urb *urb)
  1365. {
  1366. struct edgeport_serial *edge_serial = urb->context;
  1367. struct usb_serial_port *port;
  1368. struct edgeport_port *edge_port;
  1369. unsigned char *data = urb->transfer_buffer;
  1370. int length = urb->actual_length;
  1371. int port_number;
  1372. int function;
  1373. int retval;
  1374. __u8 lsr;
  1375. __u8 msr;
  1376. int status = urb->status;
  1377. dbg("%s", __func__);
  1378. switch (status) {
  1379. case 0:
  1380. /* success */
  1381. break;
  1382. case -ECONNRESET:
  1383. case -ENOENT:
  1384. case -ESHUTDOWN:
  1385. /* this urb is terminated, clean up */
  1386. dbg("%s - urb shutting down with status: %d",
  1387. __func__, status);
  1388. return;
  1389. default:
  1390. dev_err(&urb->dev->dev, "%s - nonzero urb status received: "
  1391. "%d\n", __func__, status);
  1392. goto exit;
  1393. }
  1394. if (!length) {
  1395. dbg("%s - no data in urb", __func__);
  1396. goto exit;
  1397. }
  1398. usb_serial_debug_data(debug, &edge_serial->serial->dev->dev,
  1399. __func__, length, data);
  1400. if (length != 2) {
  1401. dbg("%s - expecting packet of size 2, got %d",
  1402. __func__, length);
  1403. goto exit;
  1404. }
  1405. port_number = TIUMP_GET_PORT_FROM_CODE(data[0]);
  1406. function = TIUMP_GET_FUNC_FROM_CODE(data[0]);
  1407. dbg("%s - port_number %d, function %d, info 0x%x",
  1408. __func__, port_number, function, data[1]);
  1409. port = edge_serial->serial->port[port_number];
  1410. edge_port = usb_get_serial_port_data(port);
  1411. if (!edge_port) {
  1412. dbg("%s - edge_port not found", __func__);
  1413. return;
  1414. }
  1415. switch (function) {
  1416. case TIUMP_INTERRUPT_CODE_LSR:
  1417. lsr = map_line_status(data[1]);
  1418. if (lsr & UMP_UART_LSR_DATA_MASK) {
  1419. /* Save the LSR event for bulk read
  1420. completion routine */
  1421. dbg("%s - LSR Event Port %u LSR Status = %02x",
  1422. __func__, port_number, lsr);
  1423. edge_port->lsr_event = 1;
  1424. edge_port->lsr_mask = lsr;
  1425. } else {
  1426. dbg("%s - ===== Port %d LSR Status = %02x ======",
  1427. __func__, port_number, lsr);
  1428. handle_new_lsr(edge_port, 0, lsr, 0);
  1429. }
  1430. break;
  1431. case TIUMP_INTERRUPT_CODE_MSR: /* MSR */
  1432. /* Copy MSR from UMP */
  1433. msr = data[1];
  1434. dbg("%s - ===== Port %u MSR Status = %02x ======\n",
  1435. __func__, port_number, msr);
  1436. handle_new_msr(edge_port, msr);
  1437. break;
  1438. default:
  1439. dev_err(&urb->dev->dev,
  1440. "%s - Unknown Interrupt code from UMP %x\n",
  1441. __func__, data[1]);
  1442. break;
  1443. }
  1444. exit:
  1445. retval = usb_submit_urb(urb, GFP_ATOMIC);
  1446. if (retval)
  1447. dev_err(&urb->dev->dev,
  1448. "%s - usb_submit_urb failed with result %d\n",
  1449. __func__, retval);
  1450. }
  1451. static void edge_bulk_in_callback(struct urb *urb)
  1452. {
  1453. struct edgeport_port *edge_port = urb->context;
  1454. unsigned char *data = urb->transfer_buffer;
  1455. struct tty_struct *tty;
  1456. int retval = 0;
  1457. int port_number;
  1458. int status = urb->status;
  1459. dbg("%s", __func__);
  1460. switch (status) {
  1461. case 0:
  1462. /* success */
  1463. break;
  1464. case -ECONNRESET:
  1465. case -ENOENT:
  1466. case -ESHUTDOWN:
  1467. /* this urb is terminated, clean up */
  1468. dbg("%s - urb shutting down with status: %d",
  1469. __func__, status);
  1470. return;
  1471. default:
  1472. dev_err(&urb->dev->dev,
  1473. "%s - nonzero read bulk status received: %d\n",
  1474. __func__, status);
  1475. }
  1476. if (status == -EPIPE)
  1477. goto exit;
  1478. if (status) {
  1479. dev_err(&urb->dev->dev, "%s - stopping read!\n", __func__);
  1480. return;
  1481. }
  1482. port_number = edge_port->port->number - edge_port->port->serial->minor;
  1483. if (edge_port->lsr_event) {
  1484. edge_port->lsr_event = 0;
  1485. dbg("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
  1486. __func__, port_number, edge_port->lsr_mask, *data);
  1487. handle_new_lsr(edge_port, 1, edge_port->lsr_mask, *data);
  1488. /* Adjust buffer length/pointer */
  1489. --urb->actual_length;
  1490. ++data;
  1491. }
  1492. tty = edge_port->port->port.tty;
  1493. if (tty && urb->actual_length) {
  1494. usb_serial_debug_data(debug, &edge_port->port->dev,
  1495. __func__, urb->actual_length, data);
  1496. if (edge_port->close_pending)
  1497. dbg("%s - close pending, dropping data on the floor",
  1498. __func__);
  1499. else
  1500. edge_tty_recv(&edge_port->port->dev, tty, data,
  1501. urb->actual_length);
  1502. edge_port->icount.rx += urb->actual_length;
  1503. }
  1504. exit:
  1505. /* continue read unless stopped */
  1506. spin_lock(&edge_port->ep_lock);
  1507. if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING) {
  1508. urb->dev = edge_port->port->serial->dev;
  1509. retval = usb_submit_urb(urb, GFP_ATOMIC);
  1510. } else if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPING) {
  1511. edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPED;
  1512. }
  1513. spin_unlock(&edge_port->ep_lock);
  1514. if (retval)
  1515. dev_err(&urb->dev->dev,
  1516. "%s - usb_submit_urb failed with result %d\n",
  1517. __func__, retval);
  1518. }
  1519. static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
  1520. unsigned char *data, int length)
  1521. {
  1522. int queued;
  1523. tty_buffer_request_room(tty, length);
  1524. queued = tty_insert_flip_string(tty, data, length);
  1525. if (queued < length)
  1526. dev_err(dev, "%s - dropping data, %d bytes lost\n",
  1527. __func__, length - queued);
  1528. tty_flip_buffer_push(tty);
  1529. }
  1530. static void edge_bulk_out_callback(struct urb *urb)
  1531. {
  1532. struct usb_serial_port *port = urb->context;
  1533. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  1534. int status = urb->status;
  1535. dbg("%s - port %d", __func__, port->number);
  1536. edge_port->ep_write_urb_in_use = 0;
  1537. switch (status) {
  1538. case 0:
  1539. /* success */
  1540. break;
  1541. case -ECONNRESET:
  1542. case -ENOENT:
  1543. case -ESHUTDOWN:
  1544. /* this urb is terminated, clean up */
  1545. dbg("%s - urb shutting down with status: %d",
  1546. __func__, status);
  1547. return;
  1548. default:
  1549. dev_err(&urb->dev->dev, "%s - nonzero write bulk status "
  1550. "received: %d\n", __func__, status);
  1551. }
  1552. /* send any buffered data */
  1553. edge_send(port->port.tty);
  1554. }
  1555. static int edge_open(struct tty_struct *tty,
  1556. struct usb_serial_port *port, struct file *filp)
  1557. {
  1558. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  1559. struct edgeport_serial *edge_serial;
  1560. struct usb_device *dev;
  1561. struct urb *urb;
  1562. int port_number;
  1563. int status;
  1564. u16 open_settings;
  1565. u8 transaction_timeout;
  1566. dbg("%s - port %d", __func__, port->number);
  1567. if (edge_port == NULL)
  1568. return -ENODEV;
  1569. if (tty)
  1570. tty->low_latency = low_latency;
  1571. port_number = port->number - port->serial->minor;
  1572. switch (port_number) {
  1573. case 0:
  1574. edge_port->uart_base = UMPMEM_BASE_UART1;
  1575. edge_port->dma_address = UMPD_OEDB1_ADDRESS;
  1576. break;
  1577. case 1:
  1578. edge_port->uart_base = UMPMEM_BASE_UART2;
  1579. edge_port->dma_address = UMPD_OEDB2_ADDRESS;
  1580. break;
  1581. default:
  1582. dev_err(&port->dev, "Unknown port number!!!\n");
  1583. return -ENODEV;
  1584. }
  1585. dbg("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
  1586. __func__, port_number, edge_port->uart_base,
  1587. edge_port->dma_address);
  1588. dev = port->serial->dev;
  1589. memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount));
  1590. init_waitqueue_head(&edge_port->delta_msr_wait);
  1591. /* turn off loopback */
  1592. status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0);
  1593. if (status) {
  1594. dev_err(&port->dev,
  1595. "%s - cannot send clear loopback command, %d\n",
  1596. __func__, status);
  1597. return status;
  1598. }
  1599. /* set up the port settings */
  1600. if (tty)
  1601. edge_set_termios(tty, port, port->port.tty->termios);
  1602. /* open up the port */
  1603. /* milliseconds to timeout for DMA transfer */
  1604. transaction_timeout = 2;
  1605. edge_port->ump_read_timeout =
  1606. max(20, ((transaction_timeout * 3) / 2));
  1607. /* milliseconds to timeout for DMA transfer */
  1608. open_settings = (u8)(UMP_DMA_MODE_CONTINOUS |
  1609. UMP_PIPE_TRANS_TIMEOUT_ENA |
  1610. (transaction_timeout << 2));
  1611. dbg("%s - Sending UMPC_OPEN_PORT", __func__);
  1612. /* Tell TI to open and start the port */
  1613. status = send_cmd(dev, UMPC_OPEN_PORT,
  1614. (u8)(UMPM_UART1_PORT + port_number), open_settings, NULL, 0);
  1615. if (status) {
  1616. dev_err(&port->dev, "%s - cannot send open command, %d\n",
  1617. __func__, status);
  1618. return status;
  1619. }
  1620. /* Start the DMA? */
  1621. status = send_cmd(dev, UMPC_START_PORT,
  1622. (u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0);
  1623. if (status) {
  1624. dev_err(&port->dev, "%s - cannot send start DMA command, %d\n",
  1625. __func__, status);
  1626. return status;
  1627. }
  1628. /* Clear TX and RX buffers in UMP */
  1629. status = purge_port(port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
  1630. if (status) {
  1631. dev_err(&port->dev,
  1632. "%s - cannot send clear buffers command, %d\n",
  1633. __func__, status);
  1634. return status;
  1635. }
  1636. /* Read Initial MSR */
  1637. status = ti_vread_sync(dev, UMPC_READ_MSR, 0,
  1638. (__u16)(UMPM_UART1_PORT + port_number),
  1639. &edge_port->shadow_msr, 1);
  1640. if (status) {
  1641. dev_err(&port->dev, "%s - cannot send read MSR command, %d\n",
  1642. __func__, status);
  1643. return status;
  1644. }
  1645. dbg("ShadowMSR 0x%X", edge_port->shadow_msr);
  1646. /* Set Initial MCR */
  1647. edge_port->shadow_mcr = MCR_RTS | MCR_DTR;
  1648. dbg("ShadowMCR 0x%X", edge_port->shadow_mcr);
  1649. edge_serial = edge_port->edge_serial;
  1650. if (mutex_lock_interruptible(&edge_serial->es_lock))
  1651. return -ERESTARTSYS;
  1652. if (edge_serial->num_ports_open == 0) {
  1653. /* we are the first port to open, post the interrupt urb */
  1654. urb = edge_serial->serial->port[0]->interrupt_in_urb;
  1655. if (!urb) {
  1656. dev_err(&port->dev,
  1657. "%s - no interrupt urb present, exiting\n",
  1658. __func__);
  1659. status = -EINVAL;
  1660. goto release_es_lock;
  1661. }
  1662. urb->complete = edge_interrupt_callback;
  1663. urb->context = edge_serial;
  1664. urb->dev = dev;
  1665. status = usb_submit_urb(urb, GFP_KERNEL);
  1666. if (status) {
  1667. dev_err(&port->dev,
  1668. "%s - usb_submit_urb failed with value %d\n",
  1669. __func__, status);
  1670. goto release_es_lock;
  1671. }
  1672. }
  1673. /*
  1674. * reset the data toggle on the bulk endpoints to work around bug in
  1675. * host controllers where things get out of sync some times
  1676. */
  1677. usb_clear_halt(dev, port->write_urb->pipe);
  1678. usb_clear_halt(dev, port->read_urb->pipe);
  1679. /* start up our bulk read urb */
  1680. urb = port->read_urb;
  1681. if (!urb) {
  1682. dev_err(&port->dev, "%s - no read urb present, exiting\n",
  1683. __func__);
  1684. status = -EINVAL;
  1685. goto unlink_int_urb;
  1686. }
  1687. edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING;
  1688. urb->complete = edge_bulk_in_callback;
  1689. urb->context = edge_port;
  1690. urb->dev = dev;
  1691. status = usb_submit_urb(urb, GFP_KERNEL);
  1692. if (status) {
  1693. dev_err(&port->dev,
  1694. "%s - read bulk usb_submit_urb failed with value %d\n",
  1695. __func__, status);
  1696. goto unlink_int_urb;
  1697. }
  1698. ++edge_serial->num_ports_open;
  1699. dbg("%s - exited", __func__);
  1700. goto release_es_lock;
  1701. unlink_int_urb:
  1702. if (edge_port->edge_serial->num_ports_open == 0)
  1703. usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
  1704. release_es_lock:
  1705. mutex_unlock(&edge_serial->es_lock);
  1706. return status;
  1707. }
  1708. static void edge_close(struct tty_struct *tty,
  1709. struct usb_serial_port *port, struct file *filp)
  1710. {
  1711. struct edgeport_serial *edge_serial;
  1712. struct edgeport_port *edge_port;
  1713. int port_number;
  1714. int status;
  1715. dbg("%s - port %d", __func__, port->number);
  1716. edge_serial = usb_get_serial_data(port->serial);
  1717. edge_port = usb_get_serial_port_data(port);
  1718. if (edge_serial == NULL || edge_port == NULL)
  1719. return;
  1720. /* The bulkreadcompletion routine will check
  1721. * this flag and dump add read data */
  1722. edge_port->close_pending = 1;
  1723. /* chase the port close and flush */
  1724. chase_port(edge_port, (HZ * closing_wait) / 100, 1);
  1725. usb_kill_urb(port->read_urb);
  1726. usb_kill_urb(port->write_urb);
  1727. edge_port->ep_write_urb_in_use = 0;
  1728. /* assuming we can still talk to the device,
  1729. * send a close port command to it */
  1730. dbg("%s - send umpc_close_port", __func__);
  1731. port_number = port->number - port->serial->minor;
  1732. status = send_cmd(port->serial->dev,
  1733. UMPC_CLOSE_PORT,
  1734. (__u8)(UMPM_UART1_PORT + port_number),
  1735. 0,
  1736. NULL,
  1737. 0);
  1738. mutex_lock(&edge_serial->es_lock);
  1739. --edge_port->edge_serial->num_ports_open;
  1740. if (edge_port->edge_serial->num_ports_open <= 0) {
  1741. /* last port is now closed, let's shut down our interrupt urb */
  1742. usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
  1743. edge_port->edge_serial->num_ports_open = 0;
  1744. }
  1745. mutex_unlock(&edge_serial->es_lock);
  1746. edge_port->close_pending = 0;
  1747. dbg("%s - exited", __func__);
  1748. }
  1749. static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
  1750. const unsigned char *data, int count)
  1751. {
  1752. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  1753. unsigned long flags;
  1754. dbg("%s - port %d", __func__, port->number);
  1755. if (count == 0) {
  1756. dbg("%s - write request of 0 bytes", __func__);
  1757. return 0;
  1758. }
  1759. if (edge_port == NULL)
  1760. return -ENODEV;
  1761. if (edge_port->close_pending == 1)
  1762. return -ENODEV;
  1763. spin_lock_irqsave(&edge_port->ep_lock, flags);
  1764. count = edge_buf_put(edge_port->ep_out_buf, data, count);
  1765. spin_unlock_irqrestore(&edge_port->ep_lock, flags);
  1766. edge_send(tty);
  1767. return count;
  1768. }
  1769. static void edge_send(struct tty_struct *tty)
  1770. {
  1771. struct usb_serial_port *port = tty->driver_data;
  1772. int count, result;
  1773. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  1774. unsigned long flags;
  1775. dbg("%s - port %d", __func__, port->number);
  1776. spin_lock_irqsave(&edge_port->ep_lock, flags);
  1777. if (edge_port->ep_write_urb_in_use) {
  1778. spin_unlock_irqrestore(&edge_port->ep_lock, flags);
  1779. return;
  1780. }
  1781. count = edge_buf_get(edge_port->ep_out_buf,
  1782. port->write_urb->transfer_buffer,
  1783. port->bulk_out_size);
  1784. if (count == 0) {
  1785. spin_unlock_irqrestore(&edge_port->ep_lock, flags);
  1786. return;
  1787. }
  1788. edge_port->ep_write_urb_in_use = 1;
  1789. spin_unlock_irqrestore(&edge_port->ep_lock, flags);
  1790. usb_serial_debug_data(debug, &port->dev, __func__, count,
  1791. port->write_urb->transfer_buffer);
  1792. /* set up our urb */
  1793. usb_fill_bulk_urb(port->write_urb, port->serial->dev,
  1794. usb_sndbulkpipe(port->serial->dev,
  1795. port->bulk_out_endpointAddress),
  1796. port->write_urb->transfer_buffer, count,
  1797. edge_bulk_out_callback,
  1798. port);
  1799. /* send the data out the bulk port */
  1800. result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
  1801. if (result) {
  1802. dev_err(&port->dev,
  1803. "%s - failed submitting write urb, error %d\n",
  1804. __func__, result);
  1805. edge_port->ep_write_urb_in_use = 0;
  1806. /* TODO: reschedule edge_send */
  1807. } else
  1808. edge_port->icount.tx += count;
  1809. /* wakeup any process waiting for writes to complete */
  1810. /* there is now more room in the buffer for new writes */
  1811. if (tty)
  1812. tty_wakeup(tty);
  1813. }
  1814. static int edge_write_room(struct tty_struct *tty)
  1815. {
  1816. struct usb_serial_port *port = tty->driver_data;
  1817. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  1818. int room = 0;
  1819. unsigned long flags;
  1820. dbg("%s - port %d", __func__, port->number);
  1821. if (edge_port == NULL)
  1822. return 0;
  1823. if (edge_port->close_pending == 1)
  1824. return 0;
  1825. spin_lock_irqsave(&edge_port->ep_lock, flags);
  1826. room = edge_buf_space_avail(edge_port->ep_out_buf);
  1827. spin_unlock_irqrestore(&edge_port->ep_lock, flags);
  1828. dbg("%s - returns %d", __func__, room);
  1829. return room;
  1830. }
  1831. static int edge_chars_in_buffer(struct tty_struct *tty)
  1832. {
  1833. struct usb_serial_port *port = tty->driver_data;
  1834. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  1835. int chars = 0;
  1836. unsigned long flags;
  1837. dbg("%s - port %d", __func__, port->number);
  1838. if (edge_port == NULL)
  1839. return 0;
  1840. if (edge_port->close_pending == 1)
  1841. return 0;
  1842. spin_lock_irqsave(&edge_port->ep_lock, flags);
  1843. chars = edge_buf_data_avail(edge_port->ep_out_buf);
  1844. spin_unlock_irqrestore(&edge_port->ep_lock, flags);
  1845. dbg("%s - returns %d", __func__, chars);
  1846. return chars;
  1847. }
  1848. static void edge_throttle(struct tty_struct *tty)
  1849. {
  1850. struct usb_serial_port *port = tty->driver_data;
  1851. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  1852. int status;
  1853. dbg("%s - port %d", __func__, port->number);
  1854. if (edge_port == NULL)
  1855. return;
  1856. /* if we are implementing XON/XOFF, send the stop character */
  1857. if (I_IXOFF(tty)) {
  1858. unsigned char stop_char = STOP_CHAR(tty);
  1859. status = edge_write(tty, port, &stop_char, 1);
  1860. if (status <= 0) {
  1861. dev_err(&port->dev, "%s - failed to write stop character, %d\n", __func__, status);
  1862. }
  1863. }
  1864. /* if we are implementing RTS/CTS, stop reads */
  1865. /* and the Edgeport will clear the RTS line */
  1866. if (C_CRTSCTS(tty))
  1867. stop_read(edge_port);
  1868. }
  1869. static void edge_unthrottle(struct tty_struct *tty)
  1870. {
  1871. struct usb_serial_port *port = tty->driver_data;
  1872. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  1873. int status;
  1874. dbg("%s - port %d", __func__, port->number);
  1875. if (edge_port == NULL)
  1876. return;
  1877. /* if we are implementing XON/XOFF, send the start character */
  1878. if (I_IXOFF(tty)) {
  1879. unsigned char start_char = START_CHAR(tty);
  1880. status = edge_write(tty, port, &start_char, 1);
  1881. if (status <= 0) {
  1882. dev_err(&port->dev, "%s - failed to write start character, %d\n", __func__, status);
  1883. }
  1884. }
  1885. /* if we are implementing RTS/CTS, restart reads */
  1886. /* are the Edgeport will assert the RTS line */
  1887. if (C_CRTSCTS(tty)) {
  1888. status = restart_read(edge_port);
  1889. if (status)
  1890. dev_err(&port->dev,
  1891. "%s - read bulk usb_submit_urb failed: %d\n",
  1892. __func__, status);
  1893. }
  1894. }
  1895. static void stop_read(struct edgeport_port *edge_port)
  1896. {
  1897. unsigned long flags;
  1898. spin_lock_irqsave(&edge_port->ep_lock, flags);
  1899. if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING)
  1900. edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPING;
  1901. edge_port->shadow_mcr &= ~MCR_RTS;
  1902. spin_unlock_irqrestore(&edge_port->ep_lock, flags);
  1903. }
  1904. static int restart_read(struct edgeport_port *edge_port)
  1905. {
  1906. struct urb *urb;
  1907. int status = 0;
  1908. unsigned long flags;
  1909. spin_lock_irqsave(&edge_port->ep_lock, flags);
  1910. if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPED) {
  1911. urb = edge_port->port->read_urb;
  1912. urb->complete = edge_bulk_in_callback;
  1913. urb->context = edge_port;
  1914. urb->dev = edge_port->port->serial->dev;
  1915. status = usb_submit_urb(urb, GFP_ATOMIC);
  1916. }
  1917. edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING;
  1918. edge_port->shadow_mcr |= MCR_RTS;
  1919. spin_unlock_irqrestore(&edge_port->ep_lock, flags);
  1920. return status;
  1921. }
  1922. static void change_port_settings(struct tty_struct *tty,
  1923. struct edgeport_port *edge_port, struct ktermios *old_termios)
  1924. {
  1925. struct ump_uart_config *config;
  1926. int baud;
  1927. unsigned cflag;
  1928. int status;
  1929. int port_number = edge_port->port->number -
  1930. edge_port->port->serial->minor;
  1931. dbg("%s - port %d", __func__, edge_port->port->number);
  1932. config = kmalloc (sizeof (*config), GFP_KERNEL);
  1933. if (!config) {
  1934. *tty->termios = *old_termios;
  1935. dev_err(&edge_port->port->dev, "%s - out of memory\n",
  1936. __func__);
  1937. return;
  1938. }
  1939. cflag = tty->termios->c_cflag;
  1940. config->wFlags = 0;
  1941. /* These flags must be set */
  1942. config->wFlags |= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT;
  1943. config->wFlags |= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR;
  1944. config->bUartMode = (__u8)(edge_port->bUartMode);
  1945. switch (cflag & CSIZE) {
  1946. case CS5:
  1947. config->bDataBits = UMP_UART_CHAR5BITS;
  1948. dbg("%s - data bits = 5", __func__);
  1949. break;
  1950. case CS6:
  1951. config->bDataBits = UMP_UART_CHAR6BITS;
  1952. dbg("%s - data bits = 6", __func__);
  1953. break;
  1954. case CS7:
  1955. config->bDataBits = UMP_UART_CHAR7BITS;
  1956. dbg("%s - data bits = 7", __func__);
  1957. break;
  1958. default:
  1959. case CS8:
  1960. config->bDataBits = UMP_UART_CHAR8BITS;
  1961. dbg("%s - data bits = 8", __func__);
  1962. break;
  1963. }
  1964. if (cflag & PARENB) {
  1965. if (cflag & PARODD) {
  1966. config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
  1967. config->bParity = UMP_UART_ODDPARITY;
  1968. dbg("%s - parity = odd", __func__);
  1969. } else {
  1970. config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
  1971. config->bParity = UMP_UART_EVENPARITY;
  1972. dbg("%s - parity = even", __func__);
  1973. }
  1974. } else {
  1975. config->bParity = UMP_UART_NOPARITY;
  1976. dbg("%s - parity = none", __func__);
  1977. }
  1978. if (cflag & CSTOPB) {
  1979. config->bStopBits = UMP_UART_STOPBIT2;
  1980. dbg("%s - stop bits = 2", __func__);
  1981. } else {
  1982. config->bStopBits = UMP_UART_STOPBIT1;
  1983. dbg("%s - stop bits = 1", __func__);
  1984. }
  1985. /* figure out the flow control settings */
  1986. if (cflag & CRTSCTS) {
  1987. config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW;
  1988. config->wFlags |= UMP_MASK_UART_FLAGS_RTS_FLOW;
  1989. dbg("%s - RTS/CTS is enabled", __func__);
  1990. } else {
  1991. dbg("%s - RTS/CTS is disabled", __func__);
  1992. tty->hw_stopped = 0;
  1993. restart_read(edge_port);
  1994. }
  1995. /* if we are implementing XON/XOFF, set the start and stop
  1996. character in the device */
  1997. config->cXon = START_CHAR(tty);
  1998. config->cXoff = STOP_CHAR(tty);
  1999. /* if we are implementing INBOUND XON/XOFF */
  2000. if (I_IXOFF(tty)) {
  2001. config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
  2002. dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
  2003. __func__, config->cXon, config->cXoff);
  2004. } else
  2005. dbg("%s - INBOUND XON/XOFF is disabled", __func__);
  2006. /* if we are implementing OUTBOUND XON/XOFF */
  2007. if (I_IXON(tty)) {
  2008. config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
  2009. dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
  2010. __func__, config->cXon, config->cXoff);
  2011. } else
  2012. dbg("%s - OUTBOUND XON/XOFF is disabled", __func__);
  2013. tty->termios->c_cflag &= ~CMSPAR;
  2014. /* Round the baud rate */
  2015. baud = tty_get_baud_rate(tty);
  2016. if (!baud) {
  2017. /* pick a default, any default... */
  2018. baud = 9600;
  2019. } else
  2020. tty_encode_baud_rate(tty, baud, baud);
  2021. edge_port->baud_rate = baud;
  2022. config->wBaudRate = (__u16)((461550L + baud/2) / baud);
  2023. /* FIXME: Recompute actual baud from divisor here */
  2024. dbg("%s - baud rate = %d, wBaudRate = %d", __func__, baud,
  2025. config->wBaudRate);
  2026. dbg("wBaudRate: %d", (int)(461550L / config->wBaudRate));
  2027. dbg("wFlags: 0x%x", config->wFlags);
  2028. dbg("bDataBits: %d", config->bDataBits);
  2029. dbg("bParity: %d", config->bParity);
  2030. dbg("bStopBits: %d", config->bStopBits);
  2031. dbg("cXon: %d", config->cXon);
  2032. dbg("cXoff: %d", config->cXoff);
  2033. dbg("bUartMode: %d", config->bUartMode);
  2034. /* move the word values into big endian mode */
  2035. cpu_to_be16s(&config->wFlags);
  2036. cpu_to_be16s(&config->wBaudRate);
  2037. status = send_cmd(edge_port->port->serial->dev, UMPC_SET_CONFIG,
  2038. (__u8)(UMPM_UART1_PORT + port_number),
  2039. 0, (__u8 *)config, sizeof(*config));
  2040. if (status)
  2041. dbg("%s - error %d when trying to write config to device",
  2042. __func__, status);
  2043. kfree(config);
  2044. return;
  2045. }
  2046. static void edge_set_termios(struct tty_struct *tty,
  2047. struct usb_serial_port *port, struct ktermios *old_termios)
  2048. {
  2049. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  2050. unsigned int cflag;
  2051. cflag = tty->termios->c_cflag;
  2052. dbg("%s - clfag %08x iflag %08x", __func__,
  2053. tty->termios->c_cflag, tty->termios->c_iflag);
  2054. dbg("%s - old clfag %08x old iflag %08x", __func__,
  2055. old_termios->c_cflag, old_termios->c_iflag);
  2056. dbg("%s - port %d", __func__, port->number);
  2057. if (edge_port == NULL)
  2058. return;
  2059. /* change the port settings to the new ones specified */
  2060. change_port_settings(tty, edge_port, old_termios);
  2061. return;
  2062. }
  2063. static int edge_tiocmset(struct tty_struct *tty, struct file *file,
  2064. unsigned int set, unsigned int clear)
  2065. {
  2066. struct usb_serial_port *port = tty->driver_data;
  2067. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  2068. unsigned int mcr;
  2069. unsigned long flags;
  2070. dbg("%s - port %d", __func__, port->number);
  2071. spin_lock_irqsave(&edge_port->ep_lock, flags);
  2072. mcr = edge_port->shadow_mcr;
  2073. if (set & TIOCM_RTS)
  2074. mcr |= MCR_RTS;
  2075. if (set & TIOCM_DTR)
  2076. mcr |= MCR_DTR;
  2077. if (set & TIOCM_LOOP)
  2078. mcr |= MCR_LOOPBACK;
  2079. if (clear & TIOCM_RTS)
  2080. mcr &= ~MCR_RTS;
  2081. if (clear & TIOCM_DTR)
  2082. mcr &= ~MCR_DTR;
  2083. if (clear & TIOCM_LOOP)
  2084. mcr &= ~MCR_LOOPBACK;
  2085. edge_port->shadow_mcr = mcr;
  2086. spin_unlock_irqrestore(&edge_port->ep_lock, flags);
  2087. restore_mcr(edge_port, mcr);
  2088. return 0;
  2089. }
  2090. static int edge_tiocmget(struct tty_struct *tty, struct file *file)
  2091. {
  2092. struct usb_serial_port *port = tty->driver_data;
  2093. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  2094. unsigned int result = 0;
  2095. unsigned int msr;
  2096. unsigned int mcr;
  2097. unsigned long flags;
  2098. dbg("%s - port %d", __func__, port->number);
  2099. spin_lock_irqsave(&edge_port->ep_lock, flags);
  2100. msr = edge_port->shadow_msr;
  2101. mcr = edge_port->shadow_mcr;
  2102. result = ((mcr & MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */
  2103. | ((mcr & MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */
  2104. | ((msr & EDGEPORT_MSR_CTS) ? TIOCM_CTS: 0) /* 0x020 */
  2105. | ((msr & EDGEPORT_MSR_CD) ? TIOCM_CAR: 0) /* 0x040 */
  2106. | ((msr & EDGEPORT_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */
  2107. | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
  2108. dbg("%s -- %x", __func__, result);
  2109. spin_unlock_irqrestore(&edge_port->ep_lock, flags);
  2110. return result;
  2111. }
  2112. static int get_serial_info(struct edgeport_port *edge_port,
  2113. struct serial_struct __user *retinfo)
  2114. {
  2115. struct serial_struct tmp;
  2116. if (!retinfo)
  2117. return -EFAULT;
  2118. memset(&tmp, 0, sizeof(tmp));
  2119. tmp.type = PORT_16550A;
  2120. tmp.line = edge_port->port->serial->minor;
  2121. tmp.port = edge_port->port->number;
  2122. tmp.irq = 0;
  2123. tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
  2124. tmp.xmit_fifo_size = edge_port->port->bulk_out_size;
  2125. tmp.baud_base = 9600;
  2126. tmp.close_delay = 5*HZ;
  2127. tmp.closing_wait = closing_wait;
  2128. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  2129. return -EFAULT;
  2130. return 0;
  2131. }
  2132. static int edge_ioctl(struct tty_struct *tty, struct file *file,
  2133. unsigned int cmd, unsigned long arg)
  2134. {
  2135. struct usb_serial_port *port = tty->driver_data;
  2136. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  2137. struct async_icount cnow;
  2138. struct async_icount cprev;
  2139. dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
  2140. switch (cmd) {
  2141. case TIOCGSERIAL:
  2142. dbg("%s - (%d) TIOCGSERIAL", __func__, port->number);
  2143. return get_serial_info(edge_port,
  2144. (struct serial_struct __user *) arg);
  2145. case TIOCMIWAIT:
  2146. dbg("%s - (%d) TIOCMIWAIT", __func__, port->number);
  2147. cprev = edge_port->icount;
  2148. while (1) {
  2149. interruptible_sleep_on(&edge_port->delta_msr_wait);
  2150. /* see if a signal did it */
  2151. if (signal_pending(current))
  2152. return -ERESTARTSYS;
  2153. cnow = edge_port->icount;
  2154. if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
  2155. cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
  2156. return -EIO; /* no change => error */
  2157. if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
  2158. ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
  2159. ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
  2160. ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
  2161. return 0;
  2162. }
  2163. cprev = cnow;
  2164. }
  2165. /* not reached */
  2166. break;
  2167. case TIOCGICOUNT:
  2168. dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
  2169. port->number, edge_port->icount.rx, edge_port->icount.tx);
  2170. if (copy_to_user((void __user *)arg, &edge_port->icount,
  2171. sizeof(edge_port->icount)))
  2172. return -EFAULT;
  2173. return 0;
  2174. }
  2175. return -ENOIOCTLCMD;
  2176. }
  2177. static void edge_break(struct tty_struct *tty, int break_state)
  2178. {
  2179. struct usb_serial_port *port = tty->driver_data;
  2180. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  2181. int status;
  2182. int bv = 0; /* Off */
  2183. dbg("%s - state = %d", __func__, break_state);
  2184. /* chase the port close */
  2185. chase_port(edge_port, 0, 0);
  2186. if (break_state == -1)
  2187. bv = 1; /* On */
  2188. status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv);
  2189. if (status)
  2190. dbg("%s - error %d sending break set/clear command.",
  2191. __func__, status);
  2192. }
  2193. static int edge_startup(struct usb_serial *serial)
  2194. {
  2195. struct edgeport_serial *edge_serial;
  2196. struct edgeport_port *edge_port;
  2197. struct usb_device *dev;
  2198. int status;
  2199. int i;
  2200. dev = serial->dev;
  2201. /* create our private serial structure */
  2202. edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
  2203. if (edge_serial == NULL) {
  2204. dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
  2205. return -ENOMEM;
  2206. }
  2207. mutex_init(&edge_serial->es_lock);
  2208. edge_serial->serial = serial;
  2209. usb_set_serial_data(serial, edge_serial);
  2210. status = download_fw(edge_serial);
  2211. if (status) {
  2212. kfree(edge_serial);
  2213. return status;
  2214. }
  2215. /* set up our port private structures */
  2216. for (i = 0; i < serial->num_ports; ++i) {
  2217. edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL);
  2218. if (edge_port == NULL) {
  2219. dev_err(&serial->dev->dev, "%s - Out of memory\n",
  2220. __func__);
  2221. goto cleanup;
  2222. }
  2223. spin_lock_init(&edge_port->ep_lock);
  2224. edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE);
  2225. if (edge_port->ep_out_buf == NULL) {
  2226. dev_err(&serial->dev->dev, "%s - Out of memory\n",
  2227. __func__);
  2228. kfree(edge_port);
  2229. goto cleanup;
  2230. }
  2231. edge_port->port = serial->port[i];
  2232. edge_port->edge_serial = edge_serial;
  2233. usb_set_serial_port_data(serial->port[i], edge_port);
  2234. edge_port->bUartMode = default_uart_mode;
  2235. }
  2236. return 0;
  2237. cleanup:
  2238. for (--i; i >= 0; --i) {
  2239. edge_port = usb_get_serial_port_data(serial->port[i]);
  2240. edge_buf_free(edge_port->ep_out_buf);
  2241. kfree(edge_port);
  2242. usb_set_serial_port_data(serial->port[i], NULL);
  2243. }
  2244. kfree(edge_serial);
  2245. usb_set_serial_data(serial, NULL);
  2246. return -ENOMEM;
  2247. }
  2248. static void edge_shutdown(struct usb_serial *serial)
  2249. {
  2250. int i;
  2251. struct edgeport_port *edge_port;
  2252. dbg("%s", __func__);
  2253. for (i = 0; i < serial->num_ports; ++i) {
  2254. edge_port = usb_get_serial_port_data(serial->port[i]);
  2255. edge_remove_sysfs_attrs(edge_port->port);
  2256. edge_buf_free(edge_port->ep_out_buf);
  2257. kfree(edge_port);
  2258. usb_set_serial_port_data(serial->port[i], NULL);
  2259. }
  2260. kfree(usb_get_serial_data(serial));
  2261. usb_set_serial_data(serial, NULL);
  2262. }
  2263. /* Sysfs Attributes */
  2264. static ssize_t show_uart_mode(struct device *dev,
  2265. struct device_attribute *attr, char *buf)
  2266. {
  2267. struct usb_serial_port *port = to_usb_serial_port(dev);
  2268. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  2269. return sprintf(buf, "%d\n", edge_port->bUartMode);
  2270. }
  2271. static ssize_t store_uart_mode(struct device *dev,
  2272. struct device_attribute *attr, const char *valbuf, size_t count)
  2273. {
  2274. struct usb_serial_port *port = to_usb_serial_port(dev);
  2275. struct edgeport_port *edge_port = usb_get_serial_port_data(port);
  2276. unsigned int v = simple_strtoul(valbuf, NULL, 0);
  2277. dbg("%s: setting uart_mode = %d", __func__, v);
  2278. if (v < 256)
  2279. edge_port->bUartMode = v;
  2280. else
  2281. dev_err(dev, "%s - uart_mode %d is invalid\n", __func__, v);
  2282. return count;
  2283. }
  2284. static DEVICE_ATTR(uart_mode, S_IWUSR | S_IRUGO, show_uart_mode,
  2285. store_uart_mode);
  2286. static int edge_create_sysfs_attrs(struct usb_serial_port *port)
  2287. {
  2288. return device_create_file(&port->dev, &dev_attr_uart_mode);
  2289. }
  2290. static int edge_remove_sysfs_attrs(struct usb_serial_port *port)
  2291. {
  2292. device_remove_file(&port->dev, &dev_attr_uart_mode);
  2293. return 0;
  2294. }
  2295. /* Circular Buffer */
  2296. /*
  2297. * edge_buf_alloc
  2298. *
  2299. * Allocate a circular buffer and all associated memory.
  2300. */
  2301. static struct edge_buf *edge_buf_alloc(unsigned int size)
  2302. {
  2303. struct edge_buf *eb;
  2304. if (size == 0)
  2305. return NULL;
  2306. eb = kmalloc(sizeof(struct edge_buf), GFP_KERNEL);
  2307. if (eb == NULL)
  2308. return NULL;
  2309. eb->buf_buf = kmalloc(size, GFP_KERNEL);
  2310. if (eb->buf_buf == NULL) {
  2311. kfree(eb);
  2312. return NULL;
  2313. }
  2314. eb->buf_size = size;
  2315. eb->buf_get = eb->buf_put = eb->buf_buf;
  2316. return eb;
  2317. }
  2318. /*
  2319. * edge_buf_free
  2320. *
  2321. * Free the buffer and all associated memory.
  2322. */
  2323. static void edge_buf_free(struct edge_buf *eb)
  2324. {
  2325. if (eb) {
  2326. kfree(eb->buf_buf);
  2327. kfree(eb);
  2328. }
  2329. }
  2330. /*
  2331. * edge_buf_clear
  2332. *
  2333. * Clear out all data in the circular buffer.
  2334. */
  2335. static void edge_buf_clear(struct edge_buf *eb)
  2336. {
  2337. if (eb != NULL)
  2338. eb->buf_get = eb->buf_put;
  2339. /* equivalent to a get of all data available */
  2340. }
  2341. /*
  2342. * edge_buf_data_avail
  2343. *
  2344. * Return the number of bytes of data available in the circular
  2345. * buffer.
  2346. */
  2347. static unsigned int edge_buf_data_avail(struct edge_buf *eb)
  2348. {
  2349. if (eb == NULL)
  2350. return 0;
  2351. return ((eb->buf_size + eb->buf_put - eb->buf_get) % eb->buf_size);
  2352. }
  2353. /*
  2354. * edge_buf_space_avail
  2355. *
  2356. * Return the number of bytes of space available in the circular
  2357. * buffer.
  2358. */
  2359. static unsigned int edge_buf_space_avail(struct edge_buf *eb)
  2360. {
  2361. if (eb == NULL)
  2362. return 0;
  2363. return ((eb->buf_size + eb->buf_get - eb->buf_put - 1) % eb->buf_size);
  2364. }
  2365. /*
  2366. * edge_buf_put
  2367. *
  2368. * Copy data data from a user buffer and put it into the circular buffer.
  2369. * Restrict to the amount of space available.
  2370. *
  2371. * Return the number of bytes copied.
  2372. */
  2373. static unsigned int edge_buf_put(struct edge_buf *eb, const char *buf,
  2374. unsigned int count)
  2375. {
  2376. unsigned int len;
  2377. if (eb == NULL)
  2378. return 0;
  2379. len = edge_buf_space_avail(eb);
  2380. if (count > len)
  2381. count = len;
  2382. if (count == 0)
  2383. return 0;
  2384. len = eb->buf_buf + eb->buf_size - eb->buf_put;
  2385. if (count > len) {
  2386. memcpy(eb->buf_put, buf, len);
  2387. memcpy(eb->buf_buf, buf+len, count - len);
  2388. eb->buf_put = eb->buf_buf + count - len;
  2389. } else {
  2390. memcpy(eb->buf_put, buf, count);
  2391. if (count < len)
  2392. eb->buf_put += count;
  2393. else /* count == len */
  2394. eb->buf_put = eb->buf_buf;
  2395. }
  2396. return count;
  2397. }
  2398. /*
  2399. * edge_buf_get
  2400. *
  2401. * Get data from the circular buffer and copy to the given buffer.
  2402. * Restrict to the amount of data available.
  2403. *
  2404. * Return the number of bytes copied.
  2405. */
  2406. static unsigned int edge_buf_get(struct edge_buf *eb, char *buf,
  2407. unsigned int count)
  2408. {
  2409. unsigned int len;
  2410. if (eb == NULL)
  2411. return 0;
  2412. len = edge_buf_data_avail(eb);
  2413. if (count > len)
  2414. count = len;
  2415. if (count == 0)
  2416. return 0;
  2417. len = eb->buf_buf + eb->buf_size - eb->buf_get;
  2418. if (count > len) {
  2419. memcpy(buf, eb->buf_get, len);
  2420. memcpy(buf+len, eb->buf_buf, count - len);
  2421. eb->buf_get = eb->buf_buf + count - len;
  2422. } else {
  2423. memcpy(buf, eb->buf_get, count);
  2424. if (count < len)
  2425. eb->buf_get += count;
  2426. else /* count == len */
  2427. eb->buf_get = eb->buf_buf;
  2428. }
  2429. return count;
  2430. }
  2431. static struct usb_serial_driver edgeport_1port_device = {
  2432. .driver = {
  2433. .owner = THIS_MODULE,
  2434. .name = "edgeport_ti_1",
  2435. },
  2436. .description = "Edgeport TI 1 port adapter",
  2437. .usb_driver = &io_driver,
  2438. .id_table = edgeport_1port_id_table,
  2439. .num_ports = 1,
  2440. .open = edge_open,
  2441. .close = edge_close,
  2442. .throttle = edge_throttle,
  2443. .unthrottle = edge_unthrottle,
  2444. .attach = edge_startup,
  2445. .shutdown = edge_shutdown,
  2446. .port_probe = edge_create_sysfs_attrs,
  2447. .ioctl = edge_ioctl,
  2448. .set_termios = edge_set_termios,
  2449. .tiocmget = edge_tiocmget,
  2450. .tiocmset = edge_tiocmset,
  2451. .write = edge_write,
  2452. .write_room = edge_write_room,
  2453. .chars_in_buffer = edge_chars_in_buffer,
  2454. .break_ctl = edge_break,
  2455. .read_int_callback = edge_interrupt_callback,
  2456. .read_bulk_callback = edge_bulk_in_callback,
  2457. .write_bulk_callback = edge_bulk_out_callback,
  2458. };
  2459. static struct usb_serial_driver edgeport_2port_device = {
  2460. .driver = {
  2461. .owner = THIS_MODULE,
  2462. .name = "edgeport_ti_2",
  2463. },
  2464. .description = "Edgeport TI 2 port adapter",
  2465. .usb_driver = &io_driver,
  2466. .id_table = edgeport_2port_id_table,
  2467. .num_ports = 2,
  2468. .open = edge_open,
  2469. .close = edge_close,
  2470. .throttle = edge_throttle,
  2471. .unthrottle = edge_unthrottle,
  2472. .attach = edge_startup,
  2473. .shutdown = edge_shutdown,
  2474. .port_probe = edge_create_sysfs_attrs,
  2475. .ioctl = edge_ioctl,
  2476. .set_termios = edge_set_termios,
  2477. .tiocmget = edge_tiocmget,
  2478. .tiocmset = edge_tiocmset,
  2479. .write = edge_write,
  2480. .write_room = edge_write_room,
  2481. .chars_in_buffer = edge_chars_in_buffer,
  2482. .break_ctl = edge_break,
  2483. .read_int_callback = edge_interrupt_callback,
  2484. .read_bulk_callback = edge_bulk_in_callback,
  2485. .write_bulk_callback = edge_bulk_out_callback,
  2486. };
  2487. static int __init edgeport_init(void)
  2488. {
  2489. int retval;
  2490. retval = usb_serial_register(&edgeport_1port_device);
  2491. if (retval)
  2492. goto failed_1port_device_register;
  2493. retval = usb_serial_register(&edgeport_2port_device);
  2494. if (retval)
  2495. goto failed_2port_device_register;
  2496. retval = usb_register(&io_driver);
  2497. if (retval)
  2498. goto failed_usb_register;
  2499. info(DRIVER_DESC " " DRIVER_VERSION);
  2500. return 0;
  2501. failed_usb_register:
  2502. usb_serial_deregister(&edgeport_2port_device);
  2503. failed_2port_device_register:
  2504. usb_serial_deregister(&edgeport_1port_device);
  2505. failed_1port_device_register:
  2506. return retval;
  2507. }
  2508. static void __exit edgeport_exit(void)
  2509. {
  2510. usb_deregister(&io_driver);
  2511. usb_serial_deregister(&edgeport_1port_device);
  2512. usb_serial_deregister(&edgeport_2port_device);
  2513. }
  2514. module_init(edgeport_init);
  2515. module_exit(edgeport_exit);
  2516. /* Module information */
  2517. MODULE_AUTHOR(DRIVER_AUTHOR);
  2518. MODULE_DESCRIPTION(DRIVER_DESC);
  2519. MODULE_LICENSE("GPL");
  2520. MODULE_FIRMWARE("edgeport/down3.bin");
  2521. module_param(debug, bool, S_IRUGO | S_IWUSR);
  2522. MODULE_PARM_DESC(debug, "Debug enabled or not");
  2523. module_param(low_latency, bool, S_IRUGO | S_IWUSR);
  2524. MODULE_PARM_DESC(low_latency, "Low latency enabled or not");
  2525. module_param(closing_wait, int, S_IRUGO | S_IWUSR);
  2526. MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs");
  2527. module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR);
  2528. MODULE_PARM_DESC(ignore_cpu_rev,
  2529. "Ignore the cpu revision when connecting to a device");
  2530. module_param(default_uart_mode, int, S_IRUGO | S_IWUSR);
  2531. MODULE_PARM_DESC(default_uart_mode, "Default uart_mode, 0=RS232, ...");