io_ti.c 80 KB

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