ftdi_sio.c 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459
  1. /*
  2. * USB FTDI SIO driver
  3. *
  4. * Copyright (C) 1999 - 2001
  5. * Greg Kroah-Hartman (greg@kroah.com)
  6. * Bill Ryder (bryder@sgi.com)
  7. * Copyright (C) 2002
  8. * Kuba Ober (kuba@mareimbrium.org)
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * See Documentation/usb/usb-serial.txt for more information on using this
  16. * driver
  17. *
  18. * See http://ftdi-usb-sio.sourceforge.net for upto date testing info
  19. * and extra documentation
  20. *
  21. * Change entries from 2004 and earlier can be found in versions of this
  22. * file in kernel versions prior to the 2.6.24 release.
  23. *
  24. */
  25. /* Bill Ryder - bryder@sgi.com - wrote the FTDI_SIO implementation */
  26. /* Thanx to FTDI for so kindly providing details of the protocol required */
  27. /* to talk to the device */
  28. /* Thanx to gkh and the rest of the usb dev group for all code I have
  29. assimilated :-) */
  30. #include <linux/kernel.h>
  31. #include <linux/errno.h>
  32. #include <linux/init.h>
  33. #include <linux/slab.h>
  34. #include <linux/tty.h>
  35. #include <linux/tty_driver.h>
  36. #include <linux/tty_flip.h>
  37. #include <linux/module.h>
  38. #include <linux/spinlock.h>
  39. #include <linux/uaccess.h>
  40. #include <linux/usb.h>
  41. #include <linux/serial.h>
  42. #include <linux/usb/serial.h>
  43. #include "ftdi_sio.h"
  44. /*
  45. * Version Information
  46. */
  47. #define DRIVER_VERSION "v1.4.3"
  48. #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>"
  49. #define DRIVER_DESC "USB FTDI Serial Converters Driver"
  50. static int debug;
  51. static __u16 vendor = FTDI_VID;
  52. static __u16 product;
  53. struct ftdi_private {
  54. ftdi_chip_type_t chip_type;
  55. /* type of device, either SIO or FT8U232AM */
  56. int baud_base; /* baud base clock for divisor setting */
  57. int custom_divisor; /* custom_divisor kludge, this is for
  58. baud_base (different from what goes to the
  59. chip!) */
  60. __u16 last_set_data_urb_value ;
  61. /* the last data state set - needed for doing
  62. * a break
  63. */
  64. int write_offset; /* This is the offset in the usb data block to
  65. * write the serial data - it varies between
  66. * devices
  67. */
  68. int flags; /* some ASYNC_xxxx flags are supported */
  69. unsigned long last_dtr_rts; /* saved modem control outputs */
  70. wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
  71. char prev_status, diff_status; /* Used for TIOCMIWAIT */
  72. __u8 rx_flags; /* receive state flags (throttling) */
  73. spinlock_t rx_lock; /* spinlock for receive state */
  74. struct delayed_work rx_work;
  75. struct usb_serial_port *port;
  76. int rx_processed;
  77. unsigned long rx_bytes;
  78. __u16 interface; /* FT2232C port interface (0 for FT232/245) */
  79. speed_t force_baud; /* if non-zero, force the baud rate to
  80. this value */
  81. int force_rtscts; /* if non-zero, force RTS-CTS to always
  82. be enabled */
  83. spinlock_t tx_lock; /* spinlock for transmit state */
  84. unsigned long tx_bytes;
  85. unsigned long tx_outstanding_bytes;
  86. unsigned long tx_outstanding_urbs;
  87. };
  88. /* struct ftdi_sio_quirk is used by devices requiring special attention. */
  89. struct ftdi_sio_quirk {
  90. int (*probe)(struct usb_serial *);
  91. /* Special settings for probed ports. */
  92. void (*port_probe)(struct ftdi_private *);
  93. };
  94. static int ftdi_jtag_probe(struct usb_serial *serial);
  95. static int ftdi_mtxorb_hack_setup(struct usb_serial *serial);
  96. static void ftdi_USB_UIRT_setup(struct ftdi_private *priv);
  97. static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv);
  98. static struct ftdi_sio_quirk ftdi_jtag_quirk = {
  99. .probe = ftdi_jtag_probe,
  100. };
  101. static struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
  102. .probe = ftdi_mtxorb_hack_setup,
  103. };
  104. static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
  105. .port_probe = ftdi_USB_UIRT_setup,
  106. };
  107. static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
  108. .port_probe = ftdi_HE_TIRA1_setup,
  109. };
  110. /*
  111. * The 8U232AM has the same API as the sio except for:
  112. * - it can support MUCH higher baudrates; up to:
  113. * o 921600 for RS232 and 2000000 for RS422/485 at 48MHz
  114. * o 230400 at 12MHz
  115. * so .. 8U232AM's baudrate setting codes are different
  116. * - it has a two byte status code.
  117. * - it returns characters every 16ms (the FTDI does it every 40ms)
  118. *
  119. * the bcdDevice value is used to differentiate FT232BM and FT245BM from
  120. * the earlier FT8U232AM and FT8U232BM. For now, include all known VID/PID
  121. * combinations in both tables.
  122. * FIXME: perhaps bcdDevice can also identify 12MHz FT8U232AM devices,
  123. * but I don't know if those ever went into mass production. [Ian Abbott]
  124. */
  125. static struct usb_device_id id_table_combined [] = {
  126. { USB_DEVICE(FTDI_VID, FTDI_AMC232_PID) },
  127. { USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) },
  128. { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_0_PID) },
  129. { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_1_PID) },
  130. { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_2_PID) },
  131. { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_3_PID) },
  132. { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_4_PID) },
  133. { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_5_PID) },
  134. { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_6_PID) },
  135. { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_7_PID) },
  136. { USB_DEVICE(FTDI_VID, FTDI_ACTZWAVE_PID) },
  137. { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) },
  138. { USB_DEVICE(FTDI_VID, FTDI_IPLUS_PID) },
  139. { USB_DEVICE(FTDI_VID, FTDI_IPLUS2_PID) },
  140. { USB_DEVICE(FTDI_VID, FTDI_DMX4ALL) },
  141. { USB_DEVICE(FTDI_VID, FTDI_SIO_PID) },
  142. { USB_DEVICE(FTDI_VID, FTDI_8U232AM_PID) },
  143. { USB_DEVICE(FTDI_VID, FTDI_8U232AM_ALT_PID) },
  144. { USB_DEVICE(FTDI_VID, FTDI_232RL_PID) },
  145. { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) },
  146. { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) },
  147. { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) },
  148. { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) },
  149. { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) },
  150. { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) },
  151. { USB_DEVICE(FTDI_VID, FTDI_XF_632_PID) },
  152. { USB_DEVICE(FTDI_VID, FTDI_XF_634_PID) },
  153. { USB_DEVICE(FTDI_VID, FTDI_XF_547_PID) },
  154. { USB_DEVICE(FTDI_VID, FTDI_XF_633_PID) },
  155. { USB_DEVICE(FTDI_VID, FTDI_XF_631_PID) },
  156. { USB_DEVICE(FTDI_VID, FTDI_XF_635_PID) },
  157. { USB_DEVICE(FTDI_VID, FTDI_XF_640_PID) },
  158. { USB_DEVICE(FTDI_VID, FTDI_XF_642_PID) },
  159. { USB_DEVICE(FTDI_VID, FTDI_DSS20_PID) },
  160. { USB_DEVICE(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID) },
  161. { USB_DEVICE(FTDI_VID, FTDI_VNHCPCUSB_D_PID) },
  162. { USB_DEVICE(FTDI_VID, FTDI_MTXORB_0_PID) },
  163. { USB_DEVICE(FTDI_VID, FTDI_MTXORB_1_PID) },
  164. { USB_DEVICE(FTDI_VID, FTDI_MTXORB_2_PID) },
  165. { USB_DEVICE(FTDI_VID, FTDI_MTXORB_3_PID) },
  166. { USB_DEVICE(FTDI_VID, FTDI_MTXORB_4_PID) },
  167. { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) },
  168. { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) },
  169. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0100_PID) },
  170. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0101_PID) },
  171. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0102_PID) },
  172. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0103_PID) },
  173. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0104_PID) },
  174. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0105_PID) },
  175. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0106_PID) },
  176. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0107_PID) },
  177. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0108_PID) },
  178. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0109_PID) },
  179. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010A_PID) },
  180. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010B_PID) },
  181. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010C_PID) },
  182. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010D_PID) },
  183. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010E_PID) },
  184. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010F_PID) },
  185. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0110_PID) },
  186. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0111_PID) },
  187. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0112_PID) },
  188. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0113_PID) },
  189. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0114_PID) },
  190. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0115_PID) },
  191. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0116_PID) },
  192. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0117_PID) },
  193. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0118_PID) },
  194. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0119_PID) },
  195. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011A_PID) },
  196. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011B_PID) },
  197. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011C_PID) },
  198. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011D_PID) },
  199. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011E_PID) },
  200. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011F_PID) },
  201. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0120_PID) },
  202. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0121_PID) },
  203. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0122_PID) },
  204. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0123_PID) },
  205. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0124_PID) },
  206. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0125_PID) },
  207. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0126_PID) },
  208. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0127_PID),
  209. .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
  210. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0128_PID) },
  211. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0129_PID) },
  212. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012A_PID) },
  213. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012B_PID) },
  214. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012C_PID),
  215. .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
  216. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012D_PID) },
  217. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012E_PID) },
  218. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012F_PID) },
  219. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0130_PID) },
  220. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0131_PID) },
  221. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0132_PID) },
  222. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0133_PID) },
  223. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0134_PID) },
  224. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0135_PID) },
  225. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0136_PID) },
  226. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0137_PID) },
  227. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0138_PID) },
  228. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0139_PID) },
  229. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013A_PID) },
  230. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013B_PID) },
  231. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013C_PID) },
  232. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013D_PID) },
  233. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013E_PID) },
  234. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013F_PID) },
  235. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0140_PID) },
  236. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0141_PID) },
  237. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0142_PID) },
  238. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0143_PID) },
  239. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0144_PID) },
  240. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0145_PID) },
  241. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0146_PID) },
  242. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0147_PID) },
  243. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0148_PID) },
  244. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0149_PID) },
  245. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014A_PID) },
  246. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014B_PID) },
  247. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014C_PID) },
  248. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014D_PID) },
  249. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014E_PID) },
  250. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014F_PID) },
  251. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0150_PID) },
  252. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0151_PID) },
  253. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0152_PID) },
  254. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0153_PID),
  255. .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
  256. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0154_PID),
  257. .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
  258. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0155_PID),
  259. .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
  260. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0156_PID),
  261. .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
  262. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0157_PID),
  263. .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
  264. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0158_PID),
  265. .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
  266. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0159_PID) },
  267. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015A_PID) },
  268. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015B_PID) },
  269. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015C_PID) },
  270. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015D_PID) },
  271. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015E_PID) },
  272. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015F_PID) },
  273. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0160_PID) },
  274. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0161_PID) },
  275. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0162_PID) },
  276. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0163_PID) },
  277. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0164_PID) },
  278. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0165_PID) },
  279. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0166_PID) },
  280. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0167_PID) },
  281. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0168_PID) },
  282. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0169_PID) },
  283. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016A_PID) },
  284. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016B_PID) },
  285. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016C_PID) },
  286. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016D_PID) },
  287. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016E_PID) },
  288. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016F_PID) },
  289. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0170_PID) },
  290. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0171_PID) },
  291. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0172_PID) },
  292. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0173_PID) },
  293. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0174_PID) },
  294. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0175_PID) },
  295. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0176_PID) },
  296. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0177_PID) },
  297. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0178_PID) },
  298. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0179_PID) },
  299. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017A_PID) },
  300. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017B_PID) },
  301. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017C_PID) },
  302. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017D_PID) },
  303. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017E_PID) },
  304. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017F_PID) },
  305. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0180_PID) },
  306. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0181_PID) },
  307. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0182_PID) },
  308. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0183_PID) },
  309. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0184_PID) },
  310. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0185_PID) },
  311. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0186_PID) },
  312. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0187_PID) },
  313. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0188_PID) },
  314. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0189_PID) },
  315. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018A_PID) },
  316. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018B_PID) },
  317. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018C_PID) },
  318. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018D_PID) },
  319. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018E_PID) },
  320. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018F_PID) },
  321. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0190_PID) },
  322. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0191_PID) },
  323. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0192_PID) },
  324. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0193_PID) },
  325. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0194_PID) },
  326. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0195_PID) },
  327. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0196_PID) },
  328. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0197_PID) },
  329. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0198_PID) },
  330. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0199_PID) },
  331. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019A_PID) },
  332. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019B_PID) },
  333. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019C_PID) },
  334. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019D_PID) },
  335. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019E_PID) },
  336. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019F_PID) },
  337. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A0_PID) },
  338. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A1_PID) },
  339. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A2_PID) },
  340. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A3_PID) },
  341. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A4_PID) },
  342. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A5_PID) },
  343. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A6_PID) },
  344. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A7_PID) },
  345. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A8_PID) },
  346. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A9_PID) },
  347. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AA_PID) },
  348. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AB_PID) },
  349. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AC_PID) },
  350. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AD_PID) },
  351. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AE_PID) },
  352. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AF_PID) },
  353. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B0_PID) },
  354. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B1_PID) },
  355. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B2_PID) },
  356. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B3_PID) },
  357. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B4_PID) },
  358. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B5_PID) },
  359. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B6_PID) },
  360. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B7_PID) },
  361. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B8_PID) },
  362. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B9_PID) },
  363. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BA_PID) },
  364. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BB_PID) },
  365. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BC_PID) },
  366. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BD_PID) },
  367. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BE_PID) },
  368. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BF_PID) },
  369. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C0_PID) },
  370. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C1_PID) },
  371. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C2_PID) },
  372. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C3_PID) },
  373. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C4_PID) },
  374. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C5_PID) },
  375. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C6_PID) },
  376. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C7_PID) },
  377. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C8_PID) },
  378. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C9_PID) },
  379. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CA_PID) },
  380. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CB_PID) },
  381. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CC_PID) },
  382. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CD_PID) },
  383. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CE_PID) },
  384. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CF_PID) },
  385. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D0_PID) },
  386. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D1_PID) },
  387. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D2_PID) },
  388. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D3_PID) },
  389. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D4_PID) },
  390. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D5_PID) },
  391. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D6_PID) },
  392. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D7_PID) },
  393. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D8_PID) },
  394. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D9_PID) },
  395. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DA_PID) },
  396. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DB_PID) },
  397. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DC_PID) },
  398. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DD_PID) },
  399. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DE_PID) },
  400. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DF_PID) },
  401. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E0_PID) },
  402. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E1_PID) },
  403. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E2_PID) },
  404. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E3_PID) },
  405. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E4_PID) },
  406. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E5_PID) },
  407. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E6_PID) },
  408. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E7_PID) },
  409. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E8_PID) },
  410. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E9_PID) },
  411. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EA_PID) },
  412. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EB_PID) },
  413. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EC_PID) },
  414. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01ED_PID) },
  415. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EE_PID) },
  416. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EF_PID) },
  417. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F0_PID) },
  418. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F1_PID) },
  419. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F2_PID) },
  420. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F3_PID) },
  421. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F4_PID) },
  422. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F5_PID) },
  423. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F6_PID) },
  424. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F7_PID) },
  425. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F8_PID) },
  426. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F9_PID) },
  427. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FA_PID) },
  428. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FB_PID) },
  429. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FC_PID) },
  430. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FD_PID) },
  431. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FE_PID) },
  432. { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FF_PID) },
  433. { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) },
  434. { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) },
  435. { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) },
  436. { USB_DEVICE(FTDI_VID, FTDI_USBX_707_PID) },
  437. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2101_PID) },
  438. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) },
  439. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2103_PID) },
  440. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2104_PID) },
  441. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2106_PID) },
  442. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_1_PID) },
  443. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_2_PID) },
  444. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2202_1_PID) },
  445. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2202_2_PID) },
  446. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2203_1_PID) },
  447. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2203_2_PID) },
  448. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_1_PID) },
  449. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_2_PID) },
  450. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_3_PID) },
  451. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_4_PID) },
  452. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_1_PID) },
  453. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_2_PID) },
  454. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_3_PID) },
  455. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_4_PID) },
  456. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_1_PID) },
  457. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_2_PID) },
  458. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_3_PID) },
  459. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_4_PID) },
  460. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_1_PID) },
  461. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_2_PID) },
  462. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_3_PID) },
  463. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_4_PID) },
  464. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_5_PID) },
  465. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_6_PID) },
  466. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_7_PID) },
  467. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_8_PID) },
  468. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_1_PID) },
  469. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_2_PID) },
  470. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_3_PID) },
  471. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_4_PID) },
  472. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_5_PID) },
  473. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_6_PID) },
  474. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_7_PID) },
  475. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_8_PID) },
  476. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_1_PID) },
  477. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_2_PID) },
  478. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_3_PID) },
  479. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_4_PID) },
  480. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_5_PID) },
  481. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_6_PID) },
  482. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_7_PID) },
  483. { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_8_PID) },
  484. { USB_DEVICE(IDTECH_VID, IDTECH_IDT1221U_PID) },
  485. { USB_DEVICE(OCT_VID, OCT_US101_PID) },
  486. { USB_DEVICE(FTDI_VID, FTDI_HE_TIRA1_PID),
  487. .driver_info = (kernel_ulong_t)&ftdi_HE_TIRA1_quirk },
  488. { USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID),
  489. .driver_info = (kernel_ulong_t)&ftdi_USB_UIRT_quirk },
  490. { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_1) },
  491. { USB_DEVICE(FTDI_VID, PROTEGO_R2X0) },
  492. { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_3) },
  493. { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_4) },
  494. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E808_PID) },
  495. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E809_PID) },
  496. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80A_PID) },
  497. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80B_PID) },
  498. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80C_PID) },
  499. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80D_PID) },
  500. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80E_PID) },
  501. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80F_PID) },
  502. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E888_PID) },
  503. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E889_PID) },
  504. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88A_PID) },
  505. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88B_PID) },
  506. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88C_PID) },
  507. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88D_PID) },
  508. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88E_PID) },
  509. { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88F_PID) },
  510. { USB_DEVICE(FTDI_VID, FTDI_ELV_UO100_PID) },
  511. { USB_DEVICE(FTDI_VID, FTDI_ELV_UM100_PID) },
  512. { USB_DEVICE(FTDI_VID, FTDI_ELV_UR100_PID) },
  513. { USB_DEVICE(FTDI_VID, FTDI_ELV_ALC8500_PID) },
  514. { USB_DEVICE(FTDI_VID, FTDI_PYRAMID_PID) },
  515. { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1000PC_PID) },
  516. { USB_DEVICE(FTDI_VID, FTDI_IBS_US485_PID) },
  517. { USB_DEVICE(FTDI_VID, FTDI_IBS_PICPRO_PID) },
  518. { USB_DEVICE(FTDI_VID, FTDI_IBS_PCMCIA_PID) },
  519. { USB_DEVICE(FTDI_VID, FTDI_IBS_PK1_PID) },
  520. { USB_DEVICE(FTDI_VID, FTDI_IBS_RS232MON_PID) },
  521. { USB_DEVICE(FTDI_VID, FTDI_IBS_APP70_PID) },
  522. { USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) },
  523. { USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) },
  524. /*
  525. * Due to many user requests for multiple ELV devices we enable
  526. * them by default.
  527. */
  528. { USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) },
  529. { USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) },
  530. { USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) },
  531. { USB_DEVICE(FTDI_VID, FTDI_ELV_UDF77_PID) },
  532. { USB_DEVICE(FTDI_VID, FTDI_ELV_UIO88_PID) },
  533. { USB_DEVICE(FTDI_VID, FTDI_ELV_UAD8_PID) },
  534. { USB_DEVICE(FTDI_VID, FTDI_ELV_UDA7_PID) },
  535. { USB_DEVICE(FTDI_VID, FTDI_ELV_USI2_PID) },
  536. { USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) },
  537. { USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) },
  538. { USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) },
  539. { USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) },
  540. { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) },
  541. { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) },
  542. { USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) },
  543. { USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) },
  544. { USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) },
  545. { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) },
  546. { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1010PC_PID) },
  547. { USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) },
  548. { USB_DEVICE(FTDI_VID, FTDI_ELV_HS485_PID) },
  549. { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) },
  550. { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) },
  551. { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) },
  552. { USB_DEVICE(FTDI_VID, LINX_FUTURE_1_PID) },
  553. { USB_DEVICE(FTDI_VID, LINX_FUTURE_2_PID) },
  554. { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) },
  555. { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) },
  556. { USB_DEVICE(FTDI_VID, FTDI_CCSMACHX_2_PID) },
  557. { USB_DEVICE(FTDI_VID, INSIDE_ACCESSO) },
  558. { USB_DEVICE(INTREPID_VID, INTREPID_VALUECAN_PID) },
  559. { USB_DEVICE(INTREPID_VID, INTREPID_NEOVI_PID) },
  560. { USB_DEVICE(FALCOM_VID, FALCOM_TWIST_PID) },
  561. { USB_DEVICE(FALCOM_VID, FALCOM_SAMBA_PID) },
  562. { USB_DEVICE(FTDI_VID, FTDI_SUUNTO_SPORTS_PID) },
  563. { USB_DEVICE(TTI_VID, TTI_QL355P_PID) },
  564. { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) },
  565. { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) },
  566. { USB_DEVICE(BANDB_VID, BANDB_USTL4_PID) },
  567. { USB_DEVICE(BANDB_VID, BANDB_USO9ML2_PID) },
  568. { USB_DEVICE(FTDI_VID, EVER_ECO_PRO_CDS) },
  569. { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) },
  570. { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) },
  571. { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_0_PID) },
  572. { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_1_PID) },
  573. { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_2_PID) },
  574. { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_3_PID) },
  575. { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_4_PID) },
  576. { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_5_PID) },
  577. { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_6_PID) },
  578. { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_7_PID) },
  579. { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) },
  580. { USB_DEVICE(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID) },
  581. { USB_DEVICE(FTDI_VID, FTDI_MHAM_KW_PID) },
  582. { USB_DEVICE(FTDI_VID, FTDI_MHAM_YS_PID) },
  583. { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y6_PID) },
  584. { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y8_PID) },
  585. { USB_DEVICE(FTDI_VID, FTDI_MHAM_IC_PID) },
  586. { USB_DEVICE(FTDI_VID, FTDI_MHAM_DB9_PID) },
  587. { USB_DEVICE(FTDI_VID, FTDI_MHAM_RS232_PID) },
  588. { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y9_PID) },
  589. { USB_DEVICE(FTDI_VID, FTDI_TERATRONIK_VCP_PID) },
  590. { USB_DEVICE(FTDI_VID, FTDI_TERATRONIK_D2XX_PID) },
  591. { USB_DEVICE(EVOLUTION_VID, EVOLUTION_ER1_PID) },
  592. { USB_DEVICE(EVOLUTION_VID, EVO_HYBRID_PID) },
  593. { USB_DEVICE(EVOLUTION_VID, EVO_RCM4_PID) },
  594. { USB_DEVICE(FTDI_VID, FTDI_ARTEMIS_PID) },
  595. { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16_PID) },
  596. { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16C_PID) },
  597. { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HR_PID) },
  598. { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HRC_PID) },
  599. { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16IC_PID) },
  600. { USB_DEVICE(KOBIL_VID, KOBIL_CONV_B1_PID) },
  601. { USB_DEVICE(KOBIL_VID, KOBIL_CONV_KAAN_PID) },
  602. { USB_DEVICE(POSIFLEX_VID, POSIFLEX_PP7000_PID) },
  603. { USB_DEVICE(FTDI_VID, FTDI_TTUSB_PID) },
  604. { USB_DEVICE(FTDI_VID, FTDI_ECLO_COM_1WIRE_PID) },
  605. { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_777_PID) },
  606. { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_8900F_PID) },
  607. { USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) },
  608. { USB_DEVICE(FTDI_VID, FTDI_RRCIRKITS_LOCOBUFFER_PID) },
  609. { USB_DEVICE(FTDI_VID, FTDI_ASK_RDR400_PID) },
  610. { USB_DEVICE(ICOM_ID1_VID, ICOM_ID1_PID) },
  611. { USB_DEVICE(PAPOUCH_VID, PAPOUCH_TMU_PID) },
  612. { USB_DEVICE(FTDI_VID, FTDI_ACG_HFDUAL_PID) },
  613. { USB_DEVICE(FTDI_VID, FTDI_YEI_SERVOCENTER31_PID) },
  614. { USB_DEVICE(FTDI_VID, FTDI_THORLABS_PID) },
  615. { USB_DEVICE(TESTO_VID, TESTO_USB_INTERFACE_PID) },
  616. { USB_DEVICE(FTDI_VID, FTDI_GAMMA_SCOUT_PID) },
  617. { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13M_PID) },
  618. { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13S_PID) },
  619. { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13U_PID) },
  620. { USB_DEVICE(ELEKTOR_VID, ELEKTOR_FT323R_PID) },
  621. { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) },
  622. { USB_DEVICE(FTDI_VID, FTDI_MAXSTREAM_PID) },
  623. { USB_DEVICE(FTDI_VID, FTDI_PHI_FISCO_PID) },
  624. { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) },
  625. { USB_DEVICE(FTDI_VID, FTDI_ELSTER_UNICOM_PID) },
  626. { USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) },
  627. { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID),
  628. .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
  629. { USB_DEVICE(FIC_VID, FIC_NEO1973_DEBUG_PID),
  630. .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
  631. { USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID),
  632. .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
  633. { USB_DEVICE(FTDI_VID, LMI_LM3S_DEVEL_BOARD_PID),
  634. .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
  635. { USB_DEVICE(FTDI_VID, LMI_LM3S_EVAL_BOARD_PID),
  636. .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
  637. { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_USB60F) },
  638. { USB_DEVICE(FTDI_VID, FTDI_REU_TINY_PID) },
  639. { USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO4x4_PID) },
  640. { USB_DEVICE(FTDI_VID, FTDI_DOMINTELL_DGQG_PID) },
  641. { USB_DEVICE(FTDI_VID, FTDI_DOMINTELL_DUSB_PID) },
  642. { }, /* Optional parameter entry */
  643. { } /* Terminating entry */
  644. };
  645. MODULE_DEVICE_TABLE(usb, id_table_combined);
  646. static struct usb_driver ftdi_driver = {
  647. .name = "ftdi_sio",
  648. .probe = usb_serial_probe,
  649. .disconnect = usb_serial_disconnect,
  650. .id_table = id_table_combined,
  651. .no_dynamic_id = 1,
  652. };
  653. static const char *ftdi_chip_name[] = {
  654. [SIO] = "SIO", /* the serial part of FT8U100AX */
  655. [FT8U232AM] = "FT8U232AM",
  656. [FT232BM] = "FT232BM",
  657. [FT2232C] = "FT2232C",
  658. [FT232RL] = "FT232RL",
  659. };
  660. /* Constants for read urb and write urb */
  661. #define BUFSZ 512
  662. #define PKTSZ 64
  663. /* rx_flags */
  664. #define THROTTLED 0x01
  665. #define ACTUALLY_THROTTLED 0x02
  666. /* Used for TIOCMIWAIT */
  667. #define FTDI_STATUS_B0_MASK (FTDI_RS0_CTS | FTDI_RS0_DSR | FTDI_RS0_RI | FTDI_RS0_RLSD)
  668. #define FTDI_STATUS_B1_MASK (FTDI_RS_BI)
  669. /* End TIOCMIWAIT */
  670. #define FTDI_IMPL_ASYNC_FLAGS = (ASYNC_SPD_HI | ASYNC_SPD_VHI \
  671. | ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP)
  672. /* function prototypes for a FTDI serial converter */
  673. static int ftdi_sio_probe(struct usb_serial *serial,
  674. const struct usb_device_id *id);
  675. static void ftdi_shutdown(struct usb_serial *serial);
  676. static int ftdi_sio_port_probe(struct usb_serial_port *port);
  677. static int ftdi_sio_port_remove(struct usb_serial_port *port);
  678. static int ftdi_open(struct tty_struct *tty,
  679. struct usb_serial_port *port, struct file *filp);
  680. static void ftdi_close(struct tty_struct *tty,
  681. struct usb_serial_port *port, struct file *filp);
  682. static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
  683. const unsigned char *buf, int count);
  684. static int ftdi_write_room(struct tty_struct *tty);
  685. static int ftdi_chars_in_buffer(struct tty_struct *tty);
  686. static void ftdi_write_bulk_callback(struct urb *urb);
  687. static void ftdi_read_bulk_callback(struct urb *urb);
  688. static void ftdi_process_read(struct work_struct *work);
  689. static void ftdi_set_termios(struct tty_struct *tty,
  690. struct usb_serial_port *port, struct ktermios *old);
  691. static int ftdi_tiocmget(struct tty_struct *tty, struct file *file);
  692. static int ftdi_tiocmset(struct tty_struct *tty, struct file *file,
  693. unsigned int set, unsigned int clear);
  694. static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
  695. unsigned int cmd, unsigned long arg);
  696. static void ftdi_break_ctl(struct tty_struct *tty, int break_state);
  697. static void ftdi_throttle(struct tty_struct *tty);
  698. static void ftdi_unthrottle(struct tty_struct *tty);
  699. static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base);
  700. static unsigned short int ftdi_232am_baud_to_divisor(int baud);
  701. static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base);
  702. static __u32 ftdi_232bm_baud_to_divisor(int baud);
  703. static struct usb_serial_driver ftdi_sio_device = {
  704. .driver = {
  705. .owner = THIS_MODULE,
  706. .name = "ftdi_sio",
  707. },
  708. .description = "FTDI USB Serial Device",
  709. .usb_driver = &ftdi_driver ,
  710. .id_table = id_table_combined,
  711. .num_ports = 1,
  712. .probe = ftdi_sio_probe,
  713. .port_probe = ftdi_sio_port_probe,
  714. .port_remove = ftdi_sio_port_remove,
  715. .open = ftdi_open,
  716. .close = ftdi_close,
  717. .throttle = ftdi_throttle,
  718. .unthrottle = ftdi_unthrottle,
  719. .write = ftdi_write,
  720. .write_room = ftdi_write_room,
  721. .chars_in_buffer = ftdi_chars_in_buffer,
  722. .read_bulk_callback = ftdi_read_bulk_callback,
  723. .write_bulk_callback = ftdi_write_bulk_callback,
  724. .tiocmget = ftdi_tiocmget,
  725. .tiocmset = ftdi_tiocmset,
  726. .ioctl = ftdi_ioctl,
  727. .set_termios = ftdi_set_termios,
  728. .break_ctl = ftdi_break_ctl,
  729. .shutdown = ftdi_shutdown,
  730. };
  731. #define WDR_TIMEOUT 5000 /* default urb timeout */
  732. #define WDR_SHORT_TIMEOUT 1000 /* shorter urb timeout */
  733. /* High and low are for DTR, RTS etc etc */
  734. #define HIGH 1
  735. #define LOW 0
  736. /* number of outstanding urbs to prevent userspace DoS from happening */
  737. #define URB_UPPER_LIMIT 42
  738. /*
  739. * ***************************************************************************
  740. * Utility functions
  741. * ***************************************************************************
  742. */
  743. static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base)
  744. {
  745. unsigned short int divisor;
  746. /* divisor shifted 3 bits to the left */
  747. int divisor3 = base / 2 / baud;
  748. if ((divisor3 & 0x7) == 7)
  749. divisor3++; /* round x.7/8 up to x+1 */
  750. divisor = divisor3 >> 3;
  751. divisor3 &= 0x7;
  752. if (divisor3 == 1)
  753. divisor |= 0xc000;
  754. else if (divisor3 >= 4)
  755. divisor |= 0x4000;
  756. else if (divisor3 != 0)
  757. divisor |= 0x8000;
  758. else if (divisor == 1)
  759. divisor = 0; /* special case for maximum baud rate */
  760. return divisor;
  761. }
  762. static unsigned short int ftdi_232am_baud_to_divisor(int baud)
  763. {
  764. return ftdi_232am_baud_base_to_divisor(baud, 48000000);
  765. }
  766. static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base)
  767. {
  768. static const unsigned char divfrac[8] = { 0, 3, 2, 4, 1, 5, 6, 7 };
  769. __u32 divisor;
  770. /* divisor shifted 3 bits to the left */
  771. int divisor3 = base / 2 / baud;
  772. divisor = divisor3 >> 3;
  773. divisor |= (__u32)divfrac[divisor3 & 0x7] << 14;
  774. /* Deal with special cases for highest baud rates. */
  775. if (divisor == 1)
  776. divisor = 0;
  777. else if (divisor == 0x4001)
  778. divisor = 1;
  779. return divisor;
  780. }
  781. static __u32 ftdi_232bm_baud_to_divisor(int baud)
  782. {
  783. return ftdi_232bm_baud_base_to_divisor(baud, 48000000);
  784. }
  785. #define set_mctrl(port, set) update_mctrl((port), (set), 0)
  786. #define clear_mctrl(port, clear) update_mctrl((port), 0, (clear))
  787. static int update_mctrl(struct usb_serial_port *port, unsigned int set,
  788. unsigned int clear)
  789. {
  790. struct ftdi_private *priv = usb_get_serial_port_data(port);
  791. char *buf;
  792. unsigned urb_value;
  793. int rv;
  794. if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0) {
  795. dbg("%s - DTR|RTS not being set|cleared", __func__);
  796. return 0; /* no change */
  797. }
  798. buf = kmalloc(1, GFP_NOIO);
  799. if (!buf)
  800. return -ENOMEM;
  801. clear &= ~set; /* 'set' takes precedence over 'clear' */
  802. urb_value = 0;
  803. if (clear & TIOCM_DTR)
  804. urb_value |= FTDI_SIO_SET_DTR_LOW;
  805. if (clear & TIOCM_RTS)
  806. urb_value |= FTDI_SIO_SET_RTS_LOW;
  807. if (set & TIOCM_DTR)
  808. urb_value |= FTDI_SIO_SET_DTR_HIGH;
  809. if (set & TIOCM_RTS)
  810. urb_value |= FTDI_SIO_SET_RTS_HIGH;
  811. rv = usb_control_msg(port->serial->dev,
  812. usb_sndctrlpipe(port->serial->dev, 0),
  813. FTDI_SIO_SET_MODEM_CTRL_REQUEST,
  814. FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE,
  815. urb_value, priv->interface,
  816. buf, 0, WDR_TIMEOUT);
  817. kfree(buf);
  818. if (rv < 0) {
  819. err("%s Error from MODEM_CTRL urb: DTR %s, RTS %s",
  820. __func__,
  821. (set & TIOCM_DTR) ? "HIGH" :
  822. (clear & TIOCM_DTR) ? "LOW" : "unchanged",
  823. (set & TIOCM_RTS) ? "HIGH" :
  824. (clear & TIOCM_RTS) ? "LOW" : "unchanged");
  825. } else {
  826. dbg("%s - DTR %s, RTS %s", __func__,
  827. (set & TIOCM_DTR) ? "HIGH" :
  828. (clear & TIOCM_DTR) ? "LOW" : "unchanged",
  829. (set & TIOCM_RTS) ? "HIGH" :
  830. (clear & TIOCM_RTS) ? "LOW" : "unchanged");
  831. /* FIXME: locking on last_dtr_rts */
  832. priv->last_dtr_rts = (priv->last_dtr_rts & ~clear) | set;
  833. }
  834. return rv;
  835. }
  836. static __u32 get_ftdi_divisor(struct tty_struct *tty,
  837. struct usb_serial_port *port)
  838. { /* get_ftdi_divisor */
  839. struct ftdi_private *priv = usb_get_serial_port_data(port);
  840. __u32 div_value = 0;
  841. int div_okay = 1;
  842. int baud;
  843. /*
  844. * The logic involved in setting the baudrate can be cleanly split into
  845. * 3 steps.
  846. * 1. Standard baud rates are set in tty->termios->c_cflag
  847. * 2. If these are not enough, you can set any speed using alt_speed as
  848. * follows:
  849. * - set tty->termios->c_cflag speed to B38400
  850. * - set your real speed in tty->alt_speed; it gets ignored when
  851. * alt_speed==0, (or)
  852. * - call TIOCSSERIAL ioctl with (struct serial_struct) set as
  853. * follows:
  854. * flags & ASYNC_SPD_MASK == ASYNC_SPD_[HI, VHI, SHI, WARP],
  855. * this just sets alt_speed to (HI: 57600, VHI: 115200,
  856. * SHI: 230400, WARP: 460800)
  857. * ** Steps 1, 2 are done courtesy of tty_get_baud_rate
  858. * 3. You can also set baud rate by setting custom divisor as follows
  859. * - set tty->termios->c_cflag speed to B38400
  860. * - call TIOCSSERIAL ioctl with (struct serial_struct) set as
  861. * follows:
  862. * o flags & ASYNC_SPD_MASK == ASYNC_SPD_CUST
  863. * o custom_divisor set to baud_base / your_new_baudrate
  864. * ** Step 3 is done courtesy of code borrowed from serial.c
  865. * I should really spend some time and separate + move this common
  866. * code to serial.c, it is replicated in nearly every serial driver
  867. * you see.
  868. */
  869. /* 1. Get the baud rate from the tty settings, this observes
  870. alt_speed hack */
  871. baud = tty_get_baud_rate(tty);
  872. dbg("%s - tty_get_baud_rate reports speed %d", __func__, baud);
  873. /* 2. Observe async-compatible custom_divisor hack, update baudrate
  874. if needed */
  875. if (baud == 38400 &&
  876. ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
  877. (priv->custom_divisor)) {
  878. baud = priv->baud_base / priv->custom_divisor;
  879. dbg("%s - custom divisor %d sets baud rate to %d",
  880. __func__, priv->custom_divisor, baud);
  881. }
  882. /* 3. Convert baudrate to device-specific divisor */
  883. if (!baud)
  884. baud = 9600;
  885. switch (priv->chip_type) {
  886. case SIO: /* SIO chip */
  887. switch (baud) {
  888. case 300: div_value = ftdi_sio_b300; break;
  889. case 600: div_value = ftdi_sio_b600; break;
  890. case 1200: div_value = ftdi_sio_b1200; break;
  891. case 2400: div_value = ftdi_sio_b2400; break;
  892. case 4800: div_value = ftdi_sio_b4800; break;
  893. case 9600: div_value = ftdi_sio_b9600; break;
  894. case 19200: div_value = ftdi_sio_b19200; break;
  895. case 38400: div_value = ftdi_sio_b38400; break;
  896. case 57600: div_value = ftdi_sio_b57600; break;
  897. case 115200: div_value = ftdi_sio_b115200; break;
  898. } /* baud */
  899. if (div_value == 0) {
  900. dbg("%s - Baudrate (%d) requested is not supported",
  901. __func__, baud);
  902. div_value = ftdi_sio_b9600;
  903. baud = 9600;
  904. div_okay = 0;
  905. }
  906. break;
  907. case FT8U232AM: /* 8U232AM chip */
  908. if (baud <= 3000000) {
  909. div_value = ftdi_232am_baud_to_divisor(baud);
  910. } else {
  911. dbg("%s - Baud rate too high!", __func__);
  912. baud = 9600;
  913. div_value = ftdi_232am_baud_to_divisor(9600);
  914. div_okay = 0;
  915. }
  916. break;
  917. case FT232BM: /* FT232BM chip */
  918. case FT2232C: /* FT2232C chip */
  919. case FT232RL:
  920. if (baud <= 3000000) {
  921. div_value = ftdi_232bm_baud_to_divisor(baud);
  922. } else {
  923. dbg("%s - Baud rate too high!", __func__);
  924. div_value = ftdi_232bm_baud_to_divisor(9600);
  925. div_okay = 0;
  926. baud = 9600;
  927. }
  928. break;
  929. } /* priv->chip_type */
  930. if (div_okay) {
  931. dbg("%s - Baud rate set to %d (divisor 0x%lX) on chip %s",
  932. __func__, baud, (unsigned long)div_value,
  933. ftdi_chip_name[priv->chip_type]);
  934. }
  935. tty_encode_baud_rate(tty, baud, baud);
  936. return div_value;
  937. }
  938. static int change_speed(struct tty_struct *tty, struct usb_serial_port *port)
  939. {
  940. struct ftdi_private *priv = usb_get_serial_port_data(port);
  941. char *buf;
  942. __u16 urb_value;
  943. __u16 urb_index;
  944. __u32 urb_index_value;
  945. int rv;
  946. buf = kmalloc(1, GFP_NOIO);
  947. if (!buf)
  948. return -ENOMEM;
  949. urb_index_value = get_ftdi_divisor(tty, port);
  950. urb_value = (__u16)urb_index_value;
  951. urb_index = (__u16)(urb_index_value >> 16);
  952. if (priv->interface) { /* FT2232C */
  953. urb_index = (__u16)((urb_index << 8) | priv->interface);
  954. }
  955. rv = usb_control_msg(port->serial->dev,
  956. usb_sndctrlpipe(port->serial->dev, 0),
  957. FTDI_SIO_SET_BAUDRATE_REQUEST,
  958. FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE,
  959. urb_value, urb_index,
  960. buf, 0, WDR_SHORT_TIMEOUT);
  961. kfree(buf);
  962. return rv;
  963. }
  964. static int get_serial_info(struct usb_serial_port *port,
  965. struct serial_struct __user *retinfo)
  966. {
  967. struct ftdi_private *priv = usb_get_serial_port_data(port);
  968. struct serial_struct tmp;
  969. if (!retinfo)
  970. return -EFAULT;
  971. memset(&tmp, 0, sizeof(tmp));
  972. tmp.flags = priv->flags;
  973. tmp.baud_base = priv->baud_base;
  974. tmp.custom_divisor = priv->custom_divisor;
  975. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  976. return -EFAULT;
  977. return 0;
  978. } /* get_serial_info */
  979. static int set_serial_info(struct tty_struct *tty,
  980. struct usb_serial_port *port, struct serial_struct __user *newinfo)
  981. { /* set_serial_info */
  982. struct ftdi_private *priv = usb_get_serial_port_data(port);
  983. struct serial_struct new_serial;
  984. struct ftdi_private old_priv;
  985. if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
  986. return -EFAULT;
  987. old_priv = *priv;
  988. /* Do error checking and permission checking */
  989. if (!capable(CAP_SYS_ADMIN)) {
  990. if (((new_serial.flags & ~ASYNC_USR_MASK) !=
  991. (priv->flags & ~ASYNC_USR_MASK)))
  992. return -EPERM;
  993. priv->flags = ((priv->flags & ~ASYNC_USR_MASK) |
  994. (new_serial.flags & ASYNC_USR_MASK));
  995. priv->custom_divisor = new_serial.custom_divisor;
  996. goto check_and_exit;
  997. }
  998. if ((new_serial.baud_base != priv->baud_base) &&
  999. (new_serial.baud_base < 9600))
  1000. return -EINVAL;
  1001. /* Make the changes - these are privileged changes! */
  1002. priv->flags = ((priv->flags & ~ASYNC_FLAGS) |
  1003. (new_serial.flags & ASYNC_FLAGS));
  1004. priv->custom_divisor = new_serial.custom_divisor;
  1005. tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
  1006. check_and_exit:
  1007. if ((old_priv.flags & ASYNC_SPD_MASK) !=
  1008. (priv->flags & ASYNC_SPD_MASK)) {
  1009. if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  1010. tty->alt_speed = 57600;
  1011. else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  1012. tty->alt_speed = 115200;
  1013. else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  1014. tty->alt_speed = 230400;
  1015. else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  1016. tty->alt_speed = 460800;
  1017. else
  1018. tty->alt_speed = 0;
  1019. }
  1020. if (((old_priv.flags & ASYNC_SPD_MASK) !=
  1021. (priv->flags & ASYNC_SPD_MASK)) ||
  1022. (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
  1023. (old_priv.custom_divisor != priv->custom_divisor))) {
  1024. change_speed(tty, port);
  1025. }
  1026. return 0;
  1027. } /* set_serial_info */
  1028. /* Determine type of FTDI chip based on USB config and descriptor. */
  1029. static void ftdi_determine_type(struct usb_serial_port *port)
  1030. {
  1031. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1032. struct usb_serial *serial = port->serial;
  1033. struct usb_device *udev = serial->dev;
  1034. unsigned version;
  1035. unsigned interfaces;
  1036. /* Assume it is not the original SIO device for now. */
  1037. priv->baud_base = 48000000 / 2;
  1038. priv->write_offset = 0;
  1039. version = le16_to_cpu(udev->descriptor.bcdDevice);
  1040. interfaces = udev->actconfig->desc.bNumInterfaces;
  1041. dbg("%s: bcdDevice = 0x%x, bNumInterfaces = %u", __func__,
  1042. version, interfaces);
  1043. if (interfaces > 1) {
  1044. int inter;
  1045. /* Multiple interfaces. Assume FT2232C. */
  1046. priv->chip_type = FT2232C;
  1047. /* Determine interface code. */
  1048. inter = serial->interface->altsetting->desc.bInterfaceNumber;
  1049. if (inter == 0)
  1050. priv->interface = PIT_SIOA;
  1051. else
  1052. priv->interface = PIT_SIOB;
  1053. /* BM-type devices have a bug where bcdDevice gets set
  1054. * to 0x200 when iSerialNumber is 0. */
  1055. if (version < 0x500) {
  1056. dbg("%s: something fishy - bcdDevice too low for multi-interface device",
  1057. __func__);
  1058. }
  1059. } else if (version < 0x200) {
  1060. /* Old device. Assume its the original SIO. */
  1061. priv->chip_type = SIO;
  1062. priv->baud_base = 12000000 / 16;
  1063. priv->write_offset = 1;
  1064. } else if (version < 0x400) {
  1065. /* Assume its an FT8U232AM (or FT8U245AM) */
  1066. /* (It might be a BM because of the iSerialNumber bug,
  1067. * but it will still work as an AM device.) */
  1068. priv->chip_type = FT8U232AM;
  1069. } else if (version < 0x600) {
  1070. /* Assume its an FT232BM (or FT245BM) */
  1071. priv->chip_type = FT232BM;
  1072. } else {
  1073. /* Assume its an FT232R */
  1074. priv->chip_type = FT232RL;
  1075. }
  1076. info("Detected %s", ftdi_chip_name[priv->chip_type]);
  1077. }
  1078. /*
  1079. * ***************************************************************************
  1080. * Sysfs Attribute
  1081. * ***************************************************************************
  1082. */
  1083. static ssize_t show_latency_timer(struct device *dev,
  1084. struct device_attribute *attr, char *buf)
  1085. {
  1086. struct usb_serial_port *port = to_usb_serial_port(dev);
  1087. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1088. struct usb_device *udev = port->serial->dev;
  1089. unsigned short latency = 0;
  1090. int rv = 0;
  1091. dbg("%s", __func__);
  1092. rv = usb_control_msg(udev,
  1093. usb_rcvctrlpipe(udev, 0),
  1094. FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
  1095. FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE,
  1096. 0, priv->interface,
  1097. (char *) &latency, 1, WDR_TIMEOUT);
  1098. if (rv < 0) {
  1099. dev_err(dev, "Unable to read latency timer: %i\n", rv);
  1100. return -EIO;
  1101. }
  1102. return sprintf(buf, "%i\n", latency);
  1103. }
  1104. /* Write a new value of the latency timer, in units of milliseconds. */
  1105. static ssize_t store_latency_timer(struct device *dev,
  1106. struct device_attribute *attr, const char *valbuf,
  1107. size_t count)
  1108. {
  1109. struct usb_serial_port *port = to_usb_serial_port(dev);
  1110. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1111. struct usb_device *udev = port->serial->dev;
  1112. char buf[1];
  1113. int v = simple_strtoul(valbuf, NULL, 10);
  1114. int rv = 0;
  1115. dbg("%s: setting latency timer = %i", __func__, v);
  1116. rv = usb_control_msg(udev,
  1117. usb_sndctrlpipe(udev, 0),
  1118. FTDI_SIO_SET_LATENCY_TIMER_REQUEST,
  1119. FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE,
  1120. v, priv->interface,
  1121. buf, 0, WDR_TIMEOUT);
  1122. if (rv < 0) {
  1123. dev_err(dev, "Unable to write latency timer: %i\n", rv);
  1124. return -EIO;
  1125. }
  1126. return count;
  1127. }
  1128. /* Write an event character directly to the FTDI register. The ASCII
  1129. value is in the low 8 bits, with the enable bit in the 9th bit. */
  1130. static ssize_t store_event_char(struct device *dev,
  1131. struct device_attribute *attr, const char *valbuf, size_t count)
  1132. {
  1133. struct usb_serial_port *port = to_usb_serial_port(dev);
  1134. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1135. struct usb_device *udev = port->serial->dev;
  1136. char buf[1];
  1137. int v = simple_strtoul(valbuf, NULL, 10);
  1138. int rv = 0;
  1139. dbg("%s: setting event char = %i", __func__, v);
  1140. rv = usb_control_msg(udev,
  1141. usb_sndctrlpipe(udev, 0),
  1142. FTDI_SIO_SET_EVENT_CHAR_REQUEST,
  1143. FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE,
  1144. v, priv->interface,
  1145. buf, 0, WDR_TIMEOUT);
  1146. if (rv < 0) {
  1147. dbg("Unable to write event character: %i", rv);
  1148. return -EIO;
  1149. }
  1150. return count;
  1151. }
  1152. static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer,
  1153. store_latency_timer);
  1154. static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char);
  1155. static int create_sysfs_attrs(struct usb_serial_port *port)
  1156. {
  1157. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1158. int retval = 0;
  1159. dbg("%s", __func__);
  1160. /* XXX I've no idea if the original SIO supports the event_char
  1161. * sysfs parameter, so I'm playing it safe. */
  1162. if (priv->chip_type != SIO) {
  1163. dbg("sysfs attributes for %s", ftdi_chip_name[priv->chip_type]);
  1164. retval = device_create_file(&port->dev, &dev_attr_event_char);
  1165. if ((!retval) &&
  1166. (priv->chip_type == FT232BM ||
  1167. priv->chip_type == FT2232C ||
  1168. priv->chip_type == FT232RL)) {
  1169. retval = device_create_file(&port->dev,
  1170. &dev_attr_latency_timer);
  1171. }
  1172. }
  1173. return retval;
  1174. }
  1175. static void remove_sysfs_attrs(struct usb_serial_port *port)
  1176. {
  1177. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1178. dbg("%s", __func__);
  1179. /* XXX see create_sysfs_attrs */
  1180. if (priv->chip_type != SIO) {
  1181. device_remove_file(&port->dev, &dev_attr_event_char);
  1182. if (priv->chip_type == FT232BM ||
  1183. priv->chip_type == FT2232C ||
  1184. priv->chip_type == FT232RL) {
  1185. device_remove_file(&port->dev, &dev_attr_latency_timer);
  1186. }
  1187. }
  1188. }
  1189. /*
  1190. * ***************************************************************************
  1191. * FTDI driver specific functions
  1192. * ***************************************************************************
  1193. */
  1194. /* Probe function to check for special devices */
  1195. static int ftdi_sio_probe(struct usb_serial *serial,
  1196. const struct usb_device_id *id)
  1197. {
  1198. struct ftdi_sio_quirk *quirk =
  1199. (struct ftdi_sio_quirk *)id->driver_info;
  1200. if (quirk && quirk->probe) {
  1201. int ret = quirk->probe(serial);
  1202. if (ret != 0)
  1203. return ret;
  1204. }
  1205. usb_set_serial_data(serial, (void *)id->driver_info);
  1206. return 0;
  1207. }
  1208. static int ftdi_sio_port_probe(struct usb_serial_port *port)
  1209. {
  1210. struct ftdi_private *priv;
  1211. struct ftdi_sio_quirk *quirk = usb_get_serial_data(port->serial);
  1212. dbg("%s", __func__);
  1213. priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL);
  1214. if (!priv) {
  1215. err("%s- kmalloc(%Zd) failed.", __func__,
  1216. sizeof(struct ftdi_private));
  1217. return -ENOMEM;
  1218. }
  1219. spin_lock_init(&priv->rx_lock);
  1220. spin_lock_init(&priv->tx_lock);
  1221. init_waitqueue_head(&priv->delta_msr_wait);
  1222. /* This will push the characters through immediately rather
  1223. than queue a task to deliver them */
  1224. priv->flags = ASYNC_LOW_LATENCY;
  1225. if (quirk && quirk->port_probe)
  1226. quirk->port_probe(priv);
  1227. /* Increase the size of read buffers */
  1228. kfree(port->bulk_in_buffer);
  1229. port->bulk_in_buffer = kmalloc(BUFSZ, GFP_KERNEL);
  1230. if (!port->bulk_in_buffer) {
  1231. kfree(priv);
  1232. return -ENOMEM;
  1233. }
  1234. if (port->read_urb) {
  1235. port->read_urb->transfer_buffer = port->bulk_in_buffer;
  1236. port->read_urb->transfer_buffer_length = BUFSZ;
  1237. }
  1238. INIT_DELAYED_WORK(&priv->rx_work, ftdi_process_read);
  1239. priv->port = port;
  1240. /* Free port's existing write urb and transfer buffer. */
  1241. if (port->write_urb) {
  1242. usb_free_urb(port->write_urb);
  1243. port->write_urb = NULL;
  1244. }
  1245. kfree(port->bulk_out_buffer);
  1246. port->bulk_out_buffer = NULL;
  1247. usb_set_serial_port_data(port, priv);
  1248. ftdi_determine_type(port);
  1249. create_sysfs_attrs(port);
  1250. return 0;
  1251. }
  1252. /* Setup for the USB-UIRT device, which requires hardwired
  1253. * baudrate (38400 gets mapped to 312500) */
  1254. /* Called from usbserial:serial_probe */
  1255. static void ftdi_USB_UIRT_setup(struct ftdi_private *priv)
  1256. {
  1257. dbg("%s", __func__);
  1258. priv->flags |= ASYNC_SPD_CUST;
  1259. priv->custom_divisor = 77;
  1260. priv->force_baud = 38400;
  1261. } /* ftdi_USB_UIRT_setup */
  1262. /* Setup for the HE-TIRA1 device, which requires hardwired
  1263. * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */
  1264. static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv)
  1265. {
  1266. dbg("%s", __func__);
  1267. priv->flags |= ASYNC_SPD_CUST;
  1268. priv->custom_divisor = 240;
  1269. priv->force_baud = 38400;
  1270. priv->force_rtscts = 1;
  1271. } /* ftdi_HE_TIRA1_setup */
  1272. /*
  1273. * First port on JTAG adaptors such as Olimex arm-usb-ocd or the FIC/OpenMoko
  1274. * Neo1973 Debug Board is reserved for JTAG interface and can be accessed from
  1275. * userspace using openocd.
  1276. */
  1277. static int ftdi_jtag_probe(struct usb_serial *serial)
  1278. {
  1279. struct usb_device *udev = serial->dev;
  1280. struct usb_interface *interface = serial->interface;
  1281. dbg("%s", __func__);
  1282. if (interface == udev->actconfig->interface[0]) {
  1283. info("Ignoring serial port reserved for JTAG");
  1284. return -ENODEV;
  1285. }
  1286. return 0;
  1287. }
  1288. /*
  1289. * The Matrix Orbital VK204-25-USB has an invalid IN endpoint.
  1290. * We have to correct it if we want to read from it.
  1291. */
  1292. static int ftdi_mtxorb_hack_setup(struct usb_serial *serial)
  1293. {
  1294. struct usb_host_endpoint *ep = serial->dev->ep_in[1];
  1295. struct usb_endpoint_descriptor *ep_desc = &ep->desc;
  1296. if (ep->enabled && ep_desc->wMaxPacketSize == 0) {
  1297. ep_desc->wMaxPacketSize = cpu_to_le16(0x40);
  1298. info("Fixing invalid wMaxPacketSize on read pipe");
  1299. }
  1300. return 0;
  1301. }
  1302. /* ftdi_shutdown is called from usbserial:usb_serial_disconnect
  1303. * it is called when the usb device is disconnected
  1304. *
  1305. * usbserial:usb_serial_disconnect
  1306. * calls __serial_close for each open of the port
  1307. * shutdown is called then (ie ftdi_shutdown)
  1308. */
  1309. static void ftdi_shutdown(struct usb_serial *serial)
  1310. {
  1311. dbg("%s", __func__);
  1312. }
  1313. static int ftdi_sio_port_remove(struct usb_serial_port *port)
  1314. {
  1315. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1316. dbg("%s", __func__);
  1317. remove_sysfs_attrs(port);
  1318. /* all open ports are closed at this point
  1319. * (by usbserial.c:__serial_close, which calls ftdi_close)
  1320. */
  1321. if (priv) {
  1322. usb_set_serial_port_data(port, NULL);
  1323. kfree(priv);
  1324. }
  1325. return 0;
  1326. }
  1327. static int ftdi_open(struct tty_struct *tty,
  1328. struct usb_serial_port *port, struct file *filp)
  1329. { /* ftdi_open */
  1330. struct usb_device *dev = port->serial->dev;
  1331. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1332. unsigned long flags;
  1333. int result = 0;
  1334. char buf[1]; /* Needed for the usb_control_msg I think */
  1335. dbg("%s", __func__);
  1336. spin_lock_irqsave(&priv->tx_lock, flags);
  1337. priv->tx_bytes = 0;
  1338. spin_unlock_irqrestore(&priv->tx_lock, flags);
  1339. spin_lock_irqsave(&priv->rx_lock, flags);
  1340. priv->rx_bytes = 0;
  1341. spin_unlock_irqrestore(&priv->rx_lock, flags);
  1342. if (tty)
  1343. tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
  1344. /* No error checking for this (will get errors later anyway) */
  1345. /* See ftdi_sio.h for description of what is reset */
  1346. usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  1347. FTDI_SIO_RESET_REQUEST, FTDI_SIO_RESET_REQUEST_TYPE,
  1348. FTDI_SIO_RESET_SIO,
  1349. priv->interface, buf, 0, WDR_TIMEOUT);
  1350. /* Termios defaults are set by usb_serial_init. We don't change
  1351. port->tty->termios - this would loose speed settings, etc.
  1352. This is same behaviour as serial.c/rs_open() - Kuba */
  1353. /* ftdi_set_termios will send usb control messages */
  1354. if (tty)
  1355. ftdi_set_termios(tty, port, tty->termios);
  1356. /* FIXME: Flow control might be enabled, so it should be checked -
  1357. we have no control of defaults! */
  1358. /* Turn on RTS and DTR since we are not flow controlling by default */
  1359. set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
  1360. /* Not throttled */
  1361. spin_lock_irqsave(&priv->rx_lock, flags);
  1362. priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
  1363. spin_unlock_irqrestore(&priv->rx_lock, flags);
  1364. /* Start reading from the device */
  1365. priv->rx_processed = 0;
  1366. usb_fill_bulk_urb(port->read_urb, dev,
  1367. usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
  1368. port->read_urb->transfer_buffer,
  1369. port->read_urb->transfer_buffer_length,
  1370. ftdi_read_bulk_callback, port);
  1371. result = usb_submit_urb(port->read_urb, GFP_KERNEL);
  1372. if (result)
  1373. err("%s - failed submitting read urb, error %d",
  1374. __func__, result);
  1375. return result;
  1376. } /* ftdi_open */
  1377. /*
  1378. * usbserial:__serial_close only calls ftdi_close if the point is open
  1379. *
  1380. * This only gets called when it is the last close
  1381. *
  1382. *
  1383. */
  1384. static void ftdi_close(struct tty_struct *tty,
  1385. struct usb_serial_port *port, struct file *filp)
  1386. { /* ftdi_close */
  1387. unsigned int c_cflag = tty->termios->c_cflag;
  1388. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1389. char buf[1];
  1390. dbg("%s", __func__);
  1391. mutex_lock(&port->serial->disc_mutex);
  1392. if (c_cflag & HUPCL && !port->serial->disconnected) {
  1393. /* Disable flow control */
  1394. if (usb_control_msg(port->serial->dev,
  1395. usb_sndctrlpipe(port->serial->dev, 0),
  1396. FTDI_SIO_SET_FLOW_CTRL_REQUEST,
  1397. FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
  1398. 0, priv->interface, buf, 0,
  1399. WDR_TIMEOUT) < 0) {
  1400. err("error from flowcontrol urb");
  1401. }
  1402. /* drop RTS and DTR */
  1403. clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
  1404. } /* Note change no line if hupcl is off */
  1405. mutex_unlock(&port->serial->disc_mutex);
  1406. /* cancel any scheduled reading */
  1407. cancel_delayed_work(&priv->rx_work);
  1408. flush_scheduled_work();
  1409. /* shutdown our bulk read */
  1410. usb_kill_urb(port->read_urb);
  1411. } /* ftdi_close */
  1412. /* The SIO requires the first byte to have:
  1413. * B0 1
  1414. * B1 0
  1415. * B2..7 length of message excluding byte 0
  1416. *
  1417. * The new devices do not require this byte
  1418. */
  1419. static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
  1420. const unsigned char *buf, int count)
  1421. { /* ftdi_write */
  1422. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1423. struct urb *urb;
  1424. unsigned char *buffer;
  1425. int data_offset ; /* will be 1 for the SIO and 0 otherwise */
  1426. int status;
  1427. int transfer_size;
  1428. unsigned long flags;
  1429. dbg("%s port %d, %d bytes", __func__, port->number, count);
  1430. if (count == 0) {
  1431. dbg("write request of 0 bytes");
  1432. return 0;
  1433. }
  1434. spin_lock_irqsave(&priv->tx_lock, flags);
  1435. if (priv->tx_outstanding_urbs > URB_UPPER_LIMIT) {
  1436. spin_unlock_irqrestore(&priv->tx_lock, flags);
  1437. dbg("%s - write limit hit\n", __func__);
  1438. return 0;
  1439. }
  1440. priv->tx_outstanding_urbs++;
  1441. spin_unlock_irqrestore(&priv->tx_lock, flags);
  1442. data_offset = priv->write_offset;
  1443. dbg("data_offset set to %d", data_offset);
  1444. /* Determine total transfer size */
  1445. transfer_size = count;
  1446. if (data_offset > 0) {
  1447. /* Original sio needs control bytes too... */
  1448. transfer_size += (data_offset *
  1449. ((count + (PKTSZ - 1 - data_offset)) /
  1450. (PKTSZ - data_offset)));
  1451. }
  1452. buffer = kmalloc(transfer_size, GFP_ATOMIC);
  1453. if (!buffer) {
  1454. err("%s ran out of kernel memory for urb ...", __func__);
  1455. count = -ENOMEM;
  1456. goto error_no_buffer;
  1457. }
  1458. urb = usb_alloc_urb(0, GFP_ATOMIC);
  1459. if (!urb) {
  1460. err("%s - no more free urbs", __func__);
  1461. count = -ENOMEM;
  1462. goto error_no_urb;
  1463. }
  1464. /* Copy data */
  1465. if (data_offset > 0) {
  1466. /* Original sio requires control byte at start of
  1467. each packet. */
  1468. int user_pktsz = PKTSZ - data_offset;
  1469. int todo = count;
  1470. unsigned char *first_byte = buffer;
  1471. const unsigned char *current_position = buf;
  1472. while (todo > 0) {
  1473. if (user_pktsz > todo)
  1474. user_pktsz = todo;
  1475. /* Write the control byte at the front of the packet*/
  1476. *first_byte = 1 | ((user_pktsz) << 2);
  1477. /* Copy data for packet */
  1478. memcpy(first_byte + data_offset,
  1479. current_position, user_pktsz);
  1480. first_byte += user_pktsz + data_offset;
  1481. current_position += user_pktsz;
  1482. todo -= user_pktsz;
  1483. }
  1484. } else {
  1485. /* No control byte required. */
  1486. /* Copy in the data to send */
  1487. memcpy(buffer, buf, count);
  1488. }
  1489. usb_serial_debug_data(debug, &port->dev, __func__,
  1490. transfer_size, buffer);
  1491. /* fill the buffer and send it */
  1492. usb_fill_bulk_urb(urb, port->serial->dev,
  1493. usb_sndbulkpipe(port->serial->dev,
  1494. port->bulk_out_endpointAddress),
  1495. buffer, transfer_size,
  1496. ftdi_write_bulk_callback, port);
  1497. status = usb_submit_urb(urb, GFP_ATOMIC);
  1498. if (status) {
  1499. err("%s - failed submitting write urb, error %d",
  1500. __func__, status);
  1501. count = status;
  1502. goto error;
  1503. } else {
  1504. spin_lock_irqsave(&priv->tx_lock, flags);
  1505. priv->tx_outstanding_bytes += count;
  1506. priv->tx_bytes += count;
  1507. spin_unlock_irqrestore(&priv->tx_lock, flags);
  1508. }
  1509. /* we are done with this urb, so let the host driver
  1510. * really free it when it is finished with it */
  1511. usb_free_urb(urb);
  1512. dbg("%s write returning: %d", __func__, count);
  1513. return count;
  1514. error:
  1515. usb_free_urb(urb);
  1516. error_no_urb:
  1517. kfree(buffer);
  1518. error_no_buffer:
  1519. spin_lock_irqsave(&priv->tx_lock, flags);
  1520. priv->tx_outstanding_urbs--;
  1521. spin_unlock_irqrestore(&priv->tx_lock, flags);
  1522. return count;
  1523. } /* ftdi_write */
  1524. /* This function may get called when the device is closed */
  1525. static void ftdi_write_bulk_callback(struct urb *urb)
  1526. {
  1527. unsigned long flags;
  1528. struct usb_serial_port *port = urb->context;
  1529. struct ftdi_private *priv;
  1530. int data_offset; /* will be 1 for the SIO and 0 otherwise */
  1531. unsigned long countback;
  1532. int status = urb->status;
  1533. /* free up the transfer buffer, as usb_free_urb() does not do this */
  1534. kfree(urb->transfer_buffer);
  1535. dbg("%s - port %d", __func__, port->number);
  1536. if (status) {
  1537. dbg("nonzero write bulk status received: %d", status);
  1538. return;
  1539. }
  1540. priv = usb_get_serial_port_data(port);
  1541. if (!priv) {
  1542. dbg("%s - bad port private data pointer - exiting", __func__);
  1543. return;
  1544. }
  1545. /* account for transferred data */
  1546. countback = urb->actual_length;
  1547. data_offset = priv->write_offset;
  1548. if (data_offset > 0) {
  1549. /* Subtract the control bytes */
  1550. countback -= (data_offset * DIV_ROUND_UP(countback, PKTSZ));
  1551. }
  1552. spin_lock_irqsave(&priv->tx_lock, flags);
  1553. --priv->tx_outstanding_urbs;
  1554. priv->tx_outstanding_bytes -= countback;
  1555. spin_unlock_irqrestore(&priv->tx_lock, flags);
  1556. usb_serial_port_softint(port);
  1557. } /* ftdi_write_bulk_callback */
  1558. static int ftdi_write_room(struct tty_struct *tty)
  1559. {
  1560. struct usb_serial_port *port = tty->driver_data;
  1561. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1562. int room;
  1563. unsigned long flags;
  1564. dbg("%s - port %d", __func__, port->number);
  1565. spin_lock_irqsave(&priv->tx_lock, flags);
  1566. if (priv->tx_outstanding_urbs < URB_UPPER_LIMIT) {
  1567. /*
  1568. * We really can take anything the user throws at us
  1569. * but let's pick a nice big number to tell the tty
  1570. * layer that we have lots of free space
  1571. */
  1572. room = 2048;
  1573. } else {
  1574. room = 0;
  1575. }
  1576. spin_unlock_irqrestore(&priv->tx_lock, flags);
  1577. return room;
  1578. }
  1579. static int ftdi_chars_in_buffer(struct tty_struct *tty)
  1580. {
  1581. struct usb_serial_port *port = tty->driver_data;
  1582. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1583. int buffered;
  1584. unsigned long flags;
  1585. dbg("%s - port %d", __func__, port->number);
  1586. spin_lock_irqsave(&priv->tx_lock, flags);
  1587. buffered = (int)priv->tx_outstanding_bytes;
  1588. spin_unlock_irqrestore(&priv->tx_lock, flags);
  1589. if (buffered < 0) {
  1590. err("%s outstanding tx bytes is negative!", __func__);
  1591. buffered = 0;
  1592. }
  1593. return buffered;
  1594. }
  1595. static void ftdi_read_bulk_callback(struct urb *urb)
  1596. {
  1597. struct usb_serial_port *port = urb->context;
  1598. struct tty_struct *tty;
  1599. struct ftdi_private *priv;
  1600. unsigned long countread;
  1601. unsigned long flags;
  1602. int status = urb->status;
  1603. if (urb->number_of_packets > 0) {
  1604. err("%s transfer_buffer_length %d actual_length %d number of packets %d",
  1605. __func__,
  1606. urb->transfer_buffer_length,
  1607. urb->actual_length, urb->number_of_packets);
  1608. err("%s transfer_flags %x ", __func__, urb->transfer_flags);
  1609. }
  1610. dbg("%s - port %d", __func__, port->number);
  1611. if (port->port.count <= 0)
  1612. return;
  1613. tty = port->port.tty;
  1614. if (!tty) {
  1615. dbg("%s - bad tty pointer - exiting", __func__);
  1616. return;
  1617. }
  1618. priv = usb_get_serial_port_data(port);
  1619. if (!priv) {
  1620. dbg("%s - bad port private data pointer - exiting", __func__);
  1621. return;
  1622. }
  1623. if (urb != port->read_urb)
  1624. err("%s - Not my urb!", __func__);
  1625. if (status) {
  1626. /* This will happen at close every time so it is a dbg not an
  1627. err */
  1628. dbg("(this is ok on close) nonzero read bulk status received: %d", status);
  1629. return;
  1630. }
  1631. /* count data bytes, but not status bytes */
  1632. countread = urb->actual_length;
  1633. countread -= 2 * DIV_ROUND_UP(countread, PKTSZ);
  1634. spin_lock_irqsave(&priv->rx_lock, flags);
  1635. priv->rx_bytes += countread;
  1636. spin_unlock_irqrestore(&priv->rx_lock, flags);
  1637. ftdi_process_read(&priv->rx_work.work);
  1638. } /* ftdi_read_bulk_callback */
  1639. static void ftdi_process_read(struct work_struct *work)
  1640. { /* ftdi_process_read */
  1641. struct ftdi_private *priv =
  1642. container_of(work, struct ftdi_private, rx_work.work);
  1643. struct usb_serial_port *port = priv->port;
  1644. struct urb *urb;
  1645. struct tty_struct *tty;
  1646. char error_flag;
  1647. unsigned char *data;
  1648. int i;
  1649. int result;
  1650. int need_flip;
  1651. int packet_offset;
  1652. unsigned long flags;
  1653. dbg("%s - port %d", __func__, port->number);
  1654. if (port->port.count <= 0)
  1655. return;
  1656. tty = port->port.tty;
  1657. if (!tty) {
  1658. dbg("%s - bad tty pointer - exiting", __func__);
  1659. return;
  1660. }
  1661. priv = usb_get_serial_port_data(port);
  1662. if (!priv) {
  1663. dbg("%s - bad port private data pointer - exiting", __func__);
  1664. return;
  1665. }
  1666. urb = port->read_urb;
  1667. if (!urb) {
  1668. dbg("%s - bad read_urb pointer - exiting", __func__);
  1669. return;
  1670. }
  1671. data = urb->transfer_buffer;
  1672. if (priv->rx_processed) {
  1673. dbg("%s - already processed: %d bytes, %d remain", __func__,
  1674. priv->rx_processed,
  1675. urb->actual_length - priv->rx_processed);
  1676. } else {
  1677. /* The first two bytes of every read packet are status */
  1678. if (urb->actual_length > 2)
  1679. usb_serial_debug_data(debug, &port->dev, __func__,
  1680. urb->actual_length, data);
  1681. else
  1682. dbg("Status only: %03oo %03oo", data[0], data[1]);
  1683. }
  1684. /* TO DO -- check for hung up line and handle appropriately: */
  1685. /* send hangup */
  1686. /* See acm.c - you do a tty_hangup - eg tty_hangup(tty) */
  1687. /* if CD is dropped and the line is not CLOCAL then we should hangup */
  1688. need_flip = 0;
  1689. for (packet_offset = priv->rx_processed;
  1690. packet_offset < urb->actual_length; packet_offset += PKTSZ) {
  1691. int length;
  1692. /* Compare new line status to the old one, signal if different/
  1693. N.B. packet may be processed more than once, but differences
  1694. are only processed once. */
  1695. if (priv != NULL) {
  1696. char new_status = data[packet_offset + 0] &
  1697. FTDI_STATUS_B0_MASK;
  1698. if (new_status != priv->prev_status) {
  1699. priv->diff_status |=
  1700. new_status ^ priv->prev_status;
  1701. wake_up_interruptible(&priv->delta_msr_wait);
  1702. priv->prev_status = new_status;
  1703. }
  1704. }
  1705. length = min(PKTSZ, urb->actual_length-packet_offset)-2;
  1706. if (length < 0) {
  1707. err("%s - bad packet length: %d", __func__, length+2);
  1708. length = 0;
  1709. }
  1710. if (priv->rx_flags & THROTTLED) {
  1711. dbg("%s - throttled", __func__);
  1712. break;
  1713. }
  1714. if (tty_buffer_request_room(tty, length) < length) {
  1715. /* break out & wait for throttling/unthrottling to
  1716. happen */
  1717. dbg("%s - receive room low", __func__);
  1718. break;
  1719. }
  1720. /* Handle errors and break */
  1721. error_flag = TTY_NORMAL;
  1722. /* Although the device uses a bitmask and hence can have
  1723. multiple errors on a packet - the order here sets the
  1724. priority the error is returned to the tty layer */
  1725. if (data[packet_offset+1] & FTDI_RS_OE) {
  1726. error_flag = TTY_OVERRUN;
  1727. dbg("OVERRRUN error");
  1728. }
  1729. if (data[packet_offset+1] & FTDI_RS_BI) {
  1730. error_flag = TTY_BREAK;
  1731. dbg("BREAK received");
  1732. }
  1733. if (data[packet_offset+1] & FTDI_RS_PE) {
  1734. error_flag = TTY_PARITY;
  1735. dbg("PARITY error");
  1736. }
  1737. if (data[packet_offset+1] & FTDI_RS_FE) {
  1738. error_flag = TTY_FRAME;
  1739. dbg("FRAMING error");
  1740. }
  1741. if (length > 0) {
  1742. for (i = 2; i < length+2; i++) {
  1743. /* Note that the error flag is duplicated for
  1744. every character received since we don't know
  1745. which character it applied to */
  1746. tty_insert_flip_char(tty,
  1747. data[packet_offset + i], error_flag);
  1748. }
  1749. need_flip = 1;
  1750. }
  1751. #ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW
  1752. /* if a parity error is detected you get status packets forever
  1753. until a character is sent without a parity error.
  1754. This doesn't work well since the application receives a
  1755. never ending stream of bad data - even though new data
  1756. hasn't been sent. Therefore I (bill) have taken this out.
  1757. However - this might make sense for framing errors and so on
  1758. so I am leaving the code in for now.
  1759. */
  1760. else {
  1761. if (error_flag != TTY_NORMAL) {
  1762. dbg("error_flag is not normal");
  1763. /* In this case it is just status - if that is
  1764. an error send a bad character */
  1765. if (tty->flip.count >= TTY_FLIPBUF_SIZE)
  1766. tty_flip_buffer_push(tty);
  1767. tty_insert_flip_char(tty, 0xff, error_flag);
  1768. need_flip = 1;
  1769. }
  1770. }
  1771. #endif
  1772. } /* "for(packet_offset=0..." */
  1773. /* Low latency */
  1774. if (need_flip)
  1775. tty_flip_buffer_push(tty);
  1776. if (packet_offset < urb->actual_length) {
  1777. /* not completely processed - record progress */
  1778. priv->rx_processed = packet_offset;
  1779. dbg("%s - incomplete, %d bytes processed, %d remain",
  1780. __func__, packet_offset,
  1781. urb->actual_length - packet_offset);
  1782. /* check if we were throttled while processing */
  1783. spin_lock_irqsave(&priv->rx_lock, flags);
  1784. if (priv->rx_flags & THROTTLED) {
  1785. priv->rx_flags |= ACTUALLY_THROTTLED;
  1786. spin_unlock_irqrestore(&priv->rx_lock, flags);
  1787. dbg("%s - deferring remainder until unthrottled",
  1788. __func__);
  1789. return;
  1790. }
  1791. spin_unlock_irqrestore(&priv->rx_lock, flags);
  1792. /* if the port is closed stop trying to read */
  1793. if (port->port.count > 0)
  1794. /* delay processing of remainder */
  1795. schedule_delayed_work(&priv->rx_work, 1);
  1796. else
  1797. dbg("%s - port is closed", __func__);
  1798. return;
  1799. }
  1800. /* urb is completely processed */
  1801. priv->rx_processed = 0;
  1802. /* if the port is closed stop trying to read */
  1803. if (port->port.count > 0) {
  1804. /* Continue trying to always read */
  1805. usb_fill_bulk_urb(port->read_urb, port->serial->dev,
  1806. usb_rcvbulkpipe(port->serial->dev,
  1807. port->bulk_in_endpointAddress),
  1808. port->read_urb->transfer_buffer,
  1809. port->read_urb->transfer_buffer_length,
  1810. ftdi_read_bulk_callback, port);
  1811. result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
  1812. if (result)
  1813. err("%s - failed resubmitting read urb, error %d",
  1814. __func__, result);
  1815. }
  1816. } /* ftdi_process_read */
  1817. static void ftdi_break_ctl(struct tty_struct *tty, int break_state)
  1818. {
  1819. struct usb_serial_port *port = tty->driver_data;
  1820. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1821. __u16 urb_value = 0;
  1822. char buf[1];
  1823. /* break_state = -1 to turn on break, and 0 to turn off break */
  1824. /* see drivers/char/tty_io.c to see it used */
  1825. /* last_set_data_urb_value NEVER has the break bit set in it */
  1826. if (break_state)
  1827. urb_value = priv->last_set_data_urb_value | FTDI_SIO_SET_BREAK;
  1828. else
  1829. urb_value = priv->last_set_data_urb_value;
  1830. if (usb_control_msg(port->serial->dev,
  1831. usb_sndctrlpipe(port->serial->dev, 0),
  1832. FTDI_SIO_SET_DATA_REQUEST,
  1833. FTDI_SIO_SET_DATA_REQUEST_TYPE,
  1834. urb_value , priv->interface,
  1835. buf, 0, WDR_TIMEOUT) < 0) {
  1836. err("%s FAILED to enable/disable break state (state was %d)",
  1837. __func__, break_state);
  1838. }
  1839. dbg("%s break state is %d - urb is %d", __func__,
  1840. break_state, urb_value);
  1841. }
  1842. /* old_termios contains the original termios settings and tty->termios contains
  1843. * the new setting to be used
  1844. * WARNING: set_termios calls this with old_termios in kernel space
  1845. */
  1846. static void ftdi_set_termios(struct tty_struct *tty,
  1847. struct usb_serial_port *port, struct ktermios *old_termios)
  1848. { /* ftdi_termios */
  1849. struct usb_device *dev = port->serial->dev;
  1850. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1851. struct ktermios *termios = tty->termios;
  1852. unsigned int cflag = termios->c_cflag;
  1853. __u16 urb_value; /* will hold the new flags */
  1854. char buf[1]; /* Perhaps I should dynamically alloc this? */
  1855. /* Added for xon/xoff support */
  1856. unsigned int iflag = termios->c_iflag;
  1857. unsigned char vstop;
  1858. unsigned char vstart;
  1859. dbg("%s", __func__);
  1860. /* Force baud rate if this device requires it, unless it is set to
  1861. B0. */
  1862. if (priv->force_baud && ((termios->c_cflag & CBAUD) != B0)) {
  1863. dbg("%s: forcing baud rate for this device", __func__);
  1864. tty_encode_baud_rate(tty, priv->force_baud,
  1865. priv->force_baud);
  1866. }
  1867. /* Force RTS-CTS if this device requires it. */
  1868. if (priv->force_rtscts) {
  1869. dbg("%s: forcing rtscts for this device", __func__);
  1870. termios->c_cflag |= CRTSCTS;
  1871. }
  1872. cflag = termios->c_cflag;
  1873. /* FIXME -For this cut I don't care if the line is really changing or
  1874. not - so just do the change regardless - should be able to
  1875. compare old_termios and tty->termios */
  1876. /* NOTE These routines can get interrupted by
  1877. ftdi_sio_read_bulk_callback - need to examine what this means -
  1878. don't see any problems yet */
  1879. /* Set number of data bits, parity, stop bits */
  1880. termios->c_cflag &= ~CMSPAR;
  1881. urb_value = 0;
  1882. urb_value |= (cflag & CSTOPB ? FTDI_SIO_SET_DATA_STOP_BITS_2 :
  1883. FTDI_SIO_SET_DATA_STOP_BITS_1);
  1884. urb_value |= (cflag & PARENB ?
  1885. (cflag & PARODD ? FTDI_SIO_SET_DATA_PARITY_ODD :
  1886. FTDI_SIO_SET_DATA_PARITY_EVEN) :
  1887. FTDI_SIO_SET_DATA_PARITY_NONE);
  1888. if (cflag & CSIZE) {
  1889. switch (cflag & CSIZE) {
  1890. case CS5: urb_value |= 5; dbg("Setting CS5"); break;
  1891. case CS6: urb_value |= 6; dbg("Setting CS6"); break;
  1892. case CS7: urb_value |= 7; dbg("Setting CS7"); break;
  1893. case CS8: urb_value |= 8; dbg("Setting CS8"); break;
  1894. default:
  1895. err("CSIZE was set but not CS5-CS8");
  1896. }
  1897. }
  1898. /* This is needed by the break command since it uses the same command
  1899. - but is or'ed with this value */
  1900. priv->last_set_data_urb_value = urb_value;
  1901. if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  1902. FTDI_SIO_SET_DATA_REQUEST,
  1903. FTDI_SIO_SET_DATA_REQUEST_TYPE,
  1904. urb_value , priv->interface,
  1905. buf, 0, WDR_SHORT_TIMEOUT) < 0) {
  1906. err("%s FAILED to set databits/stopbits/parity", __func__);
  1907. }
  1908. /* Now do the baudrate */
  1909. if ((cflag & CBAUD) == B0) {
  1910. /* Disable flow control */
  1911. if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  1912. FTDI_SIO_SET_FLOW_CTRL_REQUEST,
  1913. FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
  1914. 0, priv->interface,
  1915. buf, 0, WDR_TIMEOUT) < 0) {
  1916. err("%s error from disable flowcontrol urb", __func__);
  1917. }
  1918. /* Drop RTS and DTR */
  1919. clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
  1920. } else {
  1921. /* set the baudrate determined before */
  1922. if (change_speed(tty, port))
  1923. err("%s urb failed to set baudrate", __func__);
  1924. /* Ensure RTS and DTR are raised when baudrate changed from 0 */
  1925. if (!old_termios || (old_termios->c_cflag & CBAUD) == B0)
  1926. set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
  1927. }
  1928. /* Set flow control */
  1929. /* Note device also supports DTR/CD (ugh) and Xon/Xoff in hardware */
  1930. if (cflag & CRTSCTS) {
  1931. dbg("%s Setting to CRTSCTS flow control", __func__);
  1932. if (usb_control_msg(dev,
  1933. usb_sndctrlpipe(dev, 0),
  1934. FTDI_SIO_SET_FLOW_CTRL_REQUEST,
  1935. FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
  1936. 0 , (FTDI_SIO_RTS_CTS_HS | priv->interface),
  1937. buf, 0, WDR_TIMEOUT) < 0) {
  1938. err("urb failed to set to rts/cts flow control");
  1939. }
  1940. } else {
  1941. /*
  1942. * Xon/Xoff code
  1943. *
  1944. * Check the IXOFF status in the iflag component of the
  1945. * termios structure. If IXOFF is not set, the pre-xon/xoff
  1946. * code is executed.
  1947. */
  1948. if (iflag & IXOFF) {
  1949. dbg("%s request to enable xonxoff iflag=%04x",
  1950. __func__, iflag);
  1951. /* Try to enable the XON/XOFF on the ftdi_sio
  1952. * Set the vstart and vstop -- could have been done up
  1953. * above where a lot of other dereferencing is done but
  1954. * that would be very inefficient as vstart and vstop
  1955. * are not always needed.
  1956. */
  1957. vstart = termios->c_cc[VSTART];
  1958. vstop = termios->c_cc[VSTOP];
  1959. urb_value = (vstop << 8) | (vstart);
  1960. if (usb_control_msg(dev,
  1961. usb_sndctrlpipe(dev, 0),
  1962. FTDI_SIO_SET_FLOW_CTRL_REQUEST,
  1963. FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
  1964. urb_value , (FTDI_SIO_XON_XOFF_HS
  1965. | priv->interface),
  1966. buf, 0, WDR_TIMEOUT) < 0) {
  1967. err("urb failed to set to xon/xoff flow control");
  1968. }
  1969. } else {
  1970. /* else clause to only run if cflag ! CRTSCTS and iflag
  1971. * ! XOFF. CHECKME Assuming XON/XOFF handled by tty
  1972. * stack - not by device */
  1973. dbg("%s Turning off hardware flow control", __func__);
  1974. if (usb_control_msg(dev,
  1975. usb_sndctrlpipe(dev, 0),
  1976. FTDI_SIO_SET_FLOW_CTRL_REQUEST,
  1977. FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
  1978. 0, priv->interface,
  1979. buf, 0, WDR_TIMEOUT) < 0) {
  1980. err("urb failed to clear flow control");
  1981. }
  1982. }
  1983. }
  1984. return;
  1985. }
  1986. static int ftdi_tiocmget(struct tty_struct *tty, struct file *file)
  1987. {
  1988. struct usb_serial_port *port = tty->driver_data;
  1989. struct ftdi_private *priv = usb_get_serial_port_data(port);
  1990. unsigned char buf[2];
  1991. int ret;
  1992. dbg("%s TIOCMGET", __func__);
  1993. switch (priv->chip_type) {
  1994. case SIO:
  1995. /* Request the status from the device */
  1996. ret = usb_control_msg(port->serial->dev,
  1997. usb_rcvctrlpipe(port->serial->dev, 0),
  1998. FTDI_SIO_GET_MODEM_STATUS_REQUEST,
  1999. FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
  2000. 0, 0,
  2001. buf, 1, WDR_TIMEOUT);
  2002. if (ret < 0) {
  2003. err("%s Could not get modem status of device - err: %d", __func__,
  2004. ret);
  2005. return ret;
  2006. }
  2007. break;
  2008. case FT8U232AM:
  2009. case FT232BM:
  2010. case FT2232C:
  2011. case FT232RL:
  2012. /* the 8U232AM returns a two byte value (the sio is a 1 byte
  2013. value) - in the same format as the data returned from the in
  2014. point */
  2015. ret = usb_control_msg(port->serial->dev,
  2016. usb_rcvctrlpipe(port->serial->dev, 0),
  2017. FTDI_SIO_GET_MODEM_STATUS_REQUEST,
  2018. FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
  2019. 0, priv->interface,
  2020. buf, 2, WDR_TIMEOUT);
  2021. if (ret < 0) {
  2022. err("%s Could not get modem status of device - err: %d", __func__,
  2023. ret);
  2024. return ret;
  2025. }
  2026. break;
  2027. default:
  2028. return -EFAULT;
  2029. break;
  2030. }
  2031. return (buf[0] & FTDI_SIO_DSR_MASK ? TIOCM_DSR : 0) |
  2032. (buf[0] & FTDI_SIO_CTS_MASK ? TIOCM_CTS : 0) |
  2033. (buf[0] & FTDI_SIO_RI_MASK ? TIOCM_RI : 0) |
  2034. (buf[0] & FTDI_SIO_RLSD_MASK ? TIOCM_CD : 0) |
  2035. priv->last_dtr_rts;
  2036. }
  2037. static int ftdi_tiocmset(struct tty_struct *tty, struct file *file,
  2038. unsigned int set, unsigned int clear)
  2039. {
  2040. struct usb_serial_port *port = tty->driver_data;
  2041. dbg("%s TIOCMSET", __func__);
  2042. return update_mctrl(port, set, clear);
  2043. }
  2044. static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
  2045. unsigned int cmd, unsigned long arg)
  2046. {
  2047. struct usb_serial_port *port = tty->driver_data;
  2048. struct ftdi_private *priv = usb_get_serial_port_data(port);
  2049. dbg("%s cmd 0x%04x", __func__, cmd);
  2050. /* Based on code from acm.c and others */
  2051. switch (cmd) {
  2052. case TIOCGSERIAL: /* gets serial port data */
  2053. return get_serial_info(port,
  2054. (struct serial_struct __user *) arg);
  2055. case TIOCSSERIAL: /* sets serial port data */
  2056. return set_serial_info(tty, port,
  2057. (struct serial_struct __user *) arg);
  2058. /*
  2059. * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
  2060. * - mask passed in arg for lines of interest
  2061. * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
  2062. * Caller should use TIOCGICOUNT to see which one it was.
  2063. *
  2064. * This code is borrowed from linux/drivers/char/serial.c
  2065. */
  2066. case TIOCMIWAIT:
  2067. while (priv != NULL) {
  2068. interruptible_sleep_on(&priv->delta_msr_wait);
  2069. /* see if a signal did it */
  2070. if (signal_pending(current))
  2071. return -ERESTARTSYS;
  2072. else {
  2073. char diff = priv->diff_status;
  2074. if (diff == 0)
  2075. return -EIO; /* no change => error */
  2076. /* Consume all events */
  2077. priv->diff_status = 0;
  2078. /* Return 0 if caller wanted to know about
  2079. these bits */
  2080. if (((arg & TIOCM_RNG) && (diff & FTDI_RS0_RI)) ||
  2081. ((arg & TIOCM_DSR) && (diff & FTDI_RS0_DSR)) ||
  2082. ((arg & TIOCM_CD) && (diff & FTDI_RS0_RLSD)) ||
  2083. ((arg & TIOCM_CTS) && (diff & FTDI_RS0_CTS))) {
  2084. return 0;
  2085. }
  2086. /*
  2087. * Otherwise caller can't care less about what
  2088. * happened,and so we continue to wait for more
  2089. * events.
  2090. */
  2091. }
  2092. }
  2093. return 0;
  2094. default:
  2095. break;
  2096. }
  2097. /* This is not necessarily an error - turns out the higher layers
  2098. * will do some ioctls themselves (see comment above)
  2099. */
  2100. dbg("%s arg not supported - it was 0x%04x - check /usr/include/asm/ioctls.h", __func__, cmd);
  2101. return -ENOIOCTLCMD;
  2102. }
  2103. static void ftdi_throttle(struct tty_struct *tty)
  2104. {
  2105. struct usb_serial_port *port = tty->driver_data;
  2106. struct ftdi_private *priv = usb_get_serial_port_data(port);
  2107. unsigned long flags;
  2108. dbg("%s - port %d", __func__, port->number);
  2109. spin_lock_irqsave(&priv->rx_lock, flags);
  2110. priv->rx_flags |= THROTTLED;
  2111. spin_unlock_irqrestore(&priv->rx_lock, flags);
  2112. }
  2113. static void ftdi_unthrottle(struct tty_struct *tty)
  2114. {
  2115. struct usb_serial_port *port = tty->driver_data;
  2116. struct ftdi_private *priv = usb_get_serial_port_data(port);
  2117. int actually_throttled;
  2118. unsigned long flags;
  2119. dbg("%s - port %d", __func__, port->number);
  2120. spin_lock_irqsave(&priv->rx_lock, flags);
  2121. actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
  2122. priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
  2123. spin_unlock_irqrestore(&priv->rx_lock, flags);
  2124. if (actually_throttled)
  2125. schedule_delayed_work(&priv->rx_work, 0);
  2126. }
  2127. static int __init ftdi_init(void)
  2128. {
  2129. int retval;
  2130. dbg("%s", __func__);
  2131. if (vendor > 0 && product > 0) {
  2132. /* Add user specified VID/PID to reserved element of table. */
  2133. int i;
  2134. for (i = 0; id_table_combined[i].idVendor; i++)
  2135. ;
  2136. id_table_combined[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
  2137. id_table_combined[i].idVendor = vendor;
  2138. id_table_combined[i].idProduct = product;
  2139. }
  2140. retval = usb_serial_register(&ftdi_sio_device);
  2141. if (retval)
  2142. goto failed_sio_register;
  2143. retval = usb_register(&ftdi_driver);
  2144. if (retval)
  2145. goto failed_usb_register;
  2146. info(DRIVER_VERSION ":" DRIVER_DESC);
  2147. return 0;
  2148. failed_usb_register:
  2149. usb_serial_deregister(&ftdi_sio_device);
  2150. failed_sio_register:
  2151. return retval;
  2152. }
  2153. static void __exit ftdi_exit(void)
  2154. {
  2155. dbg("%s", __func__);
  2156. usb_deregister(&ftdi_driver);
  2157. usb_serial_deregister(&ftdi_sio_device);
  2158. }
  2159. module_init(ftdi_init);
  2160. module_exit(ftdi_exit);
  2161. MODULE_AUTHOR(DRIVER_AUTHOR);
  2162. MODULE_DESCRIPTION(DRIVER_DESC);
  2163. MODULE_LICENSE("GPL");
  2164. module_param(debug, bool, S_IRUGO | S_IWUSR);
  2165. MODULE_PARM_DESC(debug, "Debug enabled or not");
  2166. module_param(vendor, ushort, 0);
  2167. MODULE_PARM_DESC(vendor, "User specified vendor ID (default="
  2168. __MODULE_STRING(FTDI_VID)")");
  2169. module_param(product, ushort, 0);
  2170. MODULE_PARM_DESC(vendor, "User specified product ID");