mos7840.c 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. *
  16. * Clean ups from Moschip version and a few ioctl implementations by:
  17. * Paul B Schroeder <pschroeder "at" uplogix "dot" com>
  18. *
  19. * Originally based on drivers/usb/serial/io_edgeport.c which is:
  20. * Copyright (C) 2000 Inside Out Networks, All rights reserved.
  21. * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
  22. *
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/errno.h>
  26. #include <linux/init.h>
  27. #include <linux/slab.h>
  28. #include <linux/tty.h>
  29. #include <linux/tty_driver.h>
  30. #include <linux/tty_flip.h>
  31. #include <linux/module.h>
  32. #include <linux/serial.h>
  33. #include <linux/usb.h>
  34. #include <linux/usb/serial.h>
  35. #include <linux/uaccess.h>
  36. /*
  37. * Version Information
  38. */
  39. #define DRIVER_VERSION "1.3.2"
  40. #define DRIVER_DESC "Moschip 7840/7820 USB Serial Driver"
  41. /*
  42. * 16C50 UART register defines
  43. */
  44. #define LCR_BITS_5 0x00 /* 5 bits/char */
  45. #define LCR_BITS_6 0x01 /* 6 bits/char */
  46. #define LCR_BITS_7 0x02 /* 7 bits/char */
  47. #define LCR_BITS_8 0x03 /* 8 bits/char */
  48. #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
  49. #define LCR_STOP_1 0x00 /* 1 stop bit */
  50. #define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */
  51. #define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */
  52. #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */
  53. #define LCR_PAR_NONE 0x00 /* No parity */
  54. #define LCR_PAR_ODD 0x08 /* Odd parity */
  55. #define LCR_PAR_EVEN 0x18 /* Even parity */
  56. #define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */
  57. #define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */
  58. #define LCR_PAR_MASK 0x38 /* Mask for parity field */
  59. #define LCR_SET_BREAK 0x40 /* Set Break condition */
  60. #define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */
  61. #define MCR_DTR 0x01 /* Assert DTR */
  62. #define MCR_RTS 0x02 /* Assert RTS */
  63. #define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */
  64. #define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */
  65. #define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */
  66. #define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */
  67. #define MOS7840_MSR_CTS 0x10 /* Current state of CTS */
  68. #define MOS7840_MSR_DSR 0x20 /* Current state of DSR */
  69. #define MOS7840_MSR_RI 0x40 /* Current state of RI */
  70. #define MOS7840_MSR_CD 0x80 /* Current state of CD */
  71. /*
  72. * Defines used for sending commands to port
  73. */
  74. #define WAIT_FOR_EVER (HZ * 0) /* timeout urb is wait for ever */
  75. #define MOS_WDR_TIMEOUT (HZ * 5) /* default urb timeout */
  76. #define MOS_PORT1 0x0200
  77. #define MOS_PORT2 0x0300
  78. #define MOS_VENREG 0x0000
  79. #define MOS_MAX_PORT 0x02
  80. #define MOS_WRITE 0x0E
  81. #define MOS_READ 0x0D
  82. /* Requests */
  83. #define MCS_RD_RTYPE 0xC0
  84. #define MCS_WR_RTYPE 0x40
  85. #define MCS_RDREQ 0x0D
  86. #define MCS_WRREQ 0x0E
  87. #define MCS_CTRL_TIMEOUT 500
  88. #define VENDOR_READ_LENGTH (0x01)
  89. #define MAX_NAME_LEN 64
  90. #define ZLP_REG1 0x3A /* Zero_Flag_Reg1 58 */
  91. #define ZLP_REG5 0x3E /* Zero_Flag_Reg5 62 */
  92. /* For higher baud Rates use TIOCEXBAUD */
  93. #define TIOCEXBAUD 0x5462
  94. /* vendor id and device id defines */
  95. /* The native mos7840/7820 component */
  96. #define USB_VENDOR_ID_MOSCHIP 0x9710
  97. #define MOSCHIP_DEVICE_ID_7840 0x7840
  98. #define MOSCHIP_DEVICE_ID_7820 0x7820
  99. #define MOSCHIP_DEVICE_ID_7810 0x7810
  100. /* The native component can have its vendor/device id's overridden
  101. * in vendor-specific implementations. Such devices can be handled
  102. * by making a change here, in moschip_port_id_table, and in
  103. * moschip_id_table_combined
  104. */
  105. #define USB_VENDOR_ID_BANDB 0x0856
  106. #define BANDB_DEVICE_ID_USO9ML2_2 0xAC22
  107. #define BANDB_DEVICE_ID_USO9ML2_2P 0xBC00
  108. #define BANDB_DEVICE_ID_USO9ML2_4 0xAC24
  109. #define BANDB_DEVICE_ID_USO9ML2_4P 0xBC01
  110. #define BANDB_DEVICE_ID_US9ML2_2 0xAC29
  111. #define BANDB_DEVICE_ID_US9ML2_4 0xAC30
  112. #define BANDB_DEVICE_ID_USPTL4_2 0xAC31
  113. #define BANDB_DEVICE_ID_USPTL4_4 0xAC32
  114. #define BANDB_DEVICE_ID_USOPTL4_2 0xAC42
  115. #define BANDB_DEVICE_ID_USOPTL4_2P 0xBC02
  116. #define BANDB_DEVICE_ID_USOPTL4_4 0xAC44
  117. #define BANDB_DEVICE_ID_USOPTL4_4P 0xBC03
  118. #define BANDB_DEVICE_ID_USOPTL2_4 0xAC24
  119. /* This driver also supports
  120. * ATEN UC2324 device using Moschip MCS7840
  121. * ATEN UC2322 device using Moschip MCS7820
  122. */
  123. #define USB_VENDOR_ID_ATENINTL 0x0557
  124. #define ATENINTL_DEVICE_ID_UC2324 0x2011
  125. #define ATENINTL_DEVICE_ID_UC2322 0x7820
  126. /* Interrupt Routine Defines */
  127. #define SERIAL_IIR_RLS 0x06
  128. #define SERIAL_IIR_MS 0x00
  129. /*
  130. * Emulation of the bit mask on the LINE STATUS REGISTER.
  131. */
  132. #define SERIAL_LSR_DR 0x0001
  133. #define SERIAL_LSR_OE 0x0002
  134. #define SERIAL_LSR_PE 0x0004
  135. #define SERIAL_LSR_FE 0x0008
  136. #define SERIAL_LSR_BI 0x0010
  137. #define MOS_MSR_DELTA_CTS 0x10
  138. #define MOS_MSR_DELTA_DSR 0x20
  139. #define MOS_MSR_DELTA_RI 0x40
  140. #define MOS_MSR_DELTA_CD 0x80
  141. /* Serial Port register Address */
  142. #define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01))
  143. #define FIFO_CONTROL_REGISTER ((__u16)(0x02))
  144. #define LINE_CONTROL_REGISTER ((__u16)(0x03))
  145. #define MODEM_CONTROL_REGISTER ((__u16)(0x04))
  146. #define LINE_STATUS_REGISTER ((__u16)(0x05))
  147. #define MODEM_STATUS_REGISTER ((__u16)(0x06))
  148. #define SCRATCH_PAD_REGISTER ((__u16)(0x07))
  149. #define DIVISOR_LATCH_LSB ((__u16)(0x00))
  150. #define DIVISOR_LATCH_MSB ((__u16)(0x01))
  151. #define CLK_MULTI_REGISTER ((__u16)(0x02))
  152. #define CLK_START_VALUE_REGISTER ((__u16)(0x03))
  153. #define GPIO_REGISTER ((__u16)(0x07))
  154. #define SERIAL_LCR_DLAB ((__u16)(0x0080))
  155. /*
  156. * URB POOL related defines
  157. */
  158. #define NUM_URBS 16 /* URB Count */
  159. #define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
  160. /* LED on/off milliseconds*/
  161. #define LED_ON_MS 500
  162. #define LED_OFF_MS 500
  163. static int device_type;
  164. static const struct usb_device_id moschip_port_id_table[] = {
  165. {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)},
  166. {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)},
  167. {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7810)},
  168. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)},
  169. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P)},
  170. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)},
  171. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P)},
  172. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)},
  173. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)},
  174. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)},
  175. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)},
  176. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)},
  177. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P)},
  178. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)},
  179. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P)},
  180. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)},
  181. {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)},
  182. {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)},
  183. {} /* terminating entry */
  184. };
  185. static const struct usb_device_id moschip_id_table_combined[] __devinitconst = {
  186. {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)},
  187. {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)},
  188. {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7810)},
  189. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)},
  190. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P)},
  191. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)},
  192. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P)},
  193. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)},
  194. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)},
  195. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)},
  196. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)},
  197. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)},
  198. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P)},
  199. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)},
  200. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P)},
  201. {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)},
  202. {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)},
  203. {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)},
  204. {} /* terminating entry */
  205. };
  206. MODULE_DEVICE_TABLE(usb, moschip_id_table_combined);
  207. /* This structure holds all of the local port information */
  208. struct moschip_port {
  209. int port_num; /*Actual port number in the device(1,2,etc) */
  210. struct urb *write_urb; /* write URB for this port */
  211. struct urb *read_urb; /* read URB for this port */
  212. struct urb *int_urb;
  213. __u8 shadowLCR; /* last LCR value received */
  214. __u8 shadowMCR; /* last MCR value received */
  215. char open;
  216. char open_ports;
  217. char zombie;
  218. wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
  219. wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */
  220. int delta_msr_cond;
  221. struct async_icount icount;
  222. struct usb_serial_port *port; /* loop back to the owner of this object */
  223. /* Offsets */
  224. __u8 SpRegOffset;
  225. __u8 ControlRegOffset;
  226. __u8 DcrRegOffset;
  227. /* for processing control URBS in interrupt context */
  228. struct urb *control_urb;
  229. struct usb_ctrlrequest *dr;
  230. char *ctrl_buf;
  231. int MsrLsr;
  232. spinlock_t pool_lock;
  233. struct urb *write_urb_pool[NUM_URBS];
  234. char busy[NUM_URBS];
  235. bool read_urb_busy;
  236. /* For device(s) with LED indicator */
  237. bool has_led;
  238. bool led_flag;
  239. struct timer_list led_timer1; /* Timer for LED on */
  240. struct timer_list led_timer2; /* Timer for LED off */
  241. };
  242. static bool debug;
  243. /*
  244. * mos7840_set_reg_sync
  245. * To set the Control register by calling usb_fill_control_urb function
  246. * by passing usb_sndctrlpipe function as parameter.
  247. */
  248. static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg,
  249. __u16 val)
  250. {
  251. struct usb_device *dev = port->serial->dev;
  252. val = val & 0x00ff;
  253. dbg("mos7840_set_reg_sync offset is %x, value %x", reg, val);
  254. return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
  255. MCS_WR_RTYPE, val, reg, NULL, 0,
  256. MOS_WDR_TIMEOUT);
  257. }
  258. /*
  259. * mos7840_get_reg_sync
  260. * To set the Uart register by calling usb_fill_control_urb function by
  261. * passing usb_rcvctrlpipe function as parameter.
  262. */
  263. static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg,
  264. __u16 *val)
  265. {
  266. struct usb_device *dev = port->serial->dev;
  267. int ret = 0;
  268. u8 *buf;
  269. buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
  270. if (!buf)
  271. return -ENOMEM;
  272. ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
  273. MCS_RD_RTYPE, 0, reg, buf, VENDOR_READ_LENGTH,
  274. MOS_WDR_TIMEOUT);
  275. *val = buf[0];
  276. dbg("mos7840_get_reg_sync offset is %x, return val %x", reg, *val);
  277. kfree(buf);
  278. return ret;
  279. }
  280. /*
  281. * mos7840_set_uart_reg
  282. * To set the Uart register by calling usb_fill_control_urb function by
  283. * passing usb_sndctrlpipe function as parameter.
  284. */
  285. static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg,
  286. __u16 val)
  287. {
  288. struct usb_device *dev = port->serial->dev;
  289. val = val & 0x00ff;
  290. /* For the UART control registers, the application number need
  291. to be Or'ed */
  292. if (port->serial->num_ports == 4) {
  293. val |= (((__u16) port->number -
  294. (__u16) (port->serial->minor)) + 1) << 8;
  295. dbg("mos7840_set_uart_reg application number is %x", val);
  296. } else {
  297. if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
  298. val |= (((__u16) port->number -
  299. (__u16) (port->serial->minor)) + 1) << 8;
  300. dbg("mos7840_set_uart_reg application number is %x",
  301. val);
  302. } else {
  303. val |=
  304. (((__u16) port->number -
  305. (__u16) (port->serial->minor)) + 2) << 8;
  306. dbg("mos7840_set_uart_reg application number is %x",
  307. val);
  308. }
  309. }
  310. return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
  311. MCS_WR_RTYPE, val, reg, NULL, 0,
  312. MOS_WDR_TIMEOUT);
  313. }
  314. /*
  315. * mos7840_get_uart_reg
  316. * To set the Control register by calling usb_fill_control_urb function
  317. * by passing usb_rcvctrlpipe function as parameter.
  318. */
  319. static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
  320. __u16 *val)
  321. {
  322. struct usb_device *dev = port->serial->dev;
  323. int ret = 0;
  324. __u16 Wval;
  325. u8 *buf;
  326. buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
  327. if (!buf)
  328. return -ENOMEM;
  329. /* dbg("application number is %4x",
  330. (((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); */
  331. /* Wval is same as application number */
  332. if (port->serial->num_ports == 4) {
  333. Wval =
  334. (((__u16) port->number - (__u16) (port->serial->minor)) +
  335. 1) << 8;
  336. dbg("mos7840_get_uart_reg application number is %x", Wval);
  337. } else {
  338. if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
  339. Wval = (((__u16) port->number -
  340. (__u16) (port->serial->minor)) + 1) << 8;
  341. dbg("mos7840_get_uart_reg application number is %x",
  342. Wval);
  343. } else {
  344. Wval = (((__u16) port->number -
  345. (__u16) (port->serial->minor)) + 2) << 8;
  346. dbg("mos7840_get_uart_reg application number is %x",
  347. Wval);
  348. }
  349. }
  350. ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
  351. MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH,
  352. MOS_WDR_TIMEOUT);
  353. *val = buf[0];
  354. kfree(buf);
  355. return ret;
  356. }
  357. static void mos7840_dump_serial_port(struct moschip_port *mos7840_port)
  358. {
  359. dbg("***************************************");
  360. dbg("SpRegOffset is %2x", mos7840_port->SpRegOffset);
  361. dbg("ControlRegOffset is %2x", mos7840_port->ControlRegOffset);
  362. dbg("DCRRegOffset is %2x", mos7840_port->DcrRegOffset);
  363. dbg("***************************************");
  364. }
  365. /************************************************************************/
  366. /************************************************************************/
  367. /* I N T E R F A C E F U N C T I O N S */
  368. /* I N T E R F A C E F U N C T I O N S */
  369. /************************************************************************/
  370. /************************************************************************/
  371. static inline void mos7840_set_port_private(struct usb_serial_port *port,
  372. struct moschip_port *data)
  373. {
  374. usb_set_serial_port_data(port, (void *)data);
  375. }
  376. static inline struct moschip_port *mos7840_get_port_private(struct
  377. usb_serial_port
  378. *port)
  379. {
  380. return (struct moschip_port *)usb_get_serial_port_data(port);
  381. }
  382. static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr)
  383. {
  384. struct moschip_port *mos7840_port;
  385. struct async_icount *icount;
  386. mos7840_port = port;
  387. icount = &mos7840_port->icount;
  388. if (new_msr &
  389. (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI |
  390. MOS_MSR_DELTA_CD)) {
  391. icount = &mos7840_port->icount;
  392. /* update input line counters */
  393. if (new_msr & MOS_MSR_DELTA_CTS) {
  394. icount->cts++;
  395. smp_wmb();
  396. }
  397. if (new_msr & MOS_MSR_DELTA_DSR) {
  398. icount->dsr++;
  399. smp_wmb();
  400. }
  401. if (new_msr & MOS_MSR_DELTA_CD) {
  402. icount->dcd++;
  403. smp_wmb();
  404. }
  405. if (new_msr & MOS_MSR_DELTA_RI) {
  406. icount->rng++;
  407. smp_wmb();
  408. }
  409. }
  410. }
  411. static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
  412. {
  413. struct async_icount *icount;
  414. dbg("%s - %02x", __func__, new_lsr);
  415. if (new_lsr & SERIAL_LSR_BI) {
  416. /*
  417. * Parity and Framing errors only count if they
  418. * occur exclusive of a break being
  419. * received.
  420. */
  421. new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
  422. }
  423. /* update input line counters */
  424. icount = &port->icount;
  425. if (new_lsr & SERIAL_LSR_BI) {
  426. icount->brk++;
  427. smp_wmb();
  428. }
  429. if (new_lsr & SERIAL_LSR_OE) {
  430. icount->overrun++;
  431. smp_wmb();
  432. }
  433. if (new_lsr & SERIAL_LSR_PE) {
  434. icount->parity++;
  435. smp_wmb();
  436. }
  437. if (new_lsr & SERIAL_LSR_FE) {
  438. icount->frame++;
  439. smp_wmb();
  440. }
  441. }
  442. /************************************************************************/
  443. /************************************************************************/
  444. /* U S B C A L L B A C K F U N C T I O N S */
  445. /* U S B C A L L B A C K F U N C T I O N S */
  446. /************************************************************************/
  447. /************************************************************************/
  448. static void mos7840_control_callback(struct urb *urb)
  449. {
  450. unsigned char *data;
  451. struct moschip_port *mos7840_port;
  452. __u8 regval = 0x0;
  453. int result = 0;
  454. int status = urb->status;
  455. mos7840_port = urb->context;
  456. switch (status) {
  457. case 0:
  458. /* success */
  459. break;
  460. case -ECONNRESET:
  461. case -ENOENT:
  462. case -ESHUTDOWN:
  463. /* this urb is terminated, clean up */
  464. dbg("%s - urb shutting down with status: %d", __func__,
  465. status);
  466. return;
  467. default:
  468. dbg("%s - nonzero urb status received: %d", __func__,
  469. status);
  470. goto exit;
  471. }
  472. dbg("%s urb buffer size is %d", __func__, urb->actual_length);
  473. dbg("%s mos7840_port->MsrLsr is %d port %d", __func__,
  474. mos7840_port->MsrLsr, mos7840_port->port_num);
  475. data = urb->transfer_buffer;
  476. regval = (__u8) data[0];
  477. dbg("%s data is %x", __func__, regval);
  478. if (mos7840_port->MsrLsr == 0)
  479. mos7840_handle_new_msr(mos7840_port, regval);
  480. else if (mos7840_port->MsrLsr == 1)
  481. mos7840_handle_new_lsr(mos7840_port, regval);
  482. exit:
  483. spin_lock(&mos7840_port->pool_lock);
  484. if (!mos7840_port->zombie)
  485. result = usb_submit_urb(mos7840_port->int_urb, GFP_ATOMIC);
  486. spin_unlock(&mos7840_port->pool_lock);
  487. if (result) {
  488. dev_err(&urb->dev->dev,
  489. "%s - Error %d submitting interrupt urb\n",
  490. __func__, result);
  491. }
  492. }
  493. static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
  494. __u16 *val)
  495. {
  496. struct usb_device *dev = mcs->port->serial->dev;
  497. struct usb_ctrlrequest *dr = mcs->dr;
  498. unsigned char *buffer = mcs->ctrl_buf;
  499. int ret;
  500. dr->bRequestType = MCS_RD_RTYPE;
  501. dr->bRequest = MCS_RDREQ;
  502. dr->wValue = cpu_to_le16(Wval); /* 0 */
  503. dr->wIndex = cpu_to_le16(reg);
  504. dr->wLength = cpu_to_le16(2);
  505. usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0),
  506. (unsigned char *)dr, buffer, 2,
  507. mos7840_control_callback, mcs);
  508. mcs->control_urb->transfer_buffer_length = 2;
  509. ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC);
  510. return ret;
  511. }
  512. static void mos7840_set_led_callback(struct urb *urb)
  513. {
  514. switch (urb->status) {
  515. case 0:
  516. /* Success */
  517. break;
  518. case -ECONNRESET:
  519. case -ENOENT:
  520. case -ESHUTDOWN:
  521. /* This urb is terminated, clean up */
  522. dbg("%s - urb shutting down with status: %d", __func__,
  523. urb->status);
  524. break;
  525. default:
  526. dbg("%s - nonzero urb status received: %d", __func__,
  527. urb->status);
  528. }
  529. }
  530. static void mos7840_set_led_async(struct moschip_port *mcs, __u16 wval,
  531. __u16 reg)
  532. {
  533. struct usb_device *dev = mcs->port->serial->dev;
  534. struct usb_ctrlrequest *dr = mcs->dr;
  535. dr->bRequestType = MCS_WR_RTYPE;
  536. dr->bRequest = MCS_WRREQ;
  537. dr->wValue = cpu_to_le16(wval);
  538. dr->wIndex = cpu_to_le16(reg);
  539. dr->wLength = cpu_to_le16(0);
  540. usb_fill_control_urb(mcs->control_urb, dev, usb_sndctrlpipe(dev, 0),
  541. (unsigned char *)dr, NULL, 0, mos7840_set_led_callback, NULL);
  542. usb_submit_urb(mcs->control_urb, GFP_ATOMIC);
  543. }
  544. static void mos7840_set_led_sync(struct usb_serial_port *port, __u16 reg,
  545. __u16 val)
  546. {
  547. struct usb_device *dev = port->serial->dev;
  548. usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, MCS_WR_RTYPE,
  549. val, reg, NULL, 0, MOS_WDR_TIMEOUT);
  550. }
  551. static void mos7840_led_off(unsigned long arg)
  552. {
  553. struct moschip_port *mcs = (struct moschip_port *) arg;
  554. /* Turn off LED */
  555. mos7840_set_led_async(mcs, 0x0300, MODEM_CONTROL_REGISTER);
  556. mod_timer(&mcs->led_timer2,
  557. jiffies + msecs_to_jiffies(LED_OFF_MS));
  558. }
  559. static void mos7840_led_flag_off(unsigned long arg)
  560. {
  561. struct moschip_port *mcs = (struct moschip_port *) arg;
  562. mcs->led_flag = false;
  563. }
  564. /*****************************************************************************
  565. * mos7840_interrupt_callback
  566. * this is the callback function for when we have received data on the
  567. * interrupt endpoint.
  568. *****************************************************************************/
  569. static void mos7840_interrupt_callback(struct urb *urb)
  570. {
  571. int result;
  572. int length;
  573. struct moschip_port *mos7840_port;
  574. struct usb_serial *serial;
  575. __u16 Data;
  576. unsigned char *data;
  577. __u8 sp[5], st;
  578. int i, rv = 0;
  579. __u16 wval, wreg = 0;
  580. int status = urb->status;
  581. dbg("%s", " : Entering");
  582. switch (status) {
  583. case 0:
  584. /* success */
  585. break;
  586. case -ECONNRESET:
  587. case -ENOENT:
  588. case -ESHUTDOWN:
  589. /* this urb is terminated, clean up */
  590. dbg("%s - urb shutting down with status: %d", __func__,
  591. status);
  592. return;
  593. default:
  594. dbg("%s - nonzero urb status received: %d", __func__,
  595. status);
  596. goto exit;
  597. }
  598. length = urb->actual_length;
  599. data = urb->transfer_buffer;
  600. serial = urb->context;
  601. /* Moschip get 5 bytes
  602. * Byte 1 IIR Port 1 (port.number is 0)
  603. * Byte 2 IIR Port 2 (port.number is 1)
  604. * Byte 3 IIR Port 3 (port.number is 2)
  605. * Byte 4 IIR Port 4 (port.number is 3)
  606. * Byte 5 FIFO status for both */
  607. if (length && length > 5) {
  608. dbg("%s", "Wrong data !!!");
  609. return;
  610. }
  611. sp[0] = (__u8) data[0];
  612. sp[1] = (__u8) data[1];
  613. sp[2] = (__u8) data[2];
  614. sp[3] = (__u8) data[3];
  615. st = (__u8) data[4];
  616. for (i = 0; i < serial->num_ports; i++) {
  617. mos7840_port = mos7840_get_port_private(serial->port[i]);
  618. wval =
  619. (((__u16) serial->port[i]->number -
  620. (__u16) (serial->minor)) + 1) << 8;
  621. if (mos7840_port->open) {
  622. if (sp[i] & 0x01) {
  623. dbg("SP%d No Interrupt !!!", i);
  624. } else {
  625. switch (sp[i] & 0x0f) {
  626. case SERIAL_IIR_RLS:
  627. dbg("Serial Port %d: Receiver status error or ", i);
  628. dbg("address bit detected in 9-bit mode");
  629. mos7840_port->MsrLsr = 1;
  630. wreg = LINE_STATUS_REGISTER;
  631. break;
  632. case SERIAL_IIR_MS:
  633. dbg("Serial Port %d: Modem status change", i);
  634. mos7840_port->MsrLsr = 0;
  635. wreg = MODEM_STATUS_REGISTER;
  636. break;
  637. }
  638. spin_lock(&mos7840_port->pool_lock);
  639. if (!mos7840_port->zombie) {
  640. rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data);
  641. } else {
  642. spin_unlock(&mos7840_port->pool_lock);
  643. return;
  644. }
  645. spin_unlock(&mos7840_port->pool_lock);
  646. }
  647. }
  648. }
  649. if (!(rv < 0))
  650. /* the completion handler for the control urb will resubmit */
  651. return;
  652. exit:
  653. result = usb_submit_urb(urb, GFP_ATOMIC);
  654. if (result) {
  655. dev_err(&urb->dev->dev,
  656. "%s - Error %d submitting interrupt urb\n",
  657. __func__, result);
  658. }
  659. }
  660. static int mos7840_port_paranoia_check(struct usb_serial_port *port,
  661. const char *function)
  662. {
  663. if (!port) {
  664. dbg("%s - port == NULL", function);
  665. return -1;
  666. }
  667. if (!port->serial) {
  668. dbg("%s - port->serial == NULL", function);
  669. return -1;
  670. }
  671. return 0;
  672. }
  673. /* Inline functions to check the sanity of a pointer that is passed to us */
  674. static int mos7840_serial_paranoia_check(struct usb_serial *serial,
  675. const char *function)
  676. {
  677. if (!serial) {
  678. dbg("%s - serial == NULL", function);
  679. return -1;
  680. }
  681. if (!serial->type) {
  682. dbg("%s - serial->type == NULL!", function);
  683. return -1;
  684. }
  685. return 0;
  686. }
  687. static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port,
  688. const char *function)
  689. {
  690. /* if no port was specified, or it fails a paranoia check */
  691. if (!port ||
  692. mos7840_port_paranoia_check(port, function) ||
  693. mos7840_serial_paranoia_check(port->serial, function)) {
  694. /* then say that we don't have a valid usb_serial thing,
  695. * which will end up genrating -ENODEV return values */
  696. return NULL;
  697. }
  698. return port->serial;
  699. }
  700. /*****************************************************************************
  701. * mos7840_bulk_in_callback
  702. * this is the callback function for when we have received data on the
  703. * bulk in endpoint.
  704. *****************************************************************************/
  705. static void mos7840_bulk_in_callback(struct urb *urb)
  706. {
  707. int retval;
  708. unsigned char *data;
  709. struct usb_serial *serial;
  710. struct usb_serial_port *port;
  711. struct moschip_port *mos7840_port;
  712. struct tty_struct *tty;
  713. int status = urb->status;
  714. mos7840_port = urb->context;
  715. if (!mos7840_port) {
  716. dbg("%s", "NULL mos7840_port pointer");
  717. return;
  718. }
  719. if (status) {
  720. dbg("nonzero read bulk status received: %d", status);
  721. mos7840_port->read_urb_busy = false;
  722. return;
  723. }
  724. port = (struct usb_serial_port *)mos7840_port->port;
  725. if (mos7840_port_paranoia_check(port, __func__)) {
  726. dbg("%s", "Port Paranoia failed");
  727. mos7840_port->read_urb_busy = false;
  728. return;
  729. }
  730. serial = mos7840_get_usb_serial(port, __func__);
  731. if (!serial) {
  732. dbg("%s", "Bad serial pointer");
  733. mos7840_port->read_urb_busy = false;
  734. return;
  735. }
  736. dbg("%s", "Entering... ");
  737. data = urb->transfer_buffer;
  738. dbg("%s", "Entering ...........");
  739. if (urb->actual_length) {
  740. tty = tty_port_tty_get(&mos7840_port->port->port);
  741. if (tty) {
  742. tty_insert_flip_string(tty, data, urb->actual_length);
  743. dbg(" %s ", data);
  744. tty_flip_buffer_push(tty);
  745. tty_kref_put(tty);
  746. }
  747. mos7840_port->icount.rx += urb->actual_length;
  748. smp_wmb();
  749. dbg("mos7840_port->icount.rx is %d:",
  750. mos7840_port->icount.rx);
  751. }
  752. if (!mos7840_port->read_urb) {
  753. dbg("%s", "URB KILLED !!!");
  754. mos7840_port->read_urb_busy = false;
  755. return;
  756. }
  757. /* Turn on LED */
  758. if (mos7840_port->has_led && !mos7840_port->led_flag) {
  759. mos7840_port->led_flag = true;
  760. mos7840_set_led_async(mos7840_port, 0x0301,
  761. MODEM_CONTROL_REGISTER);
  762. mod_timer(&mos7840_port->led_timer1,
  763. jiffies + msecs_to_jiffies(LED_ON_MS));
  764. }
  765. mos7840_port->read_urb_busy = true;
  766. retval = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
  767. if (retval) {
  768. dbg("usb_submit_urb(read bulk) failed, retval = %d", retval);
  769. mos7840_port->read_urb_busy = false;
  770. }
  771. }
  772. /*****************************************************************************
  773. * mos7840_bulk_out_data_callback
  774. * this is the callback function for when we have finished sending
  775. * serial data on the bulk out endpoint.
  776. *****************************************************************************/
  777. static void mos7840_bulk_out_data_callback(struct urb *urb)
  778. {
  779. struct moschip_port *mos7840_port;
  780. struct tty_struct *tty;
  781. int status = urb->status;
  782. int i;
  783. mos7840_port = urb->context;
  784. spin_lock(&mos7840_port->pool_lock);
  785. for (i = 0; i < NUM_URBS; i++) {
  786. if (urb == mos7840_port->write_urb_pool[i]) {
  787. mos7840_port->busy[i] = 0;
  788. break;
  789. }
  790. }
  791. spin_unlock(&mos7840_port->pool_lock);
  792. if (status) {
  793. dbg("nonzero write bulk status received:%d", status);
  794. return;
  795. }
  796. if (mos7840_port_paranoia_check(mos7840_port->port, __func__)) {
  797. dbg("%s", "Port Paranoia failed");
  798. return;
  799. }
  800. dbg("%s", "Entering .........");
  801. tty = tty_port_tty_get(&mos7840_port->port->port);
  802. if (tty && mos7840_port->open)
  803. tty_wakeup(tty);
  804. tty_kref_put(tty);
  805. }
  806. /************************************************************************/
  807. /* D R I V E R T T Y I N T E R F A C E F U N C T I O N S */
  808. /************************************************************************/
  809. #ifdef MCSSerialProbe
  810. static int mos7840_serial_probe(struct usb_serial *serial,
  811. const struct usb_device_id *id)
  812. {
  813. /*need to implement the mode_reg reading and updating\
  814. structures usb_serial_ device_type\
  815. (i.e num_ports, num_bulkin,bulkout etc) */
  816. /* Also we can update the changes attach */
  817. return 1;
  818. }
  819. #endif
  820. /*****************************************************************************
  821. * mos7840_open
  822. * this function is called by the tty driver when a port is opened
  823. * If successful, we return 0
  824. * Otherwise we return a negative error number.
  825. *****************************************************************************/
  826. static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
  827. {
  828. int response;
  829. int j;
  830. struct usb_serial *serial;
  831. struct urb *urb;
  832. __u16 Data;
  833. int status;
  834. struct moschip_port *mos7840_port;
  835. struct moschip_port *port0;
  836. dbg ("%s enter", __func__);
  837. if (mos7840_port_paranoia_check(port, __func__)) {
  838. dbg("%s", "Port Paranoia failed");
  839. return -ENODEV;
  840. }
  841. serial = port->serial;
  842. if (mos7840_serial_paranoia_check(serial, __func__)) {
  843. dbg("%s", "Serial Paranoia failed");
  844. return -ENODEV;
  845. }
  846. mos7840_port = mos7840_get_port_private(port);
  847. port0 = mos7840_get_port_private(serial->port[0]);
  848. if (mos7840_port == NULL || port0 == NULL)
  849. return -ENODEV;
  850. usb_clear_halt(serial->dev, port->write_urb->pipe);
  851. usb_clear_halt(serial->dev, port->read_urb->pipe);
  852. port0->open_ports++;
  853. /* Initialising the write urb pool */
  854. for (j = 0; j < NUM_URBS; ++j) {
  855. urb = usb_alloc_urb(0, GFP_KERNEL);
  856. mos7840_port->write_urb_pool[j] = urb;
  857. if (urb == NULL) {
  858. dev_err(&port->dev, "No more urbs???\n");
  859. continue;
  860. }
  861. urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
  862. GFP_KERNEL);
  863. if (!urb->transfer_buffer) {
  864. usb_free_urb(urb);
  865. mos7840_port->write_urb_pool[j] = NULL;
  866. dev_err(&port->dev,
  867. "%s-out of memory for urb buffers.\n",
  868. __func__);
  869. continue;
  870. }
  871. }
  872. /*****************************************************************************
  873. * Initialize MCS7840 -- Write Init values to corresponding Registers
  874. *
  875. * Register Index
  876. * 1 : IER
  877. * 2 : FCR
  878. * 3 : LCR
  879. * 4 : MCR
  880. *
  881. * 0x08 : SP1/2 Control Reg
  882. *****************************************************************************/
  883. /* NEED to check the following Block */
  884. Data = 0x0;
  885. status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
  886. if (status < 0) {
  887. dbg("Reading Spreg failed");
  888. return -1;
  889. }
  890. Data |= 0x80;
  891. status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
  892. if (status < 0) {
  893. dbg("writing Spreg failed");
  894. return -1;
  895. }
  896. Data &= ~0x80;
  897. status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
  898. if (status < 0) {
  899. dbg("writing Spreg failed");
  900. return -1;
  901. }
  902. /* End of block to be checked */
  903. Data = 0x0;
  904. status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
  905. &Data);
  906. if (status < 0) {
  907. dbg("Reading Controlreg failed");
  908. return -1;
  909. }
  910. Data |= 0x08; /* Driver done bit */
  911. Data |= 0x20; /* rx_disable */
  912. status = mos7840_set_reg_sync(port,
  913. mos7840_port->ControlRegOffset, Data);
  914. if (status < 0) {
  915. dbg("writing Controlreg failed");
  916. return -1;
  917. }
  918. /* do register settings here */
  919. /* Set all regs to the device default values. */
  920. /***********************************
  921. * First Disable all interrupts.
  922. ***********************************/
  923. Data = 0x00;
  924. status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
  925. if (status < 0) {
  926. dbg("disabling interrupts failed");
  927. return -1;
  928. }
  929. /* Set FIFO_CONTROL_REGISTER to the default value */
  930. Data = 0x00;
  931. status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
  932. if (status < 0) {
  933. dbg("Writing FIFO_CONTROL_REGISTER failed");
  934. return -1;
  935. }
  936. Data = 0xcf;
  937. status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
  938. if (status < 0) {
  939. dbg("Writing FIFO_CONTROL_REGISTER failed");
  940. return -1;
  941. }
  942. Data = 0x03;
  943. status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
  944. mos7840_port->shadowLCR = Data;
  945. Data = 0x0b;
  946. status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
  947. mos7840_port->shadowMCR = Data;
  948. Data = 0x00;
  949. status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
  950. mos7840_port->shadowLCR = Data;
  951. Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
  952. status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
  953. Data = 0x0c;
  954. status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
  955. Data = 0x0;
  956. status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
  957. Data = 0x00;
  958. status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
  959. Data = Data & ~SERIAL_LCR_DLAB;
  960. status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
  961. mos7840_port->shadowLCR = Data;
  962. /* clearing Bulkin and Bulkout Fifo */
  963. Data = 0x0;
  964. status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
  965. Data = Data | 0x0c;
  966. status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
  967. Data = Data & ~0x0c;
  968. status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
  969. /* Finally enable all interrupts */
  970. Data = 0x0c;
  971. status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
  972. /* clearing rx_disable */
  973. Data = 0x0;
  974. status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
  975. &Data);
  976. Data = Data & ~0x20;
  977. status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
  978. Data);
  979. /* rx_negate */
  980. Data = 0x0;
  981. status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
  982. &Data);
  983. Data = Data | 0x10;
  984. status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
  985. Data);
  986. /* Check to see if we've set up our endpoint info yet *
  987. * (can't set it up in mos7840_startup as the structures *
  988. * were not set up at that time.) */
  989. if (port0->open_ports == 1) {
  990. if (serial->port[0]->interrupt_in_buffer == NULL) {
  991. /* set up interrupt urb */
  992. usb_fill_int_urb(serial->port[0]->interrupt_in_urb,
  993. serial->dev,
  994. usb_rcvintpipe(serial->dev,
  995. serial->port[0]->interrupt_in_endpointAddress),
  996. serial->port[0]->interrupt_in_buffer,
  997. serial->port[0]->interrupt_in_urb->
  998. transfer_buffer_length,
  999. mos7840_interrupt_callback,
  1000. serial,
  1001. serial->port[0]->interrupt_in_urb->interval);
  1002. /* start interrupt read for mos7840 *
  1003. * will continue as long as mos7840 is connected */
  1004. response =
  1005. usb_submit_urb(serial->port[0]->interrupt_in_urb,
  1006. GFP_KERNEL);
  1007. if (response) {
  1008. dev_err(&port->dev, "%s - Error %d submitting "
  1009. "interrupt urb\n", __func__, response);
  1010. }
  1011. }
  1012. }
  1013. /* see if we've set up our endpoint info yet *
  1014. * (can't set it up in mos7840_startup as the *
  1015. * structures were not set up at that time.) */
  1016. dbg("port number is %d", port->number);
  1017. dbg("serial number is %d", port->serial->minor);
  1018. dbg("Bulkin endpoint is %d", port->bulk_in_endpointAddress);
  1019. dbg("BulkOut endpoint is %d", port->bulk_out_endpointAddress);
  1020. dbg("Interrupt endpoint is %d", port->interrupt_in_endpointAddress);
  1021. dbg("port's number in the device is %d", mos7840_port->port_num);
  1022. mos7840_port->read_urb = port->read_urb;
  1023. /* set up our bulk in urb */
  1024. if ((serial->num_ports == 2)
  1025. && ((((__u16)port->number -
  1026. (__u16)(port->serial->minor)) % 2) != 0)) {
  1027. usb_fill_bulk_urb(mos7840_port->read_urb,
  1028. serial->dev,
  1029. usb_rcvbulkpipe(serial->dev,
  1030. (port->bulk_in_endpointAddress) + 2),
  1031. port->bulk_in_buffer,
  1032. mos7840_port->read_urb->transfer_buffer_length,
  1033. mos7840_bulk_in_callback, mos7840_port);
  1034. } else {
  1035. usb_fill_bulk_urb(mos7840_port->read_urb,
  1036. serial->dev,
  1037. usb_rcvbulkpipe(serial->dev,
  1038. port->bulk_in_endpointAddress),
  1039. port->bulk_in_buffer,
  1040. mos7840_port->read_urb->transfer_buffer_length,
  1041. mos7840_bulk_in_callback, mos7840_port);
  1042. }
  1043. dbg("mos7840_open: bulkin endpoint is %d",
  1044. port->bulk_in_endpointAddress);
  1045. mos7840_port->read_urb_busy = true;
  1046. response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL);
  1047. if (response) {
  1048. dev_err(&port->dev, "%s - Error %d submitting control urb\n",
  1049. __func__, response);
  1050. mos7840_port->read_urb_busy = false;
  1051. }
  1052. /* initialize our wait queues */
  1053. init_waitqueue_head(&mos7840_port->wait_chase);
  1054. init_waitqueue_head(&mos7840_port->delta_msr_wait);
  1055. /* initialize our icount structure */
  1056. memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
  1057. /* initialize our port settings */
  1058. /* Must set to enable ints! */
  1059. mos7840_port->shadowMCR = MCR_MASTER_IE;
  1060. /* send a open port command */
  1061. mos7840_port->open = 1;
  1062. /* mos7840_change_port_settings(mos7840_port,old_termios); */
  1063. mos7840_port->icount.tx = 0;
  1064. mos7840_port->icount.rx = 0;
  1065. dbg("usb_serial serial:%p mos7840_port:%p\n usb_serial_port port:%p",
  1066. serial, mos7840_port, port);
  1067. dbg ("%s leave", __func__);
  1068. return 0;
  1069. }
  1070. /*****************************************************************************
  1071. * mos7840_chars_in_buffer
  1072. * this function is called by the tty driver when it wants to know how many
  1073. * bytes of data we currently have outstanding in the port (data that has
  1074. * been written, but hasn't made it out the port yet)
  1075. * If successful, we return the number of bytes left to be written in the
  1076. * system,
  1077. * Otherwise we return zero.
  1078. *****************************************************************************/
  1079. static int mos7840_chars_in_buffer(struct tty_struct *tty)
  1080. {
  1081. struct usb_serial_port *port = tty->driver_data;
  1082. int i;
  1083. int chars = 0;
  1084. unsigned long flags;
  1085. struct moschip_port *mos7840_port;
  1086. dbg("%s", " mos7840_chars_in_buffer:entering ...........");
  1087. if (mos7840_port_paranoia_check(port, __func__)) {
  1088. dbg("%s", "Invalid port");
  1089. return 0;
  1090. }
  1091. mos7840_port = mos7840_get_port_private(port);
  1092. if (mos7840_port == NULL) {
  1093. dbg("%s", "mos7840_break:leaving ...........");
  1094. return 0;
  1095. }
  1096. spin_lock_irqsave(&mos7840_port->pool_lock, flags);
  1097. for (i = 0; i < NUM_URBS; ++i)
  1098. if (mos7840_port->busy[i])
  1099. chars += URB_TRANSFER_BUFFER_SIZE;
  1100. spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
  1101. dbg("%s - returns %d", __func__, chars);
  1102. return chars;
  1103. }
  1104. /*****************************************************************************
  1105. * mos7840_close
  1106. * this function is called by the tty driver when a port is closed
  1107. *****************************************************************************/
  1108. static void mos7840_close(struct usb_serial_port *port)
  1109. {
  1110. struct usb_serial *serial;
  1111. struct moschip_port *mos7840_port;
  1112. struct moschip_port *port0;
  1113. int j;
  1114. __u16 Data;
  1115. dbg("%s", "mos7840_close:entering...");
  1116. if (mos7840_port_paranoia_check(port, __func__)) {
  1117. dbg("%s", "Port Paranoia failed");
  1118. return;
  1119. }
  1120. serial = mos7840_get_usb_serial(port, __func__);
  1121. if (!serial) {
  1122. dbg("%s", "Serial Paranoia failed");
  1123. return;
  1124. }
  1125. mos7840_port = mos7840_get_port_private(port);
  1126. port0 = mos7840_get_port_private(serial->port[0]);
  1127. if (mos7840_port == NULL || port0 == NULL)
  1128. return;
  1129. for (j = 0; j < NUM_URBS; ++j)
  1130. usb_kill_urb(mos7840_port->write_urb_pool[j]);
  1131. /* Freeing Write URBs */
  1132. for (j = 0; j < NUM_URBS; ++j) {
  1133. if (mos7840_port->write_urb_pool[j]) {
  1134. if (mos7840_port->write_urb_pool[j]->transfer_buffer)
  1135. kfree(mos7840_port->write_urb_pool[j]->
  1136. transfer_buffer);
  1137. usb_free_urb(mos7840_port->write_urb_pool[j]);
  1138. }
  1139. }
  1140. /* While closing port, shutdown all bulk read, write *
  1141. * and interrupt read if they exists */
  1142. if (serial->dev) {
  1143. if (mos7840_port->write_urb) {
  1144. dbg("%s", "Shutdown bulk write");
  1145. usb_kill_urb(mos7840_port->write_urb);
  1146. }
  1147. if (mos7840_port->read_urb) {
  1148. dbg("%s", "Shutdown bulk read");
  1149. usb_kill_urb(mos7840_port->read_urb);
  1150. mos7840_port->read_urb_busy = false;
  1151. }
  1152. if ((&mos7840_port->control_urb)) {
  1153. dbg("%s", "Shutdown control read");
  1154. /*/ usb_kill_urb (mos7840_port->control_urb); */
  1155. }
  1156. }
  1157. /* if(mos7840_port->ctrl_buf != NULL) */
  1158. /* kfree(mos7840_port->ctrl_buf); */
  1159. port0->open_ports--;
  1160. dbg("mos7840_num_open_ports in close%d:in port%d",
  1161. port0->open_ports, port->number);
  1162. if (port0->open_ports == 0) {
  1163. if (serial->port[0]->interrupt_in_urb) {
  1164. dbg("%s", "Shutdown interrupt_in_urb");
  1165. usb_kill_urb(serial->port[0]->interrupt_in_urb);
  1166. }
  1167. }
  1168. if (mos7840_port->write_urb) {
  1169. /* if this urb had a transfer buffer already (old tx) free it */
  1170. if (mos7840_port->write_urb->transfer_buffer != NULL)
  1171. kfree(mos7840_port->write_urb->transfer_buffer);
  1172. usb_free_urb(mos7840_port->write_urb);
  1173. }
  1174. Data = 0x0;
  1175. mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
  1176. Data = 0x00;
  1177. mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
  1178. mos7840_port->open = 0;
  1179. dbg("%s", "Leaving ............");
  1180. }
  1181. /************************************************************************
  1182. *
  1183. * mos7840_block_until_chase_response
  1184. *
  1185. * This function will block the close until one of the following:
  1186. * 1. Response to our Chase comes from mos7840
  1187. * 2. A timeout of 10 seconds without activity has expired
  1188. * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty)
  1189. *
  1190. ************************************************************************/
  1191. static void mos7840_block_until_chase_response(struct tty_struct *tty,
  1192. struct moschip_port *mos7840_port)
  1193. {
  1194. int timeout = 1 * HZ;
  1195. int wait = 10;
  1196. int count;
  1197. while (1) {
  1198. count = mos7840_chars_in_buffer(tty);
  1199. /* Check for Buffer status */
  1200. if (count <= 0)
  1201. return;
  1202. /* Block the thread for a while */
  1203. interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
  1204. timeout);
  1205. /* No activity.. count down section */
  1206. wait--;
  1207. if (wait == 0) {
  1208. dbg("%s - TIMEOUT", __func__);
  1209. return;
  1210. } else {
  1211. /* Reset timeout value back to seconds */
  1212. wait = 10;
  1213. }
  1214. }
  1215. }
  1216. /*****************************************************************************
  1217. * mos7840_break
  1218. * this function sends a break to the port
  1219. *****************************************************************************/
  1220. static void mos7840_break(struct tty_struct *tty, int break_state)
  1221. {
  1222. struct usb_serial_port *port = tty->driver_data;
  1223. unsigned char data;
  1224. struct usb_serial *serial;
  1225. struct moschip_port *mos7840_port;
  1226. dbg("%s", "Entering ...........");
  1227. dbg("mos7840_break: Start");
  1228. if (mos7840_port_paranoia_check(port, __func__)) {
  1229. dbg("%s", "Port Paranoia failed");
  1230. return;
  1231. }
  1232. serial = mos7840_get_usb_serial(port, __func__);
  1233. if (!serial) {
  1234. dbg("%s", "Serial Paranoia failed");
  1235. return;
  1236. }
  1237. mos7840_port = mos7840_get_port_private(port);
  1238. if (mos7840_port == NULL)
  1239. return;
  1240. if (serial->dev)
  1241. /* flush and block until tx is empty */
  1242. mos7840_block_until_chase_response(tty, mos7840_port);
  1243. if (break_state == -1)
  1244. data = mos7840_port->shadowLCR | LCR_SET_BREAK;
  1245. else
  1246. data = mos7840_port->shadowLCR & ~LCR_SET_BREAK;
  1247. /* FIXME: no locking on shadowLCR anywhere in driver */
  1248. mos7840_port->shadowLCR = data;
  1249. dbg("mcs7840_break mos7840_port->shadowLCR is %x",
  1250. mos7840_port->shadowLCR);
  1251. mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER,
  1252. mos7840_port->shadowLCR);
  1253. }
  1254. /*****************************************************************************
  1255. * mos7840_write_room
  1256. * this function is called by the tty driver when it wants to know how many
  1257. * bytes of data we can accept for a specific port.
  1258. * If successful, we return the amount of room that we have for this port
  1259. * Otherwise we return a negative error number.
  1260. *****************************************************************************/
  1261. static int mos7840_write_room(struct tty_struct *tty)
  1262. {
  1263. struct usb_serial_port *port = tty->driver_data;
  1264. int i;
  1265. int room = 0;
  1266. unsigned long flags;
  1267. struct moschip_port *mos7840_port;
  1268. dbg("%s", " mos7840_write_room:entering ...........");
  1269. if (mos7840_port_paranoia_check(port, __func__)) {
  1270. dbg("%s", "Invalid port");
  1271. dbg("%s", " mos7840_write_room:leaving ...........");
  1272. return -1;
  1273. }
  1274. mos7840_port = mos7840_get_port_private(port);
  1275. if (mos7840_port == NULL) {
  1276. dbg("%s", "mos7840_break:leaving ...........");
  1277. return -1;
  1278. }
  1279. spin_lock_irqsave(&mos7840_port->pool_lock, flags);
  1280. for (i = 0; i < NUM_URBS; ++i) {
  1281. if (!mos7840_port->busy[i])
  1282. room += URB_TRANSFER_BUFFER_SIZE;
  1283. }
  1284. spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
  1285. room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1;
  1286. dbg("%s - returns %d", __func__, room);
  1287. return room;
  1288. }
  1289. /*****************************************************************************
  1290. * mos7840_write
  1291. * this function is called by the tty driver when data should be written to
  1292. * the port.
  1293. * If successful, we return the number of bytes written, otherwise we
  1294. * return a negative error number.
  1295. *****************************************************************************/
  1296. static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
  1297. const unsigned char *data, int count)
  1298. {
  1299. int status;
  1300. int i;
  1301. int bytes_sent = 0;
  1302. int transfer_size;
  1303. unsigned long flags;
  1304. struct moschip_port *mos7840_port;
  1305. struct usb_serial *serial;
  1306. struct urb *urb;
  1307. /* __u16 Data; */
  1308. const unsigned char *current_position = data;
  1309. unsigned char *data1;
  1310. dbg("%s", "entering ...........");
  1311. /* dbg("mos7840_write: mos7840_port->shadowLCR is %x",
  1312. mos7840_port->shadowLCR); */
  1313. #ifdef NOTMOS7840
  1314. Data = 0x00;
  1315. status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
  1316. mos7840_port->shadowLCR = Data;
  1317. dbg("mos7840_write: LINE_CONTROL_REGISTER is %x", Data);
  1318. dbg("mos7840_write: mos7840_port->shadowLCR is %x",
  1319. mos7840_port->shadowLCR);
  1320. /* Data = 0x03; */
  1321. /* status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); */
  1322. /* mos7840_port->shadowLCR=Data;//Need to add later */
  1323. Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
  1324. status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
  1325. /* Data = 0x0c; */
  1326. /* status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); */
  1327. Data = 0x00;
  1328. status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data);
  1329. dbg("mos7840_write:DLL value is %x", Data);
  1330. Data = 0x0;
  1331. status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data);
  1332. dbg("mos7840_write:DLM value is %x", Data);
  1333. Data = Data & ~SERIAL_LCR_DLAB;
  1334. dbg("mos7840_write: mos7840_port->shadowLCR is %x",
  1335. mos7840_port->shadowLCR);
  1336. status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
  1337. #endif
  1338. if (mos7840_port_paranoia_check(port, __func__)) {
  1339. dbg("%s", "Port Paranoia failed");
  1340. return -1;
  1341. }
  1342. serial = port->serial;
  1343. if (mos7840_serial_paranoia_check(serial, __func__)) {
  1344. dbg("%s", "Serial Paranoia failed");
  1345. return -1;
  1346. }
  1347. mos7840_port = mos7840_get_port_private(port);
  1348. if (mos7840_port == NULL) {
  1349. dbg("%s", "mos7840_port is NULL");
  1350. return -1;
  1351. }
  1352. /* try to find a free urb in the list */
  1353. urb = NULL;
  1354. spin_lock_irqsave(&mos7840_port->pool_lock, flags);
  1355. for (i = 0; i < NUM_URBS; ++i) {
  1356. if (!mos7840_port->busy[i]) {
  1357. mos7840_port->busy[i] = 1;
  1358. urb = mos7840_port->write_urb_pool[i];
  1359. dbg("URB:%d", i);
  1360. break;
  1361. }
  1362. }
  1363. spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
  1364. if (urb == NULL) {
  1365. dbg("%s - no more free urbs", __func__);
  1366. goto exit;
  1367. }
  1368. if (urb->transfer_buffer == NULL) {
  1369. urb->transfer_buffer =
  1370. kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
  1371. if (urb->transfer_buffer == NULL) {
  1372. dev_err_console(port, "%s no more kernel memory...\n",
  1373. __func__);
  1374. goto exit;
  1375. }
  1376. }
  1377. transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
  1378. memcpy(urb->transfer_buffer, current_position, transfer_size);
  1379. /* fill urb with data and submit */
  1380. if ((serial->num_ports == 2)
  1381. && ((((__u16)port->number -
  1382. (__u16)(port->serial->minor)) % 2) != 0)) {
  1383. usb_fill_bulk_urb(urb,
  1384. serial->dev,
  1385. usb_sndbulkpipe(serial->dev,
  1386. (port->bulk_out_endpointAddress) + 2),
  1387. urb->transfer_buffer,
  1388. transfer_size,
  1389. mos7840_bulk_out_data_callback, mos7840_port);
  1390. } else {
  1391. usb_fill_bulk_urb(urb,
  1392. serial->dev,
  1393. usb_sndbulkpipe(serial->dev,
  1394. port->bulk_out_endpointAddress),
  1395. urb->transfer_buffer,
  1396. transfer_size,
  1397. mos7840_bulk_out_data_callback, mos7840_port);
  1398. }
  1399. data1 = urb->transfer_buffer;
  1400. dbg("bulkout endpoint is %d", port->bulk_out_endpointAddress);
  1401. /* Turn on LED */
  1402. if (mos7840_port->has_led && !mos7840_port->led_flag) {
  1403. mos7840_port->led_flag = true;
  1404. mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0301);
  1405. mod_timer(&mos7840_port->led_timer1,
  1406. jiffies + msecs_to_jiffies(LED_ON_MS));
  1407. }
  1408. /* send it down the pipe */
  1409. status = usb_submit_urb(urb, GFP_ATOMIC);
  1410. if (status) {
  1411. mos7840_port->busy[i] = 0;
  1412. dev_err_console(port, "%s - usb_submit_urb(write bulk) failed "
  1413. "with status = %d\n", __func__, status);
  1414. bytes_sent = status;
  1415. goto exit;
  1416. }
  1417. bytes_sent = transfer_size;
  1418. mos7840_port->icount.tx += transfer_size;
  1419. smp_wmb();
  1420. dbg("mos7840_port->icount.tx is %d:", mos7840_port->icount.tx);
  1421. exit:
  1422. return bytes_sent;
  1423. }
  1424. /*****************************************************************************
  1425. * mos7840_throttle
  1426. * this function is called by the tty driver when it wants to stop the data
  1427. * being read from the port.
  1428. *****************************************************************************/
  1429. static void mos7840_throttle(struct tty_struct *tty)
  1430. {
  1431. struct usb_serial_port *port = tty->driver_data;
  1432. struct moschip_port *mos7840_port;
  1433. int status;
  1434. if (mos7840_port_paranoia_check(port, __func__)) {
  1435. dbg("%s", "Invalid port");
  1436. return;
  1437. }
  1438. dbg("- port %d", port->number);
  1439. mos7840_port = mos7840_get_port_private(port);
  1440. if (mos7840_port == NULL)
  1441. return;
  1442. if (!mos7840_port->open) {
  1443. dbg("%s", "port not opened");
  1444. return;
  1445. }
  1446. dbg("%s", "Entering ..........");
  1447. /* if we are implementing XON/XOFF, send the stop character */
  1448. if (I_IXOFF(tty)) {
  1449. unsigned char stop_char = STOP_CHAR(tty);
  1450. status = mos7840_write(tty, port, &stop_char, 1);
  1451. if (status <= 0)
  1452. return;
  1453. }
  1454. /* if we are implementing RTS/CTS, toggle that line */
  1455. if (tty->termios->c_cflag & CRTSCTS) {
  1456. mos7840_port->shadowMCR &= ~MCR_RTS;
  1457. status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
  1458. mos7840_port->shadowMCR);
  1459. if (status < 0)
  1460. return;
  1461. }
  1462. }
  1463. /*****************************************************************************
  1464. * mos7840_unthrottle
  1465. * this function is called by the tty driver when it wants to resume
  1466. * the data being read from the port (called after mos7840_throttle is
  1467. * called)
  1468. *****************************************************************************/
  1469. static void mos7840_unthrottle(struct tty_struct *tty)
  1470. {
  1471. struct usb_serial_port *port = tty->driver_data;
  1472. int status;
  1473. struct moschip_port *mos7840_port = mos7840_get_port_private(port);
  1474. if (mos7840_port_paranoia_check(port, __func__)) {
  1475. dbg("%s", "Invalid port");
  1476. return;
  1477. }
  1478. if (mos7840_port == NULL)
  1479. return;
  1480. if (!mos7840_port->open) {
  1481. dbg("%s - port not opened", __func__);
  1482. return;
  1483. }
  1484. dbg("%s", "Entering ..........");
  1485. /* if we are implementing XON/XOFF, send the start character */
  1486. if (I_IXOFF(tty)) {
  1487. unsigned char start_char = START_CHAR(tty);
  1488. status = mos7840_write(tty, port, &start_char, 1);
  1489. if (status <= 0)
  1490. return;
  1491. }
  1492. /* if we are implementing RTS/CTS, toggle that line */
  1493. if (tty->termios->c_cflag & CRTSCTS) {
  1494. mos7840_port->shadowMCR |= MCR_RTS;
  1495. status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
  1496. mos7840_port->shadowMCR);
  1497. if (status < 0)
  1498. return;
  1499. }
  1500. }
  1501. static int mos7840_tiocmget(struct tty_struct *tty)
  1502. {
  1503. struct usb_serial_port *port = tty->driver_data;
  1504. struct moschip_port *mos7840_port;
  1505. unsigned int result;
  1506. __u16 msr;
  1507. __u16 mcr;
  1508. int status;
  1509. mos7840_port = mos7840_get_port_private(port);
  1510. dbg("%s - port %d", __func__, port->number);
  1511. if (mos7840_port == NULL)
  1512. return -ENODEV;
  1513. status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
  1514. status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
  1515. result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
  1516. | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
  1517. | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
  1518. | ((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0)
  1519. | ((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0)
  1520. | ((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0)
  1521. | ((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0);
  1522. dbg("%s - 0x%04X", __func__, result);
  1523. return result;
  1524. }
  1525. static int mos7840_tiocmset(struct tty_struct *tty,
  1526. unsigned int set, unsigned int clear)
  1527. {
  1528. struct usb_serial_port *port = tty->driver_data;
  1529. struct moschip_port *mos7840_port;
  1530. unsigned int mcr;
  1531. int status;
  1532. dbg("%s - port %d", __func__, port->number);
  1533. mos7840_port = mos7840_get_port_private(port);
  1534. if (mos7840_port == NULL)
  1535. return -ENODEV;
  1536. /* FIXME: What locks the port registers ? */
  1537. mcr = mos7840_port->shadowMCR;
  1538. if (clear & TIOCM_RTS)
  1539. mcr &= ~MCR_RTS;
  1540. if (clear & TIOCM_DTR)
  1541. mcr &= ~MCR_DTR;
  1542. if (clear & TIOCM_LOOP)
  1543. mcr &= ~MCR_LOOPBACK;
  1544. if (set & TIOCM_RTS)
  1545. mcr |= MCR_RTS;
  1546. if (set & TIOCM_DTR)
  1547. mcr |= MCR_DTR;
  1548. if (set & TIOCM_LOOP)
  1549. mcr |= MCR_LOOPBACK;
  1550. mos7840_port->shadowMCR = mcr;
  1551. status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr);
  1552. if (status < 0) {
  1553. dbg("setting MODEM_CONTROL_REGISTER Failed");
  1554. return status;
  1555. }
  1556. return 0;
  1557. }
  1558. /*****************************************************************************
  1559. * mos7840_calc_baud_rate_divisor
  1560. * this function calculates the proper baud rate divisor for the specified
  1561. * baud rate.
  1562. *****************************************************************************/
  1563. static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor,
  1564. __u16 *clk_sel_val)
  1565. {
  1566. dbg("%s - %d", __func__, baudRate);
  1567. if (baudRate <= 115200) {
  1568. *divisor = 115200 / baudRate;
  1569. *clk_sel_val = 0x0;
  1570. }
  1571. if ((baudRate > 115200) && (baudRate <= 230400)) {
  1572. *divisor = 230400 / baudRate;
  1573. *clk_sel_val = 0x10;
  1574. } else if ((baudRate > 230400) && (baudRate <= 403200)) {
  1575. *divisor = 403200 / baudRate;
  1576. *clk_sel_val = 0x20;
  1577. } else if ((baudRate > 403200) && (baudRate <= 460800)) {
  1578. *divisor = 460800 / baudRate;
  1579. *clk_sel_val = 0x30;
  1580. } else if ((baudRate > 460800) && (baudRate <= 806400)) {
  1581. *divisor = 806400 / baudRate;
  1582. *clk_sel_val = 0x40;
  1583. } else if ((baudRate > 806400) && (baudRate <= 921600)) {
  1584. *divisor = 921600 / baudRate;
  1585. *clk_sel_val = 0x50;
  1586. } else if ((baudRate > 921600) && (baudRate <= 1572864)) {
  1587. *divisor = 1572864 / baudRate;
  1588. *clk_sel_val = 0x60;
  1589. } else if ((baudRate > 1572864) && (baudRate <= 3145728)) {
  1590. *divisor = 3145728 / baudRate;
  1591. *clk_sel_val = 0x70;
  1592. }
  1593. return 0;
  1594. #ifdef NOTMCS7840
  1595. for (i = 0; i < ARRAY_SIZE(mos7840_divisor_table); i++) {
  1596. if (mos7840_divisor_table[i].BaudRate == baudrate) {
  1597. *divisor = mos7840_divisor_table[i].Divisor;
  1598. return 0;
  1599. }
  1600. }
  1601. /* After trying for all the standard baud rates *
  1602. * Try calculating the divisor for this baud rate */
  1603. if (baudrate > 75 && baudrate < 230400) {
  1604. /* get the divisor */
  1605. custom = (__u16) (230400L / baudrate);
  1606. /* Check for round off */
  1607. round1 = (__u16) (2304000L / baudrate);
  1608. round = (__u16) (round1 - (custom * 10));
  1609. if (round > 4)
  1610. custom++;
  1611. *divisor = custom;
  1612. dbg(" Baud %d = %d", baudrate, custom);
  1613. return 0;
  1614. }
  1615. dbg("%s", " Baud calculation Failed...");
  1616. return -1;
  1617. #endif
  1618. }
  1619. /*****************************************************************************
  1620. * mos7840_send_cmd_write_baud_rate
  1621. * this function sends the proper command to change the baud rate of the
  1622. * specified port.
  1623. *****************************************************************************/
  1624. static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
  1625. int baudRate)
  1626. {
  1627. int divisor = 0;
  1628. int status;
  1629. __u16 Data;
  1630. unsigned char number;
  1631. __u16 clk_sel_val;
  1632. struct usb_serial_port *port;
  1633. if (mos7840_port == NULL)
  1634. return -1;
  1635. port = (struct usb_serial_port *)mos7840_port->port;
  1636. if (mos7840_port_paranoia_check(port, __func__)) {
  1637. dbg("%s", "Invalid port");
  1638. return -1;
  1639. }
  1640. if (mos7840_serial_paranoia_check(port->serial, __func__)) {
  1641. dbg("%s", "Invalid Serial");
  1642. return -1;
  1643. }
  1644. dbg("%s", "Entering ..........");
  1645. number = mos7840_port->port->number - mos7840_port->port->serial->minor;
  1646. dbg("%s - port = %d, baud = %d", __func__,
  1647. mos7840_port->port->number, baudRate);
  1648. /* reset clk_uart_sel in spregOffset */
  1649. if (baudRate > 115200) {
  1650. #ifdef HW_flow_control
  1651. /* NOTE: need to see the pther register to modify */
  1652. /* setting h/w flow control bit to 1 */
  1653. Data = 0x2b;
  1654. mos7840_port->shadowMCR = Data;
  1655. status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
  1656. Data);
  1657. if (status < 0) {
  1658. dbg("Writing spreg failed in set_serial_baud");
  1659. return -1;
  1660. }
  1661. #endif
  1662. } else {
  1663. #ifdef HW_flow_control
  1664. /* setting h/w flow control bit to 0 */
  1665. Data = 0xb;
  1666. mos7840_port->shadowMCR = Data;
  1667. status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
  1668. Data);
  1669. if (status < 0) {
  1670. dbg("Writing spreg failed in set_serial_baud");
  1671. return -1;
  1672. }
  1673. #endif
  1674. }
  1675. if (1) { /* baudRate <= 115200) */
  1676. clk_sel_val = 0x0;
  1677. Data = 0x0;
  1678. status = mos7840_calc_baud_rate_divisor(baudRate, &divisor,
  1679. &clk_sel_val);
  1680. status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset,
  1681. &Data);
  1682. if (status < 0) {
  1683. dbg("reading spreg failed in set_serial_baud");
  1684. return -1;
  1685. }
  1686. Data = (Data & 0x8f) | clk_sel_val;
  1687. status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset,
  1688. Data);
  1689. if (status < 0) {
  1690. dbg("Writing spreg failed in set_serial_baud");
  1691. return -1;
  1692. }
  1693. /* Calculate the Divisor */
  1694. if (status) {
  1695. dev_err(&port->dev, "%s - bad baud rate\n", __func__);
  1696. return status;
  1697. }
  1698. /* Enable access to divisor latch */
  1699. Data = mos7840_port->shadowLCR | SERIAL_LCR_DLAB;
  1700. mos7840_port->shadowLCR = Data;
  1701. mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
  1702. /* Write the divisor */
  1703. Data = (unsigned char)(divisor & 0xff);
  1704. dbg("set_serial_baud Value to write DLL is %x", Data);
  1705. mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
  1706. Data = (unsigned char)((divisor & 0xff00) >> 8);
  1707. dbg("set_serial_baud Value to write DLM is %x", Data);
  1708. mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
  1709. /* Disable access to divisor latch */
  1710. Data = mos7840_port->shadowLCR & ~SERIAL_LCR_DLAB;
  1711. mos7840_port->shadowLCR = Data;
  1712. mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
  1713. }
  1714. return status;
  1715. }
  1716. /*****************************************************************************
  1717. * mos7840_change_port_settings
  1718. * This routine is called to set the UART on the device to match
  1719. * the specified new settings.
  1720. *****************************************************************************/
  1721. static void mos7840_change_port_settings(struct tty_struct *tty,
  1722. struct moschip_port *mos7840_port, struct ktermios *old_termios)
  1723. {
  1724. int baud;
  1725. unsigned cflag;
  1726. unsigned iflag;
  1727. __u8 lData;
  1728. __u8 lParity;
  1729. __u8 lStop;
  1730. int status;
  1731. __u16 Data;
  1732. struct usb_serial_port *port;
  1733. struct usb_serial *serial;
  1734. if (mos7840_port == NULL)
  1735. return;
  1736. port = (struct usb_serial_port *)mos7840_port->port;
  1737. if (mos7840_port_paranoia_check(port, __func__)) {
  1738. dbg("%s", "Invalid port");
  1739. return;
  1740. }
  1741. if (mos7840_serial_paranoia_check(port->serial, __func__)) {
  1742. dbg("%s", "Invalid Serial");
  1743. return;
  1744. }
  1745. serial = port->serial;
  1746. dbg("%s - port %d", __func__, mos7840_port->port->number);
  1747. if (!mos7840_port->open) {
  1748. dbg("%s - port not opened", __func__);
  1749. return;
  1750. }
  1751. dbg("%s", "Entering ..........");
  1752. lData = LCR_BITS_8;
  1753. lStop = LCR_STOP_1;
  1754. lParity = LCR_PAR_NONE;
  1755. cflag = tty->termios->c_cflag;
  1756. iflag = tty->termios->c_iflag;
  1757. /* Change the number of bits */
  1758. if (cflag & CSIZE) {
  1759. switch (cflag & CSIZE) {
  1760. case CS5:
  1761. lData = LCR_BITS_5;
  1762. break;
  1763. case CS6:
  1764. lData = LCR_BITS_6;
  1765. break;
  1766. case CS7:
  1767. lData = LCR_BITS_7;
  1768. break;
  1769. default:
  1770. case CS8:
  1771. lData = LCR_BITS_8;
  1772. break;
  1773. }
  1774. }
  1775. /* Change the Parity bit */
  1776. if (cflag & PARENB) {
  1777. if (cflag & PARODD) {
  1778. lParity = LCR_PAR_ODD;
  1779. dbg("%s - parity = odd", __func__);
  1780. } else {
  1781. lParity = LCR_PAR_EVEN;
  1782. dbg("%s - parity = even", __func__);
  1783. }
  1784. } else {
  1785. dbg("%s - parity = none", __func__);
  1786. }
  1787. if (cflag & CMSPAR)
  1788. lParity = lParity | 0x20;
  1789. /* Change the Stop bit */
  1790. if (cflag & CSTOPB) {
  1791. lStop = LCR_STOP_2;
  1792. dbg("%s - stop bits = 2", __func__);
  1793. } else {
  1794. lStop = LCR_STOP_1;
  1795. dbg("%s - stop bits = 1", __func__);
  1796. }
  1797. /* Update the LCR with the correct value */
  1798. mos7840_port->shadowLCR &=
  1799. ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
  1800. mos7840_port->shadowLCR |= (lData | lParity | lStop);
  1801. dbg("mos7840_change_port_settings mos7840_port->shadowLCR is %x",
  1802. mos7840_port->shadowLCR);
  1803. /* Disable Interrupts */
  1804. Data = 0x00;
  1805. mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
  1806. Data = 0x00;
  1807. mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
  1808. Data = 0xcf;
  1809. mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
  1810. /* Send the updated LCR value to the mos7840 */
  1811. Data = mos7840_port->shadowLCR;
  1812. mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
  1813. Data = 0x00b;
  1814. mos7840_port->shadowMCR = Data;
  1815. mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
  1816. Data = 0x00b;
  1817. mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
  1818. /* set up the MCR register and send it to the mos7840 */
  1819. mos7840_port->shadowMCR = MCR_MASTER_IE;
  1820. if (cflag & CBAUD)
  1821. mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS);
  1822. if (cflag & CRTSCTS)
  1823. mos7840_port->shadowMCR |= (MCR_XON_ANY);
  1824. else
  1825. mos7840_port->shadowMCR &= ~(MCR_XON_ANY);
  1826. Data = mos7840_port->shadowMCR;
  1827. mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
  1828. /* Determine divisor based on baud rate */
  1829. baud = tty_get_baud_rate(tty);
  1830. if (!baud) {
  1831. /* pick a default, any default... */
  1832. dbg("%s", "Picked default baud...");
  1833. baud = 9600;
  1834. }
  1835. dbg("%s - baud rate = %d", __func__, baud);
  1836. status = mos7840_send_cmd_write_baud_rate(mos7840_port, baud);
  1837. /* Enable Interrupts */
  1838. Data = 0x0c;
  1839. mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
  1840. if (mos7840_port->read_urb_busy == false) {
  1841. mos7840_port->read_urb_busy = true;
  1842. status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
  1843. if (status) {
  1844. dbg("usb_submit_urb(read bulk) failed, status = %d",
  1845. status);
  1846. mos7840_port->read_urb_busy = false;
  1847. }
  1848. }
  1849. wake_up(&mos7840_port->delta_msr_wait);
  1850. mos7840_port->delta_msr_cond = 1;
  1851. dbg("mos7840_change_port_settings mos7840_port->shadowLCR is End %x",
  1852. mos7840_port->shadowLCR);
  1853. }
  1854. /*****************************************************************************
  1855. * mos7840_set_termios
  1856. * this function is called by the tty driver when it wants to change
  1857. * the termios structure
  1858. *****************************************************************************/
  1859. static void mos7840_set_termios(struct tty_struct *tty,
  1860. struct usb_serial_port *port,
  1861. struct ktermios *old_termios)
  1862. {
  1863. int status;
  1864. unsigned int cflag;
  1865. struct usb_serial *serial;
  1866. struct moschip_port *mos7840_port;
  1867. dbg("mos7840_set_termios: START");
  1868. if (mos7840_port_paranoia_check(port, __func__)) {
  1869. dbg("%s", "Invalid port");
  1870. return;
  1871. }
  1872. serial = port->serial;
  1873. if (mos7840_serial_paranoia_check(serial, __func__)) {
  1874. dbg("%s", "Invalid Serial");
  1875. return;
  1876. }
  1877. mos7840_port = mos7840_get_port_private(port);
  1878. if (mos7840_port == NULL)
  1879. return;
  1880. if (!mos7840_port->open) {
  1881. dbg("%s - port not opened", __func__);
  1882. return;
  1883. }
  1884. dbg("%s", "setting termios - ");
  1885. cflag = tty->termios->c_cflag;
  1886. dbg("%s - clfag %08x iflag %08x", __func__,
  1887. tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag));
  1888. dbg("%s - old clfag %08x old iflag %08x", __func__,
  1889. old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
  1890. dbg("%s - port %d", __func__, port->number);
  1891. /* change the port settings to the new ones specified */
  1892. mos7840_change_port_settings(tty, mos7840_port, old_termios);
  1893. if (!mos7840_port->read_urb) {
  1894. dbg("%s", "URB KILLED !!!!!");
  1895. return;
  1896. }
  1897. if (mos7840_port->read_urb_busy == false) {
  1898. mos7840_port->read_urb_busy = true;
  1899. status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
  1900. if (status) {
  1901. dbg("usb_submit_urb(read bulk) failed, status = %d",
  1902. status);
  1903. mos7840_port->read_urb_busy = false;
  1904. }
  1905. }
  1906. }
  1907. /*****************************************************************************
  1908. * mos7840_get_lsr_info - get line status register info
  1909. *
  1910. * Purpose: Let user call ioctl() to get info when the UART physically
  1911. * is emptied. On bus types like RS485, the transmitter must
  1912. * release the bus after transmitting. This must be done when
  1913. * the transmit shift register is empty, not be done when the
  1914. * transmit holding register is empty. This functionality
  1915. * allows an RS485 driver to be written in user space.
  1916. *****************************************************************************/
  1917. static int mos7840_get_lsr_info(struct tty_struct *tty,
  1918. unsigned int __user *value)
  1919. {
  1920. int count;
  1921. unsigned int result = 0;
  1922. count = mos7840_chars_in_buffer(tty);
  1923. if (count == 0) {
  1924. dbg("%s -- Empty", __func__);
  1925. result = TIOCSER_TEMT;
  1926. }
  1927. if (copy_to_user(value, &result, sizeof(int)))
  1928. return -EFAULT;
  1929. return 0;
  1930. }
  1931. /*****************************************************************************
  1932. * mos7840_get_serial_info
  1933. * function to get information about serial port
  1934. *****************************************************************************/
  1935. static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
  1936. struct serial_struct __user *retinfo)
  1937. {
  1938. struct serial_struct tmp;
  1939. if (mos7840_port == NULL)
  1940. return -1;
  1941. if (!retinfo)
  1942. return -EFAULT;
  1943. memset(&tmp, 0, sizeof(tmp));
  1944. tmp.type = PORT_16550A;
  1945. tmp.line = mos7840_port->port->serial->minor;
  1946. tmp.port = mos7840_port->port->number;
  1947. tmp.irq = 0;
  1948. tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
  1949. tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
  1950. tmp.baud_base = 9600;
  1951. tmp.close_delay = 5 * HZ;
  1952. tmp.closing_wait = 30 * HZ;
  1953. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  1954. return -EFAULT;
  1955. return 0;
  1956. }
  1957. static int mos7840_get_icount(struct tty_struct *tty,
  1958. struct serial_icounter_struct *icount)
  1959. {
  1960. struct usb_serial_port *port = tty->driver_data;
  1961. struct moschip_port *mos7840_port;
  1962. struct async_icount cnow;
  1963. mos7840_port = mos7840_get_port_private(port);
  1964. cnow = mos7840_port->icount;
  1965. smp_rmb();
  1966. icount->cts = cnow.cts;
  1967. icount->dsr = cnow.dsr;
  1968. icount->rng = cnow.rng;
  1969. icount->dcd = cnow.dcd;
  1970. icount->rx = cnow.rx;
  1971. icount->tx = cnow.tx;
  1972. icount->frame = cnow.frame;
  1973. icount->overrun = cnow.overrun;
  1974. icount->parity = cnow.parity;
  1975. icount->brk = cnow.brk;
  1976. icount->buf_overrun = cnow.buf_overrun;
  1977. dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
  1978. port->number, icount->rx, icount->tx);
  1979. return 0;
  1980. }
  1981. /*****************************************************************************
  1982. * SerialIoctl
  1983. * this function handles any ioctl calls to the driver
  1984. *****************************************************************************/
  1985. static int mos7840_ioctl(struct tty_struct *tty,
  1986. unsigned int cmd, unsigned long arg)
  1987. {
  1988. struct usb_serial_port *port = tty->driver_data;
  1989. void __user *argp = (void __user *)arg;
  1990. struct moschip_port *mos7840_port;
  1991. struct async_icount cnow;
  1992. struct async_icount cprev;
  1993. if (mos7840_port_paranoia_check(port, __func__)) {
  1994. dbg("%s", "Invalid port");
  1995. return -1;
  1996. }
  1997. mos7840_port = mos7840_get_port_private(port);
  1998. if (mos7840_port == NULL)
  1999. return -1;
  2000. dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
  2001. switch (cmd) {
  2002. /* return number of bytes available */
  2003. case TIOCSERGETLSR:
  2004. dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
  2005. return mos7840_get_lsr_info(tty, argp);
  2006. case TIOCGSERIAL:
  2007. dbg("%s (%d) TIOCGSERIAL", __func__, port->number);
  2008. return mos7840_get_serial_info(mos7840_port, argp);
  2009. case TIOCSSERIAL:
  2010. dbg("%s (%d) TIOCSSERIAL", __func__, port->number);
  2011. break;
  2012. case TIOCMIWAIT:
  2013. dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
  2014. cprev = mos7840_port->icount;
  2015. while (1) {
  2016. /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */
  2017. mos7840_port->delta_msr_cond = 0;
  2018. wait_event_interruptible(mos7840_port->delta_msr_wait,
  2019. (mos7840_port->
  2020. delta_msr_cond == 1));
  2021. /* see if a signal did it */
  2022. if (signal_pending(current))
  2023. return -ERESTARTSYS;
  2024. cnow = mos7840_port->icount;
  2025. smp_rmb();
  2026. if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
  2027. cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
  2028. return -EIO; /* no change => error */
  2029. if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
  2030. ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
  2031. ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
  2032. ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
  2033. return 0;
  2034. }
  2035. cprev = cnow;
  2036. }
  2037. /* NOTREACHED */
  2038. break;
  2039. default:
  2040. break;
  2041. }
  2042. return -ENOIOCTLCMD;
  2043. }
  2044. static int mos7810_check(struct usb_serial *serial)
  2045. {
  2046. int i, pass_count = 0;
  2047. __u16 data = 0, mcr_data = 0;
  2048. __u16 test_pattern = 0x55AA;
  2049. /* Store MCR setting */
  2050. usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  2051. MCS_RDREQ, MCS_RD_RTYPE, 0x0300, MODEM_CONTROL_REGISTER,
  2052. &mcr_data, VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
  2053. for (i = 0; i < 16; i++) {
  2054. /* Send the 1-bit test pattern out to MCS7810 test pin */
  2055. usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  2056. MCS_WRREQ, MCS_WR_RTYPE,
  2057. (0x0300 | (((test_pattern >> i) & 0x0001) << 1)),
  2058. MODEM_CONTROL_REGISTER, NULL, 0, MOS_WDR_TIMEOUT);
  2059. /* Read the test pattern back */
  2060. usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  2061. MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &data,
  2062. VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
  2063. /* If this is a MCS7810 device, both test patterns must match */
  2064. if (((test_pattern >> i) ^ (~data >> 1)) & 0x0001)
  2065. break;
  2066. pass_count++;
  2067. }
  2068. /* Restore MCR setting */
  2069. usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), MCS_WRREQ,
  2070. MCS_WR_RTYPE, 0x0300 | mcr_data, MODEM_CONTROL_REGISTER, NULL,
  2071. 0, MOS_WDR_TIMEOUT);
  2072. if (pass_count == 16)
  2073. return 1;
  2074. return 0;
  2075. }
  2076. static int mos7840_calc_num_ports(struct usb_serial *serial)
  2077. {
  2078. __u16 data = 0x00;
  2079. int mos7840_num_ports;
  2080. usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  2081. MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &data,
  2082. VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
  2083. if (serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7810 ||
  2084. serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7820) {
  2085. device_type = serial->dev->descriptor.idProduct;
  2086. } else {
  2087. /* For a MCS7840 device GPIO0 must be set to 1 */
  2088. if ((data & 0x01) == 1)
  2089. device_type = MOSCHIP_DEVICE_ID_7840;
  2090. else if (mos7810_check(serial))
  2091. device_type = MOSCHIP_DEVICE_ID_7810;
  2092. else
  2093. device_type = MOSCHIP_DEVICE_ID_7820;
  2094. }
  2095. mos7840_num_ports = (device_type >> 4) & 0x000F;
  2096. serial->num_bulk_in = mos7840_num_ports;
  2097. serial->num_bulk_out = mos7840_num_ports;
  2098. serial->num_ports = mos7840_num_ports;
  2099. return mos7840_num_ports;
  2100. }
  2101. /****************************************************************************
  2102. * mos7840_startup
  2103. ****************************************************************************/
  2104. static int mos7840_startup(struct usb_serial *serial)
  2105. {
  2106. struct moschip_port *mos7840_port;
  2107. struct usb_device *dev;
  2108. int i, status;
  2109. __u16 Data;
  2110. dbg("%s", "mos7840_startup :Entering..........");
  2111. if (!serial) {
  2112. dbg("%s", "Invalid Handler");
  2113. return -1;
  2114. }
  2115. dev = serial->dev;
  2116. dbg("%s", "Entering...");
  2117. dbg ("mos7840_startup: serial = %p", serial);
  2118. /* we set up the pointers to the endpoints in the mos7840_open *
  2119. * function, as the structures aren't created yet. */
  2120. /* set up port private structures */
  2121. for (i = 0; i < serial->num_ports; ++i) {
  2122. dbg ("mos7840_startup: configuring port %d............", i);
  2123. mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL);
  2124. if (mos7840_port == NULL) {
  2125. dev_err(&dev->dev, "%s - Out of memory\n", __func__);
  2126. status = -ENOMEM;
  2127. i--; /* don't follow NULL pointer cleaning up */
  2128. goto error;
  2129. }
  2130. /* Initialize all port interrupt end point to port 0 int
  2131. * endpoint. Our device has only one interrupt end point
  2132. * common to all port */
  2133. mos7840_port->port = serial->port[i];
  2134. mos7840_set_port_private(serial->port[i], mos7840_port);
  2135. spin_lock_init(&mos7840_port->pool_lock);
  2136. /* minor is not initialised until later by
  2137. * usb-serial.c:get_free_serial() and cannot therefore be used
  2138. * to index device instances */
  2139. mos7840_port->port_num = i + 1;
  2140. dbg ("serial->port[i]->number = %d", serial->port[i]->number);
  2141. dbg ("serial->port[i]->serial->minor = %d", serial->port[i]->serial->minor);
  2142. dbg ("mos7840_port->port_num = %d", mos7840_port->port_num);
  2143. dbg ("serial->minor = %d", serial->minor);
  2144. if (mos7840_port->port_num == 1) {
  2145. mos7840_port->SpRegOffset = 0x0;
  2146. mos7840_port->ControlRegOffset = 0x1;
  2147. mos7840_port->DcrRegOffset = 0x4;
  2148. } else if ((mos7840_port->port_num == 2)
  2149. && (serial->num_ports == 4)) {
  2150. mos7840_port->SpRegOffset = 0x8;
  2151. mos7840_port->ControlRegOffset = 0x9;
  2152. mos7840_port->DcrRegOffset = 0x16;
  2153. } else if ((mos7840_port->port_num == 2)
  2154. && (serial->num_ports == 2)) {
  2155. mos7840_port->SpRegOffset = 0xa;
  2156. mos7840_port->ControlRegOffset = 0xb;
  2157. mos7840_port->DcrRegOffset = 0x19;
  2158. } else if ((mos7840_port->port_num == 3)
  2159. && (serial->num_ports == 4)) {
  2160. mos7840_port->SpRegOffset = 0xa;
  2161. mos7840_port->ControlRegOffset = 0xb;
  2162. mos7840_port->DcrRegOffset = 0x19;
  2163. } else if ((mos7840_port->port_num == 4)
  2164. && (serial->num_ports == 4)) {
  2165. mos7840_port->SpRegOffset = 0xc;
  2166. mos7840_port->ControlRegOffset = 0xd;
  2167. mos7840_port->DcrRegOffset = 0x1c;
  2168. }
  2169. mos7840_dump_serial_port(mos7840_port);
  2170. mos7840_set_port_private(serial->port[i], mos7840_port);
  2171. /* enable rx_disable bit in control register */
  2172. status = mos7840_get_reg_sync(serial->port[i],
  2173. mos7840_port->ControlRegOffset, &Data);
  2174. if (status < 0) {
  2175. dbg("Reading ControlReg failed status-0x%x", status);
  2176. break;
  2177. } else
  2178. dbg("ControlReg Reading success val is %x, status%d",
  2179. Data, status);
  2180. Data |= 0x08; /* setting driver done bit */
  2181. Data |= 0x04; /* sp1_bit to have cts change reflect in
  2182. modem status reg */
  2183. /* Data |= 0x20; //rx_disable bit */
  2184. status = mos7840_set_reg_sync(serial->port[i],
  2185. mos7840_port->ControlRegOffset, Data);
  2186. if (status < 0) {
  2187. dbg("Writing ControlReg failed(rx_disable) status-0x%x", status);
  2188. break;
  2189. } else
  2190. dbg("ControlReg Writing success(rx_disable) status%d",
  2191. status);
  2192. /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2
  2193. and 0x24 in DCR3 */
  2194. Data = 0x01;
  2195. status = mos7840_set_reg_sync(serial->port[i],
  2196. (__u16) (mos7840_port->DcrRegOffset + 0), Data);
  2197. if (status < 0) {
  2198. dbg("Writing DCR0 failed status-0x%x", status);
  2199. break;
  2200. } else
  2201. dbg("DCR0 Writing success status%d", status);
  2202. Data = 0x05;
  2203. status = mos7840_set_reg_sync(serial->port[i],
  2204. (__u16) (mos7840_port->DcrRegOffset + 1), Data);
  2205. if (status < 0) {
  2206. dbg("Writing DCR1 failed status-0x%x", status);
  2207. break;
  2208. } else
  2209. dbg("DCR1 Writing success status%d", status);
  2210. Data = 0x24;
  2211. status = mos7840_set_reg_sync(serial->port[i],
  2212. (__u16) (mos7840_port->DcrRegOffset + 2), Data);
  2213. if (status < 0) {
  2214. dbg("Writing DCR2 failed status-0x%x", status);
  2215. break;
  2216. } else
  2217. dbg("DCR2 Writing success status%d", status);
  2218. /* write values in clkstart0x0 and clkmulti 0x20 */
  2219. Data = 0x0;
  2220. status = mos7840_set_reg_sync(serial->port[i],
  2221. CLK_START_VALUE_REGISTER, Data);
  2222. if (status < 0) {
  2223. dbg("Writing CLK_START_VALUE_REGISTER failed status-0x%x", status);
  2224. break;
  2225. } else
  2226. dbg("CLK_START_VALUE_REGISTER Writing success status%d", status);
  2227. Data = 0x20;
  2228. status = mos7840_set_reg_sync(serial->port[i],
  2229. CLK_MULTI_REGISTER, Data);
  2230. if (status < 0) {
  2231. dbg("Writing CLK_MULTI_REGISTER failed status-0x%x",
  2232. status);
  2233. goto error;
  2234. } else
  2235. dbg("CLK_MULTI_REGISTER Writing success status%d",
  2236. status);
  2237. /* write value 0x0 to scratchpad register */
  2238. Data = 0x00;
  2239. status = mos7840_set_uart_reg(serial->port[i],
  2240. SCRATCH_PAD_REGISTER, Data);
  2241. if (status < 0) {
  2242. dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x",
  2243. status);
  2244. break;
  2245. } else
  2246. dbg("SCRATCH_PAD_REGISTER Writing success status%d",
  2247. status);
  2248. /* Zero Length flag register */
  2249. if ((mos7840_port->port_num != 1)
  2250. && (serial->num_ports == 2)) {
  2251. Data = 0xff;
  2252. status = mos7840_set_reg_sync(serial->port[i],
  2253. (__u16) (ZLP_REG1 +
  2254. ((__u16)mos7840_port->port_num)), Data);
  2255. dbg("ZLIP offset %x",
  2256. (__u16) (ZLP_REG1 +
  2257. ((__u16) mos7840_port->port_num)));
  2258. if (status < 0) {
  2259. dbg("Writing ZLP_REG%d failed status-0x%x",
  2260. i + 2, status);
  2261. break;
  2262. } else
  2263. dbg("ZLP_REG%d Writing success status%d",
  2264. i + 2, status);
  2265. } else {
  2266. Data = 0xff;
  2267. status = mos7840_set_reg_sync(serial->port[i],
  2268. (__u16) (ZLP_REG1 +
  2269. ((__u16)mos7840_port->port_num) - 0x1), Data);
  2270. dbg("ZLIP offset %x",
  2271. (__u16) (ZLP_REG1 +
  2272. ((__u16) mos7840_port->port_num) - 0x1));
  2273. if (status < 0) {
  2274. dbg("Writing ZLP_REG%d failed status-0x%x",
  2275. i + 1, status);
  2276. break;
  2277. } else
  2278. dbg("ZLP_REG%d Writing success status%d",
  2279. i + 1, status);
  2280. }
  2281. mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL);
  2282. mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
  2283. mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest),
  2284. GFP_KERNEL);
  2285. if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf ||
  2286. !mos7840_port->dr) {
  2287. status = -ENOMEM;
  2288. goto error;
  2289. }
  2290. mos7840_port->has_led = false;
  2291. /* Initialize LED timers */
  2292. if (device_type == MOSCHIP_DEVICE_ID_7810) {
  2293. mos7840_port->has_led = true;
  2294. init_timer(&mos7840_port->led_timer1);
  2295. mos7840_port->led_timer1.function = mos7840_led_off;
  2296. mos7840_port->led_timer1.expires =
  2297. jiffies + msecs_to_jiffies(LED_ON_MS);
  2298. mos7840_port->led_timer1.data =
  2299. (unsigned long)mos7840_port;
  2300. init_timer(&mos7840_port->led_timer2);
  2301. mos7840_port->led_timer2.function =
  2302. mos7840_led_flag_off;
  2303. mos7840_port->led_timer2.expires =
  2304. jiffies + msecs_to_jiffies(LED_OFF_MS);
  2305. mos7840_port->led_timer2.data =
  2306. (unsigned long)mos7840_port;
  2307. mos7840_port->led_flag = false;
  2308. /* Turn off LED */
  2309. mos7840_set_led_sync(serial->port[i],
  2310. MODEM_CONTROL_REGISTER, 0x0300);
  2311. }
  2312. }
  2313. dbg ("mos7840_startup: all ports configured...........");
  2314. /* Zero Length flag enable */
  2315. Data = 0x0f;
  2316. status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data);
  2317. if (status < 0) {
  2318. dbg("Writing ZLP_REG5 failed status-0x%x", status);
  2319. goto error;
  2320. } else
  2321. dbg("ZLP_REG5 Writing success status%d", status);
  2322. /* setting configuration feature to one */
  2323. usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  2324. (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5 * HZ);
  2325. return 0;
  2326. error:
  2327. for (/* nothing */; i >= 0; i--) {
  2328. mos7840_port = mos7840_get_port_private(serial->port[i]);
  2329. kfree(mos7840_port->dr);
  2330. kfree(mos7840_port->ctrl_buf);
  2331. usb_free_urb(mos7840_port->control_urb);
  2332. kfree(mos7840_port);
  2333. serial->port[i] = NULL;
  2334. }
  2335. return status;
  2336. }
  2337. /****************************************************************************
  2338. * mos7840_disconnect
  2339. * This function is called whenever the device is removed from the usb bus.
  2340. ****************************************************************************/
  2341. static void mos7840_disconnect(struct usb_serial *serial)
  2342. {
  2343. int i;
  2344. unsigned long flags;
  2345. struct moschip_port *mos7840_port;
  2346. dbg("%s", " disconnect :entering..........");
  2347. if (!serial) {
  2348. dbg("%s", "Invalid Handler");
  2349. return;
  2350. }
  2351. /* check for the ports to be closed,close the ports and disconnect */
  2352. /* free private structure allocated for serial port *
  2353. * stop reads and writes on all ports */
  2354. for (i = 0; i < serial->num_ports; ++i) {
  2355. mos7840_port = mos7840_get_port_private(serial->port[i]);
  2356. dbg ("mos7840_port %d = %p", i, mos7840_port);
  2357. if (mos7840_port) {
  2358. spin_lock_irqsave(&mos7840_port->pool_lock, flags);
  2359. mos7840_port->zombie = 1;
  2360. spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
  2361. usb_kill_urb(mos7840_port->control_urb);
  2362. }
  2363. }
  2364. dbg("%s", "Thank u :: ");
  2365. }
  2366. /****************************************************************************
  2367. * mos7840_release
  2368. * This function is called when the usb_serial structure is freed.
  2369. ****************************************************************************/
  2370. static void mos7840_release(struct usb_serial *serial)
  2371. {
  2372. int i;
  2373. struct moschip_port *mos7840_port;
  2374. dbg("%s", " release :entering..........");
  2375. if (!serial) {
  2376. dbg("%s", "Invalid Handler");
  2377. return;
  2378. }
  2379. /* check for the ports to be closed,close the ports and disconnect */
  2380. /* free private structure allocated for serial port *
  2381. * stop reads and writes on all ports */
  2382. for (i = 0; i < serial->num_ports; ++i) {
  2383. mos7840_port = mos7840_get_port_private(serial->port[i]);
  2384. dbg("mos7840_port %d = %p", i, mos7840_port);
  2385. if (mos7840_port) {
  2386. if (mos7840_port->has_led) {
  2387. /* Turn off LED */
  2388. mos7840_set_led_sync(mos7840_port->port,
  2389. MODEM_CONTROL_REGISTER, 0x0300);
  2390. del_timer_sync(&mos7840_port->led_timer1);
  2391. del_timer_sync(&mos7840_port->led_timer2);
  2392. }
  2393. kfree(mos7840_port->ctrl_buf);
  2394. kfree(mos7840_port->dr);
  2395. kfree(mos7840_port);
  2396. }
  2397. }
  2398. dbg("%s", "Thank u :: ");
  2399. }
  2400. static struct usb_driver io_driver = {
  2401. .name = "mos7840",
  2402. .probe = usb_serial_probe,
  2403. .disconnect = usb_serial_disconnect,
  2404. .id_table = moschip_id_table_combined,
  2405. };
  2406. static struct usb_serial_driver moschip7840_4port_device = {
  2407. .driver = {
  2408. .owner = THIS_MODULE,
  2409. .name = "mos7840",
  2410. },
  2411. .description = DRIVER_DESC,
  2412. .id_table = moschip_port_id_table,
  2413. .num_ports = 4,
  2414. .open = mos7840_open,
  2415. .close = mos7840_close,
  2416. .write = mos7840_write,
  2417. .write_room = mos7840_write_room,
  2418. .chars_in_buffer = mos7840_chars_in_buffer,
  2419. .throttle = mos7840_throttle,
  2420. .unthrottle = mos7840_unthrottle,
  2421. .calc_num_ports = mos7840_calc_num_ports,
  2422. #ifdef MCSSerialProbe
  2423. .probe = mos7840_serial_probe,
  2424. #endif
  2425. .ioctl = mos7840_ioctl,
  2426. .set_termios = mos7840_set_termios,
  2427. .break_ctl = mos7840_break,
  2428. .tiocmget = mos7840_tiocmget,
  2429. .tiocmset = mos7840_tiocmset,
  2430. .get_icount = mos7840_get_icount,
  2431. .attach = mos7840_startup,
  2432. .disconnect = mos7840_disconnect,
  2433. .release = mos7840_release,
  2434. .read_bulk_callback = mos7840_bulk_in_callback,
  2435. .read_int_callback = mos7840_interrupt_callback,
  2436. };
  2437. static struct usb_serial_driver * const serial_drivers[] = {
  2438. &moschip7840_4port_device, NULL
  2439. };
  2440. module_usb_serial_driver(io_driver, serial_drivers);
  2441. MODULE_DESCRIPTION(DRIVER_DESC);
  2442. MODULE_LICENSE("GPL");
  2443. module_param(debug, bool, S_IRUGO | S_IWUSR);
  2444. MODULE_PARM_DESC(debug, "Debug enabled or not");