io_ti.c 80 KB

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