io_ti.c 80 KB

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