io_ti.c 81 KB

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