8250.c 76 KB

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