8250.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105
  1. /*
  2. * linux/drivers/char/8250.c
  3. *
  4. * Driver for 8250/16550-type serial ports
  5. *
  6. * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
  7. *
  8. * Copyright (C) 2001 Russell King.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * A note about mapbase / membase
  16. *
  17. * mapbase is the physical address of the IO port.
  18. * membase is an 'ioremapped' cookie.
  19. */
  20. #if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  21. #define SUPPORT_SYSRQ
  22. #endif
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/ioport.h>
  26. #include <linux/init.h>
  27. #include <linux/console.h>
  28. #include <linux/sysrq.h>
  29. #include <linux/delay.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/tty.h>
  32. #include <linux/tty_flip.h>
  33. #include <linux/serial_reg.h>
  34. #include <linux/serial_core.h>
  35. #include <linux/serial.h>
  36. #include <linux/serial_8250.h>
  37. #include <linux/nmi.h>
  38. #include <linux/mutex.h>
  39. #include <asm/io.h>
  40. #include <asm/irq.h>
  41. #include "8250.h"
  42. #ifdef CONFIG_SPARC
  43. #include "suncore.h"
  44. #endif
  45. /*
  46. * Configuration:
  47. * share_irqs - whether we pass IRQF_SHARED to request_irq(). This option
  48. * is unsafe when used on edge-triggered interrupts.
  49. */
  50. static unsigned int share_irqs = SERIAL8250_SHARE_IRQS;
  51. static unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS;
  52. static struct uart_driver serial8250_reg;
  53. static int serial_index(struct uart_port *port)
  54. {
  55. return (serial8250_reg.minor - 64) + port->line;
  56. }
  57. /*
  58. * Debugging.
  59. */
  60. #if 0
  61. #define DEBUG_AUTOCONF(fmt...) printk(fmt)
  62. #else
  63. #define DEBUG_AUTOCONF(fmt...) do { } while (0)
  64. #endif
  65. #if 0
  66. #define DEBUG_INTR(fmt...) printk(fmt)
  67. #else
  68. #define DEBUG_INTR(fmt...) do { } while (0)
  69. #endif
  70. #define PASS_LIMIT 256
  71. /*
  72. * We default to IRQ0 for the "no irq" hack. Some
  73. * machine types want others as well - they're free
  74. * to redefine this in their header file.
  75. */
  76. #define is_real_interrupt(irq) ((irq) != 0)
  77. #ifdef CONFIG_SERIAL_8250_DETECT_IRQ
  78. #define CONFIG_SERIAL_DETECT_IRQ 1
  79. #endif
  80. #ifdef CONFIG_SERIAL_8250_MANY_PORTS
  81. #define CONFIG_SERIAL_MANY_PORTS 1
  82. #endif
  83. /*
  84. * HUB6 is always on. This will be removed once the header
  85. * files have been cleaned.
  86. */
  87. #define CONFIG_HUB6 1
  88. #include <asm/serial.h>
  89. /*
  90. * SERIAL_PORT_DFNS tells us about built-in ports that have no
  91. * standard enumeration mechanism. Platforms that can find all
  92. * serial ports via mechanisms like ACPI or PCI need not supply it.
  93. */
  94. #ifndef SERIAL_PORT_DFNS
  95. #define SERIAL_PORT_DFNS
  96. #endif
  97. static const struct old_serial_port old_serial_port[] = {
  98. SERIAL_PORT_DFNS /* defined in asm/serial.h */
  99. };
  100. #define UART_NR CONFIG_SERIAL_8250_NR_UARTS
  101. #ifdef CONFIG_SERIAL_8250_RSA
  102. #define PORT_RSA_MAX 4
  103. static unsigned long probe_rsa[PORT_RSA_MAX];
  104. static unsigned int probe_rsa_count;
  105. #endif /* CONFIG_SERIAL_8250_RSA */
  106. struct uart_8250_port {
  107. struct uart_port port;
  108. struct timer_list timer; /* "no irq" timer */
  109. struct list_head list; /* ports on this IRQ */
  110. unsigned short capabilities; /* port capabilities */
  111. unsigned short bugs; /* port bugs */
  112. unsigned int tx_loadsz; /* transmit fifo load size */
  113. unsigned char acr;
  114. unsigned char ier;
  115. unsigned char lcr;
  116. unsigned char mcr;
  117. unsigned char mcr_mask; /* mask of user bits */
  118. unsigned char mcr_force; /* mask of forced bits */
  119. /*
  120. * Some bits in registers are cleared on a read, so they must
  121. * be saved whenever the register is read but the bits will not
  122. * be immediately processed.
  123. */
  124. #define LSR_SAVE_FLAGS UART_LSR_BRK_ERROR_BITS
  125. unsigned char lsr_saved_flags;
  126. #define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA
  127. unsigned char msr_saved_flags;
  128. /*
  129. * We provide a per-port pm hook.
  130. */
  131. void (*pm)(struct uart_port *port,
  132. unsigned int state, unsigned int old);
  133. };
  134. struct irq_info {
  135. struct hlist_node node;
  136. int irq;
  137. spinlock_t lock; /* Protects list not the hash */
  138. struct list_head *head;
  139. };
  140. #define NR_IRQ_HASH 32 /* Can be adjusted later */
  141. static struct hlist_head irq_lists[NR_IRQ_HASH];
  142. static DEFINE_MUTEX(hash_mutex); /* Used to walk the hash */
  143. /*
  144. * Here we define the default xmit fifo size used for each type of UART.
  145. */
  146. static const struct serial8250_config uart_config[] = {
  147. [PORT_UNKNOWN] = {
  148. .name = "unknown",
  149. .fifo_size = 1,
  150. .tx_loadsz = 1,
  151. },
  152. [PORT_8250] = {
  153. .name = "8250",
  154. .fifo_size = 1,
  155. .tx_loadsz = 1,
  156. },
  157. [PORT_16450] = {
  158. .name = "16450",
  159. .fifo_size = 1,
  160. .tx_loadsz = 1,
  161. },
  162. [PORT_16550] = {
  163. .name = "16550",
  164. .fifo_size = 1,
  165. .tx_loadsz = 1,
  166. },
  167. [PORT_16550A] = {
  168. .name = "16550A",
  169. .fifo_size = 16,
  170. .tx_loadsz = 16,
  171. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  172. .flags = UART_CAP_FIFO,
  173. },
  174. [PORT_CIRRUS] = {
  175. .name = "Cirrus",
  176. .fifo_size = 1,
  177. .tx_loadsz = 1,
  178. },
  179. [PORT_16650] = {
  180. .name = "ST16650",
  181. .fifo_size = 1,
  182. .tx_loadsz = 1,
  183. .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
  184. },
  185. [PORT_16650V2] = {
  186. .name = "ST16650V2",
  187. .fifo_size = 32,
  188. .tx_loadsz = 16,
  189. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
  190. UART_FCR_T_TRIG_00,
  191. .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
  192. },
  193. [PORT_16750] = {
  194. .name = "TI16750",
  195. .fifo_size = 64,
  196. .tx_loadsz = 64,
  197. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 |
  198. UART_FCR7_64BYTE,
  199. .flags = UART_CAP_FIFO | UART_CAP_SLEEP | UART_CAP_AFE,
  200. },
  201. [PORT_STARTECH] = {
  202. .name = "Startech",
  203. .fifo_size = 1,
  204. .tx_loadsz = 1,
  205. },
  206. [PORT_16C950] = {
  207. .name = "16C950/954",
  208. .fifo_size = 128,
  209. .tx_loadsz = 128,
  210. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  211. .flags = UART_CAP_FIFO,
  212. },
  213. [PORT_16654] = {
  214. .name = "ST16654",
  215. .fifo_size = 64,
  216. .tx_loadsz = 32,
  217. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
  218. UART_FCR_T_TRIG_10,
  219. .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
  220. },
  221. [PORT_16850] = {
  222. .name = "XR16850",
  223. .fifo_size = 128,
  224. .tx_loadsz = 128,
  225. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  226. .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
  227. },
  228. [PORT_RSA] = {
  229. .name = "RSA",
  230. .fifo_size = 2048,
  231. .tx_loadsz = 2048,
  232. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11,
  233. .flags = UART_CAP_FIFO,
  234. },
  235. [PORT_NS16550A] = {
  236. .name = "NS16550A",
  237. .fifo_size = 16,
  238. .tx_loadsz = 16,
  239. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  240. .flags = UART_CAP_FIFO | UART_NATSEMI,
  241. },
  242. [PORT_XSCALE] = {
  243. .name = "XScale",
  244. .fifo_size = 32,
  245. .tx_loadsz = 32,
  246. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  247. .flags = UART_CAP_FIFO | UART_CAP_UUE,
  248. },
  249. [PORT_RM9000] = {
  250. .name = "RM9000",
  251. .fifo_size = 16,
  252. .tx_loadsz = 16,
  253. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  254. .flags = UART_CAP_FIFO,
  255. },
  256. };
  257. #if defined (CONFIG_SERIAL_8250_AU1X00)
  258. /* Au1x00 UART hardware has a weird register layout */
  259. static const u8 au_io_in_map[] = {
  260. [UART_RX] = 0,
  261. [UART_IER] = 2,
  262. [UART_IIR] = 3,
  263. [UART_LCR] = 5,
  264. [UART_MCR] = 6,
  265. [UART_LSR] = 7,
  266. [UART_MSR] = 8,
  267. };
  268. static const u8 au_io_out_map[] = {
  269. [UART_TX] = 1,
  270. [UART_IER] = 2,
  271. [UART_FCR] = 4,
  272. [UART_LCR] = 5,
  273. [UART_MCR] = 6,
  274. };
  275. /* sane hardware needs no mapping */
  276. static inline int map_8250_in_reg(struct uart_8250_port *up, int offset)
  277. {
  278. if (up->port.iotype != UPIO_AU)
  279. return offset;
  280. return au_io_in_map[offset];
  281. }
  282. static inline int map_8250_out_reg(struct uart_8250_port *up, int offset)
  283. {
  284. if (up->port.iotype != UPIO_AU)
  285. return offset;
  286. return au_io_out_map[offset];
  287. }
  288. #elif defined(CONFIG_SERIAL_8250_RM9K)
  289. static const u8
  290. regmap_in[8] = {
  291. [UART_RX] = 0x00,
  292. [UART_IER] = 0x0c,
  293. [UART_IIR] = 0x14,
  294. [UART_LCR] = 0x1c,
  295. [UART_MCR] = 0x20,
  296. [UART_LSR] = 0x24,
  297. [UART_MSR] = 0x28,
  298. [UART_SCR] = 0x2c
  299. },
  300. regmap_out[8] = {
  301. [UART_TX] = 0x04,
  302. [UART_IER] = 0x0c,
  303. [UART_FCR] = 0x18,
  304. [UART_LCR] = 0x1c,
  305. [UART_MCR] = 0x20,
  306. [UART_LSR] = 0x24,
  307. [UART_MSR] = 0x28,
  308. [UART_SCR] = 0x2c
  309. };
  310. static inline int map_8250_in_reg(struct uart_8250_port *up, int offset)
  311. {
  312. if (up->port.iotype != UPIO_RM9000)
  313. return offset;
  314. return regmap_in[offset];
  315. }
  316. static inline int map_8250_out_reg(struct uart_8250_port *up, int offset)
  317. {
  318. if (up->port.iotype != UPIO_RM9000)
  319. return offset;
  320. return regmap_out[offset];
  321. }
  322. #else
  323. /* sane hardware needs no mapping */
  324. #define map_8250_in_reg(up, offset) (offset)
  325. #define map_8250_out_reg(up, offset) (offset)
  326. #endif
  327. static unsigned int serial_in(struct uart_8250_port *up, int offset)
  328. {
  329. unsigned int tmp;
  330. offset = map_8250_in_reg(up, offset) << up->port.regshift;
  331. switch (up->port.iotype) {
  332. case UPIO_HUB6:
  333. outb(up->port.hub6 - 1 + offset, up->port.iobase);
  334. return inb(up->port.iobase + 1);
  335. case UPIO_MEM:
  336. case UPIO_DWAPB:
  337. return readb(up->port.membase + offset);
  338. case UPIO_RM9000:
  339. case UPIO_MEM32:
  340. return readl(up->port.membase + offset);
  341. #ifdef CONFIG_SERIAL_8250_AU1X00
  342. case UPIO_AU:
  343. return __raw_readl(up->port.membase + offset);
  344. #endif
  345. case UPIO_TSI:
  346. if (offset == UART_IIR) {
  347. tmp = readl(up->port.membase + (UART_IIR & ~3));
  348. return (tmp >> 16) & 0xff; /* UART_IIR % 4 == 2 */
  349. } else
  350. return readb(up->port.membase + offset);
  351. default:
  352. return inb(up->port.iobase + offset);
  353. }
  354. }
  355. static void
  356. serial_out(struct uart_8250_port *up, int offset, int value)
  357. {
  358. /* Save the offset before it's remapped */
  359. int save_offset = offset;
  360. offset = map_8250_out_reg(up, offset) << up->port.regshift;
  361. switch (up->port.iotype) {
  362. case UPIO_HUB6:
  363. outb(up->port.hub6 - 1 + offset, up->port.iobase);
  364. outb(value, up->port.iobase + 1);
  365. break;
  366. case UPIO_MEM:
  367. writeb(value, up->port.membase + offset);
  368. break;
  369. case UPIO_RM9000:
  370. case UPIO_MEM32:
  371. writel(value, up->port.membase + offset);
  372. break;
  373. #ifdef CONFIG_SERIAL_8250_AU1X00
  374. case UPIO_AU:
  375. __raw_writel(value, up->port.membase + offset);
  376. break;
  377. #endif
  378. case UPIO_TSI:
  379. if (!((offset == UART_IER) && (value & UART_IER_UUE)))
  380. writeb(value, up->port.membase + offset);
  381. break;
  382. case UPIO_DWAPB:
  383. /* Save the LCR value so it can be re-written when a
  384. * Busy Detect interrupt occurs. */
  385. if (save_offset == UART_LCR)
  386. up->lcr = value;
  387. writeb(value, up->port.membase + offset);
  388. /* Read the IER to ensure any interrupt is cleared before
  389. * returning from ISR. */
  390. if (save_offset == UART_TX || save_offset == UART_IER)
  391. value = serial_in(up, UART_IER);
  392. break;
  393. default:
  394. outb(value, up->port.iobase + offset);
  395. }
  396. }
  397. static void
  398. serial_out_sync(struct uart_8250_port *up, int offset, int value)
  399. {
  400. switch (up->port.iotype) {
  401. case UPIO_MEM:
  402. case UPIO_MEM32:
  403. #ifdef CONFIG_SERIAL_8250_AU1X00
  404. case UPIO_AU:
  405. #endif
  406. case UPIO_DWAPB:
  407. serial_out(up, offset, value);
  408. serial_in(up, UART_LCR); /* safe, no side-effects */
  409. break;
  410. default:
  411. serial_out(up, offset, value);
  412. }
  413. }
  414. /*
  415. * We used to support using pause I/O for certain machines. We
  416. * haven't supported this for a while, but just in case it's badly
  417. * needed for certain old 386 machines, I've left these #define's
  418. * in....
  419. */
  420. #define serial_inp(up, offset) serial_in(up, offset)
  421. #define serial_outp(up, offset, value) serial_out(up, offset, value)
  422. /* Uart divisor latch read */
  423. static inline int _serial_dl_read(struct uart_8250_port *up)
  424. {
  425. return serial_inp(up, UART_DLL) | serial_inp(up, UART_DLM) << 8;
  426. }
  427. /* Uart divisor latch write */
  428. static inline void _serial_dl_write(struct uart_8250_port *up, int value)
  429. {
  430. serial_outp(up, UART_DLL, value & 0xff);
  431. serial_outp(up, UART_DLM, value >> 8 & 0xff);
  432. }
  433. #if defined(CONFIG_SERIAL_8250_AU1X00)
  434. /* Au1x00 haven't got a standard divisor latch */
  435. static int serial_dl_read(struct uart_8250_port *up)
  436. {
  437. if (up->port.iotype == UPIO_AU)
  438. return __raw_readl(up->port.membase + 0x28);
  439. else
  440. return _serial_dl_read(up);
  441. }
  442. static void serial_dl_write(struct uart_8250_port *up, int value)
  443. {
  444. if (up->port.iotype == UPIO_AU)
  445. __raw_writel(value, up->port.membase + 0x28);
  446. else
  447. _serial_dl_write(up, value);
  448. }
  449. #elif defined(CONFIG_SERIAL_8250_RM9K)
  450. static int serial_dl_read(struct uart_8250_port *up)
  451. {
  452. return (up->port.iotype == UPIO_RM9000) ?
  453. (((__raw_readl(up->port.membase + 0x10) << 8) |
  454. (__raw_readl(up->port.membase + 0x08) & 0xff)) & 0xffff) :
  455. _serial_dl_read(up);
  456. }
  457. static void serial_dl_write(struct uart_8250_port *up, int value)
  458. {
  459. if (up->port.iotype == UPIO_RM9000) {
  460. __raw_writel(value, up->port.membase + 0x08);
  461. __raw_writel(value >> 8, up->port.membase + 0x10);
  462. } else {
  463. _serial_dl_write(up, value);
  464. }
  465. }
  466. #else
  467. #define serial_dl_read(up) _serial_dl_read(up)
  468. #define serial_dl_write(up, value) _serial_dl_write(up, value)
  469. #endif
  470. /*
  471. * For the 16C950
  472. */
  473. static void serial_icr_write(struct uart_8250_port *up, int offset, int value)
  474. {
  475. serial_out(up, UART_SCR, offset);
  476. serial_out(up, UART_ICR, value);
  477. }
  478. static unsigned int serial_icr_read(struct uart_8250_port *up, int offset)
  479. {
  480. unsigned int value;
  481. serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
  482. serial_out(up, UART_SCR, offset);
  483. value = serial_in(up, UART_ICR);
  484. serial_icr_write(up, UART_ACR, up->acr);
  485. return value;
  486. }
  487. /*
  488. * FIFO support.
  489. */
  490. static void serial8250_clear_fifos(struct uart_8250_port *p)
  491. {
  492. if (p->capabilities & UART_CAP_FIFO) {
  493. serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO);
  494. serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO |
  495. UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
  496. serial_outp(p, UART_FCR, 0);
  497. }
  498. }
  499. /*
  500. * IER sleep support. UARTs which have EFRs need the "extended
  501. * capability" bit enabled. Note that on XR16C850s, we need to
  502. * reset LCR to write to IER.
  503. */
  504. static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
  505. {
  506. if (p->capabilities & UART_CAP_SLEEP) {
  507. if (p->capabilities & UART_CAP_EFR) {
  508. serial_outp(p, UART_LCR, 0xBF);
  509. serial_outp(p, UART_EFR, UART_EFR_ECB);
  510. serial_outp(p, UART_LCR, 0);
  511. }
  512. serial_outp(p, UART_IER, sleep ? UART_IERX_SLEEP : 0);
  513. if (p->capabilities & UART_CAP_EFR) {
  514. serial_outp(p, UART_LCR, 0xBF);
  515. serial_outp(p, UART_EFR, 0);
  516. serial_outp(p, UART_LCR, 0);
  517. }
  518. }
  519. }
  520. #ifdef CONFIG_SERIAL_8250_RSA
  521. /*
  522. * Attempts to turn on the RSA FIFO. Returns zero on failure.
  523. * We set the port uart clock rate if we succeed.
  524. */
  525. static int __enable_rsa(struct uart_8250_port *up)
  526. {
  527. unsigned char mode;
  528. int result;
  529. mode = serial_inp(up, UART_RSA_MSR);
  530. result = mode & UART_RSA_MSR_FIFO;
  531. if (!result) {
  532. serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
  533. mode = serial_inp(up, UART_RSA_MSR);
  534. result = mode & UART_RSA_MSR_FIFO;
  535. }
  536. if (result)
  537. up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
  538. return result;
  539. }
  540. static void enable_rsa(struct uart_8250_port *up)
  541. {
  542. if (up->port.type == PORT_RSA) {
  543. if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
  544. spin_lock_irq(&up->port.lock);
  545. __enable_rsa(up);
  546. spin_unlock_irq(&up->port.lock);
  547. }
  548. if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
  549. serial_outp(up, UART_RSA_FRR, 0);
  550. }
  551. }
  552. /*
  553. * Attempts to turn off the RSA FIFO. Returns zero on failure.
  554. * It is unknown why interrupts were disabled in here. However,
  555. * the caller is expected to preserve this behaviour by grabbing
  556. * the spinlock before calling this function.
  557. */
  558. static void disable_rsa(struct uart_8250_port *up)
  559. {
  560. unsigned char mode;
  561. int result;
  562. if (up->port.type == PORT_RSA &&
  563. up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) {
  564. spin_lock_irq(&up->port.lock);
  565. mode = serial_inp(up, UART_RSA_MSR);
  566. result = !(mode & UART_RSA_MSR_FIFO);
  567. if (!result) {
  568. serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
  569. mode = serial_inp(up, UART_RSA_MSR);
  570. result = !(mode & UART_RSA_MSR_FIFO);
  571. }
  572. if (result)
  573. up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
  574. spin_unlock_irq(&up->port.lock);
  575. }
  576. }
  577. #endif /* CONFIG_SERIAL_8250_RSA */
  578. /*
  579. * This is a quickie test to see how big the FIFO is.
  580. * It doesn't work at all the time, more's the pity.
  581. */
  582. static int size_fifo(struct uart_8250_port *up)
  583. {
  584. unsigned char old_fcr, old_mcr, old_lcr;
  585. unsigned short old_dl;
  586. int count;
  587. old_lcr = serial_inp(up, UART_LCR);
  588. serial_outp(up, UART_LCR, 0);
  589. old_fcr = serial_inp(up, UART_FCR);
  590. old_mcr = serial_inp(up, UART_MCR);
  591. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
  592. UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
  593. serial_outp(up, UART_MCR, UART_MCR_LOOP);
  594. serial_outp(up, UART_LCR, UART_LCR_DLAB);
  595. old_dl = serial_dl_read(up);
  596. serial_dl_write(up, 0x0001);
  597. serial_outp(up, UART_LCR, 0x03);
  598. for (count = 0; count < 256; count++)
  599. serial_outp(up, UART_TX, count);
  600. mdelay(20);/* FIXME - schedule_timeout */
  601. for (count = 0; (serial_inp(up, UART_LSR) & UART_LSR_DR) &&
  602. (count < 256); count++)
  603. serial_inp(up, UART_RX);
  604. serial_outp(up, UART_FCR, old_fcr);
  605. serial_outp(up, UART_MCR, old_mcr);
  606. serial_outp(up, UART_LCR, UART_LCR_DLAB);
  607. serial_dl_write(up, old_dl);
  608. serial_outp(up, UART_LCR, old_lcr);
  609. return count;
  610. }
  611. /*
  612. * Read UART ID using the divisor method - set DLL and DLM to zero
  613. * and the revision will be in DLL and device type in DLM. We
  614. * preserve the device state across this.
  615. */
  616. static unsigned int autoconfig_read_divisor_id(struct uart_8250_port *p)
  617. {
  618. unsigned char old_dll, old_dlm, old_lcr;
  619. unsigned int id;
  620. old_lcr = serial_inp(p, UART_LCR);
  621. serial_outp(p, UART_LCR, UART_LCR_DLAB);
  622. old_dll = serial_inp(p, UART_DLL);
  623. old_dlm = serial_inp(p, UART_DLM);
  624. serial_outp(p, UART_DLL, 0);
  625. serial_outp(p, UART_DLM, 0);
  626. id = serial_inp(p, UART_DLL) | serial_inp(p, UART_DLM) << 8;
  627. serial_outp(p, UART_DLL, old_dll);
  628. serial_outp(p, UART_DLM, old_dlm);
  629. serial_outp(p, UART_LCR, old_lcr);
  630. return id;
  631. }
  632. /*
  633. * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's.
  634. * When this function is called we know it is at least a StarTech
  635. * 16650 V2, but it might be one of several StarTech UARTs, or one of
  636. * its clones. (We treat the broken original StarTech 16650 V1 as a
  637. * 16550, and why not? Startech doesn't seem to even acknowledge its
  638. * existence.)
  639. *
  640. * What evil have men's minds wrought...
  641. */
  642. static void autoconfig_has_efr(struct uart_8250_port *up)
  643. {
  644. unsigned int id1, id2, id3, rev;
  645. /*
  646. * Everything with an EFR has SLEEP
  647. */
  648. up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
  649. /*
  650. * First we check to see if it's an Oxford Semiconductor UART.
  651. *
  652. * If we have to do this here because some non-National
  653. * Semiconductor clone chips lock up if you try writing to the
  654. * LSR register (which serial_icr_read does)
  655. */
  656. /*
  657. * Check for Oxford Semiconductor 16C950.
  658. *
  659. * EFR [4] must be set else this test fails.
  660. *
  661. * This shouldn't be necessary, but Mike Hudson (Exoray@isys.ca)
  662. * claims that it's needed for 952 dual UART's (which are not
  663. * recommended for new designs).
  664. */
  665. up->acr = 0;
  666. serial_out(up, UART_LCR, 0xBF);
  667. serial_out(up, UART_EFR, UART_EFR_ECB);
  668. serial_out(up, UART_LCR, 0x00);
  669. id1 = serial_icr_read(up, UART_ID1);
  670. id2 = serial_icr_read(up, UART_ID2);
  671. id3 = serial_icr_read(up, UART_ID3);
  672. rev = serial_icr_read(up, UART_REV);
  673. DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev);
  674. if (id1 == 0x16 && id2 == 0xC9 &&
  675. (id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) {
  676. up->port.type = PORT_16C950;
  677. /*
  678. * Enable work around for the Oxford Semiconductor 952 rev B
  679. * chip which causes it to seriously miscalculate baud rates
  680. * when DLL is 0.
  681. */
  682. if (id3 == 0x52 && rev == 0x01)
  683. up->bugs |= UART_BUG_QUOT;
  684. return;
  685. }
  686. /*
  687. * We check for a XR16C850 by setting DLL and DLM to 0, and then
  688. * reading back DLL and DLM. The chip type depends on the DLM
  689. * value read back:
  690. * 0x10 - XR16C850 and the DLL contains the chip revision.
  691. * 0x12 - XR16C2850.
  692. * 0x14 - XR16C854.
  693. */
  694. id1 = autoconfig_read_divisor_id(up);
  695. DEBUG_AUTOCONF("850id=%04x ", id1);
  696. id2 = id1 >> 8;
  697. if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) {
  698. up->port.type = PORT_16850;
  699. return;
  700. }
  701. /*
  702. * It wasn't an XR16C850.
  703. *
  704. * We distinguish between the '654 and the '650 by counting
  705. * how many bytes are in the FIFO. I'm using this for now,
  706. * since that's the technique that was sent to me in the
  707. * serial driver update, but I'm not convinced this works.
  708. * I've had problems doing this in the past. -TYT
  709. */
  710. if (size_fifo(up) == 64)
  711. up->port.type = PORT_16654;
  712. else
  713. up->port.type = PORT_16650V2;
  714. }
  715. /*
  716. * We detected a chip without a FIFO. Only two fall into
  717. * this category - the original 8250 and the 16450. The
  718. * 16450 has a scratch register (accessible with LCR=0)
  719. */
  720. static void autoconfig_8250(struct uart_8250_port *up)
  721. {
  722. unsigned char scratch, status1, status2;
  723. up->port.type = PORT_8250;
  724. scratch = serial_in(up, UART_SCR);
  725. serial_outp(up, UART_SCR, 0xa5);
  726. status1 = serial_in(up, UART_SCR);
  727. serial_outp(up, UART_SCR, 0x5a);
  728. status2 = serial_in(up, UART_SCR);
  729. serial_outp(up, UART_SCR, scratch);
  730. if (status1 == 0xa5 && status2 == 0x5a)
  731. up->port.type = PORT_16450;
  732. }
  733. static int broken_efr(struct uart_8250_port *up)
  734. {
  735. /*
  736. * Exar ST16C2550 "A2" devices incorrectly detect as
  737. * having an EFR, and report an ID of 0x0201. See
  738. * http://www.exar.com/info.php?pdf=dan180_oct2004.pdf
  739. */
  740. if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16)
  741. return 1;
  742. return 0;
  743. }
  744. /*
  745. * We know that the chip has FIFOs. Does it have an EFR? The
  746. * EFR is located in the same register position as the IIR and
  747. * we know the top two bits of the IIR are currently set. The
  748. * EFR should contain zero. Try to read the EFR.
  749. */
  750. static void autoconfig_16550a(struct uart_8250_port *up)
  751. {
  752. unsigned char status1, status2;
  753. unsigned int iersave;
  754. up->port.type = PORT_16550A;
  755. up->capabilities |= UART_CAP_FIFO;
  756. /*
  757. * Check for presence of the EFR when DLAB is set.
  758. * Only ST16C650V1 UARTs pass this test.
  759. */
  760. serial_outp(up, UART_LCR, UART_LCR_DLAB);
  761. if (serial_in(up, UART_EFR) == 0) {
  762. serial_outp(up, UART_EFR, 0xA8);
  763. if (serial_in(up, UART_EFR) != 0) {
  764. DEBUG_AUTOCONF("EFRv1 ");
  765. up->port.type = PORT_16650;
  766. up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
  767. } else {
  768. DEBUG_AUTOCONF("Motorola 8xxx DUART ");
  769. }
  770. serial_outp(up, UART_EFR, 0);
  771. return;
  772. }
  773. /*
  774. * Maybe it requires 0xbf to be written to the LCR.
  775. * (other ST16C650V2 UARTs, TI16C752A, etc)
  776. */
  777. serial_outp(up, UART_LCR, 0xBF);
  778. if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) {
  779. DEBUG_AUTOCONF("EFRv2 ");
  780. autoconfig_has_efr(up);
  781. return;
  782. }
  783. /*
  784. * Check for a National Semiconductor SuperIO chip.
  785. * Attempt to switch to bank 2, read the value of the LOOP bit
  786. * from EXCR1. Switch back to bank 0, change it in MCR. Then
  787. * switch back to bank 2, read it from EXCR1 again and check
  788. * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2
  789. */
  790. serial_outp(up, UART_LCR, 0);
  791. status1 = serial_in(up, UART_MCR);
  792. serial_outp(up, UART_LCR, 0xE0);
  793. status2 = serial_in(up, 0x02); /* EXCR1 */
  794. if (!((status2 ^ status1) & UART_MCR_LOOP)) {
  795. serial_outp(up, UART_LCR, 0);
  796. serial_outp(up, UART_MCR, status1 ^ UART_MCR_LOOP);
  797. serial_outp(up, UART_LCR, 0xE0);
  798. status2 = serial_in(up, 0x02); /* EXCR1 */
  799. serial_outp(up, UART_LCR, 0);
  800. serial_outp(up, UART_MCR, status1);
  801. if ((status2 ^ status1) & UART_MCR_LOOP) {
  802. unsigned short quot;
  803. serial_outp(up, UART_LCR, 0xE0);
  804. quot = serial_dl_read(up);
  805. quot <<= 3;
  806. status1 = serial_in(up, 0x04); /* EXCR2 */
  807. status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
  808. status1 |= 0x10; /* 1.625 divisor for baud_base --> 921600 */
  809. serial_outp(up, 0x04, status1);
  810. serial_dl_write(up, quot);
  811. serial_outp(up, UART_LCR, 0);
  812. up->port.uartclk = 921600*16;
  813. up->port.type = PORT_NS16550A;
  814. up->capabilities |= UART_NATSEMI;
  815. return;
  816. }
  817. }
  818. /*
  819. * No EFR. Try to detect a TI16750, which only sets bit 5 of
  820. * the IIR when 64 byte FIFO mode is enabled when DLAB is set.
  821. * Try setting it with and without DLAB set. Cheap clones
  822. * set bit 5 without DLAB set.
  823. */
  824. serial_outp(up, UART_LCR, 0);
  825. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
  826. status1 = serial_in(up, UART_IIR) >> 5;
  827. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
  828. serial_outp(up, UART_LCR, UART_LCR_DLAB);
  829. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
  830. status2 = serial_in(up, UART_IIR) >> 5;
  831. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
  832. serial_outp(up, UART_LCR, 0);
  833. DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2);
  834. if (status1 == 6 && status2 == 7) {
  835. up->port.type = PORT_16750;
  836. up->capabilities |= UART_CAP_AFE | UART_CAP_SLEEP;
  837. return;
  838. }
  839. /*
  840. * Try writing and reading the UART_IER_UUE bit (b6).
  841. * If it works, this is probably one of the Xscale platform's
  842. * internal UARTs.
  843. * We're going to explicitly set the UUE bit to 0 before
  844. * trying to write and read a 1 just to make sure it's not
  845. * already a 1 and maybe locked there before we even start start.
  846. */
  847. iersave = serial_in(up, UART_IER);
  848. serial_outp(up, UART_IER, iersave & ~UART_IER_UUE);
  849. if (!(serial_in(up, UART_IER) & UART_IER_UUE)) {
  850. /*
  851. * OK it's in a known zero state, try writing and reading
  852. * without disturbing the current state of the other bits.
  853. */
  854. serial_outp(up, UART_IER, iersave | UART_IER_UUE);
  855. if (serial_in(up, UART_IER) & UART_IER_UUE) {
  856. /*
  857. * It's an Xscale.
  858. * We'll leave the UART_IER_UUE bit set to 1 (enabled).
  859. */
  860. DEBUG_AUTOCONF("Xscale ");
  861. up->port.type = PORT_XSCALE;
  862. up->capabilities |= UART_CAP_UUE;
  863. return;
  864. }
  865. } else {
  866. /*
  867. * If we got here we couldn't force the IER_UUE bit to 0.
  868. * Log it and continue.
  869. */
  870. DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 ");
  871. }
  872. serial_outp(up, UART_IER, iersave);
  873. }
  874. /*
  875. * This routine is called by rs_init() to initialize a specific serial
  876. * port. It determines what type of UART chip this serial port is
  877. * using: 8250, 16450, 16550, 16550A. The important question is
  878. * whether or not this UART is a 16550A or not, since this will
  879. * determine whether or not we can use its FIFO features or not.
  880. */
  881. static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
  882. {
  883. unsigned char status1, scratch, scratch2, scratch3;
  884. unsigned char save_lcr, save_mcr;
  885. unsigned long flags;
  886. if (!up->port.iobase && !up->port.mapbase && !up->port.membase)
  887. return;
  888. DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04x, 0x%p): ",
  889. serial_index(&up->port), up->port.iobase, up->port.membase);
  890. /*
  891. * We really do need global IRQs disabled here - we're going to
  892. * be frobbing the chips IRQ enable register to see if it exists.
  893. */
  894. spin_lock_irqsave(&up->port.lock, flags);
  895. up->capabilities = 0;
  896. up->bugs = 0;
  897. if (!(up->port.flags & UPF_BUGGY_UART)) {
  898. /*
  899. * Do a simple existence test first; if we fail this,
  900. * there's no point trying anything else.
  901. *
  902. * 0x80 is used as a nonsense port to prevent against
  903. * false positives due to ISA bus float. The
  904. * assumption is that 0x80 is a non-existent port;
  905. * which should be safe since include/asm/io.h also
  906. * makes this assumption.
  907. *
  908. * Note: this is safe as long as MCR bit 4 is clear
  909. * and the device is in "PC" mode.
  910. */
  911. scratch = serial_inp(up, UART_IER);
  912. serial_outp(up, UART_IER, 0);
  913. #ifdef __i386__
  914. outb(0xff, 0x080);
  915. #endif
  916. /*
  917. * Mask out IER[7:4] bits for test as some UARTs (e.g. TL
  918. * 16C754B) allow only to modify them if an EFR bit is set.
  919. */
  920. scratch2 = serial_inp(up, UART_IER) & 0x0f;
  921. serial_outp(up, UART_IER, 0x0F);
  922. #ifdef __i386__
  923. outb(0, 0x080);
  924. #endif
  925. scratch3 = serial_inp(up, UART_IER) & 0x0f;
  926. serial_outp(up, UART_IER, scratch);
  927. if (scratch2 != 0 || scratch3 != 0x0F) {
  928. /*
  929. * We failed; there's nothing here
  930. */
  931. DEBUG_AUTOCONF("IER test failed (%02x, %02x) ",
  932. scratch2, scratch3);
  933. goto out;
  934. }
  935. }
  936. save_mcr = serial_in(up, UART_MCR);
  937. save_lcr = serial_in(up, UART_LCR);
  938. /*
  939. * Check to see if a UART is really there. Certain broken
  940. * internal modems based on the Rockwell chipset fail this
  941. * test, because they apparently don't implement the loopback
  942. * test mode. So this test is skipped on the COM 1 through
  943. * COM 4 ports. This *should* be safe, since no board
  944. * manufacturer would be stupid enough to design a board
  945. * that conflicts with COM 1-4 --- we hope!
  946. */
  947. if (!(up->port.flags & UPF_SKIP_TEST)) {
  948. serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A);
  949. status1 = serial_inp(up, UART_MSR) & 0xF0;
  950. serial_outp(up, UART_MCR, save_mcr);
  951. if (status1 != 0x90) {
  952. DEBUG_AUTOCONF("LOOP test failed (%02x) ",
  953. status1);
  954. goto out;
  955. }
  956. }
  957. /*
  958. * We're pretty sure there's a port here. Lets find out what
  959. * type of port it is. The IIR top two bits allows us to find
  960. * out if it's 8250 or 16450, 16550, 16550A or later. This
  961. * determines what we test for next.
  962. *
  963. * We also initialise the EFR (if any) to zero for later. The
  964. * EFR occupies the same register location as the FCR and IIR.
  965. */
  966. serial_outp(up, UART_LCR, 0xBF);
  967. serial_outp(up, UART_EFR, 0);
  968. serial_outp(up, UART_LCR, 0);
  969. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
  970. scratch = serial_in(up, UART_IIR) >> 6;
  971. DEBUG_AUTOCONF("iir=%d ", scratch);
  972. switch (scratch) {
  973. case 0:
  974. autoconfig_8250(up);
  975. break;
  976. case 1:
  977. up->port.type = PORT_UNKNOWN;
  978. break;
  979. case 2:
  980. up->port.type = PORT_16550;
  981. break;
  982. case 3:
  983. autoconfig_16550a(up);
  984. break;
  985. }
  986. #ifdef CONFIG_SERIAL_8250_RSA
  987. /*
  988. * Only probe for RSA ports if we got the region.
  989. */
  990. if (up->port.type == PORT_16550A && probeflags & PROBE_RSA) {
  991. int i;
  992. for (i = 0 ; i < probe_rsa_count; ++i) {
  993. if (probe_rsa[i] == up->port.iobase &&
  994. __enable_rsa(up)) {
  995. up->port.type = PORT_RSA;
  996. break;
  997. }
  998. }
  999. }
  1000. #endif
  1001. #ifdef CONFIG_SERIAL_8250_AU1X00
  1002. /* if access method is AU, it is a 16550 with a quirk */
  1003. if (up->port.type == PORT_16550A && up->port.iotype == UPIO_AU)
  1004. up->bugs |= UART_BUG_NOMSR;
  1005. #endif
  1006. serial_outp(up, UART_LCR, save_lcr);
  1007. if (up->capabilities != uart_config[up->port.type].flags) {
  1008. printk(KERN_WARNING
  1009. "ttyS%d: detected caps %08x should be %08x\n",
  1010. serial_index(&up->port), up->capabilities,
  1011. uart_config[up->port.type].flags);
  1012. }
  1013. up->port.fifosize = uart_config[up->port.type].fifo_size;
  1014. up->capabilities = uart_config[up->port.type].flags;
  1015. up->tx_loadsz = uart_config[up->port.type].tx_loadsz;
  1016. if (up->port.type == PORT_UNKNOWN)
  1017. goto out;
  1018. /*
  1019. * Reset the UART.
  1020. */
  1021. #ifdef CONFIG_SERIAL_8250_RSA
  1022. if (up->port.type == PORT_RSA)
  1023. serial_outp(up, UART_RSA_FRR, 0);
  1024. #endif
  1025. serial_outp(up, UART_MCR, save_mcr);
  1026. serial8250_clear_fifos(up);
  1027. serial_in(up, UART_RX);
  1028. if (up->capabilities & UART_CAP_UUE)
  1029. serial_outp(up, UART_IER, UART_IER_UUE);
  1030. else
  1031. serial_outp(up, UART_IER, 0);
  1032. out:
  1033. spin_unlock_irqrestore(&up->port.lock, flags);
  1034. DEBUG_AUTOCONF("type=%s\n", uart_config[up->port.type].name);
  1035. }
  1036. static void autoconfig_irq(struct uart_8250_port *up)
  1037. {
  1038. unsigned char save_mcr, save_ier;
  1039. unsigned char save_ICP = 0;
  1040. unsigned int ICP = 0;
  1041. unsigned long irqs;
  1042. int irq;
  1043. if (up->port.flags & UPF_FOURPORT) {
  1044. ICP = (up->port.iobase & 0xfe0) | 0x1f;
  1045. save_ICP = inb_p(ICP);
  1046. outb_p(0x80, ICP);
  1047. (void) inb_p(ICP);
  1048. }
  1049. /* forget possible initially masked and pending IRQ */
  1050. probe_irq_off(probe_irq_on());
  1051. save_mcr = serial_inp(up, UART_MCR);
  1052. save_ier = serial_inp(up, UART_IER);
  1053. serial_outp(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2);
  1054. irqs = probe_irq_on();
  1055. serial_outp(up, UART_MCR, 0);
  1056. udelay(10);
  1057. if (up->port.flags & UPF_FOURPORT) {
  1058. serial_outp(up, UART_MCR,
  1059. UART_MCR_DTR | UART_MCR_RTS);
  1060. } else {
  1061. serial_outp(up, UART_MCR,
  1062. UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
  1063. }
  1064. serial_outp(up, UART_IER, 0x0f); /* enable all intrs */
  1065. (void)serial_inp(up, UART_LSR);
  1066. (void)serial_inp(up, UART_RX);
  1067. (void)serial_inp(up, UART_IIR);
  1068. (void)serial_inp(up, UART_MSR);
  1069. serial_outp(up, UART_TX, 0xFF);
  1070. udelay(20);
  1071. irq = probe_irq_off(irqs);
  1072. serial_outp(up, UART_MCR, save_mcr);
  1073. serial_outp(up, UART_IER, save_ier);
  1074. if (up->port.flags & UPF_FOURPORT)
  1075. outb_p(save_ICP, ICP);
  1076. up->port.irq = (irq > 0) ? irq : 0;
  1077. }
  1078. static inline void __stop_tx(struct uart_8250_port *p)
  1079. {
  1080. if (p->ier & UART_IER_THRI) {
  1081. p->ier &= ~UART_IER_THRI;
  1082. serial_out(p, UART_IER, p->ier);
  1083. }
  1084. }
  1085. static void serial8250_stop_tx(struct uart_port *port)
  1086. {
  1087. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1088. __stop_tx(up);
  1089. /*
  1090. * We really want to stop the transmitter from sending.
  1091. */
  1092. if (up->port.type == PORT_16C950) {
  1093. up->acr |= UART_ACR_TXDIS;
  1094. serial_icr_write(up, UART_ACR, up->acr);
  1095. }
  1096. }
  1097. static void transmit_chars(struct uart_8250_port *up);
  1098. static void serial8250_start_tx(struct uart_port *port)
  1099. {
  1100. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1101. if (!(up->ier & UART_IER_THRI)) {
  1102. up->ier |= UART_IER_THRI;
  1103. serial_out(up, UART_IER, up->ier);
  1104. if (up->bugs & UART_BUG_TXEN) {
  1105. unsigned char lsr, iir;
  1106. lsr = serial_in(up, UART_LSR);
  1107. up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
  1108. iir = serial_in(up, UART_IIR) & 0x0f;
  1109. if ((up->port.type == PORT_RM9000) ?
  1110. (lsr & UART_LSR_THRE &&
  1111. (iir == UART_IIR_NO_INT || iir == UART_IIR_THRI)) :
  1112. (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT))
  1113. transmit_chars(up);
  1114. }
  1115. }
  1116. /*
  1117. * Re-enable the transmitter if we disabled it.
  1118. */
  1119. if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) {
  1120. up->acr &= ~UART_ACR_TXDIS;
  1121. serial_icr_write(up, UART_ACR, up->acr);
  1122. }
  1123. }
  1124. static void serial8250_stop_rx(struct uart_port *port)
  1125. {
  1126. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1127. up->ier &= ~UART_IER_RLSI;
  1128. up->port.read_status_mask &= ~UART_LSR_DR;
  1129. serial_out(up, UART_IER, up->ier);
  1130. }
  1131. static void serial8250_enable_ms(struct uart_port *port)
  1132. {
  1133. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1134. /* no MSR capabilities */
  1135. if (up->bugs & UART_BUG_NOMSR)
  1136. return;
  1137. up->ier |= UART_IER_MSI;
  1138. serial_out(up, UART_IER, up->ier);
  1139. }
  1140. static void
  1141. receive_chars(struct uart_8250_port *up, unsigned int *status)
  1142. {
  1143. struct tty_struct *tty = up->port.info->port.tty;
  1144. unsigned char ch, lsr = *status;
  1145. int max_count = 256;
  1146. char flag;
  1147. do {
  1148. if (likely(lsr & UART_LSR_DR))
  1149. ch = serial_inp(up, UART_RX);
  1150. else
  1151. /*
  1152. * Intel 82571 has a Serial Over Lan device that will
  1153. * set UART_LSR_BI without setting UART_LSR_DR when
  1154. * it receives a break. To avoid reading from the
  1155. * receive buffer without UART_LSR_DR bit set, we
  1156. * just force the read character to be 0
  1157. */
  1158. ch = 0;
  1159. flag = TTY_NORMAL;
  1160. up->port.icount.rx++;
  1161. lsr |= up->lsr_saved_flags;
  1162. up->lsr_saved_flags = 0;
  1163. if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) {
  1164. /*
  1165. * For statistics only
  1166. */
  1167. if (lsr & UART_LSR_BI) {
  1168. lsr &= ~(UART_LSR_FE | UART_LSR_PE);
  1169. up->port.icount.brk++;
  1170. /*
  1171. * We do the SysRQ and SAK checking
  1172. * here because otherwise the break
  1173. * may get masked by ignore_status_mask
  1174. * or read_status_mask.
  1175. */
  1176. if (uart_handle_break(&up->port))
  1177. goto ignore_char;
  1178. } else if (lsr & UART_LSR_PE)
  1179. up->port.icount.parity++;
  1180. else if (lsr & UART_LSR_FE)
  1181. up->port.icount.frame++;
  1182. if (lsr & UART_LSR_OE)
  1183. up->port.icount.overrun++;
  1184. /*
  1185. * Mask off conditions which should be ignored.
  1186. */
  1187. lsr &= up->port.read_status_mask;
  1188. if (lsr & UART_LSR_BI) {
  1189. DEBUG_INTR("handling break....");
  1190. flag = TTY_BREAK;
  1191. } else if (lsr & UART_LSR_PE)
  1192. flag = TTY_PARITY;
  1193. else if (lsr & UART_LSR_FE)
  1194. flag = TTY_FRAME;
  1195. }
  1196. if (uart_handle_sysrq_char(&up->port, ch))
  1197. goto ignore_char;
  1198. uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag);
  1199. ignore_char:
  1200. lsr = serial_inp(up, UART_LSR);
  1201. } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0));
  1202. spin_unlock(&up->port.lock);
  1203. tty_flip_buffer_push(tty);
  1204. spin_lock(&up->port.lock);
  1205. *status = lsr;
  1206. }
  1207. static void transmit_chars(struct uart_8250_port *up)
  1208. {
  1209. struct circ_buf *xmit = &up->port.info->xmit;
  1210. int count;
  1211. if (up->port.x_char) {
  1212. serial_outp(up, UART_TX, up->port.x_char);
  1213. up->port.icount.tx++;
  1214. up->port.x_char = 0;
  1215. return;
  1216. }
  1217. if (uart_tx_stopped(&up->port)) {
  1218. serial8250_stop_tx(&up->port);
  1219. return;
  1220. }
  1221. if (uart_circ_empty(xmit)) {
  1222. __stop_tx(up);
  1223. return;
  1224. }
  1225. count = up->tx_loadsz;
  1226. do {
  1227. serial_out(up, UART_TX, xmit->buf[xmit->tail]);
  1228. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  1229. up->port.icount.tx++;
  1230. if (uart_circ_empty(xmit))
  1231. break;
  1232. } while (--count > 0);
  1233. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  1234. uart_write_wakeup(&up->port);
  1235. DEBUG_INTR("THRE...");
  1236. if (uart_circ_empty(xmit))
  1237. __stop_tx(up);
  1238. }
  1239. static unsigned int check_modem_status(struct uart_8250_port *up)
  1240. {
  1241. unsigned int status = serial_in(up, UART_MSR);
  1242. status |= up->msr_saved_flags;
  1243. up->msr_saved_flags = 0;
  1244. if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI &&
  1245. up->port.info != NULL) {
  1246. if (status & UART_MSR_TERI)
  1247. up->port.icount.rng++;
  1248. if (status & UART_MSR_DDSR)
  1249. up->port.icount.dsr++;
  1250. if (status & UART_MSR_DDCD)
  1251. uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
  1252. if (status & UART_MSR_DCTS)
  1253. uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
  1254. wake_up_interruptible(&up->port.info->delta_msr_wait);
  1255. }
  1256. return status;
  1257. }
  1258. /*
  1259. * This handles the interrupt from one port.
  1260. */
  1261. static void serial8250_handle_port(struct uart_8250_port *up)
  1262. {
  1263. unsigned int status;
  1264. unsigned long flags;
  1265. spin_lock_irqsave(&up->port.lock, flags);
  1266. status = serial_inp(up, UART_LSR);
  1267. DEBUG_INTR("status = %x...", status);
  1268. if (status & (UART_LSR_DR | UART_LSR_BI))
  1269. receive_chars(up, &status);
  1270. check_modem_status(up);
  1271. if (status & UART_LSR_THRE)
  1272. transmit_chars(up);
  1273. spin_unlock_irqrestore(&up->port.lock, flags);
  1274. }
  1275. /*
  1276. * This is the serial driver's interrupt routine.
  1277. *
  1278. * Arjan thinks the old way was overly complex, so it got simplified.
  1279. * Alan disagrees, saying that need the complexity to handle the weird
  1280. * nature of ISA shared interrupts. (This is a special exception.)
  1281. *
  1282. * In order to handle ISA shared interrupts properly, we need to check
  1283. * that all ports have been serviced, and therefore the ISA interrupt
  1284. * line has been de-asserted.
  1285. *
  1286. * This means we need to loop through all ports. checking that they
  1287. * don't have an interrupt pending.
  1288. */
  1289. static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
  1290. {
  1291. struct irq_info *i = dev_id;
  1292. struct list_head *l, *end = NULL;
  1293. int pass_counter = 0, handled = 0;
  1294. DEBUG_INTR("serial8250_interrupt(%d)...", irq);
  1295. spin_lock(&i->lock);
  1296. l = i->head;
  1297. do {
  1298. struct uart_8250_port *up;
  1299. unsigned int iir;
  1300. up = list_entry(l, struct uart_8250_port, list);
  1301. iir = serial_in(up, UART_IIR);
  1302. if (!(iir & UART_IIR_NO_INT)) {
  1303. serial8250_handle_port(up);
  1304. handled = 1;
  1305. end = NULL;
  1306. } else if (up->port.iotype == UPIO_DWAPB &&
  1307. (iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
  1308. /* The DesignWare APB UART has an Busy Detect (0x07)
  1309. * interrupt meaning an LCR write attempt occured while the
  1310. * UART was busy. The interrupt must be cleared by reading
  1311. * the UART status register (USR) and the LCR re-written. */
  1312. unsigned int status;
  1313. status = *(volatile u32 *)up->port.private_data;
  1314. serial_out(up, UART_LCR, up->lcr);
  1315. handled = 1;
  1316. end = NULL;
  1317. } else if (end == NULL)
  1318. end = l;
  1319. l = l->next;
  1320. if (l == i->head && pass_counter++ > PASS_LIMIT) {
  1321. /* If we hit this, we're dead. */
  1322. printk(KERN_ERR "serial8250: too much work for "
  1323. "irq%d\n", irq);
  1324. break;
  1325. }
  1326. } while (l != end);
  1327. spin_unlock(&i->lock);
  1328. DEBUG_INTR("end.\n");
  1329. return IRQ_RETVAL(handled);
  1330. }
  1331. /*
  1332. * To support ISA shared interrupts, we need to have one interrupt
  1333. * handler that ensures that the IRQ line has been deasserted
  1334. * before returning. Failing to do this will result in the IRQ
  1335. * line being stuck active, and, since ISA irqs are edge triggered,
  1336. * no more IRQs will be seen.
  1337. */
  1338. static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
  1339. {
  1340. spin_lock_irq(&i->lock);
  1341. if (!list_empty(i->head)) {
  1342. if (i->head == &up->list)
  1343. i->head = i->head->next;
  1344. list_del(&up->list);
  1345. } else {
  1346. BUG_ON(i->head != &up->list);
  1347. i->head = NULL;
  1348. }
  1349. spin_unlock_irq(&i->lock);
  1350. /* List empty so throw away the hash node */
  1351. if (i->head == NULL) {
  1352. hlist_del(&i->node);
  1353. kfree(i);
  1354. }
  1355. }
  1356. static int serial_link_irq_chain(struct uart_8250_port *up)
  1357. {
  1358. struct hlist_head *h;
  1359. struct hlist_node *n;
  1360. struct irq_info *i;
  1361. int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? IRQF_SHARED : 0;
  1362. mutex_lock(&hash_mutex);
  1363. h = &irq_lists[up->port.irq % NR_IRQ_HASH];
  1364. hlist_for_each(n, h) {
  1365. i = hlist_entry(n, struct irq_info, node);
  1366. if (i->irq == up->port.irq)
  1367. break;
  1368. }
  1369. if (n == NULL) {
  1370. i = kzalloc(sizeof(struct irq_info), GFP_KERNEL);
  1371. if (i == NULL) {
  1372. mutex_unlock(&hash_mutex);
  1373. return -ENOMEM;
  1374. }
  1375. spin_lock_init(&i->lock);
  1376. i->irq = up->port.irq;
  1377. hlist_add_head(&i->node, h);
  1378. }
  1379. mutex_unlock(&hash_mutex);
  1380. spin_lock_irq(&i->lock);
  1381. if (i->head) {
  1382. list_add(&up->list, i->head);
  1383. spin_unlock_irq(&i->lock);
  1384. ret = 0;
  1385. } else {
  1386. INIT_LIST_HEAD(&up->list);
  1387. i->head = &up->list;
  1388. spin_unlock_irq(&i->lock);
  1389. ret = request_irq(up->port.irq, serial8250_interrupt,
  1390. irq_flags, "serial", i);
  1391. if (ret < 0)
  1392. serial_do_unlink(i, up);
  1393. }
  1394. return ret;
  1395. }
  1396. static void serial_unlink_irq_chain(struct uart_8250_port *up)
  1397. {
  1398. struct irq_info *i;
  1399. struct hlist_node *n;
  1400. struct hlist_head *h;
  1401. mutex_lock(&hash_mutex);
  1402. h = &irq_lists[up->port.irq % NR_IRQ_HASH];
  1403. hlist_for_each(n, h) {
  1404. i = hlist_entry(n, struct irq_info, node);
  1405. if (i->irq == up->port.irq)
  1406. break;
  1407. }
  1408. BUG_ON(n == NULL);
  1409. BUG_ON(i->head == NULL);
  1410. if (list_empty(i->head))
  1411. free_irq(up->port.irq, i);
  1412. serial_do_unlink(i, up);
  1413. mutex_unlock(&hash_mutex);
  1414. }
  1415. /* Base timer interval for polling */
  1416. static inline int poll_timeout(int timeout)
  1417. {
  1418. return timeout > 6 ? (timeout / 2 - 2) : 1;
  1419. }
  1420. /*
  1421. * This function is used to handle ports that do not have an
  1422. * interrupt. This doesn't work very well for 16450's, but gives
  1423. * barely passable results for a 16550A. (Although at the expense
  1424. * of much CPU overhead).
  1425. */
  1426. static void serial8250_timeout(unsigned long data)
  1427. {
  1428. struct uart_8250_port *up = (struct uart_8250_port *)data;
  1429. unsigned int iir;
  1430. iir = serial_in(up, UART_IIR);
  1431. if (!(iir & UART_IIR_NO_INT))
  1432. serial8250_handle_port(up);
  1433. mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout));
  1434. }
  1435. static void serial8250_backup_timeout(unsigned long data)
  1436. {
  1437. struct uart_8250_port *up = (struct uart_8250_port *)data;
  1438. unsigned int iir, ier = 0, lsr;
  1439. unsigned long flags;
  1440. /*
  1441. * Must disable interrupts or else we risk racing with the interrupt
  1442. * based handler.
  1443. */
  1444. if (is_real_interrupt(up->port.irq)) {
  1445. ier = serial_in(up, UART_IER);
  1446. serial_out(up, UART_IER, 0);
  1447. }
  1448. iir = serial_in(up, UART_IIR);
  1449. /*
  1450. * This should be a safe test for anyone who doesn't trust the
  1451. * IIR bits on their UART, but it's specifically designed for
  1452. * the "Diva" UART used on the management processor on many HP
  1453. * ia64 and parisc boxes.
  1454. */
  1455. spin_lock_irqsave(&up->port.lock, flags);
  1456. lsr = serial_in(up, UART_LSR);
  1457. up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
  1458. spin_unlock_irqrestore(&up->port.lock, flags);
  1459. if ((iir & UART_IIR_NO_INT) && (up->ier & UART_IER_THRI) &&
  1460. (!uart_circ_empty(&up->port.info->xmit) || up->port.x_char) &&
  1461. (lsr & UART_LSR_THRE)) {
  1462. iir &= ~(UART_IIR_ID | UART_IIR_NO_INT);
  1463. iir |= UART_IIR_THRI;
  1464. }
  1465. if (!(iir & UART_IIR_NO_INT))
  1466. serial8250_handle_port(up);
  1467. if (is_real_interrupt(up->port.irq))
  1468. serial_out(up, UART_IER, ier);
  1469. /* Standard timer interval plus 0.2s to keep the port running */
  1470. mod_timer(&up->timer,
  1471. jiffies + poll_timeout(up->port.timeout) + HZ / 5);
  1472. }
  1473. static unsigned int serial8250_tx_empty(struct uart_port *port)
  1474. {
  1475. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1476. unsigned long flags;
  1477. unsigned int lsr;
  1478. spin_lock_irqsave(&up->port.lock, flags);
  1479. lsr = serial_in(up, UART_LSR);
  1480. up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
  1481. spin_unlock_irqrestore(&up->port.lock, flags);
  1482. return lsr & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
  1483. }
  1484. static unsigned int serial8250_get_mctrl(struct uart_port *port)
  1485. {
  1486. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1487. unsigned int status;
  1488. unsigned int ret;
  1489. status = check_modem_status(up);
  1490. ret = 0;
  1491. if (status & UART_MSR_DCD)
  1492. ret |= TIOCM_CAR;
  1493. if (status & UART_MSR_RI)
  1494. ret |= TIOCM_RNG;
  1495. if (status & UART_MSR_DSR)
  1496. ret |= TIOCM_DSR;
  1497. if (status & UART_MSR_CTS)
  1498. ret |= TIOCM_CTS;
  1499. return ret;
  1500. }
  1501. static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
  1502. {
  1503. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1504. unsigned char mcr = 0;
  1505. if (mctrl & TIOCM_RTS)
  1506. mcr |= UART_MCR_RTS;
  1507. if (mctrl & TIOCM_DTR)
  1508. mcr |= UART_MCR_DTR;
  1509. if (mctrl & TIOCM_OUT1)
  1510. mcr |= UART_MCR_OUT1;
  1511. if (mctrl & TIOCM_OUT2)
  1512. mcr |= UART_MCR_OUT2;
  1513. if (mctrl & TIOCM_LOOP)
  1514. mcr |= UART_MCR_LOOP;
  1515. mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr;
  1516. serial_out(up, UART_MCR, mcr);
  1517. }
  1518. static void serial8250_break_ctl(struct uart_port *port, int break_state)
  1519. {
  1520. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1521. unsigned long flags;
  1522. spin_lock_irqsave(&up->port.lock, flags);
  1523. if (break_state == -1)
  1524. up->lcr |= UART_LCR_SBC;
  1525. else
  1526. up->lcr &= ~UART_LCR_SBC;
  1527. serial_out(up, UART_LCR, up->lcr);
  1528. spin_unlock_irqrestore(&up->port.lock, flags);
  1529. }
  1530. #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
  1531. /*
  1532. * Wait for transmitter & holding register to empty
  1533. */
  1534. static void wait_for_xmitr(struct uart_8250_port *up, int bits)
  1535. {
  1536. unsigned int status, tmout = 10000;
  1537. /* Wait up to 10ms for the character(s) to be sent. */
  1538. do {
  1539. status = serial_in(up, UART_LSR);
  1540. up->lsr_saved_flags |= status & LSR_SAVE_FLAGS;
  1541. if (--tmout == 0)
  1542. break;
  1543. udelay(1);
  1544. } while ((status & bits) != bits);
  1545. /* Wait up to 1s for flow control if necessary */
  1546. if (up->port.flags & UPF_CONS_FLOW) {
  1547. unsigned int tmout;
  1548. for (tmout = 1000000; tmout; tmout--) {
  1549. unsigned int msr = serial_in(up, UART_MSR);
  1550. up->msr_saved_flags |= msr & MSR_SAVE_FLAGS;
  1551. if (msr & UART_MSR_CTS)
  1552. break;
  1553. udelay(1);
  1554. touch_nmi_watchdog();
  1555. }
  1556. }
  1557. }
  1558. #ifdef CONFIG_CONSOLE_POLL
  1559. /*
  1560. * Console polling routines for writing and reading from the uart while
  1561. * in an interrupt or debug context.
  1562. */
  1563. static int serial8250_get_poll_char(struct uart_port *port)
  1564. {
  1565. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1566. unsigned char lsr = serial_inp(up, UART_LSR);
  1567. while (!(lsr & UART_LSR_DR))
  1568. lsr = serial_inp(up, UART_LSR);
  1569. return serial_inp(up, UART_RX);
  1570. }
  1571. static void serial8250_put_poll_char(struct uart_port *port,
  1572. unsigned char c)
  1573. {
  1574. unsigned int ier;
  1575. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1576. /*
  1577. * First save the IER then disable the interrupts
  1578. */
  1579. ier = serial_in(up, UART_IER);
  1580. if (up->capabilities & UART_CAP_UUE)
  1581. serial_out(up, UART_IER, UART_IER_UUE);
  1582. else
  1583. serial_out(up, UART_IER, 0);
  1584. wait_for_xmitr(up, BOTH_EMPTY);
  1585. /*
  1586. * Send the character out.
  1587. * If a LF, also do CR...
  1588. */
  1589. serial_out(up, UART_TX, c);
  1590. if (c == 10) {
  1591. wait_for_xmitr(up, BOTH_EMPTY);
  1592. serial_out(up, UART_TX, 13);
  1593. }
  1594. /*
  1595. * Finally, wait for transmitter to become empty
  1596. * and restore the IER
  1597. */
  1598. wait_for_xmitr(up, BOTH_EMPTY);
  1599. serial_out(up, UART_IER, ier);
  1600. }
  1601. #endif /* CONFIG_CONSOLE_POLL */
  1602. static int serial8250_startup(struct uart_port *port)
  1603. {
  1604. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1605. unsigned long flags;
  1606. unsigned char lsr, iir;
  1607. int retval;
  1608. up->capabilities = uart_config[up->port.type].flags;
  1609. up->mcr = 0;
  1610. if (up->port.type == PORT_16C950) {
  1611. /* Wake up and initialize UART */
  1612. up->acr = 0;
  1613. serial_outp(up, UART_LCR, 0xBF);
  1614. serial_outp(up, UART_EFR, UART_EFR_ECB);
  1615. serial_outp(up, UART_IER, 0);
  1616. serial_outp(up, UART_LCR, 0);
  1617. serial_icr_write(up, UART_CSR, 0); /* Reset the UART */
  1618. serial_outp(up, UART_LCR, 0xBF);
  1619. serial_outp(up, UART_EFR, UART_EFR_ECB);
  1620. serial_outp(up, UART_LCR, 0);
  1621. }
  1622. #ifdef CONFIG_SERIAL_8250_RSA
  1623. /*
  1624. * If this is an RSA port, see if we can kick it up to the
  1625. * higher speed clock.
  1626. */
  1627. enable_rsa(up);
  1628. #endif
  1629. /*
  1630. * Clear the FIFO buffers and disable them.
  1631. * (they will be reenabled in set_termios())
  1632. */
  1633. serial8250_clear_fifos(up);
  1634. /*
  1635. * Clear the interrupt registers.
  1636. */
  1637. (void) serial_inp(up, UART_LSR);
  1638. (void) serial_inp(up, UART_RX);
  1639. (void) serial_inp(up, UART_IIR);
  1640. (void) serial_inp(up, UART_MSR);
  1641. /*
  1642. * At this point, there's no way the LSR could still be 0xff;
  1643. * if it is, then bail out, because there's likely no UART
  1644. * here.
  1645. */
  1646. if (!(up->port.flags & UPF_BUGGY_UART) &&
  1647. (serial_inp(up, UART_LSR) == 0xff)) {
  1648. printk(KERN_INFO "ttyS%d: LSR safety check engaged!\n",
  1649. serial_index(&up->port));
  1650. return -ENODEV;
  1651. }
  1652. /*
  1653. * For a XR16C850, we need to set the trigger levels
  1654. */
  1655. if (up->port.type == PORT_16850) {
  1656. unsigned char fctr;
  1657. serial_outp(up, UART_LCR, 0xbf);
  1658. fctr = serial_inp(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX);
  1659. serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_RX);
  1660. serial_outp(up, UART_TRG, UART_TRG_96);
  1661. serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_TX);
  1662. serial_outp(up, UART_TRG, UART_TRG_96);
  1663. serial_outp(up, UART_LCR, 0);
  1664. }
  1665. if (is_real_interrupt(up->port.irq)) {
  1666. unsigned char iir1;
  1667. /*
  1668. * Test for UARTs that do not reassert THRE when the
  1669. * transmitter is idle and the interrupt has already
  1670. * been cleared. Real 16550s should always reassert
  1671. * this interrupt whenever the transmitter is idle and
  1672. * the interrupt is enabled. Delays are necessary to
  1673. * allow register changes to become visible.
  1674. */
  1675. spin_lock_irqsave(&up->port.lock, flags);
  1676. if (up->port.flags & UPF_SHARE_IRQ)
  1677. disable_irq_nosync(up->port.irq);
  1678. wait_for_xmitr(up, UART_LSR_THRE);
  1679. serial_out_sync(up, UART_IER, UART_IER_THRI);
  1680. udelay(1); /* allow THRE to set */
  1681. iir1 = serial_in(up, UART_IIR);
  1682. serial_out(up, UART_IER, 0);
  1683. serial_out_sync(up, UART_IER, UART_IER_THRI);
  1684. udelay(1); /* allow a working UART time to re-assert THRE */
  1685. iir = serial_in(up, UART_IIR);
  1686. serial_out(up, UART_IER, 0);
  1687. if (up->port.flags & UPF_SHARE_IRQ)
  1688. enable_irq(up->port.irq);
  1689. spin_unlock_irqrestore(&up->port.lock, flags);
  1690. /*
  1691. * If the interrupt is not reasserted, setup a timer to
  1692. * kick the UART on a regular basis.
  1693. */
  1694. if (!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) {
  1695. up->bugs |= UART_BUG_THRE;
  1696. pr_debug("ttyS%d - using backup timer\n",
  1697. serial_index(port));
  1698. }
  1699. }
  1700. /*
  1701. * The above check will only give an accurate result the first time
  1702. * the port is opened so this value needs to be preserved.
  1703. */
  1704. if (up->bugs & UART_BUG_THRE) {
  1705. up->timer.function = serial8250_backup_timeout;
  1706. up->timer.data = (unsigned long)up;
  1707. mod_timer(&up->timer, jiffies +
  1708. poll_timeout(up->port.timeout) + HZ / 5);
  1709. }
  1710. /*
  1711. * If the "interrupt" for this port doesn't correspond with any
  1712. * hardware interrupt, we use a timer-based system. The original
  1713. * driver used to do this with IRQ0.
  1714. */
  1715. if (!is_real_interrupt(up->port.irq)) {
  1716. up->timer.data = (unsigned long)up;
  1717. mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout));
  1718. } else {
  1719. retval = serial_link_irq_chain(up);
  1720. if (retval)
  1721. return retval;
  1722. }
  1723. /*
  1724. * Now, initialize the UART
  1725. */
  1726. serial_outp(up, UART_LCR, UART_LCR_WLEN8);
  1727. spin_lock_irqsave(&up->port.lock, flags);
  1728. if (up->port.flags & UPF_FOURPORT) {
  1729. if (!is_real_interrupt(up->port.irq))
  1730. up->port.mctrl |= TIOCM_OUT1;
  1731. } else
  1732. /*
  1733. * Most PC uarts need OUT2 raised to enable interrupts.
  1734. */
  1735. if (is_real_interrupt(up->port.irq))
  1736. up->port.mctrl |= TIOCM_OUT2;
  1737. serial8250_set_mctrl(&up->port, up->port.mctrl);
  1738. /*
  1739. * Do a quick test to see if we receive an
  1740. * interrupt when we enable the TX irq.
  1741. */
  1742. serial_outp(up, UART_IER, UART_IER_THRI);
  1743. lsr = serial_in(up, UART_LSR);
  1744. iir = serial_in(up, UART_IIR);
  1745. serial_outp(up, UART_IER, 0);
  1746. if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) {
  1747. if (!(up->bugs & UART_BUG_TXEN)) {
  1748. up->bugs |= UART_BUG_TXEN;
  1749. pr_debug("ttyS%d - enabling bad tx status workarounds\n",
  1750. serial_index(port));
  1751. }
  1752. } else {
  1753. up->bugs &= ~UART_BUG_TXEN;
  1754. }
  1755. spin_unlock_irqrestore(&up->port.lock, flags);
  1756. /*
  1757. * Clear the interrupt registers again for luck, and clear the
  1758. * saved flags to avoid getting false values from polling
  1759. * routines or the previous session.
  1760. */
  1761. serial_inp(up, UART_LSR);
  1762. serial_inp(up, UART_RX);
  1763. serial_inp(up, UART_IIR);
  1764. serial_inp(up, UART_MSR);
  1765. up->lsr_saved_flags = 0;
  1766. up->msr_saved_flags = 0;
  1767. /*
  1768. * Finally, enable interrupts. Note: Modem status interrupts
  1769. * are set via set_termios(), which will be occurring imminently
  1770. * anyway, so we don't enable them here.
  1771. */
  1772. up->ier = UART_IER_RLSI | UART_IER_RDI;
  1773. serial_outp(up, UART_IER, up->ier);
  1774. if (up->port.flags & UPF_FOURPORT) {
  1775. unsigned int icp;
  1776. /*
  1777. * Enable interrupts on the AST Fourport board
  1778. */
  1779. icp = (up->port.iobase & 0xfe0) | 0x01f;
  1780. outb_p(0x80, icp);
  1781. (void) inb_p(icp);
  1782. }
  1783. return 0;
  1784. }
  1785. static void serial8250_shutdown(struct uart_port *port)
  1786. {
  1787. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1788. unsigned long flags;
  1789. /*
  1790. * Disable interrupts from this port
  1791. */
  1792. up->ier = 0;
  1793. serial_outp(up, UART_IER, 0);
  1794. spin_lock_irqsave(&up->port.lock, flags);
  1795. if (up->port.flags & UPF_FOURPORT) {
  1796. /* reset interrupts on the AST Fourport board */
  1797. inb((up->port.iobase & 0xfe0) | 0x1f);
  1798. up->port.mctrl |= TIOCM_OUT1;
  1799. } else
  1800. up->port.mctrl &= ~TIOCM_OUT2;
  1801. serial8250_set_mctrl(&up->port, up->port.mctrl);
  1802. spin_unlock_irqrestore(&up->port.lock, flags);
  1803. /*
  1804. * Disable break condition and FIFOs
  1805. */
  1806. serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC);
  1807. serial8250_clear_fifos(up);
  1808. #ifdef CONFIG_SERIAL_8250_RSA
  1809. /*
  1810. * Reset the RSA board back to 115kbps compat mode.
  1811. */
  1812. disable_rsa(up);
  1813. #endif
  1814. /*
  1815. * Read data port to reset things, and then unlink from
  1816. * the IRQ chain.
  1817. */
  1818. (void) serial_in(up, UART_RX);
  1819. del_timer_sync(&up->timer);
  1820. up->timer.function = serial8250_timeout;
  1821. if (is_real_interrupt(up->port.irq))
  1822. serial_unlink_irq_chain(up);
  1823. }
  1824. static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud)
  1825. {
  1826. unsigned int quot;
  1827. /*
  1828. * Handle magic divisors for baud rates above baud_base on
  1829. * SMSC SuperIO chips.
  1830. */
  1831. if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
  1832. baud == (port->uartclk/4))
  1833. quot = 0x8001;
  1834. else if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
  1835. baud == (port->uartclk/8))
  1836. quot = 0x8002;
  1837. else
  1838. quot = uart_get_divisor(port, baud);
  1839. return quot;
  1840. }
  1841. static void
  1842. serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
  1843. struct ktermios *old)
  1844. {
  1845. struct uart_8250_port *up = (struct uart_8250_port *)port;
  1846. unsigned char cval, fcr = 0;
  1847. unsigned long flags;
  1848. unsigned int baud, quot;
  1849. switch (termios->c_cflag & CSIZE) {
  1850. case CS5:
  1851. cval = UART_LCR_WLEN5;
  1852. break;
  1853. case CS6:
  1854. cval = UART_LCR_WLEN6;
  1855. break;
  1856. case CS7:
  1857. cval = UART_LCR_WLEN7;
  1858. break;
  1859. default:
  1860. case CS8:
  1861. cval = UART_LCR_WLEN8;
  1862. break;
  1863. }
  1864. if (termios->c_cflag & CSTOPB)
  1865. cval |= UART_LCR_STOP;
  1866. if (termios->c_cflag & PARENB)
  1867. cval |= UART_LCR_PARITY;
  1868. if (!(termios->c_cflag & PARODD))
  1869. cval |= UART_LCR_EPAR;
  1870. #ifdef CMSPAR
  1871. if (termios->c_cflag & CMSPAR)
  1872. cval |= UART_LCR_SPAR;
  1873. #endif
  1874. /*
  1875. * Ask the core to calculate the divisor for us.
  1876. */
  1877. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
  1878. quot = serial8250_get_divisor(port, baud);
  1879. /*
  1880. * Oxford Semi 952 rev B workaround
  1881. */
  1882. if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0)
  1883. quot++;
  1884. if (up->capabilities & UART_CAP_FIFO && up->port.fifosize > 1) {
  1885. if (baud < 2400)
  1886. fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
  1887. else
  1888. fcr = uart_config[up->port.type].fcr;
  1889. }
  1890. /*
  1891. * MCR-based auto flow control. When AFE is enabled, RTS will be
  1892. * deasserted when the receive FIFO contains more characters than
  1893. * the trigger, or the MCR RTS bit is cleared. In the case where
  1894. * the remote UART is not using CTS auto flow control, we must
  1895. * have sufficient FIFO entries for the latency of the remote
  1896. * UART to respond. IOW, at least 32 bytes of FIFO.
  1897. */
  1898. if (up->capabilities & UART_CAP_AFE && up->port.fifosize >= 32) {
  1899. up->mcr &= ~UART_MCR_AFE;
  1900. if (termios->c_cflag & CRTSCTS)
  1901. up->mcr |= UART_MCR_AFE;
  1902. }
  1903. /*
  1904. * Ok, we're now changing the port state. Do it with
  1905. * interrupts disabled.
  1906. */
  1907. spin_lock_irqsave(&up->port.lock, flags);
  1908. /*
  1909. * Update the per-port timeout.
  1910. */
  1911. uart_update_timeout(port, termios->c_cflag, baud);
  1912. up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
  1913. if (termios->c_iflag & INPCK)
  1914. up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
  1915. if (termios->c_iflag & (BRKINT | PARMRK))
  1916. up->port.read_status_mask |= UART_LSR_BI;
  1917. /*
  1918. * Characteres to ignore
  1919. */
  1920. up->port.ignore_status_mask = 0;
  1921. if (termios->c_iflag & IGNPAR)
  1922. up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
  1923. if (termios->c_iflag & IGNBRK) {
  1924. up->port.ignore_status_mask |= UART_LSR_BI;
  1925. /*
  1926. * If we're ignoring parity and break indicators,
  1927. * ignore overruns too (for real raw support).
  1928. */
  1929. if (termios->c_iflag & IGNPAR)
  1930. up->port.ignore_status_mask |= UART_LSR_OE;
  1931. }
  1932. /*
  1933. * ignore all characters if CREAD is not set
  1934. */
  1935. if ((termios->c_cflag & CREAD) == 0)
  1936. up->port.ignore_status_mask |= UART_LSR_DR;
  1937. /*
  1938. * CTS flow control flag and modem status interrupts
  1939. */
  1940. up->ier &= ~UART_IER_MSI;
  1941. if (!(up->bugs & UART_BUG_NOMSR) &&
  1942. UART_ENABLE_MS(&up->port, termios->c_cflag))
  1943. up->ier |= UART_IER_MSI;
  1944. if (up->capabilities & UART_CAP_UUE)
  1945. up->ier |= UART_IER_UUE | UART_IER_RTOIE;
  1946. serial_out(up, UART_IER, up->ier);
  1947. if (up->capabilities & UART_CAP_EFR) {
  1948. unsigned char efr = 0;
  1949. /*
  1950. * TI16C752/Startech hardware flow control. FIXME:
  1951. * - TI16C752 requires control thresholds to be set.
  1952. * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
  1953. */
  1954. if (termios->c_cflag & CRTSCTS)
  1955. efr |= UART_EFR_CTS;
  1956. serial_outp(up, UART_LCR, 0xBF);
  1957. serial_outp(up, UART_EFR, efr);
  1958. }
  1959. #ifdef CONFIG_ARCH_OMAP
  1960. /* Workaround to enable 115200 baud on OMAP1510 internal ports */
  1961. if (cpu_is_omap1510() && is_omap_port(up)) {
  1962. if (baud == 115200) {
  1963. quot = 1;
  1964. serial_out(up, UART_OMAP_OSC_12M_SEL, 1);
  1965. } else
  1966. serial_out(up, UART_OMAP_OSC_12M_SEL, 0);
  1967. }
  1968. #endif
  1969. if (up->capabilities & UART_NATSEMI) {
  1970. /* Switch to bank 2 not bank 1, to avoid resetting EXCR2 */
  1971. serial_outp(up, UART_LCR, 0xe0);
  1972. } else {
  1973. serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
  1974. }
  1975. serial_dl_write(up, quot);
  1976. /*
  1977. * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR
  1978. * is written without DLAB set, this mode will be disabled.
  1979. */
  1980. if (up->port.type == PORT_16750)
  1981. serial_outp(up, UART_FCR, fcr);
  1982. serial_outp(up, UART_LCR, cval); /* reset DLAB */
  1983. up->lcr = cval; /* Save LCR */
  1984. if (up->port.type != PORT_16750) {
  1985. if (fcr & UART_FCR_ENABLE_FIFO) {
  1986. /* emulated UARTs (Lucent Venus 167x) need two steps */
  1987. serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
  1988. }
  1989. serial_outp(up, UART_FCR, fcr); /* set fcr */
  1990. }
  1991. serial8250_set_mctrl(&up->port, up->port.mctrl);
  1992. spin_unlock_irqrestore(&up->port.lock, flags);
  1993. /* Don't rewrite B0 */
  1994. if (tty_termios_baud_rate(termios))
  1995. tty_termios_encode_baud_rate(termios, baud, baud);
  1996. }
  1997. static void
  1998. serial8250_pm(struct uart_port *port, unsigned int state,
  1999. unsigned int oldstate)
  2000. {
  2001. struct uart_8250_port *p = (struct uart_8250_port *)port;
  2002. serial8250_set_sleep(p, state != 0);
  2003. if (p->pm)
  2004. p->pm(port, state, oldstate);
  2005. }
  2006. static unsigned int serial8250_port_size(struct uart_8250_port *pt)
  2007. {
  2008. if (pt->port.iotype == UPIO_AU)
  2009. return 0x100000;
  2010. #ifdef CONFIG_ARCH_OMAP
  2011. if (is_omap_port(pt))
  2012. return 0x16 << pt->port.regshift;
  2013. #endif
  2014. return 8 << pt->port.regshift;
  2015. }
  2016. /*
  2017. * Resource handling.
  2018. */
  2019. static int serial8250_request_std_resource(struct uart_8250_port *up)
  2020. {
  2021. unsigned int size = serial8250_port_size(up);
  2022. int ret = 0;
  2023. switch (up->port.iotype) {
  2024. case UPIO_AU:
  2025. case UPIO_TSI:
  2026. case UPIO_MEM32:
  2027. case UPIO_MEM:
  2028. case UPIO_DWAPB:
  2029. if (!up->port.mapbase)
  2030. break;
  2031. if (!request_mem_region(up->port.mapbase, size, "serial")) {
  2032. ret = -EBUSY;
  2033. break;
  2034. }
  2035. if (up->port.flags & UPF_IOREMAP) {
  2036. up->port.membase = ioremap_nocache(up->port.mapbase,
  2037. size);
  2038. if (!up->port.membase) {
  2039. release_mem_region(up->port.mapbase, size);
  2040. ret = -ENOMEM;
  2041. }
  2042. }
  2043. break;
  2044. case UPIO_HUB6:
  2045. case UPIO_PORT:
  2046. if (!request_region(up->port.iobase, size, "serial"))
  2047. ret = -EBUSY;
  2048. break;
  2049. }
  2050. return ret;
  2051. }
  2052. static void serial8250_release_std_resource(struct uart_8250_port *up)
  2053. {
  2054. unsigned int size = serial8250_port_size(up);
  2055. switch (up->port.iotype) {
  2056. case UPIO_AU:
  2057. case UPIO_TSI:
  2058. case UPIO_MEM32:
  2059. case UPIO_MEM:
  2060. case UPIO_DWAPB:
  2061. if (!up->port.mapbase)
  2062. break;
  2063. if (up->port.flags & UPF_IOREMAP) {
  2064. iounmap(up->port.membase);
  2065. up->port.membase = NULL;
  2066. }
  2067. release_mem_region(up->port.mapbase, size);
  2068. break;
  2069. case UPIO_HUB6:
  2070. case UPIO_PORT:
  2071. release_region(up->port.iobase, size);
  2072. break;
  2073. }
  2074. }
  2075. static int serial8250_request_rsa_resource(struct uart_8250_port *up)
  2076. {
  2077. unsigned long start = UART_RSA_BASE << up->port.regshift;
  2078. unsigned int size = 8 << up->port.regshift;
  2079. int ret = -EINVAL;
  2080. switch (up->port.iotype) {
  2081. case UPIO_HUB6:
  2082. case UPIO_PORT:
  2083. start += up->port.iobase;
  2084. if (request_region(start, size, "serial-rsa"))
  2085. ret = 0;
  2086. else
  2087. ret = -EBUSY;
  2088. break;
  2089. }
  2090. return ret;
  2091. }
  2092. static void serial8250_release_rsa_resource(struct uart_8250_port *up)
  2093. {
  2094. unsigned long offset = UART_RSA_BASE << up->port.regshift;
  2095. unsigned int size = 8 << up->port.regshift;
  2096. switch (up->port.iotype) {
  2097. case UPIO_HUB6:
  2098. case UPIO_PORT:
  2099. release_region(up->port.iobase + offset, size);
  2100. break;
  2101. }
  2102. }
  2103. static void serial8250_release_port(struct uart_port *port)
  2104. {
  2105. struct uart_8250_port *up = (struct uart_8250_port *)port;
  2106. serial8250_release_std_resource(up);
  2107. if (up->port.type == PORT_RSA)
  2108. serial8250_release_rsa_resource(up);
  2109. }
  2110. static int serial8250_request_port(struct uart_port *port)
  2111. {
  2112. struct uart_8250_port *up = (struct uart_8250_port *)port;
  2113. int ret = 0;
  2114. ret = serial8250_request_std_resource(up);
  2115. if (ret == 0 && up->port.type == PORT_RSA) {
  2116. ret = serial8250_request_rsa_resource(up);
  2117. if (ret < 0)
  2118. serial8250_release_std_resource(up);
  2119. }
  2120. return ret;
  2121. }
  2122. static void serial8250_config_port(struct uart_port *port, int flags)
  2123. {
  2124. struct uart_8250_port *up = (struct uart_8250_port *)port;
  2125. int probeflags = PROBE_ANY;
  2126. int ret;
  2127. /*
  2128. * Find the region that we can probe for. This in turn
  2129. * tells us whether we can probe for the type of port.
  2130. */
  2131. ret = serial8250_request_std_resource(up);
  2132. if (ret < 0)
  2133. return;
  2134. ret = serial8250_request_rsa_resource(up);
  2135. if (ret < 0)
  2136. probeflags &= ~PROBE_RSA;
  2137. if (flags & UART_CONFIG_TYPE)
  2138. autoconfig(up, probeflags);
  2139. if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ)
  2140. autoconfig_irq(up);
  2141. if (up->port.type != PORT_RSA && probeflags & PROBE_RSA)
  2142. serial8250_release_rsa_resource(up);
  2143. if (up->port.type == PORT_UNKNOWN)
  2144. serial8250_release_std_resource(up);
  2145. }
  2146. static int
  2147. serial8250_verify_port(struct uart_port *port, struct serial_struct *ser)
  2148. {
  2149. if (ser->irq >= nr_irqs || ser->irq < 0 ||
  2150. ser->baud_base < 9600 || ser->type < PORT_UNKNOWN ||
  2151. ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS ||
  2152. ser->type == PORT_STARTECH)
  2153. return -EINVAL;
  2154. return 0;
  2155. }
  2156. static const char *
  2157. serial8250_type(struct uart_port *port)
  2158. {
  2159. int type = port->type;
  2160. if (type >= ARRAY_SIZE(uart_config))
  2161. type = 0;
  2162. return uart_config[type].name;
  2163. }
  2164. static struct uart_ops serial8250_pops = {
  2165. .tx_empty = serial8250_tx_empty,
  2166. .set_mctrl = serial8250_set_mctrl,
  2167. .get_mctrl = serial8250_get_mctrl,
  2168. .stop_tx = serial8250_stop_tx,
  2169. .start_tx = serial8250_start_tx,
  2170. .stop_rx = serial8250_stop_rx,
  2171. .enable_ms = serial8250_enable_ms,
  2172. .break_ctl = serial8250_break_ctl,
  2173. .startup = serial8250_startup,
  2174. .shutdown = serial8250_shutdown,
  2175. .set_termios = serial8250_set_termios,
  2176. .pm = serial8250_pm,
  2177. .type = serial8250_type,
  2178. .release_port = serial8250_release_port,
  2179. .request_port = serial8250_request_port,
  2180. .config_port = serial8250_config_port,
  2181. .verify_port = serial8250_verify_port,
  2182. #ifdef CONFIG_CONSOLE_POLL
  2183. .poll_get_char = serial8250_get_poll_char,
  2184. .poll_put_char = serial8250_put_poll_char,
  2185. #endif
  2186. };
  2187. static struct uart_8250_port serial8250_ports[UART_NR];
  2188. static void __init serial8250_isa_init_ports(void)
  2189. {
  2190. struct uart_8250_port *up;
  2191. static int first = 1;
  2192. int i;
  2193. if (!first)
  2194. return;
  2195. first = 0;
  2196. for (i = 0; i < nr_uarts; i++) {
  2197. struct uart_8250_port *up = &serial8250_ports[i];
  2198. up->port.line = i;
  2199. spin_lock_init(&up->port.lock);
  2200. init_timer(&up->timer);
  2201. up->timer.function = serial8250_timeout;
  2202. /*
  2203. * ALPHA_KLUDGE_MCR needs to be killed.
  2204. */
  2205. up->mcr_mask = ~ALPHA_KLUDGE_MCR;
  2206. up->mcr_force = ALPHA_KLUDGE_MCR;
  2207. up->port.ops = &serial8250_pops;
  2208. }
  2209. for (i = 0, up = serial8250_ports;
  2210. i < ARRAY_SIZE(old_serial_port) && i < nr_uarts;
  2211. i++, up++) {
  2212. up->port.iobase = old_serial_port[i].port;
  2213. up->port.irq = irq_canonicalize(old_serial_port[i].irq);
  2214. up->port.uartclk = old_serial_port[i].baud_base * 16;
  2215. up->port.flags = old_serial_port[i].flags;
  2216. up->port.hub6 = old_serial_port[i].hub6;
  2217. up->port.membase = old_serial_port[i].iomem_base;
  2218. up->port.iotype = old_serial_port[i].io_type;
  2219. up->port.regshift = old_serial_port[i].iomem_reg_shift;
  2220. if (share_irqs)
  2221. up->port.flags |= UPF_SHARE_IRQ;
  2222. }
  2223. }
  2224. static void __init
  2225. serial8250_register_ports(struct uart_driver *drv, struct device *dev)
  2226. {
  2227. int i;
  2228. serial8250_isa_init_ports();
  2229. for (i = 0; i < nr_uarts; i++) {
  2230. struct uart_8250_port *up = &serial8250_ports[i];
  2231. up->port.dev = dev;
  2232. uart_add_one_port(drv, &up->port);
  2233. }
  2234. }
  2235. #ifdef CONFIG_SERIAL_8250_CONSOLE
  2236. static void serial8250_console_putchar(struct uart_port *port, int ch)
  2237. {
  2238. struct uart_8250_port *up = (struct uart_8250_port *)port;
  2239. wait_for_xmitr(up, UART_LSR_THRE);
  2240. serial_out(up, UART_TX, ch);
  2241. }
  2242. /*
  2243. * Print a string to the serial port trying not to disturb
  2244. * any possible real use of the port...
  2245. *
  2246. * The console_lock must be held when we get here.
  2247. */
  2248. static void
  2249. serial8250_console_write(struct console *co, const char *s, unsigned int count)
  2250. {
  2251. struct uart_8250_port *up = &serial8250_ports[co->index];
  2252. unsigned long flags;
  2253. unsigned int ier;
  2254. int locked = 1;
  2255. touch_nmi_watchdog();
  2256. local_irq_save(flags);
  2257. if (up->port.sysrq) {
  2258. /* serial8250_handle_port() already took the lock */
  2259. locked = 0;
  2260. } else if (oops_in_progress) {
  2261. locked = spin_trylock(&up->port.lock);
  2262. } else
  2263. spin_lock(&up->port.lock);
  2264. /*
  2265. * First save the IER then disable the interrupts
  2266. */
  2267. ier = serial_in(up, UART_IER);
  2268. if (up->capabilities & UART_CAP_UUE)
  2269. serial_out(up, UART_IER, UART_IER_UUE);
  2270. else
  2271. serial_out(up, UART_IER, 0);
  2272. uart_console_write(&up->port, s, count, serial8250_console_putchar);
  2273. /*
  2274. * Finally, wait for transmitter to become empty
  2275. * and restore the IER
  2276. */
  2277. wait_for_xmitr(up, BOTH_EMPTY);
  2278. serial_out(up, UART_IER, ier);
  2279. /*
  2280. * The receive handling will happen properly because the
  2281. * receive ready bit will still be set; it is not cleared
  2282. * on read. However, modem control will not, we must
  2283. * call it if we have saved something in the saved flags
  2284. * while processing with interrupts off.
  2285. */
  2286. if (up->msr_saved_flags)
  2287. check_modem_status(up);
  2288. if (locked)
  2289. spin_unlock(&up->port.lock);
  2290. local_irq_restore(flags);
  2291. }
  2292. static int __init serial8250_console_setup(struct console *co, char *options)
  2293. {
  2294. struct uart_port *port;
  2295. int baud = 9600;
  2296. int bits = 8;
  2297. int parity = 'n';
  2298. int flow = 'n';
  2299. /*
  2300. * Check whether an invalid uart number has been specified, and
  2301. * if so, search for the first available port that does have
  2302. * console support.
  2303. */
  2304. if (co->index >= nr_uarts)
  2305. co->index = 0;
  2306. port = &serial8250_ports[co->index].port;
  2307. if (!port->iobase && !port->membase)
  2308. return -ENODEV;
  2309. if (options)
  2310. uart_parse_options(options, &baud, &parity, &bits, &flow);
  2311. return uart_set_options(port, co, baud, parity, bits, flow);
  2312. }
  2313. static int serial8250_console_early_setup(void)
  2314. {
  2315. return serial8250_find_port_for_earlycon();
  2316. }
  2317. static struct console serial8250_console = {
  2318. .name = "ttyS",
  2319. .write = serial8250_console_write,
  2320. .device = uart_console_device,
  2321. .setup = serial8250_console_setup,
  2322. .early_setup = serial8250_console_early_setup,
  2323. .flags = CON_PRINTBUFFER,
  2324. .index = -1,
  2325. .data = &serial8250_reg,
  2326. };
  2327. static int __init serial8250_console_init(void)
  2328. {
  2329. if (nr_uarts > UART_NR)
  2330. nr_uarts = UART_NR;
  2331. serial8250_isa_init_ports();
  2332. register_console(&serial8250_console);
  2333. return 0;
  2334. }
  2335. console_initcall(serial8250_console_init);
  2336. int serial8250_find_port(struct uart_port *p)
  2337. {
  2338. int line;
  2339. struct uart_port *port;
  2340. for (line = 0; line < nr_uarts; line++) {
  2341. port = &serial8250_ports[line].port;
  2342. if (uart_match_port(p, port))
  2343. return line;
  2344. }
  2345. return -ENODEV;
  2346. }
  2347. #define SERIAL8250_CONSOLE &serial8250_console
  2348. #else
  2349. #define SERIAL8250_CONSOLE NULL
  2350. #endif
  2351. static struct uart_driver serial8250_reg = {
  2352. .owner = THIS_MODULE,
  2353. .driver_name = "serial",
  2354. .dev_name = "ttyS",
  2355. .major = TTY_MAJOR,
  2356. .minor = 64,
  2357. .cons = SERIAL8250_CONSOLE,
  2358. };
  2359. /*
  2360. * early_serial_setup - early registration for 8250 ports
  2361. *
  2362. * Setup an 8250 port structure prior to console initialisation. Use
  2363. * after console initialisation will cause undefined behaviour.
  2364. */
  2365. int __init early_serial_setup(struct uart_port *port)
  2366. {
  2367. if (port->line >= ARRAY_SIZE(serial8250_ports))
  2368. return -ENODEV;
  2369. serial8250_isa_init_ports();
  2370. serial8250_ports[port->line].port = *port;
  2371. serial8250_ports[port->line].port.ops = &serial8250_pops;
  2372. return 0;
  2373. }
  2374. /**
  2375. * serial8250_suspend_port - suspend one serial port
  2376. * @line: serial line number
  2377. *
  2378. * Suspend one serial port.
  2379. */
  2380. void serial8250_suspend_port(int line)
  2381. {
  2382. uart_suspend_port(&serial8250_reg, &serial8250_ports[line].port);
  2383. }
  2384. /**
  2385. * serial8250_resume_port - resume one serial port
  2386. * @line: serial line number
  2387. *
  2388. * Resume one serial port.
  2389. */
  2390. void serial8250_resume_port(int line)
  2391. {
  2392. struct uart_8250_port *up = &serial8250_ports[line];
  2393. if (up->capabilities & UART_NATSEMI) {
  2394. unsigned char tmp;
  2395. /* Ensure it's still in high speed mode */
  2396. serial_outp(up, UART_LCR, 0xE0);
  2397. tmp = serial_in(up, 0x04); /* EXCR2 */
  2398. tmp &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
  2399. tmp |= 0x10; /* 1.625 divisor for baud_base --> 921600 */
  2400. serial_outp(up, 0x04, tmp);
  2401. serial_outp(up, UART_LCR, 0);
  2402. }
  2403. uart_resume_port(&serial8250_reg, &up->port);
  2404. }
  2405. /*
  2406. * Register a set of serial devices attached to a platform device. The
  2407. * list is terminated with a zero flags entry, which means we expect
  2408. * all entries to have at least UPF_BOOT_AUTOCONF set.
  2409. */
  2410. static int __devinit serial8250_probe(struct platform_device *dev)
  2411. {
  2412. struct plat_serial8250_port *p = dev->dev.platform_data;
  2413. struct uart_port port;
  2414. int ret, i;
  2415. memset(&port, 0, sizeof(struct uart_port));
  2416. for (i = 0; p && p->flags != 0; p++, i++) {
  2417. port.iobase = p->iobase;
  2418. port.membase = p->membase;
  2419. port.irq = p->irq;
  2420. port.uartclk = p->uartclk;
  2421. port.regshift = p->regshift;
  2422. port.iotype = p->iotype;
  2423. port.flags = p->flags;
  2424. port.mapbase = p->mapbase;
  2425. port.hub6 = p->hub6;
  2426. port.private_data = p->private_data;
  2427. port.dev = &dev->dev;
  2428. if (share_irqs)
  2429. port.flags |= UPF_SHARE_IRQ;
  2430. ret = serial8250_register_port(&port);
  2431. if (ret < 0) {
  2432. dev_err(&dev->dev, "unable to register port at index %d "
  2433. "(IO%lx MEM%llx IRQ%d): %d\n", i,
  2434. p->iobase, (unsigned long long)p->mapbase,
  2435. p->irq, ret);
  2436. }
  2437. }
  2438. return 0;
  2439. }
  2440. /*
  2441. * Remove serial ports registered against a platform device.
  2442. */
  2443. static int __devexit serial8250_remove(struct platform_device *dev)
  2444. {
  2445. int i;
  2446. for (i = 0; i < nr_uarts; i++) {
  2447. struct uart_8250_port *up = &serial8250_ports[i];
  2448. if (up->port.dev == &dev->dev)
  2449. serial8250_unregister_port(i);
  2450. }
  2451. return 0;
  2452. }
  2453. static int serial8250_suspend(struct platform_device *dev, pm_message_t state)
  2454. {
  2455. int i;
  2456. for (i = 0; i < UART_NR; i++) {
  2457. struct uart_8250_port *up = &serial8250_ports[i];
  2458. if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
  2459. uart_suspend_port(&serial8250_reg, &up->port);
  2460. }
  2461. return 0;
  2462. }
  2463. static int serial8250_resume(struct platform_device *dev)
  2464. {
  2465. int i;
  2466. for (i = 0; i < UART_NR; i++) {
  2467. struct uart_8250_port *up = &serial8250_ports[i];
  2468. if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
  2469. serial8250_resume_port(i);
  2470. }
  2471. return 0;
  2472. }
  2473. static struct platform_driver serial8250_isa_driver = {
  2474. .probe = serial8250_probe,
  2475. .remove = __devexit_p(serial8250_remove),
  2476. .suspend = serial8250_suspend,
  2477. .resume = serial8250_resume,
  2478. .driver = {
  2479. .name = "serial8250",
  2480. .owner = THIS_MODULE,
  2481. },
  2482. };
  2483. /*
  2484. * This "device" covers _all_ ISA 8250-compatible serial devices listed
  2485. * in the table in include/asm/serial.h
  2486. */
  2487. static struct platform_device *serial8250_isa_devs;
  2488. /*
  2489. * serial8250_register_port and serial8250_unregister_port allows for
  2490. * 16x50 serial ports to be configured at run-time, to support PCMCIA
  2491. * modems and PCI multiport cards.
  2492. */
  2493. static DEFINE_MUTEX(serial_mutex);
  2494. static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *port)
  2495. {
  2496. int i;
  2497. /*
  2498. * First, find a port entry which matches.
  2499. */
  2500. for (i = 0; i < nr_uarts; i++)
  2501. if (uart_match_port(&serial8250_ports[i].port, port))
  2502. return &serial8250_ports[i];
  2503. /*
  2504. * We didn't find a matching entry, so look for the first
  2505. * free entry. We look for one which hasn't been previously
  2506. * used (indicated by zero iobase).
  2507. */
  2508. for (i = 0; i < nr_uarts; i++)
  2509. if (serial8250_ports[i].port.type == PORT_UNKNOWN &&
  2510. serial8250_ports[i].port.iobase == 0)
  2511. return &serial8250_ports[i];
  2512. /*
  2513. * That also failed. Last resort is to find any entry which
  2514. * doesn't have a real port associated with it.
  2515. */
  2516. for (i = 0; i < nr_uarts; i++)
  2517. if (serial8250_ports[i].port.type == PORT_UNKNOWN)
  2518. return &serial8250_ports[i];
  2519. return NULL;
  2520. }
  2521. /**
  2522. * serial8250_register_port - register a serial port
  2523. * @port: serial port template
  2524. *
  2525. * Configure the serial port specified by the request. If the
  2526. * port exists and is in use, it is hung up and unregistered
  2527. * first.
  2528. *
  2529. * The port is then probed and if necessary the IRQ is autodetected
  2530. * If this fails an error is returned.
  2531. *
  2532. * On success the port is ready to use and the line number is returned.
  2533. */
  2534. int serial8250_register_port(struct uart_port *port)
  2535. {
  2536. struct uart_8250_port *uart;
  2537. int ret = -ENOSPC;
  2538. if (port->uartclk == 0)
  2539. return -EINVAL;
  2540. mutex_lock(&serial_mutex);
  2541. uart = serial8250_find_match_or_unused(port);
  2542. if (uart) {
  2543. uart_remove_one_port(&serial8250_reg, &uart->port);
  2544. uart->port.iobase = port->iobase;
  2545. uart->port.membase = port->membase;
  2546. uart->port.irq = port->irq;
  2547. uart->port.uartclk = port->uartclk;
  2548. uart->port.fifosize = port->fifosize;
  2549. uart->port.regshift = port->regshift;
  2550. uart->port.iotype = port->iotype;
  2551. uart->port.flags = port->flags | UPF_BOOT_AUTOCONF;
  2552. uart->port.mapbase = port->mapbase;
  2553. uart->port.private_data = port->private_data;
  2554. if (port->dev)
  2555. uart->port.dev = port->dev;
  2556. ret = uart_add_one_port(&serial8250_reg, &uart->port);
  2557. if (ret == 0)
  2558. ret = uart->port.line;
  2559. }
  2560. mutex_unlock(&serial_mutex);
  2561. return ret;
  2562. }
  2563. EXPORT_SYMBOL(serial8250_register_port);
  2564. /**
  2565. * serial8250_unregister_port - remove a 16x50 serial port at runtime
  2566. * @line: serial line number
  2567. *
  2568. * Remove one serial port. This may not be called from interrupt
  2569. * context. We hand the port back to the our control.
  2570. */
  2571. void serial8250_unregister_port(int line)
  2572. {
  2573. struct uart_8250_port *uart = &serial8250_ports[line];
  2574. mutex_lock(&serial_mutex);
  2575. uart_remove_one_port(&serial8250_reg, &uart->port);
  2576. if (serial8250_isa_devs) {
  2577. uart->port.flags &= ~UPF_BOOT_AUTOCONF;
  2578. uart->port.type = PORT_UNKNOWN;
  2579. uart->port.dev = &serial8250_isa_devs->dev;
  2580. uart_add_one_port(&serial8250_reg, &uart->port);
  2581. } else {
  2582. uart->port.dev = NULL;
  2583. }
  2584. mutex_unlock(&serial_mutex);
  2585. }
  2586. EXPORT_SYMBOL(serial8250_unregister_port);
  2587. static int __init serial8250_init(void)
  2588. {
  2589. int ret;
  2590. if (nr_uarts > UART_NR)
  2591. nr_uarts = UART_NR;
  2592. printk(KERN_INFO "Serial: 8250/16550 driver"
  2593. "%d ports, IRQ sharing %sabled\n", nr_uarts,
  2594. share_irqs ? "en" : "dis");
  2595. #ifdef CONFIG_SPARC
  2596. ret = sunserial_register_minors(&serial8250_reg, UART_NR);
  2597. #else
  2598. serial8250_reg.nr = UART_NR;
  2599. ret = uart_register_driver(&serial8250_reg);
  2600. #endif
  2601. if (ret)
  2602. goto out;
  2603. serial8250_isa_devs = platform_device_alloc("serial8250",
  2604. PLAT8250_DEV_LEGACY);
  2605. if (!serial8250_isa_devs) {
  2606. ret = -ENOMEM;
  2607. goto unreg_uart_drv;
  2608. }
  2609. ret = platform_device_add(serial8250_isa_devs);
  2610. if (ret)
  2611. goto put_dev;
  2612. serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev);
  2613. ret = platform_driver_register(&serial8250_isa_driver);
  2614. if (ret == 0)
  2615. goto out;
  2616. platform_device_del(serial8250_isa_devs);
  2617. put_dev:
  2618. platform_device_put(serial8250_isa_devs);
  2619. unreg_uart_drv:
  2620. #ifdef CONFIG_SPARC
  2621. sunserial_unregister_minors(&serial8250_reg, UART_NR);
  2622. #else
  2623. uart_unregister_driver(&serial8250_reg);
  2624. #endif
  2625. out:
  2626. return ret;
  2627. }
  2628. static void __exit serial8250_exit(void)
  2629. {
  2630. struct platform_device *isa_dev = serial8250_isa_devs;
  2631. /*
  2632. * This tells serial8250_unregister_port() not to re-register
  2633. * the ports (thereby making serial8250_isa_driver permanently
  2634. * in use.)
  2635. */
  2636. serial8250_isa_devs = NULL;
  2637. platform_driver_unregister(&serial8250_isa_driver);
  2638. platform_device_unregister(isa_dev);
  2639. #ifdef CONFIG_SPARC
  2640. sunserial_unregister_minors(&serial8250_reg, UART_NR);
  2641. #else
  2642. uart_unregister_driver(&serial8250_reg);
  2643. #endif
  2644. }
  2645. module_init(serial8250_init);
  2646. module_exit(serial8250_exit);
  2647. EXPORT_SYMBOL(serial8250_suspend_port);
  2648. EXPORT_SYMBOL(serial8250_resume_port);
  2649. MODULE_LICENSE("GPL");
  2650. MODULE_DESCRIPTION("Generic 8250/16x50 serial driver");
  2651. module_param(share_irqs, uint, 0644);
  2652. MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices"
  2653. " (unsafe)");
  2654. module_param(nr_uarts, uint, 0644);
  2655. MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")");
  2656. #ifdef CONFIG_SERIAL_8250_RSA
  2657. module_param_array(probe_rsa, ulong, &probe_rsa_count, 0444);
  2658. MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
  2659. #endif
  2660. MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);