io_ti.c 80 KB

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